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 const RISCVDisassembler *Dis =
194 static_cast<const RISCVDisassembler *
>(
Decoder);
197 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
198 &getRISCVMCRegisterClass(RISCV::GPRPairRegClassID));
209 if (RegNo >= 8 || RegNo % 2)
221 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
226template <
unsigned RegisterClass,
unsigned NumRegsInClass,
unsigned LMul>
230 if (RegNo >= NumRegsInClass || RegNo % LMul)
233 const RISCVDisassembler *Dis =
234 static_cast<const RISCVDisassembler *
>(
Decoder);
238 &getRISCVMCRegisterClass(RegisterClass));
247 if (RegNo > 15 || RegNo % 2)
258 if (RegNo > 15 || RegNo % 4)
273 }
else if (
Imm <= 255) {
281 Result = 256 + ((
Imm & 0xF) << 4) + (((
Imm >> 4) & 1) << 3);
284 Result = Imm7To0 << 4;
297 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
303template <
int64_t Imm>
310template <
unsigned N,
unsigned LowerBound = 0>
316 if (
Imm < LowerBound)
327 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
337 if (!
Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) &&
362template <
unsigned N,
unsigned LowerBound = 1>
368 if ((
Imm + 1) < LowerBound)
398 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
411 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
428template <
unsigned T,
unsigned N>
473 bool IsRVE =
Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
488#include "RISCVGenDisassemblerTables.inc"
492struct DecoderListEntry {
493 const uint8_t *Table;
494 FeatureBitset ContainedFeatures;
497 bool haveContainedFeatures(
const FeatureBitset &ActiveFeatures)
const {
498 return ContainedFeatures.none() ||
499 (ContainedFeatures & ActiveFeatures).
any();
506 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
507 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
508 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
509 RISCV::FeatureVendorXCVbi};
512 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
513 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
514 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
515 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
516 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
517 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
518 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
519 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
520 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
524 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
525 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
526 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase,
527 RISCV::FeatureVendorXSfvfexpa, RISCV::FeatureVendorXSfvfexpa64e,
528 RISCV::FeatureVendorXSfvfbfexp16e, RISCV::FeatureVendorXSfvfexp16e,
529 RISCV::FeatureVendorXSfvfexp32e};
531 RISCV::FeatureVendorXSiFivecdiscarddlone,
532 RISCV::FeatureVendorXSiFivecflushdlone,
536 RISCV::FeatureVendorXMIPSLSP,
537 RISCV::FeatureVendorXMIPSCMov,
538 RISCV::FeatureVendorXMIPSCBOP,
539 RISCV::FeatureVendorXMIPSEXECTL,
543 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
544 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
545 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
546 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
547 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
548 RISCV::FeatureVendorXTHeadVdot};
551 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
552 RISCV::FeatureVendorXAndesVBFHCvt, RISCV::FeatureVendorXAndesVSIntH,
553 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
554 RISCV::FeatureVendorXAndesVDot};
557 RISCV::FeatureVendorXSMTVDotII};
565 {DecoderTableXTHead32,
XTHeadGroup,
"T-Head extensions"},
566 {DecoderTableXSfvector32,
XSfVectorGroup,
"SiFive vector extensions"},
567 {DecoderTableXSfsystem32,
XSfSystemGroup,
"SiFive system extensions"},
568 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease},
"SiFive sf.cease"},
569 {DecoderTableXMIPS32,
XMIPSGroup,
"Mips extensions"},
570 {DecoderTableXAndes32,
XAndesGroup,
"Andes extensions"},
571 {DecoderTableXSMT32,
XSMTGroup,
"SpacemiT extensions"},
572 {DecoderTableXAIF32,
XAIFGroup,
"AI Foundry extensions"},
574 {DecoderTable32, {},
"standard 32-bit instructions"},
575 {DecoderTableRV32Only32, {},
"RV32-only standard 32-bit instructions"},
576 {DecoderTableZfinx32, {},
"Zfinx (Float in Integer)"},
577 {DecoderTableZdinxRV32Only32, {},
"RV32-only Zdinx (Double in Integer)"},
582template <>
constexpr uint32_t InsnBitWidth<uint16_t> = 16;
583template <>
constexpr uint32_t InsnBitWidth<uint32_t> = 32;
585template <>
constexpr uint32_t InsnBitWidth<uint64_t> = 48;
592 if (Bytes.
size() < 4) {
601 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
619 {DecoderTableXqccmp16,
620 {RISCV::FeatureVendorXqccmp},
621 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
622 {DecoderTableXqccmi16,
623 {RISCV::FeatureVendorXqccmi},
624 "Xqccmi (Qualcomm 16-bit Instruction Lookup Table)"},
625 {DecoderTableXqccmt16,
626 {RISCV::FeatureVendorXqccmt},
627 "Xqccmt (Qualcomm 16-bit Table Jump Instructions)"},
628 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc},
"WCH QingKe XW"},
630 {DecoderTable16, {},
"standard 16-bit instructions"},
631 {DecoderTableRV32Only16, {},
"RV32-only 16-bit instructions"},
633 {DecoderTableZcOverlap16,
635 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
639 ArrayRef<uint8_t> Bytes,
641 raw_ostream &CS)
const {
642 if (Bytes.
size() < 2) {
651 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
669 ArrayRef<uint8_t> Bytes,
671 raw_ostream &CS)
const {
672 if (Bytes.
size() < 6) {
679 for (
size_t i =
Size; i-- != 0;)
680 Insn += (
static_cast<uint64_t>(Bytes[i]) << 8 * i);
683 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
699 ArrayRef<uint8_t> Bytes,
701 raw_ostream &CS)
const {
704 if ((Bytes[0] & 0b11) != 0b11)
714 if ((Bytes[0] & 0b1'1100) != 0b1'1100) {
720 if ((Bytes[0] & 0b11'1111) == 0b01'1111)
724 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
730 if (Bytes.
size() < 2) {
737 unsigned nnn = (Bytes[1] >> 4) & 0b111;
739 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 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.
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.