27 std::unique_ptr<MCAsmBackend> TAB,
28 std::unique_ptr<MCObjectWriter> OW,
29 std::unique_ptr<MCCodeEmitter> Emitter)
32 Context,
std::move(TAB),
std::move(Emitter),
std::move(OW))),
33 EmitEHFrame(
true), EmitDebugFrame(
false) {}
42 return Assembler.get();
47 if (PendingLabels.empty())
55 for (
MCSymbol *Sym : PendingLabels) {
57 Sym->setOffset(FOffset);
59 PendingLabels.clear();
69 void MCObjectStreamer::resolvePendingFixups() {
70 for (PendingMCFixup &PendingFixup : PendingFixups) {
71 if (!PendingFixup.Sym || PendingFixup.Sym->isUndefined ()) {
73 "unresolved relocation offset");
77 PendingFixup.Fixup.setOffset(PendingFixup.Sym->getOffset());
78 PendingFixup.DF->getFixups().push_back(PendingFixup.Fixup);
80 PendingFixups.clear();
122 EmitDebugFrame =
false;
123 PendingLabels.clear();
142 return &*std::prev(CurInsertionPoint);
182 Assembler->registerSymbol(Sym);
188 EmitDebugFrame =
Debug;
202 if (!
isUIntN(8 * Size, AbsValue) && !
isIntN(8 * Size, AbsValue)) {
204 Loc,
"value evaluated as " +
Twine(AbsValue) +
" is out of range.");
216 MCSymbol *MCObjectStreamer::EmitCFILabel() {
247 PendingLabels.push_back(Symbol);
254 auto *DF = dyn_cast_or_null<MCDataFragment>(
F);
258 PendingLabels.push_back(Symbol);
285 const MCExpr *Subsection) {
290 const MCExpr *Subsection) {
291 assert(Section &&
"Cannot switch to a null section!");
297 int64_t IntSubsection = 0;
301 if (IntSubsection < 0 || IntSubsection > 8192)
320 EmitInstructionImpl(Inst, STI);
324 void MCObjectStreamer::EmitInstructionImpl(
const MCInst &Inst,
338 EmitInstToData(Inst, STI);
351 while (
getAssembler().getBackend().mayNeedRelaxation(Relaxed, STI))
353 EmitInstToData(Relaxed, STI);
380 "Aligned bundling is not implemented for this object format";
396 unsigned Column,
unsigned Flags,
398 unsigned Discriminator,
405 Isa, Discriminator, FileName);
421 int64_t LineDelta,
const MCSymbol *Label,
436 unsigned PointerSize) {
464 unsigned Line,
unsigned Column,
465 bool PrologueEnd,
bool IsStmt,
475 FileNo, Line, Column, PrologueEnd,
488 unsigned PrimaryFunctionId,
unsigned SourceFileId,
unsigned SourceLineNum,
491 *
this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
494 PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
498 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
535 unsigned MaxBytesToEmit) {
536 if (MaxBytesToEmit == 0)
547 unsigned MaxBytesToEmit) {
645 if (Offset.evaluateAsAbsolute(OffsetValue)) {
677 int64_t Expr,
SMLoc Loc) {
678 int64_t IntNumValues;
681 if (IntNumValues < 0) {
684 "'.fill' directive with negative repeat count has no effect");
688 int64_t NonZeroSize = Size > 4 ? 4 :
Size;
689 Expr &= ~0ULL >> (64 - NonZeroSize * 8);
690 for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
692 if (NonZeroSize < Size)
730 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...
virtual void EmitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
This implements the CodeView '.cv_def_range' assembler directive.
Fragment for adding required padding.
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
void handleCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context)
Handles all target related code padding after writing a block to an object file.
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.
void EmitCodePaddingBasicBlockStart(const MCCodePaddingContext &Context) override
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
void setAlignment(unsigned Value)
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)
static MCFixupKind getKindForSize(unsigned Size, bool isPCRel)
Return the generic fixup kind for a value with the given size.
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
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
void handleCodePaddingInstructionEnd(const MCInst &Inst)
Handles all target related code padding after writing an instruction to an object file...
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
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.
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
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
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.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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
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 flushPendingLabels()
Create a dummy fragment to assign any pending labels.
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
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.
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 setHasData(bool Value)
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 EmitCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context) override
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.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
MCAssembler & getAssembler()
MCFixupKind
Extensible enumeration to represent the type of a fixup.
SmallVectorImpl< MCFixup > & getFixups()
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 handleCodePaddingInstructionBegin(const MCInst &Inst)
Handles all target related code padding before writing a new instruction to an object file...
void setOffset(uint64_t Value)
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
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.
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.
MCPaddingFragment * getOrCreatePaddingFragment()
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
void EmitCFISections(bool EH, bool Debug) override
void handleCodePaddingBasicBlockStart(MCObjectStreamer *OS, const MCCodePaddingContext &Context)
Handles all target related code padding when starting to write a new basic block to an object file...
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
const MCSymbol & getSymbol() const
MCFragment * getFragment(bool SetUsed=true) const
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 addFileName(StringRef FileName)
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
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.
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...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
iterator insert(iterator where, pointer New)
unsigned getNumFrameInfos()
void EmitBundleUnlock() override
Ends a bundle-locked group.
void emplace_back(ArgTypes &&... Args)
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 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()
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 EmitULEB128IntValue(uint64_t Value)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
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.
void setParent(MCSection *Value)
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.
MCSection::FragmentListType & getFragmentList()
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.
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool=false) override
Emit the given Instruction into the current section.