[Mlir-commits] [mlir] ea2d2d1 - [mlir][transform] Dump match failures in TrackingListener

Matthias Springer llvmlistbot at llvm.org
Tue Apr 11 21:05:07 PDT 2023


Author: Matthias Springer
Date: 2023-04-12T13:04:56+09:00
New Revision: ea2d2d10ee1ed62c450871c62a3c587343a6ea25

URL: https://github.com/llvm/llvm-project/commit/ea2d2d10ee1ed62c450871c62a3c587343a6ea25
DIFF: https://github.com/llvm/llvm-project/commit/ea2d2d10ee1ed62c450871c62a3c587343a6ea25.diff

LOG: [mlir][transform] Dump match failures in TrackingListener

Differential Revision: https://reviews.llvm.org/D147997

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Transform/IR/TransformOps.h
    mlir/lib/Dialect/Transform/IR/TransformOps.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Transform/IR/TransformOps.h b/mlir/include/mlir/Dialect/Transform/IR/TransformOps.h
index 0443e3a9f2c39..58e9d8506808a 100644
--- a/mlir/include/mlir/Dialect/Transform/IR/TransformOps.h
+++ b/mlir/include/mlir/Dialect/Transform/IR/TransformOps.h
@@ -50,6 +50,13 @@ class TrackingListener : public RewriterBase::Listener,
   virtual Operation *findReplacementOp(Operation *op,
                                        ValueRange newValues) const;
 
+  /// Notify the listener that the pattern failed to match the given operation,
+  /// and provide a callback to populate a diagnostic with the reason why the
+  /// failure occurred.
+  LogicalResult
+  notifyMatchFailure(Location loc,
+                     function_ref<void(Diagnostic &)> reasonCallback) override;
+
   /// This function is called when a tracked payload op is dropped because no
   /// replacement op was found. Derived classes can implement this function for
   /// custom error handling.

diff  --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index c4f5769531c9d..95a004a7b049b 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -181,6 +181,16 @@ bool transform::TrackingListener::isNewOp(Operation *op) const {
   return it->second.contains(op);
 }
 
+LogicalResult transform::TrackingListener::notifyMatchFailure(
+    Location loc, function_ref<void(Diagnostic &)> reasonCallback) {
+  LLVM_DEBUG({
+    Diagnostic diag(loc, DiagnosticSeverity::Remark);
+    reasonCallback(diag);
+    DBGS() << "Match Failure : " << diag.str() << "\n";
+  });
+  return failure();
+}
+
 void transform::TrackingListener::notifyOperationInserted(Operation *op) {
   newOps[op->getName()].insert(op);
 }


        


More information about the Mlir-commits mailing list