Skip to content

Commit 4a18faa

Browse files
committed
Emit named operand indices
1 parent bd6cd92 commit 4a18faa

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mlir/test/mlir-tblgen/op-operand.td

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def OpA : NS_Op<"one_normal_operand_op", []> {
1313
let arguments = (ins I32:$input);
1414
}
1515

16+
// DECL-LABEL: class OpA : {{.*}} {
17+
// DECL: static constexpr int odsIndex_input = 0;
18+
1619
// CHECK-LABEL: OpA definitions
1720

1821
// CHECK: void OpA::build
@@ -28,6 +31,9 @@ def OpB : NS_Op<"one_variadic_operand_op", []> {
2831
let arguments = (ins Variadic<I32>:$input);
2932
}
3033

34+
// DECL-LABEL: class OpB : {{.*}} {
35+
// DECL: static constexpr int odsIndex_input = 0;
36+
3137
// CHECK-LABEL: OpB::build
3238
// CHECK: ::mlir::ValueRange input
3339
// CHECK-NOT: assert
@@ -37,6 +43,11 @@ def OpD : NS_Op<"mix_variadic_and_normal_inputs_op", [SameVariadicOperandSize]>
3743
let arguments = (ins Variadic<AnyTensor>:$input1, AnyTensor:$input2, Variadic<AnyTensor>:$input3);
3844
}
3945

46+
// DECL-LABEL: class OpD : {{.*}} {
47+
// DECL: static constexpr int odsIndex_input1 = 0;
48+
// DECL: static constexpr int odsIndex_input2 = 1;
49+
// DECL: static constexpr int odsIndex_input3 = 2;
50+
4051
// DECL-LABEL: ::mlir::Operation::operand_range getInput1
4152
// DECL-NEXT: return getODSOperands(0);
4253

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,17 @@ generateNamedOperandGetters(const Operator &op, Class &opClass,
22232223
"'SameVariadicOperandSize' traits");
22242224
}
22252225

2226+
// Print the ods names so they don't need to be hardcoded in the source.
2227+
for (int i = 0; i != numOperands; ++i) {
2228+
const auto &operand = op.getOperand(i);
2229+
if (operand.name.empty())
2230+
continue;
2231+
2232+
opClass.declare<Field>("static constexpr int", Twine("odsIndex_") +
2233+
operand.name + " = " +
2234+
Twine(i));
2235+
}
2236+
22262237
// First emit a few "sink" getter methods upon which we layer all nicer named
22272238
// getter methods.
22282239
// If generating for an adaptor, the method is put into the non-templated

0 commit comments

Comments
 (0)