Skip to content

[mlir-tblgen] Emit named operand indices #146839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mlir/test/mlir-tblgen/op-operand.td
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def OpA : NS_Op<"one_normal_operand_op", []> {
let arguments = (ins I32:$input);
}

// DECL-LABEL: class OpA : {{.*}} {
// DECL: static constexpr int odsIndex_input = 0;

// CHECK-LABEL: OpA definitions

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

// DECL-LABEL: class OpB : {{.*}} {
// DECL: static constexpr int odsIndex_input = 0;

// CHECK-LABEL: OpB::build
// CHECK: ::mlir::ValueRange input
// CHECK-NOT: assert
Expand All @@ -37,6 +43,11 @@ def OpD : NS_Op<"mix_variadic_and_normal_inputs_op", [SameVariadicOperandSize]>
let arguments = (ins Variadic<AnyTensor>:$input1, AnyTensor:$input2, Variadic<AnyTensor>:$input3);
}

// DECL-LABEL: class OpD : {{.*}} {
// DECL: static constexpr int odsIndex_input1 = 0;
// DECL: static constexpr int odsIndex_input2 = 1;
// DECL: static constexpr int odsIndex_input3 = 2;

// DECL-LABEL: ::mlir::Operation::operand_range getInput1
// DECL-NEXT: return getODSOperands(0);

Expand Down
11 changes: 11 additions & 0 deletions mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2223,6 +2223,17 @@ generateNamedOperandGetters(const Operator &op, Class &opClass,
"'SameVariadicOperandSize' traits");
}

// Print the ods names so they don't need to be hardcoded in the source.
for (int i = 0; i != numOperands; ++i) {
const auto &operand = op.getOperand(i);
if (operand.name.empty())
continue;

opClass.declare<Field>("static constexpr int", Twine("odsIndex_") +
operand.name + " = " +
Twine(i));
}

// First emit a few "sink" getter methods upon which we layer all nicer named
// getter methods.
// If generating for an adaptor, the method is put into the non-templated
Expand Down
Loading