14 #include "llvm/Config/llvm-config.h" 36 if (!Sec.isVirtualSection())
37 SectionOrder.push_back(&Sec);
39 if (Sec.isVirtualSection())
40 SectionOrder.push_back(&Sec);
43 bool MCAsmLayout::isFragmentValid(
const MCFragment *
F)
const {
45 const MCFragment *LastValid = LastValidFragment.lookup(Sec);
54 if (!isFragmentValid(F))
62 void MCAsmLayout::ensureValid(
const MCFragment *F)
const {
71 while (!isFragmentValid(F)) {
72 assert(I != Sec->end() &&
"Layout bookkeeping error");
80 assert(F->Offset != ~UINT64_C(0) &&
"Address not set!");
148 Expr->
getLoc(),
"expression could not be evaluated");
156 "' could not be evaluated in a subtraction expression");
168 "Common symbol '" + ASym.
getName() +
169 "' cannot be used in assignment expr");
193 uint64_t FOffset, uint64_t FSize) {
196 "computeBundlePadding should only be called if bundling is enabled");
197 uint64_t BundleMask = BundleSize - 1;
198 uint64_t OffsetInBundle = FOffset & BundleMask;
199 uint64_t EndOfFragment = OffsetInBundle + FSize;
219 if (EndOfFragment == BundleSize)
221 else if (EndOfFragment < BundleSize)
222 return BundleSize - EndOfFragment;
224 return 2 * BundleSize - EndOfFragment;
226 }
else if (OffsetInBundle > 0 && EndOfFragment > BundleSize)
227 return BundleSize - OffsetInBundle;
240 : Kind(Kind), HasInstructions(HasInstructions), LayoutOrder(0),
241 Parent(Parent), Atom(nullptr),
Offset(~UINT64_C(0)) {
255 delete cast<MCAlignFragment>(
this);
258 delete cast<MCDataFragment>(
this);
261 delete cast<MCCompactEncodedInstFragment>(
this);
264 delete cast<MCFillFragment>(
this);
267 delete cast<MCRelaxableFragment>(
this);
270 delete cast<MCOrgFragment>(
this);
273 delete cast<MCDwarfLineAddrFragment>(
this);
276 delete cast<MCDwarfCallFrameFragment>(
this);
279 delete cast<MCLEBFragment>(
this);
282 delete cast<MCPaddingFragment>(
this);
285 delete cast<MCSymbolIdFragment>(
this);
288 delete cast<MCCVInlineLineTableFragment>(
this);
291 delete cast<MCCVDefRangeFragment>(
this);
294 delete cast<MCDummyFragment>(
this);
304 OS <<
"<MCFixup" <<
" Offset:" << AF.
getOffset()
306 <<
" Kind:" << AF.
getKind() <<
">";
312 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 321 OS <<
"MCCompactEncodedInstFragment";
break;
335 OS <<
"<MCFragment " << (
const void *)
this <<
" LayoutOrder:" << LayoutOrder
338 OS <<
" BundlePadding:" <<
static_cast<unsigned>(EF->getBundlePadding());
345 OS <<
" (emit nops)";
357 for (
unsigned i = 0, e = Contents.
size(); i != e; ++i) {
359 OS << hexdigit((Contents[i] >> 4) & 0xF) <<
hexdigit(Contents[i] & 0xF);
361 OS <<
"] (" << Contents.
size() <<
" bytes)";
377 cast<MCCompactEncodedInstFragment>(
this);
381 for (
unsigned i = 0, e = Contents.
size(); i != e; ++i) {
383 OS << hexdigit((Contents[i] >> 4) & 0xF) <<
hexdigit(Contents[i] & 0xF);
385 OS <<
"] (" << Contents.
size() <<
" bytes)";
390 OS <<
" Value:" <<
static_cast<unsigned>(FF->
getValue())
391 <<
" ValueSize:" << static_cast<unsigned>(FF->
getValueSize())
406 <<
" Value:" <<
static_cast<unsigned>(OF->
getValue());
448 const auto *F = cast<MCCVInlineLineTableFragment>(
this);
450 OS <<
" Sym:" << *F->getFnStartSym();
454 const auto *F = cast<MCCVDefRangeFragment>(
this);
456 for (std::pair<const MCSymbol *, const MCSymbol *> RangeStartEnd :
458 OS <<
" RangeStart:" << RangeStartEnd.first;
459 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)
Fragment for adding required padding.
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.
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 ...
uint8_t getValueSize() const
void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ") const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
FragmentType getKind() const
This is a compact (memory-size-wise) fragment for holding an encoded instruction (non-relaxable) that...
const MCExpr & getOffset() 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. ...
fixup_iterator fixup_end()
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.
const MCExpr & getAddrDelta() const
const MCExpr & getAddrDelta() const
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)...
bool isDummy() const
Return true if given frgment has FT_Dummy type.
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
SmallVectorImpl< char > & getContents()
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
const MCInst & getInst() const
MCAsmLayout(MCAssembler &Assembler)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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
const MCExpr & getValue() const
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.
unsigned getMaxBytesToEmit() const
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
Represents a symbol table index fragment.
unsigned getLayoutOrder() const
uint64_t getPaddingPoliciesMask() 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)
uint64_t getValue() const
const MCExpr & getNumValues() const
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
unsigned getValueSize() const
unsigned getAlignment() const
int64_t getLineDelta() const
size_t getInstSize() const
const MCInst & getInst() const
fixup_iterator fixup_begin()
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...
const MCSymbol * getSymbol()
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
StringRef getName() const
getName - Get the symbol name.
Fragment for data and encoded instructions.
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.
bool isInsertionPoint() const
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
const MCExpr * getValue() const
FragmentListType::iterator iterator
static void LLVM_ATTRIBUTE_NORETURN ReportError(uint32_t StartOffset, const char *ErrorMsg)
MCSection::FragmentListType & getFragmentList()
const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
If this symbol is equivalent to A + Constant, return A.
MCFixupKind getKind() const