31#define DEBUG_TYPE "riscv-disassembler"
37 std::unique_ptr<MCInstrInfo const>
const MCII;
65 return new RISCVDisassembler(STI, Ctx,
T.createMCInstrInfo());
81template <
unsigned FirstReg,
unsigned NumRegsInClass,
unsigned RVELimit = 0>
85 bool CheckRVE = RVELimit != 0 &&
88 if (RegNo >= NumRegsInClass || (CheckRVE && RegNo >= RVELimit))
103 if (
Reg != RISCV::X1 &&
Reg != RISCV::X5)
167 if (RegNo >= 32 || RegNo % 2)
170 const RISCVDisassembler *Dis =
171 static_cast<const RISCVDisassembler *
>(Decoder);
174 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
175 &RISCVMCRegisterClasses[RISCV::GPRPairRegClassID]);
192 if (RegNo >= 8 || RegNo % 2)
195 const RISCVDisassembler *Dis =
196 static_cast<const RISCVDisassembler *
>(Decoder);
199 RISCV::X8 + RegNo, RISCV::sub_gpr_even,
200 &RISCVMCRegisterClasses[RISCV::GPRPairCRegClassID]);
207 const void *Decoder) {
211 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
230 if (RegNo >= 32 || RegNo % 2)
233 const RISCVDisassembler *Dis =
234 static_cast<const RISCVDisassembler *
>(Decoder);
238 &RISCVMCRegisterClasses[RISCV::VRM2RegClassID]);
247 if (RegNo >= 32 || RegNo % 4)
250 const RISCVDisassembler *Dis =
251 static_cast<const RISCVDisassembler *
>(Decoder);
255 &RISCVMCRegisterClasses[RISCV::VRM4RegClassID]);
264 if (RegNo >= 32 || RegNo % 8)
267 const RISCVDisassembler *Dis =
268 static_cast<const RISCVDisassembler *
>(Decoder);
272 &RISCVMCRegisterClasses[RISCV::VRM8RegClassID]);
302 if (RegNo > 15 || RegNo % 2)
313 if (RegNo > 15 || RegNo % 4)
327 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
354template <
unsigned W
idth,
unsigned LowerBound>
360 if (Imm < LowerBound)
367template <
unsigned W
idth,
unsigned LowerBound>
373 if ((Imm + 1) < LowerBound)
384 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
455template <
unsigned T,
unsigned N>
516#include "RISCVGenDisassemblerTables.inc"
520struct DecoderListEntry {
521 const uint8_t *Table;
522 FeatureBitset ContainedFeatures;
525 bool haveContainedFeatures(
const FeatureBitset &ActiveFeatures)
const {
526 return ContainedFeatures.none() ||
527 (ContainedFeatures & ActiveFeatures).
any();
534 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
535 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
536 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
537 RISCV::FeatureVendorXCVbi};
540 RISCV::FeatureVendorXRivosVisni,
541 RISCV::FeatureVendorXRivosVizip,
545 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
546 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
547 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
548 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
549 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
550 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
551 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
552 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
553 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
557 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
558 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
559 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase,
560 RISCV::FeatureVendorXSfvfexpa, RISCV::FeatureVendorXSfvfexpa64e,
561 RISCV::FeatureVendorXSfvfbfexp16e, RISCV::FeatureVendorXSfvfexp16e,
562 RISCV::FeatureVendorXSfvfexp32e};
564 RISCV::FeatureVendorXSiFivecdiscarddlone,
565 RISCV::FeatureVendorXSiFivecflushdlone,
569 RISCV::FeatureVendorXMIPSLSP,
570 RISCV::FeatureVendorXMIPSCMov,
571 RISCV::FeatureVendorXMIPSCBOP,
572 RISCV::FeatureVendorXMIPSEXECTL,
576 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
577 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
578 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
579 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
580 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
581 RISCV::FeatureVendorXTHeadVdot};
584 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
585 RISCV::FeatureVendorXAndesVBFHCvt, RISCV::FeatureVendorXAndesVSIntH,
586 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
587 RISCV::FeatureVendorXAndesVDot};
598 {DecoderTableXVentana32,
599 {RISCV::FeatureVendorXVentanaCondOps},
601 {DecoderTableXTHead32,
XTHeadGroup,
"T-Head extensions"},
602 {DecoderTableXSfvector32,
XSfVectorGroup,
"SiFive vector extensions"},
603 {DecoderTableXSfsystem32,
XSfSystemGroup,
"SiFive system extensions"},
604 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease},
"SiFive sf.cease"},
605 {DecoderTableXMIPS32,
XMIPSGroup,
"Mips extensions"},
606 {DecoderTableXAndes32,
XAndesGroup,
"Andes extensions"},
607 {DecoderTableXSMT32,
XSMTGroup,
"SpacemiT extensions"},
608 {DecoderTableXAIF32,
XAIFGroup,
"AI Foundry extensions"},
610 {DecoderTable32, {},
"standard 32-bit instructions"},
611 {DecoderTableRV32Only32, {},
"RV32-only standard 32-bit instructions"},
612 {DecoderTableZfinx32, {},
"Zfinx (Float in Integer)"},
613 {DecoderTableZdinxRV32Only32, {},
"RV32-only Zdinx (Double in Integer)"},
618template <>
constexpr uint32_t InsnBitWidth<uint16_t> = 16;
619template <>
constexpr uint32_t InsnBitWidth<uint32_t> = 32;
621template <>
constexpr uint32_t InsnBitWidth<uint64_t> = 48;
628 if (Bytes.
size() < 4) {
637 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
655 {DecoderTableXqccmp16,
656 {RISCV::FeatureVendorXqccmp},
657 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
658 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc},
"WCH QingKe XW"},
661 {DecoderTableZicfiss16, {},
"Zicfiss (Shadow Stack 16-bit)"},
662 {DecoderTable16, {},
"standard 16-bit instructions"},
663 {DecoderTableRV32Only16, {},
"RV32-only 16-bit instructions"},
665 {DecoderTableZcOverlap16,
667 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
671 ArrayRef<uint8_t> Bytes,
673 raw_ostream &CS)
const {
674 if (Bytes.
size() < 2) {
683 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
701 ArrayRef<uint8_t> Bytes,
703 raw_ostream &CS)
const {
704 if (Bytes.
size() < 6) {
711 for (
size_t i =
Size; i-- != 0;)
712 Insn += (
static_cast<uint64_t
>(Bytes[i]) << 8 * i);
715 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
731 ArrayRef<uint8_t> Bytes,
733 raw_ostream &CS)
const {
736 if ((Bytes[0] & 0b11) != 0b11)
746 if ((Bytes[0] & 0b1'1100) != 0b1'1100) {
752 if ((Bytes[0] & 0b11'1111) == 0b01'1111)
756 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
762 if (Bytes.
size() < 2) {
769 unsigned nnn = (Bytes[1] >> 4) & 0b111;
771 Size = 10 + (nnn * 2);
MCDisassembler::DecodeStatus DecodeStatus
static DecodeStatus DecodeSimpleRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address, const MCDisassembler *Decoder)
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 XAIFGroup
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 decodeImmFourOperand(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus decodeUImmLog2XLenNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_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 DecodeTRM2RegisterClass(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 DecodeGPRX5RegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus decodeImmThreeOperand(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus decodeXqccmpRlistS0(MCInst &Inst, uint32_t Imm, 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 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 decodeImmZibiOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeSPRegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static constexpr FeatureBitset XMIPSGroup
constexpr auto DecodeGPRRegisterClass
static DecodeStatus decodeSImmNonZeroOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRPairNoX0RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_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 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 DecodeGPRX1RegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus DecodeSR07RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const void *Decoder)
static constexpr FeatureBitset XTHeadGroup
static DecodeStatus DecodeSimpleRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
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 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.
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)
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.