LLVM 20.0.0git
MCFragment.cpp
Go to the documentation of this file.
1//===- lib/MC/MCFragment.cpp - Assembler Fragment Implementation ----------===//
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
12#include "llvm/ADT/Twine.h"
13#include "llvm/Config/llvm-config.h"
14#include "llvm/MC/MCContext.h"
15#include "llvm/MC/MCFixup.h"
16#include "llvm/MC/MCSection.h"
18#include "llvm/MC/MCSymbol.h"
22#include <cassert>
23#include <utility>
24
25using namespace llvm;
26
27MCFragment::MCFragment(FragmentType Kind, bool HasInstructions)
28 : Kind(Kind), HasInstructions(HasInstructions), AlignToBundleEnd(false),
29 LinkerRelaxable(false), AllowAutoPadding(false) {}
30
32 switch (Kind) {
33 case FT_Align:
34 cast<MCAlignFragment>(this)->~MCAlignFragment();
35 return;
36 case FT_Data:
37 cast<MCDataFragment>(this)->~MCDataFragment();
38 return;
39 case FT_Fill:
40 cast<MCFillFragment>(this)->~MCFillFragment();
41 return;
42 case FT_Nops:
43 cast<MCNopsFragment>(this)->~MCNopsFragment();
44 return;
45 case FT_Relaxable:
46 cast<MCRelaxableFragment>(this)->~MCRelaxableFragment();
47 return;
48 case FT_Org:
49 cast<MCOrgFragment>(this)->~MCOrgFragment();
50 return;
51 case FT_Dwarf:
52 cast<MCDwarfLineAddrFragment>(this)->~MCDwarfLineAddrFragment();
53 return;
54 case FT_DwarfFrame:
55 cast<MCDwarfCallFrameFragment>(this)->~MCDwarfCallFrameFragment();
56 return;
57 case FT_LEB:
58 cast<MCLEBFragment>(this)->~MCLEBFragment();
59 return;
61 cast<MCBoundaryAlignFragment>(this)->~MCBoundaryAlignFragment();
62 return;
63 case FT_SymbolId:
64 cast<MCSymbolIdFragment>(this)->~MCSymbolIdFragment();
65 return;
67 cast<MCCVInlineLineTableFragment>(this)->~MCCVInlineLineTableFragment();
68 return;
69 case FT_CVDefRange:
70 cast<MCCVDefRangeFragment>(this)->~MCCVDefRangeFragment();
71 return;
72 case FT_PseudoProbe:
73 cast<MCPseudoProbeAddrFragment>(this)->~MCPseudoProbeAddrFragment();
74 return;
75 case FT_Dummy:
76 cast<MCDummyFragment>(this)->~MCDummyFragment();
77 return;
78 }
79}
80
82 return cast<MCSectionMachO>(Parent)->getAtom(LayoutOrder);
83}
84
85// Debugging methods
86
87namespace llvm {
88
90 OS << "<MCFixup" << " Offset:" << AF.getOffset()
91 << " Value:" << *AF.getValue()
92 << " Kind:" << AF.getKind() << ">";
93 return OS;
94}
95
96} // end namespace llvm
97
98#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
100 raw_ostream &OS = errs();
101
102 OS << "<";
103 switch (getKind()) {
104 case MCFragment::FT_Align: OS << "MCAlignFragment"; break;
105 case MCFragment::FT_Data: OS << "MCDataFragment"; break;
106 case MCFragment::FT_Fill: OS << "MCFillFragment"; break;
108 OS << "MCFNopsFragment";
109 break;
110 case MCFragment::FT_Relaxable: OS << "MCRelaxableFragment"; break;
111 case MCFragment::FT_Org: OS << "MCOrgFragment"; break;
112 case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break;
113 case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break;
114 case MCFragment::FT_LEB: OS << "MCLEBFragment"; break;
115 case MCFragment::FT_BoundaryAlign: OS<<"MCBoundaryAlignFragment"; break;
116 case MCFragment::FT_SymbolId: OS << "MCSymbolIdFragment"; break;
117 case MCFragment::FT_CVInlineLines: OS << "MCCVInlineLineTableFragment"; break;
118 case MCFragment::FT_CVDefRange: OS << "MCCVDefRangeTableFragment"; break;
120 OS << "MCPseudoProbe";
121 break;
122 case MCFragment::FT_Dummy: OS << "MCDummyFragment"; break;
123 }
124
125 OS << "<MCFragment " << (const void *)this << " LayoutOrder:" << LayoutOrder
126 << " Offset:" << Offset << " HasInstructions:" << hasInstructions();
127 if (const auto *EF = dyn_cast<MCEncodedFragment>(this))
128 OS << " BundlePadding:" << static_cast<unsigned>(EF->getBundlePadding());
129 OS << ">";
130
131 switch (getKind()) {
133 const auto *AF = cast<MCAlignFragment>(this);
134 if (AF->hasEmitNops())
135 OS << " (emit nops)";
136 OS << "\n ";
137 OS << " Alignment:" << AF->getAlignment().value()
138 << " Value:" << AF->getValue() << " ValueSize:" << AF->getValueSize()
139 << " MaxBytesToEmit:" << AF->getMaxBytesToEmit() << ">";
140 break;
141 }
142 case MCFragment::FT_Data: {
143 const auto *DF = cast<MCDataFragment>(this);
144 OS << "\n ";
145 OS << " Contents:[";
146 const SmallVectorImpl<char> &Contents = DF->getContents();
147 for (unsigned i = 0, e = Contents.size(); i != e; ++i) {
148 if (i) OS << ",";
149 OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
150 }
151 OS << "] (" << Contents.size() << " bytes)";
152
153 if (DF->fixup_begin() != DF->fixup_end()) {
154 OS << ",\n ";
155 OS << " Fixups:[";
156 for (MCDataFragment::const_fixup_iterator it = DF->fixup_begin(),
157 ie = DF->fixup_end(); it != ie; ++it) {
158 if (it != DF->fixup_begin()) OS << ",\n ";
159 OS << *it;
160 }
161 OS << "]";
162 }
163 break;
164 }
165 case MCFragment::FT_Fill: {
166 const auto *FF = cast<MCFillFragment>(this);
167 OS << " Value:" << static_cast<unsigned>(FF->getValue())
168 << " ValueSize:" << static_cast<unsigned>(FF->getValueSize())
169 << " NumValues:" << FF->getNumValues();
170 break;
171 }
172 case MCFragment::FT_Nops: {
173 const auto *NF = cast<MCNopsFragment>(this);
174 OS << " NumBytes:" << NF->getNumBytes()
175 << " ControlledNopLength:" << NF->getControlledNopLength();
176 break;
177 }
179 const auto *F = cast<MCRelaxableFragment>(this);
180 OS << "\n ";
181 OS << " Inst:";
182 F->getInst().dump_pretty(OS);
183 OS << " (" << F->getContents().size() << " bytes)";
184 break;
185 }
186 case MCFragment::FT_Org: {
187 const auto *OF = cast<MCOrgFragment>(this);
188 OS << "\n ";
189 OS << " Offset:" << OF->getOffset()
190 << " Value:" << static_cast<unsigned>(OF->getValue());
191 break;
192 }
194 const auto *OF = cast<MCDwarfLineAddrFragment>(this);
195 OS << "\n ";
196 OS << " AddrDelta:" << OF->getAddrDelta()
197 << " LineDelta:" << OF->getLineDelta();
198 break;
199 }
201 const auto *CF = cast<MCDwarfCallFrameFragment>(this);
202 OS << "\n ";
203 OS << " AddrDelta:" << CF->getAddrDelta();
204 break;
205 }
206 case MCFragment::FT_LEB: {
207 const auto *LF = cast<MCLEBFragment>(this);
208 OS << "\n ";
209 OS << " Value:" << LF->getValue() << " Signed:" << LF->isSigned();
210 break;
211 }
213 const auto *BF = cast<MCBoundaryAlignFragment>(this);
214 OS << "\n ";
215 OS << " BoundarySize:" << BF->getAlignment().value()
216 << " LastFragment:" << BF->getLastFragment()
217 << " Size:" << BF->getSize();
218 break;
219 }
221 const auto *F = cast<MCSymbolIdFragment>(this);
222 OS << "\n ";
223 OS << " Sym:" << F->getSymbol();
224 break;
225 }
227 const auto *F = cast<MCCVInlineLineTableFragment>(this);
228 OS << "\n ";
229 OS << " Sym:" << *F->getFnStartSym();
230 break;
231 }
233 const auto *F = cast<MCCVDefRangeFragment>(this);
234 OS << "\n ";
235 for (std::pair<const MCSymbol *, const MCSymbol *> RangeStartEnd :
236 F->getRanges()) {
237 OS << " RangeStart:" << RangeStartEnd.first;
238 OS << " RangeEnd:" << RangeStartEnd.second;
239 }
240 break;
241 }
243 const auto *OF = cast<MCPseudoProbeAddrFragment>(this);
244 OS << "\n ";
245 OS << " AddrDelta:" << OF->getAddrDelta();
246 break;
247 }
249 break;
250 }
251 OS << ">";
252}
253#endif
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:622
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
#define F(x, y, z)
Definition: MD5.cpp:55
raw_pwrite_stream & OS
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
SmallVectorImpl< MCFixup >::const_iterator const_fixup_iterator
Definition: MCFragment.h:194
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
const MCExpr * getValue() const
Definition: MCFixup.h:105
uint32_t getOffset() const
Definition: MCFixup.h:102
MCFixupKind getKind() const
Definition: MCFixup.h:98
FragmentType getKind() const
Definition: MCFragment.h:97
MCFragment()=delete
const MCSymbol * getAtom() const
Definition: MCFragment.cpp:81
void destroy()
Destroys the current fragment.
Definition: MCFragment.cpp:31
void dump() const
Definition: MCFragment.cpp:99
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
Definition: MCFragment.h:109
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
size_t size() const
Definition: SmallVector.h:78
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:573
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:303