@@ -487,6 +487,46 @@ static DecodeStatus decodeVersionImm(MCInst &Inst, unsigned Imm,
487
487
//
488
488
// ===----------------------------------------------------------------------===//
489
489
490
+ template <typename InsnType>
491
+ static DecodeStatus
492
+ tryDecodeInst (const AMDGPUDisassembler *Asm, const uint8_t *Table, MCInst &MI,
493
+ InsnType Inst, uint64_t Address, raw_ostream &Comments) {
494
+ assert (MI.getOpcode () == 0 );
495
+ assert (MI.getNumOperands () == 0 );
496
+ MCInst TmpInst;
497
+ Asm->setHasLiteral (false );
498
+ const auto SavedBytes = Asm->getBytes ();
499
+
500
+ SmallString<64 > LocalComments;
501
+ raw_svector_ostream LocalCommentStream (LocalComments);
502
+ Asm->CommentStream = &LocalCommentStream;
503
+
504
+ DecodeStatus Res = decodeInstruction (Table, TmpInst, Inst, Address, Asm,
505
+ Asm->getSubtargetInfo ());
506
+
507
+ Asm->CommentStream = nullptr ;
508
+
509
+ if (Res != MCDisassembler::Fail) {
510
+ MI = TmpInst;
511
+ Comments << LocalComments;
512
+ return MCDisassembler::Success;
513
+ }
514
+ Asm->setBytes (SavedBytes);
515
+ return MCDisassembler::Fail;
516
+ }
517
+
518
+ template <typename InsnType>
519
+ static DecodeStatus tryDecodeInst (const AMDGPUDisassembler *Asm,
520
+ const uint8_t *Table1, const uint8_t *Table2,
521
+ MCInst &MI, InsnType Inst, uint64_t Address,
522
+ raw_ostream &Comments) {
523
+ for (const uint8_t *T : {Table1, Table2}) {
524
+ if (DecodeStatus Res = tryDecodeInst (Asm, T, MI, Inst, Address, Comments))
525
+ return Res;
526
+ }
527
+ return MCDisassembler::Fail;
528
+ }
529
+
490
530
template <typename T> static inline T eatBytes (ArrayRef<uint8_t >& Bytes) {
491
531
assert (Bytes.size () >= sizeof (T));
492
532
const auto Res =
@@ -538,17 +578,17 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
538
578
DecoderUInt128 DecW = eat12Bytes (Bytes);
539
579
540
580
if (isGFX11 () &&
541
- tryDecodeInst (DecoderTableGFX1196, DecoderTableGFX11_FAKE1696, MI ,
542
- DecW, Address, CS))
581
+ tryDecodeInst (this , DecoderTableGFX1196, DecoderTableGFX11_FAKE1696 ,
582
+ MI, DecW, Address, CS))
543
583
break ;
544
584
545
585
if (isGFX12 () &&
546
- tryDecodeInst (DecoderTableGFX1296, DecoderTableGFX12_FAKE1696, MI ,
547
- DecW, Address, CS))
586
+ tryDecodeInst (this , DecoderTableGFX1296, DecoderTableGFX12_FAKE1696 ,
587
+ MI, DecW, Address, CS))
548
588
break ;
549
589
550
590
if (isGFX12 () &&
551
- tryDecodeInst (DecoderTableGFX12W6496, MI, DecW, Address, CS))
591
+ tryDecodeInst (this , DecoderTableGFX12W6496, MI, DecW, Address, CS))
552
592
break ;
553
593
554
594
// Reinitialize Bytes
@@ -557,7 +597,7 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
557
597
} else if (Bytes.size () >= 16 &&
558
598
STI.hasFeature (AMDGPU::FeatureGFX950Insts)) {
559
599
DecoderUInt128 DecW = eat16Bytes (Bytes);
560
- if (tryDecodeInst (DecoderTableGFX940128, MI, DecW, Address, CS))
600
+ if (tryDecodeInst (this , DecoderTableGFX940128, MI, DecW, Address, CS))
561
601
break ;
562
602
563
603
// Reinitialize Bytes
@@ -568,58 +608,61 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
568
608
const uint64_t QW = eatBytes<uint64_t >(Bytes);
569
609
570
610
if (STI.hasFeature (AMDGPU::FeatureGFX10_BEncoding) &&
571
- tryDecodeInst (DecoderTableGFX10_B64, MI, QW, Address, CS))
611
+ tryDecodeInst (this , DecoderTableGFX10_B64, MI, QW, Address, CS))
572
612
break ;
573
613
574
614
if (STI.hasFeature (AMDGPU::FeatureUnpackedD16VMem) &&
575
- tryDecodeInst (DecoderTableGFX80_UNPACKED64, MI, QW, Address, CS))
615
+ tryDecodeInst (this , DecoderTableGFX80_UNPACKED64, MI, QW, Address,
616
+ CS))
576
617
break ;
577
618
578
619
if (STI.hasFeature (AMDGPU::FeatureGFX950Insts) &&
579
- tryDecodeInst (DecoderTableGFX95064, MI, QW, Address, CS))
620
+ tryDecodeInst (this , DecoderTableGFX95064, MI, QW, Address, CS))
580
621
break ;
581
622
582
623
// Some GFX9 subtargets repurposed the v_mad_mix_f32, v_mad_mixlo_f16 and
583
624
// v_mad_mixhi_f16 for FMA variants. Try to decode using this special
584
625
// table first so we print the correct name.
585
626
if (STI.hasFeature (AMDGPU::FeatureFmaMixInsts) &&
586
- tryDecodeInst (DecoderTableGFX9_DL64, MI, QW, Address, CS))
627
+ tryDecodeInst (this , DecoderTableGFX9_DL64, MI, QW, Address, CS))
587
628
break ;
588
629
589
630
if (STI.hasFeature (AMDGPU::FeatureGFX940Insts) &&
590
- tryDecodeInst (DecoderTableGFX94064, MI, QW, Address, CS))
631
+ tryDecodeInst (this , DecoderTableGFX94064, MI, QW, Address, CS))
591
632
break ;
592
633
593
634
if (STI.hasFeature (AMDGPU::FeatureGFX90AInsts) &&
594
- tryDecodeInst (DecoderTableGFX90A64, MI, QW, Address, CS))
635
+ tryDecodeInst (this , DecoderTableGFX90A64, MI, QW, Address, CS))
595
636
break ;
596
637
597
638
if ((isVI () || isGFX9 ()) &&
598
- tryDecodeInst (DecoderTableGFX864, MI, QW, Address, CS))
639
+ tryDecodeInst (this , DecoderTableGFX864, MI, QW, Address, CS))
599
640
break ;
600
641
601
- if (isGFX9 () && tryDecodeInst (DecoderTableGFX964, MI, QW, Address, CS))
642
+ if (isGFX9 () &&
643
+ tryDecodeInst (this , DecoderTableGFX964, MI, QW, Address, CS))
602
644
break ;
603
645
604
- if (isGFX10 () && tryDecodeInst (DecoderTableGFX1064, MI, QW, Address, CS))
646
+ if (isGFX10 () &&
647
+ tryDecodeInst (this , DecoderTableGFX1064, MI, QW, Address, CS))
605
648
break ;
606
649
607
650
if (isGFX12 () &&
608
- tryDecodeInst (DecoderTableGFX1264, DecoderTableGFX12_FAKE1664, MI, QW ,
609
- Address, CS))
651
+ tryDecodeInst (this , DecoderTableGFX1264, DecoderTableGFX12_FAKE1664 ,
652
+ MI, QW, Address, CS))
610
653
break ;
611
654
612
655
if (isGFX11 () &&
613
- tryDecodeInst (DecoderTableGFX1164, DecoderTableGFX11_FAKE1664, MI, QW ,
614
- Address, CS))
656
+ tryDecodeInst (this , DecoderTableGFX1164, DecoderTableGFX11_FAKE1664 ,
657
+ MI, QW, Address, CS))
615
658
break ;
616
659
617
660
if (isGFX11 () &&
618
- tryDecodeInst (DecoderTableGFX11W6464, MI, QW, Address, CS))
661
+ tryDecodeInst (this , DecoderTableGFX11W6464, MI, QW, Address, CS))
619
662
break ;
620
663
621
664
if (isGFX12 () &&
622
- tryDecodeInst (DecoderTableGFX12W6464, MI, QW, Address, CS))
665
+ tryDecodeInst (this , DecoderTableGFX12W6464, MI, QW, Address, CS))
623
666
break ;
624
667
625
668
// Reinitialize Bytes
@@ -631,38 +674,40 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
631
674
const uint32_t DW = eatBytes<uint32_t >(Bytes);
632
675
633
676
if ((isVI () || isGFX9 ()) &&
634
- tryDecodeInst (DecoderTableGFX832, MI, DW, Address, CS))
677
+ tryDecodeInst (this , DecoderTableGFX832, MI, DW, Address, CS))
635
678
break ;
636
679
637
- if (tryDecodeInst (DecoderTableAMDGPU32, MI, DW, Address, CS))
680
+ if (tryDecodeInst (this , DecoderTableAMDGPU32, MI, DW, Address, CS))
638
681
break ;
639
682
640
- if (isGFX9 () && tryDecodeInst (DecoderTableGFX932, MI, DW, Address, CS))
683
+ if (isGFX9 () &&
684
+ tryDecodeInst (this , DecoderTableGFX932, MI, DW, Address, CS))
641
685
break ;
642
686
643
687
if (STI.hasFeature (AMDGPU::FeatureGFX950Insts) &&
644
- tryDecodeInst (DecoderTableGFX95032, MI, DW, Address, CS))
688
+ tryDecodeInst (this , DecoderTableGFX95032, MI, DW, Address, CS))
645
689
break ;
646
690
647
691
if (STI.hasFeature (AMDGPU::FeatureGFX90AInsts) &&
648
- tryDecodeInst (DecoderTableGFX90A32, MI, DW, Address, CS))
692
+ tryDecodeInst (this , DecoderTableGFX90A32, MI, DW, Address, CS))
649
693
break ;
650
694
651
695
if (STI.hasFeature (AMDGPU::FeatureGFX10_BEncoding) &&
652
- tryDecodeInst (DecoderTableGFX10_B32, MI, DW, Address, CS))
696
+ tryDecodeInst (this , DecoderTableGFX10_B32, MI, DW, Address, CS))
653
697
break ;
654
698
655
- if (isGFX10 () && tryDecodeInst (DecoderTableGFX1032, MI, DW, Address, CS))
699
+ if (isGFX10 () &&
700
+ tryDecodeInst (this , DecoderTableGFX1032, MI, DW, Address, CS))
656
701
break ;
657
702
658
703
if (isGFX11 () &&
659
- tryDecodeInst (DecoderTableGFX1132, DecoderTableGFX11_FAKE1632, MI, DW ,
660
- Address, CS))
704
+ tryDecodeInst (this , DecoderTableGFX1132, DecoderTableGFX11_FAKE1632 ,
705
+ MI, DW, Address, CS))
661
706
break ;
662
707
663
708
if (isGFX12 () &&
664
- tryDecodeInst (DecoderTableGFX1232, DecoderTableGFX12_FAKE1632, MI, DW ,
665
- Address, CS))
709
+ tryDecodeInst (this , DecoderTableGFX1232, DecoderTableGFX12_FAKE1632 ,
710
+ MI, DW, Address, CS))
666
711
break ;
667
712
}
668
713
0 commit comments