[Mlir-commits] [mlir] e26fb78 - [mlir][ODS] Reuse collective builders for zero-result ops (NFC) (#226059)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 24 01:51:20 PDT 2026


Author: Mehdi Amini
Date: 2026-09-24T08:51:13Z
New Revision: e26fb78a9767cf0a9b0995286cd393c8f6f8c017

URL: https://github.com/llvm/llvm-project/commit/e26fb78a9767cf0a9b0995286cd393c8f6f8c017
DIFF: https://github.com/llvm/llvm-project/commit/e26fb78a9767cf0a9b0995286cd393c8f6f8c017.diff

LOG: [mlir][ODS] Reuse collective builders for zero-result ops (NFC) (#226059)

Forward the no-result separate-argument builder to its collective
counterpart instead of generating the same operand, attribute, and
region construction twice. This cuts OpenMPDialect.cpp build time by
1.5% and its machine-code text by about 71 KB.

Assisted-by: Codex

Added: 
    

Modified: 
    mlir/test/mlir-tblgen/op-attribute.td
    mlir/test/mlir-tblgen/op-decl-and-defs.td
    mlir/test/mlir-tblgen/op-operand.td
    mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/test/mlir-tblgen/op-attribute.td b/mlir/test/mlir-tblgen/op-attribute.td
index 83a9e0ef79113..815b857f6c060 100644
--- a/mlir/test/mlir-tblgen/op-attribute.td
+++ b/mlir/test/mlir-tblgen/op-attribute.td
@@ -143,6 +143,9 @@ def AOp : NS_Op<"a_op", []> {
 // Test build methods
 // ---
 
+// DEF:      void AOp::build(
+// DEF:        build(odsBuilder, odsState, ::mlir::TypeRange{}, aAttr, bAttr, cAttr, dAttr);
+
 // DEF:      void AOp::build(
 // DEF:        auto &odsProperties = odsState.getOrAddProperties<Properties>();
 // DEF:        odsProperties.aAttr = aAttr;
@@ -150,6 +153,10 @@ def AOp : NS_Op<"a_op", []> {
 // DEF:        if (cAttr) {
 // DEF-NEXT:     odsProperties.cAttr = cAttr;
 
+// DEF:      void AOp::build(
+// DEF:        some-return-type aAttr, some-return-type bAttr, /*optional*/some-attr-kind cAttr
+// DEF:        build(odsBuilder, odsState, ::mlir::TypeRange{}, aAttr, bAttr, cAttr, dAttr);
+
 // DEF:        odsProperties.aAttr = some-const-builder-call(odsBuilder, aAttr);
 // DEF-NEXT:   odsProperties.bAttr = some-const-builder-call(odsBuilder, bAttr);
 // DEF-NEXT:   if (cAttr) {
@@ -158,10 +165,6 @@ def AOp : NS_Op<"a_op", []> {
 // DEF-NOT:    if (dAttr)
 // DEF:        odsProperties.dAttr = some-const-builder-call(odsBuilder, dAttr);
 
-// DEF:      void AOp::build(
-// DEF:        some-return-type aAttr, some-return-type bAttr, /*optional*/some-attr-kind cAttr
-// DEF:        odsProperties.aAttr = some-const-builder-call(odsBuilder, aAttr);
-
 // DEF:      void AOp::build(
 // DEF:        ::llvm::ArrayRef<::mlir::NamedAttribute> attributes
 // DEF:      buildPropertiesAndDiscardableAttributes(odsState, attributes);

diff  --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td
index 71fd83d034d3f..bcc81cd74d976 100644
--- a/mlir/test/mlir-tblgen/op-decl-and-defs.td
+++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td
@@ -212,6 +212,8 @@ def NS_BOp : NS_Op<"op_with_no_operand", []> {
 
 // CHECK-LABEL: NS::BOp declarations
 // CHECK: OpTrait::ZeroOperands
+// DEFS-LABEL: void BOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) {
+// DEFS-NEXT:   build(odsBuilder, odsState, ::mlir::TypeRange{});
 
 def NS_COp : NS_Op<"op_with_one_operand", []> {
   let arguments = (ins I32:$operand);

diff  --git a/mlir/test/mlir-tblgen/op-operand.td b/mlir/test/mlir-tblgen/op-operand.td
index ab8d721ed5427..95ddf957ee1c5 100644
--- a/mlir/test/mlir-tblgen/op-operand.td
+++ b/mlir/test/mlir-tblgen/op-operand.td
@@ -37,7 +37,9 @@ def OpB : NS_Op<"one_variadic_operand_op", []> {
 // CHECK-LABEL: OpB::build
 // CHECK:         ::mlir::ValueRange input
 // CHECK-NOT:     assert
-// CHECK:         odsState.addOperands(input);
+// CHECK:         build(odsBuilder, odsState, ::mlir::TypeRange{}, input);
+// CHECK-LABEL: OpB::build
+// CHECK:         odsState.addOperands(operands);
 
 def OpD : NS_Op<"mix_variadic_and_normal_inputs_op", [SameVariadicOperandSize]> {
   let arguments = (ins Variadic<AnyTensor>:$input1, AnyTensor:$input2, Variadic<AnyTensor>:$input3);
@@ -55,6 +57,8 @@ def OpD : NS_Op<"mix_variadic_and_normal_inputs_op", [SameVariadicOperandSize]>
 // DECL-NEXT: return ::llvm::cast<::mlir::TypedValue<::mlir::TensorType>>(*getODSOperands(1).begin());
 
 // CHECK-LABEL: OpD::build
-// CHECK-NEXT: odsState.addOperands(input1);
+// CHECK-NEXT: build(odsBuilder, odsState, ::mlir::TypeRange{}, input1, input2, input3);
+// CHECK-LABEL: OpD::build
+// CHECK: odsState.addOperands(input1);
 // CHECK-NEXT: odsState.addOperands(input2);
 // CHECK-NEXT: odsState.addOperands(input3);

diff  --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index 475336506993a..f963d70630136 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2473,6 +2473,15 @@ void OpEmitter::genSeparateArgParamBuilder() {
     genInlineCreateBody(paramList);
 
     auto &body = m->body();
+    // The no-result builder can reuse the collective builder. Both forms
+    // otherwise emit identical operand, attribute, and region handling.
+    if (paramKind == TypeParamKind::Separate && op.getNumResults() == 0) {
+      body << "  build(odsBuilder, odsState, ::mlir::TypeRange{}";
+      for (const MethodParameter &param : llvm::drop_begin(paramList, 2))
+        body << ", " << param.getName();
+      body << ");\n";
+      return;
+    }
     genCodeForAddingArgAndRegionForBuilder(body, inferredAttributes,
                                            /*isRawValueAttr=*/attrType ==
                                                AttrParamKind::UnwrappedValue);


        


More information about the Mlir-commits mailing list