[llvm-branch-commits] [mlir] [mlir] Deprecate the legacy OpBuilder::tryFold overload (PR #229200)

Victor Perez via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Oct 5 12:56:29 PDT 2026


https://github.com/victor-eds created https://github.com/llvm/llvm-project/pull/229200

Deprecate the `OpBuilder::tryFold` overload with a `SmallVectorImpl<Value> &` not supporting partial folds.

No in-tree code calls the old overload anymore, so this patch marks it as deprecated.

Assisted by: Claude Code.

>From ee1c9ac4c12675ed946cb21d5ead50a74b4445bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?V=C3=ADctor=20P=C3=A9rez=20Carrasco?=
 <victor.pc.upm at gmail.com>
Date: Sat, 3 Oct 2026 18:14:33 -0700
Subject: [PATCH] [mlir] Deprecate the OpBuilder::tryFold overload with a
 results vector
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The `OpBuilder::tryFold` overload with a `SmallVectorImpl<Value> &`
parameter drops partial folds. The overload that returns
`OpFoldResults`, together with `materializeFoldResults`, keeps them.
No in-tree code calls the old overload anymore, so this patch marks it
as deprecated. The unit test of the old overload suppresses the
deprecation warning.

Signed-off-by: Víctor Pérez Carrasco <victor.pc.upm at gmail.com>
---
 mlir/include/mlir/IR/Builders.h         | 2 ++
 mlir/unittests/IR/OpFoldResultsTest.cpp | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h
index f52f6def96a2f..8e17f3cae88c8 100644
--- a/mlir/include/mlir/IR/Builders.h
+++ b/mlir/include/mlir/IR/Builders.h
@@ -617,6 +617,8 @@ class OpBuilder : public Builder {
   /// the operation in place, and as a failure otherwise.
   ///
   /// Note: This function does not erase the operation on a successful fold.
+  [[deprecated("use the overload that returns OpFoldResults and "
+               "materializeFoldResults; they also return partial folds")]]
   LogicalResult
   tryFold(Operation *op, SmallVectorImpl<Value> &results,
           SmallVectorImpl<Operation *> *materializedConstants = nullptr);
diff --git a/mlir/unittests/IR/OpFoldResultsTest.cpp b/mlir/unittests/IR/OpFoldResultsTest.cpp
index 69dc92a922cd2..4d08c4a296a77 100644
--- a/mlir/unittests/IR/OpFoldResultsTest.cpp
+++ b/mlir/unittests/IR/OpFoldResultsTest.cpp
@@ -717,6 +717,8 @@ TEST_F(OpFoldResultsTest, FreeHelpersMatchMembers) {
   EXPECT_TRUE(failed(failedResult));
 }
 
+// This test covers the deprecated overload of OpBuilder::tryFold.
+LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_PUSH
 TEST_F(OpFoldResultsTest, OpBuilderLegacyTryFold) {
   Block block;
   OpBuilder b(&context);
@@ -757,6 +759,7 @@ TEST_F(OpFoldResultsTest, OpBuilderLegacyTryFold) {
   EXPECT_EQ(results[0], constants[0]->getResult(0));
   EXPECT_EQ(results[1], producer);
 }
+LLVM_SUPPRESS_DEPRECATED_DECLARATIONS_POP
 
 #ifdef GTEST_HAS_DEATH_TEST
 #ifndef NDEBUG



More information about the llvm-branch-commits mailing list