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

[SOL] Optimize call convention in SBFv2 #94

Merged

Conversation

LucasSte
Copy link
Collaborator

@LucasSte LucasSte commented Mar 25, 2024

Problem

SBFv2 introduces dynamic frame sizes without stack gaps, so that we know during compile time the frame size for a function. As a consequence, the call convention inherited from SBFv1 in #84 becomes inefficient.

If there are more than five arguments in a function call in the old convention, we do:

  1. Store four arguments in the registers.
  2. Store the remaining arguments in the caller's frame, starting at the frame's higher address.
  3. Copy the frame pointer to R5: mov r5, r10
  4. Access the arguments in the callee using R5.

We are clobbering R5 unnecessarily in this scheme.

Solution

This PR introduces a new call convention for SBFv2, leveraging the dynamic stack frames.

In the new convention, we do the following:

  1. Store five arguments in the registers (from r1 to r5).
  2. Store the remaining arguments in the callee's frame, starting at the higher address.
  3. Access the arguments in the callee using the frame pointer R10.

In this case, we free up one general purpose register and reduce one load and one store from function calls.

@LucasSte LucasSte changed the title Optmize call convention in SBFv2 Optimize call convention in SBFv2 Mar 25, 2024
@LucasSte LucasSte changed the title Optimize call convention in SBFv2 [SOL] Optimize call convention in SBFv2 Mar 25, 2024
@LucasSte LucasSte marked this pull request as ready for review March 26, 2024 14:04
Copy link

@dmakarov dmakarov left a comment

Choose a reason for hiding this comment

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

LGTM

@LucasSte LucasSte merged commit 3f884d3 into anza-xyz:solana-rustc/17.0-2023-12-14 Mar 27, 2024
14 checks passed
@LucasSte LucasSte deleted the opt-call-conv branch March 27, 2024 12:59
LucasSte added a commit to LucasSte/llvm-project that referenced this pull request Jun 28, 2024
LucasSte added a commit that referenced this pull request Aug 19, 2024
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.

2 participants