@@ -487,6 +487,47 @@ static DecodeStatus decodeVersionImm(MCInst &Inst, unsigned Imm,
487487//
488488// ===----------------------------------------------------------------------===//
489489
490+ template <typename InsnType>
491+ static DecodeStatus tryDecodeInst (DecoderTable2Bytes Table, MCInst &MI,
492+ InsnType Inst, uint64_t Address,
493+ raw_ostream &Comments,
494+ const AMDGPUDisassembler *Asm) {
495+ assert (MI.getOpcode () == 0 );
496+ assert (MI.getNumOperands () == 0 );
497+ MCInst TmpInst;
498+ Asm->setHasLiteral (false );
499+ const auto SavedBytes = Asm->getBytes ();
500+
501+ SmallString<64 > LocalComments;
502+ raw_svector_ostream LocalCommentStream (LocalComments);
503+ Asm->CommentStream = &LocalCommentStream;
504+
505+ DecodeStatus Res = decodeInstruction (Table, TmpInst, Inst, Address, Asm,
506+ Asm->getSubtargetInfo ());
507+
508+ Asm->CommentStream = nullptr ;
509+
510+ if (Res != MCDisassembler::Fail) {
511+ MI = TmpInst;
512+ Comments << LocalComments;
513+ return MCDisassembler::Success;
514+ }
515+ Asm->setBytes (SavedBytes);
516+ return MCDisassembler::Fail;
517+ }
518+
519+ template <typename InsnType>
520+ static DecodeStatus
521+ tryDecodeInst (DecoderTable2Bytes Table1, DecoderTable2Bytes Table2, MCInst &MI,
522+ InsnType Inst, uint64_t Address, raw_ostream &Comments,
523+ const AMDGPUDisassembler *Asm) {
524+ for (DecoderTable2Bytes T : {Table1, Table2}) {
525+ if (DecodeStatus Res = tryDecodeInst (T, MI, Inst, Address, Comments, Asm))
526+ return Res;
527+ }
528+ return MCDisassembler::Fail;
529+ }
530+
490531template <typename T> static inline T eatBytes (ArrayRef<uint8_t >& Bytes) {
491532 assert (Bytes.size () >= sizeof (T));
492533 const auto Res =
@@ -539,16 +580,16 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
539580
540581 if (isGFX11 () &&
541582 tryDecodeInst (DecoderTableGFX1196, DecoderTableGFX11_FAKE1696, MI,
542- DecW, Address, CS))
583+ DecW, Address, CS, this ))
543584 break ;
544585
545586 if (isGFX12 () &&
546587 tryDecodeInst (DecoderTableGFX1296, DecoderTableGFX12_FAKE1696, MI,
547- DecW, Address, CS))
588+ DecW, Address, CS, this ))
548589 break ;
549590
550591 if (isGFX12 () &&
551- tryDecodeInst (DecoderTableGFX12W6496, MI, DecW, Address, CS))
592+ tryDecodeInst (DecoderTableGFX12W6496, MI, DecW, Address, CS, this ))
552593 break ;
553594
554595 // Reinitialize Bytes
@@ -557,7 +598,7 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
557598 } else if (Bytes.size () >= 16 &&
558599 STI.hasFeature (AMDGPU::FeatureGFX950Insts)) {
559600 DecoderUInt128 DecW = eat16Bytes (Bytes);
560- if (tryDecodeInst (DecoderTableGFX940128, MI, DecW, Address, CS))
601+ if (tryDecodeInst (DecoderTableGFX940128, MI, DecW, Address, CS, this ))
561602 break ;
562603
563604 // Reinitialize Bytes
@@ -568,58 +609,61 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
568609 const uint64_t QW = eatBytes<uint64_t >(Bytes);
569610
570611 if (STI.hasFeature (AMDGPU::FeatureGFX10_BEncoding) &&
571- tryDecodeInst (DecoderTableGFX10_B64, MI, QW, Address, CS))
612+ tryDecodeInst (DecoderTableGFX10_B64, MI, QW, Address, CS, this ))
572613 break ;
573614
574615 if (STI.hasFeature (AMDGPU::FeatureUnpackedD16VMem) &&
575- tryDecodeInst (DecoderTableGFX80_UNPACKED64, MI, QW, Address, CS))
616+ tryDecodeInst (DecoderTableGFX80_UNPACKED64, MI, QW, Address, CS,
617+ this ))
576618 break ;
577619
578620 if (STI.hasFeature (AMDGPU::FeatureGFX950Insts) &&
579- tryDecodeInst (DecoderTableGFX95064, MI, QW, Address, CS))
621+ tryDecodeInst (DecoderTableGFX95064, MI, QW, Address, CS, this ))
580622 break ;
581623
582624 // Some GFX9 subtargets repurposed the v_mad_mix_f32, v_mad_mixlo_f16 and
583625 // v_mad_mixhi_f16 for FMA variants. Try to decode using this special
584626 // table first so we print the correct name.
585627 if (STI.hasFeature (AMDGPU::FeatureFmaMixInsts) &&
586- tryDecodeInst (DecoderTableGFX9_DL64, MI, QW, Address, CS))
628+ tryDecodeInst (DecoderTableGFX9_DL64, MI, QW, Address, CS, this ))
587629 break ;
588630
589631 if (STI.hasFeature (AMDGPU::FeatureGFX940Insts) &&
590- tryDecodeInst (DecoderTableGFX94064, MI, QW, Address, CS))
632+ tryDecodeInst (DecoderTableGFX94064, MI, QW, Address, CS, this ))
591633 break ;
592634
593635 if (STI.hasFeature (AMDGPU::FeatureGFX90AInsts) &&
594- tryDecodeInst (DecoderTableGFX90A64, MI, QW, Address, CS))
636+ tryDecodeInst (DecoderTableGFX90A64, MI, QW, Address, CS, this ))
595637 break ;
596638
597639 if ((isVI () || isGFX9 ()) &&
598- tryDecodeInst (DecoderTableGFX864, MI, QW, Address, CS))
640+ tryDecodeInst (DecoderTableGFX864, MI, QW, Address, CS, this ))
599641 break ;
600642
601- if (isGFX9 () && tryDecodeInst (DecoderTableGFX964, MI, QW, Address, CS))
643+ if (isGFX9 () &&
644+ tryDecodeInst (DecoderTableGFX964, MI, QW, Address, CS, this ))
602645 break ;
603646
604- if (isGFX10 () && tryDecodeInst (DecoderTableGFX1064, MI, QW, Address, CS))
647+ if (isGFX10 () &&
648+ tryDecodeInst (DecoderTableGFX1064, MI, QW, Address, CS, this ))
605649 break ;
606650
607651 if (isGFX12 () &&
608652 tryDecodeInst (DecoderTableGFX1264, DecoderTableGFX12_FAKE1664, MI, QW,
609- Address, CS))
653+ Address, CS, this ))
610654 break ;
611655
612656 if (isGFX11 () &&
613657 tryDecodeInst (DecoderTableGFX1164, DecoderTableGFX11_FAKE1664, MI, QW,
614- Address, CS))
658+ Address, CS, this ))
615659 break ;
616660
617661 if (isGFX11 () &&
618- tryDecodeInst (DecoderTableGFX11W6464, MI, QW, Address, CS))
662+ tryDecodeInst (DecoderTableGFX11W6464, MI, QW, Address, CS, this ))
619663 break ;
620664
621665 if (isGFX12 () &&
622- tryDecodeInst (DecoderTableGFX12W6464, MI, QW, Address, CS))
666+ tryDecodeInst (DecoderTableGFX12W6464, MI, QW, Address, CS, this ))
623667 break ;
624668
625669 // Reinitialize Bytes
@@ -631,38 +675,40 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
631675 const uint32_t DW = eatBytes<uint32_t >(Bytes);
632676
633677 if ((isVI () || isGFX9 ()) &&
634- tryDecodeInst (DecoderTableGFX832, MI, DW, Address, CS))
678+ tryDecodeInst (DecoderTableGFX832, MI, DW, Address, CS, this ))
635679 break ;
636680
637- if (tryDecodeInst (DecoderTableAMDGPU32, MI, DW, Address, CS))
681+ if (tryDecodeInst (DecoderTableAMDGPU32, MI, DW, Address, CS, this ))
638682 break ;
639683
640- if (isGFX9 () && tryDecodeInst (DecoderTableGFX932, MI, DW, Address, CS))
684+ if (isGFX9 () &&
685+ tryDecodeInst (DecoderTableGFX932, MI, DW, Address, CS, this ))
641686 break ;
642687
643688 if (STI.hasFeature (AMDGPU::FeatureGFX950Insts) &&
644- tryDecodeInst (DecoderTableGFX95032, MI, DW, Address, CS))
689+ tryDecodeInst (DecoderTableGFX95032, MI, DW, Address, CS, this ))
645690 break ;
646691
647692 if (STI.hasFeature (AMDGPU::FeatureGFX90AInsts) &&
648- tryDecodeInst (DecoderTableGFX90A32, MI, DW, Address, CS))
693+ tryDecodeInst (DecoderTableGFX90A32, MI, DW, Address, CS, this ))
649694 break ;
650695
651696 if (STI.hasFeature (AMDGPU::FeatureGFX10_BEncoding) &&
652- tryDecodeInst (DecoderTableGFX10_B32, MI, DW, Address, CS))
697+ tryDecodeInst (DecoderTableGFX10_B32, MI, DW, Address, CS, this ))
653698 break ;
654699
655- if (isGFX10 () && tryDecodeInst (DecoderTableGFX1032, MI, DW, Address, CS))
700+ if (isGFX10 () &&
701+ tryDecodeInst (DecoderTableGFX1032, MI, DW, Address, CS, this ))
656702 break ;
657703
658704 if (isGFX11 () &&
659705 tryDecodeInst (DecoderTableGFX1132, DecoderTableGFX11_FAKE1632, MI, DW,
660- Address, CS))
706+ Address, CS, this ))
661707 break ;
662708
663709 if (isGFX12 () &&
664710 tryDecodeInst (DecoderTableGFX1232, DecoderTableGFX12_FAKE1632, MI, DW,
665- Address, CS))
711+ Address, CS, this ))
666712 break ;
667713 }
668714
0 commit comments