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,
174 unsigned Size = MCII.get(
MI.getOpcode()).getSize();
176 if (IsLittleEndian) {
178 unsigned ShiftValue = 0;
179 for (
unsigned I = 0;
I !=
Size; ++
I) {
194 return Ctx.getRegisterInfo()->getEncodingValue(MO.
getReg());
205XtensaMCCodeEmitter::getJumpTargetEncoding(
const MCInst &
MI,
unsigned int OpNum,
218uint32_t XtensaMCCodeEmitter::getBranchTargetEncoding(
226 switch (
MI.getOpcode()) {
244XtensaMCCodeEmitter::getLoopTargetEncoding(
const MCInst &
MI,
unsigned int OpNum,
260XtensaMCCodeEmitter::getCallEncoding(
const MCInst &
MI,
unsigned int OpNum,
265 int32_t Res = MO.
getImm();
280XtensaMCCodeEmitter::getL32RTargetEncoding(
const MCInst &
MI,
unsigned OpNum,
285 int32_t Res = MO.
getImm();
299XtensaMCCodeEmitter::getMemRegEncoding(
const MCInst &
MI,
unsigned OpNo,
302 assert(
MI.getOperand(OpNo + 1).isImm());
306 switch (
MI.getOpcode()) {
331 switch (
MI.getOpcode()) {
334 assert((isUInt<4>(Res)) &&
"Unexpected operand value!");
337 assert((isUInt<8>(Res)) &&
"Unexpected operand value!");
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,
351 int32_t Res = MO.
getImm();
353 assert(((Res >= -128) && (Res <= 127)) &&
"Unexpected operand value!");
359XtensaMCCodeEmitter::getImm8_sh8OpValue(
const MCInst &
MI,
unsigned 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,
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,
390 assert((Res <= 15) &&
"Unexpected operand value!");
396XtensaMCCodeEmitter::getUimm5OpValue(
const MCInst &
MI,
unsigned OpNo,
402 assert((Res <= 31) &&
"Unexpected operand value!");
408XtensaMCCodeEmitter::getShimm1_31OpValue(
const MCInst &
MI,
unsigned OpNo,
414 assert(((Res >= 1) && (Res <= 31)) &&
"Unexpected operand value!");
416 return ((32 - Res) & 0x1f);
420XtensaMCCodeEmitter::getImm1_16OpValue(
const MCInst &
MI,
unsigned OpNo,
426 assert(((Res >= 1) && (Res <= 16)) &&
"Unexpected operand value!");
432XtensaMCCodeEmitter::getImm1n_15OpValue(
const MCInst &
MI,
unsigned 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,
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,
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,
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,
494 assert(((res & 0x7) == 0) &&
"Unexpected operand value!");
500XtensaMCCodeEmitter::getB4constOpValue(
const MCInst &
MI,
unsigned OpNo,
548XtensaMCCodeEmitter::getB4constuOpValue(
const MCInst &
MI,
unsigned OpNo,
598XtensaMCCodeEmitter::getImm7_22OpValue(
const MCInst &
MI,
unsigned OpNo,
605 assert(((res & 0xf) == res) &&
"Unexpected operand value!");
609#include "XtensaGenMCCodeEmitter.inc"
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
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.
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...
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.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
MCCodeEmitter * createXtensaMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)