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