[MC] Fix the comment header for this header file. It was just
[oota-llvm.git] / include / llvm / MC / SectionKind.h
1 //===-- llvm/MC/SectionKind.h - Classification of sections ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_MC_SECTIONKIND_H
11 #define LLVM_MC_SECTIONKIND_H
12
13 namespace llvm {
14
15 /// SectionKind - This is a simple POD value that classifies the properties of
16 /// a section.  A section is classified into the deepest possible
17 /// classification, and then the target maps them onto their sections based on
18 /// what capabilities they have.
19 ///
20 /// The comments below describe these as if they were an inheritance hierarchy
21 /// in order to explain the predicates below.
22 ///
23 class SectionKind {
24   enum Kind {
25     /// Metadata - Debug info sections or other metadata.
26     Metadata,
27
28     /// Text - Text section, used for functions and other executable code.
29     Text,
30
31     /// ReadOnly - Data that is never written to at program runtime by the
32     /// program or the dynamic linker.  Things in the top-level readonly
33     /// SectionKind are not mergeable.
34     ReadOnly,
35
36         /// MergableCString - Any null-terminated string which allows merging.
37         /// These values are known to end in a nul value of the specified size,
38         /// not otherwise contain a nul value, and be mergable.  This allows the
39         /// linker to unique the strings if it so desires.
40
41            /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
42            Mergeable1ByteCString,
43
44            /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
45            Mergeable2ByteCString,
46
47            /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
48            Mergeable4ByteCString,
49
50         /// MergeableConst - These are sections for merging fixed-length
51         /// constants together.  For example, this can be used to unique
52         /// constant pool entries etc.
53
54             /// MergeableConst4 - This is a section used by 4-byte constants,
55             /// for example, floats.
56             MergeableConst4,
57
58             /// MergeableConst8 - This is a section used by 8-byte constants,
59             /// for example, doubles.
60             MergeableConst8,
61
62             /// MergeableConst16 - This is a section used by 16-byte constants,
63             /// for example, vectors.
64             MergeableConst16,
65
66     /// Writeable - This is the base of all segments that need to be written
67     /// to during program runtime.
68
69        /// ThreadLocal - This is the base of all TLS segments.  All TLS
70        /// objects must be writeable, otherwise there is no reason for them to
71        /// be thread local!
72
73            /// ThreadBSS - Zero-initialized TLS data objects.
74            ThreadBSS,
75
76            /// ThreadData - Initialized TLS data objects.
77            ThreadData,
78
79        /// GlobalWriteableData - Writeable data that is global (not thread
80        /// local).
81
82            /// BSS - Zero initialized writeable data.
83            BSS,
84
85                /// BSSLocal - This is BSS (zero initialized and writable) data
86                /// which has local linkage.
87                BSSLocal,
88
89                /// BSSExtern - This is BSS data with normal external linkage.
90                BSSExtern,
91
92            /// Common - Data with common linkage.  These represent tentative
93            /// definitions, which always have a zero initializer and are never
94            /// marked 'constant'.
95            Common,
96
97            /// This is writeable data that has a non-zero initializer.
98            Data,
99
100            /// ReadOnlyWithRel - These are global variables that are never
101            /// written to by the program, but that have relocations, so they
102            /// must be stuck in a writeable section so that the dynamic linker
103            /// can write to them.  If it chooses to, the dynamic linker can
104            /// mark the pages these globals end up on as read-only after it is
105            /// done with its relocation phase.
106            ReadOnlyWithRel
107   } K : 8;
108 public:
109
110   bool isMetadata() const { return K == Metadata; }
111   bool isText() const { return K == Text; }
112
113   bool isReadOnly() const {
114     return K == ReadOnly || isMergeableCString() ||
115            isMergeableConst();
116   }
117
118   bool isMergeableCString() const {
119     return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
120            K == Mergeable4ByteCString;
121   }
122   bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
123   bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
124   bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
125
126   bool isMergeableConst() const {
127     return K == MergeableConst4 || K == MergeableConst8 ||
128            K == MergeableConst16;
129   }
130   bool isMergeableConst4() const { return K == MergeableConst4; }
131   bool isMergeableConst8() const { return K == MergeableConst8; }
132   bool isMergeableConst16() const { return K == MergeableConst16; }
133
134   bool isWriteable() const {
135     return isThreadLocal() || isGlobalWriteableData();
136   }
137
138   bool isThreadLocal() const {
139     return K == ThreadData || K == ThreadBSS;
140   }
141
142   bool isThreadBSS() const { return K == ThreadBSS; }
143   bool isThreadData() const { return K == ThreadData; }
144
145   bool isGlobalWriteableData() const {
146     return isBSS() || isCommon() || isData() || isReadOnlyWithRel();
147   }
148
149   bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
150   bool isBSSLocal() const { return K == BSSLocal; }
151   bool isBSSExtern() const { return K == BSSExtern; }
152
153   bool isCommon() const { return K == Common; }
154
155   bool isData() const { return K == Data; }
156
157   bool isReadOnlyWithRel() const {
158     return K == ReadOnlyWithRel;
159   }
160 private:
161   static SectionKind get(Kind K) {
162     SectionKind Res;
163     Res.K = K;
164     return Res;
165   }
166 public:
167
168   static SectionKind getMetadata() { return get(Metadata); }
169   static SectionKind getText() { return get(Text); }
170   static SectionKind getReadOnly() { return get(ReadOnly); }
171   static SectionKind getMergeable1ByteCString() {
172     return get(Mergeable1ByteCString);
173   }
174   static SectionKind getMergeable2ByteCString() {
175     return get(Mergeable2ByteCString);
176   }
177   static SectionKind getMergeable4ByteCString() {
178     return get(Mergeable4ByteCString);
179   }
180   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
181   static SectionKind getMergeableConst8() { return get(MergeableConst8); }
182   static SectionKind getMergeableConst16() { return get(MergeableConst16); }
183   static SectionKind getThreadBSS() { return get(ThreadBSS); }
184   static SectionKind getThreadData() { return get(ThreadData); }
185   static SectionKind getBSS() { return get(BSS); }
186   static SectionKind getBSSLocal() { return get(BSSLocal); }
187   static SectionKind getBSSExtern() { return get(BSSExtern); }
188   static SectionKind getCommon() { return get(Common); }
189   static SectionKind getData() { return get(Data); }
190   static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
191 };
192
193 } // end namespace llvm
194
195 #endif