-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: initial draft of control flow lifting transform #399
Draft
bitwalker
wants to merge
18
commits into
next
Choose a base branch
from
bitwalker/cfg-to-scf
base: next
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.
Conversation
This file contains 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
greenhat
approved these changes
Feb 14, 2025
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.
LGTM!
eacba9f
to
739adc5
Compare
This commit implements a generic control flow lifting transformation framework, and an implementation of it for the HIR dialect. The tranform converts unstructured control flow operations to structured control flow ops, e.g. `hir.cond_br` to `hir.if`. This includes complex control flow such as loops with loop-carried variables, reduce-style loops, etc. Not all control flow is guaranteed to be lifted however. Currently, the primary limitation is that all return-like operations in a region must be equivalent (i.e. the same operation type), otherwise some control flow will be left unstructured. For now, on the backend, this will result in a legalization error, as we do not have lowerings for unstructured control flow ops at this time. In the future we plan to lower directly to structured control flow, so this is more of a temporary solution for us anyway; but may also be useful for other compiler frontends.
This fixes an issue with the pass manager, which expects the fully-qualified name of an op.
…ts are implemented
739adc5
to
23a8f4c
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR implements a generic control flow lifting transformation framework, and an implementation of it for the HIR dialect.
The tranform converts unstructured control flow operations to structured control flow ops, e.g.
hir.cond_br
tohir.if
. This includes complex control flow such as loops with loop-carried variables, reduce-style loops, etc.Not all control flow is guaranteed to be lifted however. Currently, the primary limitation is that all return-like operations in a region must be equivalent (i.e. the same operation type), otherwise some control flow will be left unstructured.
For now, on the backend, this will result in a legalization error, as we do not have lowerings for unstructured control flow ops at this time. In the future we plan to lower directly to structured control flow, so this is more of a temporary solution for us anyway; but may also be useful for other compiler frontends.
@greenhat This is marked as a draft until I've finished testing and working out any kinks. I'll add the commit with the pipeline once that is ready. Fair warning, a lot of the code here is pretty rough, as it is pretty directly translated from C++ and I didn't have much time to spend re-architecting it to be as Rust-y as I'd like. Since long term we aim to lower directly to structured control flow anyway, I don't actually care all that much for now, but we may have to come back and clean this up at some point.