1 //===- MCSection.h - Machine Code Sections ----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the MCSection class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MC_MCSECTION_H
15 #define LLVM_MC_MCSECTION_H
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/ilist.h"
20 #include "llvm/ADT/ilist_node.h"
21 #include "llvm/MC/SectionKind.h"
22 #include "llvm/Support/Compiler.h"
34 class MCSectionData : public ilist_node<MCSectionData> {
35 friend class MCAsmLayout;
37 MCSectionData(const MCSectionData &) = delete;
38 void operator=(const MCSectionData &) = delete;
41 typedef iplist<MCFragment> FragmentListType;
43 typedef FragmentListType::const_iterator const_iterator;
44 typedef FragmentListType::iterator iterator;
46 typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
47 typedef FragmentListType::reverse_iterator reverse_iterator;
50 FragmentListType Fragments;
53 /// \name Assembler Backend Data
56 // FIXME: This could all be kept private to the assembler implementation.
58 /// Mapping from subsection number to insertion point for subsection numbers
59 /// below that number.
60 SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
65 // Only for use as sentinel.
67 MCSectionData(MCSection &Section);
69 MCSection &getSection() const { return *Section; }
71 /// \name Fragment Access
74 const FragmentListType &getFragmentList() const { return Fragments; }
75 FragmentListType &getFragmentList() { return Fragments; }
78 const_iterator begin() const {
79 return const_cast<MCSectionData *>(this)->begin();
83 const_iterator end() const {
84 return const_cast<MCSectionData *>(this)->end();
87 reverse_iterator rbegin();
88 const_reverse_iterator rbegin() const {
89 return const_cast<MCSectionData *>(this)->rbegin();
92 reverse_iterator rend();
93 const_reverse_iterator rend() const {
94 return const_cast<MCSectionData *>(this)->rend();
101 iterator getSubsectionInsertionPoint(unsigned Subsection);
108 /// Instances of this class represent a uniqued identifier for a section in the
109 /// current translation unit. The MCContext class uniques and creates these.
112 enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
114 /// \brief Express the state of bundle locked groups while emitting code.
115 enum BundleLockStateType {
118 BundleLockedAlignToEnd
122 MCSection(const MCSection &) = delete;
123 void operator=(const MCSection &) = delete;
126 MCSymbol *End = nullptr;
127 /// The alignment requirement of this section.
128 unsigned Alignment = 1;
129 /// The section index in the assemblers section list.
130 unsigned Ordinal = 0;
131 /// The index of this section in the layout order.
132 unsigned LayoutOrder;
134 /// \brief Keeping track of bundle-locked state.
135 BundleLockStateType BundleLockState = NotBundleLocked;
137 /// \brief Current nesting depth of bundle_lock directives.
138 unsigned BundleLockNestingDepth = 0;
140 /// \brief We've seen a bundle_lock directive but not its first instruction
142 bool BundleGroupBeforeFirstInst = false;
144 /// Whether this section has had instructions emitted into it.
145 unsigned HasInstructions : 1;
148 MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
149 : Begin(Begin), HasInstructions(false), Variant(V), Kind(K) {}
150 SectionVariant Variant;
154 virtual ~MCSection();
156 SectionKind getKind() const { return Kind; }
158 SectionVariant getVariant() const { return Variant; }
160 MCSymbol *getBeginSymbol() { return Begin; }
161 const MCSymbol *getBeginSymbol() const {
162 return const_cast<MCSection *>(this)->getBeginSymbol();
164 void setBeginSymbol(MCSymbol *Sym) {
168 MCSymbol *getEndSymbol(MCContext &Ctx);
169 bool hasEnded() const;
171 unsigned getAlignment() const { return Alignment; }
172 void setAlignment(unsigned Value) { Alignment = Value; }
174 unsigned getOrdinal() const { return Ordinal; }
175 void setOrdinal(unsigned Value) { Ordinal = Value; }
177 unsigned getLayoutOrder() const { return LayoutOrder; }
178 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
180 BundleLockStateType getBundleLockState() const { return BundleLockState; }
181 void setBundleLockState(BundleLockStateType NewState);
182 bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
184 bool isBundleGroupBeforeFirstInst() const {
185 return BundleGroupBeforeFirstInst;
187 void setBundleGroupBeforeFirstInst(bool IsFirst) {
188 BundleGroupBeforeFirstInst = IsFirst;
191 bool hasInstructions() const { return HasInstructions; }
192 void setHasInstructions(bool Value) { HasInstructions = Value; }
194 virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
195 const MCExpr *Subsection) const = 0;
197 /// Return true if a .align directive should use "optimized nops" to fill
199 virtual bool UseCodeAlign() const = 0;
201 /// Check whether this section is "virtual", that is has no actual object
203 virtual bool isVirtualSection() const = 0;
206 } // end namespace llvm