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) &&
351 Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) ? 64 : 32;
352 if (
Imm != ExpectedValue)
376template <
unsigned N,
unsigned LowerBound = 1>
382 if ((
Imm + 1) < LowerBound)
412 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
425 if (!
Decoder->tryAddingSymbolicOperand(Inst,
Value, Address,
442template <
unsigned T,
unsigned N>
487 bool IsRVE =
Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
502#include "RISCVGenDisassemblerTables.inc"
506struct DecoderListEntry {
507 const uint8_t *Table;
508 FeatureBitset ContainedFeatures;
511 bool haveContainedFeatures(
const FeatureBitset &ActiveFeatures)
const {
512 return ContainedFeatures.none() ||
513 (ContainedFeatures & ActiveFeatures).
any();
520 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
521 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
522 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
523 RISCV::FeatureVendorXCVbi};
526 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
527 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
528 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
529 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
530 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
531 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
532 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
533 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
534 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
538 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
539 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
540 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase,
541 RISCV::FeatureVendorXSfvfexpa, RISCV::FeatureVendorXSfvfexpa64e,
542 RISCV::FeatureVendorXSfvfbfexp16e, RISCV::FeatureVendorXSfvfexp16e,
543 RISCV::FeatureVendorXSfvfexp32e};
545 RISCV::FeatureVendorXSiFivecdiscarddlone,
546 RISCV::FeatureVendorXSiFivecflushdlone,
550 RISCV::FeatureVendorXMIPSLSP,
551 RISCV::FeatureVendorXMIPSCMov,
552 RISCV::FeatureVendorXMIPSCBOP,
553 RISCV::FeatureVendorXMIPSEXECTL,
557 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
558 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
559 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
560 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
561 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
562 RISCV::FeatureVendorXTHeadVdot};
565 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
566 RISCV::FeatureVendorXAndesVBFHCvt, RISCV::FeatureVendorXAndesVSIntH,
567 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
568 RISCV::FeatureVendorXAndesVDot};
571 RISCV::FeatureVendorXSMTVDotII};
579 {DecoderTableXTHead32,
XTHeadGroup,
"T-Head extensions"},
580 {DecoderTableXSfvector32,
XSfVectorGroup,
"SiFive vector extensions"},
581 {DecoderTableXSfsystem32,
XSfSystemGroup,
"SiFive system extensions"},
582 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease},
"SiFive sf.cease"},
583 {DecoderTableXMIPS32,
XMIPSGroup,
"Mips extensions"},
584 {DecoderTableXAndes32,
XAndesGroup,
"Andes extensions"},
585 {DecoderTableXSMT32,
XSMTGroup,
"SpacemiT extensions"},
586 {DecoderTableXAIF32,
XAIFGroup,
"AI Foundry extensions"},
588 {DecoderTable32, {},
"standard 32-bit instructions"},
589 {DecoderTableRV32Only32, {},
"RV32-only standard 32-bit instructions"},
590 {DecoderTableZfinx32, {},
"Zfinx (Float in Integer)"},
591 {DecoderTableZdinxRV32Only32, {},
"RV32-only Zdinx (Double in Integer)"},
596template <>
constexpr uint32_t InsnBitWidth<uint16_t> = 16;
597template <>
constexpr uint32_t InsnBitWidth<uint32_t> = 32;
599template <>
constexpr uint32_t InsnBitWidth<uint64_t> = 48;
606 if (Bytes.
size() < 4) {
615 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
633 {DecoderTableXqccmp16,
634 {RISCV::FeatureVendorXqccmp},
635 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
636 {DecoderTableXqccmi16,
637 {RISCV::FeatureVendorXqccmi},
638 "Xqccmi (Qualcomm 16-bit Instruction Lookup Table)"},
639 {DecoderTableXqccmt16,
640 {RISCV::FeatureVendorXqccmt},
641 "Xqccmt (Qualcomm 16-bit Table Jump Instructions)"},
642 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc},
"WCH QingKe XW"},
644 {DecoderTable16, {},
"standard 16-bit instructions"},
645 {DecoderTableRV32Only16, {},
"RV32-only 16-bit instructions"},
647 {DecoderTableZcOverlap16,
649 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
653 ArrayRef<uint8_t> Bytes,
655 raw_ostream &CS)
const {
656 if (Bytes.
size() < 2) {
665 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
683 ArrayRef<uint8_t> Bytes,
685 raw_ostream &CS)
const {
686 if (Bytes.
size() < 6) {
693 for (
size_t i =
Size; i-- != 0;)
694 Insn += (
static_cast<uint64_t>(Bytes[i]) << 8 * i);
697 if (!
Entry.haveContainedFeatures(STI.getFeatureBits()))
713 ArrayRef<uint8_t> Bytes,
715 raw_ostream &CS)
const {
718 if ((Bytes[0] & 0b11) != 0b11)
728 if ((Bytes[0] & 0b1'1100) != 0b1'1100) {
734 if ((Bytes[0] & 0b11'1111) == 0b01'1111)
738 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
744 if (Bytes.
size() < 2) {
751 unsigned nnn = (Bytes[1] >> 4) & 0b111;
753 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 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.