[LLVMdev] First-class structs
Dale Johannesen
dalej at apple.com
Tue Dec 16 17:03:55 PST 2008
>> On Tue, Dec 16, 2008 at 3:18 PM, Jon Harrop <jon at ffconsultancy.com>
>> wrote:
>>>
>>> Apologies for the dumb questions but I'm rustier than I had hoped
>>> on this.
>>>
>>> I'm trying to write a mini ML implementation and am considering
>>> trying to
>>> optimize tuples into structs to avoid heap allocation when
>>> possible. Tuples
>>> are often used to return multiple values in ML so I am likely to
>>> wind up
>>> returning structs from functions.
>>
>> On Dec 16, 2008, at 2:39 PM, OvermindDL1 wrote:
>>>
>>>> From a quick test on the http://llvm.org/demo/index.cgi page, gcc-
>>>> llvm
>>> at least changed a function that returns a struct and makes it
>>> return
>>> void instead, and adds a first parameter of that struct as a pointer
>>> instead, and just stored the struct values into it directly instead
>>> (this is without optimizations enabled). The caller function create
>>> the struct on the stack, and passes its pointer into the function
>>> call
>>> as the first argument.
>>
That is one common way to return structs. In other cases the struct
value, or parts of it, is held in particular registers; which ones may
depend on the definition of the struct. The right thing to use is
defined by an ABI, which varies both with the target hardware and
target OS. The IL fed into LLVM needs to match the target in this
respect to get code that interoperates nicely. llvm-gcc knows about
the ABIs of its supported targets (modulo bugs) but a new or
unsupported target will not necessarily be the same as any of these.
If llvm-gcc supports your target the best thing to do is look at the
IL it generates. Really the answer to your original question is that
efficiency is not determined by LLVM, but by your target ABI.
More information about the llvm-dev
mailing list