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"
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 explicit MCSectionData(MCSection &Section);
67 MCSection &getSection() const { return *Section; }
69 /// \name Fragment Access
72 const FragmentListType &getFragmentList() const { return Fragments; }
73 FragmentListType &getFragmentList() { return Fragments; }
76 const_iterator begin() const {
77 return const_cast<MCSectionData *>(this)->begin();
81 const_iterator end() const {
82 return const_cast<MCSectionData *>(this)->end();
85 reverse_iterator rbegin();
86 const_reverse_iterator rbegin() const {
87 return const_cast<MCSectionData *>(this)->rbegin();
90 reverse_iterator rend();
91 const_reverse_iterator rend() const {
92 return const_cast<MCSectionData *>(this)->rend();
99 iterator getSubsectionInsertionPoint(unsigned Subsection);
106 /// Instances of this class represent a uniqued identifier for a section in the
107 /// current translation unit. The MCContext class uniques and creates these.
110 enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
112 /// \brief Express the state of bundle locked groups while emitting code.
113 enum BundleLockStateType {
116 BundleLockedAlignToEnd
120 MCSection(const MCSection &) = delete;
121 void operator=(const MCSection &) = delete;
124 MCSymbol *End = nullptr;
125 /// The alignment requirement of this section.
126 unsigned Alignment = 1;
127 /// The section index in the assemblers section list.
128 unsigned Ordinal = 0;
129 /// The index of this section in the layout order.
130 unsigned LayoutOrder;
132 /// \brief Keeping track of bundle-locked state.
133 BundleLockStateType BundleLockState = NotBundleLocked;
135 /// \brief Current nesting depth of bundle_lock directives.
136 unsigned BundleLockNestingDepth = 0;
138 /// \brief We've seen a bundle_lock directive but not its first instruction
140 bool BundleGroupBeforeFirstInst = false;
142 /// Whether this section has had instructions emitted into it.
143 unsigned HasInstructions : 1;
148 MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin);
149 SectionVariant Variant;
153 virtual ~MCSection();
155 SectionKind getKind() const { return Kind; }
157 SectionVariant getVariant() const { return Variant; }
159 MCSymbol *getBeginSymbol() { return Begin; }
160 const MCSymbol *getBeginSymbol() const {
161 return const_cast<MCSection *>(this)->getBeginSymbol();
163 void setBeginSymbol(MCSymbol *Sym) {
167 MCSymbol *getEndSymbol(MCContext &Ctx);
168 bool hasEnded() const;
170 unsigned getAlignment() const { return Alignment; }
171 void setAlignment(unsigned Value) { Alignment = Value; }
173 unsigned getOrdinal() const { return Ordinal; }
174 void setOrdinal(unsigned Value) { Ordinal = Value; }
176 unsigned getLayoutOrder() const { return LayoutOrder; }
177 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
179 BundleLockStateType getBundleLockState() const { return BundleLockState; }
180 void setBundleLockState(BundleLockStateType NewState);
181 bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
183 bool isBundleGroupBeforeFirstInst() const {
184 return BundleGroupBeforeFirstInst;
186 void setBundleGroupBeforeFirstInst(bool IsFirst) {
187 BundleGroupBeforeFirstInst = IsFirst;
190 bool hasInstructions() const { return HasInstructions; }
191 void setHasInstructions(bool Value) { HasInstructions = Value; }
193 MCSectionData &getSectionData() { return Data; }
194 const MCSectionData &getSectionData() const {
195 return const_cast<MCSection *>(this)->getSectionData();
198 MCSectionData::FragmentListType &getFragmentList();
199 const MCSectionData::FragmentListType &getFragmentList() const {
200 return const_cast<MCSection *>(this)->getFragmentList();
203 MCSectionData::iterator begin();
204 MCSectionData::const_iterator begin() const {
205 return const_cast<MCSection *>(this)->begin();
208 MCSectionData::iterator end();
209 MCSectionData::const_iterator end() const {
210 return const_cast<MCSection *>(this)->end();
213 MCSectionData::reverse_iterator rbegin();
214 MCSectionData::const_reverse_iterator rbegin() const {
215 return const_cast<MCSection *>(this)->rbegin();
218 MCSectionData::reverse_iterator rend();
219 MCSectionData::const_reverse_iterator rend() const {
220 return const_cast<MCSection *>(this)->rend();
223 virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
224 const MCExpr *Subsection) const = 0;
226 /// Return true if a .align directive should use "optimized nops" to fill
228 virtual bool UseCodeAlign() const = 0;
230 /// Check whether this section is "virtual", that is has no actual object
232 virtual bool isVirtualSection() const = 0;
235 } // end namespace llvm