36#define DEBUG_TYPE "mccodeemitter"
38STATISTIC(MCNumEmitted,
"Number of MC instructions emitted");
48 SparcMCCodeEmitter(
const SparcMCCodeEmitter &) =
delete;
49 SparcMCCodeEmitter &operator=(
const SparcMCCodeEmitter &) =
delete;
50 ~SparcMCCodeEmitter()
override =
default;
52 void encodeInstruction(
const MCInst &
MI, SmallVectorImpl<char> &CB,
53 SmallVectorImpl<MCFixup> &Fixups,
54 const MCSubtargetInfo &STI)
const override;
58 uint64_t getBinaryCodeForInstr(
const MCInst &
MI,
59 SmallVectorImpl<MCFixup> &Fixups,
60 const MCSubtargetInfo &STI)
const;
64 unsigned getMachineOpValue(
const MCInst &
MI,
const MCOperand &MO,
65 SmallVectorImpl<MCFixup> &Fixups,
66 const MCSubtargetInfo &STI)
const;
67 unsigned getCallTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
68 SmallVectorImpl<MCFixup> &Fixups,
69 const MCSubtargetInfo &STI)
const;
71 SmallVectorImpl<MCFixup> &Fixups,
72 const MCSubtargetInfo &STI)
const;
73 unsigned getSImm5OpValue(
const MCInst &
MI,
unsigned OpNo,
74 SmallVectorImpl<MCFixup> &Fixups,
75 const MCSubtargetInfo &STI)
const;
76 unsigned getSImm10OpValue(
const MCInst &
MI,
unsigned OpNo,
77 SmallVectorImpl<MCFixup> &Fixups,
78 const MCSubtargetInfo &STI)
const;
79 unsigned getSImm11OpValue(
const MCInst &
MI,
unsigned OpNo,
80 SmallVectorImpl<MCFixup> &Fixups,
81 const MCSubtargetInfo &STI)
const;
82 unsigned getSImm13OpValue(
const MCInst &
MI,
unsigned OpNo,
83 SmallVectorImpl<MCFixup> &Fixups,
84 const MCSubtargetInfo &STI)
const;
85 unsigned getImm22OpValue(
const MCInst &
MI,
unsigned OpNo,
86 SmallVectorImpl<MCFixup> &Fixups,
87 const MCSubtargetInfo &STI)
const;
88 unsigned getTrapNumOpValue(
const MCInst &
MI,
unsigned OpNo,
89 SmallVectorImpl<MCFixup> &Fixups,
90 const MCSubtargetInfo &STI)
const;
91 unsigned getBranchPredTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
92 SmallVectorImpl<MCFixup> &Fixups,
93 const MCSubtargetInfo &STI)
const;
94 unsigned getBranchOnRegTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
95 SmallVectorImpl<MCFixup> &Fixups,
96 const MCSubtargetInfo &STI)
const;
97 unsigned getCompareAndBranchTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
98 SmallVectorImpl<MCFixup> &Fixups,
99 const MCSubtargetInfo &STI)
const;
108 case ELF::R_SPARC_PC10:
109 case ELF::R_SPARC_PC22:
110 case ELF::R_SPARC_WDISP10:
111 case ELF::R_SPARC_WDISP16:
112 case ELF::R_SPARC_WDISP19:
113 case ELF::R_SPARC_WDISP22:
120void SparcMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
124 unsigned Bits = getBinaryCodeForInstr(
MI, Fixups, STI);
131 unsigned SymOpNo = 0;
132 switch (
MI.getOpcode()) {
134 case SP::TLS_CALL: SymOpNo = 1;
break;
139 case SP::TLS_LDXrr: SymOpNo = 3;
break;
142 const MCOperand &MO =
MI.getOperand(SymOpNo);
144 assert(
op == 0 &&
"Unexpected operand value!");
151unsigned SparcMCCodeEmitter::
152getMachineOpValue(
const MCInst &
MI,
const MCOperand &MO,
153 SmallVectorImpl<MCFixup> &Fixups,
154 const MCSubtargetInfo &STI)
const {
162 const MCExpr *Expr = MO.
getExpr();
164 addFixup(Fixups, 0, Expr, SExpr->getSpecifier());
169 if (Expr->evaluateAsAbsolute(Res))
183 assert(MO.
isExpr() &&
"expected an immediate or an expression");
188 return CE->getValue();
191 addFixup(Fixups, 0, Expr, SExpr->getSpecifier());
198unsigned SparcMCCodeEmitter::getSImm5OpValue(
const MCInst &
MI,
unsigned OpNo,
199 SmallVectorImpl<MCFixup> &Fixups,
200 const MCSubtargetInfo &STI)
const {
205SparcMCCodeEmitter::getSImm10OpValue(
const MCInst &
MI,
unsigned OpNo,
206 SmallVectorImpl<MCFixup> &Fixups,
207 const MCSubtargetInfo &STI)
const {
212SparcMCCodeEmitter::getSImm11OpValue(
const MCInst &
MI,
unsigned OpNo,
213 SmallVectorImpl<MCFixup> &Fixups,
214 const MCSubtargetInfo &STI)
const {
219SparcMCCodeEmitter::getSImm13OpValue(
const MCInst &
MI,
unsigned OpNo,
220 SmallVectorImpl<MCFixup> &Fixups,
221 const MCSubtargetInfo &STI)
const {
225unsigned SparcMCCodeEmitter::getImm22OpValue(
const MCInst &
MI,
unsigned OpNo,
226 SmallVectorImpl<MCFixup> &Fixups,
227 const MCSubtargetInfo &STI)
const {
234SparcMCCodeEmitter::getTrapNumOpValue(
const MCInst &
MI,
unsigned OpNo,
235 SmallVectorImpl<MCFixup> &Fixups,
236 const MCSubtargetInfo &STI)
const {
240unsigned SparcMCCodeEmitter::
241getCallTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
242 SmallVectorImpl<MCFixup> &Fixups,
243 const MCSubtargetInfo &STI)
const {
244 if (
MI.getOpcode() == SP::TLS_CALL) {
250 const MCOperand &MO =
MI.getOperand(OpNo);
255unsigned SparcMCCodeEmitter::
256getBranchTargetOpValue(
const MCInst &
MI,
unsigned OpNo,
257 SmallVectorImpl<MCFixup> &Fixups,
258 const MCSubtargetInfo &STI)
const {
259 const MCOperand &MO =
MI.getOperand(OpNo);
261 return getMachineOpValue(
MI, MO, Fixups, STI);
267unsigned SparcMCCodeEmitter::getBranchPredTargetOpValue(
268 const MCInst &
MI,
unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups,
269 const MCSubtargetInfo &STI)
const {
270 const MCOperand &MO =
MI.getOperand(OpNo);
272 return getMachineOpValue(
MI, MO, Fixups, STI);
278unsigned SparcMCCodeEmitter::getBranchOnRegTargetOpValue(
279 const MCInst &
MI,
unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups,
280 const MCSubtargetInfo &STI)
const {
281 const MCOperand &MO =
MI.getOperand(OpNo);
283 return getMachineOpValue(
MI, MO, Fixups, STI);
289unsigned SparcMCCodeEmitter::getCompareAndBranchTargetOpValue(
290 const MCInst &
MI,
unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups,
291 const MCSubtargetInfo &STI)
const {
292 const MCOperand &MO =
MI.getOperand(OpNo);
294 return getMachineOpValue(
MI, MO, Fixups, STI);
300#include "SparcGenMCCodeEmitter.inc"
304 return new SparcMCCodeEmitter(MCII, Ctx);
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind, bool PCRel=false)
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 unsigned getImmOpValue(const MCOperand &MO, SmallVectorImpl< MCFixup > &Fixups, 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)
bool isLittleEndian() const
True if the target is little endian.
MCCodeEmitter - Generic instruction encoding interface.
Context object for machine code objects.
const MCRegisterInfo * getRegisterInfo() const
const MCAsmInfo & getAsmInfo() const
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
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
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
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
MCCodeEmitter * createSparcMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)