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"
23#include <cassert>
24#include <cstdint>
25#include <utility>
26
27using namespace llvm;
28
29MCFragment::MCFragment(FragmentType Kind, bool HasInstructions)
30 : Kind(Kind), HasInstructions(HasInstructions), AlignToBundleEnd(false),
31 LinkerRelaxable(false), AllowAutoPadding(false) {}
32
34 switch (Kind) {
35 case FT_Align:
36 cast<MCAlignFragment>(this)->~MCAlignFragment();
37 return;
38 case FT_Data:
39 cast<MCDataFragment>(this)->~MCDataFragment();
40 return;
41 case FT_Fill:
42 cast<MCFillFragment>(this)->~MCFillFragment();
43 return;
44 case FT_Nops:
45 cast<MCNopsFragment>(this)->~MCNopsFragment();
46 return;
47 case FT_Relaxable:
48 cast<MCRelaxableFragment>(this)->~MCRelaxableFragment();
49 return;
50 case FT_Org:
51 cast<MCOrgFragment>(this)->~MCOrgFragment();
52 return;
53 case FT_Dwarf:
54 cast<MCDwarfLineAddrFragment>(this)->~MCDwarfLineAddrFragment();
55 return;
56 case FT_DwarfFrame:
57 cast<MCDwarfCallFrameFragment>(this)->~MCDwarfCallFrameFragment();
58 return;
59 case FT_LEB:
60 cast<MCLEBFragment>(this)->~MCLEBFragment();
61 return;
63 cast<MCBoundaryAlignFragment>(this)->~MCBoundaryAlignFragment();
64 return;
65 case FT_SymbolId:
66 cast<MCSymbolIdFragment>(this)->~MCSymbolIdFragment();
67 return;
69 cast<MCCVInlineLineTableFragment>(this)->~MCCVInlineLineTableFragment();
70 return;
71 case FT_CVDefRange:
72 cast<MCCVDefRangeFragment>(this)->~MCCVDefRangeFragment();
73 return;
74 case FT_PseudoProbe:
75 cast<MCPseudoProbeAddrFragment>(this)->~MCPseudoProbeAddrFragment();
76 return;
77 case FT_Dummy:
78 cast<MCDummyFragment>(this)->~MCDummyFragment();
79 return;
80 }
81}
82
84 return cast<MCSectionMachO>(Parent)->getAtom(LayoutOrder);
85}
86
87// Debugging methods
88
89namespace llvm {
90
92 OS << "<MCFixup" << " Offset:" << AF.getOffset()
93 << " Value:" << *AF.getValue()
94 << " Kind:" << AF.getKind() << ">";
95 return OS;
96}
97
98} // end namespace llvm
99
100#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
102 raw_ostream &OS = errs();
103
104 OS << "<";
105 switch (getKind()) {
106 case MCFragment::FT_Align: OS << "MCAlignFragment"; break;
107 case MCFragment::FT_Data: OS << "MCDataFragment"; break;
108 case MCFragment::FT_Fill: OS << "MCFillFragment"; break;
110 OS << "MCFNopsFragment";
111 break;
112 case MCFragment::FT_Relaxable: OS << "MCRelaxableFragment"; break;
113 case MCFragment::FT_Org: OS << "MCOrgFragment"; break;
114 case MCFragment::FT_Dwarf: OS << "MCDwarfFragment"; break;
115 case MCFragment::FT_DwarfFrame: OS << "MCDwarfCallFrameFragment"; break;
116 case MCFragment::FT_LEB: OS << "MCLEBFragment"; break;
117 case MCFragment::FT_BoundaryAlign: OS<<"MCBoundaryAlignFragment"; break;
118 case MCFragment::FT_SymbolId: OS << "MCSymbolIdFragment"; break;
119 case MCFragment::FT_CVInlineLines: OS << "MCCVInlineLineTableFragment"; break;
120 case MCFragment::FT_CVDefRange: OS << "MCCVDefRangeTableFragment"; break;
122 OS << "MCPseudoProbe";
123 break;
124 case MCFragment::FT_Dummy: OS << "MCDummyFragment"; break;
125 }
126
127 OS << "<MCFragment " << (const void *)this << " LayoutOrder:" << LayoutOrder
128 << " Offset:" << Offset << " HasInstructions:" << hasInstructions();
129 if (const auto *EF = dyn_cast<MCEncodedFragment>(this))
130 OS << " BundlePadding:" << static_cast<unsigned>(EF->getBundlePadding());
131 OS << ">";
132
133 switch (getKind()) {
135 const auto *AF = cast<MCAlignFragment>(this);
136 if (AF->hasEmitNops())
137 OS << " (emit nops)";
138 OS << "\n ";
139 OS << " Alignment:" << AF->getAlignment().value()
140 << " Value:" << AF->getValue() << " ValueSize:" << AF->getValueSize()
141 << " MaxBytesToEmit:" << AF->getMaxBytesToEmit() << ">";
142 break;
143 }
144 case MCFragment::FT_Data: {
145 const auto *DF = cast<MCDataFragment>(this);
146 OS << "\n ";
147 OS << " Contents:[";
148 const SmallVectorImpl<char> &Contents = DF->getContents();
149 for (unsigned i = 0, e = Contents.size(); i != e; ++i) {
150 if (i) OS << ",";
151 OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
152 }
153 OS << "] (" << Contents.size() << " bytes)";
154
155 if (DF->fixup_begin() != DF->fixup_end()) {
156 OS << ",\n ";
157 OS << " Fixups:[";
158 for (MCDataFragment::const_fixup_iterator it = DF->fixup_begin(),
159 ie = DF->fixup_end(); it != ie; ++it) {
160 if (it != DF->fixup_begin()) OS << ",\n ";
161 OS << *it;
162 }
163 OS << "]";
164 }
165 break;
166 }
167 case MCFragment::FT_Fill: {
168 const auto *FF = cast<MCFillFragment>(this);
169 OS << " Value:" << static_cast<unsigned>(FF->getValue())
170 << " ValueSize:" << static_cast<unsigned>(FF->getValueSize())
171 << " NumValues:" << FF->getNumValues();
172 break;
173 }
174 case MCFragment::FT_Nops: {
175 const auto *NF = cast<MCNopsFragment>(this);
176 OS << " NumBytes:" << NF->getNumBytes()
177 << " ControlledNopLength:" << NF->getControlledNopLength();
178 break;
179 }
181 const auto *F = cast<MCRelaxableFragment>(this);
182 OS << "\n ";
183 OS << " Inst:";
184 F->getInst().dump_pretty(OS);
185 OS << " (" << F->getContents().size() << " bytes)";
186 break;
187 }
188 case MCFragment::FT_Org: {
189 const auto *OF = cast<MCOrgFragment>(this);
190 OS << "\n ";
191 OS << " Offset:" << OF->getOffset()
192 << " Value:" << static_cast<unsigned>(OF->getValue());
193 break;
194 }
196 const auto *OF = cast<MCDwarfLineAddrFragment>(this);
197 OS << "\n ";
198 OS << " AddrDelta:" << OF->getAddrDelta()
199 << " LineDelta:" << OF->getLineDelta();
200 break;
201 }
203 const auto *CF = cast<MCDwarfCallFrameFragment>(this);
204 OS << "\n ";
205 OS << " AddrDelta:" << CF->getAddrDelta();
206 break;
207 }
208 case MCFragment::FT_LEB: {
209 const auto *LF = cast<MCLEBFragment>(this);
210 OS << "\n ";
211 OS << " Value:" << LF->getValue() << " Signed:" << LF->isSigned();
212 break;
213 }
215 const auto *BF = cast<MCBoundaryAlignFragment>(this);
216 OS << "\n ";
217 OS << " BoundarySize:" << BF->getAlignment().value()
218 << " LastFragment:" << BF->getLastFragment()
219 << " Size:" << BF->getSize();
220 break;
221 }
223 const auto *F = cast<MCSymbolIdFragment>(this);
224 OS << "\n ";
225 OS << " Sym:" << F->getSymbol();
226 break;
227 }
229 const auto *F = cast<MCCVInlineLineTableFragment>(this);
230 OS << "\n ";
231 OS << " Sym:" << *F->getFnStartSym();
232 break;
233 }
235 const auto *F = cast<MCCVDefRangeFragment>(this);
236 OS << "\n ";
237 for (std::pair<const MCSymbol *, const MCSymbol *> RangeStartEnd :
238 F->getRanges()) {
239 OS << " RangeStart:" << RangeStartEnd.first;
240 OS << " RangeEnd:" << RangeStartEnd.second;
241 }
242 break;
243 }
245 const auto *OF = cast<MCPseudoProbeAddrFragment>(this);
246 OS << "\n ";
247 OS << " AddrDelta:" << OF->getAddrDelta();
248 break;
249 }
251 break;
252 }
253 OS << ">";
254}
255#endif
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:533
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:83
void destroy()
Destroys the current fragment.
Definition: MCFragment.cpp:33
void dump() const
Definition: MCFragment.cpp:101
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:91
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
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:292