[Mlir-commits] [mlir] [mlir-tblgen] Only create body for unpruned create (PR #166019)
Hsiang-Chieh Tsou
llvmlistbot at llvm.org
Sat Nov 1 18:20:02 PDT 2025
https://github.com/hsjts0u updated https://github.com/llvm/llvm-project/pull/166019
>From b118bd3f400cd6e428535a4a00f3b020effcb859 Mon Sep 17 00:00:00 2001
From: Jay Tsou <hsjts0u at gmail.com>
Date: Sat, 1 Nov 2025 13:26:18 -0700
Subject: [PATCH 1/2] [mlir-tblgen] Do not create body for pruned create
---
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 371864830a3c1..d66abdbaf9e44 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2632,11 +2632,13 @@ void OpEmitter::genInlineCreateBody(
interleaveComma(nonBuilderStateArgsList, nonBuilderStateArgsOS);
nonBuilderStateArgs = ", " + nonBuilderStateArgs;
}
- cWithLoc->body() << llvm::formatv(inlineCreateBody, locParamName,
- nonBuilderStateArgs,
- opClass.getClassName());
- cImplicitLoc->body() << llvm::formatv(inlineCreateBodyImplicitLoc,
- nonBuilderStateArgs);
+ if (cWithLoc)
+ cWithLoc->body() << llvm::formatv(inlineCreateBody, locParamName,
+ nonBuilderStateArgs,
+ opClass.getClassName());
+ if (cImplicitLoc)
+ cImplicitLoc->body() << llvm::formatv(inlineCreateBodyImplicitLoc,
+ nonBuilderStateArgs);
}
void OpEmitter::genSeparateArgParamBuilder() {
>From ade6b77fc74ed96db78351d25340ec99f5974407 Mon Sep 17 00:00:00 2001
From: Jay Tsou <hsjts0u at gmail.com>
Date: Sat, 1 Nov 2025 18:19:50 -0700
Subject: [PATCH 2/2] Add test
---
mlir/test/mlir-tblgen/op-decl-and-defs.td | 27 +++++++++++++++++++++
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 3 ++-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td
index 87b41f9dea995..e11bbc06958ea 100644
--- a/mlir/test/mlir-tblgen/op-decl-and-defs.td
+++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td
@@ -544,6 +544,33 @@ def _BOp : NS_Op<"_op_with_leading_underscore_and_no_namespace", []>;
// REDUCE_EXC-NOT: NS::AOp declarations
// REDUCE_EXC-LABEL: NS::BOp declarations
+def _RedundantBuilderOp : NS_Op<"redundant_builder_op", []> {
+ let arguments = (ins
+ SymbolNameAttr:$sym_name,
+ TypeAttrOf<FunctionType>:$function_type,
+ OptionalAttr<DictArrayAttr>:$arg_attrs,
+ OptionalAttr<DictArrayAttr>:$res_attrs
+ );
+ let regions = (region AnyRegion:$body);
+
+ let builders = [
+ OpBuilder<(ins
+ "StringRef":$name, "FunctionType":$type,
+ CArg<"ArrayRef<DictionaryAttr>", "{}">:$argAttrs,
+ CArg<"ArrayRef<DictionaryAttr>", "{}">:$resultAttrs)
+ >,
+ OpBuilder<(ins
+ "StringRef":$name, "FunctionType":$type)
+ >];
+
+ let skipDefaultBuilders = 1;
+}
+// CHECK-LABEL: NS::_RedundantBuilderOp declarations
+// CHECK: class _RedundantBuilderOp
+// CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, StringRef name, FunctionType type, ArrayRef<DictionaryAttr> argAttrs = {}, ArrayRef<DictionaryAttr> resultAttrs = {});
+// CHECK: static _RedundantBuilderOp create(::mlir::OpBuilder &builder, ::mlir::Location location, StringRef name, FunctionType type, ArrayRef<DictionaryAttr> argAttrs = {}, ArrayRef<DictionaryAttr> resultAttrs = {});
+// CHECK: static _RedundantBuilderOp create(::mlir::ImplicitLocOpBuilder &builder, StringRef name, FunctionType type, ArrayRef<DictionaryAttr> argAttrs = {}, ArrayRef<DictionaryAttr> resultAttrs = {});
+
// CHECK-LABEL: _TypeInferredPropOp declarations
def _TypeInferredPropOp : NS_Op<"type_inferred_prop_op_with_properties", [
AllTypesMatch<["value", "result"]>
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index d66abdbaf9e44..fc5361abed68e 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -3120,7 +3120,8 @@ void OpEmitter::genBuilder() {
auto properties = body ? Method::Static : Method::StaticDeclaration;
auto *method = opClass.addMethod("void", "build", properties, arguments);
- ERROR_IF_PRUNED(method, "build", op);
+ if (body)
+ ERROR_IF_PRUNED(method, "build", op);
if (method)
method->setDeprecated(builder.getDeprecatedMessage());
More information about the Mlir-commits
mailing list