@@ -487,6 +487,47 @@ static DecodeStatus decodeVersionImm(MCInst &Inst, unsigned Imm,
487
487
//
488
488
// ===----------------------------------------------------------------------===//
489
489
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
+
490
531
template <typename T> static inline T eatBytes (ArrayRef<uint8_t >& Bytes) {
491
532
assert (Bytes.size () >= sizeof (T));
492
533
const auto Res =
@@ -539,16 +580,16 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
539
580
540
581
if (isGFX11 () &&
541
582
tryDecodeInst (DecoderTableGFX1196, DecoderTableGFX11_FAKE1696, MI,
542
- DecW, Address, CS))
583
+ DecW, Address, CS, this ))
543
584
break ;
544
585
545
586
if (isGFX12 () &&
546
587
tryDecodeInst (DecoderTableGFX1296, DecoderTableGFX12_FAKE1696, MI,
547
- DecW, Address, CS))
588
+ DecW, Address, CS, this ))
548
589
break ;
549
590
550
591
if (isGFX12 () &&
551
- tryDecodeInst (DecoderTableGFX12W6496, MI, DecW, Address, CS))
592
+ tryDecodeInst (DecoderTableGFX12W6496, MI, DecW, Address, CS, this ))
552
593
break ;
553
594
554
595
// Reinitialize Bytes
@@ -557,7 +598,7 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
557
598
} else if (Bytes.size () >= 16 &&
558
599
STI.hasFeature (AMDGPU::FeatureGFX950Insts)) {
559
600
DecoderUInt128 DecW = eat16Bytes (Bytes);
560
- if (tryDecodeInst (DecoderTableGFX940128, MI, DecW, Address, CS))
601
+ if (tryDecodeInst (DecoderTableGFX940128, MI, DecW, Address, CS, this ))
561
602
break ;
562
603
563
604
// Reinitialize Bytes
@@ -568,58 +609,61 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
568
609
const uint64_t QW = eatBytes<uint64_t >(Bytes);
569
610
570
611
if (STI.hasFeature (AMDGPU::FeatureGFX10_BEncoding) &&
571
- tryDecodeInst (DecoderTableGFX10_B64, MI, QW, Address, CS))
612
+ tryDecodeInst (DecoderTableGFX10_B64, MI, QW, Address, CS, this ))
572
613
break ;
573
614
574
615
if (STI.hasFeature (AMDGPU::FeatureUnpackedD16VMem) &&
575
- tryDecodeInst (DecoderTableGFX80_UNPACKED64, MI, QW, Address, CS))
616
+ tryDecodeInst (DecoderTableGFX80_UNPACKED64, MI, QW, Address, CS,
617
+ this ))
576
618
break ;
577
619
578
620
if (STI.hasFeature (AMDGPU::FeatureGFX950Insts) &&
579
- tryDecodeInst (DecoderTableGFX95064, MI, QW, Address, CS))
621
+ tryDecodeInst (DecoderTableGFX95064, MI, QW, Address, CS, this ))
580
622
break ;
581
623
582
624
// Some GFX9 subtargets repurposed the v_mad_mix_f32, v_mad_mixlo_f16 and
583
625
// v_mad_mixhi_f16 for FMA variants. Try to decode using this special
584
626
// table first so we print the correct name.
585
627
if (STI.hasFeature (AMDGPU::FeatureFmaMixInsts) &&
586
- tryDecodeInst (DecoderTableGFX9_DL64, MI, QW, Address, CS))
628
+ tryDecodeInst (DecoderTableGFX9_DL64, MI, QW, Address, CS, this ))
587
629
break ;
588
630
589
631
if (STI.hasFeature (AMDGPU::FeatureGFX940Insts) &&
590
- tryDecodeInst (DecoderTableGFX94064, MI, QW, Address, CS))
632
+ tryDecodeInst (DecoderTableGFX94064, MI, QW, Address, CS, this ))
591
633
break ;
592
634
593
635
if (STI.hasFeature (AMDGPU::FeatureGFX90AInsts) &&
594
- tryDecodeInst (DecoderTableGFX90A64, MI, QW, Address, CS))
636
+ tryDecodeInst (DecoderTableGFX90A64, MI, QW, Address, CS, this ))
595
637
break ;
596
638
597
639
if ((isVI () || isGFX9 ()) &&
598
- tryDecodeInst (DecoderTableGFX864, MI, QW, Address, CS))
640
+ tryDecodeInst (DecoderTableGFX864, MI, QW, Address, CS, this ))
599
641
break ;
600
642
601
- if (isGFX9 () && tryDecodeInst (DecoderTableGFX964, MI, QW, Address, CS))
643
+ if (isGFX9 () &&
644
+ tryDecodeInst (DecoderTableGFX964, MI, QW, Address, CS, this ))
602
645
break ;
603
646
604
- if (isGFX10 () && tryDecodeInst (DecoderTableGFX1064, MI, QW, Address, CS))
647
+ if (isGFX10 () &&
648
+ tryDecodeInst (DecoderTableGFX1064, MI, QW, Address, CS, this ))
605
649
break ;
606
650
607
651
if (isGFX12 () &&
608
652
tryDecodeInst (DecoderTableGFX1264, DecoderTableGFX12_FAKE1664, MI, QW,
609
- Address, CS))
653
+ Address, CS, this ))
610
654
break ;
611
655
612
656
if (isGFX11 () &&
613
657
tryDecodeInst (DecoderTableGFX1164, DecoderTableGFX11_FAKE1664, MI, QW,
614
- Address, CS))
658
+ Address, CS, this ))
615
659
break ;
616
660
617
661
if (isGFX11 () &&
618
- tryDecodeInst (DecoderTableGFX11W6464, MI, QW, Address, CS))
662
+ tryDecodeInst (DecoderTableGFX11W6464, MI, QW, Address, CS, this ))
619
663
break ;
620
664
621
665
if (isGFX12 () &&
622
- tryDecodeInst (DecoderTableGFX12W6464, MI, QW, Address, CS))
666
+ tryDecodeInst (DecoderTableGFX12W6464, MI, QW, Address, CS, this ))
623
667
break ;
624
668
625
669
// Reinitialize Bytes
@@ -631,38 +675,40 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
631
675
const uint32_t DW = eatBytes<uint32_t >(Bytes);
632
676
633
677
if ((isVI () || isGFX9 ()) &&
634
- tryDecodeInst (DecoderTableGFX832, MI, DW, Address, CS))
678
+ tryDecodeInst (DecoderTableGFX832, MI, DW, Address, CS, this ))
635
679
break ;
636
680
637
- if (tryDecodeInst (DecoderTableAMDGPU32, MI, DW, Address, CS))
681
+ if (tryDecodeInst (DecoderTableAMDGPU32, MI, DW, Address, CS, this ))
638
682
break ;
639
683
640
- if (isGFX9 () && tryDecodeInst (DecoderTableGFX932, MI, DW, Address, CS))
684
+ if (isGFX9 () &&
685
+ tryDecodeInst (DecoderTableGFX932, MI, DW, Address, CS, this ))
641
686
break ;
642
687
643
688
if (STI.hasFeature (AMDGPU::FeatureGFX950Insts) &&
644
- tryDecodeInst (DecoderTableGFX95032, MI, DW, Address, CS))
689
+ tryDecodeInst (DecoderTableGFX95032, MI, DW, Address, CS, this ))
645
690
break ;
646
691
647
692
if (STI.hasFeature (AMDGPU::FeatureGFX90AInsts) &&
648
- tryDecodeInst (DecoderTableGFX90A32, MI, DW, Address, CS))
693
+ tryDecodeInst (DecoderTableGFX90A32, MI, DW, Address, CS, this ))
649
694
break ;
650
695
651
696
if (STI.hasFeature (AMDGPU::FeatureGFX10_BEncoding) &&
652
- tryDecodeInst (DecoderTableGFX10_B32, MI, DW, Address, CS))
697
+ tryDecodeInst (DecoderTableGFX10_B32, MI, DW, Address, CS, this ))
653
698
break ;
654
699
655
- if (isGFX10 () && tryDecodeInst (DecoderTableGFX1032, MI, DW, Address, CS))
700
+ if (isGFX10 () &&
701
+ tryDecodeInst (DecoderTableGFX1032, MI, DW, Address, CS, this ))
656
702
break ;
657
703
658
704
if (isGFX11 () &&
659
705
tryDecodeInst (DecoderTableGFX1132, DecoderTableGFX11_FAKE1632, MI, DW,
660
- Address, CS))
706
+ Address, CS, this ))
661
707
break ;
662
708
663
709
if (isGFX12 () &&
664
710
tryDecodeInst (DecoderTableGFX1232, DecoderTableGFX12_FAKE1632, MI, DW,
665
- Address, CS))
711
+ Address, CS, this ))
666
712
break ;
667
713
}
668
714
0 commit comments