-
Notifications
You must be signed in to change notification settings - Fork 71
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
analysis: (liveness) Port of the liveness analysis in MLIR. #3365
base: main
Are you sure you want to change the base?
Conversation
def walk_blocks_preorder(self) -> Iterator[Block]: | ||
for region in self.regions: | ||
for block in region.blocks: | ||
yield block | ||
for op in block.ops: | ||
yield from op.walk_blocks_preorder() |
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 would be great in its own PR with a separate unit test
xdsl/ir/core.py
Outdated
def successors(self) -> tuple[Block, ...]: | ||
terminator = list(self.ops)[-1] | ||
return tuple( | ||
successor for successor in terminator.successors | ||
) |
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.
does this deserve a helper? If so, I would strongly recommend against creating a list only to get its last element, self.last_op
will do the same avoiding the O(n) list creation
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 better in own PR with small unit test
This is great! I'd love to have this in. It would be great to split this PR into many smaller PRs, hopefully independent of each other to start with, to merge the helpers in this one before getting to the liveness analysis. Where is this in MLIR? Is it also a pass? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3365 +/- ##
========================================
Coverage 90.10% 90.11%
========================================
Files 449 450 +1
Lines 56599 56893 +294
Branches 5429 5490 +61
========================================
+ Hits 51001 51270 +269
- Misses 4164 4186 +22
- Partials 1434 1437 +3 ☔ View full report in Codecov by Sentry. |
You can find the liveness analysis in MLIR in https://github.com/llvm/llvm-project/blob/main/mlir/lib/Analysis/Liveness.cpp. So it's a pass, just not a transformation pass. That's why I wasn't sure where to place it in xDSL! The analysis is run with the option I agree it'd be best to have several PRs with the helpers. I'll try to do that in the following days |
Added PR for the preorder walker #3367 |
Port of the liveness analysis in MLIR: https://github.com/llvm/llvm-project/blob/main/mlir/lib/Analysis/Liveness.cpp
It passes the tests provided in https://github.com/llvm/llvm-project/blob/98e674c9f16d677d95c67bc130e267fae331e43c/mlir/test/Analysis/test-liveness.mlir
Note that this corresponds to commit 98e674c9f16d677d95c67bc130e267fae331e43c of LLVM, whereas xDSL now is up to date with d401987fe349a87c53fe25829215b080b70c0c1a. I'm happy to update this port to the new version if necessary (there is only one extra test that was added with the newer commit).
There are a few functions that had to be added in core xDSL to support the liveness analysis. Pre order walking was one of them that might need testing. Please, let me know if I should open a separate PR with these changes and corresponding tests before accepting this PR.
Finally, I placed the analysis under transforms for now, but I don't think it's the right place for it. Suggestions?