From ea2d2d10ee1ed62c450871c62a3c587343a6ea25 Mon Sep 17 00:00:00 2001 From: Matthias Springer Date: Wed, 12 Apr 2023 12:54:21 +0900 Subject: [PATCH] [mlir][transform] Dump match failures in TrackingListener Differential Revision: https://reviews.llvm.org/D147997 --- mlir/include/mlir/Dialect/Transform/IR/TransformOps.h | 7 +++++++ mlir/lib/Dialect/Transform/IR/TransformOps.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/mlir/include/mlir/Dialect/Transform/IR/TransformOps.h b/mlir/include/mlir/Dialect/Transform/IR/TransformOps.h index 0443e3a..58e9d85 100644 --- a/mlir/include/mlir/Dialect/Transform/IR/TransformOps.h +++ b/mlir/include/mlir/Dialect/Transform/IR/TransformOps.h @@ -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 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 c4f5769..95a004a 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 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); } -- 2.7.4