-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[mlir][core] Add an MLIR "pattern catalog" generator #146228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7335db1
85d6e9a
0c86b84
5d4cfdd
182eafb
5fb5dea
66a94cb
79688e2
0915b0b
a46f1d3
1aa1842
ed693d8
0f07799
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OOC why does with op vs value matter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 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" |
||
<< " | " << op->getName() << " | " << newOp->getName()); | ||
ForwardingListener::notifyOperationReplaced(op, newOp); | ||
} | ||
|
||
void RewriterBase::PatternLoggingListener::notifyOperationReplaced( | ||
Operation *op, ValueRange replacement) { | ||
LDBG(patternName << " | notifyOperationReplaced (with values)" | ||
<< " | " << op->getName()); | ||
ForwardingListener::notifyOperationReplaced(op, replacement); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So all of these may end up with duplicate notifications (e.g., a pattern could insert the same op 10 times and this would report 10 times), and so that would be handled by post-processing? (I think also conditional emission, would just be squashed right, so would end up with union of all that pattern can do) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the postprocessing includes |
||
} | ||
|
||
void RewriterBase::PatternLoggingListener::notifyOperationErased( | ||
Operation *op) { | ||
LDBG(patternName << " | notifyOperationErased" | ||
<< " | " << op->getName()); | ||
ForwardingListener::notifyOperationErased(op); | ||
} | ||
|
||
void RewriterBase::PatternLoggingListener::notifyPatternBegin( | ||
const Pattern &pattern, Operation *op) { | ||
LDBG(patternName << " | notifyPatternBegin" | ||
<< " | " << op->getName()); | ||
ForwardingListener::notifyPatternBegin(pattern, op); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// RUN: mlir-opt %s --test-walk-pattern-rewrite-driver \ | ||
// RUN: --allow-unregistered-dialect --debug-only=pattern-logging-listener 2>&1 | FileCheck %s | ||
|
||
// Check that when replacing an op with a new op, we get appropriate | ||
// pattern-logging lines. The regex is because the anonymous namespace is | ||
// printed differently on different platforms. | ||
|
||
// CHECK: [pattern-logging-listener] {{.anonymous.namespace.}}::ReplaceWithNewOp | notifyOperationInserted | test.new_op | ||
// CHECK: [pattern-logging-listener] {{.anonymous.namespace.}}::ReplaceWithNewOp | notifyOperationReplaced (with values) | test.replace_with_new_op | ||
// CHECK: [pattern-logging-listener] {{.anonymous.namespace.}}::ReplaceWithNewOp | notifyOperationModified | arith.addi | ||
// CHECK: [pattern-logging-listener] {{.anonymous.namespace.}}::ReplaceWithNewOp | notifyOperationModified | arith.addi | ||
// CHECK: [pattern-logging-listener] {{.anonymous.namespace.}}::ReplaceWithNewOp | notifyOperationErased | test.replace_with_new_op | ||
func.func @replace_with_new_op() -> i32 { | ||
%a = "test.replace_with_new_op"() : () -> (i32) | ||
%res = arith.addi %a, %a : i32 | ||
return %res : i32 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, funnily was working on a general utility that does such logging as I ended up writing it often :)