Skip to content

Minor optimizations to assembler-generated code #10811

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

Conversation

alexcrichton
Copy link
Member

This is a few minor changes in the hopes of optimizing the compile-time of the generated code itself for the x64 assembler crate, including:

  • Add derive(Copy) to all instructions to benefit from a specialized implementation of derive(Clone) when a Copy implementation is also present (e.g. it's *foo instead of a structural clone-each-field).
  • Don't use write! in Display for Inst and instead delegate directly with methods to avoid formatting machinery.
  • Use helper methods in RegisterVisitor trait to have register allocation be a method-per-operand and shrink the methods a bit.

This is a few minor changes in the hopes of optimizing the compile-time
of the generated code itself for the x64 assembler crate, including:

* Add `derive(Copy)` to all instructions to benefit from a specialized
  implementation of `derive(Clone)` when a `Copy` implementation is also
  present (e.g. it's `*foo` instead of a structural `clone`-each-field).
* Don't use `write!` in `Display for Inst` and instead delegate directly
  with methods to avoid formatting machinery.
* Use helper methods in `RegisterVisitor` trait to have register
  allocation be a method-per-operand and shrink the methods a bit.
@alexcrichton alexcrichton requested a review from abrown May 19, 2025 21:42
@alexcrichton alexcrichton requested a review from a team as a code owner May 19, 2025 21:42
@alexcrichton
Copy link
Member Author

This doesn't have a big impact on compile-time right now, nor am I confident that it'll have an impact long-term, so @abrown if you'd prefer I'm also ok to just close this and/or drop parts of it.

@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label May 19, 2025
Copy link
Contributor

@abrown abrown left a comment

Choose a reason for hiding this comment

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

Makes sense to me. My sense is that, with all this generated code, any clarity improvements are worth their weight in gold due to easier debugging, regardless of the performance improvement.

@alexcrichton alexcrichton enabled auto-merge May 20, 2025 12:16
@alexcrichton alexcrichton added this pull request to the merge queue May 20, 2025
Merged via the queue into bytecodealliance:main with commit 61eb16d May 20, 2025
41 checks passed
@alexcrichton alexcrichton deleted the shrink-some-generated-code branch May 20, 2025 12:50
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.

2 participants