[Mlir-commits] [mlir] [MLIR][SparseTensor] Fix fingerprint changes in SparseFuncAssembler (PR #188958)

Mehdi Amini llvmlistbot at llvm.org
Fri Mar 27 03:48:27 PDT 2026


https://github.com/joker-eph created https://github.com/llvm/llvm-project/pull/188958

SparseFuncAssembler::matchAndRewrite was calling funcOp.setName(), funcOp.setPrivate(), and funcOp->removeAttr() directly without notifying the rewriter, causing "operation fingerprint changed" errors under MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS.

Wrap all in-place funcOp mutations with rewriter.modifyOpInPlace.

Assisted-by: Claude Code

Fix a failure present with MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=ON.

>From 48675679ae86576310fc1473f84a1db2014531d9 Mon Sep 17 00:00:00 2001
From: Mehdi Amini <joker.eph at gmail.com>
Date: Thu, 26 Mar 2026 15:57:37 -0700
Subject: [PATCH] [MLIR][SparseTensor] Fix fingerprint changes in
 SparseFuncAssembler

SparseFuncAssembler::matchAndRewrite was calling funcOp.setName(),
funcOp.setPrivate(), and funcOp->removeAttr() directly without notifying
the rewriter, causing "operation fingerprint changed" errors under
MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS.

Wrap all in-place funcOp mutations with rewriter.modifyOpInPlace.

Assisted-by: Claude Code
Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>
Fix a failure present with MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=ON.
---
 .../SparseTensor/Transforms/SparseAssembler.cpp        | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseAssembler.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseAssembler.cpp
index 0a8f29cd0b417..4428339b38c5d 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseAssembler.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseAssembler.cpp
@@ -193,8 +193,10 @@ struct SparseFuncAssembler : public OpRewritePattern<func::FuncOp> {
     // Modify the original method into an internal, private method.
     auto orgName = funcOp.getName();
     std::string wrapper = llvm::formatv("_internal_{0}", orgName).str();
-    funcOp.setName(wrapper);
-    funcOp.setPrivate();
+    rewriter.modifyOpInPlace(funcOp, [&]() {
+      funcOp.setName(wrapper);
+      funcOp.setPrivate();
+    });
 
     // Start the new public wrapper method with original name.
     Location loc = funcOp.getLoc();
@@ -235,7 +237,9 @@ struct SparseFuncAssembler : public OpRewritePattern<func::FuncOp> {
             LLVM::LLVMDialect::getEmitCWrapperAttrName())) {
       func->setAttr(LLVM::LLVMDialect::getEmitCWrapperAttrName(),
                     UnitAttr::get(context));
-      funcOp->removeAttr(LLVM::LLVMDialect::getEmitCWrapperAttrName());
+      rewriter.modifyOpInPlace(funcOp, [&]() {
+        funcOp->removeAttr(LLVM::LLVMDialect::getEmitCWrapperAttrName());
+      });
     }
     return success();
   }



More information about the Mlir-commits mailing list