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() {}
154 return new XtensaMCCodeEmitter(MCII, Ctx,
true);
173void XtensaMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
177 uint64_t
Bits = getBinaryCodeForInstr(
MI, Fixups, STI);
180 if (IsLittleEndian) {
182 unsigned ShiftValue = 0;
183 for (
unsigned I = 0;
I !=
Size; ++
I) {
194XtensaMCCodeEmitter::getMachineOpValue(
const MCInst &
MI,
const MCOperand &MO,
195 SmallVectorImpl<MCFixup> &Fixups,
196 const MCSubtargetInfo &STI)
const {
200 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
209XtensaMCCodeEmitter::getJumpTargetEncoding(
const MCInst &
MI,
unsigned int OpNum,
210 SmallVectorImpl<MCFixup> &Fixups,
211 const MCSubtargetInfo &STI)
const {
212 const MCOperand &MO =
MI.getOperand(OpNum);
217 const MCExpr *Expr = MO.
getExpr();
222uint32_t XtensaMCCodeEmitter::getBranchTargetEncoding(
223 const MCInst &
MI,
unsigned int OpNum, SmallVectorImpl<MCFixup> &Fixups,
224 const MCSubtargetInfo &STI)
const {
225 const MCOperand &MO =
MI.getOperand(OpNum);
227 return static_cast<uint32_t
>(MO.
getImm());
229 const MCExpr *Expr = MO.
getExpr();
230 switch (
MI.getOpcode()) {
248XtensaMCCodeEmitter::getLoopTargetEncoding(
const MCInst &
MI,
unsigned int OpNum,
249 SmallVectorImpl<MCFixup> &Fixups,
250 const MCSubtargetInfo &STI)
const {
251 const MCOperand &MO =
MI.getOperand(OpNum);
253 return static_cast<uint32_t
>(MO.
getImm());
257 const MCExpr *Expr = MO.
getExpr();
264XtensaMCCodeEmitter::getCallEncoding(
const MCInst &
MI,
unsigned int OpNum,
265 SmallVectorImpl<MCFixup> &Fixups,
266 const MCSubtargetInfo &STI)
const {
267 const MCOperand &MO =
MI.getOperand(OpNum);
269 int32_t Res = MO.
getImm();
278 const MCExpr *Expr = MO.
getExpr();
284XtensaMCCodeEmitter::getL32RTargetEncoding(
const MCInst &
MI,
unsigned OpNum,
285 SmallVectorImpl<MCFixup> &Fixups,
286 const MCSubtargetInfo &STI)
const {
287 const MCOperand &MO =
MI.getOperand(OpNum);
289 int32_t Res = MO.
getImm();
303XtensaMCCodeEmitter::getMemRegEncoding(
const MCInst &
MI,
unsigned OpNo,
304 SmallVectorImpl<MCFixup> &Fixups,
305 const MCSubtargetInfo &STI)
const {
306 assert(
MI.getOperand(OpNo + 1).isImm());
308 uint32_t Res =
static_cast<uint32_t
>(
MI.getOperand(OpNo + 1).
getImm());
310 switch (
MI.getOpcode()) {
335 switch (
MI.getOpcode()) {
345 uint32_t OffBits = Res << 4;
346 uint32_t RegBits = getMachineOpValue(
MI,
MI.getOperand(OpNo), Fixups, STI);
348 return ((OffBits & 0xFF0) | RegBits);
351uint32_t XtensaMCCodeEmitter::getImm8OpValue(
const MCInst &
MI,
unsigned OpNo,
352 SmallVectorImpl<MCFixup> &Fixups,
353 const MCSubtargetInfo &STI)
const {
354 const MCOperand &MO =
MI.getOperand(OpNo);
355 int32_t Res = MO.
getImm();
357 assert(((Res >= -128) && (Res <= 127)) &&
"Unexpected operand value!");
363XtensaMCCodeEmitter::getImm8_sh8OpValue(
const MCInst &
MI,
unsigned OpNo,
364 SmallVectorImpl<MCFixup> &Fixups,
365 const MCSubtargetInfo &STI)
const {
366 const MCOperand &MO =
MI.getOperand(OpNo);
367 int32_t Res = MO.
getImm();
369 assert(((Res >= -32768) && (Res <= 32512) && ((Res & 0xff) == 0)) &&
370 "Unexpected operand value!");
372 return (Res & 0xffff);
376XtensaMCCodeEmitter::getImm12OpValue(
const MCInst &
MI,
unsigned OpNo,
377 SmallVectorImpl<MCFixup> &Fixups,
378 const MCSubtargetInfo &STI)
const {
379 const MCOperand &MO =
MI.getOperand(OpNo);
380 int32_t Res = MO.
getImm();
382 assert(((Res >= -2048) && (Res <= 2047)) &&
"Unexpected operand value!");
384 return (Res & 0xfff);
388XtensaMCCodeEmitter::getUimm4OpValue(
const MCInst &
MI,
unsigned OpNo,
389 SmallVectorImpl<MCFixup> &Fixups,
390 const MCSubtargetInfo &STI)
const {
391 const MCOperand &MO =
MI.getOperand(OpNo);
392 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
394 assert((Res <= 15) &&
"Unexpected operand value!");
400XtensaMCCodeEmitter::getUimm5OpValue(
const MCInst &
MI,
unsigned OpNo,
401 SmallVectorImpl<MCFixup> &Fixups,
402 const MCSubtargetInfo &STI)
const {
403 const MCOperand &MO =
MI.getOperand(OpNo);
404 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
406 assert((Res <= 31) &&
"Unexpected operand value!");
412XtensaMCCodeEmitter::getShimm1_31OpValue(
const MCInst &
MI,
unsigned OpNo,
413 SmallVectorImpl<MCFixup> &Fixups,
414 const MCSubtargetInfo &STI)
const {
415 const MCOperand &MO =
MI.getOperand(OpNo);
416 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
418 assert(((Res >= 1) && (Res <= 31)) &&
"Unexpected operand value!");
420 return ((32 - Res) & 0x1f);
424XtensaMCCodeEmitter::getImm1_16OpValue(
const MCInst &
MI,
unsigned OpNo,
425 SmallVectorImpl<MCFixup> &Fixups,
426 const MCSubtargetInfo &STI)
const {
427 const MCOperand &MO =
MI.getOperand(OpNo);
428 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
430 assert(((Res >= 1) && (Res <= 16)) &&
"Unexpected operand value!");
436XtensaMCCodeEmitter::getImm1n_15OpValue(
const MCInst &
MI,
unsigned OpNo,
437 SmallVectorImpl<MCFixup> &Fixups,
438 const MCSubtargetInfo &STI)
const {
439 const MCOperand &MO =
MI.getOperand(OpNo);
440 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
442 assert(((Res >= -1) && (Res <= 15) && (Res != 0)) &&
443 "Unexpected operand value!");
452XtensaMCCodeEmitter::getImm32n_95OpValue(
const MCInst &
MI,
unsigned OpNo,
453 SmallVectorImpl<MCFixup> &Fixups,
454 const MCSubtargetInfo &STI)
const {
455 const MCOperand &MO =
MI.getOperand(OpNo);
456 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
458 assert(((Res >= -32) && (Res <= 95)) &&
"Unexpected operand value!");
464XtensaMCCodeEmitter::getImm8n_7OpValue(
const MCInst &
MI,
unsigned OpNo,
465 SmallVectorImpl<MCFixup> &Fixups,
466 const MCSubtargetInfo &STI)
const {
467 const MCOperand &MO =
MI.getOperand(OpNo);
468 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
470 assert(((Res >= -8) && (Res <= 7)) &&
"Unexpected operand value!");
479XtensaMCCodeEmitter::getImm64n_4nOpValue(
const MCInst &
MI,
unsigned OpNo,
480 SmallVectorImpl<MCFixup> &Fixups,
481 const MCSubtargetInfo &STI)
const {
482 const MCOperand &MO =
MI.getOperand(OpNo);
483 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
485 assert(((Res >= -64) && (Res <= -4) && ((Res & 0x3) == 0)) &&
486 "Unexpected operand value!");
492XtensaMCCodeEmitter::getEntry_Imm12OpValue(
const MCInst &
MI,
unsigned OpNo,
493 SmallVectorImpl<MCFixup> &Fixups,
494 const MCSubtargetInfo &STI)
const {
495 const MCOperand &MO =
MI.getOperand(OpNo);
496 uint32_t res =
static_cast<uint32_t
>(MO.
getImm());
498 assert(((res & 0x7) == 0) &&
"Unexpected operand value!");
504XtensaMCCodeEmitter::getB4constOpValue(
const MCInst &
MI,
unsigned OpNo,
505 SmallVectorImpl<MCFixup> &Fixups,
506 const MCSubtargetInfo &STI)
const {
507 const MCOperand &MO =
MI.getOperand(OpNo);
508 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
552XtensaMCCodeEmitter::getB4constuOpValue(
const MCInst &
MI,
unsigned OpNo,
553 SmallVectorImpl<MCFixup> &Fixups,
554 const MCSubtargetInfo &STI)
const {
555 const MCOperand &MO =
MI.getOperand(OpNo);
556 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
602XtensaMCCodeEmitter::getImm7_22OpValue(
const MCInst &
MI,
unsigned OpNo,
603 SmallVectorImpl<MCFixup> &Fixups,
604 const MCSubtargetInfo &STI)
const {
605 const MCOperand &MO =
MI.getOperand(OpNo);
606 uint32_t res =
static_cast<uint32_t
>(MO.
getImm());
609 assert(((res & 0xf) == res) &&
"Unexpected operand value!");
615XtensaMCCodeEmitter::getSelect_256OpValue(
const MCInst &
MI,
unsigned OpNo,
616 SmallVectorImpl<MCFixup> &Fixups,
617 const MCSubtargetInfo &STI)
const {
618 const MCOperand &MO =
MI.getOperand(OpNo);
619 uint8_t Res =
static_cast<uint8_t
>(MO.
getImm());
625#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)