Skip to content

Implement passing arguments by ref for win64 ABI #1670

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

Merged
merged 1 commit into from
Jun 1, 2020

Conversation

teapotd
Copy link
Contributor

@teapotd teapotd commented May 7, 2020

This PR goes on top of #1510 and fixes legalization of function arguments in win64 ABI - arguments larger than pointer width are passed by reference. Fixes #1651.

@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label May 7, 2020
@github-actions
Copy link

github-actions bot commented May 7, 2020

Subscribe to Label Action

cc @bnjbvr

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.

@@ -156,6 +156,8 @@ pub struct AbiParam {
/// ABI-specific location of this argument, or `Unassigned` for arguments that have not yet
/// been legalized.
pub location: ArgumentLoc,
/// Was the argument converted to pointer during legalization?
pub legalized_to_pointer: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should instead be a new variant of ArgumentLoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I implemented the change of value into pointer as a new ValueConversion, like splitting or zero-extending, so it's separate from argument location. In case of passing-by-ref, location specifies how pointer (not the original value) should be passed - register or stack. For example legalization of i128 argument for win64 goes as follows:

  1. We start with i128
  2. First pass: i128 is converted to pointer of type i64
  3. Second pass: Now argument has type i64, so we assign register or stack location

As far as I can see the signature legalization just changes argument types without saving information how to convert them and it is later recovered during legalization of calls/entry block params (legalize_abi_value). I introduced legalized_to_pointer flag to be able to detect it has been converted to pointer (and not split, for example).

Copy link
Contributor

@bjorn3 bjorn3 May 7, 2020

Choose a reason for hiding this comment

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

For (i64, i64, i64, i64, i128) is the i128 still passed as a pointer, and then the pointer is stored on the stack at a fixed offset like a normal argument that doesn't fit in a register anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@teapotd teapotd force-pushed the win64-pass-by-ref branch 2 times, most recently from 4796bcf to 9962084 Compare May 25, 2020 18:59
@teapotd teapotd force-pushed the win64-pass-by-ref branch from 9962084 to aa1ae77 Compare May 29, 2020 17:09
@teapotd
Copy link
Contributor Author

teapotd commented May 29, 2020

#1510 just got merged, I rebased this PR so it contains 1 commit.

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Looks good, but a nitpick and a question inline below. Thanks!

@teapotd teapotd force-pushed the win64-pass-by-ref branch from aa1ae77 to 759cc3e Compare May 29, 2020 18:12
@teapotd teapotd requested a review from fitzgen May 29, 2020 18:18
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

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

Thanks!

@teapotd
Copy link
Contributor Author

teapotd commented May 30, 2020

Seems like there were some issues with MacOS CI.

@fitzgen
Copy link
Member

fitzgen commented Jun 1, 2020

Seems like there were some issues with MacOS CI.

Re-running the CI jobs, hopefully that will clear them up.

@fitzgen
Copy link
Member

fitzgen commented Jun 1, 2020

Re-running the CI jobs, hopefully that will clear them up.

It looks like the re-run CI jobs are green, but the cancelled ones are still making the whole thing show up as not passing. Pretty sure this is a github actions bug. I'm going to just merge this.

@fitzgen fitzgen merged commit 7c68a10 into bytecodealliance:master Jun 1, 2020
@teapotd teapotd deleted the win64-pass-by-ref branch June 2, 2020 00:18
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
Development

Successfully merging this pull request may close these issues.

Cranelift: implement passing arguments by ref in win64 ABI
3 participants