31#define DEBUG_TYPE "riscv-disassembler"
37 std::unique_ptr<MCInstrInfo const>
const MCII;
65 return new RISCVDisassembler(STI, Ctx,
T.createMCInstrInfo());
86 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
99 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
112 if (RegNo >= 32 || (IsRVE && RegNo >= 16))
124 if (
Reg != RISCV::X1 &&
Reg != RISCV::X5)
245 if (RegNo >= 32 || RegNo % 2)
248 const RISCVDisassembler *Dis =
249 static_cast<const RISCVDisassembler *
>(Decoder);
252 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
253 &RISCVMCRegisterClasses[RISCV::GPRPairRegClassID]);
261 if (RegNo >= 8 || RegNo % 2)
264 const RISCVDisassembler *Dis =
265 static_cast<const RISCVDisassembler *
>(Decoder);
268 RISCV::X8 + RegNo, RISCV::sub_gpr_even,
269 &RISCVMCRegisterClasses[RISCV::GPRPairCRegClassID]);
276 const void *Decoder) {
280 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
299 if (RegNo >= 32 || RegNo % 2)
302 const RISCVDisassembler *Dis =
303 static_cast<const RISCVDisassembler *
>(Decoder);
307 &RISCVMCRegisterClasses[RISCV::VRM2RegClassID]);
316 if (RegNo >= 32 || RegNo % 4)
319 const RISCVDisassembler *Dis =
320 static_cast<const RISCVDisassembler *
>(Decoder);
324 &RISCVMCRegisterClasses[RISCV::VRM4RegClassID]);
333 if (RegNo >= 32 || RegNo % 8)
336 const RISCVDisassembler *Dis =
337 static_cast<const RISCVDisassembler *
>(Decoder);
341 &RISCVMCRegisterClasses[RISCV::VRM8RegClassID]);
371 if (RegNo > 15 || RegNo % 2)
382 if (RegNo > 15 || RegNo % 4)
396 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
411template <
unsigned W
idth,
unsigned LowerBound>
417 if (Imm < LowerBound)
424template <
unsigned W
idth,
unsigned LowerBound>
430 if ((Imm + 1) < LowerBound)
441 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
504template <
unsigned T,
unsigned N>
595 bool IsWordOp = (Opcode == RISCV::TH_LWD || Opcode == RISCV::TH_LWUD ||
596 Opcode == RISCV::TH_SWD);
605#include "RISCVGenDisassemblerTables.inc"
609struct DecoderListEntry {
610 const uint8_t *Table;
611 FeatureBitset ContainedFeatures;
614 bool haveContainedFeatures(
const FeatureBitset &ActiveFeatures)
const {
615 return ContainedFeatures.none() ||
616 (ContainedFeatures & ActiveFeatures).
any();
623 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
624 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
625 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
626 RISCV::FeatureVendorXCVbi};
629 RISCV::FeatureVendorXRivosVisni,
630 RISCV::FeatureVendorXRivosVizip,
634 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
635 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
636 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
637 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
638 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
639 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
640 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
641 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
642 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
646 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
647 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
648 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase};
650 RISCV::FeatureVendorXSiFivecdiscarddlone,
651 RISCV::FeatureVendorXSiFivecflushdlone,
655 RISCV::FeatureVendorXMIPSLSP,
656 RISCV::FeatureVendorXMIPSCMov,
657 RISCV::FeatureVendorXMIPSCBOP,
658 RISCV::FeatureVendorXMIPSEXECTL,
662 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
663 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
664 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
665 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
666 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
667 RISCV::FeatureVendorXTHeadVdot};
670 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
671 RISCV::FeatureVendorXAndesVBFHCvt,
672 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
673 RISCV::FeatureVendorXAndesVDot};
682 {DecoderTableXVentana32,
683 {RISCV::FeatureVendorXVentanaCondOps},
685 {DecoderTableXTHead32,
XTHeadGroup,
"T-Head extensions"},
686 {DecoderTableXSfvector32,
XSfVectorGroup,
"SiFive vector extensions"},
687 {DecoderTableXSfsystem32,
XSfSystemGroup,
"SiFive system extensions"},
688 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease},
"SiFive sf.cease"},
689 {DecoderTableXMIPS32,
XMIPSGroup,
"Mips extensions"},
690 {DecoderTableXAndes32,
XAndesGroup,
"Andes extensions"},
691 {DecoderTableXSMT32,
XSMTGroup,
"SpacemiT extensions"},
693 {DecoderTable32, {},
"standard 32-bit instructions"},
694 {DecoderTableRV32Only32, {},
"RV32-only standard 32-bit instructions"},
695 {DecoderTableZfinx32, {},
"Zfinx (Float in Integer)"},
696 {DecoderTableZdinxRV32Only32, {},
"RV32-only Zdinx (Double in Integer)"},
701template <>
constexpr uint32_t InsnBitWidth<uint16_t> = 16;
702template <>
constexpr uint32_t InsnBitWidth<uint32_t> = 32;
704template <>
constexpr uint32_t InsnBitWidth<uint64_t> = 48;
711 if (Bytes.
size() < 4) {
720 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
738 {DecoderTableXqccmp16,
739 {RISCV::FeatureVendorXqccmp},
740 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
741 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc},
"WCH QingKe XW"},
744 {DecoderTableZicfiss16, {},
"Zicfiss (Shadow Stack 16-bit)"},
745 {DecoderTable16, {},
"standard 16-bit instructions"},
746 {DecoderTableRV32Only16, {},
"RV32-only 16-bit instructions"},
748 {DecoderTableZcOverlap16,
750 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
754 ArrayRef<uint8_t> Bytes,
756 raw_ostream &CS)
const {
757 if (Bytes.
size() < 2) {
766 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
784 ArrayRef<uint8_t> Bytes,
786 raw_ostream &CS)
const {
787 if (Bytes.
size() < 6) {
794 for (
size_t i =
Size; i-- != 0;)
795 Insn += (
static_cast<uint64_t
>(Bytes[i]) << 8 * i);
798 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
814 ArrayRef<uint8_t> Bytes,
816 raw_ostream &CS)
const {
819 if ((Bytes[0] & 0b11) != 0b11)
824 if ((Bytes[0] & 0b1'1100) != 0b1'1100)
828 if ((Bytes[0] & 0b11'1111) == 0b01'1111) {
833 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
839 if (Bytes.
size() < 2) {
846 unsigned nnn = (Bytes[1] >> 4) & 0b111;
848 Size = 10 + (nnn * 2);
MCDisassembler::DecodeStatus DecodeStatus
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_EXTERNAL_VISIBILITY
static constexpr FeatureBitset XqciFeatureGroup
static DecodeStatus decodeUImmSlistOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static constexpr FeatureBitset XSMTGroup
static DecodeStatus decodeUImmLog2XLenOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static constexpr FeatureBitset XCVFeatureGroup
static constexpr DecoderListEntry DecoderList48[]
static DecodeStatus decodeSImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static constexpr DecoderListEntry DecoderList16[]
static DecodeStatus DecodeGPRX1X5RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRNoX31RegisterClass(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 DecodeStatus decodeUImmLog2XLenNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeCSSPushPopchk(MCInst &Inst, uint16_t Insn, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeRTZArg(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static MCDisassembler * createRISCVDisassembler(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx)
static DecodeStatus DecodeGPRF16RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeTRM2RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR128RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeSImmOperandAndLslN(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static constexpr FeatureBitset XSfVectorGroup
static constexpr DecoderListEntry DecoderList32[]
static DecodeStatus decodeXqccmpRlistS0(MCInst &Inst, uint32_t Imm, uint64_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 decodeUImmPlus1Operand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeCLUIImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeZcmpRlist(MCInst &Inst, uint32_t Imm, 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 DecodeGPRNoX2RegisterClass(MCInst &Inst, uint64_t RegNo, uint32_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 DecodeSPRegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static constexpr FeatureBitset XMIPSGroup
static DecodeStatus decodeSImmNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVMV0RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeTRRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeFPR64CRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRF32RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static constexpr FeatureBitset XAndesGroup
static DecodeStatus DecodeTRM4RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
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 constexpr FeatureBitset XTHeadGroup
static constexpr FeatureBitset XRivosFeatureGroup
static DecodeStatus decodeUImmPlus1OperandGE(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
LLVM_ABI LLVM_EXTERNAL_VISIBILITY void LLVMInitializeRISCVDisassembler()
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)
static constexpr FeatureBitset XSfSystemGroup
static DecodeStatus decodeUImmOperandGE(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRPairCRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Container class for subtarget features.
Context object for machine code objects.
Superclass for all disassemblers.
const MCSubtargetInfo & getSubtargetInfo() const
DecodeStatus
Ternary decode status.
Instances of this class represent a single low-level machine instruction.
unsigned getOpcode() const
void addOperand(const MCOperand Op)
Interface to description of machine instruction set.
static MCOperand createReg(MCRegister 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.
constexpr bool any(E Val)
std::enable_if_t< std::is_integral_v< IntType >, IntType > fieldFromInstruction(const IntType &Insn, unsigned StartBit, unsigned NumBits)
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 & getTheRISCV64beTarget()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Target & getTheRISCV64Target()
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
Target & getTheRISCV32beTarget()
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.