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))
116template <
unsigned PhysReg,
unsigned Encoding>
120 assert(RegNo == Encoding);
125template <
unsigned PhysReg,
unsigned Encoding>
135template <auto DecodeFn, auto PredicateFn>
139 if (!PredicateFn(RegNo))
141 return DecodeFn(Inst, RegNo, Address,
Decoder);
161 if (RegNo >= 32 || RegNo % 2)
164 const RISCVDisassembler *Dis =
165 static_cast<const RISCVDisassembler *
>(
Decoder);
168 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
169 &getRISCVMCRegisterClass(RISCV::GPRPairRegClassID));
180 if (RegNo >= 8 || RegNo % 2)
192 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
197template <
unsigned RegisterClass,
unsigned NumRegsInClass,
unsigned LMul>
201 if (RegNo >= NumRegsInClass || RegNo % LMul)
204 const RISCVDisassembler *Dis =
205 static_cast<const RISCVDisassembler *
>(
Decoder);
209 &getRISCVMCRegisterClass(RegisterClass));
218 if (RegNo > 15 || RegNo % 2)
229 if (RegNo > 15 || RegNo % 4)
244 }
else if (
Imm <= 255) {
252 Result = 256 + ((
Imm & 0xF) << 4) + (((
Imm >> 4) & 1) << 3);
255 Result = Imm7To0 << 4;
268 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
274template <
int64_t Imm>
281template <
unsigned N,
unsigned LowerBound = 0>
287 if (
Imm < LowerBound)
298 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
308 if (!
Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) &&
322 Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) ? 64 : 32;
323 if (
Imm != ExpectedValue)
347template <
unsigned N,
unsigned LowerBound = 1>
353 if ((
Imm + 1) < LowerBound)
383 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
396 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
413template <
unsigned T,
unsigned N>
449 bool IsRVE =
Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
464#include "RISCVGenDisassemblerTables.inc"
468struct DecoderListEntry {
469 const uint8_t *Table;
470 FeatureBitset ContainedFeatures;
473 bool haveContainedFeatures(
const FeatureBitset &ActiveFeatures)
const {
474 return ContainedFeatures.none() ||
475 (ContainedFeatures & ActiveFeatures).
any();
482 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
483 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
484 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
485 RISCV::FeatureVendorXCVbi};
488 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
489 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
490 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
491 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
492 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
493 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
494 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
495 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
496 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
500 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
501 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
502 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase,
503 RISCV::FeatureVendorXSfvfexpa, RISCV::FeatureVendorXSfvfexpa64e,
504 RISCV::FeatureVendorXSfvfbfexp16e, RISCV::FeatureVendorXSfvfexp16e,
505 RISCV::FeatureVendorXSfvfexp32e};
507 RISCV::FeatureVendorXSiFivecdiscarddlone,
508 RISCV::FeatureVendorXSiFivecflushdlone,
512 RISCV::FeatureVendorXMIPSLSP,
513 RISCV::FeatureVendorXMIPSCMov,
514 RISCV::FeatureVendorXMIPSCBOP,
515 RISCV::FeatureVendorXMIPSEXECTL,
519 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
520 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
521 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
522 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
523 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
524 RISCV::FeatureVendorXTHeadVdot};
527 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
528 RISCV::FeatureVendorXAndesVBFHCvt, RISCV::FeatureVendorXAndesVSIntH,
529 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
530 RISCV::FeatureVendorXAndesVDot};
533 RISCV::FeatureVendorXSMTVDotII};
541 {DecoderTableXTHead32,
XTHeadGroup,
"T-Head extensions"},
542 {DecoderTableXSfvector32,
XSfVectorGroup,
"SiFive vector extensions"},
543 {DecoderTableXSfsystem32,
XSfSystemGroup,
"SiFive system extensions"},
544 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease},
"SiFive sf.cease"},
545 {DecoderTableXMIPS32,
XMIPSGroup,
"Mips extensions"},
546 {DecoderTableXAndes32,
XAndesGroup,
"Andes extensions"},
547 {DecoderTableXSMT32,
XSMTGroup,
"SpacemiT extensions"},
548 {DecoderTableXAIF32,
XAIFGroup,
"AI Foundry extensions"},
550 {DecoderTable32, {},
"standard 32-bit instructions"},
551 {DecoderTableRV32Only32, {},
"RV32-only standard 32-bit instructions"},
552 {DecoderTableZfinx32, {},
"Zfinx (Float in Integer)"},
553 {DecoderTableZdinxRV32Only32, {},
"RV32-only Zdinx (Double in Integer)"},
558template <>
constexpr uint32_t InsnBitWidth<uint16_t> = 16;
559template <>
constexpr uint32_t InsnBitWidth<uint32_t> = 32;
561template <>
constexpr uint32_t InsnBitWidth<uint64_t> = 48;
568 if (Bytes.
size() < 4) {
577 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
595 {DecoderTableXqccmp16,
596 {RISCV::FeatureVendorXqccmp},
597 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
598 {DecoderTableXqccmt16,
599 {RISCV::FeatureVendorXqccmt},
600 "Xqccmt (Qualcomm 16-bit Table Jump Instructions)"},
601 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc},
"WCH QingKe XW"},
603 {DecoderTable16, {},
"standard 16-bit instructions"},
604 {DecoderTableRV32Only16, {},
"RV32-only 16-bit instructions"},
606 {DecoderTableZcOverlap16,
608 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
612 ArrayRef<uint8_t> Bytes,
614 raw_ostream &CS)
const {
615 if (Bytes.
size() < 2) {
624 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
642 ArrayRef<uint8_t> Bytes,
644 raw_ostream &CS)
const {
645 if (Bytes.
size() < 6) {
652 for (
size_t i =
Size; i-- != 0;)
653 Insn += (
static_cast<uint64_t>(Bytes[i]) << 8 * i);
656 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
672 ArrayRef<uint8_t> Bytes,
674 raw_ostream &CS)
const {
677 if ((Bytes[0] & 0b11) != 0b11)
687 if ((Bytes[0] & 0b1'1100) != 0b1'1100) {
693 if ((Bytes[0] & 0b11'1111) == 0b01'1111)
697 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
703 if (Bytes.
size() < 2) {
710 unsigned nnn = (Bytes[1] >> 4) & 0b111;
712 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
static DecodeStatus decodeFixedImmOperand(MCInst &Inst, const MCDisassembler *Decoder)
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[]
constexpr auto DecodeGPRX1X5RegisterClass
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 decodeXqccmpRlistS0(MCInst &Inst, uint32_t Imm, uint64_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 decodeUImmPlus1Operand(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)
constexpr bool PredX1OrX5(uint32_t RegNo)
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 decodeUImmOperand(MCInst &Inst, uint32_t Imm, int64_t Address, 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 constexpr FeatureBitset XTHeadGroup
static DecodeStatus DecodeSimpleRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeSingleRegister(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)
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 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.