13 #include "llvm/Config/llvm-config.h" 35 if (!Sec.isVirtualSection())
36 SectionOrder.push_back(&Sec);
38 if (Sec.isVirtualSection())
39 SectionOrder.push_back(&Sec);
42 bool MCAsmLayout::isFragmentValid(
const MCFragment *
F)
const {
44 const MCFragment *LastValid = LastValidFragment.lookup(Sec);
53 if (!isFragmentValid(F))
61 void MCAsmLayout::ensureValid(
const MCFragment *F)
const {
70 while (!isFragmentValid(F)) {
71 assert(I != Sec->end() &&
"Layout bookkeeping error");
79 assert(F->Offset != ~UINT64_C(0) &&
"Address not set!");
147 Expr->
getLoc(),
"expression could not be evaluated");
155 "' could not be evaluated in a subtraction expression");
167 "Common symbol '" + ASym.
getName() +
168 "' cannot be used in assignment expr");
192 uint64_t FOffset, uint64_t FSize) {
195 "computeBundlePadding should only be called if bundling is enabled");
196 uint64_t BundleMask = BundleSize - 1;
197 uint64_t OffsetInBundle = FOffset & BundleMask;
198 uint64_t EndOfFragment = OffsetInBundle + FSize;
218 if (EndOfFragment == BundleSize)
220 else if (EndOfFragment < BundleSize)
221 return BundleSize - EndOfFragment;
223 return 2 * BundleSize - EndOfFragment;
225 }
else if (OffsetInBundle > 0 && EndOfFragment > BundleSize)
226 return BundleSize - OffsetInBundle;
237 : Parent(Parent), Atom(nullptr),
Offset(~UINT64_C(0)), LayoutOrder(0),
238 Kind(Kind), HasInstructions(HasInstructions) {
239 if (Parent && !isa<MCDummyFragment>(*
this))
252 delete cast<MCAlignFragment>(
this);
255 delete cast<MCDataFragment>(
this);
258 delete cast<MCCompactEncodedInstFragment>(
this);
261 delete cast<MCFillFragment>(
this);
264 delete cast<MCRelaxableFragment>(
this);
267 delete cast<MCOrgFragment>(
this);
270 delete cast<MCDwarfLineAddrFragment>(
this);
273 delete cast<MCDwarfCallFrameFragment>(
this);
276 delete cast<MCLEBFragment>(
this);
279 delete cast<MCBoundaryAlignFragment>(
this);
282 delete cast<MCSymbolIdFragment>(
this);
285 delete cast<MCCVInlineLineTableFragment>(
this);
288 delete cast<MCCVDefRangeFragment>(
this);
291 delete cast<MCDummyFragment>(
this);
301 OS <<
"<MCFixup" <<
" Offset:" << AF.
getOffset()
303 <<
" Kind:" << AF.
getKind() <<
">";
309 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 318 OS <<
"MCCompactEncodedInstFragment";
break;
332 OS <<
"<MCFragment " << (
const void *)
this <<
" LayoutOrder:" << LayoutOrder
334 if (
const auto *EF = dyn_cast<MCEncodedFragment>(
this))
335 OS <<
" BundlePadding:" <<
static_cast<unsigned>(EF->getBundlePadding());
340 const auto *AF = cast<MCAlignFragment>(
this);
341 if (AF->hasEmitNops())
342 OS <<
" (emit nops)";
344 OS <<
" Alignment:" << AF->getAlignment()
345 <<
" Value:" << AF->getValue() <<
" ValueSize:" << AF->getValueSize()
346 <<
" MaxBytesToEmit:" << AF->getMaxBytesToEmit() <<
">";
350 const auto *
DF = cast<MCDataFragment>(
this);
354 for (
unsigned i = 0,
e = Contents.
size(); i !=
e; ++i) {
356 OS << hexdigit((Contents[i] >> 4) & 0xF) <<
hexdigit(Contents[i] & 0xF);
358 OS <<
"] (" << Contents.
size() <<
" bytes)";
360 if (
DF->fixup_begin() !=
DF->fixup_end()) {
364 ie =
DF->fixup_end(); it != ie; ++it) {
365 if (it !=
DF->fixup_begin()) OS <<
",\n ";
374 cast<MCCompactEncodedInstFragment>(
this);
378 for (
unsigned i = 0,
e = Contents.
size(); i !=
e; ++i) {
380 OS << hexdigit((Contents[i] >> 4) & 0xF) <<
hexdigit(Contents[i] & 0xF);
382 OS <<
"] (" << Contents.
size() <<
" bytes)";
386 const auto *FF = cast<MCFillFragment>(
this);
387 OS <<
" Value:" <<
static_cast<unsigned>(FF->getValue())
388 <<
" ValueSize:" << static_cast<unsigned>(FF->getValueSize())
389 <<
" NumValues:" << FF->getNumValues();
393 const auto *F = cast<MCRelaxableFragment>(
this);
396 F->getInst().dump_pretty(OS);
400 const auto *OF = cast<MCOrgFragment>(
this);
402 OS <<
" Offset:" << OF->getOffset()
403 <<
" Value:" <<
static_cast<unsigned>(OF->getValue());
407 const auto *OF = cast<MCDwarfLineAddrFragment>(
this);
409 OS <<
" AddrDelta:" << OF->getAddrDelta()
410 <<
" LineDelta:" << OF->getLineDelta();
414 const auto *CF = cast<MCDwarfCallFrameFragment>(
this);
416 OS <<
" AddrDelta:" << CF->getAddrDelta();
420 const auto *LF = cast<MCLEBFragment>(
this);
422 OS <<
" Value:" << LF->getValue() <<
" Signed:" << LF->isSigned();
426 const auto *BF = cast<MCBoundaryAlignFragment>(
this);
427 if (BF->canEmitNops())
428 OS <<
" (can emit nops to align";
430 OS <<
" fused branch)";
432 OS <<
" unfused branch)";
434 OS <<
" BoundarySize:" << BF->getAlignment().value()
435 <<
" Size:" << BF->getSize();
439 const auto *F = cast<MCSymbolIdFragment>(
this);
441 OS <<
" Sym:" << F->getSymbol();
445 const auto *F = cast<MCCVInlineLineTableFragment>(
this);
447 OS <<
" Sym:" << *F->getFnStartSym();
451 const auto *F = cast<MCCVDefRangeFragment>(
this);
453 for (std::pair<const MCSymbol *, const MCSymbol *> RangeStartEnd :
455 OS <<
" RangeStart:" << RangeStartEnd.first;
456 OS <<
" RangeEnd:" << RangeStartEnd.second;
Instances of this class represent a uniqued identifier for a section in the current translation unit...
bool alignToBundleEnd() const
Should this fragment be placed at the end of an aligned bundle?
static bool getSymbolOffsetImpl(const MCAsmLayout &Layout, const MCSymbol &S, bool ReportError, uint64_t &Val)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
bool isVariable() const
isVariable - Check if this is a variable symbol.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
This represents an "assembler immediate".
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
FragmentType getKind() const
bool isCommon() const
Is this a 'common' symbol.
static bool getLabelOffset(const MCAsmLayout &Layout, const MCSymbol &S, bool ReportError, uint64_t &Val)
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
unsigned getBundleAlignSize() const
MCContext & getContext() const
int64_t getConstant() const
const MCSymbolRefExpr * getSymB() const
Interface implemented by fragments that contain encoded instructions and/or data. ...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
SmallVectorImpl< MCFixup >::const_iterator const_fixup_iterator
Encapsulates the layout of an assembly file at a particular point in time.
Base class for the full range of assembler expressions which are needed for parsing.
Represent a reference to a symbol from inside an expression.
void destroy()
Destroys the current fragment.
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
char hexdigit(unsigned X, bool LowerCase=false)
hexdigit - Return the hexadecimal character for the given number X (which should be less than 16)...
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
MCAsmLayout(MCAssembler &Assembler)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static void LLVM_ATTRIBUTE_NORETURN ReportError(uint64_t StartOffset, const char *ErrorMsg)
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized.
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
const MCSymbolRefExpr * getSymA() const
void reportError(SMLoc L, const Twine &Msg)
uint64_t getOffset() const
uint32_t getOffset() const
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
Iterator for intrusive lists based on ilist_node.
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
const MCSymbol & getSymbol() const
MCFragment * getFragment(bool SetUsed=true) const
unsigned getLayoutOrder() const
static void deleteNode(NodeTy *V)
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCEncodedFragment *F, uint64_t FOffset, uint64_t FSize)
Compute the amount of padding required before the fragment F to obey bundling restrictions, where FOffset is the fragment's offset in its section and FSize is the fragment's size.
Target - Wrapper for Target specific information.
MCSection * getParent() const
void push_back(pointer val)
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
bool evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const
Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables...
uint64_t computeFragmentSize(const MCAsmLayout &Layout, const MCFragment &F) const
Compute the effective fragment size assuming it is laid out at the given SectionAddress and FragmentO...
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
StringRef getName() const
getName - Get the symbol name.
uint64_t getSectionFileSize(const MCSection *Sec) const
Get the data size of the given section, as emitted to the object file.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCExpr * getVariableValue(bool SetUsed=true) const
getVariableValue - Get the value for variable symbols.
This class implements an extremely fast bulk output stream that can only output to a stream...
const MCExpr * getValue() const
FragmentListType::iterator iterator
MCSection::FragmentListType & getFragmentList()
const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
If this symbol is equivalent to A + Constant, return A.
MCFixupKind getKind() const