[LLVMdev] First-class structs

Eli Friedman eli.friedman at gmail.com
Tue Dec 16 14:37:28 PST 2008


On Tue, Dec 16, 2008 at 2:18 PM, Jon Harrop <jon at ffconsultancy.com> wrote:
> 1. What is a function returning a struct compiled to (e.g. by GCC on Linux)?

There are a few possibilities... the generic case is a parameter
marked with sret, but it can get extremely complicated with certain
ABIs like x86-64.

> 2. What caveats are there (e.g. is complex in C99 handled differently?)?

It's horrendously complicated; you probably don't want to think about it.

> 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)?

If you do it naively, you'll most likely end up with the wrong thing,
especially with more complicated ABIs like x86-64.  And yes, returning
first-class structs with many members directly is likely to break on
x86.

> 4. Will run-time performance be degraded if I make heavy use of nested structs
> and/or return them from functions?

LLVM should be able to deal with nesting without any issues.

-Eli



More information about the llvm-dev mailing list