37#define DEBUG_TYPE "mccodeemitter"
39STATISTIC(MCNumEmitted,
"Number of MC instructions emitted");
49 SparcMCCodeEmitter(
const SparcMCCodeEmitter &) =
delete;
50 SparcMCCodeEmitter &
operator=(
const SparcMCCodeEmitter &) =
delete;
51 ~SparcMCCodeEmitter()
override =
default;
68 unsigned getCallTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
74 unsigned getSImm5OpValue(
const MCInst &
MI,
unsigned OpNo,
77 unsigned getSImm13OpValue(
const MCInst &
MI,
unsigned OpNo,
80 unsigned getBranchPredTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
83 unsigned getBranchOnRegTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
86 unsigned getCompareAndBranchTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
97 case ELF::R_SPARC_PC10:
98 case ELF::R_SPARC_PC22:
99 case ELF::R_SPARC_WDISP10:
100 case ELF::R_SPARC_WDISP16:
101 case ELF::R_SPARC_WDISP19:
102 case ELF::R_SPARC_WDISP22:
109void SparcMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
113 unsigned Bits = getBinaryCodeForInstr(
MI, Fixups, STI);
115 Ctx.getAsmInfo()->isLittleEndian()
120 unsigned SymOpNo = 0;
121 switch (
MI.getOpcode()) {
123 case SP::TLS_CALL: SymOpNo = 1;
break;
128 case SP::TLS_LDXrr: SymOpNo = 3;
break;
133 assert(
op == 0 &&
"Unexpected operand value!");
140unsigned SparcMCCodeEmitter::
145 return Ctx.getRegisterInfo()->getEncodingValue(MO.
getReg());
152 if (
auto *SExpr = dyn_cast<MCSpecifierExpr>(Expr)) {
153 addFixup(Fixups, 0, Expr, SExpr->getSpecifier());
158 if (Expr->evaluateAsAbsolute(Res))
165unsigned SparcMCCodeEmitter::getSImm5OpValue(
const MCInst &
MI,
unsigned OpNo,
174 "getSImm5OpValue expects only expressions or an immediate");
180 return CE->getValue();
182 if (
auto *SExpr = dyn_cast<MCSpecifierExpr>(Expr)) {
183 addFixup(Fixups, 0, Expr, SExpr->getSpecifier());
186 addFixup(Fixups, 0, Expr, ELF::R_SPARC_5);
191SparcMCCodeEmitter::getSImm13OpValue(
const MCInst &
MI,
unsigned OpNo,
200 "getSImm13OpValue expects only expressions or an immediate");
206 return CE->getValue();
208 if (
auto *SExpr = dyn_cast<MCSpecifierExpr>(Expr)) {
209 addFixup(Fixups, 0, Expr, SExpr->getSpecifier());
216unsigned SparcMCCodeEmitter::
217getCallTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
220 if (
MI.getOpcode() == SP::TLS_CALL) {
231unsigned SparcMCCodeEmitter::
232getBranchTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
237 return getMachineOpValue(
MI, MO, Fixups, STI);
243unsigned SparcMCCodeEmitter::getBranchPredTargetOpValue(
248 return getMachineOpValue(
MI, MO, Fixups, STI);
254unsigned SparcMCCodeEmitter::getBranchOnRegTargetOpValue(
259 return getMachineOpValue(
MI, MO, Fixups, STI);
265unsigned SparcMCCodeEmitter::getCompareAndBranchTargetOpValue(
270 return getMachineOpValue(
MI, MO, Fixups, STI);
276#include "SparcGenMCCodeEmitter.inc"
280 return new SparcMCCodeEmitter(MCII, Ctx);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static uint32_t getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx, unsigned FixupKind, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI)
getBranchTargetOpValue - Helper function to get the branch target operand, which is either an immedia...
This file defines the SmallVector class.
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
MCCodeEmitter - Generic instruction encoding interface.
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
Encode the given Inst to bytes and append to CB.
MCCodeEmitter & operator=(const MCCodeEmitter &)=delete
Context object for machine code objects.
Base class for the full range of assembler expressions which are needed for parsing.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
Instances of this class represent a single low-level machine instruction.
Interface to description of machine instruction set.
Instances of this class represent operands of the MCInst class.
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
Generic base class for all target subtargets.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ fixup_sparc_13
fixup_sparc_13 - 13-bit fixup
@ CE
Windows NT (Windows on ARM)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
This is an optimization pass for GlobalISel generic memory operations.
MCCodeEmitter * createSparcMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)