Skip to content

Commit 9976127

Browse files
committed
[AMDGPU][AsmParser][NFC] Refine defining i8- and i16-typed custom operands.
Reviewed By: dp Differential Revision: https://reviews.llvm.org/D140799
1 parent 904f2cc commit 9976127

File tree

2 files changed

+42
-36
lines changed

2 files changed

+42
-36
lines changed

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

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,6 +1578,7 @@ class AMDGPUAsmParser : public MCTargetAsmParser {
15781578
OperandMatchResultTy parseFORMAT(OperandVector &Operands);
15791579
OperandMatchResultTy parseSymbolicOrNumericFormat(int64_t &Format);
15801580
OperandMatchResultTy parseNumericFormat(int64_t &Format);
1581+
OperandMatchResultTy parseFlatOffset(OperandVector &Operands);
15811582
bool tryParseFmt(const char *Pref, int64_t MaxVal, int64_t &Val);
15821583
bool matchDfmtNfmt(int64_t &Dfmt, int64_t &Nfmt, StringRef FormatStr, SMLoc Loc);
15831584

@@ -6359,6 +6360,16 @@ AMDGPUAsmParser::parseFORMAT(OperandVector &Operands) {
63596360
return MatchOperand_Success;
63606361
}
63616362

6363+
OperandMatchResultTy AMDGPUAsmParser::parseFlatOffset(OperandVector &Operands) {
6364+
OperandMatchResultTy Res =
6365+
parseIntWithPrefix("offset", Operands, AMDGPUOperand::ImmTyOffset);
6366+
if (Res == MatchOperand_NoMatch) {
6367+
Res = parseIntWithPrefix("inst_offset", Operands,
6368+
AMDGPUOperand::ImmTyInstOffset);
6369+
}
6370+
return Res;
6371+
}
6372+
63626373
//===----------------------------------------------------------------------===//
63636374
// ds
63646375
//===----------------------------------------------------------------------===//
@@ -9107,8 +9118,6 @@ AMDGPUAsmParser::parseCustomOperand(OperandVector &Operands, unsigned MCK) {
91079118
return parseNamedBit("d16", Operands, AMDGPUOperand::ImmTyD16);
91089119
case MCK_ImmDA:
91099120
return parseNamedBit("da", Operands, AMDGPUOperand::ImmTyDA);
9110-
case MCK_ImmDMask:
9111-
return parseIntWithPrefix("dmask", Operands, AMDGPUOperand::ImmTyDMask);
91129121
case MCK_ImmExpCompr:
91139122
return parseNamedBit("compr", Operands, AMDGPUOperand::ImmTyExpCompr);
91149123
case MCK_ImmExpVM:
@@ -9130,22 +9139,8 @@ AMDGPUAsmParser::parseCustomOperand(OperandVector &Operands, unsigned MCK) {
91309139
case MCK_ImmNegLo:
91319140
return parseOperandArrayWithPrefix("neg_lo", Operands,
91329141
AMDGPUOperand::ImmTyNegLo);
9133-
case MCK_ImmOffset:
91349142
case MCK_ImmSMEMOffset:
91359143
return parseIntWithPrefix("offset", Operands, AMDGPUOperand::ImmTyOffset);
9136-
case MCK_ImmFlatOffset: {
9137-
OperandMatchResultTy Res =
9138-
parseIntWithPrefix("offset", Operands, AMDGPUOperand::ImmTyOffset);
9139-
if (Res == MatchOperand_NoMatch) {
9140-
Res = parseIntWithPrefix("inst_offset", Operands,
9141-
AMDGPUOperand::ImmTyInstOffset);
9142-
}
9143-
return Res;
9144-
}
9145-
case MCK_ImmOffset0:
9146-
return parseIntWithPrefix("offset0", Operands, AMDGPUOperand::ImmTyOffset0);
9147-
case MCK_ImmOffset1:
9148-
return parseIntWithPrefix("offset1", Operands, AMDGPUOperand::ImmTyOffset1);
91499144
case MCK_ImmOModSI:
91509145
return parseOModOperand(Operands);
91519146
case MCK_ImmOpSel:
@@ -9179,12 +9174,6 @@ AMDGPUAsmParser::parseCustomOperand(OperandVector &Operands, unsigned MCK) {
91799174
return parseNamedBit("tfe", Operands, AMDGPUOperand::ImmTyTFE);
91809175
case MCK_ImmUNorm:
91819176
return parseNamedBit("unorm", Operands, AMDGPUOperand::ImmTyUNorm);
9182-
case MCK_ImmWaitEXP:
9183-
return parseIntWithPrefix("wait_exp", Operands,
9184-
AMDGPUOperand::ImmTyWaitEXP);
9185-
case MCK_ImmWaitVDST:
9186-
return parseIntWithPrefix("wait_vdst", Operands,
9187-
AMDGPUOperand::ImmTyWaitVDST);
91889177
}
91899178
return tryCustomParseOperand(Operands, MCK);
91909179
}

llvm/lib/Target/AMDGPU/SIInstrInfo.td

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,16 +1174,33 @@ class NamedOperandBit_1<string Name, AsmOperandClass MatchClass> :
11741174
let ParserMatchClass = MatchClass;
11751175
}
11761176

1177-
class NamedOperandU8<string Name, AsmOperandClass MatchClass> : Operand<i8> {
1178-
let PrintMethod = "print"#Name;
1179-
let ParserMatchClass = MatchClass;
1177+
class CustomOperandClass<string CName, bit Optional> : AsmOperandClass {
1178+
let Name = CName;
1179+
let PredicateMethod = "is"#CName;
1180+
let ParserMethod = "parse"#CName;
1181+
let RenderMethod = "addImmOperands";
1182+
let IsOptional = Optional;
1183+
let DefaultMethod = "default"#CName;
11801184
}
11811185

1182-
class NamedOperandU16<string Name, AsmOperandClass MatchClass> : Operand<i16> {
1186+
class CustomOperand<ValueType Type, bit Optional = 0, string Name = NAME,
1187+
AsmOperandClass Class = CustomOperandClass<Name, Optional>>
1188+
: Operand<Type> {
11831189
let PrintMethod = "print"#Name;
1184-
let ParserMatchClass = MatchClass;
1190+
let ParserMatchClass = Class;
1191+
}
1192+
1193+
class NamedIntOperandClass<string Prefix, string Name>
1194+
: CustomOperandClass<Name, 1> {
1195+
string ImmTy = "AMDGPUOperand::ImmTy"#Name;
1196+
let ParserMethod =
1197+
"[this](OperandVector &Operands) -> OperandMatchResultTy { "#
1198+
"return parseIntWithPrefix(\""#Prefix#"\", Operands, "#ImmTy#"); }";
11851199
}
11861200

1201+
class NamedIntOperand<ValueType Type, string Prefix, string Name = NAME>
1202+
: CustomOperand<Type, 1, Name, NamedIntOperandClass<Prefix, Name>>;
1203+
11871204
class NamedOperandU32<string Name, AsmOperandClass MatchClass> : Operand<i32> {
11881205
let PrintMethod = "print"#Name;
11891206
let ParserMatchClass = MatchClass;
@@ -1209,10 +1226,10 @@ class NamedOperandU32Default1<string Name, AsmOperandClass MatchClass> :
12091226

12101227
let OperandType = "OPERAND_IMMEDIATE" in {
12111228

1212-
def flat_offset : NamedOperandU16<"FlatOffset", NamedMatchClass<"FlatOffset">>;
1213-
def offset : NamedOperandU16<"Offset", NamedMatchClass<"Offset">>;
1214-
def offset0 : NamedOperandU8<"Offset0", NamedMatchClass<"Offset0">>;
1215-
def offset1 : NamedOperandU8<"Offset1", NamedMatchClass<"Offset1">>;
1229+
def flat_offset : CustomOperand<i16, 1, "FlatOffset">;
1230+
def offset : NamedIntOperand<i16, "offset", "Offset">;
1231+
def offset0 : NamedIntOperand<i8, "offset0", "Offset0">;
1232+
def offset1 : NamedIntOperand<i8, "offset1", "Offset1">;
12161233

12171234
def gds : NamedOperandBit<"GDS", NamedMatchClass<"GDS">>;
12181235

@@ -1242,10 +1259,10 @@ def LWE : NamedOperandBit<"LWE", NamedMatchClass<"LWE">>;
12421259
def exp_compr : NamedOperandBit<"ExpCompr", NamedMatchClass<"ExpCompr">>;
12431260
def exp_vm : NamedOperandBit<"ExpVM", NamedMatchClass<"ExpVM">>;
12441261

1245-
def FORMAT : NamedOperandU8<"FORMAT", NamedMatchClass<"FORMAT", 0>>;
1262+
def FORMAT : CustomOperand<i8>;
12461263

1247-
def DMask : NamedOperandU16<"DMask", NamedMatchClass<"DMask">>;
1248-
def Dim : NamedOperandU8<"Dim", NamedMatchClass<"Dim", 0>>;
1264+
def DMask : NamedIntOperand<i16, "dmask">;
1265+
def Dim : CustomOperand<i8>;
12491266

12501267
def dst_sel : NamedOperandU32<"SDWADstSel", NamedMatchClass<"SDWADstSel">>;
12511268
def src0_sel : NamedOperandU32<"SDWASrc0Sel", NamedMatchClass<"SDWASrc0Sel">>;
@@ -1275,8 +1292,8 @@ def exp_tgt : NamedOperandU32<"ExpTgt", NamedMatchClass<"ExpTgt", 0>> {
12751292

12761293
}
12771294

1278-
def wait_vdst : NamedOperandU8<"WaitVDST", NamedMatchClass<"WaitVDST">>;
1279-
def wait_exp : NamedOperandU8<"WaitEXP", NamedMatchClass<"WaitEXP">>;
1295+
def wait_vdst : NamedIntOperand<i8, "wait_vdst", "WaitVDST">;
1296+
def wait_exp : NamedIntOperand<i8, "wait_exp", "WaitEXP">;
12801297

12811298
} // End OperandType = "OPERAND_IMMEDIATE"
12821299

0 commit comments

Comments
 (0)