[LLVMdev] First-class structs

OvermindDL1 overminddl1 at gmail.com
Tue Dec 16 14:39:26 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.
>
> I also want to support as much of a C-like representation of the internal data
> structures as possible in order to ease interoperability. This raises several
> questions:
>
> 1. What is a function returning a struct compiled to (e.g. by GCC on Linux)?
>
> 2. What caveats are there (e.g. is complex in C99 handled differently?)?
>
> 3. If I just throw IL at LLVM naively, when is it likely to emit code that is
> incompatible with GCC-compiled C code or barf entirely in this context (e.g.
> are >2 fields in a returned struct on x86 not yet implemented)?
>
> 4. Will run-time performance be degraded if I make heavy use of nested structs
> and/or return them from functions?

>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.



More information about the llvm-dev mailing list