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 ABICallee trait #4701

Merged
merged 5 commits into from
Aug 15, 2022

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Aug 12, 2022

No description provided.

@fitzgen fitzgen requested a review from cfallin August 12, 2022 00:02
@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 Aug 12, 2022
Copy link
Contributor

@jameysharp jameysharp left a comment

Choose a reason for hiding this comment

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

Always nice to not only get rid of dynamic dispatch but also heap indirection! This is cool.

I spotted a couple comments that could use a little help, but this looks good to me. I assume Chris should still take a look though.

Naming conventions are hard. AbiCallee looks weird to me. But 🤷

cranelift/codegen/src/machinst/abi.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/machinst/abi_impl.rs Show resolved Hide resolved
cranelift/codegen/src/machinst/abi_impl.rs Outdated Show resolved Hide resolved
cranelift/codegen/src/machinst/abi_impl.rs Show resolved Hide resolved
cranelift/codegen/src/machinst/compile.rs Outdated Show resolved Hide resolved
@bjorn3
Copy link
Contributor

bjorn3 commented Aug 12, 2022

I thought this trait existed because some architectures may have an ABI sufficiently different from the norm that ABICalleeImpl would not be able to implement it.

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 tackling this! I'm happy to see things simplified here. LGTM overall, just one slightly bikesheddy comment below.

To address a few points in discussion:

@bjorn3:

I thought this trait existed because some architectures may have an ABI sufficiently different from the norm that ABICalleeImpl would not be able to implement it.

The trait initially existed because each backend implemented it separately; there was no shared "vanilla ABI" code. Eventually I refactored things to share that (this was in #2128 and #2142 for aarch64 and x64 respectively; and s390x never had its own impl, it has always used abi_impl EDIT: reading the first PR further I'm reminded s390x did have its own backend, out of tree, but moved to abi_impl before merging here IIRC.). We kept the trait around because, as you suggest, there was a thought that other machines might need very different implementations.

But in practice, (i) this trait separation adds complexity and hinders refactoring (@fitzgen was hitting some issues recently, motivating this PR), and (ii) we've actually managed to make the shared abi_impl code pretty flexible, by adding hooks to the ABIMachineSpec. I'm confident that we can tweak things as needed to fit most reasonable architectures -- e.g., the in-progress riscv64 backend uses it with no problem -- and for truly different architectures, we can update the design when we understand the requirements better.

@jameysharp:

Naming conventions are hard. AbiCallee looks weird to me. But 🤷

Indeed, we spent a bunch of discussion on this two years ago, actually; it was originally some other name that escapes me at the moment (ABIBody maybe?) and there was a suggestion to name the traits in terms of the role that they represent. So ABICallee is the callee side (receiving arguments, doing prologues and epilogues) and ABICaller is the caller side (setting up arguments, emitting a call instruction, noting clobbers as side-effects).

cranelift/codegen/src/machinst/abi_impl.rs Outdated Show resolved Hide resolved
It has only one implementation: the `ABICalleeImpl` struct. By using that
directly we can avoid unnecessary layers of generics and abstractions as well as
a couple `Box`es that were previously putting the single implementation into a
`Box<dyn>`.
@fitzgen fitzgen enabled auto-merge (squash) August 15, 2022 17:13
@@ -65,7 +65,7 @@ fn saved_reg_stack_size(

/// AArch64-specific ABI behavior. This struct just serves as an implementation
/// point for the trait; it is never actually instantiated.
pub(crate) struct AArch64MachineDeps;
pub struct AArch64MachineDeps;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it is public now that there is the MachInst::ABIMachineSpec associated type.

@fitzgen fitzgen merged commit f0c60f4 into bytecodealliance:main Aug 15, 2022
@fitzgen fitzgen deleted the no-more-abi-callee-trait branch August 15, 2022 18:28
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.

None yet

4 participants