Skip to content

Commit a1177d3

Browse files
committed
[AMDGPU] Try decoding instructions longest first. NFCI.
AMDGPUDisassembler::getInstruction tries decoding instructions using different DecoderTables in a confusing order: first 96-bit instructions, then some 64-bit, then 32-bit, then some more 64-bit. This patch changes it to always try longer encodings first. The motivation is to make getInstruction easier to understand, and to pave the way for combining some 64-bit tables that do not need to be separate.
1 parent a52c0c7 commit a1177d3

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,52 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
585585
if (Res)
586586
break;
587587
}
588+
589+
Res = tryDecodeInst(DecoderTableGFX864, MI, QW, Address, CS);
590+
if (Res)
591+
break;
592+
593+
Res = tryDecodeInst(DecoderTableGFX964, MI, QW, Address, CS);
594+
if (Res)
595+
break;
596+
597+
if (STI.hasFeature(AMDGPU::FeatureGFX940Insts)) {
598+
Res = tryDecodeInst(DecoderTableGFX94064, MI, QW, Address, CS);
599+
if (Res)
600+
break;
601+
}
602+
603+
if (STI.hasFeature(AMDGPU::FeatureGFX90AInsts)) {
604+
Res = tryDecodeInst(DecoderTableGFX90A64, MI, QW, Address, CS);
605+
if (Res)
606+
break;
607+
}
608+
609+
Res = tryDecodeInst(DecoderTableAMDGPU64, MI, QW, Address, CS);
610+
if (Res)
611+
break;
612+
613+
Res = tryDecodeInst(DecoderTableGFX1064, MI, QW, Address, CS);
614+
if (Res)
615+
break;
616+
617+
Res = tryDecodeInst(DecoderTableGFX1264, DecoderTableGFX12_FAKE1664, MI,
618+
QW, Address, CS);
619+
if (Res)
620+
break;
621+
622+
Res = tryDecodeInst(DecoderTableGFX1164, DecoderTableGFX11_FAKE1664, MI,
623+
QW, Address, CS);
624+
if (Res)
625+
break;
626+
627+
Res = tryDecodeInst(DecoderTableGFX11W6464, MI, QW, Address, CS);
628+
if (Res)
629+
break;
630+
631+
Res = tryDecodeInst(DecoderTableGFX12W6464, MI, QW, Address, CS);
632+
if (Res)
633+
break;
588634
}
589635

590636
// Reinitialize Bytes as DPP64 could have eaten too much
@@ -624,49 +670,6 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
624670
Address, CS);
625671
if (Res)
626672
break;
627-
628-
if (Bytes.size() < 4) break;
629-
const uint64_t QW = ((uint64_t)eatBytes<uint32_t>(Bytes) << 32) | DW;
630-
631-
if (STI.hasFeature(AMDGPU::FeatureGFX940Insts)) {
632-
Res = tryDecodeInst(DecoderTableGFX94064, MI, QW, Address, CS);
633-
if (Res)
634-
break;
635-
}
636-
637-
if (STI.hasFeature(AMDGPU::FeatureGFX90AInsts)) {
638-
Res = tryDecodeInst(DecoderTableGFX90A64, MI, QW, Address, CS);
639-
if (Res)
640-
break;
641-
}
642-
643-
Res = tryDecodeInst(DecoderTableGFX864, MI, QW, Address, CS);
644-
if (Res) break;
645-
646-
Res = tryDecodeInst(DecoderTableAMDGPU64, MI, QW, Address, CS);
647-
if (Res) break;
648-
649-
Res = tryDecodeInst(DecoderTableGFX964, MI, QW, Address, CS);
650-
if (Res) break;
651-
652-
Res = tryDecodeInst(DecoderTableGFX1064, MI, QW, Address, CS);
653-
if (Res) break;
654-
655-
Res = tryDecodeInst(DecoderTableGFX1264, DecoderTableGFX12_FAKE1664, MI, QW,
656-
Address, CS);
657-
if (Res)
658-
break;
659-
660-
Res = tryDecodeInst(DecoderTableGFX1164, DecoderTableGFX11_FAKE1664, MI, QW,
661-
Address, CS);
662-
if (Res)
663-
break;
664-
665-
Res = tryDecodeInst(DecoderTableGFX11W6464, MI, QW, Address, CS);
666-
if (Res)
667-
break;
668-
669-
Res = tryDecodeInst(DecoderTableGFX12W6464, MI, QW, Address, CS);
670673
} while (false);
671674

672675
if (Res && AMDGPU::isMAC(MI.getOpcode())) {

llvm/lib/Target/AMDGPU/SOPInstructions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,11 +2571,13 @@ multiclass SOPP_Real_32_gfx11_Renamed_gfx12<bits<7> op, string gfx12_name> :
25712571

25722572
multiclass SOPP_Real_With_Relaxation_gfx12<bits<7> op> {
25732573
defm "" : SOPP_Real_32_gfx12<op>;
2574+
let isCodeGenOnly = 1 in
25742575
defm _pad_s_nop : SOPP_Real_64_gfx12<op>;
25752576
}
25762577

25772578
multiclass SOPP_Real_With_Relaxation_gfx11<bits<7> op> {
25782579
defm "" : SOPP_Real_32_gfx11<op>;
2580+
let isCodeGenOnly = 1 in
25792581
defm _pad_s_nop : SOPP_Real_64_gfx11<op>;
25802582
}
25812583

@@ -2697,6 +2699,7 @@ multiclass SOPP_Real_64_gfx6_gfx7_gfx8_gfx9_gfx10<bits<7> op> :
26972699
//relaxation for insts with no operands not implemented
26982700
multiclass SOPP_Real_With_Relaxation_gfx6_gfx7_gfx8_gfx9_gfx10<bits<7> op> {
26992701
defm "" : SOPP_Real_32_gfx6_gfx7_gfx8_gfx9_gfx10<op>;
2702+
let isCodeGenOnly = 1 in
27002703
defm _pad_s_nop : SOPP_Real_64_gfx6_gfx7_gfx8_gfx9_gfx10<op>;
27012704
}
27022705

0 commit comments

Comments
 (0)