LLVM 20.0.0git
|
Generic interface to target specific assembler backends. More...
#include "llvm/MC/MCAsmBackend.h"
Public Member Functions | |
MCAsmBackend (const MCAsmBackend &)=delete | |
MCAsmBackend & | operator= (const MCAsmBackend &)=delete |
virtual | ~MCAsmBackend () |
bool | allowLinkerRelaxation () const |
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 | reset () |
lifetime management | |
std::unique_ptr< MCObjectWriter > | createObjectWriter (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< MCObjectWriter > | 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. | |
virtual std::unique_ptr< MCObjectTargetWriter > | createObjectTargetWriter () 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) 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 uint64_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< MCFixupKind > | getFixupKind (StringRef Name) const |
Map a relocation name used in .reloc to a fixup kind. | |
virtual const MCFixupKindInfo & | getFixupKindInfo (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, 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 MCFixup &Fixup, const MCFragment *DF, const MCValue &Target, const MCSubtargetInfo *STI, uint64_t &Value, bool &WasForced) |
virtual bool | handleAddSubRelocations (const MCAssembler &Asm, 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 MCAssembler &Asm, const MCFixup &Fixup, bool Resolved, uint64_t Value, const MCRelaxableFragment *DF, 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 |
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 (const MCAssembler &Asm, MCDwarfLineAddrFragment &DF, bool &WasRelaxed) const |
virtual bool | relaxDwarfCFA (const MCAssembler &Asm, MCDwarfCallFrameFragment &DF, bool &WasRelaxed) const |
virtual std::pair< bool, bool > | relaxLEB128 (const MCAssembler &Asm, MCLEBFragment &LF, int64_t &Value) const |
Public Attributes | |
const llvm::endianness | Endian |
const unsigned | RelaxFixupKind |
Fixup kind used for linker relaxation. | |
Protected Member Functions | |
MCAsmBackend (llvm::endianness Endian, unsigned RelaxFixupKind=MaxFixupKind) | |
Generic interface to target specific assembler backends.
Definition at line 42 of file MCAsmBackend.h.
|
protected |
Definition at line 27 of file MCAsmBackend.cpp.
References Endian.
|
delete |
|
virtualdefault |
|
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 60 of file MCAsmBackend.h.
|
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 64 of file MCAsmBackend.h.
|
inline |
Definition at line 56 of file MCAsmBackend.h.
References llvm::MaxFixupKind, and RelaxFixupKind.
|
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().
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 67 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::LLVMTargetMachine::createMCStreamer().
|
pure virtual |
Implemented in llvm::ARMAsmBackendDarwin, llvm::ARMAsmBackendELF, llvm::ARMAsmBackendWinCOFF, llvm::AVRAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::MipsAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.
Referenced by createDwoObjectWriter(), and createObjectWriter().
std::unique_ptr< MCObjectWriter > MCAsmBackend::createObjectWriter | ( | raw_pwrite_stream & | OS | ) | const |
Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file.
Definition at line 33 of file MCAsmBackend.cpp.
References llvm::Triple::COFF, llvm::createDXContainerObjectWriter(), llvm::createGOFFObjectWriter(), createObjectTargetWriter(), llvm::createSPIRVObjectWriter(), llvm::createWasmObjectWriter(), llvm::createWinCOFFObjectWriter(), llvm::createXCOFFObjectWriter(), llvm::Triple::DXContainer, llvm::Triple::ELF, Endian, llvm::Triple::GOFF, llvm::little, llvm_unreachable, llvm::Triple::MachO, OS, llvm::Triple::SPIRV, llvm::Triple::Wasm, and llvm::Triple::XCOFF.
Referenced by llvm::LLVMTargetMachine::addPassesToEmitMC(), llvm::LLVMTargetMachine::createMCStreamer(), llvm::dwarf_linker::classic::DwarfStreamer::init(), and llvm::dwarf_linker::parallel::DwarfEmitterImpl::init().
|
inlinevirtual |
Reimplemented in llvm::RISCVAsmBackend.
Definition at line 118 of file MCAsmBackend.h.
References llvm_unreachable.
|
inlinevirtual |
Give backend an opportunity to finish layout after relaxation.
Definition at line 223 of file MCAsmBackend.h.
Referenced by llvm::MCAssembler::layout().
|
inlinevirtual |
Simple predicate for targets where !Resolved implies requiring relaxation.
Reimplemented in llvm::ARMAsmBackend, and llvm::CSKYAsmBackend.
Definition at line 169 of file MCAsmBackend.h.
References llvm_unreachable.
Referenced by fixupNeedsRelaxationAdvanced().
|
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 120 of file MCAsmBackend.cpp.
References Fixup, and fixupNeedsRelaxation().
|
inlinevirtual |
Generate the compact unwind encoding for the CFI instructions.
Reimplemented in llvm::ARMAsmBackendDarwin.
Definition at line 229 of file MCAsmBackend.h.
Referenced by llvm::MCStreamer::generateCompactUnwindEncodings().
|
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 86 of file MCAsmBackend.cpp.
Referenced by llvm::MCObjectStreamer::emitRelocDirective(), llvm::MCXCOFFStreamer::emitXCOFFRefDirective(), and llvm::MipsAsmBackend::getFixupKind().
|
virtual |
Get information on a fixup kind.
Reimplemented in llvm::ARMAsmBackend, llvm::AVRAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::MipsAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.
Definition at line 90 of file MCAsmBackend.cpp.
References assert(), and llvm::MCFixupKindInfo::FKF_IsPCRel.
Referenced by llvm::ARMAsmBackend::getFixupKindInfo(), llvm::AVRAsmBackend::getFixupKindInfo(), llvm::CSKYAsmBackend::getFixupKindInfo(), llvm::LoongArchAsmBackend::getFixupKindInfo(), llvm::MipsAsmBackend::getFixupKindInfo(), llvm::RISCVAsmBackend::getFixupKindInfo(), llvm::XtensaMCAsmBackend::getFixupKindInfo(), and llvm::ELFObjectWriter::recordRelocation().
|
inlinevirtual |
Returns the maximum size of a nop in bytes on this target.
Definition at line 211 of file MCAsmBackend.h.
|
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 207 of file MCAsmBackend.h.
|
pure virtual |
Get the number of target specific fixup kinds.
Implemented in llvm::ARMAsmBackend, llvm::AVRAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::MipsAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.
|
inlinevirtual |
Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.
Definition at line 126 of file MCAsmBackend.h.
|
inlinevirtual |
Handle any target-specific assembler flags. By default, do nothing.
Reimplemented in llvm::ARMAsmBackend.
Definition at line 226 of file MCAsmBackend.h.
Referenced by llvm::MCELFStreamer::emitAssemblerFlag(), llvm::MCWasmStreamer::emitAssemblerFlag(), and llvm::MCWinCOFFStreamer::emitAssemblerFlag().
Definition at line 130 of file MCAsmBackend.cpp.
References llvm_unreachable, name, and Sym.
Referenced by llvm::ARMAsmBackendDarwin::generateCompactUnwindEncoding().
Check whether a given symbol has been flagged with MICROMIPS flag.
Reimplemented in llvm::MipsAsmBackend.
Definition at line 235 of file MCAsmBackend.h.
|
inlinevirtual |
Check whether the given instruction may need relaxation.
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 155 of file MCAsmBackend.h.
|
delete |
|
inlinevirtual |
Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.
Definition at line 188 of file MCAsmBackend.h.
|
inlinevirtual |
Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.
Definition at line 182 of file MCAsmBackend.h.
|
inlinevirtual |
Relax the instruction in the given fragment to the next wider instruction.
[out] | Inst | The instruction to relax, which is also the relaxed instruction. |
STI | the subtarget information for the associated instruction. |
Reimplemented in llvm::ARMAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.
Definition at line 179 of file MCAsmBackend.h.
|
inlinevirtual |
Reimplemented in llvm::LoongArchAsmBackend, and llvm::RISCVAsmBackend.
Definition at line 197 of file MCAsmBackend.h.
|
inlinevirtual |
lifetime management
Definition at line 67 of file MCAsmBackend.h.
Referenced by llvm::MCAssembler::reset().
|
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 96 of file MCAsmBackend.h.
|
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 106 of file MCAsmBackend.h.
|
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 113 of file MCAsmBackend.h.
Referenced by llvm::MCAssembler::layout().
|
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.
Implemented in llvm::ARMAsmBackend, llvm::AVRAsmBackend, llvm::CSKYAsmBackend, llvm::LoongArchAsmBackend, llvm::MipsAsmBackend, llvm::RISCVAsmBackend, and llvm::XtensaMCAsmBackend.
const llvm::endianness llvm::MCAsmBackend::Endian |
Definition at line 51 of file MCAsmBackend.h.
Referenced by llvm::ARMAsmBackend::adjustFixupValue(), llvm::ARMAsmBackend::applyFixup(), llvm::CSKYAsmBackend::applyFixup(), llvm::MipsAsmBackend::applyFixup(), createDwoObjectWriter(), createObjectWriter(), llvm::ARMAsmBackend::getFixupKindInfo(), llvm::MipsAsmBackend::getFixupKindInfo(), and llvm::ARMAsmBackend::writeNopData().
Fixup kind used for linker relaxation.
Currently only used by RISC-V and LoongArch.
Definition at line 55 of file MCAsmBackend.h.
Referenced by allowLinkerRelaxation().