Skip to content

Commit 0f88c29

Browse files
committed
AMDGPU: Move some code out of macro for defining regclass decoder
Use a template function for the implementation, and use the macro to define a constant function pointer with the expected name. Not sure if there's a cleaner way to do this. This worked out to less code using variadic templates to forward the arguments, but it added a noticable ~10 seconds to compilation time on this file. This will help avoid another copy-paste version of this function in a future change.
1 parent b8aeec1 commit 0f88c29

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,22 @@ static DecodeStatus decodeDpp8FI(MCInst &Inst, unsigned Val, uint64_t Addr,
146146
return addOperand(Inst, DAsm->DecoderName(Imm)); \
147147
}
148148

149-
// Decoder for registers, decode directly using RegClassID. Imm(8-bit) is
150-
// number of register. Used by VGPR only and AGPR only operands.
149+
// Decoder for registers, decode directly using RegClassID. Imm(8-bit) is number
150+
// of register. Used by VGPR only and AGPR only operands.
151+
template <unsigned RegClassID>
152+
static DecodeStatus decodeRegisterClassImpl(MCInst &Inst, unsigned Imm,
153+
uint64_t /*Addr*/,
154+
const MCDisassembler *Decoder) {
155+
assert(Imm < (1 << 8) && "8-bit encoding");
156+
auto DAsm = static_cast<const AMDGPUDisassembler *>(Decoder);
157+
return addOperand(Inst, DAsm->createRegOperand(RegClassID, Imm));
158+
}
159+
160+
using RegClassDecoder = decltype(&decodeRegisterClassImpl<0>);
161+
151162
#define DECODE_OPERAND_REG_8(RegClass) \
152-
static DecodeStatus Decode##RegClass##RegisterClass( \
153-
MCInst &Inst, unsigned Imm, uint64_t /*Addr*/, \
154-
const MCDisassembler *Decoder) { \
155-
assert(Imm < (1 << 8) && "8-bit encoding"); \
156-
auto DAsm = static_cast<const AMDGPUDisassembler *>(Decoder); \
157-
return addOperand( \
158-
Inst, DAsm->createRegOperand(AMDGPU::RegClass##RegClassID, Imm)); \
159-
}
163+
static const constexpr RegClassDecoder Decode##RegClass##RegisterClass = \
164+
decodeRegisterClassImpl<AMDGPU::RegClass##RegClassID>;
160165

161166
#define DECODE_SrcOp(Name, EncSize, OpWidth, EncImm) \
162167
static DecodeStatus Name(MCInst &Inst, unsigned Imm, uint64_t /*Addr*/, \

0 commit comments

Comments
 (0)