LLVM  8.0.0svn
MCSection.h
Go to the documentation of this file.
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/ilist.h"
19 #include "llvm/MC/MCFragment.h"
20 #include "llvm/MC/SectionKind.h"
21 #include <cassert>
22 #include <utility>
23 
24 namespace llvm {
25 
26 class MCAsmInfo;
27 class MCContext;
28 class MCExpr;
29 class MCSymbol;
30 class raw_ostream;
31 class Triple;
32 
33 template <> struct ilist_alloc_traits<MCFragment> {
34  static void deleteNode(MCFragment *V);
35 };
36 
37 /// Instances of this class represent a uniqued identifier for a section in the
38 /// current translation unit. The MCContext class uniques and creates these.
39 class MCSection {
40 public:
41  enum SectionVariant { SV_COFF = 0, SV_ELF, SV_MachO, SV_Wasm };
42 
43  /// Express the state of bundle locked groups while emitting code.
47  BundleLockedAlignToEnd
48  };
49 
51 
54 
57 
58 private:
59  MCSymbol *Begin;
60  MCSymbol *End = nullptr;
61  /// The alignment requirement of this section.
62  unsigned Alignment = 1;
63  /// The section index in the assemblers section list.
64  unsigned Ordinal = 0;
65  /// The index of this section in the layout order.
66  unsigned LayoutOrder;
67 
68  /// Keeping track of bundle-locked state.
69  BundleLockStateType BundleLockState = NotBundleLocked;
70 
71  /// Current nesting depth of bundle_lock directives.
72  unsigned BundleLockNestingDepth = 0;
73 
74  /// We've seen a bundle_lock directive but not its first instruction
75  /// yet.
76  bool BundleGroupBeforeFirstInst : 1;
77 
78  /// Whether this section has had instructions emitted into it.
79  bool HasInstructions : 1;
80 
81  /// Whether this section has had data emitted into it.
82  /// Right now this is only used by the ARM backend.
83  bool HasData : 1;
84 
85  bool IsRegistered : 1;
86 
87  MCDummyFragment DummyFragment;
88 
89  FragmentListType Fragments;
90 
91  /// Mapping from subsection number to insertion point for subsection numbers
92  /// below that number.
93  SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
94 
95 protected:
98 
100  ~MCSection();
101 
102 public:
103  MCSection(const MCSection &) = delete;
104  MCSection &operator=(const MCSection &) = delete;
105 
106  SectionKind getKind() const { return Kind; }
107 
108  SectionVariant getVariant() const { return Variant; }
109 
110  MCSymbol *getBeginSymbol() { return Begin; }
111  const MCSymbol *getBeginSymbol() const {
112  return const_cast<MCSection *>(this)->getBeginSymbol();
113  }
115  assert(!Begin);
116  Begin = Sym;
117  }
118  MCSymbol *getEndSymbol(MCContext &Ctx);
119  bool hasEnded() const;
120 
121  unsigned getAlignment() const { return Alignment; }
122  void setAlignment(unsigned Value) { Alignment = Value; }
123 
124  unsigned getOrdinal() const { return Ordinal; }
125  void setOrdinal(unsigned Value) { Ordinal = Value; }
126 
127  unsigned getLayoutOrder() const { return LayoutOrder; }
128  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
129 
130  BundleLockStateType getBundleLockState() const { return BundleLockState; }
131  void setBundleLockState(BundleLockStateType NewState);
132  bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
133 
135  return BundleGroupBeforeFirstInst;
136  }
137  void setBundleGroupBeforeFirstInst(bool IsFirst) {
138  BundleGroupBeforeFirstInst = IsFirst;
139  }
140 
141  bool hasInstructions() const { return HasInstructions; }
142  void setHasInstructions(bool Value) { HasInstructions = Value; }
143 
144  bool hasData() const { return HasData; }
145  void setHasData(bool Value) { HasData = Value; }
146 
147  bool isRegistered() const { return IsRegistered; }
148  void setIsRegistered(bool Value) { IsRegistered = Value; }
149 
152  return const_cast<MCSection *>(this)->getFragmentList();
153  }
154 
155  /// Support for MCFragment::getNextNode().
157  return &MCSection::Fragments;
158  }
159 
160  const MCDummyFragment &getDummyFragment() const { return DummyFragment; }
161  MCDummyFragment &getDummyFragment() { return DummyFragment; }
162 
163  iterator begin() { return Fragments.begin(); }
164  const_iterator begin() const { return Fragments.begin(); }
165 
166  iterator end() { return Fragments.end(); }
167  const_iterator end() const { return Fragments.end(); }
168 
169  reverse_iterator rbegin() { return Fragments.rbegin(); }
170  const_reverse_iterator rbegin() const { return Fragments.rbegin(); }
171 
172  reverse_iterator rend() { return Fragments.rend(); }
173  const_reverse_iterator rend() const { return Fragments.rend(); }
174 
175  MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection);
176 
177  void dump() const;
178 
179  virtual void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
180  raw_ostream &OS,
181  const MCExpr *Subsection) const = 0;
182 
183  /// Return true if a .align directive should use "optimized nops" to fill
184  /// instead of 0s.
185  virtual bool UseCodeAlign() const = 0;
186 
187  /// Check whether this section is "virtual", that is has no actual object
188  /// file contents.
189  virtual bool isVirtualSection() const = 0;
190 };
191 
192 } // end namespace llvm
193 
194 #endif // LLVM_MC_MCSECTION_H
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
SectionKind getKind() const
Definition: MCSection.h:106
bool hasInstructions() const
Definition: MCSection.h:141
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
const MCSymbol * getBeginSymbol() const
Definition: MCSection.h:111
void setLayoutOrder(unsigned Value)
Definition: MCSection.h:128
reverse_iterator rend()
Definition: MCSection.h:172
void setAlignment(unsigned Value)
Definition: MCSection.h:122
unsigned getOrdinal() const
Definition: MCSection.h:124
unsigned getAlignment() const
Definition: MCSection.h:121
BundleLockStateType
Express the state of bundle locked groups while emitting code.
Definition: MCSection.h:44
void setHasInstructions(bool Value)
Definition: MCSection.h:142
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Context object for machine code objects.
Definition: MCContext.h:63
reverse_iterator rbegin()
Definition: MCSection.h:169
BundleLockStateType getBundleLockState() const
Definition: MCSection.h:130
bool isBundleLocked() const
Definition: MCSection.h:132
void setHasData(bool Value)
Definition: MCSection.h:145
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Use delete by default for iplist and ilist.
Definition: ilist.h:41
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
bool isRegistered() const
Definition: MCSection.h:147
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
const_reverse_iterator rbegin() const
Definition: MCSection.h:170
void setIsRegistered(bool Value)
Definition: MCSection.h:148
SectionVariant getVariant() const
Definition: MCSection.h:108
SectionVariant Variant
Definition: MCSection.h:96
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool hasData() const
Definition: MCSection.h:144
void setOrdinal(unsigned Value)
Definition: MCSection.h:125
Iterator for intrusive lists based on ilist_node.
const MCDummyFragment & getDummyFragment() const
Definition: MCSection.h:160
const_reverse_iterator rend() const
Definition: MCSection.h:173
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
const MCSection::FragmentListType & getFragmentList() const
Definition: MCSection.h:151
MCSymbol * getBeginSymbol()
Definition: MCSection.h:110
const_iterator begin() const
Definition: MCSection.h:164
static void deleteNode(NodeTy *V)
Definition: ilist.h:42
static FragmentListType MCSection::* getSublistAccess(MCFragment *)
Support for MCFragment::getNextNode().
Definition: MCSection.h:156
const_iterator end() const
Definition: MCSection.h:167
bool isBundleGroupBeforeFirstInst() const
Definition: MCSection.h:134
void setBundleGroupBeforeFirstInst(bool IsFirst)
Definition: MCSection.h:137
unsigned getLayoutOrder() const
Definition: MCSection.h:127
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
MCDummyFragment & getDummyFragment()
Definition: MCSection.h:161
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
iterator end()
Definition: MCSection.h:166
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:150
SectionKind Kind
Definition: MCSection.h:97
iterator begin()
Definition: MCSection.h:163
void setBeginSymbol(MCSymbol *Sym)
Definition: MCSection.h:114