Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

gabrielrodcanal
Copy link
Contributor

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?

@gabrielrodcanal gabrielrodcanal marked this pull request as draft October 30, 2024 21:13
xdsl/ir/core.py Outdated Show resolved Hide resolved
Comment on lines +980 to +985
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()
Copy link
Member

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
Comment on lines 1438 to 1442
def successors(self) -> tuple[Block, ...]:
terminator = list(self.ops)[-1]
return tuple(
successor for successor in terminator.successors
)
Copy link
Member

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

Copy link
Member

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

@superlopuh
Copy link
Member

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?

Copy link

codecov bot commented Oct 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.11%. Comparing base (e6c7282) to head (190ffb1).

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.
📢 Have feedback on the report? Share it here.

@gabrielrodcanal
Copy link
Contributor Author

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?

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 test-print-liveness as you can see in https://github.com/llvm/llvm-project/blob/98e674c9f16d677d95c67bc130e267fae331e43c/mlir/test/Analysis/test-liveness.mlir

I agree it'd be best to have several PRs with the helpers. I'll try to do that in the following days

@gabrielrodcanal gabrielrodcanal added the enhancement New feature or request label Oct 31, 2024
@gabrielrodcanal
Copy link
Contributor Author

Added PR for the preorder walker #3367

@gabrielrodcanal gabrielrodcanal marked this pull request as ready for review November 1, 2024 02:33
@compor compor self-requested a review November 13, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants