31#define DEBUG_TYPE "riscv-disassembler"
37 std::unique_ptr<MCInstrInfo const>
const MCII;
65 return new RISCVDisassembler(STI, Ctx,
T.createMCInstrInfo());
72 std::unique_ptr<MCRelocationInfo> &&RelInfo) {
77 DisInfo, Ctx, std::move(RelInfo));
101template <
unsigned FirstReg,
unsigned NumRegsInClass,
unsigned RVELimit = 0>
105 bool CheckRVE = RVELimit != 0 &&
106 Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
108 if (RegNo >= NumRegsInClass || (CheckRVE && RegNo >= RVELimit))
123 if (
Reg != RISCV::X1 &&
Reg != RISCV::X5)
156template <auto DecodeFn, auto PredicateFn>
160 if (!PredicateFn(RegNo))
162 return DecodeFn(Inst, RegNo, Address,
Decoder);
179 if (RegNo >= 32 || RegNo % 2)
182 const RISCVDisassembler *Dis =
183 static_cast<const RISCVDisassembler *
>(
Decoder);
186 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
187 &getRISCVMCRegisterClass(RISCV::GPRPairRegClassID));
198 if (RegNo >= 8 || RegNo % 2)
201 const RISCVDisassembler *Dis =
202 static_cast<const RISCVDisassembler *
>(
Decoder);
205 RISCV::X8 + RegNo, RISCV::sub_gpr_even,
206 &getRISCVMCRegisterClass(RISCV::GPRPairCRegClassID));
217 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
222template <
unsigned RegisterClass,
unsigned NumRegsInClass,
unsigned LMul>
226 if (RegNo >= NumRegsInClass || RegNo % LMul)
229 const RISCVDisassembler *Dis =
230 static_cast<const RISCVDisassembler *
>(
Decoder);
234 &getRISCVMCRegisterClass(RegisterClass));
243 if (RegNo > 15 || RegNo % 2)
254 if (RegNo > 15 || RegNo % 4)
269 }
else if (
Imm <= 255) {
277 Result = 256 + ((
Imm & 0xF) << 4) + (((
Imm >> 4) & 1) << 3);
280 Result = Imm7To0 << 4;
293 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
320template <
unsigned W
idth,
unsigned LowerBound>
326 if (
Imm < LowerBound)
333template <
unsigned W
idth,
unsigned LowerBound>
339 if ((
Imm + 1) < LowerBound)
350 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
360 if (!
Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) &&
374 Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) ? 64 : 32;
375 if (
Imm != ExpectedValue)
431 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
444 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
461template <
unsigned T,
unsigned N>
497 bool IsRVE =
Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
512#include "RISCVGenDisassemblerTables.inc"
516struct DecoderListEntry {
517 const uint8_t *Table;
518 FeatureBitset ContainedFeatures;
521 bool haveContainedFeatures(
const FeatureBitset &ActiveFeatures)
const {
522 return ContainedFeatures.none() ||
523 (ContainedFeatures & ActiveFeatures).
any();
530 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
531 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
532 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
533 RISCV::FeatureVendorXCVbi};
536 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
537 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
538 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
539 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
540 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
541 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
542 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
543 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
544 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
548 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
549 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
550 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase,
551 RISCV::FeatureVendorXSfvfexpa, RISCV::FeatureVendorXSfvfexpa64e,
552 RISCV::FeatureVendorXSfvfbfexp16e, RISCV::FeatureVendorXSfvfexp16e,
553 RISCV::FeatureVendorXSfvfexp32e};
555 RISCV::FeatureVendorXSiFivecdiscarddlone,
556 RISCV::FeatureVendorXSiFivecflushdlone,
560 RISCV::FeatureVendorXMIPSLSP,
561 RISCV::FeatureVendorXMIPSCMov,
562 RISCV::FeatureVendorXMIPSCBOP,
563 RISCV::FeatureVendorXMIPSEXECTL,
567 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
568 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
569 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
570 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
571 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
572 RISCV::FeatureVendorXTHeadVdot};
575 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
576 RISCV::FeatureVendorXAndesVBFHCvt, RISCV::FeatureVendorXAndesVSIntH,
577 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
578 RISCV::FeatureVendorXAndesVDot};
581 RISCV::FeatureVendorXSMTVDotII};
589 {DecoderTableXVentana32,
590 {RISCV::FeatureVendorXVentanaCondOps},
592 {DecoderTableXTHead32,
XTHeadGroup,
"T-Head extensions"},
593 {DecoderTableXSfvector32,
XSfVectorGroup,
"SiFive vector extensions"},
594 {DecoderTableXSfsystem32,
XSfSystemGroup,
"SiFive system extensions"},
595 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease},
"SiFive sf.cease"},
596 {DecoderTableXMIPS32,
XMIPSGroup,
"Mips extensions"},
597 {DecoderTableXAndes32,
XAndesGroup,
"Andes extensions"},
598 {DecoderTableXSMT32,
XSMTGroup,
"SpacemiT extensions"},
599 {DecoderTableXAIF32,
XAIFGroup,
"AI Foundry extensions"},
601 {DecoderTable32, {},
"standard 32-bit instructions"},
602 {DecoderTableRV32Only32, {},
"RV32-only standard 32-bit instructions"},
603 {DecoderTableZfinx32, {},
"Zfinx (Float in Integer)"},
604 {DecoderTableZdinxRV32Only32, {},
"RV32-only Zdinx (Double in Integer)"},
609template <>
constexpr uint32_t InsnBitWidth<uint16_t> = 16;
610template <>
constexpr uint32_t InsnBitWidth<uint32_t> = 32;
612template <>
constexpr uint32_t InsnBitWidth<uint64_t> = 48;
619 if (Bytes.
size() < 4) {
628 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
646 {DecoderTableXqccmp16,
647 {RISCV::FeatureVendorXqccmp},
648 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
649 {DecoderTableXqccmt16,
650 {RISCV::FeatureVendorXqccmt},
651 "Xqccmt (Qualcomm 16-bit Table Jump Instructions)"},
652 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc},
"WCH QingKe XW"},
655 {DecoderTableZicfiss16, {},
"Zicfiss (Shadow Stack 16-bit)"},
656 {DecoderTable16, {},
"standard 16-bit instructions"},
657 {DecoderTableRV32Only16, {},
"RV32-only 16-bit instructions"},
659 {DecoderTableZcOverlap16,
661 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
665 ArrayRef<uint8_t> Bytes,
667 raw_ostream &CS)
const {
668 if (Bytes.
size() < 2) {
677 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
695 ArrayRef<uint8_t> Bytes,
697 raw_ostream &CS)
const {
698 if (Bytes.
size() < 6) {
705 for (
size_t i =
Size; i-- != 0;)
706 Insn += (
static_cast<uint64_t>(Bytes[i]) << 8 * i);
709 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
725 ArrayRef<uint8_t> Bytes,
727 raw_ostream &CS)
const {
730 if ((Bytes[0] & 0b11) != 0b11)
740 if ((Bytes[0] & 0b1'1100) != 0b1'1100) {
746 if ((Bytes[0] & 0b11'1111) == 0b01'1111)
750 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
756 if (Bytes.
size() < 2) {
763 unsigned nnn = (Bytes[1] >> 4) & 0b111;
765 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!")
unsigned const MCDisassembler * Decoder
#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
constexpr auto DecodeGPRNoX31RegisterClass
static DecodeStatus decodeUImm7EqXLenOperand(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)
constexpr auto DecodeGPRPairNoX0RegisterClass
constexpr bool PredNoX2(uint32_t RegNo)
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 decodeImmFourOperand(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus decodeUImmLog2XLenNonZeroOperand(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 DecodeVectorRegisterClass(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[]
constexpr bool PredNoX0(uint32_t RegNo)
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 MCSymbolizer * createRISCVMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo)
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 decodeUImm20Operand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRPairRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeSImm12LoOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
constexpr auto DecodeGPRNoX2RegisterClass
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 DecodeFilteredRegisterClass(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 DecodeYBNDSWImm(MCInst &Inst, uint64_t Imm, int64_t Address, const MCDisassembler *Decoder)
constexpr bool PredNoX31(uint32_t RegNo)
static DecodeStatus decodeFRMArg(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRX1RegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static constexpr FeatureBitset XTHeadGroup
static DecodeStatus DecodeSimpleRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRS07RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const void *Decoder)
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)
constexpr auto DecodeGPRNoX0RegisterClass
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)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
Container class for subtarget features.
Context object for machine code objects.
Superclass for all disassemblers.
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.
Symbolize and annotate disassembled instructions.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
int(* LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t OpSize, uint64_t InstSize, int TagType, void *TagBuf)
The type for the operand information call back function.
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 MCSymbolizer * createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo)
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 RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn)
RegisterMCSymbolizer - Register an MCSymbolizer implementation for the given target.
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.