26 std::unique_ptr<MCAsmBackend> TAB,
27 std::unique_ptr<MCObjectWriter> OW,
28 std::unique_ptr<MCCodeEmitter> Emitter)
31 Context,
std::move(TAB),
std::move(Emitter),
std::move(OW))),
32 EmitEHFrame(
true), EmitDebugFrame(
false) {
33 if (Assembler->getBackendPtr())
44 return Assembler.get();
52 if (!PendingLabels.empty()) {
55 PendingLabels.clear();
62 auto SecIt =
std::find(PendingLabelSections.begin(),
63 PendingLabelSections.end(), CurSection);
64 if (SecIt == PendingLabelSections.end())
65 PendingLabelSections.push_back(CurSection);
69 PendingLabels.push_back(S);
75 assert(PendingLabels.empty());
79 if (!PendingLabels.empty()) {
82 PendingLabels.clear();
95 if (!PendingLabels.empty()) {
100 PendingLabels.clear();
115 void MCObjectStreamer::resolvePendingFixups() {
116 for (PendingMCFixup &PendingFixup : PendingFixups) {
117 if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
119 "unresolved relocation offset");
123 PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
124 PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
126 PendingFixups.clear();
168 EmitDebugFrame =
false;
169 PendingLabels.clear();
170 PendingLabelSections.clear();
189 return &*std::prev(CurInsertionPoint);
219 Assembler->registerSymbol(Sym);
225 EmitDebugFrame =
Debug;
239 if (!
isUIntN(8 * Size, AbsValue) && !
isIntN(8 * Size, AbsValue)) {
241 Loc,
"value evaluated as " +
Twine(AbsValue) +
" is out of range.");
253 MCSymbol *MCObjectStreamer::EmitCFILabel() {
300 auto *
DF = dyn_cast_or_null<MCDataFragment>(
F);
305 assert(isa<MCDummyFragment>(F) &&
306 "F must either be an MCDataFragment or the pending MCDummyFragment");
336 const MCExpr *Subsection) {
341 const MCExpr *Subsection) {
342 assert(Section &&
"Cannot switch to a null section!");
347 int64_t IntSubsection = 0;
351 if (IntSubsection < 0 || IntSubsection > 8192)
353 CurSubsectionIdx =
unsigned(IntSubsection);
371 EmitInstructionImpl(Inst, STI);
375 void MCObjectStreamer::EmitInstructionImpl(
const MCInst &Inst,
389 EmitInstToData(Inst, STI);
402 while (
getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI))
404 EmitInstToData(Relaxed, STI);
431 "Aligned bundling is not implemented for this object format";
447 unsigned Column,
unsigned Flags,
449 unsigned Discriminator,
456 Isa, Discriminator, FileName);
472 int64_t LineDelta,
const MCSymbol *Label,
487 unsigned PointerSize) {
515 unsigned Line,
unsigned Column,
516 bool PrologueEnd,
bool IsStmt,
526 FileNo, Line, Column, PrologueEnd,
539 unsigned PrimaryFunctionId,
unsigned SourceFileId,
unsigned SourceLineNum,
542 *
this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
545 PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
549 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
580 unsigned MaxBytesToEmit) {
581 if (MaxBytesToEmit == 0)
592 unsigned MaxBytesToEmit) {
680 if (Offset.evaluateAsAbsolute(OffsetValue)) {
712 int64_t Expr,
SMLoc Loc) {
713 int64_t IntNumValues;
716 if (IntNumValues < 0) {
719 "'.fill' directive with negative repeat count has no effect");
723 int64_t NonZeroSize = Size > 4 ? 4 :
Size;
724 Expr &= ~0ULL >> (64 - NonZeroSize * 8);
725 for (uint64_t i = 0,
e = IntNumValues; i !=
e; ++i) {
727 if (NonZeroSize < Size)
767 resolvePendingFixups();
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName)
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
Instances of this class represent a uniqued identifier for a section in the current translation unit...
reference emplace_back(ArgTypes &&... Args)
virtual void EmitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
This implements the CodeView '.cv_def_range' assembler directive.
void addPendingLabel(MCSymbol *label, unsigned Subsection=0)
Add a pending label for the requested subsection.
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
A eight-byte dtp relative fixup.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
bool hasInstructions() const
static void Make(MCObjectStreamer *MCOS, MCSection *Section)
static const char *const BundlingNotImplementedMsg
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
void EmitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
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.
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
bool isVariable() const
isVariable - Check if this is a variable symbol.
virtual bool mayNeedRelaxation(const MCInst &Inst, const MCSubtargetInfo &STI) const =0
Check whether the given instruction may need relaxation.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
virtual void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
virtual bool requiresDiffExpressionRelocations() const
Check whether the given target requires emitting differences of two symbols as a set of relocations...
virtual void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, MCInst &Res) const =0
Relax the instruction in the given fragment to the next wider instruction.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual 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 reset()
State management.
MCFragment * emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
A raw_ostream that writes to an SmallVector or SmallString.
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView '.cv_filechecksumoffset' assembler directive.
void EmitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion) override
This implements the CodeView '.cv_def_range' assembler directive.
block Block Frequency true
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
void flushPendingLabels(MCFragment *F, uint64_t FOffset=0, unsigned Subsection=0)
Associate all pending labels in a subsection with a fragment.
static void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
bool isBundlingEnabled() 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.
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI)
Emit the given Instruction into the current section.
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)
void EmitCVStringTableDirective() override
This implements the CodeView '.cv_stringtable' assembler directive.
virtual void EmitCFISections(bool EH, bool Debug)
unsigned getAlignment() const
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
MCContext & getContext() const
unsigned getNumFrameInfos()
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void setHasInstructions(bool Value)
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
bool EmitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc, const MCSubtargetInfo &STI) override
Emit a .reloc directive.
MCCodeEmitter & getEmitter() const
void flushPendingLabels()
Create a data fragment for any pending labels across all Sections and Subsections.
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
A four-byte tp relative fixup.
Base class for the full range of assembler expressions which are needed for parsing.
bool registerSection(MCSection &Section)
Represent a reference to a symbol from inside an expression.
MCObjectWriter & getWriter() const
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
bool mayHaveInstructions(MCSection &Sec) const override
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
void addPendingLabel(MCSymbol *label)
Assign a label to the current Section and Subsection even though a fragment is not yet present...
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Context object for machine code objects.
void EmitDTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
A four-byte gp relative fixup.
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
void EmitFileDirective(StringRef Filename) override
Switch to a new logical file.
virtual void alignBranchesBegin(MCObjectStreamer &OS, const MCInst &Inst)
Give the target a chance to manipulate state related to instruction alignment (e.g.
Streaming object file generation interface.
MCAssembler * getAssemblerPtr() override
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isBundleLocked() const
bool getUseAssemblerInfoForParsing()
void EmitDTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
SmallVectorImpl< char > & getContents()
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...
Instances of this class represent a single low-level machine instruction.
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) override
Emit the absolute difference between two symbols if possible.
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
A four-byte dtp relative fixup.
void EmitULEB128Value(const MCExpr *Value) override
Streaming machine code generation interface.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void visitUsedSymbol(const MCSymbol &Sym) override
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.
virtual void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView '.cv_linetable' assembler directive.
void EmitSLEB128Value(const MCExpr *Value) override
void insert(MCFragment *F)
void EmitAddrsig() override
void EmitAddrsigSym(const MCSymbol *Sym) override
void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
MCAssembler & getAssembler()
MCFixupKind
Extensible enumeration to represent the type of a fixup.
SmallVectorImpl< MCFixup > & getFixups()
void setAlignment(Align Value)
void reportError(SMLoc L, const Twine &Msg)
uint64_t getOffset() const
A eight-byte tp relative fixup.
void EmitFrames(MCAsmBackend *MAB)
const SourceMgr * getSourceManager() const
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
void setOffset(uint64_t Value)
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
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.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
void EmitCFISections(bool EH, bool Debug) override
void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label)
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
MCAsmBackend * getBackendPtr() const
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
MCAsmBackend & getBackend() const
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override
Emit the given Instruction into the current section.
const MCSymbol & getSymbol() const
MCFragment * getFragment(bool SetUsed=true) const
virtual void alignBranchesEnd(MCObjectStreamer &OS, const MCInst &Inst)
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 EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin, const MCSymbol *End) override
This implements the CodeView '.cv_linetable' assembler directive.
void EmitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
void addFileName(StringRef FileName)
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
virtual void EmitLabelAtPos(MCSymbol *Symbol, SMLoc Loc, MCFragment *F, uint64_t Offset)
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
MCSection * getCurrentSectionOnly() const
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.
MCSection * getParent() const
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc)
Returns true if the the .cv_loc directive is in the right section.
static void Emit(MCStreamer *MCOS)
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
void EmitTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (32-bit TP relative) value.
static void Emit(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params)
MCDataFragment * getOrCreateDataFragment(const MCSubtargetInfo *STI=nullptr)
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...
void EmitBundleUnlock() override
Ends a bundle-locked group.
void FinishImpl() override
Streamer specific finalization.
static Optional< uint64_t > absoluteSymbolDiff(MCAssembler &Asm, const MCSymbol *Hi, const MCSymbol *Lo)
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
void reset() override
state management
static bool CanReuseDataFragment(const MCDataFragment &F, const MCAssembler &Assembler, const MCSubtargetInfo *STI)
Generic base class for all target subtargets.
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
References to labels and assigned expressions.
void setAllowAutoPadding(bool v)
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
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 EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName) override
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) override
This implements the CodeView '.cv_inline_linetable' assembler directive.
MCFragment * getCurrentFragment() const
CodeViewContext & getCVContext()
static MCFixupKind getKindForSize(unsigned Size, bool IsPCRel)
Return the generic fixup kind for a value with the given size.
Fragment for data and encoded instructions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter)
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
LLVM Value Representation.
Generic interface to target specific assembler backends.
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
void EmitGPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
StringRef - Represent a constant reference to a string, i.e.
FragmentListType::iterator iterator
void EmitCVFileChecksumsDirective() override
This implements the CodeView '.cv_filechecksums' assembler directive.
Represents a location in source code.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
virtual void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) override
Emit the absolute difference between two symbols encoded with ULEB128.
void Finish()
Finish - Do final processing and write the object to the output stream.
void EmitGPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
void EmitTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (64-bit TP relative) value.