Skip to content

Commit 2aa8945

Browse files
authored
[AMDGPU][NFC] Use templates to decode AV operands. (#79313)
Eliminates the need to define them manually. Part of <#62629>.
1 parent e4375bf commit 2aa8945

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ static DecodeStatus decodeSplitBarrier(MCInst &Inst, unsigned Val,
145145
MandatoryLiteral, ImmWidth)); \
146146
}
147147

148+
static DecodeStatus decodeSrcOp(MCInst &Inst, unsigned EncSize,
149+
AMDGPUDisassembler::OpWidthTy OpWidth,
150+
unsigned Imm, unsigned EncImm,
151+
bool MandatoryLiteral, unsigned ImmWidth,
152+
const MCDisassembler *Decoder) {
153+
assert(Imm < (1 << EncSize) && "Operand doesn't fit encoding!");
154+
auto DAsm = static_cast<const AMDGPUDisassembler *>(Decoder);
155+
return addOperand(
156+
Inst, DAsm->decodeSrcOp(OpWidth, EncImm, MandatoryLiteral, ImmWidth));
157+
}
158+
148159
// Decoder for registers. Imm(7-bit) is number of register, uses decodeSrcOp to
149160
// get register class. Used by SGPR only operands.
150161
#define DECODE_OPERAND_REG_7(RegClass, OpWidth) \
@@ -154,9 +165,12 @@ static DecodeStatus decodeSplitBarrier(MCInst &Inst, unsigned Val,
154165
// Imm{9} is acc(agpr or vgpr) Imm{8} should be 0 (see VOP3Pe_SMFMAC).
155166
// Set Imm{8} to 1 (IS_VGPR) to decode using 'enum10' from decodeSrcOp.
156167
// Used by AV_ register classes (AGPR or VGPR only register operands).
157-
#define DECODE_OPERAND_REG_AV10(RegClass, OpWidth) \
158-
DECODE_SrcOp(Decode##RegClass##RegisterClass, 10, OpWidth, \
159-
Imm | AMDGPU::EncValues::IS_VGPR, false, 0)
168+
template <AMDGPUDisassembler::OpWidthTy OpWidth>
169+
static DecodeStatus decodeAV10(MCInst &Inst, unsigned Imm, uint64_t /* Addr */,
170+
const MCDisassembler *Decoder) {
171+
return decodeSrcOp(Inst, 10, OpWidth, Imm, Imm | AMDGPU::EncValues::IS_VGPR,
172+
false, 0, Decoder);
173+
}
160174

161175
// Decoder for Src(9-bit encoding) registers only.
162176
#define DECODE_OPERAND_SRC_REG_9(RegClass, OpWidth) \
@@ -165,13 +179,20 @@ static DecodeStatus decodeSplitBarrier(MCInst &Inst, unsigned Val,
165179
// Decoder for Src(9-bit encoding) AGPR, register number encoded in 9bits, set
166180
// Imm{9} to 1 (set acc) and decode using 'enum10' from decodeSrcOp, registers
167181
// only.
168-
#define DECODE_OPERAND_SRC_REG_A9(RegClass, OpWidth) \
169-
DECODE_SrcOp(decodeOperand_##RegClass, 9, OpWidth, Imm | 512, false, 0)
182+
template <AMDGPUDisassembler::OpWidthTy OpWidth>
183+
static DecodeStatus decodeSrcA9(MCInst &Inst, unsigned Imm, uint64_t /* Addr */,
184+
const MCDisassembler *Decoder) {
185+
return decodeSrcOp(Inst, 9, OpWidth, Imm, Imm | 512, false, 0, Decoder);
186+
}
170187

171188
// Decoder for 'enum10' from decodeSrcOp, Imm{0-8} is 9-bit Src encoding
172189
// Imm{9} is acc, registers only.
173-
#define DECODE_SRC_OPERAND_REG_AV10(RegClass, OpWidth) \
174-
DECODE_SrcOp(decodeOperand_##RegClass, 10, OpWidth, Imm, false, 0)
190+
template <AMDGPUDisassembler::OpWidthTy OpWidth>
191+
static DecodeStatus decodeSrcAV10(MCInst &Inst, unsigned Imm,
192+
uint64_t /* Addr */,
193+
const MCDisassembler *Decoder) {
194+
return decodeSrcOp(Inst, 10, OpWidth, Imm, Imm, false, 0, Decoder);
195+
}
175196

176197
// Decoder for RegisterOperands using 9-bit Src encoding. Operand can be
177198
// register from RegClass or immediate. Registers that don't belong to RegClass
@@ -229,9 +250,6 @@ DECODE_OPERAND_REG_8(AReg_256)
229250
DECODE_OPERAND_REG_8(AReg_512)
230251
DECODE_OPERAND_REG_8(AReg_1024)
231252

232-
DECODE_OPERAND_REG_AV10(AVDst_128, OPW128)
233-
DECODE_OPERAND_REG_AV10(AVDst_512, OPW512)
234-
235253
// Decoders for register only source RegisterOperands that use use 9-bit Src
236254
// encoding: 'decodeOperand_<RegClass>'.
237255

@@ -241,12 +259,6 @@ DECODE_OPERAND_SRC_REG_9(VReg_128, OPW128)
241259
DECODE_OPERAND_SRC_REG_9(VReg_256, OPW256)
242260
DECODE_OPERAND_SRC_REG_9(VRegOrLds_32, OPW32)
243261

244-
DECODE_OPERAND_SRC_REG_A9(AGPR_32, OPW32)
245-
246-
DECODE_SRC_OPERAND_REG_AV10(AV_32, OPW32)
247-
DECODE_SRC_OPERAND_REG_AV10(AV_64, OPW64)
248-
DECODE_SRC_OPERAND_REG_AV10(AV_128, OPW128)
249-
250262
// Decoders for register or immediate RegisterOperands that use 9-bit Src
251263
// encoding: 'decodeOperand_<RegClass>_Imm<ImmWidth>'.
252264

llvm/lib/Target/AMDGPU/SIRegisterInfo.td

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,14 @@ def VGPRSrc_16_Lo128 : RegisterOperand<VGPR_16_Lo128> {
13211321
// ASrc_* Operands with an AccVGPR
13221322
//===----------------------------------------------------------------------===//
13231323

1324-
def ARegSrc_32 : RegisterOperand<AGPR_32> {
1325-
let DecoderMethod = "decodeOperand_AGPR_32";
1324+
class AVOperand<RegisterClass regClass, string decoder, string width>
1325+
: RegisterOperand<regClass> {
1326+
let DecoderMethod = decoder # "<AMDGPUDisassembler::" # width # ">";
13261327
let EncoderMethod = "getAVOperandEncoding";
13271328
}
13281329

1330+
def ARegSrc_32 : AVOperand<AGPR_32, "decodeSrcA9", "OPW32">;
1331+
13291332
//===----------------------------------------------------------------------===//
13301333
// VCSrc_* Operands with an SGPR, VGPR or an inline constant
13311334
//===----------------------------------------------------------------------===//
@@ -1359,36 +1362,21 @@ def VISrc_1024_f32 : RegOrF32 <"VReg_1024", "OPERAND_REG_INLINE_C">;
13591362
// AVSrc_*, AVDst_*, AVLdSt_* Operands with an AGPR or VGPR
13601363
//===----------------------------------------------------------------------===//
13611364

1362-
def AVSrc_32 : RegisterOperand<AV_32> {
1363-
let DecoderMethod = "decodeOperand_AV_32";
1364-
let EncoderMethod = "getAVOperandEncoding";
1365-
}
1366-
1367-
def AVSrc_64 : RegisterOperand<AV_64> {
1368-
let DecoderMethod = "decodeOperand_AV_64";
1369-
let EncoderMethod = "getAVOperandEncoding";
1370-
}
1365+
class AVSrcOperand<RegisterClass regClass, string width>
1366+
: AVOperand<regClass, "decodeSrcAV10", width>;
13711367

1372-
def AVSrc_128 : RegisterOperand<AV_128> {
1373-
let DecoderMethod = "decodeOperand_AV_128";
1374-
let EncoderMethod = "getAVOperandEncoding";
1375-
}
1368+
def AVSrc_32 : AVSrcOperand<AV_32, "OPW32">;
1369+
def AVSrc_64 : AVSrcOperand<AV_64, "OPW64">;
1370+
def AVSrc_128 : AVSrcOperand<AV_128, "OPW128">;
13761371

1377-
def AVDst_128 : RegisterOperand<AV_128> {
1378-
let DecoderMethod = "DecodeAVDst_128RegisterClass";
1379-
let EncoderMethod = "getAVOperandEncoding";
1380-
}
1372+
class AVDstOperand<RegisterClass regClass, string width>
1373+
: AVOperand<regClass, "decodeAV10", width>;
13811374

1382-
def AVDst_512 : RegisterOperand<AV_512> {
1383-
let DecoderMethod = "DecodeAVDst_512RegisterClass";
1384-
let EncoderMethod = "getAVOperandEncoding";
1385-
}
1375+
def AVDst_128 : AVDstOperand<AV_128, "OPW128">;
1376+
def AVDst_512 : AVDstOperand<AV_512, "OPW512">;
13861377

13871378
class AVLdStOperand<RegisterClass regClass, string width>
1388-
: RegisterOperand<regClass> {
1389-
let DecoderMethod = "decodeAVLdSt<AMDGPUDisassembler::" # width # ">";
1390-
let EncoderMethod = "getAVOperandEncoding";
1391-
}
1379+
: AVOperand<regClass, "decodeAVLdSt", width>;
13921380

13931381
def AVLdSt_32 : AVLdStOperand<AV_32, "OPW32">;
13941382
def AVLdSt_64 : AVLdStOperand<AV_64, "OPW64">;

0 commit comments

Comments
 (0)