[Mlir-commits] [mlir] 58c0bd1 - [mlir][Transforms] Dialect Conversion: `allowPatternRollback` to check foldings (#148394)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Jul 13 01:06:10 PDT 2025
Author: Matthias Springer
Date: 2025-07-13T10:06:07+02:00
New Revision: 58c0bd196e566f20a6b5e35ff0b57db8fe6b34ca
URL: https://github.com/llvm/llvm-project/commit/58c0bd196e566f20a6b5e35ff0b57db8fe6b34ca
DIFF: https://github.com/llvm/llvm-project/commit/58c0bd196e566f20a6b5e35ff0b57db8fe6b34ca.diff
LOG: [mlir][Transforms] Dialect Conversion: `allowPatternRollback` to check foldings (#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. (Support
for rolling back foldings could be added at a later point of time.)
This commit improves the `allowPatternRollback` flag handling, such that
a fatal error is reported when a folder is attempted to be rolled back.
Added:
Modified:
mlir/lib/Transforms/Utils/DialectConversion.cpp
Removed:
################################################################################
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