Skip to content

aarch64: emit SP copies when SP is involved in an explicit add during address lowering #1586

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 3 commits into from
Apr 24, 2020

Conversation

bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Apr 23, 2020

and use explicit address lowering for passing stack arguments to calls, when the offset is large.

One question is: what Inst should cause a move from SP to another register? I preferred to keep the "high-level" semantics of Inst::Mov, instead of relying on every producer to produce an Inst::Add { rd, sp, 0 }. This means we have to modify the codegen of Inst::Mov when SP is involved, but it seemed like fine blackboxing.

The PR as a whole is a bit messy. I was wondering if gen_copy_reg_to_arg shouldn't just take the ctx argument, but then type parameters were involved, making the trait more contrived. I didn't look into it, it might be the right thing to do in the future (otherwise this aarch64 impl detail leaks into the general interface, which is bad).

Good thing is that thanks to many new assertions, error like this one should be more easily caught in the future.

cc @julian-seward1 because I was hitting an assertion in regalloc if I didn't include the change in is_move: assert!(iix_bounds.uses_len == 1); (backtracking.rs:572). That happens during coalescing; I checked and the value was 0, instead of the expected 1. I don't think the change in is_move ought to be correct, so it'd be nice to see if there's something else to do to fix this.

@bnjbvr bnjbvr requested a review from cfallin April 23, 2020 17:37
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:aarch64 Issues related to AArch64 backend. labels Apr 23, 2020
@github-actions
Copy link

Subscribe to Label Action

cc @bnjbvr

This issue or pull request has been labeled: "cranelift", "cranelift:area:aarch64"

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
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.

Thanks for this! As mentioned below, I'm happy to clean up the design a bit to not require these temporaries afterward; don't want to block our correctness push on account of it, though. Good to go after a small comment tweak below.

&self,
idx: usize,
from_reg: Reg,
tmp1: Writable<Reg>,
Copy link
Member

Choose a reason for hiding this comment

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

Hmm. I don't want to block this PR on it, but I'm thinking we should really clean up the ABI traits to take a LowerCtx and just emit instructions and allocate temps as needed directly, as you suggested above. @alexcrichton hit a similar issue with is stack-check PR (#1573). It's my design flaw originally (sorry!) so I can take this as a followup item once that PR and this one land.

Copy link
Member Author

Choose a reason for hiding this comment

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

I looked into this, and I could make it work as discussed, but it puts the type parameter down to the implementation of store_stack_sp, which is unfortunate. Maybe we could revisit this later, and instead manually monomorphize the LowerCtx trait into its own impl Lower.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, indeed; I want to try to keep things parameterized on the Lower trait (and not simplify to just the one impl) because it gives us flexibility later to e.g. be generic over multiple input IRs. This seems fine for now, I think.

@bnjbvr
Copy link
Member Author

bnjbvr commented Apr 24, 2020

Thanks for the review! (Three more tests passing in wasmtime, yay!)

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.

The new version looks good, thanks!

I had been worried after commenting yesterday that it might not actually work to parameterize on LowerCtx in ABICall, because trait methods can't be generic; but that restriction only applies for dynamically-dispatched traits, namely the "object safety" rules, and we only statically monomorphize on ABICall (ABIBody on the other hand is held as dyn in a Box) so we just squeaked by, here.

@cfallin cfallin merged commit c756078 into bytecodealliance:master Apr 24, 2020
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 Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants