[llvm-dev] On passing structures in registers

james faure via llvm-dev llvm-dev at lists.llvm.org
Fri Sep 10 06:03:10 PDT 2021


There are several ways to pass structures in and out of functions, and the fastest will presumably usually be in registers.

Return:
System V lets us use 2 64-bit registers for structure returns, where figuring this out seems to be the frontend's problem; If the packed struct is <= 128 bits, pass it by value as a llvm aggregate (and use extractvalue and insertvalue to manipulate it) otherwise write to a pointer with "sret" attribute and return void. It seems that once I commit to the sret style, llvm can no longer return the struct in registers, but I am also suspicious of always returning structs by value, and even recall reading somewhere that llvm is not good at handling large aggregates (maybe that applies mainly to loads and stores).

Struct arguments:
Here too we have a choice between passing a llvm aggregate or passing down a pointer argument with "byval" attribute. As before it is unclear which should be preferred.

I'm also curious about how best to represent bitvectors, and have noticed clang sometimes casting structures to arrays; I currently use raw arrays of %i1 and extract|insert value.

My final concern is that the convention needs to be predictable, both for ABI compatibility reasons and to inform appropriate Bitcasting of function pointers. I would also like to understand what exactly informs the threshold for switching strategy.

Thanks for any insights,
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210910/ee0fd56d/attachment.html>


More information about the llvm-dev mailing list