LLVM  8.0.1
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]
Collaboration diagram for llvm::MCAsmBackend:
Collaboration graph
[legend]

Public Member Functions

 MCAsmBackend (const MCAsmBackend &)=delete
 
MCAsmBackendoperator= (const MCAsmBackend &)=delete
 
virtual ~MCAsmBackend ()
 
virtual void reset ()
 lifetime management More...
 
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. More...
 
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. More...
 
virtual std::unique_ptr< MCObjectTargetWritercreateObjectTargetWriter () const =0
 
virtual unsigned getMinimumNopSize () const
 Returns the minimum size of a nop in bytes on this target. More...
 
virtual bool writeNopData (raw_ostream &OS, uint64_t Count) const =0
 Write an (optimal) nop sequence of Count bytes to the given output. More...
 
virtual void finishLayout (MCAssembler const &Asm, MCAsmLayout &Layout) const
 Give backend an opportunity to finish layout after relaxation. More...
 
virtual void handleAssemblerFlag (MCAssemblerFlag Flag)
 Handle any target-specific assembler flags. By default, do nothing. More...
 
virtual uint32_t generateCompactUnwindEncoding (ArrayRef< MCCFIInstruction >) const
 Generate the compact unwind encoding for the CFI instructions. More...
 
virtual bool isMicroMips (const MCSymbol *Sym) const
 Check whether a given symbol has been flagged with MICROMIPS flag. More...
 
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. More...
 
void handleCodePaddingBasicBlockEnd (const MCCodePaddingContext &Context)
 Handles all target related code padding after writing a block to an object file. More...
 
void handleCodePaddingInstructionBegin (const MCInst &Inst)
 Handles all target related code padding before writing a new instruction to an object file. More...
 
void handleCodePaddingInstructionEnd (const MCInst &Inst)
 Handles all target related code padding after writing an instruction to an object file. More...
 
bool relaxFragment (MCPaddingFragment *PF, MCAsmLayout &Layout)
 Relaxes a fragment (changes the size of the padding) according to target requirements. More...
 
Target Fixup Interfaces
virtual unsigned getNumFixupKinds () const =0
 Get the number of target specific fixup kinds. More...
 
virtual Optional< MCFixupKindgetFixupKind (StringRef Name) const
 Map a relocation name used in .reloc to a fixup kind. More...
 
virtual const MCFixupKindInfogetFixupKindInfo (MCFixupKind Kind) const
 Get information on a fixup kind. More...
 
virtual bool shouldForceRelocation (const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target)
 Hook to check if a relocation is needed for some target specific reason. More...
 
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. More...
 
virtual bool requiresDiffExpressionRelocations () const
 Check whether the given target requires emitting differences of two symbols as a set of relocations. More...
 
Target Relaxation Interfaces
virtual bool mayNeedRelaxation (const MCInst &Inst, const MCSubtargetInfo &STI) const =0
 Check whether the given instruction may need relaxation. More...
 
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. More...
 
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. More...
 
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. More...
 

Public Attributes

const support::endianness Endian
 

Protected Member Functions

 MCAsmBackend (support::endianness Endian)
 

Detailed Description

Generic interface to target specific assembler backends.

Definition at line 42 of file MCAsmBackend.h.

Constructor & Destructor Documentation

◆ MCAsmBackend() [1/2]

MCAsmBackend::MCAsmBackend ( support::endianness  Endian)
protected

Definition at line 26 of file MCAsmBackend.cpp.

References ~MCAsmBackend().

◆ MCAsmBackend() [2/2]

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

◆ ~MCAsmBackend()

MCAsmBackend::~MCAsmBackend ( )
virtualdefault

Referenced by MCAsmBackend().

Member Function Documentation

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

Referenced by llvm::MCAssembler::layout(), and shouldForceRelocation().

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

References llvm::createELFDwoObjectWriter(), createObjectTargetWriter(), llvm::Triple::ELF, Endian, llvm::support::little, and llvm::report_fatal_error().

Referenced by llvm::LLVMTargetMachine::addAsmPrinter(), and reset().

◆ createObjectTargetWriter()

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

◆ createObjectWriter()

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

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

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

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

Referenced by fixupNeedsRelaxationAdvanced(), and requiresDiffExpressionRelocations().

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

Definition at line 101 of file MCAsmBackend.cpp.

References fixupNeedsRelaxation().

Referenced by llvm::MCAssembler::Finish(), and requiresDiffExpressionRelocations().

◆ generateCompactUnwindEncoding()

virtual uint32_t llvm::MCAsmBackend::generateCompactUnwindEncoding ( ArrayRef< MCCFIInstruction ) const
inlinevirtual

Generate the compact unwind encoding for the CFI instructions.

Reimplemented in llvm::ARMAsmBackendDarwin.

Definition at line 164 of file MCAsmBackend.h.

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

◆ getFixupKind()

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

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

Reimplemented in llvm::MipsAsmBackend.

Definition at line 62 of file MCAsmBackend.cpp.

References llvm::None.

Referenced by llvm::MipsAsmBackend::getFixupKind(), getRelaxedOpcode(), and reset().

◆ getFixupKindInfo()

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

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

References writeNopData().

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

◆ getNumFixupKinds()

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

Get the number of target specific fixup kinds.

Implemented in llvm::RISCVAsmBackend, llvm::MipsAsmBackend, llvm::AVRAsmBackend, and llvm::ARMAsmBackend.

Referenced by reset().

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

Referenced by llvm::MCELFStreamer::EmitAssemblerFlag(), and llvm::MCWasmStreamer::EmitAssemblerFlag().

◆ handleCodePaddingBasicBlockEnd()

void MCAsmBackend::handleCodePaddingBasicBlockEnd ( const MCCodePaddingContext Context)

Handles all target related code padding after writing a block to an object file.

Parameters
Contextthe context of the padding, Embeds the basic block's parameters.

Definition at line 115 of file MCAsmBackend.cpp.

Referenced by llvm::MCObjectStreamer::EmitCodePaddingBasicBlockEnd(), and isMicroMips().

◆ handleCodePaddingBasicBlockStart()

void MCAsmBackend::handleCodePaddingBasicBlockStart ( MCObjectStreamer OS,
const MCCodePaddingContext Context 
)

Handles all target related code padding when starting to write a new basic block to an object file.

Parameters
OSThe streamer used for writing the padding data and function.
Contextthe context of the padding, Embeds the basic block's parameters.

Definition at line 110 of file MCAsmBackend.cpp.

Referenced by llvm::MCObjectStreamer::EmitCodePaddingBasicBlockStart(), and isMicroMips().

◆ handleCodePaddingInstructionBegin()

void MCAsmBackend::handleCodePaddingInstructionBegin ( const MCInst Inst)

Handles all target related code padding before writing a new instruction to an object file.

Parameters
Instthe instruction.

Definition at line 120 of file MCAsmBackend.cpp.

Referenced by llvm::MCObjectStreamer::EmitInstruction(), and isMicroMips().

◆ handleCodePaddingInstructionEnd()

void MCAsmBackend::handleCodePaddingInstructionEnd ( const MCInst Inst)

Handles all target related code padding after writing an instruction to an object file.

Parameters
Instthe instruction.

Definition at line 124 of file MCAsmBackend.cpp.

Referenced by llvm::MCObjectStreamer::EmitInstruction(), and isMicroMips().

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

References Context, handleCodePaddingBasicBlockEnd(), handleCodePaddingBasicBlockStart(), handleCodePaddingInstructionBegin(), handleCodePaddingInstructionEnd(), and relaxFragment().

◆ mayNeedRelaxation()

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

Check whether the given instruction may need relaxation.

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

Implemented in llvm::RISCVAsmBackend, llvm::MipsAsmBackend, llvm::ARMAsmBackend, and llvm::AVRAsmBackend.

Referenced by llvm::MCObjectStreamer::EmitInstruction(), and requiresDiffExpressionRelocations().

◆ operator=()

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

◆ relaxFragment()

bool MCAsmBackend::relaxFragment ( MCPaddingFragment PF,
MCAsmLayout Layout 
)

Relaxes a fragment (changes the size of the padding) according to target requirements.

The new size computation is done w.r.t a layout.

Parameters
PFThe fragment to relax.
LayoutCode layout information.
Returns
true iff any relaxation occurred.

Definition at line 128 of file MCAsmBackend.cpp.

Referenced by isMicroMips().

◆ relaxInstruction()

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

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

Parameters
InstThe instruction to relax, which may be the same as the output.
STIthe subtarget information for the associated instruction.
[out]ResOn return, the relaxed instruction.

Implemented in llvm::RISCVAsmBackend, llvm::MipsAsmBackend, llvm::ARMAsmBackend, and llvm::AVRAsmBackend.

Referenced by llvm::MCObjectStreamer::EmitInstruction(), llvm::MCAssembler::Finish(), and requiresDiffExpressionRelocations().

◆ requiresDiffExpressionRelocations()

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

Check whether the given target requires emitting differences of two symbols as a set of relocations.

Reimplemented in llvm::RISCVAsmBackend.

Definition at line 104 of file MCAsmBackend.h.

References fixupNeedsRelaxation(), fixupNeedsRelaxationAdvanced(), mayNeedRelaxation(), and relaxInstruction().

Referenced by absoluteSymbolDiff().

◆ reset()

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

◆ shouldForceRelocation()

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

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

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

Definition at line 85 of file MCAsmBackend.h.

References applyFixup(), llvm::HexStyle::Asm, llvm::Data, and Fixup.

◆ writeNopData()

virtual bool llvm::MCAsmBackend::writeNopData ( raw_ostream OS,
uint64_t  Count 
) 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::RISCVAsmBackend, llvm::MipsAsmBackend, llvm::ARMAsmBackend, and llvm::AVRAsmBackend.

Referenced by getMinimumNopSize().

Member Data Documentation

◆ Endian

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

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