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

Move down the stack check if possible #2373

Merged
merged 26 commits into from
Apr 12, 2024
Merged

Move down the stack check if possible #2373

merged 26 commits into from
Apr 12, 2024

Conversation

xclerc
Copy link
Contributor

@xclerc xclerc commented Mar 19, 2024

This pull request changes the logic behind the
insertion of the stack check. Instead of always
emitting it at the top of the function, we try to
"push it down" so that it is executed only when
necessary.

In order to determine where to emit the check, we:

  • determine the set of CFG block that must only
    be executed after the check;
  • for each node of the dominator tree compute
    the number of nodes in the subtree that need
    the check;
  • select the block for the stack check as the root
    of the smallest subtree that contains all block
    that must only be executed after the check.

The new beahviour is controlled by a command-line
flag, namely -cfg-stack-checks, and disabled by
default.

@xclerc xclerc marked this pull request as draft March 19, 2024 10:34
@xclerc
Copy link
Contributor Author

xclerc commented Mar 19, 2024

(As noted offline by @stedolan, it would
make sense to also move the prologue.)

@xclerc xclerc marked this pull request as ready for review March 19, 2024 12:52
@xclerc xclerc force-pushed the stack-check-explicit-instruction branch from bc4ab1d to 334e55f Compare March 25, 2024 10:34
@mshinwell mshinwell self-requested a review April 2, 2024 10:08
@xclerc xclerc force-pushed the stack-check-cfg branch from c6f0154 to 5553e47 Compare April 8, 2024 13:00
Base automatically changed from stack-check-explicit-instruction to main April 12, 2024 10:07
Copy link
Collaborator

@mshinwell mshinwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok to merge once the Specific_can_raise match has been made exhaustive, and maybe "is a non-tail call" moved into Cfg itself, as discussed elsewhere.

@xclerc xclerc merged commit b91dd49 into main Apr 12, 2024
17 checks passed
@xclerc xclerc deleted the stack-check-cfg branch April 12, 2024 13:29
Forestryks pushed a commit to Forestryks/flambda-backend that referenced this pull request Apr 17, 2024
samsa1 pushed a commit to samsa1/flambda-backend that referenced this pull request Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants