mirflow: make optimization algorithm non-recursive#1675
Open
zerbina wants to merge 4 commits intonim-works:develfrom
Open
mirflow: make optimization algorithm non-recursive#1675zerbina wants to merge 4 commits intonim-works:develfrom
zerbina wants to merge 4 commits intonim-works:develfrom
Conversation
Reordering the fields achieves a size of 24 byte on a 64-bit architecture, compared to the 32 byte the type required previously.
The tree structure the statement list may form can get very deeply nested, especially when high-level case statements with many branches are involved, which can lead to stack overflow or exceeding the maximum recursion depth. Folding is now done without recursion and as part of constructing the block structures, which also gets rid of the having to do a separate pass over the list.
Only breaks in dispatcher targets are considered right now, as those are the source of the most egregious tree nesting.
The statement is a terminator too, so the block folding and continuation inlining needs to know also needs to know about it.
Collaborator
Author
|
Changing As for the CI failure, the C code generator currently emits code that relies on C compiler extensions or C23 (i.e., declarations immediately following a label), and the clang used by the macOS CI seems to be rather strict. I'll make a separate PR for fixing this. |
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.
Summary
Change the space optimization applied to the internal, structured
control-flow representation used in the code generator to use a non-
recursive approach.
Details
mirflow.Stmtin order to reduce the type'srequired space (24 byte vs. 32 byte, on a 64-bit architecture)
the recursive post-processing
blockcontinuations into dispatcher targets
continue,so that the latter is visible as a terminator to statement analysis
The optimization pass eliminates deep nesting when there are
casestatements with many branches, though it's unable to fully optimize the
hash-table lookup generated for
casestatements overstringvalues.Processing of the structure control-flow representation in
mir2cgstill uses recursion, meaning that its still susceptible to stack
overflow when the structures are very nested.
Notes for Reviewers
thtmlparser.nimnot compiling with a debug compiler