[WIP] Reify unstructured control-flow into thunk values.#39
Draft
eddyb wants to merge 7 commits intoeddyb/structurize-noretfrom
Draft
[WIP] Reify unstructured control-flow into thunk values.#39eddyb wants to merge 7 commits intoeddyb/structurize-noretfrom
thunk values.#39eddyb wants to merge 7 commits intoeddyb/structurize-noretfrom
Conversation
…a new kind of `thunk` "value".
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
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.
Note: this PR is a draft to avoid accidental merging onto its "base" branch (used as a form of ad-hoc PR stacking), and will remain as such, until its "base" branch can be set to
main, i.e. all prerequisite PRs will have landed, up to and including this PR (whose branch is the "base" of this one):Before this PR,
cf::unstructured::ControlFlowGraphcontained an ad-hoc CFG, by attaching aControlInstto eachRegion(as its "terminator") participating in the unstructured control-flow graph.This PR starts to move more of that information into the structured side of SPIR-T, introducing the concept of a
thunk, which encapsulates an unstructured destination, and necessary inputs, into oneValue(akin to high-level closures, or more specifically CPS-style "continuations"), where the type is alwaysthunk(hiding any details).While such a high-level-looking feature seems out of place, these
thunks:For example, a
ControlInstKind::SelectBranchbetween targetsL3(v1)andL5(v1, v2), now becomes:(some of this verbosity could be cleaned up, in general, in SPIR-T pretty-printing, but I wanted to be explicit here)
This encoding, if allowed to be used a bit more dynamically, also mirrors the worst-case structurization needs to handle: a reified destination and inputs for all possible destination choices. Long-term,
thunks may allow a more "local" definition of structurization, as reducing the use ofthunks where possible, and encoding the remainingthunks almost like a Rustenumbeing constructed and then pattern-matched on.The original motivation for attempting this refactor, interestingly enough, would involve writing
thunks to memory (an emulated stack, for a form of CPS-based recursion/indirect-call emulation), but a specific design which allows both the "unstructured CFG", and said stackful CPS usecase, has yet to be finalized.TODO: better documentation, consider implementing the
thunkswitch/loop-switchdescribed in comments (seesrc/cf/unstructured.rs, the long// FIXME(eddyb)comment abovestruct ControlFlowGraph).