LLVM 19.0.0git
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
llvm::MCAsmBackend Class Referenceabstract

Generic interface to target specific assembler backends. More...

#include "llvm/MC/MCAsmBackend.h"

Inheritance diagram for llvm::MCAsmBackend:
Inheritance graph
[legend]

Public Member Functions

 MCAsmBackend (const MCAsmBackend &)=delete
 
MCAsmBackendoperator= (const MCAsmBackend &)=delete
 
virtual ~MCAsmBackend ()
 
virtual bool allowAutoPadding () const
 Return true if this target might automatically pad instructions and thus need to emit padding enable/disable directives around sensative code.
 
virtual bool allowEnhancedRelaxation () const
 Return true if this target allows an unrelaxable instruction to be emitted into RelaxableFragment and then we can increase its size in a tricky way for optimization.
 
virtual void emitInstructionBegin (MCObjectStreamer &OS, const MCInst &Inst, const MCSubtargetInfo &STI)
 Give the target a chance to manipulate state related to instruction alignment (e.g.
 
virtual void emitInstructionEnd (MCObjectStreamer &OS, const MCInst &Inst)
 
virtual void reset ()
 lifetime management
 
std::unique_ptr< MCObjectWritercreateObjectWriter (raw_pwrite_stream &OS) const
 Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file.
 
std::unique_ptr< MCObjectWritercreateDwoObjectWriter (raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS) const
 Create an MCObjectWriter that writes two object files: a .o file which is linked into the final program and a .dwo file which is used by debuggers.
 
virtual std::unique_ptr< MCObjectTargetWritercreateObjectTargetWriter () const =0
 
virtual unsigned getMinimumNopSize () const
 Returns the minimum size of a nop in bytes on this target.
 
virtual unsigned getMaximumNopSize (const MCSubtargetInfo &STI) const
 Returns the maximum size of a nop in bytes on this target.
 
virtual bool writeNopData (raw_ostream &OS, uint64_t Count, const MCSubtargetInfo *STI) const =0
 Write an (optimal) nop sequence of Count bytes to the given output.
 
virtual void finishLayout (MCAssembler const &Asm, MCAsmLayout &Layout) const
 Give backend an opportunity to finish layout after relaxation.
 
virtual void handleAssemblerFlag (MCAssemblerFlag Flag)
 Handle any target-specific assembler flags. By default, do nothing.
 
virtual uint32_t generateCompactUnwindEncoding (const MCDwarfFrameInfo *FI, const MCContext *Ctxt) const
 Generate the compact unwind encoding for the CFI instructions.
 
virtual bool isMicroMips (const MCSymbol *Sym) const
 Check whether a given symbol has been flagged with MICROMIPS flag.
 
bool isDarwinCanonicalPersonality (const MCSymbol *Sym) const
 
Target Fixup Interfaces
virtual unsigned getNumFixupKinds () const =0
 Get the number of target specific fixup kinds.
 
virtual std::optional< MCFixupKindgetFixupKind (StringRef Name) const
 Map a relocation name used in .reloc to a fixup kind.
 
virtual const MCFixupKindInfogetFixupKindInfo (MCFixupKind Kind) const
 Get information on a fixup kind.
 
virtual bool shouldForceRelocation (const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, const MCSubtargetInfo *STI)
 Hook to check if a relocation is needed for some target specific reason.
 
virtual bool shouldInsertExtraNopBytesForCodeAlign (const MCAlignFragment &AF, unsigned &Size)
 Hook to check if extra nop bytes must be inserted for alignment directive.
 
virtual bool shouldInsertFixupForCodeAlign (MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF)
 Hook which indicates if the target requires a fixup to be generated when handling an align directive in an executable section.
 
virtual bool evaluateTargetFixup (const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFixup &Fixup, const MCFragment *DF, const MCValue &Target, const MCSubtargetInfo *STI, uint64_t &Value, bool &WasForced)
 
virtual bool handleAddSubRelocations (const MCAsmLayout &Layout, const MCFragment &F, const MCFixup &Fixup, const MCValue &Target, uint64_t &FixedValue) const
 
virtual void applyFixup (const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const =0
 Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup and following the fixup kind as appropriate.
 
Target Relaxation Interfaces
virtual bool mayNeedRelaxation (const MCInst &Inst, const MCSubtargetInfo &STI) const
 Check whether the given instruction may need relaxation.
 
virtual bool fixupNeedsRelaxationAdvanced (const MCFixup &Fixup, bool Resolved, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout, const bool WasForced) const
 Target specific predicate for whether a given fixup requires the associated instruction to be relaxed.
 
virtual bool fixupNeedsRelaxation (const MCFixup &Fixup, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout) const =0
 Simple predicate for targets where !Resolved implies requiring relaxation.
 
virtual void relaxInstruction (MCInst &Inst, const MCSubtargetInfo &STI) const
 Relax the instruction in the given fragment to the next wider instruction.
 
virtual bool relaxDwarfLineAddr (MCDwarfLineAddrFragment &DF, MCAsmLayout &Layout, bool &WasRelaxed) const
 
virtual bool relaxDwarfCFA (MCDwarfCallFrameFragment &DF, MCAsmLayout &Layout, bool &WasRelaxed) const
 
virtual std::pair< bool, boolrelaxLEB128 (MCLEBFragment &LF, MCAsmLayout &Layout, int64_t &Value) const
 

Public Attributes

const llvm::endianness Endian
 
const unsigned RelaxFixupKind
 Fixup kind used for linker relaxation. Currently only used by RISC-V.
 

Protected Member Functions

 MCAsmBackend (llvm::endianness Endian, unsigned RelaxFixupKind=MaxFixupKind)
 

Detailed Description

Generic interface to target specific assembler backends.

Definition at line 43 of file MCAsmBackend.h.

Constructor & Destructor Documentation

◆ MCAsmBackend() [1/2]

MCAsmBackend::MCAsmBackend ( llvm::endianness  Endian,
unsigned  RelaxFixupKind = MaxFixupKind 
)
protected

Definition at line 26 of file MCAsmBackend.cpp.

References Endian.

◆ MCAsmBackend() [2/2]

llvm::MCAsmBackend::MCAsmBackend ( const MCAsmBackend )
delete

◆ ~MCAsmBackend()

MCAsmBackend::~MCAsmBackend ( )
virtualdefault

Member Function Documentation

◆ allowAutoPadding()

virtual bool llvm::MCAsmBackend::allowAutoPadding ( ) const
inlinevirtual

Return true if this target might automatically pad instructions and thus need to emit padding enable/disable directives around sensative code.

Definition at line 59 of file MCAsmBackend.h.

◆ allowEnhancedRelaxation()

virtual bool llvm::MCAsmBackend::allowEnhancedRelaxation ( ) const
inlinevirtual

Return true if this target allows an unrelaxable instruction to be emitted into RelaxableFragment and then we can increase its size in a tricky way for optimization.

Definition at line 63 of file MCAsmBackend.h.

◆ applyFixup()

virtual void llvm::MCAsmBackend::applyFixup ( const MCAssembler Asm,
const MCFixup Fixup,
const MCValue Target,
MutableArrayRef< char Data,
uint64_t  Value,
bool  IsResolved,
const MCSubtargetInfo STI 
) const
pure virtual

Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup and following the fixup kind as appropriate.

Errors (such as an out of range fixup value) should be reported via Ctx. The STI is present only for fragments of type MCRelaxableFragment and MCDataFragment with hasInstructions() == true.

Implemented in llvm::ARMAsmBackend, llvm::AVRAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::MipsAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.

Referenced by llvm::MCAssembler::layout().

◆ createDwoObjectWriter()

std::unique_ptr< MCObjectWriter > MCAsmBackend::createDwoObjectWriter ( raw_pwrite_stream OS,
raw_pwrite_stream DwoOS 
) const

Create an MCObjectWriter that writes two object files: a .o file which is linked into the final program and a .dwo file which is used by debuggers.

This function is only supported with ELF targets.

Definition at line 65 of file MCAsmBackend.cpp.

References llvm::Triple::COFF, llvm::createELFDwoObjectWriter(), createObjectTargetWriter(), llvm::createWasmDwoObjectWriter(), llvm::createWinCOFFDwoObjectWriter(), llvm::Triple::ELF, Endian, llvm::little, OS, llvm::report_fatal_error(), and llvm::Triple::Wasm.

Referenced by llvm::LLVMTargetMachine::createMCStreamer().

◆ createObjectTargetWriter()

virtual std::unique_ptr< MCObjectTargetWriter > llvm::MCAsmBackend::createObjectTargetWriter ( ) const
pure virtual

◆ createObjectWriter()

std::unique_ptr< MCObjectWriter > MCAsmBackend::createObjectWriter ( raw_pwrite_stream OS) const

◆ emitInstructionBegin()

virtual void llvm::MCAsmBackend::emitInstructionBegin ( MCObjectStreamer OS,
const MCInst Inst,
const MCSubtargetInfo STI 
)
inlinevirtual

Give the target a chance to manipulate state related to instruction alignment (e.g.

padding for optimization), instruction relaxablility, etc. before and after actually emitting the instruction.

Definition at line 68 of file MCAsmBackend.h.

Referenced by llvm::MCObjectStreamer::emitInstruction().

◆ emitInstructionEnd()

virtual void llvm::MCAsmBackend::emitInstructionEnd ( MCObjectStreamer OS,
const MCInst Inst 
)
inlinevirtual

Definition at line 70 of file MCAsmBackend.h.

Referenced by llvm::MCObjectStreamer::emitInstruction().

◆ evaluateTargetFixup()

virtual bool llvm::MCAsmBackend::evaluateTargetFixup ( const MCAssembler Asm,
const MCAsmLayout Layout,
const MCFixup Fixup,
const MCFragment DF,
const MCValue Target,
const MCSubtargetInfo STI,
uint64_t Value,
bool WasForced 
)
inlinevirtual

Reimplemented in llvm::RISCVAsmBackend.

Definition at line 125 of file MCAsmBackend.h.

References llvm_unreachable.

◆ finishLayout()

virtual void llvm::MCAsmBackend::finishLayout ( MCAssembler const Asm,
MCAsmLayout Layout 
) const
inlinevirtual

Give backend an opportunity to finish layout after relaxation.

Definition at line 228 of file MCAsmBackend.h.

◆ fixupNeedsRelaxation()

virtual bool llvm::MCAsmBackend::fixupNeedsRelaxation ( const MCFixup Fixup,
uint64_t  Value,
const MCRelaxableFragment DF,
const MCAsmLayout Layout 
) const
pure virtual

Simple predicate for targets where !Resolved implies requiring relaxation.

Implemented in llvm::ARMAsmBackend, llvm::AVRAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::MipsAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.

Referenced by fixupNeedsRelaxationAdvanced().

◆ fixupNeedsRelaxationAdvanced()

bool MCAsmBackend::fixupNeedsRelaxationAdvanced ( const MCFixup Fixup,
bool  Resolved,
uint64_t  Value,
const MCRelaxableFragment DF,
const MCAsmLayout Layout,
const bool  WasForced 
) const
virtual

Target specific predicate for whether a given fixup requires the associated instruction to be relaxed.

Reimplemented in llvm::CSKYAsmBackend, and llvm::RISCVAsmBackend.

Definition at line 118 of file MCAsmBackend.cpp.

References DF, Fixup, and fixupNeedsRelaxation().

◆ generateCompactUnwindEncoding()

virtual uint32_t llvm::MCAsmBackend::generateCompactUnwindEncoding ( const MCDwarfFrameInfo FI,
const MCContext Ctxt 
) const
inlinevirtual

Generate the compact unwind encoding for the CFI instructions.

Reimplemented in llvm::ARMAsmBackendDarwin.

Definition at line 235 of file MCAsmBackend.h.

Referenced by llvm::MCStreamer::generateCompactUnwindEncodings().

◆ getFixupKind()

std::optional< MCFixupKind > MCAsmBackend::getFixupKind ( StringRef  Name) const
virtual

◆ getFixupKindInfo()

const MCFixupKindInfo & MCAsmBackend::getFixupKindInfo ( MCFixupKind  Kind) const
virtual

◆ getMaximumNopSize()

virtual unsigned llvm::MCAsmBackend::getMaximumNopSize ( const MCSubtargetInfo STI) const
inlinevirtual

Returns the maximum size of a nop in bytes on this target.

Definition at line 216 of file MCAsmBackend.h.

◆ getMinimumNopSize()

virtual unsigned llvm::MCAsmBackend::getMinimumNopSize ( ) const
inlinevirtual

Returns the minimum size of a nop in bytes on this target.

The assembler will use this to emit excess padding in situations where the padding required for simple alignment would be less than the minimum nop size.

Definition at line 212 of file MCAsmBackend.h.

◆ getNumFixupKinds()

virtual unsigned llvm::MCAsmBackend::getNumFixupKinds ( ) const
pure virtual

◆ handleAddSubRelocations()

virtual bool llvm::MCAsmBackend::handleAddSubRelocations ( const MCAsmLayout Layout,
const MCFragment F,
const MCFixup Fixup,
const MCValue Target,
uint64_t FixedValue 
) const
inlinevirtual

Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.

Definition at line 134 of file MCAsmBackend.h.

◆ handleAssemblerFlag()

virtual void llvm::MCAsmBackend::handleAssemblerFlag ( MCAssemblerFlag  Flag)
inlinevirtual

Handle any target-specific assembler flags. By default, do nothing.

Reimplemented in llvm::ARMAsmBackend.

Definition at line 232 of file MCAsmBackend.h.

Referenced by llvm::MCELFStreamer::emitAssemblerFlag(), llvm::MCWasmStreamer::emitAssemblerFlag(), and llvm::MCWinCOFFStreamer::emitAssemblerFlag().

◆ isDarwinCanonicalPersonality()

bool MCAsmBackend::isDarwinCanonicalPersonality ( const MCSymbol Sym) const

Definition at line 127 of file MCAsmBackend.cpp.

References llvm_unreachable, name, and Sym.

Referenced by llvm::ARMAsmBackendDarwin::generateCompactUnwindEncoding().

◆ isMicroMips()

virtual bool llvm::MCAsmBackend::isMicroMips ( const MCSymbol Sym) const
inlinevirtual

Check whether a given symbol has been flagged with MICROMIPS flag.

Reimplemented in llvm::MipsAsmBackend.

Definition at line 241 of file MCAsmBackend.h.

◆ mayNeedRelaxation()

virtual bool llvm::MCAsmBackend::mayNeedRelaxation ( const MCInst Inst,
const MCSubtargetInfo STI 
) const
inlinevirtual

Check whether the given instruction may need relaxation.

Parameters
Inst- The instruction to test.
STI- The MCSubtargetInfo in effect when the instruction was encoded.

Reimplemented in llvm::ARMAsmBackend, llvm::CSKYAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.

Definition at line 163 of file MCAsmBackend.h.

◆ operator=()

MCAsmBackend & llvm::MCAsmBackend::operator= ( const MCAsmBackend )
delete

◆ relaxDwarfCFA()

virtual bool llvm::MCAsmBackend::relaxDwarfCFA ( MCDwarfCallFrameFragment DF,
MCAsmLayout Layout,
bool WasRelaxed 
) const
inlinevirtual

Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.

Definition at line 194 of file MCAsmBackend.h.

◆ relaxDwarfLineAddr()

virtual bool llvm::MCAsmBackend::relaxDwarfLineAddr ( MCDwarfLineAddrFragment DF,
MCAsmLayout Layout,
bool WasRelaxed 
) const
inlinevirtual

Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.

Definition at line 189 of file MCAsmBackend.h.

◆ relaxInstruction()

virtual void llvm::MCAsmBackend::relaxInstruction ( MCInst Inst,
const MCSubtargetInfo STI 
) const
inlinevirtual

Relax the instruction in the given fragment to the next wider instruction.

Parameters
[out]InstThe instruction to relax, which is also the relaxed instruction.
STIthe subtarget information for the associated instruction.

Reimplemented in llvm::ARMAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.

Definition at line 186 of file MCAsmBackend.h.

◆ relaxLEB128()

virtual std::pair< bool, bool > llvm::MCAsmBackend::relaxLEB128 ( MCLEBFragment LF,
MCAsmLayout Layout,
int64_t &  Value 
) const
inlinevirtual

Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.

Definition at line 202 of file MCAsmBackend.h.

◆ reset()

virtual void llvm::MCAsmBackend::reset ( )
inlinevirtual

lifetime management

Definition at line 73 of file MCAsmBackend.h.

Referenced by llvm::MCAssembler::reset().

◆ shouldForceRelocation()

virtual bool llvm::MCAsmBackend::shouldForceRelocation ( const MCAssembler Asm,
const MCFixup Fixup,
const MCValue Target,
const MCSubtargetInfo STI 
)
inlinevirtual

Hook to check if a relocation is needed for some target specific reason.

Reimplemented in llvm::ARMAsmBackend, llvm::AVRAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::MipsAsmBackend, and llvm::RISCVAsmBackend.

Definition at line 102 of file MCAsmBackend.h.

◆ shouldInsertExtraNopBytesForCodeAlign()

virtual bool llvm::MCAsmBackend::shouldInsertExtraNopBytesForCodeAlign ( const MCAlignFragment AF,
unsigned Size 
)
inlinevirtual

Hook to check if extra nop bytes must be inserted for alignment directive.

For some targets this may be necessary in order to support linker relaxation. The number of bytes to insert are returned in Size.

Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.

Definition at line 112 of file MCAsmBackend.h.

◆ shouldInsertFixupForCodeAlign()

virtual bool llvm::MCAsmBackend::shouldInsertFixupForCodeAlign ( MCAssembler Asm,
const MCAsmLayout Layout,
MCAlignFragment AF 
)
inlinevirtual

Hook which indicates if the target requires a fixup to be generated when handling an align directive in an executable section.

Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.

Definition at line 119 of file MCAsmBackend.h.

Referenced by llvm::MCAssembler::layout().

◆ writeNopData()

virtual bool llvm::MCAsmBackend::writeNopData ( raw_ostream OS,
uint64_t  Count,
const MCSubtargetInfo STI 
) const
pure virtual

Write an (optimal) nop sequence of Count bytes to the given output.

If the target cannot generate such a sequence, it should return an error.

Returns
- True on success.

Implemented in llvm::ARMAsmBackend, llvm::AVRAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::MipsAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.

Member Data Documentation

◆ Endian

const llvm::endianness llvm::MCAsmBackend::Endian

◆ RelaxFixupKind

const unsigned llvm::MCAsmBackend::RelaxFixupKind

Fixup kind used for linker relaxation. Currently only used by RISC-V.

Definition at line 55 of file MCAsmBackend.h.


The documentation for this class was generated from the following files: