[llvm-branch-commits] [mlir] [mlir][Transforms] Dialect conversion: Add flag to disable rollback (PR #136490)

Markus Böck via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Apr 21 21:49:11 PDT 2025


================
@@ -1216,10 +1220,19 @@ void ConversionPatternRewriterImpl::resetState(RewriterState state) {
     replacedOps.pop_back();
 }
 
-void ConversionPatternRewriterImpl::undoRewrites(unsigned numRewritesToKeep) {
+void ConversionPatternRewriterImpl::undoRewrites(unsigned numRewritesToKeep,
+                                                 StringRef patternName) {
   for (auto &rewrite :
-       llvm::reverse(llvm::drop_begin(rewrites, numRewritesToKeep)))
+       llvm::reverse(llvm::drop_begin(rewrites, numRewritesToKeep))) {
+    if (!config.allowPatternRollback &&
+        !isa<UnresolvedMaterializationRewrite>(rewrite)) {
+      // Unresolved materializations can always be rolled back (erased).
+      std::string errorMessage = "pattern '" + std::string(patternName) +
+                                 "' rollback of IR modifications requested";
+      llvm_unreachable(errorMessage.c_str());
----------------
zero9178 wrote:

```suggestion
      llvm::report_fatal_error("pattern '" + patternName +
                               "' rollback of IR modifications requested");
```
`llvm_unreachable` might not expand to `report_fatal_error`. I think it'd be better to call it directly.

https://github.com/llvm/llvm-project/pull/136490


More information about the llvm-branch-commits mailing list