LLVM API Documentation

SectionKind.h

Go to the documentation of this file.
00001 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements classes used to handle lowerings specific to common
00011 // object file formats.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_MC_SECTIONKIND_H
00016 #define LLVM_MC_SECTIONKIND_H
00017 
00018 namespace llvm {
00019 
00020 /// SectionKind - This is a simple POD value that classifies the properties of
00021 /// a section.  A section is classified into the deepest possible
00022 /// classification, and then the target maps them onto their sections based on
00023 /// what capabilities they have.
00024 ///
00025 /// The comments below describe these as if they were an inheritance hierarchy
00026 /// in order to explain the predicates below.
00027 ///
00028 class SectionKind {
00029   enum Kind {
00030     /// Metadata - Debug info sections or other metadata.
00031     Metadata,
00032     
00033     /// Text - Text section, used for functions and other executable code.
00034     Text,
00035     
00036     /// ReadOnly - Data that is never written to at program runtime by the
00037     /// program or the dynamic linker.  Things in the top-level readonly
00038     /// SectionKind are not mergeable.
00039     ReadOnly,
00040 
00041         /// MergableCString - Any null-terminated string which allows merging.
00042         /// These values are known to end in a nul value of the specified size,
00043         /// not otherwise contain a nul value, and be mergable.  This allows the
00044         /// linker to unique the strings if it so desires.
00045 
00046            /// Mergeable1ByteCString - 1 byte mergable, null terminated, string.
00047            Mergeable1ByteCString,
00048     
00049            /// Mergeable2ByteCString - 2 byte mergable, null terminated, string.
00050            Mergeable2ByteCString,
00051 
00052            /// Mergeable4ByteCString - 4 byte mergable, null terminated, string.
00053            Mergeable4ByteCString,
00054 
00055         /// MergeableConst - These are sections for merging fixed-length
00056         /// constants together.  For example, this can be used to unique
00057         /// constant pool entries etc.
00058         MergeableConst,
00059     
00060             /// MergeableConst4 - This is a section used by 4-byte constants,
00061             /// for example, floats.
00062             MergeableConst4,
00063     
00064             /// MergeableConst8 - This is a section used by 8-byte constants,
00065             /// for example, doubles.
00066             MergeableConst8,
00067 
00068             /// MergeableConst16 - This is a section used by 16-byte constants,
00069             /// for example, vectors.
00070             MergeableConst16,
00071     
00072     /// Writeable - This is the base of all segments that need to be written
00073     /// to during program runtime.
00074     
00075        /// ThreadLocal - This is the base of all TLS segments.  All TLS
00076        /// objects must be writeable, otherwise there is no reason for them to
00077        /// be thread local!
00078     
00079            /// ThreadBSS - Zero-initialized TLS data objects.
00080            ThreadBSS,
00081     
00082            /// ThreadData - Initialized TLS data objects.
00083            ThreadData,
00084     
00085        /// GlobalWriteableData - Writeable data that is global (not thread
00086        /// local).
00087     
00088            /// BSS - Zero initialized writeable data.
00089            BSS,
00090 
00091            /// DataRel - This is the most general form of data that is written
00092            /// to by the program, it can have random relocations to arbitrary
00093            /// globals.
00094            DataRel,
00095 
00096                /// DataRelLocal - This is writeable data that has a non-zero
00097                /// initializer and has relocations in it, but all of the
00098                /// relocations are known to be within the final linked image
00099                /// the global is linked into.
00100                DataRelLocal,
00101 
00102                    /// DataNoRel - This is writeable data that has a non-zero
00103                    /// initializer, but whose initializer is known to have no
00104                    /// relocations.
00105                    DataNoRel,
00106 
00107            /// ReadOnlyWithRel - These are global variables that are never
00108            /// written to by the program, but that have relocations, so they
00109            /// must be stuck in a writeable section so that the dynamic linker
00110            /// can write to them.  If it chooses to, the dynamic linker can
00111            /// mark the pages these globals end up on as read-only after it is
00112            /// done with its relocation phase.
00113            ReadOnlyWithRel,
00114     
00115                /// ReadOnlyWithRelLocal - This is data that is readonly by the
00116                /// program, but must be writeable so that the dynamic linker
00117                /// can perform relocations in it.  This is used when we know
00118                /// that all the relocations are to globals in this final
00119                /// linked image.
00120                ReadOnlyWithRelLocal
00121     
00122   } K : 8;
00123 public:
00124   
00125   bool isMetadata() const { return K == Metadata; }
00126   bool isText() const { return K == Text; }
00127   
00128   bool isReadOnly() const {
00129     return K == ReadOnly || isMergeableCString() ||
00130            isMergeableConst();
00131   }
00132 
00133   bool isMergeableCString() const {
00134     return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
00135            K == Mergeable4ByteCString;
00136   }
00137   bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
00138   bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
00139   bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
00140   
00141   bool isMergeableConst() const {
00142     return K == MergeableConst || K == MergeableConst4 ||
00143            K == MergeableConst8 || K == MergeableConst16;
00144   }
00145   bool isMergeableConst4() const { return K == MergeableConst4; }
00146   bool isMergeableConst8() const { return K == MergeableConst8; }
00147   bool isMergeableConst16() const { return K == MergeableConst16; }
00148   
00149   bool isWriteable() const {
00150     return isThreadLocal() || isGlobalWriteableData();
00151   }
00152   
00153   bool isThreadLocal() const {
00154     return K == ThreadData || K == ThreadBSS;
00155   }
00156   
00157   bool isThreadBSS() const { return K == ThreadBSS; } 
00158   bool isThreadData() const { return K == ThreadData; } 
00159 
00160   bool isGlobalWriteableData() const {
00161     return isBSS() || isDataRel() || isReadOnlyWithRel();
00162   }
00163   
00164   bool isBSS() const { return K == BSS; }
00165   
00166   bool isDataRel() const {
00167     return K == DataRel || K == DataRelLocal || K == DataNoRel;
00168   }
00169   
00170   bool isDataRelLocal() const {
00171     return K == DataRelLocal || K == DataNoRel;
00172   }
00173 
00174   bool isDataNoRel() const { return K == DataNoRel; }
00175   
00176   bool isReadOnlyWithRel() const {
00177     return K == ReadOnlyWithRel || K == ReadOnlyWithRelLocal;
00178   }
00179 
00180   bool isReadOnlyWithRelLocal() const {
00181     return K == ReadOnlyWithRelLocal;
00182   }
00183 private: 
00184   static SectionKind get(Kind K) {
00185     SectionKind Res;
00186     Res.K = K;
00187     return Res;
00188   }
00189 public:
00190   
00191   static SectionKind getMetadata() { return get(Metadata); }
00192   static SectionKind getText() { return get(Text); }
00193   static SectionKind getReadOnly() { return get(ReadOnly); }
00194   static SectionKind getMergeable1ByteCString() {
00195     return get(Mergeable1ByteCString);
00196   }
00197   static SectionKind getMergeable2ByteCString() {
00198     return get(Mergeable2ByteCString);
00199   }
00200   static SectionKind getMergeable4ByteCString() {
00201     return get(Mergeable4ByteCString);
00202   }
00203   static SectionKind getMergeableConst() { return get(MergeableConst); }
00204   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
00205   static SectionKind getMergeableConst8() { return get(MergeableConst8); }
00206   static SectionKind getMergeableConst16() { return get(MergeableConst16); }
00207   static SectionKind getThreadBSS() { return get(ThreadBSS); }
00208   static SectionKind getThreadData() { return get(ThreadData); }
00209   static SectionKind getBSS() { return get(BSS); }
00210   static SectionKind getDataRel() { return get(DataRel); }
00211   static SectionKind getDataRelLocal() { return get(DataRelLocal); }
00212   static SectionKind getDataNoRel() { return get(DataNoRel); }
00213   static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
00214   static SectionKind getReadOnlyWithRelLocal(){
00215     return get(ReadOnlyWithRelLocal);
00216   }
00217 };
00218   
00219 } // end namespace llvm
00220 
00221 #endif