[mlir][transform] Dump match failures in TrackingListener
authorMatthias Springer <springerm@google.com>
Wed, 12 Apr 2023 03:54:21 +0000 (12:54 +0900)
committerMatthias Springer <springerm@google.com>
Wed, 12 Apr 2023 04:04:56 +0000 (13:04 +0900)
Differential Revision: https://reviews.llvm.org/D147997

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

index 0443e3a..58e9d85 100644 (file)
@@ -50,6 +50,13 @@ protected:
   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.
index c4f5769..95a004a 100644 (file)
@@ -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);
 }