LLVM 22.0.0git
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | 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:
[legend]

Public Member Functions

 MCAsmBackend (const MCAsmBackend &)=delete
 
MCAsmBackendoperator= (const MCAsmBackend &)=delete
 
virtual ~MCAsmBackend ()
 
void setAssembler (MCAssembler *A)
 
MCContextgetContext () const
 
bool allowAutoPadding () const
 Return true if this target might automatically pad instructions and thus need to emit padding enable/disable directives around sensative code.
 
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 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 bool finishLayout (const MCAssembler &Asm) const
 
virtual uint64_t generateCompactUnwindEncoding (const MCDwarfFrameInfo *FI, const MCContext *Ctxt) const
 Generate the compact unwind encoding for the CFI instructions.
 
bool isDarwinCanonicalPersonality (const MCSymbol *Sym) const
 
Target Fixup Interfaces
virtual std::optional< MCFixupKindgetFixupKind (StringRef Name) const
 Map a relocation name used in .reloc to a fixup kind.
 
virtual MCFixupKindInfo getFixupKindInfo (MCFixupKind Kind) const
 Get information on a fixup kind.
 
virtual std::optional< boolevaluateFixup (const MCFragment &, MCFixup &, MCValue &, uint64_t &)
 
void maybeAddReloc (const MCFragment &, const MCFixup &, const MCValue &, uint64_t &Value, bool IsResolved)
 
virtual void applyFixup (const MCFragment &, const MCFixup &, const MCValue &Target, uint8_t *Data, uint64_t Value, bool IsResolved)=0
 
Target Relaxation Interfaces
virtual bool mayNeedRelaxation (unsigned Opcode, ArrayRef< MCOperand > Operands, const MCSubtargetInfo &STI) const
 Check whether the given instruction (encoded as Opcode+Operands) may need relaxation.
 
virtual bool fixupNeedsRelaxationAdvanced (const MCFragment &, const MCFixup &, const MCValue &, uint64_t, bool Resolved) 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
 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 relaxAlign (MCFragment &F, unsigned &Size)
 
virtual bool relaxDwarfLineAddr (MCFragment &) const
 
virtual bool relaxDwarfCFA (MCFragment &) const
 
virtual std::pair< bool, boolrelaxLEB128 (MCFragment &, int64_t &Value) const
 

Static Public Member Functions

static const MCSubtargetInfogetSubtargetInfo (const MCFragment &F)
 

Public Attributes

const llvm::endianness Endian
 

Protected Member Functions

 MCAsmBackend (llvm::endianness Endian)
 

Protected Attributes

MCAssemblerAsm = nullptr
 
bool AllowAutoPadding = false
 
bool AllowEnhancedRelaxation = false
 

Detailed Description

Generic interface to target specific assembler backends.

Definition at line 55 of file MCAsmBackend.h.

Constructor & Destructor Documentation

◆ MCAsmBackend() [1/2]

llvm::MCAsmBackend::MCAsmBackend ( llvm::endianness  Endian)
inlineprotected

Definition at line 57 of file MCAsmBackend.h.

◆ MCAsmBackend() [2/2]

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

◆ ~MCAsmBackend()

MCAsmBackend::~MCAsmBackend ( )
virtualdefault

Member Function Documentation

◆ allowAutoPadding()

bool llvm::MCAsmBackend::allowAutoPadding ( ) const
inline

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

Definition at line 77 of file MCAsmBackend.h.

◆ allowEnhancedRelaxation()

bool llvm::MCAsmBackend::allowEnhancedRelaxation ( ) const
inline

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 81 of file MCAsmBackend.h.

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

◆ applyFixup()

virtual void llvm::MCAsmBackend::applyFixup ( const MCFragment ,
const MCFixup ,
const MCValue Target,
uint8_t Data,
uint64_t  Value,
bool  IsResolved 
)
pure virtual

◆ 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 66 of file MCAsmBackend.cpp.

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

Referenced by llvm::CodeGenTargetMachineImpl::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

◆ evaluateFixup()

virtual std::optional< bool > llvm::MCAsmBackend::evaluateFixup ( const MCFragment ,
MCFixup ,
MCValue ,
uint64_t  
)
inlinevirtual

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

Definition at line 112 of file MCAsmBackend.h.

◆ finishLayout()

virtual bool llvm::MCAsmBackend::finishLayout ( const MCAssembler Asm) const
inlinevirtual

Definition at line 202 of file MCAsmBackend.h.

◆ fixupNeedsRelaxation()

virtual bool llvm::MCAsmBackend::fixupNeedsRelaxation ( const MCFixup Fixup,
uint64_t  Value 
) const
inlinevirtual

Simple predicate for targets where !Resolved implies requiring relaxation.

Reimplemented in llvm::CSKYAsmBackend.

Definition at line 147 of file MCAsmBackend.h.

References llvm_unreachable.

Referenced by fixupNeedsRelaxationAdvanced().

◆ fixupNeedsRelaxationAdvanced()

bool MCAsmBackend::fixupNeedsRelaxationAdvanced ( const MCFragment ,
const MCFixup Fixup,
const MCValue ,
uint64_t  Value,
bool  Resolved 
) const
virtual

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

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

Definition at line 109 of file MCAsmBackend.cpp.

References Fixup, and fixupNeedsRelaxation().

◆ generateCompactUnwindEncoding()

virtual uint64_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 205 of file MCAsmBackend.h.

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

◆ getContext()

MCContext & MCAsmBackend::getContext ( ) const

◆ getFixupKind()

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

Map a relocation name used in .reloc to a fixup kind.

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

Definition at line 85 of file MCAsmBackend.cpp.

Referenced by llvm::MipsAsmBackend::getFixupKind().

◆ getFixupKindInfo()

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 189 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 185 of file MCAsmBackend.h.

◆ getSubtargetInfo()

const MCSubtargetInfo * MCAsmBackend::getSubtargetInfo ( const MCFragment F)
static

Definition at line 139 of file MCAsmBackend.cpp.

References assert(), and F.

Referenced by llvm::ARMAsmBackend::applyFixup().

◆ isDarwinCanonicalPersonality()

bool MCAsmBackend::isDarwinCanonicalPersonality ( const MCSymbol Sym) const

Definition at line 125 of file MCAsmBackend.cpp.

References assert(), getContext(), name, and Sym.

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

◆ maybeAddReloc()

void MCAsmBackend::maybeAddReloc ( const MCFragment F,
const MCFixup Fixup,
const MCValue Target,
uint64_t Value,
bool  IsResolved 
)

◆ mayNeedRelaxation()

virtual bool llvm::MCAsmBackend::mayNeedRelaxation ( unsigned  Opcode,
ArrayRef< MCOperand Operands,
const MCSubtargetInfo STI 
) const
inlinevirtual

Check whether the given instruction (encoded as Opcode+Operands) may need relaxation.

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

Definition at line 135 of file MCAsmBackend.h.

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

◆ operator=()

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

◆ relaxAlign()

virtual bool llvm::MCAsmBackend::relaxAlign ( MCFragment F,
unsigned Size 
)
inlinevirtual

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

Definition at line 168 of file MCAsmBackend.h.

◆ relaxDwarfCFA()

virtual bool llvm::MCAsmBackend::relaxDwarfCFA ( MCFragment ) const
inlinevirtual

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

Definition at line 170 of file MCAsmBackend.h.

◆ relaxDwarfLineAddr()

virtual bool llvm::MCAsmBackend::relaxDwarfLineAddr ( MCFragment ) const
inlinevirtual

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

Definition at line 169 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, and llvm::RISCVAsmBackend.

Definition at line 157 of file MCAsmBackend.h.

References llvm_unreachable.

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

◆ relaxLEB128()

virtual std::pair< bool, bool > llvm::MCAsmBackend::relaxLEB128 ( MCFragment ,
int64_t &  Value 
) const
inlinevirtual

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

Definition at line 174 of file MCAsmBackend.h.

◆ reset()

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

lifetime management

Definition at line 84 of file MCAsmBackend.h.

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

◆ setAssembler()

void llvm::MCAsmBackend::setAssembler ( MCAssembler A)
inline

Definition at line 71 of file MCAsmBackend.h.

References A.

◆ 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, and llvm::RISCVAsmBackend.

Member Data Documentation

◆ AllowAutoPadding

bool llvm::MCAsmBackend::AllowAutoPadding = false
protected

Definition at line 61 of file MCAsmBackend.h.

◆ AllowEnhancedRelaxation

bool llvm::MCAsmBackend::AllowEnhancedRelaxation = false
protected

Definition at line 62 of file MCAsmBackend.h.

◆ Asm

MCAssembler* llvm::MCAsmBackend::Asm = nullptr
protected

◆ Endian

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

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