28#define DEBUG_TYPE "riscv-disassembler"
34 std::unique_ptr<MCInstrInfo const>
const MCII;
46 void addSPOperands(
MCInst &
MI)
const;
60 return new RISCVDisassembler(STI, Ctx,
T.createMCInstrInfo());
76 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
88 if (Reg != RISCV::X1 && Reg != RISCV::X5)
184 if (RegNo >= 32 || RegNo & 1)
194 const void *Decoder) {
198 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
217 if (RegNo >= 32 || RegNo % 2)
220 const RISCVDisassembler *Dis =
221 static_cast<const RISCVDisassembler *
>(Decoder);
225 &RISCVMCRegisterClasses[RISCV::VRM2RegClassID]);
234 if (RegNo >= 32 || RegNo % 4)
237 const RISCVDisassembler *Dis =
238 static_cast<const RISCVDisassembler *
>(Decoder);
242 &RISCVMCRegisterClasses[RISCV::VRM4RegClassID]);
251 if (RegNo >= 32 || RegNo % 8)
254 const RISCVDisassembler *Dis =
255 static_cast<const RISCVDisassembler *
>(Decoder);
259 &RISCVMCRegisterClasses[RISCV::VRM8RegClassID]);
271 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
281 assert(isUInt<N>(Imm) &&
"Invalid immediate");
292 return decodeUImmOperand<N>(Inst, Imm, Address, Decoder);
299 assert(isUInt<N>(Imm) &&
"Invalid immediate");
311 return decodeSImmOperand<N>(Inst, Imm, Address, Decoder);
318 assert(isUInt<N>(Imm) &&
"Invalid immediate");
329 assert(isUInt<6>(Imm) &&
"Invalid immediate");
331 Imm = (SignExtend64<6>(Imm) & 0xfffff);
339 assert(isUInt<3>(Imm) &&
"Invalid immediate");
372 uint64_t Address,
const void *Decoder);
378 uint64_t Address,
const void *Decoder);
384#include "RISCVGenDisassemblerTables.inc"
413 fieldFromInstruction(
Insn, 12, 1) << 5 | fieldFromInstruction(
Insn, 2, 5);
415 decodeSImmOperand<6>(Inst, SImm6, Address, Decoder);
426 fieldFromInstruction(
Insn, 12, 1) << 5 | fieldFromInstruction(
Insn, 2, 5);
428 decodeUImmOperand<6>(Inst, UImm6, Address, Decoder);
465 decodeUImmOperand<2>(Inst, UImm2, Address, Decoder);
470 bool IsWordOp = (Opcode == RISCV::TH_LWD || Opcode == RISCV::TH_LWUD ||
471 Opcode == RISCV::TH_SWD);
481 uint64_t Address,
const void *Decoder) {
498 uint64_t Address,
const void *Decoder) {
505void RISCVDisassembler::addSPOperands(
MCInst &
MI)
const {
508 if (MCID.
operands()[i].RegClass == RISCV::SPRegClassID)
512#define TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, \
513 DESC, ADDITIONAL_OPERATION) \
515 if (FEATURE_CHECKS) { \
516 LLVM_DEBUG(dbgs() << "Trying " DESC ":\n"); \
517 DecodeStatus Result = \
518 decodeInstruction(DECODER_TABLE, MI, Insn, Address, this, STI); \
519 if (Result != MCDisassembler::Fail) { \
520 ADDITIONAL_OPERATION; \
525#define TRY_TO_DECODE_AND_ADD_SP(FEATURE_CHECKS, DECODER_TABLE, DESC) \
526 TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, DESC, \
528#define TRY_TO_DECODE(FEATURE_CHECKS, DECODER_TABLE, DESC) \
529 TRY_TO_DECODE_WITH_ADDITIONAL_OPERATION(FEATURE_CHECKS, DECODER_TABLE, DESC, \
531#define TRY_TO_DECODE_FEATURE(FEATURE, DECODER_TABLE, DESC) \
532 TRY_TO_DECODE(STI.hasFeature(FEATURE), DECODER_TABLE, DESC)
538 if (Bytes.
size() < 4) {
547 !STI.hasFeature(RISCV::Feature64Bit),
548 DecoderTableRV32Zdinx32,
549 "RV32Zdinx table (Double in Integer and rv32)");
551 !STI.hasFeature(RISCV::Feature64Bit),
552 DecoderTableRV32Zacas32,
553 "RV32Zacas table (Compare-And-Swap and rv32)");
555 "RVZfinx table (Float in Integer)");
557 DecoderTableXVentana32,
"Ventana custom opcode table");
559 "XTHeadBa custom opcode table");
561 "XTHeadBb custom opcode table");
563 "XTHeadBs custom opcode table");
565 DecoderTableXTHeadCondMov32,
566 "XTHeadCondMov custom opcode table");
568 "XTHeadCmo custom opcode table");
570 DecoderTableXTHeadFMemIdx32,
571 "XTHeadFMemIdx custom opcode table");
573 "XTHeadMac custom opcode table");
575 DecoderTableXTHeadMemIdx32,
576 "XTHeadMemIdx custom opcode table");
578 DecoderTableXTHeadMemPair32,
579 "XTHeadMemPair custom opcode table");
581 DecoderTableXTHeadSync32,
582 "XTHeadSync custom opcode table");
584 DecoderTableXTHeadVdot32,
585 "XTHeadVdot custom opcode table");
587 "SiFive VCIX custom opcode table");
589 RISCV::FeatureVendorXSfvqmaccdod, DecoderTableXSfvqmaccdod32,
590 "SiFive Matrix Multiplication (2x8 and 8x2) Instruction opcode table");
592 RISCV::FeatureVendorXSfvqmaccqoq, DecoderTableXSfvqmaccqoq32,
593 "SiFive Matrix Multiplication (4x8 and 8x4) Instruction opcode table");
595 RISCV::FeatureVendorXSfvfwmaccqqq, DecoderTableXSfvfwmaccqqq32,
596 "SiFive Matrix Multiplication Instruction opcode table");
598 RISCV::FeatureVendorXSfvfnrclipxfqf, DecoderTableXSfvfnrclipxfqf32,
599 "SiFive FP32-to-int8 Ranged Clip Instructions opcode table");
601 DecoderTableXSiFivecdiscarddlone32,
602 "SiFive sf.cdiscard.d.l1 custom opcode table");
604 DecoderTableXSiFivecflushdlone32,
605 "SiFive sf.cflush.d.l1 custom opcode table");
607 "SiFive sf.cease custom opcode table");
609 DecoderTableXCVbitmanip32,
610 "CORE-V Bit Manipulation custom opcode table");
612 "CORE-V Event load custom opcode table");
614 "CORE-V MAC custom opcode table");
616 "CORE-V MEM custom opcode table");
618 "CORE-V ALU custom opcode table");
620 "CORE-V SIMD extensions custom opcode table");
622 "CORE-V Immediate Branching custom opcode table");
632 if (Bytes.
size() < 2) {
640 DecoderTableRISCV32Only_16,
641 "RISCV32Only_16 table (16-bit Instruction)");
643 "RVZicfiss table (Shadow Stack)");
645 "Zcmt table (16-bit Table Jump Instructions)");
647 RISCV::FeatureStdExtZcmp, DecoderTableRVZcmp16,
648 "Zcmp table (16-bit Push/Pop & Double Move Instructions)");
651 "WCH QingKe XW custom opcode table");
653 "RISCV_C table (16-bit Instruction)");
663 if ((Bytes[0] & 0b11) != 0b11)
664 return getInstruction16(
MI,
Size, Bytes, Address, CS);
668 if ((Bytes[0] & 0b1'1100) != 0b1'1100)
669 return getInstruction32(
MI,
Size, Bytes, Address, CS);
672 if ((Bytes[0] & 0b11'1111) == 0b01'1111) {
678 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
684 if (Bytes.
size() < 2) {
691 unsigned nnn = (Bytes[1] >> 4) & 0b111;
693 Size = 10 + (nnn * 2);
SmallVector< AArch64_IMM::ImmInsnModel, 4 > Insn
#define LLVM_EXTERNAL_VISIBILITY
#define TRY_TO_DECODE(FEATURE_CHECKS, DECODER_TABLE, DESC)
static DecodeStatus decodeRegReg(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeZcmpRlist(MCInst &Inst, uint32_t Imm, uint64_t Address, const void *Decoder)
static DecodeStatus decodeRVCInstrRdRs1Rs2(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
MCDisassembler::DecodeStatus DecodeStatus
static DecodeStatus decodeSImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRX1X5RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRCRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR64RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static MCDisassembler * createRISCVDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
static DecodeStatus decodeRVCInstrRdRs1ImmZero(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
#define TRY_TO_DECODE_FEATURE(FEATURE, DECODER_TABLE, DESC)
static DecodeStatus decodeSImmOperandAndLsl1(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR32CRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeXTHeadMemPair(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeCLUIImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeCSSPushPopchk(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeUImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR32RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRM8RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRM4RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeRVCInstrRdSImm(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRM2RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRPairRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeZcmpSpimm(MCInst &Inst, uint32_t Imm, uint64_t Address, const void *Decoder)
static DecodeStatus DecodeGPRNoX0X2RegisterClass(MCInst &Inst, uint64_t RegNo, uint32_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeRVCInstrRdRs2(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeSImmNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR64CRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVDisassembler()
static DecodeStatus DecodeGPRNoX0RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeFRMArg(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeSR07RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const void *Decoder)
static DecodeStatus decodeRVCInstrRdRs1UImm(MCInst &Inst, uint32_t Insn, uint64_t Address, const MCDisassembler *Decoder)
#define TRY_TO_DECODE_AND_ADD_SP(FEATURE_CHECKS, DECODER_TABLE, DESC)
static DecodeStatus DecodeFPR16RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeVMaskReg(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeUImmNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Context object for machine code objects.
Superclass for all disassemblers.
const MCSubtargetInfo & getSubtargetInfo() const
DecodeStatus
Ternary decode status.
virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const =0
Returns the disassembly of a single instruction.
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
void addOperand(const MCOperand Op)
const MCOperand & getOperand(unsigned i) const
Describe properties that are true of each instruction in the target description file.
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction.
ArrayRef< MCOperandInfo > operands() const
Interface to description of machine instruction set.
static MCOperand createReg(unsigned Reg)
static MCOperand createImm(int64_t Val)
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
MCRegister getMatchingSuperReg(MCRegister Reg, unsigned SubIdx, const MCRegisterClass *RC) const
Return a super-register of the specified register Reg so its sub-register of index SubIdx is Reg.
Wrapper class representing physical registers. Should be passed by value.
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
Target - Wrapper for Target specific information.
This class implements an extremely fast bulk output stream that can only output to a stream.
static bool isValidRoundingMode(unsigned Mode)
uint16_t read16le(const void *P)
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
Target & getTheRISCV32Target()
Target & getTheRISCV64Target()
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.