Skip to content

Commit dac5957

Browse files
committed
[AMDGPU][AsmParser][NFC] Clean up the implementation of KImmFP operands.
addKImmFPOperands() duplicates the KImmFP-specific logic implemented in addLiteralImmOperand() and therefore can be removed. Part of <#62629>. Reviewed By: foad Differential Revision: https://reviews.llvm.org/D154427
1 parent 7de4c6f commit dac5957

File tree

4 files changed

+9
-55
lines changed

4 files changed

+9
-55
lines changed

llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -949,17 +949,6 @@ class AMDGPUOperand : public MCParsedAsmOperand {
949949

950950
void addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyModifiers) const;
951951

952-
template <unsigned Bitwidth>
953-
void addKImmFPOperands(MCInst &Inst, unsigned N) const;
954-
955-
void addKImmFP16Operands(MCInst &Inst, unsigned N) const {
956-
addKImmFPOperands<16>(Inst, N);
957-
}
958-
959-
void addKImmFP32Operands(MCInst &Inst, unsigned N) const {
960-
addKImmFPOperands<32>(Inst, N);
961-
}
962-
963952
void addRegOperands(MCInst &Inst, unsigned N) const;
964953

965954
void addRegOrImmOperands(MCInst &Inst, unsigned N) const {
@@ -2269,24 +2258,6 @@ void AMDGPUOperand::addLiteralImmOperand(MCInst &Inst, int64_t Val, bool ApplyMo
22692258
}
22702259
}
22712260

2272-
template <unsigned Bitwidth>
2273-
void AMDGPUOperand::addKImmFPOperands(MCInst &Inst, unsigned N) const {
2274-
APInt Literal(64, Imm.Val);
2275-
setImmKindMandatoryLiteral();
2276-
2277-
if (!Imm.IsFPImm) {
2278-
// We got int literal token.
2279-
Inst.addOperand(MCOperand::createImm(Literal.getLoBits(Bitwidth).getZExtValue()));
2280-
return;
2281-
}
2282-
2283-
bool Lost;
2284-
APFloat FPLiteral(APFloat::IEEEdouble(), Literal);
2285-
FPLiteral.convert(*getFltSemantics(Bitwidth / 8),
2286-
APFloat::rmNearestTiesToEven, &Lost);
2287-
Inst.addOperand(MCOperand::createImm(FPLiteral.bitcastToAPInt().getZExtValue()));
2288-
}
2289-
22902261
void AMDGPUOperand::addRegOperands(MCInst &Inst, unsigned N) const {
22912262
Inst.addOperand(MCOperand::createReg(AMDGPU::getMCReg(getReg(), AsmParser->getSTI())));
22922263
}

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,9 @@ DECODE_OPERAND_SRC_REG_OR_IMM_DEFERRED_9(VS_32_Lo128, OPW16, 16)
262262
DECODE_OPERAND_SRC_REG_OR_IMM_DEFERRED_9(VS_32, OPW16, 16)
263263
DECODE_OPERAND_SRC_REG_OR_IMM_DEFERRED_9(VS_32, OPW32, 32)
264264

265-
static DecodeStatus decodeOperand_f32kimm(MCInst &Inst, unsigned Imm,
266-
uint64_t Addr,
267-
const MCDisassembler *Decoder) {
268-
const auto *DAsm = static_cast<const AMDGPUDisassembler *>(Decoder);
269-
return addOperand(Inst, DAsm->decodeMandatoryLiteralConstant(Imm));
270-
}
271-
272-
static DecodeStatus decodeOperand_f16kimm(MCInst &Inst, unsigned Imm,
273-
uint64_t Addr,
274-
const MCDisassembler *Decoder) {
265+
static DecodeStatus decodeOperand_KImmFP(MCInst &Inst, unsigned Imm,
266+
uint64_t Addr,
267+
const MCDisassembler *Decoder) {
275268
const auto *DAsm = static_cast<const AMDGPUDisassembler *>(Decoder);
276269
return addOperand(Inst, DAsm->decodeMandatoryLiteralConstant(Imm));
277270
}

llvm/lib/Target/AMDGPU/SIInstrInfo.td

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,29 +1142,19 @@ def exp_tgt : CustomOperand<i32, 0, "ExpTgt">;
11421142
def wait_vdst : NamedIntOperand<i8, "wait_vdst", "WaitVDST">;
11431143
def wait_exp : NamedIntOperand<i8, "wait_exp", "WaitEXP">;
11441144

1145-
class KImmMatchClass<int size> : AsmOperandClass {
1146-
let Name = "KImmFP"#size;
1147-
let PredicateMethod = "isKImmFP"#size;
1148-
let ParserMethod = "parseImm";
1149-
let RenderMethod = "addKImmFP"#size#"Operands";
1150-
}
1151-
1152-
class kimmOperand<ValueType vt> : Operand<vt> {
1145+
class KImmFPOperand<ValueType vt> : ImmOperand<vt> {
11531146
let OperandNamespace = "AMDGPU";
11541147
let OperandType = "OPERAND_KIMM"#vt.Size;
11551148
let PrintMethod = "printU"#vt.Size#"ImmOperand";
1156-
let ParserMatchClass = !cast<AsmOperandClass>("KImmFP"#vt.Size#"MatchClass");
1157-
let DecoderMethod = "decodeOperand_f"#vt.Size#"kimm";
1149+
let DecoderMethod = "decodeOperand_KImmFP";
11581150
}
11591151

11601152
// 32-bit VALU immediate operand that uses the constant bus.
1161-
def KImmFP32MatchClass : KImmMatchClass<32>;
1162-
def f32kimm : kimmOperand<i32>;
1153+
def KImmFP32 : KImmFPOperand<i32>;
11631154

11641155
// 32-bit VALU immediate operand with a 16-bit value that uses the
11651156
// constant bus.
1166-
def KImmFP16MatchClass : KImmMatchClass<16>;
1167-
def f16kimm : kimmOperand<i16>;
1157+
def KImmFP16 : KImmFPOperand<i16>;
11681158

11691159
class FPInputModsMatchClass <int opSize> : AsmOperandClass {
11701160
let Name = "RegOrImmWithFP"#opSize#"InputMods";

llvm/lib/Target/AMDGPU/VOP2Instructions.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class VOP_MADK_Base<ValueType vt> : VOPProfile <[vt, vt, vt, vt]> {
357357
}
358358

359359
class VOP_MADAK <ValueType vt> : VOP_MADK_Base<vt> {
360-
field Operand ImmOpType = !if(!eq(vt.Size, 32), f32kimm, f16kimm);
360+
field Operand ImmOpType = !if(!eq(vt.Size, 32), KImmFP32, KImmFP16);
361361
field dag Ins32 = !if(!eq(vt.Size, 32),
362362
(ins VSrc_f32_Deferred:$src0, VGPR_32:$src1, ImmOpType:$imm),
363363
(ins VSrc_f16_Deferred:$src0, VGPR_32:$src1, ImmOpType:$imm));
@@ -383,7 +383,7 @@ def VOP_MADAK_F16_t16 : VOP_MADAK <f16> {
383383
def VOP_MADAK_F32 : VOP_MADAK <f32>;
384384

385385
class VOP_MADMK <ValueType vt> : VOP_MADK_Base<vt> {
386-
field Operand ImmOpType = !if(!eq(vt.Size, 32), f32kimm, f16kimm);
386+
field Operand ImmOpType = !if(!eq(vt.Size, 32), KImmFP32, KImmFP16);
387387
field dag Ins32 = !if(!eq(vt.Size, 32),
388388
(ins VSrc_f32_Deferred:$src0, ImmOpType:$imm, VGPR_32:$src1),
389389
(ins VSrc_f16_Deferred:$src0, ImmOpType:$imm, VGPR_32:$src1));

0 commit comments

Comments
 (0)