-
Notifications
You must be signed in to change notification settings - Fork 29
MLIR: Add ReplaceOpAction into DialectConversion and PatternMatch #709
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
base: aie-public
Are you sure you want to change the base?
Conversation
a84528d to
a1da90b
Compare
| /// Find uses of `from` and replace them with `to`. Also notify the listener | ||
| /// about every in-place op modification (for every use that was replaced). | ||
| void replaceAllUsesWith(Value from, Value to) { | ||
| if (auto *fromOp = from.getDefiningOp()) |
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.
Also notify the listener
/// about every in-place op modification (for every use that was replaced).
Was this not up-to-date? Or is an action something else than the listener?
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.
My main question is also whats the difference between an action and a listener
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.
The RewriterBase supports attaching listeners, and the MLIRContext supports action handlers. In this PR, we use the action handlers on the MLIRContext, which allow us to observe across all passes without modifying each.
cferry-AMD
left a comment
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.
replaceAllUsesWith(ValueRange, ValueRange) should also be modified, shouldn't it?
|
cferry-AMD
left a comment
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.
Thanks for the claraifications, that looks good.
|
|
||
| void ReplaceOpAction::print(raw_ostream &os) const { | ||
| OpPrintingFlags flags; | ||
| flags.elideLargeElementsAttrs(10); |
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.
I assume we do not have access to the compiler flags at this point?
| for (auto r : replacement) { | ||
| if (!first) | ||
| os << ", "; | ||
| os << "`"; | ||
| r.print(os, flags); | ||
| os << "`"; | ||
| first = false; | ||
| } |
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.
nit: This could have been written with llvm::interleave, but does not make a big difference
roberteg16
left a comment
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.
Thanks!
| void replaceAllUsesWith(Value from, Value to) { | ||
| if (auto *fromOp = from.getDefiningOp()) | ||
| getContext()->executeAction<ReplaceOpAction>( | ||
| []() {}, ArrayRef<IRUnit>{fromOp}, to); |
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.
| []() {}, ArrayRef<IRUnit>{fromOp}, to); | |
| /*actionFn=*/[]() {}, ArrayRef<IRUnit>{fromOp}, to); |
| bool first = true; | ||
| for (auto r : replacement) { | ||
| if (!first) | ||
| os << ", "; | ||
| os << "`"; | ||
| r.print(os, flags); | ||
| os << "`"; | ||
| first = false; | ||
| } |
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.
Can you use llvm:interleaveComma here?
| if (replace) { | ||
| if (auto *fromOp = from.getDefiningOp()) | ||
| getContext()->executeAction<ReplaceOpAction>( | ||
| []() {}, ArrayRef<IRUnit>{fromOp}, to); |
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.
| []() {}, ArrayRef<IRUnit>{fromOp}, to); | |
| /*actionFn=*/[]() {}, ArrayRef<IRUnit>{fromOp}, to); |
| #include "mlir/IR/BuiltinOps.h" | ||
| #include "llvm/ADT/FunctionExtras.h" | ||
| #include "llvm/Support/TypeName.h" | ||
| #include <mlir/IR/PatternMatchAction.h> |
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.
I believe mlir project prefers "" for internal headers
| #include <mlir/IR/PatternMatchAction.h> | |
| #include "mlir/IR/PatternMatchAction.h" |
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.
Thanks Robert, TIL :)
Add action to enable listener for
RewriterBase::replaceOp,RewriterBase::replaceAllUsesWithand friends.