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

cranelift: Remove the virtual sp offset from all backends #8631

Merged

Conversation

elliottt
Copy link
Member

@elliottt elliottt commented May 15, 2024

After the changes required to support tail calls, the general frame layout in cranelift always includes a stack allocation that's large enough to hold all outgoing args/return values. An effect of this change is that the only place that the virtual SP offset (the offset from the current value of SP to the nominal SP) was meaningfully changed was in the function prologue, where it was always updated to include the size of the outgoing argument area. As the only other place that the virtual SP offset was modified was in the handling for call instructions to functions that used the tail-call abi, the need for the virtual SP offset is no longer obvious.

This PR removes the virtual SP offset from all backends, and instead maintains the invariant that SP always points to the end of the stack frame, right after the outgoing arguments area. This does require the call pseudo-instruction to decrement SP after a call to a tail-call function, as those free their incoming argument area, but I believe this change to be a benefit as we now no longer directly manipulate SP outside of the function prologue and epilogue.

Looking forward a bit, another benefit of this change is that it better sets us up to handle compiling without frame pointers: as SP is now a consistent base that we can address anything in the frame from, we're no longer reliant on FP to address some parts of the frame.

@elliottt elliottt requested a review from a team as a code owner May 15, 2024 22:07
@elliottt elliottt requested review from cfallin and removed request for a team May 15, 2024 22:07
@elliottt elliottt force-pushed the trevor/remove-virtual-sp-offset branch from 13ab189 to 1e4c6f2 Compare May 15, 2024 23:30
@elliottt elliottt force-pushed the trevor/remove-virtual-sp-offset branch from 1e4c6f2 to 4cb4394 Compare May 15, 2024 23:31
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen labels May 16, 2024
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Excellent simplification, thanks!

cranelift/codegen/src/isa/x64/inst/emit.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/machinst/abi.rs Outdated Show resolved Hide resolved
@elliottt elliottt added this pull request to the merge queue May 16, 2024
Merged via the queue into bytecodealliance:main with commit 54e53cc May 16, 2024
65 checks passed
@elliottt elliottt deleted the trevor/remove-virtual-sp-offset branch May 16, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants