[Mlir-commits] [llvm] [mlir] [mlir][core] Add an MLIR "pattern catalog" generator (PR #146228)

Jeremy Kun llvmlistbot at llvm.org
Thu Jul 17 09:07:16 PDT 2025


================
@@ -0,0 +1,50 @@
+#include "mlir/IR/PatternMatch.h"
+#include "llvm/Support/Debug.h"
+
+#define DEBUG_TYPE "pattern-logging-listener"
+#define DBGS() (llvm::dbgs() << "[" << DEBUG_TYPE << "] ")
+#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
+
+using namespace mlir;
+
+void RewriterBase::PatternLoggingListener::notifyOperationInserted(
+    Operation *op, InsertPoint previous) {
+  LDBG(patternName << " | notifyOperationInserted"
+                   << " | " << op->getName());
+  ForwardingListener::notifyOperationInserted(op, previous);
+}
+
+void RewriterBase::PatternLoggingListener::notifyOperationModified(
+    Operation *op) {
+  LDBG(patternName << " | notifyOperationModified"
+                   << " | " << op->getName());
+  ForwardingListener::notifyOperationModified(op);
+}
+
+void RewriterBase::PatternLoggingListener::notifyOperationReplaced(
+    Operation *op, Operation *newOp) {
+  LDBG(patternName << " | notifyOperationReplaced (with op)"
----------------
j2kun wrote:

I was hoping originally to be able to query for a source and target op, but then I found that almost all upstream patterns replace an op with values rather than calling `replaceOpWithNewOp` (even when `replaceOp` is given an operation, it is cast to the results and the notification hook is treated as replacing with values).

I'm not sure what to do with this in the end: keep it and expose it in the search, or just treat "operation replaced" as if it is "operation erased"

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


More information about the Mlir-commits mailing list