fix a layering violation by moving SectionKind out to its own header.
[oota-llvm.git] / include / llvm / MC / SectionKind.h
1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- 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 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_MC_SECTIONKIND_H
16 #define LLVM_MC_SECTIONKIND_H
17
18 namespace llvm {
19
20 /// SectionKind - This is a simple POD value that classifies the properties of
21 /// a section.  A section is classified into the deepest possible
22 /// classification, and then the target maps them onto their sections based on
23 /// what capabilities they have.
24 ///
25 /// The comments below describe these as if they were an inheritance hierarchy
26 /// in order to explain the predicates below.
27 ///
28 class SectionKind {
29 public:
30   enum Kind {
31     /// Metadata - Debug info sections or other metadata.
32     Metadata,
33     
34     /// Text - Text section, used for functions and other executable code.
35     Text,
36     
37     /// ReadOnly - Data that is never written to at program runtime by the
38     /// program or the dynamic linker.  Things in the top-level readonly
39     /// SectionKind are not mergeable.
40     ReadOnly,
41
42         /// MergeableCString - This is a special section for nul-terminated
43         /// strings.  The linker can unique the C strings, knowing their
44         /// semantics.  Because it uniques based on the nul terminators, the
45         /// compiler can't put strings in this section that have embeded nuls
46         /// in them.
47         MergeableCString,
48     
49         /// MergeableConst - These are sections for merging fixed-length
50         /// constants together.  For example, this can be used to unique
51         /// constant pool entries etc.
52         MergeableConst,
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            /// DataRel - This is the most general form of data that is written
86            /// to by the program, it can have random relocations to arbitrary
87            /// globals.
88            DataRel,
89
90                /// DataRelLocal - This is writeable data that has a non-zero
91                /// initializer and has relocations in it, but all of the
92                /// relocations are known to be within the final linked image
93                /// the global is linked into.
94                DataRelLocal,
95
96                    /// DataNoRel - This is writeable data that has a non-zero
97                    /// initializer, but whose initializer is known to have no
98                    /// relocations.
99                    DataNoRel,
100
101            /// ReadOnlyWithRel - These are global variables that are never
102            /// written to by the program, but that have relocations, so they
103            /// must be stuck in a writeable section so that the dynamic linker
104            /// can write to them.  If it chooses to, the dynamic linker can
105            /// mark the pages these globals end up on as read-only after it is
106            /// done with its relocation phase.
107            ReadOnlyWithRel,
108     
109                /// ReadOnlyWithRelLocal - This is data that is readonly by the
110                /// program, but must be writeable so that the dynamic linker
111                /// can perform relocations in it.  This is used when we know
112                /// that all the relocations are to globals in this final
113                /// linked image.
114                ReadOnlyWithRelLocal
115     
116   };
117   
118 protected:
119   Kind K : 8;
120   
121 public:
122   
123   bool isMetadata() const { return K == Metadata; }
124   bool isText() const { return K == Text; }
125   
126   bool isReadOnly() const {
127     return K == ReadOnly || K == MergeableCString || isMergeableConst();
128   }
129
130   bool isMergeableCString() const { return K == MergeableCString; }
131   bool isMergeableConst() const {
132     return K == MergeableConst || K == MergeableConst4 ||
133            K == MergeableConst8 || K == MergeableConst16;
134   }
135   
136   bool isMergeableConst4() const { return K == MergeableConst4; }
137   bool isMergeableConst8() const { return K == MergeableConst8; }
138   bool isMergeableConst16() const { return K == MergeableConst16; }
139   
140   bool isWriteable() const {
141     return isThreadLocal() || isGlobalWriteableData();
142   }
143   
144   bool isThreadLocal() const {
145     return K == ThreadData || K == ThreadBSS;
146   }
147   
148   bool isThreadBSS() const { return K == ThreadBSS; } 
149   bool isThreadData() const { return K == ThreadData; } 
150
151   bool isGlobalWriteableData() const {
152     return isBSS() || isDataRel() || isReadOnlyWithRel();
153   }
154   
155   bool isBSS() const { return K == BSS; }
156   
157   bool isDataRel() const {
158     return K == DataRel || K == DataRelLocal || K == DataNoRel;
159   }
160   
161   bool isDataRelLocal() const {
162     return K == DataRelLocal || K == DataNoRel;
163   }
164
165   bool isDataNoRel() const { return K == DataNoRel; }
166   
167   bool isReadOnlyWithRel() const {
168     return K == ReadOnlyWithRel || K == ReadOnlyWithRelLocal;
169   }
170
171   bool isReadOnlyWithRelLocal() const {
172     return K == ReadOnlyWithRelLocal;
173   }
174   
175   static SectionKind get(Kind K) {
176     SectionKind Res;
177     Res.K = K;
178     return Res;
179   }
180 };
181   
182 } // end namespace llvm
183
184 #endif