[Mlir-commits] [mlir] [mlir][ODS] Reuse collective builders for zero-result ops (NFC) (PR #226059)
Mehdi Amini
llvmlistbot at llvm.org
Thu Sep 24 01:02:43 PDT 2026
https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/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
>From 6cd8f103a7743785b636694f5d3f35a391bf844c Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Wed, 23 Sep 2026 08:34:29 -0700
Subject: [PATCH] [mlir][ODS] Reuse collective builders for zero-result ops
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 compiler work
by 1.5% and its machine-code text by about 71 KB.
Assisted-by: Codex
(cherry picked from commit b452f58f7c29795f5bcee4426940ac8b80729825)
---
mlir/test/mlir-tblgen/op-decl-and-defs.td | 2 ++
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 9 +++++++++
2 files changed, 11 insertions(+)
diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td
index 32c4bb88d188b..bd39c4a013ba3 100644
--- a/mlir/test/mlir-tblgen/op-decl-and-defs.td
+++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td
@@ -205,6 +205,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/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index aa9ff159903bc..6bda98d00e50f 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -2485,6 +2485,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 ¶m : 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