Skip to content

Commit a4d4615

Browse files
authored
[AMDGPU] Try decoding instructions longest first. NFCI. (#82014)
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 26d4afc commit a4d4615

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

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

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,48 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
595595
if (Res)
596596
break;
597597
}
598+
599+
if (STI.hasFeature(AMDGPU::FeatureGFX940Insts)) {
600+
Res = tryDecodeInst(DecoderTableGFX94064, MI, QW, Address, CS);
601+
if (Res)
602+
break;
603+
}
604+
605+
if (STI.hasFeature(AMDGPU::FeatureGFX90AInsts)) {
606+
Res = tryDecodeInst(DecoderTableGFX90A64, MI, QW, Address, CS);
607+
if (Res)
608+
break;
609+
}
610+
611+
Res = tryDecodeInst(DecoderTableGFX864, MI, QW, Address, CS);
612+
if (Res)
613+
break;
614+
615+
Res = tryDecodeInst(DecoderTableGFX964, MI, QW, Address, CS);
616+
if (Res)
617+
break;
618+
619+
Res = tryDecodeInst(DecoderTableGFX1064, MI, QW, Address, CS);
620+
if (Res)
621+
break;
622+
623+
Res = tryDecodeInst(DecoderTableGFX1264, DecoderTableGFX12_FAKE1664, MI,
624+
QW, Address, CS);
625+
if (Res)
626+
break;
627+
628+
Res = tryDecodeInst(DecoderTableGFX1164, DecoderTableGFX11_FAKE1664, MI,
629+
QW, Address, CS);
630+
if (Res)
631+
break;
632+
633+
Res = tryDecodeInst(DecoderTableGFX11W6464, MI, QW, Address, CS);
634+
if (Res)
635+
break;
636+
637+
Res = tryDecodeInst(DecoderTableGFX12W6464, MI, QW, Address, CS);
638+
if (Res)
639+
break;
598640
}
599641

600642
// Reinitialize Bytes as DPP64 could have eaten too much
@@ -632,48 +674,6 @@ DecodeStatus AMDGPUDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
632674

633675
Res = tryDecodeInst(DecoderTableGFX1232, DecoderTableGFX12_FAKE1632, MI, DW,
634676
Address, CS);
635-
if (Res)
636-
break;
637-
638-
if (Bytes.size() < 4) break;
639-
const uint64_t QW = ((uint64_t)eatBytes<uint32_t>(Bytes) << 32) | DW;
640-
641-
if (STI.hasFeature(AMDGPU::FeatureGFX940Insts)) {
642-
Res = tryDecodeInst(DecoderTableGFX94064, MI, QW, Address, CS);
643-
if (Res)
644-
break;
645-
}
646-
647-
if (STI.hasFeature(AMDGPU::FeatureGFX90AInsts)) {
648-
Res = tryDecodeInst(DecoderTableGFX90A64, MI, QW, Address, CS);
649-
if (Res)
650-
break;
651-
}
652-
653-
Res = tryDecodeInst(DecoderTableGFX864, MI, QW, Address, CS);
654-
if (Res) break;
655-
656-
Res = tryDecodeInst(DecoderTableGFX964, MI, QW, Address, CS);
657-
if (Res) break;
658-
659-
Res = tryDecodeInst(DecoderTableGFX1064, MI, QW, Address, CS);
660-
if (Res) break;
661-
662-
Res = tryDecodeInst(DecoderTableGFX1264, DecoderTableGFX12_FAKE1664, MI, QW,
663-
Address, CS);
664-
if (Res)
665-
break;
666-
667-
Res = tryDecodeInst(DecoderTableGFX1164, DecoderTableGFX11_FAKE1664, MI, QW,
668-
Address, CS);
669-
if (Res)
670-
break;
671-
672-
Res = tryDecodeInst(DecoderTableGFX11W6464, MI, QW, Address, CS);
673-
if (Res)
674-
break;
675-
676-
Res = tryDecodeInst(DecoderTableGFX12W6464, MI, QW, Address, CS);
677677
} while (false);
678678

679679
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)