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)
257 if (RegNo >= 32 || RegNo % 2)
260 const RISCVDisassembler *Dis =
261 static_cast<const RISCVDisassembler *
>(Decoder);
264 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
265 &RISCVMCRegisterClasses[RISCV::GPRPairRegClassID]);
282 if (RegNo >= 8 || RegNo % 2)
285 const RISCVDisassembler *Dis =
286 static_cast<const RISCVDisassembler *
>(Decoder);
289 RISCV::X8 + RegNo, RISCV::sub_gpr_even,
290 &RISCVMCRegisterClasses[RISCV::GPRPairCRegClassID]);
297 const void *Decoder) {
301 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
320 if (RegNo >= 32 || RegNo % 2)
323 const RISCVDisassembler *Dis =
324 static_cast<const RISCVDisassembler *
>(Decoder);
328 &RISCVMCRegisterClasses[RISCV::VRM2RegClassID]);
337 if (RegNo >= 32 || RegNo % 4)
340 const RISCVDisassembler *Dis =
341 static_cast<const RISCVDisassembler *
>(Decoder);
345 &RISCVMCRegisterClasses[RISCV::VRM4RegClassID]);
354 if (RegNo >= 32 || RegNo % 8)
357 const RISCVDisassembler *Dis =
358 static_cast<const RISCVDisassembler *
>(Decoder);
362 &RISCVMCRegisterClasses[RISCV::VRM8RegClassID]);
392 if (RegNo > 15 || RegNo % 2)
403 if (RegNo > 15 || RegNo % 4)
417 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
444template <
unsigned W
idth,
unsigned LowerBound>
450 if (Imm < LowerBound)
457template <
unsigned W
idth,
unsigned LowerBound>
463 if ((Imm + 1) < LowerBound)
474 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
545template <
unsigned T,
unsigned N>
606#include "RISCVGenDisassemblerTables.inc"
610struct DecoderListEntry {
611 const uint8_t *Table;
612 FeatureBitset ContainedFeatures;
615 bool haveContainedFeatures(
const FeatureBitset &ActiveFeatures)
const {
616 return ContainedFeatures.none() ||
617 (ContainedFeatures & ActiveFeatures).
any();
624 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
625 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
626 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
627 RISCV::FeatureVendorXCVbi};
630 RISCV::FeatureVendorXRivosVisni,
631 RISCV::FeatureVendorXRivosVizip,
635 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
636 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
637 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
638 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
639 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
640 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
641 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
642 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
643 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
647 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
648 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
649 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase};
651 RISCV::FeatureVendorXSiFivecdiscarddlone,
652 RISCV::FeatureVendorXSiFivecflushdlone,
656 RISCV::FeatureVendorXMIPSLSP,
657 RISCV::FeatureVendorXMIPSCMov,
658 RISCV::FeatureVendorXMIPSCBOP,
659 RISCV::FeatureVendorXMIPSEXECTL,
663 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
664 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
665 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
666 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
667 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
668 RISCV::FeatureVendorXTHeadVdot};
671 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
672 RISCV::FeatureVendorXAndesVBFHCvt,
673 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
674 RISCV::FeatureVendorXAndesVDot};
683 {DecoderTableXVentana32,
684 {RISCV::FeatureVendorXVentanaCondOps},
686 {DecoderTableXTHead32,
XTHeadGroup,
"T-Head extensions"},
687 {DecoderTableXSfvector32,
XSfVectorGroup,
"SiFive vector extensions"},
688 {DecoderTableXSfsystem32,
XSfSystemGroup,
"SiFive system extensions"},
689 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease},
"SiFive sf.cease"},
690 {DecoderTableXMIPS32,
XMIPSGroup,
"Mips extensions"},
691 {DecoderTableXAndes32,
XAndesGroup,
"Andes extensions"},
692 {DecoderTableXSMT32,
XSMTGroup,
"SpacemiT extensions"},
694 {DecoderTable32, {},
"standard 32-bit instructions"},
695 {DecoderTableRV32Only32, {},
"RV32-only standard 32-bit instructions"},
696 {DecoderTableZfinx32, {},
"Zfinx (Float in Integer)"},
697 {DecoderTableZdinxRV32Only32, {},
"RV32-only Zdinx (Double in Integer)"},
702template <>
constexpr uint32_t InsnBitWidth<uint16_t> = 16;
703template <>
constexpr uint32_t InsnBitWidth<uint32_t> = 32;
705template <>
constexpr uint32_t InsnBitWidth<uint64_t> = 48;
712 if (Bytes.
size() < 4) {
721 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
739 {DecoderTableXqccmp16,
740 {RISCV::FeatureVendorXqccmp},
741 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
742 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc},
"WCH QingKe XW"},
745 {DecoderTableZicfiss16, {},
"Zicfiss (Shadow Stack 16-bit)"},
746 {DecoderTable16, {},
"standard 16-bit instructions"},
747 {DecoderTableRV32Only16, {},
"RV32-only 16-bit instructions"},
749 {DecoderTableZcOverlap16,
751 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
755 ArrayRef<uint8_t> Bytes,
757 raw_ostream &CS)
const {
758 if (Bytes.
size() < 2) {
767 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
785 ArrayRef<uint8_t> Bytes,
787 raw_ostream &CS)
const {
788 if (Bytes.
size() < 6) {
795 for (
size_t i =
Size; i-- != 0;)
796 Insn += (
static_cast<uint64_t
>(Bytes[i]) << 8 * i);
799 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
815 ArrayRef<uint8_t> Bytes,
817 raw_ostream &CS)
const {
820 if ((Bytes[0] & 0b11) != 0b11)
825 if ((Bytes[0] & 0b1'1100) != 0b1'1100)
829 if ((Bytes[0] & 0b11'1111) == 0b01'1111) {
834 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
840 if (Bytes.
size() < 2) {
847 unsigned nnn = (Bytes[1] >> 4) & 0b111;
849 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 decodeImmFourOperand(MCInst &Inst, 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 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 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 DecodeFPR32CRegisterClass(MCInst &Inst, uint32_t RegNo, 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 decodeImmZibiOperand(MCInst &Inst, uint32_t Imm, int64_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 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 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 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 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.
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.