Delete dead code. NFC.
[oota-llvm.git] / include / llvm / MC / MCSection.h
1 //===- MCSection.h - Machine Code Sections ----------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the MCSection class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCSECTION_H
15 #define LLVM_MC_MCSECTION_H
16
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"
23
24 namespace llvm {
25 class MCAssembler;
26 class MCAsmInfo;
27 class MCContext;
28 class MCExpr;
29 class MCFragment;
30 class MCSection;
31 class MCSymbol;
32 class raw_ostream;
33
34 class MCSectionData {
35   friend class MCAsmLayout;
36   friend class MCSection;
37
38   MCSectionData(const MCSectionData &) = delete;
39   void operator=(const MCSectionData &) = delete;
40
41 public:
42   typedef iplist<MCFragment> FragmentListType;
43
44   typedef FragmentListType::const_iterator const_iterator;
45   typedef FragmentListType::iterator iterator;
46
47   typedef FragmentListType::const_reverse_iterator const_reverse_iterator;
48   typedef FragmentListType::reverse_iterator reverse_iterator;
49
50 private:
51   FragmentListType Fragments;
52   MCSection *Section;
53
54   /// \name Assembler Backend Data
55   /// @{
56   //
57   // FIXME: This could all be kept private to the assembler implementation.
58
59   /// Mapping from subsection number to insertion point for subsection numbers
60   /// below that number.
61   SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
62
63   /// @}
64
65 public:
66   explicit MCSectionData(MCSection &Section);
67
68   MCSection &getSection() const { return *Section; }
69
70   /// \name Fragment Access
71   /// @{
72
73   const FragmentListType &getFragmentList() const { return Fragments; }
74   FragmentListType &getFragmentList() { return Fragments; }
75
76   iterator begin();
77   const_iterator begin() const {
78     return const_cast<MCSectionData *>(this)->begin();
79   }
80
81   iterator end();
82   const_iterator end() const {
83     return const_cast<MCSectionData *>(this)->end();
84   }
85
86   reverse_iterator rbegin();
87   const_reverse_iterator rbegin() const {
88     return const_cast<MCSectionData *>(this)->rbegin();
89   }
90
91   reverse_iterator rend();
92   const_reverse_iterator rend() const {
93     return const_cast<MCSectionData *>(this)->rend();
94   }
95
96   void dump();
97
98   /// @}
99 };
100
101 /// Instances of this class represent a uniqued identifier for a section in the
102 /// current translation unit.  The MCContext class uniques and creates these.
103 class MCSection {
104 public:
105   enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO };
106
107   /// \brief Express the state of bundle locked groups while emitting code.
108   enum BundleLockStateType {
109     NotBundleLocked,
110     BundleLocked,
111     BundleLockedAlignToEnd
112   };
113
114 private:
115   MCSection(const MCSection &) = delete;
116   void operator=(const MCSection &) = delete;
117
118   MCSymbol *Begin;
119   MCSymbol *End = nullptr;
120   /// The alignment requirement of this section.
121   unsigned Alignment = 1;
122   /// The section index in the assemblers section list.
123   unsigned Ordinal = 0;
124   /// The index of this section in the layout order.
125   unsigned LayoutOrder;
126
127   /// \brief Keeping track of bundle-locked state.
128   BundleLockStateType BundleLockState = NotBundleLocked;
129
130   /// \brief Current nesting depth of bundle_lock directives.
131   unsigned BundleLockNestingDepth = 0;
132
133   /// \brief We've seen a bundle_lock directive but not its first instruction
134   /// yet.
135   bool BundleGroupBeforeFirstInst = false;
136
137   /// Whether this section has had instructions emitted into it.
138   unsigned HasInstructions : 1;
139
140   MCSectionData Data;
141
142 protected:
143   MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin);
144   SectionVariant Variant;
145   SectionKind Kind;
146
147 public:
148   virtual ~MCSection();
149
150   SectionKind getKind() const { return Kind; }
151
152   SectionVariant getVariant() const { return Variant; }
153
154   MCSymbol *getBeginSymbol() { return Begin; }
155   const MCSymbol *getBeginSymbol() const {
156     return const_cast<MCSection *>(this)->getBeginSymbol();
157   }
158   void setBeginSymbol(MCSymbol *Sym) {
159     assert(!Begin);
160     Begin = Sym;
161   }
162   MCSymbol *getEndSymbol(MCContext &Ctx);
163   bool hasEnded() const;
164
165   unsigned getAlignment() const { return Alignment; }
166   void setAlignment(unsigned Value) { Alignment = Value; }
167
168   unsigned getOrdinal() const { return Ordinal; }
169   void setOrdinal(unsigned Value) { Ordinal = Value; }
170
171   unsigned getLayoutOrder() const { return LayoutOrder; }
172   void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
173
174   BundleLockStateType getBundleLockState() const { return BundleLockState; }
175   void setBundleLockState(BundleLockStateType NewState);
176   bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
177
178   bool isBundleGroupBeforeFirstInst() const {
179     return BundleGroupBeforeFirstInst;
180   }
181   void setBundleGroupBeforeFirstInst(bool IsFirst) {
182     BundleGroupBeforeFirstInst = IsFirst;
183   }
184
185   bool hasInstructions() const { return HasInstructions; }
186   void setHasInstructions(bool Value) { HasInstructions = Value; }
187
188   MCSectionData &getSectionData() { return Data; }
189   const MCSectionData &getSectionData() const {
190     return const_cast<MCSection *>(this)->getSectionData();
191   }
192
193   MCSectionData::FragmentListType &getFragmentList();
194   const MCSectionData::FragmentListType &getFragmentList() const {
195     return const_cast<MCSection *>(this)->getFragmentList();
196   }
197
198   MCSectionData::iterator begin();
199   MCSectionData::const_iterator begin() const {
200     return const_cast<MCSection *>(this)->begin();
201   }
202
203   MCSectionData::iterator end();
204   MCSectionData::const_iterator end() const {
205     return const_cast<MCSection *>(this)->end();
206   }
207
208   MCSectionData::reverse_iterator rbegin();
209   MCSectionData::const_reverse_iterator rbegin() const {
210     return const_cast<MCSection *>(this)->rbegin();
211   }
212
213   MCSectionData::reverse_iterator rend();
214   MCSectionData::const_reverse_iterator rend() const {
215     return const_cast<MCSection *>(this)->rend();
216   }
217
218   MCSectionData::iterator getSubsectionInsertionPoint(unsigned Subsection);
219
220   virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
221                                     const MCExpr *Subsection) const = 0;
222
223   /// Return true if a .align directive should use "optimized nops" to fill
224   /// instead of 0s.
225   virtual bool UseCodeAlign() const = 0;
226
227   /// Check whether this section is "virtual", that is has no actual object
228   /// file contents.
229   virtual bool isVirtualSection() const = 0;
230 };
231
232 } // end namespace llvm
233
234 #endif