[Mlir-commits] [mlir] [mlir][Transforms] Dialect Conversion: `allowPatternRollback` to check foldings (PR #148394)
Matthias Springer
llvmlistbot at llvm.org
Sat Jul 12 12:13:09 PDT 2025
https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/148394
When an operation is folded to an attribute, the attribute must be materialized as a constant operation. That operation must then be legalized. If such a legalization fails, the entire folding is rolled back. This is not supported in a One-Shot Dialect Conversion.
This commit improves the `allowPatternRollback` flag handling, such that a fatal error is reported when a folder is attempted to be rolled back.
>From 886438865e2656fdbb135882729e6133bdc8f47e Mon Sep 17 00:00:00 2001
From: Matthias Springer <me at m-sp.org>
Date: Sat, 12 Jul 2025 18:54:39 +0000
Subject: [PATCH] [mlir][Transforms] Dialect Conversion: `allowPatternRollback`
to check foldings
---
mlir/lib/Transforms/Utils/DialectConversion.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/mlir/lib/Transforms/Utils/DialectConversion.cpp b/mlir/lib/Transforms/Utils/DialectConversion.cpp
index 9f71129d39d09..437dbcfea5288 100644
--- a/mlir/lib/Transforms/Utils/DialectConversion.cpp
+++ b/mlir/lib/Transforms/Utils/DialectConversion.cpp
@@ -2176,6 +2176,7 @@ OperationLegalizer::legalizeWithFold(Operation *op,
(void)rewriterImpl;
// Try to fold the operation.
+ StringRef opName = op->getName().getStringRef();
SmallVector<Value, 2> replacementValues;
SmallVector<Operation *, 2> newOps;
rewriter.setInsertionPoint(op);
@@ -2195,6 +2196,12 @@ OperationLegalizer::legalizeWithFold(Operation *op,
LLVM_DEBUG(logFailure(rewriterImpl.logger,
"failed to legalize generated constant '{0}'",
newOp->getName()));
+ if (!config.allowPatternRollback) {
+ // Rolling back a folder is like rolling back a pattern.
+ llvm::report_fatal_error(
+ "op '" + opName +
+ "' folder rollback of IR modifications requested");
+ }
// Legalization failed: erase all materialized constants.
for (Operation *op : newOps)
rewriter.eraseOp(op);
More information about the Mlir-commits
mailing list