From b118bd3f400cd6e428535a4a00f3b020effcb859 Mon Sep 17 00:00:00 2001 From: Jay Tsou Date: Sat, 1 Nov 2025 13:26:18 -0700 Subject: [PATCH 1/3] [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 Date: Sat, 1 Nov 2025 18:19:50 -0700 Subject: [PATCH 2/3] 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:$function_type, + OptionalAttr:$arg_attrs, + OptionalAttr:$res_attrs + ); + let regions = (region AnyRegion:$body); + + let builders = [ + OpBuilder<(ins + "StringRef":$name, "FunctionType":$type, + CArg<"ArrayRef", "{}">:$argAttrs, + CArg<"ArrayRef", "{}">:$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 argAttrs = {}, ArrayRef resultAttrs = {}); +// CHECK: static _RedundantBuilderOp create(::mlir::OpBuilder &builder, ::mlir::Location location, StringRef name, FunctionType type, ArrayRef argAttrs = {}, ArrayRef resultAttrs = {}); +// CHECK: static _RedundantBuilderOp create(::mlir::ImplicitLocOpBuilder &builder, StringRef name, FunctionType type, ArrayRef argAttrs = {}, ArrayRef 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()); From cafd4481076ecb4df029e394cba1393b0abed7c4 Mon Sep 17 00:00:00 2001 From: Jay Tsou Date: Sat, 1 Nov 2025 18:28:45 -0700 Subject: [PATCH 3/3] Revert "Add test" This reverts commit ade6b77fc74ed96db78351d25340ec99f5974407. --- mlir/test/mlir-tblgen/op-decl-and-defs.td | 27 --------------------- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 3 +-- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td index e11bbc06958ea..87b41f9dea995 100644 --- a/mlir/test/mlir-tblgen/op-decl-and-defs.td +++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td @@ -544,33 +544,6 @@ 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:$function_type, - OptionalAttr:$arg_attrs, - OptionalAttr:$res_attrs - ); - let regions = (region AnyRegion:$body); - - let builders = [ - OpBuilder<(ins - "StringRef":$name, "FunctionType":$type, - CArg<"ArrayRef", "{}">:$argAttrs, - CArg<"ArrayRef", "{}">:$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 argAttrs = {}, ArrayRef resultAttrs = {}); -// CHECK: static _RedundantBuilderOp create(::mlir::OpBuilder &builder, ::mlir::Location location, StringRef name, FunctionType type, ArrayRef argAttrs = {}, ArrayRef resultAttrs = {}); -// CHECK: static _RedundantBuilderOp create(::mlir::ImplicitLocOpBuilder &builder, StringRef name, FunctionType type, ArrayRef argAttrs = {}, ArrayRef 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 fc5361abed68e..d66abdbaf9e44 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -3120,8 +3120,7 @@ void OpEmitter::genBuilder() { auto properties = body ? Method::Static : Method::StaticDeclaration; auto *method = opClass.addMethod("void", "build", properties, arguments); - if (body) - ERROR_IF_PRUNED(method, "build", op); + ERROR_IF_PRUNED(method, "build", op); if (method) method->setDeprecated(builder.getDeprecatedMessage());