[LLVMdev] Structure returns to-do or not-to-do?
kennethuil at gmail.com
Wed Oct 20 17:09:52 CDT 2010
On Wed, Oct 20, 2010 at 4:56 PM, roger roger <roger83 at hotmail.co.uk> wrote:
> I notice that using the online demo, functions which return structures are
> converted to be void, and instead take an extra argument which is the a
> pointer to the returned structure, and the allocation is made by the caller.
> Even declared, but undefined functions are converted like this, presumably
> this doesn't cause a problem during linking?
> I had a look back through the previous releases and saw that this was
> required before version 2.3 because return types could not be structures
> (structures weren't considered first class). However, since then it is legal
> to return a structure, and that there is an optimization pass which looks
> specifically for the type of functions which have an 'sret' argument and
> tries to return the structure in registers if it fits.
> I can imagine that the above behavior could be an artifact of the old
> system, but obviously, when the structure is too large, it's going to have
> to be return via pointer anyway.
> So my question is, should I be following the demo's example for IR
> generation or just generate IR which returns structures, even if they could
> be too large to fit in registers?
The X86 platform should handle structure returns that don't fit in
registers (by converting it to an sret argument at codegen time), but
as far as I know, that hasn't been implemented on any other platform.
More information about the LLVMdev