28 std::unique_ptr<MCAsmBackend> TAB,
29 std::unique_ptr<MCObjectWriter> OW,
30 std::unique_ptr<MCCodeEmitter>
Emitter)
35 assert(Assembler->getBackendPtr() && Assembler->getEmitterPtr());
38 if (
Context.getTargetOptions() &&
Context.getTargetOptions()->MCRelaxAll)
39 Assembler->setRelaxAll(
true);
46 return Assembler.get();
81 if (Headroom <= FragSpace)
88void MCObjectStreamer::addSpecialFragment(
MCFragment *Frag) {
90 "Frag should have a variable-size tail");
114 FragSpace -= Contents.
size();
137 if (
Hi->isVariable() ||
Lo->isVariable())
139 auto *LoF =
Lo->getFragment();
140 if (!LoF ||
Hi->getFragment() != LoF || LoF->isLinkerRelaxable())
143 auto Fixed = LoF->getFixedSize();
147 return Hi->getOffset() -
Lo->getOffset();
171 Assembler->setRelaxAll(
getContext().getTargetOptions()->MCRelaxAll);
174 EmitDebugFrame =
false;
177 SpecialFragAllocator.
Reset();
191 if (EmitSFrame || (
getContext().getTargetOptions() &&
192 getContext().getTargetOptions()->EmitSFrameUnwind))
197 Assembler->registerSymbol(
Sym);
203 EmitDebugFrame =
Debug;
218 Loc,
"value evaluated as " +
Twine(AbsValue) +
" is out of range.");
250 if (Symbol->isVariable())
259 Symbol->setFragment(
F);
260 Symbol->setOffset(
F->getFixedSize());
266 auto Assignments = pendingAssignments.find(Symbol);
267 if (Assignments != pendingAssignments.end()) {
268 for (
const PendingAssignment &
A : Assignments->second)
271 pendingAssignments.erase(Assignments);
282 Symbol->setFragment(&
F);
283 Symbol->setOffset(
Offset);
314 assert(Section &&
"Cannot switch to a null section!");
321 if (NewSec && Subsection) {
339 F->setParent(Section);
341 auto &Subsections = Section->Subsections;
342 size_t I = 0, E = Subsections.size();
343 while (
I != E && Subsections[
I].first < Subsection)
347 if (
I == E || Subsections[
I].first != Subsection) {
348 Subsections.insert(Subsections.begin() +
I,
350 Section->CurFragList = &Subsections[
I].second;
353 Section->CurFragList = &Subsections[
I].second;
362 if (
auto *
Sym = Section->getBeginSymbol()) {
376 const MCSymbol *
Target = &cast<MCSymbolRefExpr>(*Value).getSymbol();
380 if (
Target->isRegistered())
383 pendingAssignments[
Target].push_back({Symbol,
Value});
406 emitInstToData(Inst, STI);
416 emitInstToData(Relaxed, STI);
423void MCObjectStreamer::emitInstToData(
const MCInst &Inst,
437 F->setHasInstructions(STI);
441 bool MarkedLinkerRelaxable =
false;
442 for (
auto &
Fixup : Fixups) {
443 Fixup.setOffset(
Fixup.getOffset() + CodeOffset);
444 if (!
Fixup.isLinkerRelaxable() || MarkedLinkerRelaxable)
446 MarkedLinkerRelaxable =
true;
449 auto *Sec =
F->getParent();
450 if (!Sec->isLinkerRelaxable())
451 Sec->setFirstLinkerRelaxable(
F->getLayoutOrder());
455 F->setLinkerRelaxable();
458 F->appendFixups(Fixups);
469 F->setHasInstructions(STI);
471 F->setVarContents(
Data);
474 bool MarkedLinkerRelaxable =
false;
475 for (
auto &
Fixup : Fixups) {
476 if (!
Fixup.isLinkerRelaxable() || MarkedLinkerRelaxable)
478 MarkedLinkerRelaxable =
true;
479 auto *Sec =
F->getParent();
480 if (!Sec->isLinkerRelaxable())
481 Sec->setFirstLinkerRelaxable(
F->getLayoutOrder());
482 F->setLinkerRelaxable();
484 F->setVarFixups(Fixups);
490 unsigned Column,
unsigned Flags,
492 unsigned Discriminator,
500 Discriminator, FileName, Comment);
515 int64_t LineDelta,
const MCSymbol *Label,
518 OS.emitIntValue(dwarf::DW_LNS_extended_op, 1);
519 OS.emitULEB128IntValue(PointerSize + 1);
520 OS.emitIntValue(dwarf::DW_LNE_set_address, 1);
521 OS.emitSymbolValue(Label, PointerSize);
530 unsigned PointerSize) {
543 LineDelta, *OptAddrDelta, Tmp);
551 F->setDwarfLineDelta(LineDelta);
587 unsigned Line,
unsigned Column,
588 bool PrologueEnd,
bool IsStmt,
598 FileNo, Line, Column, PrologueEnd,
611 unsigned PrimaryFunctionId,
unsigned SourceFileId,
unsigned SourceLineNum,
614 *
this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
617 PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
621 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
647 unsigned MaxBytesToEmit) {
648 if (MaxBytesToEmit == 0)
649 MaxBytesToEmit = Alignment.
value();
651 F->makeAlign(Alignment, Fill, FillLen, MaxBytesToEmit);
655 F->getParent()->ensureMinAlignment(Alignment);
660 unsigned MaxBytesToEmit) {
663 F->u.align.EmitNops =
true;
670 newSpecialFragment<MCOrgFragment>(*
Offset,
Value, Loc);
675 std::optional<MCFixupKind> MaybeKind =
676 Assembler->getBackend().getFixupKind(
Name);
691 if (
Offset.evaluateAsAbsolute(Val,
nullptr)) {
702 newSpecialFragment<MCFillFragment>(FillValue, 1, NumBytes, Loc);
706 int64_t Expr,
SMLoc Loc) {
707 int64_t IntNumValues;
709 if (NumValues.evaluateAsAbsolute(IntNumValues,
getAssembler())) {
710 if (IntNumValues < 0) {
713 "'.fill' directive with negative repeat count has no effect");
717 int64_t NonZeroSize =
Size > 4 ? 4 :
Size;
718 Expr &= ~0ULL >> (64 - NonZeroSize * 8);
719 for (
uint64_t i = 0, e = IntNumValues; i != e; ++i) {
721 if (NonZeroSize <
Size)
729 newSpecialFragment<MCFillFragment>(Expr,
Size, NumValues, Loc);
735 newSpecialFragment<MCNopsFragment>(NumBytes, ControlledNopLength, Loc, STI);
740 Asm.getWriter().addFileName(Filename);
748 W.addFileName(Filename);
749 if (CompilerVersion.
size())
750 W.setCompilerVersion(CompilerVersion);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_LIKELY(EXPR)
dxil DXContainer Global Emitter
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B, SMLoc Loc)
constexpr size_t FragBlockSize
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
static std::optional< uint64_t > absoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo)
constexpr size_t NewFragHeadroom
PowerPC TLS Dynamic Call Fixup
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it,...
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
void recordCVLoc(MCContext &Ctx, const MCSymbol *Label, unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt)
Saves the information from the currently parsed .cv_loc directive and sets CVLocSeen.
void emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion)
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
Generic interface to target specific assembler backends.
bool allowEnhancedRelaxation() const
Return true if this target allows an unrelaxable instruction to be emitted into RelaxableFragment and...
virtual void relaxInstruction(MCInst &Inst, const MCSubtargetInfo &STI) const
Relax the instruction in the given fragment to the next wider instruction.
virtual bool mayNeedRelaxation(unsigned Opcode, ArrayRef< MCOperand > Operands, const MCSubtargetInfo &STI) const
Check whether the given instruction (encoded as Opcode+Operands) may need relaxation.
This class is intended to be used as a base class for asm properties and features specific to the tar...
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
LLVM_ABI void Finish()
Finish - Do final processing and write the object to the output stream.
MCObjectWriter & getWriter() const
LLVM_ABI void addRelocDirective(RelocDirective RD)
MCCodeEmitter & getEmitter() const
MCAsmBackend & getBackend() const
LLVM_ABI bool registerSection(MCSection &Section)
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol)
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static LLVM_ABI const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
Encode the given Inst to bytes and append to CB.
Context object for machine code objects.
const MCObjectFileInfo * getObjectFileInfo() const
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
LLVM_ABI void RemapDebugPaths()
LLVM_ABI CodeViewContext & getCVContext()
const SourceMgr * getSourceManager() const
const MCAsmInfo * getAsmInfo() const
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
static LLVM_ABI void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
static LLVM_ABI void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
static LLVM_ABI void encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
static LLVM_ABI void make(MCStreamer *MCOS, MCSection *Section)
static LLVM_ABI void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params)
Base class for the full range of assembler expressions which are needed for parsing.
static MCFixupKind getDataKindForSize(unsigned Size)
Return the generic fixup kind for a value with the given size.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
FragmentType getKind() const
LLVM_ABI void addFixup(MCFixup Fixup)
static LLVM_ABI void Emit(MCStreamer *MCOS)
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
ArrayRef< MCOperand > getOperands() const
MCSection * getDwarfLineSection() const
Streaming object file generation interface.
void reset() override
state management
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
void emitValueToAlignment(Align Alignment, int64_t Fill=0, uint8_t FillLen=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
void emitCFISections(bool EH, bool Debug, bool SFrame) override
void emitULEB128Value(const MCExpr *Value) override
void emitSLEB128Value(const MCExpr *Value) override
void emitNops(int64_t NumBytes, int64_t ControlledNopLength, SMLoc Loc, const MCSubtargetInfo &STI) override
void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) override
This implements the CodeView '.cv_inline_linetable' assembler directive.
void emitCVStringTableDirective() override
This implements the CodeView '.cv_stringtable' assembler directive.
MCAssembler & getAssembler()
void emitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize) override
If targets does not support representing debug line section by .loc/.file directives in assembly outp...
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Target) override
Emit an weak reference from Alias to Symbol.
void appendContents(ArrayRef< char > Contents)
void emitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc) override
This implements the CodeView '.cv_loc' assembler directive.
void emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc={}) override
Record a relocation described by the .reloc directive.
void emitBytes(StringRef Data) override
Emit the bytes in Data into the output.
void emitPendingAssignments(MCSymbol *Symbol)
Emits pending conditional assignments that depend on Symbol being emitted.
void addFixup(const MCExpr *Value, MCFixupKind Kind)
void emitFileDirective(StringRef Filename) override
Switch to a new logical file.
void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName, StringRef Comment={}) override
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
MCSymbol * emitCFILabel() override
When emitting an object file, create and emit a real label.
void emitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion) override
This implements the CodeView '.cv_def_range' assembler directive.
MCAssembler * getAssemblerPtr() override
void emitAddrsigSym(const MCSymbol *Sym) override
void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel, MCSymbol *EndLabel=nullptr) override
Emit the debug line end entry.
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
void visitUsedSymbol(const MCSymbol &Sym) override
void emitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
virtual void emitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment &F, uint64_t Offset)
void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void finishImpl() override
Streamer specific finalization.
void changeSection(MCSection *Section, uint32_t Subsection=0) override
This is called by popSection and switchSection, if the current section changes.
void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) override
Emit the absolute difference between two symbols encoded with ULEB128.
MCFragment * allocFragSpace(size_t Headroom)
void emitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label, SMLoc Loc)
bool mayHaveInstructions(MCSection &Sec) const override
void emitCodeAlignment(Align ByteAlignment, const MCSubtargetInfo *STI, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
void emitFrames(MCAsmBackend *MAB)
void ensureHeadroom(size_t Headroom)
void emitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView '.cv_filechecksumoffset' assembler directive.
void emitAddrsig() override
void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol, but only if Value is also emitted.
void emitCVFileChecksumsDirective() override
This implements the CodeView '.cv_filechecksums' assembler directive.
void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin, const MCSymbol *End) override
This implements the CodeView '.cv_linetable' assembler directive.
void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc) override
Emit some number of copies of Value until the byte offset Offset is reached.
uint8_t * getCurFragEnd() const
void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) override
Emit the absolute difference between two symbols if possible.
Defines the object file and target independent interfaces used by the assembler backend to write nati...
void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
static LLVM_ABI void emit(MCObjectStreamer *MCOS)
static void emit(MCObjectStreamer &Streamer)
Instances of this class represent a uniqued identifier for a section in the current translation unit.
bool hasInstructions() const
void setHasInstructions(bool Value)
MCSymbol * getBeginSymbol()
Streaming machine code generation interface.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void emitCFISections(bool EH, bool Debug, bool SFrame)
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
MCFragment * getCurrentFragment() const
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
bool getUseAssemblerInfoForParsing()
MCContext & getContext() const
bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc)
Returns true if the .cv_loc directive is in the right section.
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
void setAllowAutoPadding(bool v)
virtual void reset()
State management.
virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName, StringRef Comment={})
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
virtual void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView '.cv_linetable' assembler directive.
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
unsigned getNumFrameInfos()
size_t getCurFragSize() const
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
MCSymbol * endSection(MCSection *Section)
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
virtual void emitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol * > > Ranges, StringRef FixedSizePortion)
This implements the CodeView '.cv_def_range' assembler directive.
MCSection * getCurrentSectionOnly() const
virtual void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Emit the expression Value into the output as a native integer of the given Size bytes.
void addFragment(MCFragment *F)
unsigned emitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
This implements the CodeView '.cv_inline_linetable' assembler directive.
void visitUsedExpr(const MCExpr &Expr)
Generic base class for all target subtargets.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Represents a location in source code.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM_ABI void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
StringRef - Represent a constant reference to a string, i.e.
constexpr size_t size() const
size - Get the string size.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
This class represents a function that is read from a sample profile.
This is an optimization pass for GlobalISel generic memory operations.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
constexpr T alignToPowerOf2(U Value, V Align)
Will overflow only if result is not representable in T.
OutputIt copy(R &&Range, OutputIt Out)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.