[prev in list] [next in list] [prev in thread] [next in thread]
List: llvm-commits
Subject: [PATCH] D140799: [AMDGPU][AsmParser][NFC] Refine defining i8- and i16-typed custom operands.
From: Ivan Kosarev via Phabricator via llvm-commits <llvm-commits () lists ! llvm ! org>
Date: 2022-12-31 10:25:42
Message-ID: zQC_mtH0S2Cx4yXBktsK-Q () geopod-ismtpd-2-1
[Download RAW message or body]
kosarev created this revision.
kosarev added reviewers: dp, rampitec, arsenm, foad.
Herald added subscribers: kerbowa, hiraditya, tpr, dstuttard, yaxunl, jvese=
ly, kzhuravl.
Herald added a project: All.
kosarev requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140799
Files:
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
llvm/lib/Target/AMDGPU/SIInstrInfo.td
["D140799.485759.patch" (D140799.485759.patch)]
Index: llvm/lib/Target/AMDGPU/SIInstrInfo.td
===================================================================
--- llvm/lib/Target/AMDGPU/SIInstrInfo.td
+++ llvm/lib/Target/AMDGPU/SIInstrInfo.td
@@ -1174,16 +1174,34 @@
let ParserMatchClass = MatchClass;
}
-class NamedOperandU8<string Name, AsmOperandClass MatchClass> : Operand<i8> {
- let PrintMethod = "print"#Name;
- let ParserMatchClass = MatchClass;
+class CustomOperandClass<string CName, bit Optional> : AsmOperandClass {
+ let Name = CName;
+ let PredicateMethod = "is"#CName;
+ let ParserMethod = "parse"#CName;
+ let RenderMethod = "addImmOperands";
+ let IsOptional = Optional;
+ let DefaultMethod = "default"#CName;
}
-class NamedOperandU16<string Name, AsmOperandClass MatchClass> : Operand<i16> {
+class CustomOperand<ValueType Type, bit Optional = 0, string Name = NAME,
+ AsmOperandClass Class = CustomOperandClass<Name, Optional>>
+ : Operand<Type> {
let PrintMethod = "print"#Name;
- let ParserMatchClass = MatchClass;
+ let ParserMatchClass = Class;
+ let OperandType = "OPERAND_IMMEDIATE";
}
+class NamedOperandClass<string Prefix, string Name>
+ : CustomOperandClass<Name, 1> {
+ string ImmTy = "AMDGPUOperand::ImmTy"#Name;
+ let ParserMethod =
+ "[this](OperandVector &Operands) -> OperandMatchResultTy { "#
+ "return parseIntWithPrefix(\""#Prefix#"\", Operands, "#ImmTy#"); }";
+}
+
+class NamedOperand<ValueType Type, string Prefix, string Name = NAME>
+ : CustomOperand<Type, 1, Name, NamedOperandClass<Prefix, Name>>;
+
class NamedOperandU32<string Name, AsmOperandClass MatchClass> : Operand<i32> {
let PrintMethod = "print"#Name;
let ParserMatchClass = MatchClass;
@@ -1209,10 +1227,10 @@
let OperandType = "OPERAND_IMMEDIATE" in {
-def flat_offset : NamedOperandU16<"FlatOffset", NamedMatchClass<"FlatOffset">>;
-def offset : NamedOperandU16<"Offset", NamedMatchClass<"Offset">>;
-def offset0 : NamedOperandU8<"Offset0", NamedMatchClass<"Offset0">>;
-def offset1 : NamedOperandU8<"Offset1", NamedMatchClass<"Offset1">>;
+def flat_offset : CustomOperand<i16, 1, "FlatOffset">;
+def offset : NamedOperand<i16, "offset", "Offset">;
+def offset0 : NamedOperand<i8, "offset0", "Offset0">;
+def offset1 : NamedOperand<i8, "offset1", "Offset1">;
def gds : NamedOperandBit<"GDS", NamedMatchClass<"GDS">>;
@@ -1242,10 +1260,10 @@
def exp_compr : NamedOperandBit<"ExpCompr", NamedMatchClass<"ExpCompr">>;
def exp_vm : NamedOperandBit<"ExpVM", NamedMatchClass<"ExpVM">>;
-def FORMAT : NamedOperandU8<"FORMAT", NamedMatchClass<"FORMAT", 0>>;
+def FORMAT : CustomOperand<i8>;
-def DMask : NamedOperandU16<"DMask", NamedMatchClass<"DMask">>;
-def Dim : NamedOperandU8<"Dim", NamedMatchClass<"Dim", 0>>;
+def DMask : NamedOperand<i16, "dmask">;
+def Dim : CustomOperand<i8>;
def dst_sel : NamedOperandU32<"SDWADstSel", NamedMatchClass<"SDWADstSel">>;
def src0_sel : NamedOperandU32<"SDWASrc0Sel", NamedMatchClass<"SDWASrc0Sel">>;
@@ -1275,8 +1293,8 @@
}
-def wait_vdst : NamedOperandU8<"WaitVDST", NamedMatchClass<"WaitVDST">>;
-def wait_exp : NamedOperandU8<"WaitEXP", NamedMatchClass<"WaitEXP">>;
+def wait_vdst : NamedOperand<i8, "wait_vdst", "WaitVDST">;
+def wait_exp : NamedOperand<i8, "wait_exp", "WaitEXP">;
} // End OperandType = "OPERAND_IMMEDIATE"
Index: llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
+++ llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
@@ -1580,6 +1580,7 @@
OperandMatchResultTy parseFORMAT(OperandVector &Operands);
OperandMatchResultTy parseSymbolicOrNumericFormat(int64_t &Format);
OperandMatchResultTy parseNumericFormat(int64_t &Format);
+ OperandMatchResultTy parseFlatOffset(OperandVector &Operands);
bool tryParseFmt(const char *Pref, int64_t MaxVal, int64_t &Val);
bool matchDfmtNfmt(int64_t &Dfmt, int64_t &Nfmt, StringRef FormatStr, SMLoc Loc);
@@ -6366,6 +6367,16 @@
return MatchOperand_Success;
}
+OperandMatchResultTy AMDGPUAsmParser::parseFlatOffset(OperandVector &Operands) {
+ OperandMatchResultTy Res =
+ parseIntWithPrefix("offset", Operands, AMDGPUOperand::ImmTyOffset);
+ if (Res == MatchOperand_NoMatch) {
+ Res = parseIntWithPrefix("inst_offset", Operands,
+ AMDGPUOperand::ImmTyInstOffset);
+ }
+ return Res;
+}
+
//===----------------------------------------------------------------------===//
// ds
//===----------------------------------------------------------------------===//
@@ -9114,8 +9125,6 @@
return parseNamedBit("d16", Operands, AMDGPUOperand::ImmTyD16);
case MCK_ImmDA:
return parseNamedBit("da", Operands, AMDGPUOperand::ImmTyDA);
- case MCK_ImmDMask:
- return parseIntWithPrefix("dmask", Operands, AMDGPUOperand::ImmTyDMask);
case MCK_ImmExpCompr:
return parseNamedBit("compr", Operands, AMDGPUOperand::ImmTyExpCompr);
case MCK_ImmExpVM:
@@ -9137,22 +9146,8 @@
case MCK_ImmNegLo:
return parseOperandArrayWithPrefix("neg_lo", Operands,
AMDGPUOperand::ImmTyNegLo);
- case MCK_ImmOffset:
case MCK_ImmSMEMOffset:
return parseIntWithPrefix("offset", Operands, AMDGPUOperand::ImmTyOffset);
- case MCK_ImmFlatOffset: {
- OperandMatchResultTy Res =
- parseIntWithPrefix("offset", Operands, AMDGPUOperand::ImmTyOffset);
- if (Res == MatchOperand_NoMatch) {
- Res = parseIntWithPrefix("inst_offset", Operands,
- AMDGPUOperand::ImmTyInstOffset);
- }
- return Res;
- }
- case MCK_ImmOffset0:
- return parseIntWithPrefix("offset0", Operands, AMDGPUOperand::ImmTyOffset0);
- case MCK_ImmOffset1:
- return parseIntWithPrefix("offset1", Operands, AMDGPUOperand::ImmTyOffset1);
case MCK_ImmOModSI:
return parseOModOperand(Operands);
case MCK_ImmOpSel:
@@ -9186,12 +9181,6 @@
return parseNamedBit("tfe", Operands, AMDGPUOperand::ImmTyTFE);
case MCK_ImmUNorm:
return parseNamedBit("unorm", Operands, AMDGPUOperand::ImmTyUNorm);
- case MCK_ImmWaitEXP:
- return parseIntWithPrefix("wait_exp", Operands,
- AMDGPUOperand::ImmTyWaitEXP);
- case MCK_ImmWaitVDST:
- return parseIntWithPrefix("wait_vdst", Operands,
- AMDGPUOperand::ImmTyWaitVDST);
}
return tryCustomParseOperand(Operands, MCK);
}
[Attachment #4 (text/plain)]
_______________________________________________
llvm-commits mailing list
llvm-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic