diff --git a/mlir/include/mlir/IR/PatternMatch.h b/mlir/include/mlir/IR/PatternMatch.h --- a/mlir/include/mlir/IR/PatternMatch.h +++ b/mlir/include/mlir/IR/PatternMatch.h @@ -322,10 +322,15 @@ /// why the failure occurred. This method allows for derived rewriters to /// optionally hook into the reason why a pattern failed, and display it to /// users. - virtual LogicalResult - notifyMatchFailure(Operation *op, - function_ref reasonCallback) { + template + std::enable_if_t::value, LogicalResult> + notifyMatchFailure(Operation *op, CallbackT &&reasonCallback) { +#ifndef NDEBUG + return notifyMatchFailure(op, + function_ref(reasonCallback)); +#else return failure(); +#endif } LogicalResult notifyMatchFailure(Operation *op, const Twine &msg) { return notifyMatchFailure(op, [&](Diagnostic &diag) { diag << msg; }); @@ -351,6 +356,17 @@ /// uses. virtual void notifyOperationRemoved(Operation *op) {} + /// Notify the pattern rewriter that the pattern is failing to match the given + /// operation, and provide a callback to populate a diagnostic with the reason + /// why the failure occurred. This method allows for derived rewriters to + /// optionally hook into the reason why a pattern failed, and display it to + /// users. + virtual LogicalResult + notifyMatchFailure(Operation *op, + function_ref reasonCallback) { + return failure(); + } + private: /// 'op' and 'newOp' are known to have the same number of results, replace the /// uses of op with uses of newOp.