25#define GET_INSTRMAP_INFO
26#include "XtensaGenInstrInfo.inc"
27#undef GET_INSTRMAP_INFO
31#define DEBUG_TYPE "mccodeemitter"
41 : MCII(mcii), Ctx(ctx), IsLittleEndian(isLE) {}
43 ~XtensaMCCodeEmitter() {}
150 return new XtensaMCCodeEmitter(MCII, Ctx,
true);
169void XtensaMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
173 uint64_t
Bits = getBinaryCodeForInstr(
MI, Fixups, STI);
176 if (IsLittleEndian) {
178 unsigned ShiftValue = 0;
179 for (
unsigned I = 0;
I !=
Size; ++
I) {
190XtensaMCCodeEmitter::getMachineOpValue(
const MCInst &
MI,
const MCOperand &MO,
191 SmallVectorImpl<MCFixup> &Fixups,
192 const MCSubtargetInfo &STI)
const {
196 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
205XtensaMCCodeEmitter::getJumpTargetEncoding(
const MCInst &
MI,
unsigned int OpNum,
206 SmallVectorImpl<MCFixup> &Fixups,
207 const MCSubtargetInfo &STI)
const {
208 const MCOperand &MO =
MI.getOperand(OpNum);
213 const MCExpr *Expr = MO.
getExpr();
218uint32_t XtensaMCCodeEmitter::getBranchTargetEncoding(
219 const MCInst &
MI,
unsigned int OpNum, SmallVectorImpl<MCFixup> &Fixups,
220 const MCSubtargetInfo &STI)
const {
221 const MCOperand &MO =
MI.getOperand(OpNum);
223 return static_cast<uint32_t
>(MO.
getImm());
225 const MCExpr *Expr = MO.
getExpr();
226 switch (
MI.getOpcode()) {
244XtensaMCCodeEmitter::getLoopTargetEncoding(
const MCInst &
MI,
unsigned int OpNum,
245 SmallVectorImpl<MCFixup> &Fixups,
246 const MCSubtargetInfo &STI)
const {
247 const MCOperand &MO =
MI.getOperand(OpNum);
249 return static_cast<uint32_t
>(MO.
getImm());
253 const MCExpr *Expr = MO.
getExpr();
260XtensaMCCodeEmitter::getCallEncoding(
const MCInst &
MI,
unsigned int OpNum,
261 SmallVectorImpl<MCFixup> &Fixups,
262 const MCSubtargetInfo &STI)
const {
263 const MCOperand &MO =
MI.getOperand(OpNum);
265 int32_t Res = MO.
getImm();
274 const MCExpr *Expr = MO.
getExpr();
280XtensaMCCodeEmitter::getL32RTargetEncoding(
const MCInst &
MI,
unsigned OpNum,
281 SmallVectorImpl<MCFixup> &Fixups,
282 const MCSubtargetInfo &STI)
const {
283 const MCOperand &MO =
MI.getOperand(OpNum);
285 int32_t Res = MO.
getImm();
299XtensaMCCodeEmitter::getMemRegEncoding(
const MCInst &
MI,
unsigned OpNo,
300 SmallVectorImpl<MCFixup> &Fixups,
301 const MCSubtargetInfo &STI)
const {
302 assert(
MI.getOperand(OpNo + 1).isImm());
304 uint32_t Res =
static_cast<uint32_t
>(
MI.getOperand(OpNo + 1).
getImm());
306 switch (
MI.getOpcode()) {
331 switch (
MI.getOpcode()) {
341 uint32_t OffBits = Res << 4;
342 uint32_t RegBits = getMachineOpValue(
MI,
MI.getOperand(OpNo), Fixups, STI);
344 return ((OffBits & 0xFF0) | RegBits);
347uint32_t XtensaMCCodeEmitter::getImm8OpValue(
const MCInst &
MI,
unsigned OpNo,
348 SmallVectorImpl<MCFixup> &Fixups,
349 const MCSubtargetInfo &STI)
const {
350 const MCOperand &MO =
MI.getOperand(OpNo);
351 int32_t Res = MO.
getImm();
353 assert(((Res >= -128) && (Res <= 127)) &&
"Unexpected operand value!");
359XtensaMCCodeEmitter::getImm8_sh8OpValue(
const MCInst &
MI,
unsigned OpNo,
360 SmallVectorImpl<MCFixup> &Fixups,
361 const MCSubtargetInfo &STI)
const {
362 const MCOperand &MO =
MI.getOperand(OpNo);
363 int32_t Res = MO.
getImm();
365 assert(((Res >= -32768) && (Res <= 32512) && ((Res & 0xff) == 0)) &&
366 "Unexpected operand value!");
368 return (Res & 0xffff);
372XtensaMCCodeEmitter::getImm12OpValue(
const MCInst &
MI,
unsigned OpNo,
373 SmallVectorImpl<MCFixup> &Fixups,
374 const MCSubtargetInfo &STI)
const {
375 const MCOperand &MO =
MI.getOperand(OpNo);
376 int32_t Res = MO.
getImm();
378 assert(((Res >= -2048) && (Res <= 2047)) &&
"Unexpected operand value!");
380 return (Res & 0xfff);
384XtensaMCCodeEmitter::getUimm4OpValue(
const MCInst &
MI,
unsigned OpNo,
385 SmallVectorImpl<MCFixup> &Fixups,
386 const MCSubtargetInfo &STI)
const {
387 const MCOperand &MO =
MI.getOperand(OpNo);
388 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
390 assert((Res <= 15) &&
"Unexpected operand value!");
396XtensaMCCodeEmitter::getUimm5OpValue(
const MCInst &
MI,
unsigned OpNo,
397 SmallVectorImpl<MCFixup> &Fixups,
398 const MCSubtargetInfo &STI)
const {
399 const MCOperand &MO =
MI.getOperand(OpNo);
400 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
402 assert((Res <= 31) &&
"Unexpected operand value!");
408XtensaMCCodeEmitter::getShimm1_31OpValue(
const MCInst &
MI,
unsigned OpNo,
409 SmallVectorImpl<MCFixup> &Fixups,
410 const MCSubtargetInfo &STI)
const {
411 const MCOperand &MO =
MI.getOperand(OpNo);
412 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
414 assert(((Res >= 1) && (Res <= 31)) &&
"Unexpected operand value!");
416 return ((32 - Res) & 0x1f);
420XtensaMCCodeEmitter::getImm1_16OpValue(
const MCInst &
MI,
unsigned OpNo,
421 SmallVectorImpl<MCFixup> &Fixups,
422 const MCSubtargetInfo &STI)
const {
423 const MCOperand &MO =
MI.getOperand(OpNo);
424 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
426 assert(((Res >= 1) && (Res <= 16)) &&
"Unexpected operand value!");
432XtensaMCCodeEmitter::getImm1n_15OpValue(
const MCInst &
MI,
unsigned OpNo,
433 SmallVectorImpl<MCFixup> &Fixups,
434 const MCSubtargetInfo &STI)
const {
435 const MCOperand &MO =
MI.getOperand(OpNo);
436 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
438 assert(((Res >= -1) && (Res <= 15) && (Res != 0)) &&
439 "Unexpected operand value!");
448XtensaMCCodeEmitter::getImm32n_95OpValue(
const MCInst &
MI,
unsigned OpNo,
449 SmallVectorImpl<MCFixup> &Fixups,
450 const MCSubtargetInfo &STI)
const {
451 const MCOperand &MO =
MI.getOperand(OpNo);
452 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
454 assert(((Res >= -32) && (Res <= 95)) &&
"Unexpected operand value!");
460XtensaMCCodeEmitter::getImm8n_7OpValue(
const MCInst &
MI,
unsigned OpNo,
461 SmallVectorImpl<MCFixup> &Fixups,
462 const MCSubtargetInfo &STI)
const {
463 const MCOperand &MO =
MI.getOperand(OpNo);
464 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
466 assert(((Res >= -8) && (Res <= 7)) &&
"Unexpected operand value!");
475XtensaMCCodeEmitter::getImm64n_4nOpValue(
const MCInst &
MI,
unsigned OpNo,
476 SmallVectorImpl<MCFixup> &Fixups,
477 const MCSubtargetInfo &STI)
const {
478 const MCOperand &MO =
MI.getOperand(OpNo);
479 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
481 assert(((Res >= -64) && (Res <= -4) && ((Res & 0x3) == 0)) &&
482 "Unexpected operand value!");
488XtensaMCCodeEmitter::getEntry_Imm12OpValue(
const MCInst &
MI,
unsigned OpNo,
489 SmallVectorImpl<MCFixup> &Fixups,
490 const MCSubtargetInfo &STI)
const {
491 const MCOperand &MO =
MI.getOperand(OpNo);
492 uint32_t res =
static_cast<uint32_t
>(MO.
getImm());
494 assert(((res & 0x7) == 0) &&
"Unexpected operand value!");
500XtensaMCCodeEmitter::getB4constOpValue(
const MCInst &
MI,
unsigned OpNo,
501 SmallVectorImpl<MCFixup> &Fixups,
502 const MCSubtargetInfo &STI)
const {
503 const MCOperand &MO =
MI.getOperand(OpNo);
504 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
548XtensaMCCodeEmitter::getB4constuOpValue(
const MCInst &
MI,
unsigned OpNo,
549 SmallVectorImpl<MCFixup> &Fixups,
550 const MCSubtargetInfo &STI)
const {
551 const MCOperand &MO =
MI.getOperand(OpNo);
552 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
598XtensaMCCodeEmitter::getImm7_22OpValue(
const MCInst &
MI,
unsigned OpNo,
599 SmallVectorImpl<MCFixup> &Fixups,
600 const MCSubtargetInfo &STI)
const {
601 const MCOperand &MO =
MI.getOperand(OpNo);
602 uint32_t res =
static_cast<uint32_t
>(MO.
getImm());
605 assert(((res & 0xf) == res) &&
"Unexpected operand value!");
609#include "XtensaGenMCCodeEmitter.inc"
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!")
MCCodeEmitter - Generic instruction encoding interface.
Context object for machine code objects.
const MCRegisterInfo * getRegisterInfo() 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.
unsigned getSize() const
Return the number of bytes in the encoding of this instruction, or zero if the encoding size cannot b...
Interface to description of machine instruction set.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
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...
void push_back(const T &Elt)
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
MachineInstr * getImm(const MachineOperand &MO, const MachineRegisterInfo *MRI)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
MCCodeEmitter * createXtensaMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)