LLVM 23.0.0git
RISCVDisassembler.cpp
Go to the documentation of this file.
1//===-- RISCVDisassembler.cpp - Disassembler for RISC-V -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the RISCVDisassembler class.
10//
11//===----------------------------------------------------------------------===//
12
16#include "llvm/MC/MCContext.h"
17#include "llvm/MC/MCDecoder.h"
20#include "llvm/MC/MCInst.h"
21#include "llvm/MC/MCInstrInfo.h"
26#include "llvm/Support/Endian.h"
27
28using namespace llvm;
29using namespace llvm::MCD;
30
31#define DEBUG_TYPE "riscv-disassembler"
32
34
35namespace {
36class RISCVDisassembler : public MCDisassembler {
37 std::unique_ptr<MCInstrInfo const> const MCII;
38
39public:
40 RISCVDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx,
41 MCInstrInfo const *MCII)
42 : MCDisassembler(STI, Ctx), MCII(MCII) {}
43
44 DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
45 ArrayRef<uint8_t> Bytes, uint64_t Address,
46 raw_ostream &CStream) const override;
47
48private:
49 DecodeStatus getInstruction48(MCInst &Instr, uint64_t &Size,
50 ArrayRef<uint8_t> Bytes, uint64_t Address,
51 raw_ostream &CStream) const;
52
53 DecodeStatus getInstruction32(MCInst &Instr, uint64_t &Size,
54 ArrayRef<uint8_t> Bytes, uint64_t Address,
55 raw_ostream &CStream) const;
56 DecodeStatus getInstruction16(MCInst &Instr, uint64_t &Size,
57 ArrayRef<uint8_t> Bytes, uint64_t Address,
58 raw_ostream &CStream) const;
59};
60} // end anonymous namespace
61
63 const MCSubtargetInfo &STI,
64 MCContext &Ctx) {
65 return new RISCVDisassembler(STI, Ctx, T.createMCInstrInfo());
66}
67
80
81template <unsigned FirstReg, unsigned NumRegsInClass, unsigned RVELimit = 0>
83 uint64_t Address,
84 const MCDisassembler *Decoder) {
85 bool CheckRVE = RVELimit != 0 &&
86 Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
87
88 if (RegNo >= NumRegsInClass || (CheckRVE && RegNo >= RVELimit))
90
91 MCRegister Reg = FirstReg + RegNo;
94}
95
96constexpr auto DecodeGPRRegisterClass =
97 DecodeSimpleRegisterClass<RISCV::X0, 32, /*RVELimit=*/16>;
98
100 uint64_t Address,
101 const MCDisassembler *Decoder) {
102 MCRegister Reg = RISCV::X0 + RegNo;
103 if (Reg != RISCV::X1 && Reg != RISCV::X5)
105
108}
109
111 const MCDisassembler *Decoder) {
112 Inst.addOperand(MCOperand::createReg(RISCV::X1));
114}
115
117 const MCDisassembler *Decoder) {
118 Inst.addOperand(MCOperand::createReg(RISCV::X2));
120}
121
123 uint32_t Address,
124 const MCDisassembler *Decoder) {
125 assert(RegNo == 2);
126 Inst.addOperand(MCOperand::createReg(RISCV::X2));
128}
129
131 const MCDisassembler *Decoder) {
132 Inst.addOperand(MCOperand::createReg(RISCV::X5));
134}
135
137 uint64_t Address,
138 const MCDisassembler *Decoder) {
139 if (RegNo == 0)
141
142 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
143}
144
146 uint32_t Address,
147 const MCDisassembler *Decoder) {
148 if (RegNo == 2)
150
151 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
152}
153
155 uint64_t Address,
156 const MCDisassembler *Decoder) {
157 if (RegNo == 31) {
159 }
160
161 return DecodeGPRRegisterClass(Inst, RegNo, Address, Decoder);
162}
163
165 uint64_t Address,
166 const MCDisassembler *Decoder) {
167 if (RegNo >= 32 || RegNo % 2)
169
170 const RISCVDisassembler *Dis =
171 static_cast<const RISCVDisassembler *>(Decoder);
172 const MCRegisterInfo *RI = Dis->getContext().getRegisterInfo();
174 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
175 &RISCVMCRegisterClasses[RISCV::GPRPairRegClassID]);
178}
179
180static DecodeStatus
182 const MCDisassembler *Decoder) {
183 if (RegNo == 0)
185
186 return DecodeGPRPairRegisterClass(Inst, RegNo, Address, Decoder);
187}
188
190 uint64_t Address,
191 const MCDisassembler *Decoder) {
192 if (RegNo >= 8 || RegNo % 2)
194
195 const RISCVDisassembler *Dis =
196 static_cast<const RISCVDisassembler *>(Decoder);
197 const MCRegisterInfo *RI = Dis->getContext().getRegisterInfo();
199 RISCV::X8 + RegNo, RISCV::sub_gpr_even,
200 &RISCVMCRegisterClasses[RISCV::GPRPairCRegClassID]);
203}
204
206 uint64_t Address,
207 const void *Decoder) {
208 if (RegNo >= 8)
210
211 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
214}
215
217 uint64_t Address,
218 const MCDisassembler *Decoder) {
219 if (RegNo >= 32)
221
222 MCRegister Reg = RISCV::V0 + RegNo;
225}
226
228 uint64_t Address,
229 const MCDisassembler *Decoder) {
230 if (RegNo >= 32 || RegNo % 2)
232
233 const RISCVDisassembler *Dis =
234 static_cast<const RISCVDisassembler *>(Decoder);
235 const MCRegisterInfo *RI = Dis->getContext().getRegisterInfo();
237 RI->getMatchingSuperReg(RISCV::V0 + RegNo, RISCV::sub_vrm1_0,
238 &RISCVMCRegisterClasses[RISCV::VRM2RegClassID]);
239
242}
243
245 uint64_t Address,
246 const MCDisassembler *Decoder) {
247 if (RegNo >= 32 || RegNo % 4)
249
250 const RISCVDisassembler *Dis =
251 static_cast<const RISCVDisassembler *>(Decoder);
252 const MCRegisterInfo *RI = Dis->getContext().getRegisterInfo();
254 RI->getMatchingSuperReg(RISCV::V0 + RegNo, RISCV::sub_vrm1_0,
255 &RISCVMCRegisterClasses[RISCV::VRM4RegClassID]);
256
259}
260
262 uint64_t Address,
263 const MCDisassembler *Decoder) {
264 if (RegNo >= 32 || RegNo % 8)
266
267 const RISCVDisassembler *Dis =
268 static_cast<const RISCVDisassembler *>(Decoder);
269 const MCRegisterInfo *RI = Dis->getContext().getRegisterInfo();
271 RI->getMatchingSuperReg(RISCV::V0 + RegNo, RISCV::sub_vrm1_0,
272 &RISCVMCRegisterClasses[RISCV::VRM8RegClassID]);
273
276}
277
279 uint64_t Address,
280 const MCDisassembler *Decoder) {
281 if (RegNo)
283
284 Inst.addOperand(MCOperand::createReg(RISCV::V0));
286}
287
289 uint64_t Address,
290 const MCDisassembler *Decoder) {
291 if (RegNo > 15)
293
294 MCRegister Reg = RISCV::T0 + RegNo;
297}
298
300 uint64_t Address,
301 const MCDisassembler *Decoder) {
302 if (RegNo > 15 || RegNo % 2)
304
305 MCRegister Reg = RISCV::T0 + RegNo;
308}
309
311 uint64_t Address,
312 const MCDisassembler *Decoder) {
313 if (RegNo > 15 || RegNo % 4)
315
316 MCRegister Reg = RISCV::T0 + RegNo;
319}
320
322 uint64_t Address,
323 const MCDisassembler *Decoder) {
324 if (RegNo >= 2)
326
327 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
328
331}
332
334 const MCDisassembler *Decoder) {
337}
338
340 const MCDisassembler *Decoder) {
343}
344
345template <unsigned N>
347 int64_t Address,
348 const MCDisassembler *Decoder) {
349 assert(isUInt<N>(Imm) && "Invalid immediate");
352}
353
354template <unsigned Width, unsigned LowerBound>
356 int64_t Address,
357 const MCDisassembler *Decoder) {
358 assert(isUInt<Width>(Imm) && "Invalid immediate");
359
360 if (Imm < LowerBound)
362
365}
366
367template <unsigned Width, unsigned LowerBound>
369 int64_t Address,
370 const MCDisassembler *Decoder) {
371 assert(isUInt<Width>(Imm) && "Invalid immediate");
372
373 if ((Imm + 1) < LowerBound)
375
376 Inst.addOperand(MCOperand::createImm(Imm + 1));
378}
379
381 int64_t Address,
382 const MCDisassembler *Decoder) {
383 assert(isUInt<3>(Imm) && "Invalid Slist immediate");
384 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
385 Inst.addOperand(MCOperand::createImm(Slist[Imm]));
387}
388
390 int64_t Address,
391 const MCDisassembler *Decoder) {
392 assert(isUInt<6>(Imm) && "Invalid immediate");
393
394 if (!Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) &&
395 !isUInt<5>(Imm))
397
400}
401
402template <unsigned N>
404 int64_t Address,
405 const MCDisassembler *Decoder) {
406 if (Imm == 0)
408 return decodeUImmOperand<N>(Inst, Imm, Address, Decoder);
409}
410
411static DecodeStatus
413 const MCDisassembler *Decoder) {
414 if (Imm == 0)
416 return decodeUImmLog2XLenOperand(Inst, Imm, Address, Decoder);
417}
418
419template <unsigned N>
421 int64_t Address,
422 const MCDisassembler *Decoder) {
423 assert(isUInt<N>(Imm) && "Invalid immediate");
424 Inst.addOperand(MCOperand::createImm(Imm + 1));
426}
427
429 int64_t Address,
430 const MCDisassembler *Decoder) {
431 assert(isUInt<5>(Imm) && "Invalid immediate");
432 Inst.addOperand(MCOperand::createImm(Imm ? Imm : -1LL));
434}
435
436template <unsigned N>
438 int64_t Address,
439 const MCDisassembler *Decoder) {
440 assert(isUInt<N>(Imm) && "Invalid immediate");
441 // Sign-extend the number in the bottom N bits of Imm
444}
445
446template <unsigned N>
448 int64_t Address,
449 const MCDisassembler *Decoder) {
450 if (Imm == 0)
452 return decodeSImmOperand<N>(Inst, Imm, Address, Decoder);
453}
454
455template <unsigned T, unsigned N>
457 int64_t Address,
458 const MCDisassembler *Decoder) {
459 assert(isUInt<T - N + 1>(Imm) && "Invalid immediate");
460 // Sign-extend the number in the bottom T bits of Imm after accounting for
461 // the fact that the T bit immediate is stored in T-N bits (the LSB is
462 // always zero)
465}
466
468 int64_t Address,
469 const MCDisassembler *Decoder) {
470 assert(isUInt<6>(Imm) && "Invalid immediate");
471 if (Imm == 0)
473 Imm = SignExtend64<6>(Imm) & 0xfffff;
476}
477
478static DecodeStatus decodeFRMArg(MCInst &Inst, uint32_t Imm, int64_t Address,
479 const MCDisassembler *Decoder) {
480 assert(isUInt<3>(Imm) && "Invalid immediate");
483
486}
487
488static DecodeStatus decodeRTZArg(MCInst &Inst, uint32_t Imm, int64_t Address,
489 const MCDisassembler *Decoder) {
490 assert(isUInt<3>(Imm) && "Invalid immediate");
491 if (Imm != RISCVFPRndMode::RTZ)
493
496}
497
499 uint64_t Address,
500 const MCDisassembler *Decoder) {
501 bool IsRVE = Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
502 if (Imm < RISCVZC::RA || (IsRVE && Imm >= RISCVZC::RA_S0_S2))
506}
507
509 uint64_t Address,
510 const MCDisassembler *Decoder) {
511 if (Imm < RISCVZC::RA_S0)
513 return decodeZcmpRlist(Inst, Imm, Address, Decoder);
514}
515
516#include "RISCVGenDisassemblerTables.inc"
517
518namespace {
519
520struct DecoderListEntry {
521 const uint8_t *Table;
522 FeatureBitset ContainedFeatures;
523 const char *Desc;
524
525 bool haveContainedFeatures(const FeatureBitset &ActiveFeatures) const {
526 return ContainedFeatures.none() ||
527 (ContainedFeatures & ActiveFeatures).any();
528 }
529};
530
531} // end anonymous namespace
532
533static constexpr FeatureBitset XCVFeatureGroup = {
534 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
535 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
536 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
537 RISCV::FeatureVendorXCVbi};
538
540 RISCV::FeatureVendorXRivosVisni,
541 RISCV::FeatureVendorXRivosVizip,
542};
543
544static constexpr FeatureBitset XqciFeatureGroup = {
545 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
546 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
547 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
548 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
549 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
550 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
551 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
552 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
553 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
554};
555
556static constexpr FeatureBitset XSfVectorGroup = {
557 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
558 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
559 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase,
560 RISCV::FeatureVendorXSfvfexpa, RISCV::FeatureVendorXSfvfexpa64e,
561 RISCV::FeatureVendorXSfvfbfexp16e, RISCV::FeatureVendorXSfvfexp16e,
562 RISCV::FeatureVendorXSfvfexp32e};
563static constexpr FeatureBitset XSfSystemGroup = {
564 RISCV::FeatureVendorXSiFivecdiscarddlone,
565 RISCV::FeatureVendorXSiFivecflushdlone,
566};
567
568static constexpr FeatureBitset XMIPSGroup = {
569 RISCV::FeatureVendorXMIPSLSP,
570 RISCV::FeatureVendorXMIPSCMov,
571 RISCV::FeatureVendorXMIPSCBOP,
572 RISCV::FeatureVendorXMIPSEXECTL,
573};
574
575static constexpr FeatureBitset XTHeadGroup = {
576 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
577 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
578 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
579 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
580 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
581 RISCV::FeatureVendorXTHeadVdot};
582
583static constexpr FeatureBitset XAndesGroup = {
584 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
585 RISCV::FeatureVendorXAndesVBFHCvt, RISCV::FeatureVendorXAndesVSIntH,
586 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
587 RISCV::FeatureVendorXAndesVDot};
588
589static constexpr FeatureBitset XSMTGroup = {RISCV::FeatureVendorXSMTVDot};
590
591static constexpr FeatureBitset XAIFGroup = {RISCV::FeatureVendorXAIFET};
592
593static constexpr DecoderListEntry DecoderList32[]{
594 // Vendor Extensions
595 {DecoderTableXCV32, XCVFeatureGroup, "CORE-V extensions"},
596 {DecoderTableXRivos32, XRivosFeatureGroup, "Rivos"},
597 {DecoderTableXqci32, XqciFeatureGroup, "Qualcomm uC Extensions"},
598 {DecoderTableXVentana32,
599 {RISCV::FeatureVendorXVentanaCondOps},
600 "XVentanaCondOps"},
601 {DecoderTableXTHead32, XTHeadGroup, "T-Head extensions"},
602 {DecoderTableXSfvector32, XSfVectorGroup, "SiFive vector extensions"},
603 {DecoderTableXSfsystem32, XSfSystemGroup, "SiFive system extensions"},
604 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease}, "SiFive sf.cease"},
605 {DecoderTableXMIPS32, XMIPSGroup, "Mips extensions"},
606 {DecoderTableXAndes32, XAndesGroup, "Andes extensions"},
607 {DecoderTableXSMT32, XSMTGroup, "SpacemiT extensions"},
608 {DecoderTableXAIF32, XAIFGroup, "AI Foundry extensions"},
609 // Standard Extensions
610 {DecoderTable32, {}, "standard 32-bit instructions"},
611 {DecoderTableRV32Only32, {}, "RV32-only standard 32-bit instructions"},
612 {DecoderTableZfinx32, {}, "Zfinx (Float in Integer)"},
613 {DecoderTableZdinxRV32Only32, {}, "RV32-only Zdinx (Double in Integer)"},
614};
615
616namespace {
617// Define bitwidths for various types used to instantiate the decoder.
618template <> constexpr uint32_t InsnBitWidth<uint16_t> = 16;
619template <> constexpr uint32_t InsnBitWidth<uint32_t> = 32;
620// Use uint64_t to represent 48 bit instructions.
621template <> constexpr uint32_t InsnBitWidth<uint64_t> = 48;
622} // namespace
623
624DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
625 ArrayRef<uint8_t> Bytes,
626 uint64_t Address,
627 raw_ostream &CS) const {
628 if (Bytes.size() < 4) {
629 Size = 0;
631 }
632 Size = 4;
633
634 uint32_t Insn = support::endian::read32le(Bytes.data());
635
636 for (const DecoderListEntry &Entry : DecoderList32) {
637 if (!Entry.haveContainedFeatures(STI.getFeatureBits()))
638 continue;
639
640 LLVM_DEBUG(dbgs() << "Trying " << Entry.Desc << " table:\n");
642 decodeInstruction(Entry.Table, MI, Insn, Address, this, STI);
643 if (Result == MCDisassembler::Fail)
644 continue;
645
646 return Result;
647 }
648
650}
651
652static constexpr DecoderListEntry DecoderList16[]{
653 // Vendor Extensions
654 {DecoderTableXqci16, XqciFeatureGroup, "Qualcomm uC 16-bit"},
655 {DecoderTableXqccmp16,
656 {RISCV::FeatureVendorXqccmp},
657 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
658 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc}, "WCH QingKe XW"},
659 // Standard Extensions
660 // DecoderTableZicfiss16 must be checked before DecoderTable16.
661 {DecoderTableZicfiss16, {}, "Zicfiss (Shadow Stack 16-bit)"},
662 {DecoderTable16, {}, "standard 16-bit instructions"},
663 {DecoderTableRV32Only16, {}, "RV32-only 16-bit instructions"},
664 // Zc* instructions incompatible with Zcf or Zcd
665 {DecoderTableZcOverlap16,
666 {},
667 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
668};
669
670DecodeStatus RISCVDisassembler::getInstruction16(MCInst &MI, uint64_t &Size,
671 ArrayRef<uint8_t> Bytes,
672 uint64_t Address,
673 raw_ostream &CS) const {
674 if (Bytes.size() < 2) {
675 Size = 0;
677 }
678 Size = 2;
679
680 uint16_t Insn = support::endian::read16le(Bytes.data());
681
682 for (const DecoderListEntry &Entry : DecoderList16) {
683 if (!Entry.haveContainedFeatures(STI.getFeatureBits()))
684 continue;
685
686 LLVM_DEBUG(dbgs() << "Trying " << Entry.Desc << " table:\n");
688 decodeInstruction(Entry.Table, MI, Insn, Address, this, STI);
689 if (Result != MCDisassembler::Fail)
690 return Result;
691 }
692
694}
695
696static constexpr DecoderListEntry DecoderList48[]{
697 {DecoderTableXqci48, XqciFeatureGroup, "Qualcomm uC 48bit"},
698};
699
700DecodeStatus RISCVDisassembler::getInstruction48(MCInst &MI, uint64_t &Size,
701 ArrayRef<uint8_t> Bytes,
702 uint64_t Address,
703 raw_ostream &CS) const {
704 if (Bytes.size() < 6) {
705 Size = 0;
707 }
708 Size = 6;
709
710 uint64_t Insn = 0;
711 for (size_t i = Size; i-- != 0;)
712 Insn += (static_cast<uint64_t>(Bytes[i]) << 8 * i);
713
714 for (const DecoderListEntry &Entry : DecoderList48) {
715 if (!Entry.haveContainedFeatures(STI.getFeatureBits()))
716 continue;
717
718 LLVM_DEBUG(dbgs() << "Trying " << Entry.Desc << " table:\n");
720 decodeInstruction(Entry.Table, MI, Insn, Address, this, STI);
721 if (Result == MCDisassembler::Fail)
722 continue;
723
724 return Result;
725 }
726
728}
729
730DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
731 ArrayRef<uint8_t> Bytes,
732 uint64_t Address,
733 raw_ostream &CS) const {
734 CommentStream = &CS;
735 // It's a 16 bit instruction if bit 0 and 1 are not 0b11.
736 if ((Bytes[0] & 0b11) != 0b11)
737 return getInstruction16(MI, Size, Bytes, Address, CS);
738
739 // Try to decode as a 32-bit instruction first.
740 DecodeStatus Result = getInstruction32(MI, Size, Bytes, Address, CS);
741 if (Result != MCDisassembler::Fail)
742 return Result;
743
744 // If bits [4:2] are 0b111 this might be a 48-bit or larger instruction,
745 // otherwise assume it's an unknown 32-bit instruction.
746 if ((Bytes[0] & 0b1'1100) != 0b1'1100) {
747 Size = Bytes.size() >= 4 ? 4 : 0;
749 }
750
751 // 48-bit instructions are encoded as 0bxx011111.
752 if ((Bytes[0] & 0b11'1111) == 0b01'1111)
753 return getInstruction48(MI, Size, Bytes, Address, CS);
754
755 // 64-bit instructions are encoded as 0x0111111.
756 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
757 Size = Bytes.size() >= 8 ? 8 : 0;
759 }
760
761 // Remaining cases need to check a second byte.
762 if (Bytes.size() < 2) {
763 Size = 0;
765 }
766
767 // 80-bit through 176-bit instructions are encoded as 0bxnnnxxxx_x1111111.
768 // Where the number of bits is (80 + (nnn * 16)) for nnn != 0b111.
769 unsigned nnn = (Bytes[1] >> 4) & 0b111;
770 if (nnn != 0b111) {
771 Size = 10 + (nnn * 2);
772 if (Bytes.size() < Size)
773 Size = 0;
775 }
776
777 // Remaining encodings are reserved for > 176-bit instructions.
778 Size = 0;
780}
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!")
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
IRTranslator LLVM IR MI
Register Reg
#define T
static constexpr FeatureBitset XqciFeatureGroup
static DecodeStatus decodeUImmSlistOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static constexpr FeatureBitset XAIFGroup
static constexpr FeatureBitset XSMTGroup
static DecodeStatus decodeUImmLog2XLenOperand(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
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 DecodeGPRNoX31RegisterClass(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 DecodeStatus decodeRTZArg(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 decodeSImmOperandAndLslN(MCInst &Inst, uint32_t Imm, int64_t Address, const MCDisassembler *Decoder)
static constexpr FeatureBitset XSfVectorGroup
static constexpr DecoderListEntry DecoderList32[]
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 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 DecodeVRM8RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRM4RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRNoX2RegisterClass(MCInst &Inst, uint64_t RegNo, uint32_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVRM2RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeGPRPairRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
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 DecodeGPRPairNoX0RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeVMV0RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static DecodeStatus DecodeTRRegisterClass(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 DecodeGPRNoX0RegisterClass(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 DecodeStatus DecodeGPRX1RegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static DecodeStatus DecodeSR07RegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const void *Decoder)
static constexpr FeatureBitset XTHeadGroup
static DecodeStatus DecodeSimpleRegisterClass(MCInst &Inst, uint32_t RegNo, uint64_t Address, const MCDisassembler *Decoder)
static constexpr FeatureBitset XRivosFeatureGroup
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)
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)
#define LLVM_DEBUG(...)
Definition Debug.h:114
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
const T * data() const
Definition ArrayRef.h:139
Container class for subtarget features.
Context object for machine code objects.
Definition MCContext.h:83
Superclass for all disassemblers.
const MCSubtargetInfo & getSubtargetInfo() const
DecodeStatus
Ternary decode status.
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
void addOperand(const MCOperand Op)
Definition MCInst.h:215
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
static MCOperand createReg(MCRegister Reg)
Definition MCInst.h:138
static MCOperand createImm(int64_t Val)
Definition MCInst.h:145
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.
Definition MCRegister.h:41
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
Target - Wrapper for Target specific information.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
constexpr bool any(E Val)
@ Entry
Definition COFF.h:862
static bool isValidRoundingMode(unsigned Mode)
uint16_t read16le(const void *P)
Definition Endian.h:429
uint32_t read32le(const void *P)
Definition Endian.h:432
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
Target & getTheRISCV32Target()
Target & getTheRISCV64beTarget()
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:189
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.
Definition MathExtras.h:572
Target & getTheRISCV32beTarget()
#define N
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.