[Mlir-commits] [mlir] MLIR Rewriters: add new listener to emit match failures to user, enhance docs (PR #94130)

Ryan Thomas Lynch llvmlistbot at llvm.org
Mon Jun 3 10:15:46 PDT 2024


================
@@ -511,6 +512,50 @@ class RewriterBase : public OpBuilder {
     OpBuilder::Listener *listener;
   };
 
+  /// A listener that emits all notifyMatchFailure calls
+  /// with the given DiagnosticSeverity (default is Error).
+  /// This can be used so that any notifyMatchFailure calls will be emitted
+  /// as a message with the given severity (Remark will be used for Note)
+  struct MatchFailureEmittingListener : public RewriterBase::Listener {
----------------
emosy wrote:

I agree that "creative misuse" seems to describe it well. But if all that `applyPartialConversion` returns is `LogicalResult`, then how else do you describe to the user that a lowering step failed? For example, I see a lot of `if(failed(applyPartialConversion(...))) return signalPassFailure();` which means that you get whatever error message partial conversion decides to give, which is usually something about illegal operations that were not able to be lowered without any reason why they couldn't be lowered.

Imagine my surprise when I realized that all the helpful messages we were carefully crafting in `notifyMatchFailure` calls weren't even being printed since we didn't have a listener configured, and then when I did try to configure a listener, the dialect conversion driver doesn't even call the `notifyMatchFailure` on the listener!

I wish there were a way to attach a note to the "failed to legalize illegal operation" message in partial conversion with the match failure reason, but it was not immediately obvious to me how to do that.

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


More information about the Mlir-commits mailing list