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: clone ABIArg instead of allocating SmallInstVec #8164

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

jameysharp
Copy link
Contributor

This allows us to make a single pass over an argument's slots instead of needing to first pre-allocate temporaries, because we don't need to hold a borrow of ctx. For the same reason, we can also emit the new instructions directly instead of buffering them and copying them at the end.

This approach also moves less data around. A SmallInstVec is a usize plus four M::Insts, which are 32 or 40 bytes each, while an ABIArg is only 40 bytes. Since the SmallVecs inside ABIArg almost never spill to the heap, cloning one uses less memory than allocating temporary space for a few instructions.

I was inspired to write this after working on #8151 with @elliottt, and working on this also inspired #8163.

This allows us to make a single pass over an argument's slots instead of
needing to first pre-allocate temporaries, because we don't need to hold
a borrow of `ctx`. For the same reason, we can also emit the new
instructions directly instead of buffering them and copying them at the
end.

This approach also moves less data around. A SmallInstVec is a usize
plus four `M::Inst`s, which are 32 or 40 bytes each, while an ABIArg is
only 40 bytes. Since the SmallVecs inside ABIArg almost never spill to
the heap, cloning one uses less memory than allocating temporary space
for a few instructions.
@jameysharp jameysharp requested a review from a team as a code owner March 18, 2024 08:20
@jameysharp jameysharp requested review from abrown and removed request for a team March 18, 2024 08:20
@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. labels Mar 18, 2024
Copy link
Member

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

:shipit:

@jameysharp jameysharp added this pull request to the merge queue Mar 18, 2024
Merged via the queue into bytecodealliance:main with commit 56ca849 Mar 18, 2024
19 checks passed
@jameysharp jameysharp deleted the simplify-gen-arg branch March 18, 2024 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants