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                /// BSSLocal - This is BSS (zero initialized and writable) data
00092                /// which has local linkage.
00093                BSSLocal,
00094 
00095                /// BSSExtern - This is BSS data with normal external linkage.
00096                BSSExtern,
00097 
00098            /// Common - Data with common linkage.  These represent tentative
00099            /// definitions, which always have a zero initializer and are never
00100            /// marked 'constant'.
00101            Common,
00102 
00103            /// DataRel - This is the most general form of data that is written
00104            /// to by the program, it can have random relocations to arbitrary
00105            /// globals.
00106            DataRel,
00107 
00108                /// DataRelLocal - This is writeable data that has a non-zero
00109                /// initializer and has relocations in it, but all of the
00110                /// relocations are known to be within the final linked image
00111                /// the global is linked into.
00112                DataRelLocal,
00113 
00114                    /// DataNoRel - This is writeable data that has a non-zero
00115                    /// initializer, but whose initializer is known to have no
00116                    /// relocations.
00117                    DataNoRel,
00118 
00119            /// ReadOnlyWithRel - These are global variables that are never
00120            /// written to by the program, but that have relocations, so they
00121            /// must be stuck in a writeable section so that the dynamic linker
00122            /// can write to them.  If it chooses to, the dynamic linker can
00123            /// mark the pages these globals end up on as read-only after it is
00124            /// done with its relocation phase.
00125            ReadOnlyWithRel,
00126 
00127                /// ReadOnlyWithRelLocal - This is data that is readonly by the
00128                /// program, but must be writeable so that the dynamic linker
00129                /// can perform relocations in it.  This is used when we know
00130                /// that all the relocations are to globals in this final
00131                /// linked image.
00132                ReadOnlyWithRelLocal
00133 
00134   } K : 8;
00135 public:
00136 
00137   bool isMetadata() const { return K == Metadata; }
00138   bool isText() const { return K == Text; }
00139 
00140   bool isReadOnly() const {
00141     return K == ReadOnly || isMergeableCString() ||
00142            isMergeableConst();
00143   }
00144 
00145   bool isMergeableCString() const {
00146     return K == Mergeable1ByteCString || K == Mergeable2ByteCString ||
00147            K == Mergeable4ByteCString;
00148   }
00149   bool isMergeable1ByteCString() const { return K == Mergeable1ByteCString; }
00150   bool isMergeable2ByteCString() const { return K == Mergeable2ByteCString; }
00151   bool isMergeable4ByteCString() const { return K == Mergeable4ByteCString; }
00152 
00153   bool isMergeableConst() const {
00154     return K == MergeableConst || K == MergeableConst4 ||
00155            K == MergeableConst8 || K == MergeableConst16;
00156   }
00157   bool isMergeableConst4() const { return K == MergeableConst4; }
00158   bool isMergeableConst8() const { return K == MergeableConst8; }
00159   bool isMergeableConst16() const { return K == MergeableConst16; }
00160 
00161   bool isWriteable() const {
00162     return isThreadLocal() || isGlobalWriteableData();
00163   }
00164 
00165   bool isThreadLocal() const {
00166     return K == ThreadData || K == ThreadBSS;
00167   }
00168 
00169   bool isThreadBSS() const { return K == ThreadBSS; }
00170   bool isThreadData() const { return K == ThreadData; }
00171 
00172   bool isGlobalWriteableData() const {
00173     return isBSS() || isCommon() || isDataRel() || isReadOnlyWithRel();
00174   }
00175 
00176   bool isBSS() const { return K == BSS || K == BSSLocal || K == BSSExtern; }
00177   bool isBSSLocal() const { return K == BSSLocal; }
00178   bool isBSSExtern() const { return K == BSSExtern; }
00179 
00180   bool isCommon() const { return K == Common; }
00181 
00182   bool isDataRel() const {
00183     return K == DataRel || K == DataRelLocal || K == DataNoRel;
00184   }
00185 
00186   bool isDataRelLocal() const {
00187     return K == DataRelLocal || K == DataNoRel;
00188   }
00189 
00190   bool isDataNoRel() const { return K == DataNoRel; }
00191 
00192   bool isReadOnlyWithRel() const {
00193     return K == ReadOnlyWithRel || K == ReadOnlyWithRelLocal;
00194   }
00195 
00196   bool isReadOnlyWithRelLocal() const {
00197     return K == ReadOnlyWithRelLocal;
00198   }
00199 private:
00200   static SectionKind get(Kind K) {
00201     SectionKind Res;
00202     Res.K = K;
00203     return Res;
00204   }
00205 public:
00206 
00207   static SectionKind getMetadata() { return get(Metadata); }
00208   static SectionKind getText() { return get(Text); }
00209   static SectionKind getReadOnly() { return get(ReadOnly); }
00210   static SectionKind getMergeable1ByteCString() {
00211     return get(Mergeable1ByteCString);
00212   }
00213   static SectionKind getMergeable2ByteCString() {
00214     return get(Mergeable2ByteCString);
00215   }
00216   static SectionKind getMergeable4ByteCString() {
00217     return get(Mergeable4ByteCString);
00218   }
00219   static SectionKind getMergeableConst() { return get(MergeableConst); }
00220   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
00221   static SectionKind getMergeableConst8() { return get(MergeableConst8); }
00222   static SectionKind getMergeableConst16() { return get(MergeableConst16); }
00223   static SectionKind getThreadBSS() { return get(ThreadBSS); }
00224   static SectionKind getThreadData() { return get(ThreadData); }
00225   static SectionKind getBSS() { return get(BSS); }
00226   static SectionKind getBSSLocal() { return get(BSSLocal); }
00227   static SectionKind getBSSExtern() { return get(BSSExtern); }
00228   static SectionKind getCommon() { return get(Common); }
00229   static SectionKind getDataRel() { return get(DataRel); }
00230   static SectionKind getDataRelLocal() { return get(DataRelLocal); }
00231   static SectionKind getDataNoRel() { return get(DataNoRel); }
00232   static SectionKind getReadOnlyWithRel() { return get(ReadOnlyWithRel); }
00233   static SectionKind getReadOnlyWithRelLocal(){
00234     return get(ReadOnlyWithRelLocal);
00235   }
00236 };
00237 
00238 } // end namespace llvm
00239 
00240 #endif