Skip to content

Commit 58c0bd1

Browse files
[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.
1 parent a647fd7 commit 58c0bd1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mlir/lib/Transforms/Utils/DialectConversion.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,7 @@ OperationLegalizer::legalizeWithFold(Operation *op,
21762176
(void)rewriterImpl;
21772177

21782178
// Try to fold the operation.
2179+
StringRef opName = op->getName().getStringRef();
21792180
SmallVector<Value, 2> replacementValues;
21802181
SmallVector<Operation *, 2> newOps;
21812182
rewriter.setInsertionPoint(op);
@@ -2195,6 +2196,12 @@ OperationLegalizer::legalizeWithFold(Operation *op,
21952196
LLVM_DEBUG(logFailure(rewriterImpl.logger,
21962197
"failed to legalize generated constant '{0}'",
21972198
newOp->getName()));
2199+
if (!config.allowPatternRollback) {
2200+
// Rolling back a folder is like rolling back a pattern.
2201+
llvm::report_fatal_error(
2202+
"op '" + opName +
2203+
"' folder rollback of IR modifications requested");
2204+
}
21982205
// Legalization failed: erase all materialized constants.
21992206
for (Operation *op : newOps)
22002207
rewriter.eraseOp(op);

0 commit comments

Comments
 (0)