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

Detect block cycles using stackalloc op #3416

Conversation

WojciechMazur
Copy link
Contributor

Detect block cycles using stackalloc to improve stack memory managment of inlined, potentially looped functions.
Previously, we've emitted a StackSave/Restore LLVM intrinnsics every time inlined code contained Op.Stackalloc instructions. These however where not required, when inlined code, was never part of a loop. Also in the past multiple subsequent inlines created multiple StackSave/Restore instructions leading to potentiall performance penalty.

This change adds detection of cycles and stackallocation in MergeBlocks. Based on them we create exactly 1 StackSave operation at the entry of the loop, and exactly 1 StackRestore before each jump to block marked as start of loop.

@WojciechMazur WojciechMazur marked this pull request as ready for review August 7, 2023 13:21
@WojciechMazur WojciechMazur merged commit 3273166 into scala-native:main Aug 9, 2023
79 checks passed
@WojciechMazur WojciechMazur deleted the inline/check-when-reset-stackalloc branch August 9, 2023 19:47
WojciechMazur added a commit to WojciechMazur/scala-native that referenced this pull request Sep 1, 2023
* Detect block cycles using stackalloc to improve stack memory managment of inlined, potentially looped functions
* Fix issue with reseting state upon assigning memory to variable and though escaping the loop.
* Ensure the stackrestore target exists. Fixes issues found in release mode

(cherry picked from commit 3273166)
WojciechMazur added a commit that referenced this pull request Sep 4, 2023
* Detect block cycles using stackalloc to improve stack memory managment of inlined, potentially looped functions
* Fix issue with reseting state upon assigning memory to variable and though escaping the loop.
* Ensure the stackrestore target exists. Fixes issues found in release mode

(cherry picked from commit 3273166)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant