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() {}
166 int8_t getOffset_16_16OpValue(
const MCInst &
MI,
unsigned OpNo,
170 int16_t getOffset_256_16OpValue(
const MCInst &
MI,
unsigned OpNo,
174 int16_t getOffset_256_8OpValue(
const MCInst &
MI,
unsigned OpNo,
178 int16_t getOffset_256_4OpValue(
const MCInst &
MI,
unsigned OpNo,
190 int16_t getOffset_64_16OpValue(
const MCInst &
MI,
unsigned OpNo,
198 return new XtensaMCCodeEmitter(MCII, Ctx,
true);
217void XtensaMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
224 if (IsLittleEndian) {
226 unsigned ShiftValue = 0;
227 for (
unsigned I = 0;
I !=
Size; ++
I) {
238XtensaMCCodeEmitter::getMachineOpValue(
const MCInst &
MI,
const MCOperand &MO,
239 SmallVectorImpl<MCFixup> &Fixups,
240 const MCSubtargetInfo &STI)
const {
244 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
253XtensaMCCodeEmitter::getJumpTargetEncoding(
const MCInst &
MI,
unsigned int OpNum,
254 SmallVectorImpl<MCFixup> &Fixups,
255 const MCSubtargetInfo &STI)
const {
256 const MCOperand &MO =
MI.getOperand(OpNum);
261 const MCExpr *Expr = MO.
getExpr();
266uint32_t XtensaMCCodeEmitter::getBranchTargetEncoding(
267 const MCInst &
MI,
unsigned int OpNum, SmallVectorImpl<MCFixup> &Fixups,
268 const MCSubtargetInfo &STI)
const {
269 const MCOperand &MO =
MI.getOperand(OpNum);
271 return static_cast<uint32_t
>(MO.
getImm());
273 const MCExpr *Expr = MO.
getExpr();
274 switch (
MI.getOpcode()) {
292XtensaMCCodeEmitter::getLoopTargetEncoding(
const MCInst &
MI,
unsigned int OpNum,
293 SmallVectorImpl<MCFixup> &Fixups,
294 const MCSubtargetInfo &STI)
const {
295 const MCOperand &MO =
MI.getOperand(OpNum);
297 return static_cast<uint32_t
>(MO.
getImm());
301 const MCExpr *Expr = MO.
getExpr();
308XtensaMCCodeEmitter::getCallEncoding(
const MCInst &
MI,
unsigned int OpNum,
309 SmallVectorImpl<MCFixup> &Fixups,
310 const MCSubtargetInfo &STI)
const {
311 const MCOperand &MO =
MI.getOperand(OpNum);
313 int32_t Res = MO.
getImm();
322 const MCExpr *Expr = MO.
getExpr();
328XtensaMCCodeEmitter::getL32RTargetEncoding(
const MCInst &
MI,
unsigned OpNum,
329 SmallVectorImpl<MCFixup> &Fixups,
330 const MCSubtargetInfo &STI)
const {
331 const MCOperand &MO =
MI.getOperand(OpNum);
333 int32_t Res = MO.
getImm();
347XtensaMCCodeEmitter::getMemRegEncoding(
const MCInst &
MI,
unsigned OpNo,
348 SmallVectorImpl<MCFixup> &Fixups,
349 const MCSubtargetInfo &STI)
const {
350 assert(
MI.getOperand(OpNo + 1).isImm());
352 uint32_t Res =
static_cast<uint32_t
>(
MI.getOperand(OpNo + 1).
getImm());
354 switch (
MI.getOpcode()) {
379 switch (
MI.getOpcode()) {
389 uint32_t OffBits = Res << 4;
390 uint32_t RegBits = getMachineOpValue(
MI,
MI.getOperand(OpNo), Fixups, STI);
392 return ((OffBits & 0xFF0) | RegBits);
395uint32_t XtensaMCCodeEmitter::getImm8OpValue(
const MCInst &
MI,
unsigned OpNo,
396 SmallVectorImpl<MCFixup> &Fixups,
397 const MCSubtargetInfo &STI)
const {
398 const MCOperand &MO =
MI.getOperand(OpNo);
399 int32_t Res = MO.
getImm();
401 assert(((Res >= -128) && (Res <= 127)) &&
"Unexpected operand value!");
407XtensaMCCodeEmitter::getImm8_sh8OpValue(
const MCInst &
MI,
unsigned OpNo,
408 SmallVectorImpl<MCFixup> &Fixups,
409 const MCSubtargetInfo &STI)
const {
410 const MCOperand &MO =
MI.getOperand(OpNo);
411 int32_t Res = MO.
getImm();
413 assert(((Res >= -32768) && (Res <= 32512) && ((Res & 0xff) == 0)) &&
414 "Unexpected operand value!");
416 return (Res & 0xffff);
420XtensaMCCodeEmitter::getImm12OpValue(
const MCInst &
MI,
unsigned OpNo,
421 SmallVectorImpl<MCFixup> &Fixups,
422 const MCSubtargetInfo &STI)
const {
423 const MCOperand &MO =
MI.getOperand(OpNo);
424 int32_t Res = MO.
getImm();
426 assert(((Res >= -2048) && (Res <= 2047)) &&
"Unexpected operand value!");
428 return (Res & 0xfff);
432XtensaMCCodeEmitter::getUimm4OpValue(
const MCInst &
MI,
unsigned OpNo,
433 SmallVectorImpl<MCFixup> &Fixups,
434 const MCSubtargetInfo &STI)
const {
435 const MCOperand &MO =
MI.getOperand(OpNo);
436 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
438 assert((Res <= 15) &&
"Unexpected operand value!");
444XtensaMCCodeEmitter::getUimm5OpValue(
const MCInst &
MI,
unsigned OpNo,
445 SmallVectorImpl<MCFixup> &Fixups,
446 const MCSubtargetInfo &STI)
const {
447 const MCOperand &MO =
MI.getOperand(OpNo);
448 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
450 assert((Res <= 31) &&
"Unexpected operand value!");
456XtensaMCCodeEmitter::getShimm1_31OpValue(
const MCInst &
MI,
unsigned OpNo,
457 SmallVectorImpl<MCFixup> &Fixups,
458 const MCSubtargetInfo &STI)
const {
459 const MCOperand &MO =
MI.getOperand(OpNo);
460 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
462 assert(((Res >= 1) && (Res <= 31)) &&
"Unexpected operand value!");
464 return ((32 - Res) & 0x1f);
468XtensaMCCodeEmitter::getImm1_16OpValue(
const MCInst &
MI,
unsigned OpNo,
469 SmallVectorImpl<MCFixup> &Fixups,
470 const MCSubtargetInfo &STI)
const {
471 const MCOperand &MO =
MI.getOperand(OpNo);
472 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
474 assert(((Res >= 1) && (Res <= 16)) &&
"Unexpected operand value!");
480XtensaMCCodeEmitter::getImm1n_15OpValue(
const MCInst &
MI,
unsigned OpNo,
481 SmallVectorImpl<MCFixup> &Fixups,
482 const MCSubtargetInfo &STI)
const {
483 const MCOperand &MO =
MI.getOperand(OpNo);
484 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
486 assert(((Res >= -1) && (Res <= 15) && (Res != 0)) &&
487 "Unexpected operand value!");
496XtensaMCCodeEmitter::getImm32n_95OpValue(
const MCInst &
MI,
unsigned OpNo,
497 SmallVectorImpl<MCFixup> &Fixups,
498 const MCSubtargetInfo &STI)
const {
499 const MCOperand &MO =
MI.getOperand(OpNo);
500 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
502 assert(((Res >= -32) && (Res <= 95)) &&
"Unexpected operand value!");
508XtensaMCCodeEmitter::getImm8n_7OpValue(
const MCInst &
MI,
unsigned OpNo,
509 SmallVectorImpl<MCFixup> &Fixups,
510 const MCSubtargetInfo &STI)
const {
511 const MCOperand &MO =
MI.getOperand(OpNo);
512 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
514 assert(((Res >= -8) && (Res <= 7)) &&
"Unexpected operand value!");
523XtensaMCCodeEmitter::getImm64n_4nOpValue(
const MCInst &
MI,
unsigned OpNo,
524 SmallVectorImpl<MCFixup> &Fixups,
525 const MCSubtargetInfo &STI)
const {
526 const MCOperand &MO =
MI.getOperand(OpNo);
527 int32_t Res =
static_cast<int32_t
>(MO.
getImm());
529 assert(((Res >= -64) && (Res <= -4) && ((Res & 0x3) == 0)) &&
530 "Unexpected operand value!");
536XtensaMCCodeEmitter::getEntry_Imm12OpValue(
const MCInst &
MI,
unsigned OpNo,
537 SmallVectorImpl<MCFixup> &Fixups,
538 const MCSubtargetInfo &STI)
const {
539 const MCOperand &MO =
MI.getOperand(OpNo);
540 uint32_t res =
static_cast<uint32_t
>(MO.
getImm());
542 assert(((res & 0x7) == 0) &&
"Unexpected operand value!");
548XtensaMCCodeEmitter::getB4constOpValue(
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());
596XtensaMCCodeEmitter::getB4constuOpValue(
const MCInst &
MI,
unsigned OpNo,
597 SmallVectorImpl<MCFixup> &Fixups,
598 const MCSubtargetInfo &STI)
const {
599 const MCOperand &MO =
MI.getOperand(OpNo);
600 uint32_t Res =
static_cast<uint32_t
>(MO.
getImm());
646XtensaMCCodeEmitter::getImm7_22OpValue(
const MCInst &
MI,
unsigned OpNo,
647 SmallVectorImpl<MCFixup> &Fixups,
648 const MCSubtargetInfo &STI)
const {
649 const MCOperand &MO =
MI.getOperand(OpNo);
650 uint32_t res =
static_cast<uint32_t
>(MO.
getImm());
653 assert(((res & 0xf) == res) &&
"Unexpected operand value!");
659XtensaMCCodeEmitter::getSelect_2OpValue(
const MCInst &
MI,
unsigned OpNo,
660 SmallVectorImpl<MCFixup> &Fixups,
661 const MCSubtargetInfo &STI)
const {
662 const MCOperand &MO =
MI.getOperand(OpNo);
663 uint8_t Res =
static_cast<uint8_t
>(MO.
getImm());
665 assert(((Res >= 0) && (Res <= 1)) &&
"Unexpected operand value!");
671XtensaMCCodeEmitter::getSelect_4OpValue(
const MCInst &
MI,
unsigned OpNo,
672 SmallVectorImpl<MCFixup> &Fixups,
673 const MCSubtargetInfo &STI)
const {
674 const MCOperand &MO =
MI.getOperand(OpNo);
675 uint8_t Res =
static_cast<uint8_t
>(MO.
getImm());
677 assert(((Res >= 0) && (Res <= 3)) &&
"Unexpected operand value!");
683XtensaMCCodeEmitter::getSelect_8OpValue(
const MCInst &
MI,
unsigned OpNo,
684 SmallVectorImpl<MCFixup> &Fixups,
685 const MCSubtargetInfo &STI)
const {
686 const MCOperand &MO =
MI.getOperand(OpNo);
687 uint8_t Res =
static_cast<uint8_t
>(MO.
getImm());
689 assert(((Res >= 0) && (Res <= 7)) &&
"Unexpected operand value!");
695XtensaMCCodeEmitter::getSelect_16OpValue(
const MCInst &
MI,
unsigned OpNo,
696 SmallVectorImpl<MCFixup> &Fixups,
697 const MCSubtargetInfo &STI)
const {
698 const MCOperand &MO =
MI.getOperand(OpNo);
699 uint8_t Res =
static_cast<uint8_t
>(MO.
getImm());
701 assert(((Res >= 0) && (Res <= 15)) &&
"Unexpected operand value!");
707XtensaMCCodeEmitter::getSelect_256OpValue(
const MCInst &
MI,
unsigned OpNo,
708 SmallVectorImpl<MCFixup> &Fixups,
709 const MCSubtargetInfo &STI)
const {
710 const MCOperand &MO =
MI.getOperand(OpNo);
711 uint8_t Res =
static_cast<uint8_t
>(MO.
getImm());
713 assert(((Res >= 0) && (Res <= 255)) &&
"Unexpected operand value!");
717#include "XtensaGenMCCodeEmitter.inc"
720XtensaMCCodeEmitter::getOffset_16_16OpValue(
const MCInst &
MI,
unsigned OpNo,
721 SmallVectorImpl<MCFixup> &Fixups,
722 const MCSubtargetInfo &STI)
const {
723 const MCOperand &MO =
MI.getOperand(OpNo);
724 int8_t Res =
static_cast<int8_t
>(MO.
getImm());
726 assert(((Res >= -128) && (Res <= 112) && ((Res & 0xf) == 0)) &&
727 "Unexpected operand value!");
733XtensaMCCodeEmitter::getOffset_256_8OpValue(
const MCInst &
MI,
unsigned OpNo,
734 SmallVectorImpl<MCFixup> &Fixups,
735 const MCSubtargetInfo &STI)
const {
736 const MCOperand &MO =
MI.getOperand(OpNo);
737 int16_t Res =
static_cast<int16_t
>(MO.
getImm());
739 assert(((Res >= -1024) && (Res <= 1016) && ((Res & 0x7) == 0)) &&
740 "Unexpected operand value!");
746XtensaMCCodeEmitter::getOffset_256_16OpValue(
const MCInst &
MI,
unsigned OpNo,
747 SmallVectorImpl<MCFixup> &Fixups,
748 const MCSubtargetInfo &STI)
const {
749 const MCOperand &MO =
MI.getOperand(OpNo);
750 int16_t Res =
static_cast<int16_t
>(MO.
getImm());
752 assert(((Res >= -2048) && (Res <= 2032) && ((Res & 0xf) == 0)) &&
753 "Unexpected operand value!");
759XtensaMCCodeEmitter::getOffset_256_4OpValue(
const MCInst &
MI,
unsigned OpNo,
760 SmallVectorImpl<MCFixup> &Fixups,
761 const MCSubtargetInfo &STI)
const {
762 const MCOperand &MO =
MI.getOperand(OpNo);
763 int16_t Res =
static_cast<int16_t
>(MO.
getImm());
765 assert(((Res >= -512) && (Res <= 508) && ((Res & 0x3) == 0)) &&
766 "Unexpected operand value!");
772XtensaMCCodeEmitter::getOffset_128_2OpValue(
const MCInst &
MI,
unsigned OpNo,
773 SmallVectorImpl<MCFixup> &Fixups,
774 const MCSubtargetInfo &STI)
const {
775 const MCOperand &MO =
MI.getOperand(OpNo);
776 uint8_t Res =
static_cast<uint8_t
>(MO.
getImm());
778 assert(((Res >= 0) && (Res <= 254) && ((Res & 0x1) == 0)) &&
779 "Unexpected operand value!");
785XtensaMCCodeEmitter::getOffset_128_1OpValue(
const MCInst &
MI,
unsigned OpNo,
786 SmallVectorImpl<MCFixup> &Fixups,
787 const MCSubtargetInfo &STI)
const {
788 const MCOperand &MO =
MI.getOperand(OpNo);
789 uint8_t Res =
static_cast<uint8_t
>(MO.
getImm());
791 assert(((Res >= 0) && (Res <= 127)) &&
"Unexpected operand value!");
797XtensaMCCodeEmitter::getOffset_64_16OpValue(
const MCInst &
MI,
unsigned OpNo,
798 SmallVectorImpl<MCFixup> &Fixups,
799 const MCSubtargetInfo &STI)
const {
800 const MCOperand &MO =
MI.getOperand(OpNo);
801 int16_t Res =
static_cast<int16_t
>(MO.
getImm());
803 assert(((Res >= -512) && (Res <= 496) && ((Res & 0xf) == 0)) &&
804 "Unexpected operand value!");
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)