Skip to content

Cranelift: Fix FPR saving and shadow space allocation for Windows x64.#1734

Merged
peterhuene merged 4 commits intobytecodealliance:masterfrom
peterhuene:fix-saved-fprs
May 22, 2020
Merged

Cranelift: Fix FPR saving and shadow space allocation for Windows x64.#1734
peterhuene merged 4 commits intobytecodealliance:masterfrom
peterhuene:fix-saved-fprs

Conversation

@peterhuene
Copy link
Member

This PR fixes both how FPR callee-saved registers are saved and how the
shadow space allocation occurs when laying out the stack for Windows x64
calling convention.

Importantly, this PR removes the compiler limitation of stack size for
Windows x64 that was imposed because FPR saves previously couldn't always be
represented in the unwind information.

The FPR saves are now performed without using stack slots, much like how the
callee-saved GPRs are saved. The total CSR space is given to layout_stack so
that it is included in the frame size and to offset the layout of spills and
explicit slots.

The FPR saves are now done via an RSP offset (post adjustment) and they always
follow the GPR saves on the stack. A simpler calculation can now be made to
determine the proper offsets of the FPR saves for representing the unwind
information.

Additionally, the shadow space is no longer treated as an incoming argument,
but an explicit stack slot that gets laid out at the lowest address possible in
the local frame. This prevents layout_stack from putting a spill or explicit
slot in this reserved space. In the future, layout_stack should take
advantage of the caller-provided shadow space for spills, but this PR does
not attempt to address that.

The shadow space is now omitted from the local frame for leaf functions.

Fixes #1728.
Fixes #1587.
Fixes #1475.

This commit fixes both how FPR callee-saved registers are saved and how the
shadow space allocation occurs when laying out the stack for Windows x64
calling convention.

Importantly, this commit removes the compiler limitation of stack size for
Windows x64 that was imposed because FPR saves previously couldn't always be
represented in the unwind information.

The FPR saves are now performed without using stack slots, much like how the
callee-saved GPRs are saved. The total CSR space is given to `layout_stack` so
that it is included in the frame size and to offset the layout of spills and
explicit slots.

The FPR saves are now done via an RSP offset (post adjustment) and they always
follow the GPR saves on the stack. A simpler calculation can now be made to
determine the proper offsets of the FPR saves for representing the unwind
information.

Additionally, the shadow space is no longer treated as an incoming argument,
but an explicit stack slot that gets laid out at the lowest address possible in
the local frame. This prevents `layout_stack` from putting a spill or explicit
slot in this reserved space. In the future, `layout_stack` should take
advantage of the *caller-provided* shadow space for spills, but this commit does
not attempt to address that.

The shadow space is now omitted from the local frame for leaf functions.

Fixes bytecodealliance#1728.
Fixes bytecodealliance#1587.
Fixes bytecodealliance#1475.
@peterhuene peterhuene requested review from bnjbvr and iximeow May 20, 2020 22:39
@peterhuene peterhuene added the cranelift Issues related to the Cranelift code generator label May 20, 2020
@peterhuene
Copy link
Member Author

See this comment for a "before and after" codegen.

@github-actions
Copy link

Subscribe to Label Action

cc @bnjbvr

Details This issue or pull request has been labeled: "cranelift"

Thus the following users have been cc'd because of the following labels:

  • bnjbvr: cranelift

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Contributor

@iximeow iximeow 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 great, thank you! Taking sp as an argument to avoid dealing with stack slots is a good idea, wish I thought of it :)

"requesting changes" because I left a few thoughts about alignment details particularly for non-64bit platforms. I'm also not sure if those platforms have callee-save FPRs in the first place, so it might be an academic concern. Either way, that's my only hesitance towards approving.

@alexcrichton
Copy link
Member

I think that this may be all that's necessary to remove this ignore block as well perhaps?

@peterhuene
Copy link
Member Author

Good catch! I forgot we had disabled tests because of this issue. I'll re-enable.

Copy link
Contributor

@iximeow iximeow left a comment

Choose a reason for hiding this comment

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

Thank you! (modulo happy CI run)

This commit prevents updating the XMM save unwind operation offsets when a
frame pointer is not used, even though currently Cranelift always uses a
frame pointer.

This will prevent incorrect unwind information in the future when we start
omitting frame pointers.
@peterhuene
Copy link
Member Author

@bnjbvr would you mind reviewing or suggesting a reviewer from cranelift core? Thanks!

@peterhuene
Copy link
Member Author

After discussing with Dan, I'm proceeding with merging this with @iximeow's sign-off.

@peterhuene peterhuene merged commit f365391 into bytecodealliance:master May 22, 2020
@peterhuene peterhuene deleted the fix-saved-fprs branch May 22, 2020 19:06
@bnjbvr
Copy link
Member

bnjbvr commented May 26, 2020

Oops, sorry I didn't see this among the github-bot mentions; I entirely trust @iximeow's reviews when it comes to Cranelift, for what it's worth :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator

Projects

None yet

4 participants