[llvm] 4857067 - [AMDGPU][AsmParser][NFC] Specify parser methods directly in operand classes.
Ivan Kosarev via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 5 05:04:23 PDT 2023
Author: Ivan Kosarev
Date: 2023-06-05T13:04:15+01:00
New Revision: 48570678c1a35d108802fdd422f726e0bac91d76
URL: https://github.com/llvm/llvm-project/commit/48570678c1a35d108802fdd422f726e0bac91d76
DIFF: https://github.com/llvm/llvm-project/commit/48570678c1a35d108802fdd422f726e0bac91d76.diff
LOG: [AMDGPU][AsmParser][NFC] Specify parser methods directly in operand classes.
Eliminates the need for custom operand classes whose only purpose is to
define a parser method.
Part of <https://github.com/llvm/llvm-project/issues/62629>.
Reviewed By: dp
Differential Revision: https://reviews.llvm.org/D151685
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
llvm/lib/Target/AMDGPU/SIInstrInfo.td
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
index c74728a9fb578..ed02c445d64c0 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
@@ -123,34 +123,31 @@ def FMA : Predicate<"Subtarget->hasFMA()">;
def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
-class CustomOperandClass<string name, bit optional> : AsmOperandClass {
+class CustomOperandClass<string name, bit optional, string parserMethod>
+ : AsmOperandClass {
let Name = name;
let PredicateMethod = "is"#name;
- let ParserMethod = "parse"#name;
+ let ParserMethod = parserMethod;
let RenderMethod = "addImmOperands";
let IsOptional = optional;
let DefaultMethod = "default"#name;
}
-class CustomOperandProps<bit optional = 0, string name = NAME,
- AsmOperandClass opClass = CustomOperandClass<name, optional>> {
+class CustomOperandProps<bit optional = 0, string name = NAME> {
+ string ParserMethod = "parse"#name;
string PrintMethod = "print"#name;
- AsmOperandClass ParserMatchClass = opClass;
+ AsmOperandClass ParserMatchClass =
+ CustomOperandClass<name, optional, ParserMethod>;
string OperandType = "OPERAND_IMMEDIATE";
}
-class CustomOperand<ValueType type, bit optional = 0, string name = NAME,
- AsmOperandClass opClass = CustomOperandClass<name, optional>>
- : Operand<type>, CustomOperandProps<optional, name, opClass>;
-
-class ImmOperandClass<string name, bit optional>
- : CustomOperandClass<name, optional> {
- let ParserMethod = "";
-}
+class CustomOperand<ValueType type, bit optional = 0, string name = NAME>
+ : Operand<type>, CustomOperandProps<optional, name>;
class ImmOperand<ValueType type, string name, bit optional = 0,
string printer = "print"#name>
- : CustomOperand<type, optional, name, ImmOperandClass<name, optional>> {
+ : CustomOperand<type, optional, name> {
+ let ParserMethod = "";
let PrintMethod = printer;
}
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.td b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
index 77dad7e4e64da..4cbe0fca7e69e 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.td
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.td
@@ -1121,8 +1121,9 @@ def SDWAVopcDst : BoolRC {
let PrintMethod = "printVOPDst";
}
-class NamedIntOperandClass<string Prefix, string Name, string ConvertMethod>
- : CustomOperandClass<Name, 1> {
+class NamedIntOperand<ValueType Type, string Prefix, string Name = NAME,
+ string ConvertMethod = "nullptr">
+ : CustomOperand<Type, 1, Name> {
string ImmTy = "AMDGPUOperand::ImmTy"#Name;
let ParserMethod =
"[this](OperandVector &Operands) -> OperandMatchResultTy { "#
@@ -1130,48 +1131,37 @@ class NamedIntOperandClass<string Prefix, string Name, string ConvertMethod>
ConvertMethod#"); }";
}
-class NamedIntOperand<ValueType Type, string Prefix, string Name = NAME,
- string ConvertMethod = "nullptr">
- : CustomOperand<Type, 1, Name, NamedIntOperandClass<Prefix, Name, ConvertMethod>>;
-
-class BitOperandClass<string Id, string Name>
- : CustomOperandClass<Name, 1> {
+class NamedBitOperand<string Id, string Name = NAME>
+ : CustomOperand<i1, 1, Name> {
string ImmTy = "AMDGPUOperand::ImmTy"#Name;
let ParserMethod =
"[this](OperandVector &Operands) -> OperandMatchResultTy { "#
"return parseNamedBit(\""#Id#"\", Operands, "#ImmTy#"); }";
}
-class NamedBitOperand<string Id, string Name = NAME>
- : CustomOperand<i1, 1, Name, BitOperandClass<Id, Name>>;
-
class DefaultOperand<CustomOperand Op, int Value>
: OperandWithDefaultOps<Op.Type, (ops (Op.Type Value))>,
- CustomOperandProps<1, Op.ParserMatchClass.Name, Op.ParserMatchClass>;
+ CustomOperandProps<1, Op.ParserMatchClass.Name> {
+ let ParserMethod = Op.ParserMatchClass.ParserMethod;
+}
-class SDWAOperandClass<string Id, string Name>
- : CustomOperandClass<Name, 1> {
+class SDWAOperand<string Id, string Name = NAME>
+ : CustomOperand<i32, 1, Name> {
string ImmTy = "AMDGPUOperand::ImmTy"#Name;
let ParserMethod =
"[this](OperandVector &Operands) -> OperandMatchResultTy { "#
"return parseSDWASel(Operands, \""#Id#"\", "#ImmTy#"); }";
}
-class SDWAOperand<string Id, string Name = NAME>
- : CustomOperand<i32, 1, Name, SDWAOperandClass<Id, Name>>;
-
-class ArrayOperandClass<string Id, string Name>
- : CustomOperandClass<Name, 1> {
+class ArrayOperand0<string Id, string Name = NAME>
+ : OperandWithDefaultOps<i32, (ops (i32 0))>,
+ CustomOperandProps<1, Name> {
string ImmTy = "AMDGPUOperand::ImmTy"#Name;
let ParserMethod =
"[this](OperandVector &Operands) -> OperandMatchResultTy { "#
"return parseOperandArrayWithPrefix(\""#Id#"\", Operands, "#ImmTy#"); }";
}
-class ArrayOperand0<string Id, string Name = NAME>
- : OperandWithDefaultOps<i32, (ops (i32 0))>,
- CustomOperandProps<1, Name, ArrayOperandClass<Id, Name>>;
-
def flat_offset : CustomOperand<i32, 1, "FlatOffset">;
def offset : NamedIntOperand<i32, "offset", "Offset">;
def offset0 : NamedIntOperand<i8, "offset0", "Offset0">;
More information about the llvm-commits
mailing list