x86_64 ABI: pass structs indirectly if there are no more available registers #11344
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #9519
Unix x86_64 ABI defines CPU registers
rdi
,rsi
,rdx
,rcx
,r8
,r9
(for integer values) andxmm0
throughxmm7
(for floating point values) for passing arguments to functions. Small structures (smaller than 64 bytes, or 8 eight-bytes) can be passed using registers as well, by passing individual fields into separate registers. But if the number of arguments is larger than the available registers, the remaining values are passed through the stack. LLVM manages this for scalar values, but for aggregates it needs thebyval
attribute to the argument type added.This patch is heavily inspired by the Rust implementation (from where the original ABI code was taken). The previously added spec by #9520 is enabled and I also added a new one to cover the
StructRet
scenario which effectively introduces an extra hidden function argument as a pointer to the caller-allocated return value.