X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FMC%2FMCSection.h;h=08af5334bc1972cc55ae5ecb381a2c07dac0f122;hb=6426aea54e5be9ceb0dd981db8459857785a2e61;hp=b741216f94a4a265d774ef1a483c4aae96a24606;hpb=60cb528246dd01b80b1b1260a2a877ea488e620a;p=oota-llvm.git diff --git a/include/llvm/MC/MCSection.h b/include/llvm/MC/MCSection.h index b741216f94a..08af5334bc1 100644 --- a/include/llvm/MC/MCSection.h +++ b/include/llvm/MC/MCSection.h @@ -14,59 +14,190 @@ #ifndef LLVM_MC_MCSECTION_H #define LLVM_MC_MCSECTION_H -#include +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/ilist.h" +#include "llvm/ADT/ilist_node.h" +#include "llvm/MC/MCAssembler.h" #include "llvm/MC/SectionKind.h" -#include "llvm/Support/Casting.h" +#include "llvm/Support/Compiler.h" namespace llvm { - class MCContext; - class MCAsmInfo; - class raw_ostream; - - /// MCSection - Instances of this class represent a uniqued identifier for a - /// section in the current translation unit. The MCContext class uniques and - /// creates these. - class MCSection { - public: - enum SectionVariant { - SV_COFF = 0, - SV_ELF, - SV_MachO - }; - - private: - MCSection(const MCSection&); // DO NOT IMPLEMENT - void operator=(const MCSection&); // DO NOT IMPLEMENT - protected: - MCSection(SectionVariant V, SectionKind K) : Variant(V), Kind(K) {} - SectionVariant Variant; - SectionKind Kind; - public: - virtual ~MCSection(); - - SectionKind getKind() const { return Kind; } - - SectionVariant getVariant() const { return Variant; } - - virtual void PrintSwitchToSection(const MCAsmInfo &MAI, - raw_ostream &OS) const = 0; - - /// isBaseAddressKnownZero - Return true if we know that this section will - /// get a base address of zero. In cases where we know that this is true we - /// can emit section offsets as direct references to avoid a subtraction - /// from the base of the section, saving a relocation. - virtual bool isBaseAddressKnownZero() const { - return false; - } - - // UseCodeAlign - Return true if a .align directive should use - // "optimized nops" to fill instead of 0s. - virtual bool UseCodeAlign() const = 0; - - static bool classof(const MCSection *) { return true; } +class MCAssembler; +class MCAsmInfo; +class MCContext; +class MCExpr; +class MCFragment; +class MCSection; +class MCSymbol; +class raw_ostream; + +template<> +struct ilist_node_traits { + MCFragment *createNode(const MCFragment &V); + static void deleteNode(MCFragment *V); + + void addNodeToList(MCFragment *) {} + void removeNodeFromList(MCFragment *) {} + void transferNodesFromList(ilist_node_traits & /*SrcTraits*/, + ilist_iterator /*first*/, + ilist_iterator /*last*/) {} +}; + +/// Instances of this class represent a uniqued identifier for a section in the +/// current translation unit. The MCContext class uniques and creates these. +class MCSection { +public: + enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO }; + + /// \brief Express the state of bundle locked groups while emitting code. + enum BundleLockStateType { + NotBundleLocked, + BundleLocked, + BundleLockedAlignToEnd }; + typedef iplist FragmentListType; + + typedef FragmentListType::const_iterator const_iterator; + typedef FragmentListType::iterator iterator; + + typedef FragmentListType::const_reverse_iterator const_reverse_iterator; + typedef FragmentListType::reverse_iterator reverse_iterator; + +private: + MCSection(const MCSection &) = delete; + void operator=(const MCSection &) = delete; + + MCSymbol *Begin; + MCSymbol *End = nullptr; + /// The alignment requirement of this section. + unsigned Alignment = 1; + /// The section index in the assemblers section list. + unsigned Ordinal = 0; + /// The index of this section in the layout order. + unsigned LayoutOrder; + + /// \brief Keeping track of bundle-locked state. + BundleLockStateType BundleLockState = NotBundleLocked; + + /// \brief Current nesting depth of bundle_lock directives. + unsigned BundleLockNestingDepth = 0; + + /// \brief We've seen a bundle_lock directive but not its first instruction + /// yet. + unsigned BundleGroupBeforeFirstInst : 1; + + /// Whether this section has had instructions emitted into it. + unsigned HasInstructions : 1; + + unsigned IsRegistered : 1; + + MCDummyFragment DummyFragment; + + FragmentListType Fragments; + + /// Mapping from subsection number to insertion point for subsection numbers + /// below that number. + SmallVector, 1> SubsectionFragmentMap; + +protected: + MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin); + SectionVariant Variant; + SectionKind Kind; + ~MCSection(); + +public: + SectionKind getKind() const { return Kind; } + + SectionVariant getVariant() const { return Variant; } + + MCSymbol *getBeginSymbol() { return Begin; } + const MCSymbol *getBeginSymbol() const { + return const_cast(this)->getBeginSymbol(); + } + void setBeginSymbol(MCSymbol *Sym) { + assert(!Begin); + Begin = Sym; + } + MCSymbol *getEndSymbol(MCContext &Ctx); + bool hasEnded() const; + + unsigned getAlignment() const { return Alignment; } + void setAlignment(unsigned Value) { Alignment = Value; } + + unsigned getOrdinal() const { return Ordinal; } + void setOrdinal(unsigned Value) { Ordinal = Value; } + + unsigned getLayoutOrder() const { return LayoutOrder; } + void setLayoutOrder(unsigned Value) { LayoutOrder = Value; } + + BundleLockStateType getBundleLockState() const { return BundleLockState; } + void setBundleLockState(BundleLockStateType NewState); + bool isBundleLocked() const { return BundleLockState != NotBundleLocked; } + + bool isBundleGroupBeforeFirstInst() const { + return BundleGroupBeforeFirstInst; + } + void setBundleGroupBeforeFirstInst(bool IsFirst) { + BundleGroupBeforeFirstInst = IsFirst; + } + + bool hasInstructions() const { return HasInstructions; } + void setHasInstructions(bool Value) { HasInstructions = Value; } + + bool isRegistered() const { return IsRegistered; } + void setIsRegistered(bool Value) { IsRegistered = Value; } + + MCSection::FragmentListType &getFragmentList() { return Fragments; } + const MCSection::FragmentListType &getFragmentList() const { + return const_cast(this)->getFragmentList(); + } + + /// Support for MCFragment::getNextNode(). + static FragmentListType MCSection::*getSublistAccess(MCFragment *) { + return &MCSection::Fragments; + } + + const MCDummyFragment &getDummyFragment() const { return DummyFragment; } + MCDummyFragment &getDummyFragment() { return DummyFragment; } + + MCSection::iterator begin(); + MCSection::const_iterator begin() const { + return const_cast(this)->begin(); + } + + MCSection::iterator end(); + MCSection::const_iterator end() const { + return const_cast(this)->end(); + } + + MCSection::reverse_iterator rbegin(); + MCSection::const_reverse_iterator rbegin() const { + return const_cast(this)->rbegin(); + } + + MCSection::reverse_iterator rend(); + MCSection::const_reverse_iterator rend() const { + return const_cast(this)->rend(); + } + + MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection); + + void dump(); + + virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, + const MCExpr *Subsection) const = 0; + + /// Return true if a .align directive should use "optimized nops" to fill + /// instead of 0s. + virtual bool UseCodeAlign() const = 0; + + /// Check whether this section is "virtual", that is has no actual object + /// file contents. + virtual bool isVirtualSection() const = 0; +}; + } // end namespace llvm #endif