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);
182 if (Rs1 == Rd1 || Rs1 == Rd2 || Rd1 == Rd2)
190 if (RegNo >= 32 || RegNo % 2)
193 bool IsRVE =
Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
194 if (IsRVE && RegNo >= 16)
197 const RISCVDisassembler *Dis =
198 static_cast<const RISCVDisassembler *
>(
Decoder);
201 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
202 &getRISCVMCRegisterClass(RISCV::GPRPairRegClassID));
213 if (RegNo >= 8 || RegNo % 2)
223 bool IsRVE =
Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
224 if (RegNo >= 8 || (IsRVE && RegNo > 1))
227 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
232template <
unsigned RegisterClass,
unsigned NumRegsInClass,
unsigned LMul>
236 if (RegNo >= NumRegsInClass || RegNo % LMul)
239 const RISCVDisassembler *Dis =
240 static_cast<const RISCVDisassembler *
>(
Decoder);
244 &getRISCVMCRegisterClass(RegisterClass));
253 if (RegNo > 15 || RegNo % 2)
264 if (RegNo > 15 || RegNo % 4)
279 }
else if (
Imm <= 255) {
287 Result = 256 + ((
Imm & 0xF) << 4) + (((
Imm >> 4) & 1) << 3);
290 Result = Imm7To0 << 4;
303 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
309template <
int64_t Imm>
316template <
unsigned N,
unsigned LowerBound = 0>
322 if (
Imm < LowerBound)
333 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
343 if (!
Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) &&
368template <
unsigned N,
unsigned LowerBound = 1>
374 if ((
Imm + 1) < LowerBound)
404 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
417 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
434template <
unsigned T,
unsigned N>
479 bool IsRVE =
Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
506#include "RISCVGenDisassemblerTables.inc"
510struct DecoderListEntry {
511 const uint8_t *Table;
512 FeatureBitset ContainedFeatures;
515 bool haveContainedFeatures(
const FeatureBitset &ActiveFeatures)
const {
516 return ContainedFeatures.none() ||
517 (ContainedFeatures & ActiveFeatures).
any();
524 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
525 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
526 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
527 RISCV::FeatureVendorXCVbi};
530 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
531 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
532 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
533 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
534 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
535 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
536 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
537 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
538 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
542 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
543 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
544 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase,
545 RISCV::FeatureVendorXSfvfexpa, RISCV::FeatureVendorXSfvfexpa64e,
546 RISCV::FeatureVendorXSfvfbfexp16e, RISCV::FeatureVendorXSfvfexp16e,
547 RISCV::FeatureVendorXSfvfexp32e};
549 RISCV::FeatureVendorXSiFivecdiscarddlone,
550 RISCV::FeatureVendorXSiFivecflushdlone,
554 RISCV::FeatureVendorXMIPSLSP,
555 RISCV::FeatureVendorXMIPSCMov,
556 RISCV::FeatureVendorXMIPSCBOP,
557 RISCV::FeatureVendorXMIPSEXECTL,
561 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
562 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
563 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
564 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
565 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
566 RISCV::FeatureVendorXTHeadVdot};
569 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
570 RISCV::FeatureVendorXAndesVBFHCvt, RISCV::FeatureVendorXAndesVSIntH,
571 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
572 RISCV::FeatureVendorXAndesVDot};
575 RISCV::FeatureVendorXSMTVDotII};
583 {DecoderTableXTHead32,
XTHeadGroup,
"T-Head extensions"},
584 {DecoderTableXSfvector32,
XSfVectorGroup,
"SiFive vector extensions"},
585 {DecoderTableXSfsystem32,
XSfSystemGroup,
"SiFive system extensions"},
586 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease},
"SiFive sf.cease"},
587 {DecoderTableXMIPS32,
XMIPSGroup,
"Mips extensions"},
588 {DecoderTableXAndes32,
XAndesGroup,
"Andes extensions"},
589 {DecoderTableXSMT32,
XSMTGroup,
"SpacemiT extensions"},
590 {DecoderTableXAIF32,
XAIFGroup,
"AI Foundry extensions"},
592 {DecoderTable32, {},
"standard 32-bit instructions"},
593 {DecoderTableRV32Only32, {},
"RV32-only standard 32-bit instructions"},
594 {DecoderTableZfinx32, {},
"Zfinx (Float in Integer)"},
595 {DecoderTableZdinxRV32Only32, {},
"RV32-only Zdinx (Double in Integer)"},
600template <>
constexpr uint32_t InsnBitWidth<uint16_t> = 16;
601template <>
constexpr uint32_t InsnBitWidth<uint32_t> = 32;
603template <>
constexpr uint32_t InsnBitWidth<uint64_t> = 48;
610 if (Bytes.
size() < 4) {
619 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
637 {DecoderTableXqccmp16,
638 {RISCV::FeatureVendorXqccmp},
639 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
640 {DecoderTableXqccmi16,
641 {RISCV::FeatureVendorXqccmi},
642 "Xqccmi (Qualcomm 16-bit Instruction Lookup Table)"},
643 {DecoderTableXqccmt16,
644 {RISCV::FeatureVendorXqccmt},
645 "Xqccmt (Qualcomm 16-bit Table Jump Instructions)"},
646 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc},
"WCH QingKe XW"},
648 {DecoderTable16, {},
"standard 16-bit instructions"},
649 {DecoderTableRV32Only16, {},
"RV32-only 16-bit instructions"},
651 {DecoderTableZcOverlap16,
653 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
657 ArrayRef<uint8_t> Bytes,
659 raw_ostream &CS)
const {
660 if (Bytes.
size() < 2) {
669 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
687 ArrayRef<uint8_t> Bytes,
689 raw_ostream &CS)
const {
690 if (Bytes.
size() < 6) {
697 for (
size_t i =
Size; i-- != 0;)
698 Insn += (
static_cast<uint64_t>(Bytes[i]) << 8 * i);
701 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
717 ArrayRef<uint8_t> Bytes,
719 raw_ostream &CS)
const {
722 if ((Bytes[0] & 0b11) != 0b11)
732 if ((Bytes[0] & 0b1'1100) != 0b1'1100) {
738 if ((Bytes[0] & 0b11'1111) == 0b01'1111)
742 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
748 if (Bytes.
size() < 2) {
755 unsigned nnn = (Bytes[1] >> 4) & 0b111;
757 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 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 decodeCVInsertIs2Operand(MCInst &Inst, uint32_t Imm, int64_t Address, 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 decodeTHMemPairRs1Operand(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 decodeTHMemIdxRs1Operand(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus decodeMvsa01Rs2Operand(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 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 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 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.
unsigned getNumOperands() const
void addOperand(const MCOperand Op)
const MCOperand & getOperand(unsigned i) const
Interface to description of machine instruction set.
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
MCRegister getReg() const
Returns the register number.
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.