-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[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
Open
j2kun
wants to merge
12
commits into
llvm:main
Choose a base branch
from
j2kun:pattern-discovery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+110
−2
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7335db1
Add an MLIR "pattern catalog" generator.
j2kun 85d6e9a
remove use of RTTI
j2kun 0c86b84
remove mutex/file writes in favor of toolsubst+llvm::dbgs
j2kun 5d4cfdd
add debug log marker for ease of filtering
j2kun 182eafb
formatting
j2kun 5fb5dea
Apply RAII
j2kun 66a94cb
Remove need for post set-listener with RAII
j2kun 79688e2
formatting
j2kun 0915b0b
rename to PatternLoggingListener
j2kun a46f1d3
rename catalogingListener -> loggingListener
j2kun 1aa1842
use LDBG macro for brevity
j2kun ed693d8
add lit test
j2kun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
<< " | " << 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); | ||
} | ||
|
||
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); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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 | ||
// 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 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How does the FileCheck substitution relates to the catalog environment? Is this because some tests are redirecting stderr and you're using this to preserve the debug output?
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.
This and for future proofing against such trickery. I didn't do a detailed analysis of which tests redirect stderr (i.e., if many involve the rewrite engine), but many tests do and so it seems acceptable to account for this.