[LLVMdev] Structs as first class values.

Chris Lattner clattner at apple.com
Wed Jul 23 12:58:31 PDT 2008


On Jul 23, 2008, at 11:57 AM, David Greene wrote:

> I'm still not sure this is good.  If I hand-write LLVM IR that  
> returns a large
> struct by value, the generated code should be correct.  It's not right
> now AFAIK.  If you want to make the memcpy explicit, we could do the
> l;owering in a separate pass.  That's fine with me, as long as it's
> handled by LLVM so it produces correct code.

David, you're missing something here.  There is a many to one mapping  
of C to LLVM types.  From the LLVM type you can't judge what the input  
type was.  You can't just see that an llvm return type is {double,i64}  
and assign to xmm/gpr.  It works in this case, but not in the general  
case.

For example, in this case:

struct x {
   double x;
   float f;
   int i;
};

struct x foo(float *F, int *I) {
   struct x y;
   y.x = *F;
   y.f = *F;
   y.i = *I;
   return y;
}

llvm-gcc produces:

	ret { double, i64 } %mrv5

to get the right ABI.  There is not enough information in the llvm ir  
to do this without the front-end's help.  Again, there is a many to  
one mapping from C type to LLVM type and not all C types that map onto  
the same llvm type are supposed to be handled the same way.

-Chris



More information about the llvm-dev mailing list