LLVM 24.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
68static MCSymbolizer *
70 LLVMSymbolLookupCallback /*SymbolLookUp*/,
71 void *DisInfo, MCContext *Ctx,
72 std::unique_ptr<MCRelocationInfo> &&RelInfo) {
73 // RISC-V only asks MCSymbolizer to decode HI20/LO12 address fragments. They
74 // require relocation information and cannot be looked up as absolute
75 // addresses when GetOpInfo fails.
76 return llvm::createMCSymbolizer(TT, GetOpInfo, /*SymbolLookUp=*/nullptr,
77 DisInfo, Ctx, std::move(RelInfo));
78}
79
100
101template <unsigned FirstReg, unsigned NumRegsInClass, unsigned RVELimit = 0>
103 uint64_t Address,
104 const MCDisassembler *Decoder) {
105 bool CheckRVE = RVELimit != 0 &&
106 Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
107
108 if (RegNo >= NumRegsInClass || (CheckRVE && RegNo >= RVELimit))
110
111 MCRegister Reg = FirstReg + RegNo;
114}
115
117 DecodeSimpleRegisterClass<RISCV::X0, 32, /*RVELimit=*/16>;
118
120 uint64_t Address,
121 const MCDisassembler *Decoder) {
122 MCRegister Reg = RISCV::X0 + RegNo;
123 if (Reg != RISCV::X1 && Reg != RISCV::X5)
125
128}
129
135
141
143 uint32_t Address,
144 const MCDisassembler *Decoder) {
145 assert(RegNo == 2);
146 Inst.addOperand(MCOperand::createReg(RISCV::X2));
148}
149
155
156template <auto DecodeFn, auto PredicateFn>
158 uint64_t Address,
159 const MCDisassembler *Decoder) {
160 if (!PredicateFn(RegNo))
162 return DecodeFn(Inst, RegNo, Address, Decoder);
163}
164
165constexpr bool PredNoX0(uint32_t RegNo) { return RegNo != 0; }
166constexpr bool PredNoX2(uint32_t RegNo) { return RegNo != 2; }
167constexpr bool PredNoX31(uint32_t RegNo) { return RegNo != 31; }
168
175
177 uint64_t Address,
178 const MCDisassembler *Decoder) {
179 if (RegNo >= 32 || RegNo % 2)
181
182 const RISCVDisassembler *Dis =
183 static_cast<const RISCVDisassembler *>(Decoder);
184 const MCRegisterInfo *RI = Dis->getContext().getRegisterInfo();
186 RISCV::X0 + RegNo, RISCV::sub_gpr_even,
187 &getRISCVMCRegisterClass(RISCV::GPRPairRegClassID));
190}
191
194
196 uint64_t Address,
197 const MCDisassembler *Decoder) {
198 if (RegNo >= 8 || RegNo % 2)
200
201 const RISCVDisassembler *Dis =
202 static_cast<const RISCVDisassembler *>(Decoder);
203 const MCRegisterInfo *RI = Dis->getContext().getRegisterInfo();
205 RISCV::X8 + RegNo, RISCV::sub_gpr_even,
206 &getRISCVMCRegisterClass(RISCV::GPRPairCRegClassID));
209}
210
212 uint64_t Address,
213 const void *Decoder) {
214 if (RegNo >= 8)
216
217 MCRegister Reg = (RegNo < 2) ? (RegNo + RISCV::X8) : (RegNo - 2 + RISCV::X18);
220}
221
222template <unsigned RegisterClass, unsigned NumRegsInClass, unsigned LMul>
224 uint64_t Address,
225 const MCDisassembler *Decoder) {
226 if (RegNo >= NumRegsInClass || RegNo % LMul)
228
229 const RISCVDisassembler *Dis =
230 static_cast<const RISCVDisassembler *>(Decoder);
231 const MCRegisterInfo *RI = Dis->getContext().getRegisterInfo();
233 RI->getMatchingSuperReg(RISCV::V0 + RegNo, RISCV::sub_vrm1_0,
234 &getRISCVMCRegisterClass(RegisterClass));
235
238}
239
241 uint64_t Address,
242 const MCDisassembler *Decoder) {
243 if (RegNo > 15 || RegNo % 2)
245
246 MCRegister Reg = RISCV::T0 + RegNo;
249}
250
252 uint64_t Address,
253 const MCDisassembler *Decoder) {
254 if (RegNo > 15 || RegNo % 4)
256
257 MCRegister Reg = RISCV::T0 + RegNo;
260}
261
262static DecodeStatus DecodeYBNDSWImm(MCInst &Inst, uint64_t Imm, int64_t Address,
263 const MCDisassembler *Decoder) {
264 assert(isUInt<9>(Imm) && "Invalid immediate");
265 uint64_t Result;
266 if (Imm == 0) {
267 // If imm[8:0] == 0, result is 4096.
268 Result = 4096;
269 } else if (Imm <= 255) {
270 // If imm[8] == 0 and imm[7:0] != 0, result is imm[7:0].
271 Result = Imm;
272 } else {
273 uint64_t Imm7To0 = Imm & 0xFF;
274 if (Imm7To0 <= 31) {
275 // If imm[8] == 1 and imm[7:5] == 0 (i.e. imm[7:0] <= 31), result is
276 // `256 | (imm[3:0] << 4) | (imm[4] << 3)`.
277 Result = 256 + ((Imm & 0xF) << 4) + (((Imm >> 4) & 1) << 3);
278 } else {
279 // Otherwise, result is imm[7:0] << 4.
280 Result = Imm7To0 << 4;
281 }
282 }
283 Inst.addOperand(MCOperand::createImm(Result));
285}
286
288 uint64_t Address,
289 const MCDisassembler *Decoder) {
290 if (RegNo >= 2)
292
293 MCRegister Reg = (RegNo == 0) ? RISCV::V0 : RISCV::NoRegister;
294
297}
298
304
310
311template <unsigned N>
313 int64_t Address,
314 const MCDisassembler *Decoder) {
315 assert(isUInt<N>(Imm) && "Invalid immediate");
318}
319
320template <unsigned Width, unsigned LowerBound>
322 int64_t Address,
323 const MCDisassembler *Decoder) {
324 assert(isUInt<Width>(Imm) && "Invalid immediate");
325
326 if (Imm < LowerBound)
328
331}
332
333template <unsigned Width, unsigned LowerBound>
335 int64_t Address,
336 const MCDisassembler *Decoder) {
337 assert(isUInt<Width>(Imm) && "Invalid immediate");
338
339 if ((Imm + 1) < LowerBound)
341
344}
345
347 int64_t Address,
348 const MCDisassembler *Decoder) {
349 assert(isUInt<3>(Imm) && "Invalid Slist immediate");
350 const uint8_t Slist[] = {0, 1, 2, 4, 8, 16, 15, 31};
351 Inst.addOperand(MCOperand::createImm(Slist[Imm]));
353}
354
356 int64_t Address,
357 const MCDisassembler *Decoder) {
358 assert(isUInt<6>(Imm) && "Invalid immediate");
359
360 if (!Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) &&
361 !isUInt<5>(Imm))
363
366}
367
369 int64_t Address,
370 const MCDisassembler *Decoder) {
371 assert(isUInt<7>(Imm) && "Invalid immediate");
372
373 uint32_t ExpectedValue =
374 Decoder->getSubtargetInfo().hasFeature(RISCV::Feature64Bit) ? 64 : 32;
375 if (Imm != ExpectedValue)
377
380}
381
382template <unsigned N>
384 int64_t Address,
385 const MCDisassembler *Decoder) {
386 if (Imm == 0)
388 return decodeUImmOperand<N>(Inst, Imm, Address, Decoder);
389}
390
391static DecodeStatus
393 const MCDisassembler *Decoder) {
394 if (Imm == 0)
396 return decodeUImmLog2XLenOperand(Inst, Imm, Address, Decoder);
397}
398
399template <unsigned N>
401 int64_t Address,
402 const MCDisassembler *Decoder) {
403 assert(isUInt<N>(Imm) && "Invalid immediate");
406}
407
409 int64_t Address,
410 const MCDisassembler *Decoder) {
411 assert(isUInt<5>(Imm) && "Invalid immediate");
412 Inst.addOperand(MCOperand::createImm(Imm ? Imm : -1LL));
414}
415
416template <unsigned N>
418 int64_t Address,
419 const MCDisassembler *Decoder) {
420 assert(isUInt<N>(Imm) && "Invalid immediate");
421 // Sign-extend the number in the bottom N bits of Imm
424}
425
427 int64_t Address,
428 const MCDisassembler *Decoder) {
429 assert(isUInt<12>(Imm) && "Invalid immediate");
430 const int64_t Value = SignExtend64<12>(Imm);
431 if (!Decoder->tryAddingSymbolicOperand(Inst, Value, Address,
432 /*IsBranch=*/false,
433 /*Offset=*/0, /*OpSize=*/4,
434 /*InstSize=*/4))
437}
438
440 int64_t Address,
441 const MCDisassembler *Decoder) {
442 assert(isUInt<20>(Imm) && "Invalid immediate");
443 const int64_t Value = SignExtend64<32>(Imm << 12);
444 if (!Decoder->tryAddingSymbolicOperand(Inst, Value, Address,
445 /*IsBranch=*/false,
446 /*Offset=*/0, /*OpSize=*/4,
447 /*InstSize=*/4))
450}
451
452template <unsigned N>
454 int64_t Address,
455 const MCDisassembler *Decoder) {
456 if (Imm == 0)
458 return decodeSImmOperand<N>(Inst, Imm, Address, Decoder);
459}
460
461template <unsigned T, unsigned N>
463 int64_t Address,
464 const MCDisassembler *Decoder) {
465 assert(isUInt<T - N + 1>(Imm) && "Invalid immediate");
466 // Sign-extend the number in the bottom T bits of Imm after accounting for
467 // the fact that the T bit immediate is stored in T-N bits (the LSB is
468 // always zero)
471}
472
474 int64_t Address,
475 const MCDisassembler *Decoder) {
476 assert(isUInt<6>(Imm) && "Invalid immediate");
477 if (Imm == 0)
479 Imm = SignExtend64<6>(Imm) & 0xfffff;
482}
483
484static DecodeStatus decodeFRMArg(MCInst &Inst, uint32_t Imm, int64_t Address,
485 const MCDisassembler *Decoder) {
486 assert(isUInt<3>(Imm) && "Invalid immediate");
489
492}
493
495 uint64_t Address,
496 const MCDisassembler *Decoder) {
497 bool IsRVE = Decoder->getSubtargetInfo().hasFeature(RISCV::FeatureStdExtE);
498 if (Imm < RISCVZC::RA || (IsRVE && Imm >= RISCVZC::RA_S0_S2))
502}
503
505 uint64_t Address,
506 const MCDisassembler *Decoder) {
507 if (Imm < RISCVZC::RA_S0)
509 return decodeZcmpRlist(Inst, Imm, Address, Decoder);
510}
511
512#include "RISCVGenDisassemblerTables.inc"
513
514namespace {
515
516struct DecoderListEntry {
517 const uint8_t *Table;
518 FeatureBitset ContainedFeatures;
519 const char *Desc;
520
521 bool haveContainedFeatures(const FeatureBitset &ActiveFeatures) const {
522 return ContainedFeatures.none() ||
523 (ContainedFeatures & ActiveFeatures).any();
524 }
525};
526
527} // end anonymous namespace
528
529static constexpr FeatureBitset XCVFeatureGroup = {
530 RISCV::FeatureVendorXCVbitmanip, RISCV::FeatureVendorXCVelw,
531 RISCV::FeatureVendorXCVmac, RISCV::FeatureVendorXCVmem,
532 RISCV::FeatureVendorXCValu, RISCV::FeatureVendorXCVsimd,
533 RISCV::FeatureVendorXCVbi};
534
535static constexpr FeatureBitset XqciFeatureGroup = {
536 RISCV::FeatureVendorXqcia, RISCV::FeatureVendorXqciac,
537 RISCV::FeatureVendorXqcibi, RISCV::FeatureVendorXqcibm,
538 RISCV::FeatureVendorXqcicli, RISCV::FeatureVendorXqcicm,
539 RISCV::FeatureVendorXqcics, RISCV::FeatureVendorXqcicsr,
540 RISCV::FeatureVendorXqciint, RISCV::FeatureVendorXqciio,
541 RISCV::FeatureVendorXqcilb, RISCV::FeatureVendorXqcili,
542 RISCV::FeatureVendorXqcilia, RISCV::FeatureVendorXqcilo,
543 RISCV::FeatureVendorXqcilsm, RISCV::FeatureVendorXqcisim,
544 RISCV::FeatureVendorXqcisls, RISCV::FeatureVendorXqcisync,
545};
546
547static constexpr FeatureBitset XSfVectorGroup = {
548 RISCV::FeatureVendorXSfvcp, RISCV::FeatureVendorXSfvqmaccdod,
549 RISCV::FeatureVendorXSfvqmaccqoq, RISCV::FeatureVendorXSfvfwmaccqqq,
550 RISCV::FeatureVendorXSfvfnrclipxfqf, RISCV::FeatureVendorXSfmmbase,
551 RISCV::FeatureVendorXSfvfexpa, RISCV::FeatureVendorXSfvfexpa64e,
552 RISCV::FeatureVendorXSfvfbfexp16e, RISCV::FeatureVendorXSfvfexp16e,
553 RISCV::FeatureVendorXSfvfexp32e};
554static constexpr FeatureBitset XSfSystemGroup = {
555 RISCV::FeatureVendorXSiFivecdiscarddlone,
556 RISCV::FeatureVendorXSiFivecflushdlone,
557};
558
559static constexpr FeatureBitset XMIPSGroup = {
560 RISCV::FeatureVendorXMIPSLSP,
561 RISCV::FeatureVendorXMIPSCMov,
562 RISCV::FeatureVendorXMIPSCBOP,
563 RISCV::FeatureVendorXMIPSEXECTL,
564};
565
566static constexpr FeatureBitset XTHeadGroup = {
567 RISCV::FeatureVendorXTHeadBa, RISCV::FeatureVendorXTHeadBb,
568 RISCV::FeatureVendorXTHeadBs, RISCV::FeatureVendorXTHeadCondMov,
569 RISCV::FeatureVendorXTHeadCmo, RISCV::FeatureVendorXTHeadFMemIdx,
570 RISCV::FeatureVendorXTHeadMac, RISCV::FeatureVendorXTHeadMemIdx,
571 RISCV::FeatureVendorXTHeadMemPair, RISCV::FeatureVendorXTHeadSync,
572 RISCV::FeatureVendorXTHeadVdot};
573
574static constexpr FeatureBitset XAndesGroup = {
575 RISCV::FeatureVendorXAndesPerf, RISCV::FeatureVendorXAndesBFHCvt,
576 RISCV::FeatureVendorXAndesVBFHCvt, RISCV::FeatureVendorXAndesVSIntH,
577 RISCV::FeatureVendorXAndesVSIntLoad, RISCV::FeatureVendorXAndesVPackFPH,
578 RISCV::FeatureVendorXAndesVDot};
579
580static constexpr FeatureBitset XSMTGroup = {RISCV::FeatureVendorXSMTVDot,
581 RISCV::FeatureVendorXSMTVDotII};
582
583static constexpr FeatureBitset XAIFGroup = {RISCV::FeatureVendorXAIFET};
584
585static constexpr DecoderListEntry DecoderList32[]{
586 // Vendor Extensions
587 {DecoderTableXCV32, XCVFeatureGroup, "CORE-V extensions"},
588 {DecoderTableXqci32, XqciFeatureGroup, "Qualcomm uC Extensions"},
589 {DecoderTableXVentana32,
590 {RISCV::FeatureVendorXVentanaCondOps},
591 "XVentanaCondOps"},
592 {DecoderTableXTHead32, XTHeadGroup, "T-Head extensions"},
593 {DecoderTableXSfvector32, XSfVectorGroup, "SiFive vector extensions"},
594 {DecoderTableXSfsystem32, XSfSystemGroup, "SiFive system extensions"},
595 {DecoderTableXSfcease32, {RISCV::FeatureVendorXSfcease}, "SiFive sf.cease"},
596 {DecoderTableXMIPS32, XMIPSGroup, "Mips extensions"},
597 {DecoderTableXAndes32, XAndesGroup, "Andes extensions"},
598 {DecoderTableXSMT32, XSMTGroup, "SpacemiT extensions"},
599 {DecoderTableXAIF32, XAIFGroup, "AI Foundry extensions"},
600 // Standard Extensions
601 {DecoderTable32, {}, "standard 32-bit instructions"},
602 {DecoderTableRV32Only32, {}, "RV32-only standard 32-bit instructions"},
603 {DecoderTableZfinx32, {}, "Zfinx (Float in Integer)"},
604 {DecoderTableZdinxRV32Only32, {}, "RV32-only Zdinx (Double in Integer)"},
605};
606
607namespace {
608// Define bitwidths for various types used to instantiate the decoder.
609template <> constexpr uint32_t InsnBitWidth<uint16_t> = 16;
610template <> constexpr uint32_t InsnBitWidth<uint32_t> = 32;
611// Use uint64_t to represent 48 bit instructions.
612template <> constexpr uint32_t InsnBitWidth<uint64_t> = 48;
613} // namespace
614
615DecodeStatus RISCVDisassembler::getInstruction32(MCInst &MI, uint64_t &Size,
616 ArrayRef<uint8_t> Bytes,
617 uint64_t Address,
618 raw_ostream &CS) const {
619 if (Bytes.size() < 4) {
620 Size = 0;
622 }
623 Size = 4;
624
625 uint32_t Insn = support::endian::read32le(Bytes.data());
626
627 for (const DecoderListEntry &Entry : DecoderList32) {
628 if (!Entry.haveContainedFeatures(STI.getFeatureBits()))
629 continue;
630
631 LLVM_DEBUG(dbgs() << "Trying " << Entry.Desc << " table:\n");
633 decodeInstruction(Entry.Table, MI, Insn, Address, this, STI);
634 if (Result == MCDisassembler::Fail)
635 continue;
636
637 return Result;
638 }
639
641}
642
643static constexpr DecoderListEntry DecoderList16[]{
644 // Vendor Extensions
645 {DecoderTableXqci16, XqciFeatureGroup, "Qualcomm uC 16-bit"},
646 {DecoderTableXqccmp16,
647 {RISCV::FeatureVendorXqccmp},
648 "Xqccmp (Qualcomm 16-bit Push/Pop & Double Move Instructions)"},
649 {DecoderTableXqccmt16,
650 {RISCV::FeatureVendorXqccmt},
651 "Xqccmt (Qualcomm 16-bit Table Jump Instructions)"},
652 {DecoderTableXwchc16, {RISCV::FeatureVendorXwchc}, "WCH QingKe XW"},
653 // Standard Extensions
654 // DecoderTableZicfiss16 must be checked before DecoderTable16.
655 {DecoderTableZicfiss16, {}, "Zicfiss (Shadow Stack 16-bit)"},
656 {DecoderTable16, {}, "standard 16-bit instructions"},
657 {DecoderTableRV32Only16, {}, "RV32-only 16-bit instructions"},
658 // Zc* instructions incompatible with Zcf or Zcd
659 {DecoderTableZcOverlap16,
660 {},
661 "ZcOverlap (16-bit Instructions overlapping with Zcf/Zcd)"},
662};
663
664DecodeStatus RISCVDisassembler::getInstruction16(MCInst &MI, uint64_t &Size,
665 ArrayRef<uint8_t> Bytes,
667 raw_ostream &CS) const {
668 if (Bytes.size() < 2) {
669 Size = 0;
671 }
672 Size = 2;
673
674 uint16_t Insn = support::endian::read16le(Bytes.data());
675
676 for (const DecoderListEntry &Entry : DecoderList16) {
677 if (!Entry.haveContainedFeatures(STI.getFeatureBits()))
678 continue;
679
680 LLVM_DEBUG(dbgs() << "Trying " << Entry.Desc << " table:\n");
682 decodeInstruction(Entry.Table, MI, Insn, Address, this, STI);
683 if (Result != MCDisassembler::Fail)
684 return Result;
685 }
686
688}
689
690static constexpr DecoderListEntry DecoderList48[]{
691 {DecoderTableXqci48, XqciFeatureGroup, "Qualcomm uC 48bit"},
692};
693
694DecodeStatus RISCVDisassembler::getInstruction48(MCInst &MI, uint64_t &Size,
695 ArrayRef<uint8_t> Bytes,
697 raw_ostream &CS) const {
698 if (Bytes.size() < 6) {
699 Size = 0;
701 }
702 Size = 6;
703
704 uint64_t Insn = 0;
705 for (size_t i = Size; i-- != 0;)
706 Insn += (static_cast<uint64_t>(Bytes[i]) << 8 * i);
707
708 for (const DecoderListEntry &Entry : DecoderList48) {
709 if (!Entry.haveContainedFeatures(STI.getFeatureBits()))
710 continue;
711
712 LLVM_DEBUG(dbgs() << "Trying " << Entry.Desc << " table:\n");
714 decodeInstruction(Entry.Table, MI, Insn, Address, this, STI);
715 if (Result == MCDisassembler::Fail)
716 continue;
717
718 return Result;
719 }
720
722}
723
724DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
725 ArrayRef<uint8_t> Bytes,
727 raw_ostream &CS) const {
728 CommentStream = &CS;
729 // It's a 16 bit instruction if bit 0 and 1 are not 0b11.
730 if ((Bytes[0] & 0b11) != 0b11)
731 return getInstruction16(MI, Size, Bytes, Address, CS);
732
733 // Try to decode as a 32-bit instruction first.
734 DecodeStatus Result = getInstruction32(MI, Size, Bytes, Address, CS);
735 if (Result != MCDisassembler::Fail)
736 return Result;
737
738 // If bits [4:2] are 0b111 this might be a 48-bit or larger instruction,
739 // otherwise assume it's an unknown 32-bit instruction.
740 if ((Bytes[0] & 0b1'1100) != 0b1'1100) {
741 Size = Bytes.size() >= 4 ? 4 : 0;
743 }
744
745 // 48-bit instructions are encoded as 0bxx011111.
746 if ((Bytes[0] & 0b11'1111) == 0b01'1111)
747 return getInstruction48(MI, Size, Bytes, Address, CS);
748
749 // 64-bit instructions are encoded as 0x0111111.
750 if ((Bytes[0] & 0b111'1111) == 0b011'1111) {
751 Size = Bytes.size() >= 8 ? 8 : 0;
753 }
754
755 // Remaining cases need to check a second byte.
756 if (Bytes.size() < 2) {
757 Size = 0;
759 }
760
761 // 80-bit through 176-bit instructions are encoded as 0bxnnnxxxx_x1111111.
762 // Where the number of bits is (80 + (nnn * 16)) for nnn != 0b111.
763 unsigned nnn = (Bytes[1] >> 4) & 0b111;
764 if (nnn != 0b111) {
765 Size = 10 + (nnn * 2);
766 if (Bytes.size() < Size)
767 Size = 0;
769 }
770
771 // Remaining encodings are reserved for > 176-bit instructions.
772 Size = 0;
774}
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 Imm
unsigned uint64_t
unsigned const MCDisassembler * Decoder
#define LLVM_ABI
Definition Compiler.h:215
#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
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[]
static DecodeStatus DecodeGPRX1X5RegisterClass(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 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 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 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 decodeUImmOperand(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)
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 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 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 DecodeStatus DecodeGPRX1RegisterClass(MCInst &Inst, const MCDisassembler *Decoder)
static constexpr FeatureBitset XTHeadGroup
static DecodeStatus DecodeSimpleRegisterClass(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)
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)
constexpr auto DecodeGPRNoX0RegisterClass
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:119
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
const T * data() const
Definition ArrayRef.h:138
Container class for subtarget features.
Context object for machine code objects.
Definition MCContext.h:83
Superclass for all disassemblers.
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.
Symbolize and annotate disassembled instructions.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
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)
@ Entry
Definition COFF.h:862
static bool isValidRoundingMode(unsigned Mode)
uint16_t read16le(const void *P)
Definition Endian.h:409
uint32_t read32le(const void *P)
Definition Endian.h:412
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.
Definition Debug.cpp:209
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
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:573
Target & getTheRISCV32beTarget()
#define N
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.