LLVM 19.0.0git
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
17#include "llvm/ADT/ilist.h"
18#include "llvm/MC/MCFragment.h"
19#include "llvm/MC/SectionKind.h"
21#include <cassert>
22#include <utility>
23
24namespace llvm {
25
26class MCAsmInfo;
27class MCContext;
28class MCExpr;
29class MCSymbol;
30class raw_ostream;
31class Triple;
32
33template <> 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.
39class MCSection {
40public:
41 static constexpr unsigned NonUniqueID = ~0U;
42
52 };
53
54 /// Express the state of bundle locked groups while emitting code.
59 };
60
62
65
68
69private:
70 MCSymbol *Begin;
71 MCSymbol *End = nullptr;
72 /// The alignment requirement of this section.
73 Align Alignment;
74 /// The section index in the assemblers section list.
75 unsigned Ordinal = 0;
76 /// The index of this section in the layout order.
77 unsigned LayoutOrder = 0;
78
79 /// Keeping track of bundle-locked state.
80 BundleLockStateType BundleLockState = NotBundleLocked;
81
82 /// Current nesting depth of bundle_lock directives.
83 unsigned BundleLockNestingDepth = 0;
84
85 /// We've seen a bundle_lock directive but not its first instruction
86 /// yet.
87 bool BundleGroupBeforeFirstInst : 1;
88
89 /// Whether this section has had instructions emitted into it.
90 bool HasInstructions : 1;
91
92 bool IsRegistered : 1;
93
94 MCDummyFragment DummyFragment;
95
96 FragmentListType Fragments;
97
98 /// Mapping from subsection number to insertion point for subsection numbers
99 /// below that number.
100 SmallVector<std::pair<unsigned, MCFragment *>, 1> SubsectionFragmentMap;
101
102 /// State for tracking labels that don't yet have Fragments
103 struct PendingLabel {
104 MCSymbol* Sym;
105 unsigned Subsection;
106 PendingLabel(MCSymbol* Sym, unsigned Subsection = 0)
107 : Sym(Sym), Subsection(Subsection) {}
108 };
109 SmallVector<PendingLabel, 2> PendingLabels;
110
111protected:
112 // TODO Make Name private when possible.
116
119
120public:
121 MCSection(const MCSection &) = delete;
122 MCSection &operator=(const MCSection &) = delete;
123
124 StringRef getName() const { return Name; }
125 SectionKind getKind() const { return Kind; }
126
128
129 MCSymbol *getBeginSymbol() { return Begin; }
130 const MCSymbol *getBeginSymbol() const {
131 return const_cast<MCSection *>(this)->getBeginSymbol();
132 }
134 assert(!Begin);
135 Begin = Sym;
136 }
138 bool hasEnded() const;
139
140 Align getAlign() const { return Alignment; }
141 void setAlignment(Align Value) { Alignment = Value; }
142
143 /// Makes sure that Alignment is at least MinAlignment.
144 void ensureMinAlignment(Align MinAlignment) {
145 if (Alignment < MinAlignment)
146 Alignment = MinAlignment;
147 }
148
149 unsigned getOrdinal() const { return Ordinal; }
150 void setOrdinal(unsigned Value) { Ordinal = Value; }
151
152 unsigned getLayoutOrder() const { return LayoutOrder; }
153 void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
154
155 BundleLockStateType getBundleLockState() const { return BundleLockState; }
157 bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
158
160 return BundleGroupBeforeFirstInst;
161 }
162 void setBundleGroupBeforeFirstInst(bool IsFirst) {
163 BundleGroupBeforeFirstInst = IsFirst;
164 }
165
166 bool hasInstructions() const { return HasInstructions; }
167 void setHasInstructions(bool Value) { HasInstructions = Value; }
168
169 bool isRegistered() const { return IsRegistered; }
170 void setIsRegistered(bool Value) { IsRegistered = Value; }
171
174 return const_cast<MCSection *>(this)->getFragmentList();
175 }
176
177 /// Support for MCFragment::getNextNode().
179 return &MCSection::Fragments;
180 }
181
182 const MCDummyFragment &getDummyFragment() const { return DummyFragment; }
183 MCDummyFragment &getDummyFragment() { return DummyFragment; }
184
185 iterator begin() { return Fragments.begin(); }
186 const_iterator begin() const { return Fragments.begin(); }
187
188 iterator end() { return Fragments.end(); }
189 const_iterator end() const { return Fragments.end(); }
190
192
193 void dump() const;
194
195 virtual void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
197 const MCExpr *Subsection) const = 0;
198
199 /// Return true if a .align directive should use "optimized nops" to fill
200 /// instead of 0s.
201 virtual bool useCodeAlign() const = 0;
202
203 /// Check whether this section is "virtual", that is has no actual object
204 /// file contents.
205 virtual bool isVirtualSection() const = 0;
206
207 virtual StringRef getVirtualSectionKind() const;
208
209 /// Add a pending label for the requested subsection. This label will be
210 /// associated with a fragment in flushPendingLabels()
211 void addPendingLabel(MCSymbol* label, unsigned Subsection = 0);
212
213 /// Associate all pending labels in a subsection with a fragment.
214 void flushPendingLabels(MCFragment *F, uint64_t FOffset = 0,
215 unsigned Subsection = 0);
216
217 /// Associate all pending labels with empty data fragments. One fragment
218 /// will be created for each subsection as necessary.
219 void flushPendingLabels();
220};
221
222} // end namespace llvm
223
224#endif // LLVM_MC_MCSECTION_H
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
This file defines the SmallVector class.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
Context object for machine code objects.
Definition: MCContext.h:76
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
void setAlignment(Align Value)
Definition: MCSection.h:141
void addPendingLabel(MCSymbol *label, unsigned Subsection=0)
Add a pending label for the requested subsection.
Definition: MCSection.cpp:91
const MCDummyFragment & getDummyFragment() const
Definition: MCSection.h:182
unsigned getOrdinal() const
Definition: MCSection.h:149
const_iterator end() const
Definition: MCSection.h:189
void setLayoutOrder(unsigned Value)
Definition: MCSection.h:153
virtual StringRef getVirtualSectionKind() const
Definition: MCSection.cpp:89
void ensureMinAlignment(Align MinAlignment)
Makes sure that Alignment is at least MinAlignment.
Definition: MCSection.h:144
void dump() const
Definition: MCSection.cpp:128
unsigned getLayoutOrder() const
Definition: MCSection.h:152
FragmentListType::reverse_iterator reverse_iterator
Definition: MCSection.h:67
static FragmentListType MCSection::* getSublistAccess(MCFragment *)
Support for MCFragment::getNextNode().
Definition: MCSection.h:178
void flushPendingLabels()
Associate all pending labels with empty data fragments.
Definition: MCSection.cpp:109
SectionVariant getVariant() const
Definition: MCSection.h:127
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:172
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:29
Align getAlign() const
Definition: MCSection.h:140
SectionVariant Variant
Definition: MCSection.h:114
const MCSection::FragmentListType & getFragmentList() const
Definition: MCSection.h:173
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:39
static constexpr unsigned NonUniqueID
Definition: MCSection.h:41
const MCSymbol * getBeginSymbol() const
Definition: MCSection.h:130
bool hasInstructions() const
Definition: MCSection.h:166
bool isRegistered() const
Definition: MCSection.h:169
void setHasInstructions(bool Value)
Definition: MCSection.h:167
FragmentListType::const_reverse_iterator const_reverse_iterator
Definition: MCSection.h:66
void setBeginSymbol(MCSymbol *Sym)
Definition: MCSection.h:133
MCSection(const MCSection &)=delete
iterator end()
Definition: MCSection.h:188
FragmentListType::const_iterator const_iterator
Definition: MCSection.h:63
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
bool isBundleGroupBeforeFirstInst() const
Definition: MCSection.h:159
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
Definition: MCSection.cpp:59
void setOrdinal(unsigned Value)
Definition: MCSection.h:150
SectionKind getKind() const
Definition: MCSection.h:125
StringRef Name
Definition: MCSection.h:113
virtual bool useCodeAlign() const =0
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
bool isBundleLocked() const
Definition: MCSection.h:157
MCDummyFragment & getDummyFragment()
Definition: MCSection.h:183
MCSection & operator=(const MCSection &)=delete
StringRef getName() const
Definition: MCSection.h:124
bool hasEnded() const
Definition: MCSection.cpp:35
BundleLockStateType
Express the state of bundle locked groups while emitting code.
Definition: MCSection.h:55
@ BundleLockedAlignToEnd
Definition: MCSection.h:58
MCSymbol * getBeginSymbol()
Definition: MCSection.h:129
BundleLockStateType getBundleLockState() const
Definition: MCSection.h:155
const_iterator begin() const
Definition: MCSection.h:186
virtual void printSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const =0
FragmentListType::iterator iterator
Definition: MCSection.h:64
SectionKind Kind
Definition: MCSection.h:115
void setBundleGroupBeforeFirstInst(bool IsFirst)
Definition: MCSection.h:162
void setIsRegistered(bool Value)
Definition: MCSection.h:170
iterator begin()
Definition: MCSection.h:185
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
LLVM Value Representation.
Definition: Value.h:74
base_list_type::const_reverse_iterator const_reverse_iterator
Definition: ilist.h:125
base_list_type::reverse_iterator reverse_iterator
Definition: ilist.h:123
base_list_type::const_iterator const_iterator
Definition: ilist.h:122
base_list_type::iterator iterator
Definition: ilist.h:121
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This file defines classes to implement an intrusive doubly linked list class (i.e.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Use delete by default for iplist and ilist.
Definition: ilist.h:41
static void deleteNode(NodeTy *V)
Definition: ilist.h:42