[cfe-dev] struct copy

Chris Lattner clattner at apple.com
Sun Sep 28 10:04:05 PDT 2008


On Sep 28, 2008, at 9:48 AM, Argiris Kirtzidis wrote:

> Chris Lattner wrote:
>>
>> On Sep 28, 2008, at 4:59 AM, Argiris Kirtzidis wrote:
>>
>>>
>>> What is wrong with having the compiler always produce a load/store ?
>>
>> For small structs, almost nothing!  It has the same semantics as an  
>> element-by-element copy.  For large structs, you really don't want  
>> to do this.
>>
>> The problem is that you need the same heuristic: you need to know  
>> that the struct is "small" and the struct has no holes in the LLVM  
>> type that some other element of the C type (e.g. through a union)  
>> contain data in.
>
> Give these types:
>
> Isn't this enough information for the backend to know where the  
> holes are in the struct and also to deal with unions (unions  
> considered as the type of the largest field) ?

Sure, that case is fine.  Try something like this:

struct a {
   char A;
   double D;
};

union c {
   struct a a;
   int I;
};


Which compiles to:
	%struct.a = type { i8, double }
	%struct.c = type { %struct.a }

Note that the llvm type for struct.c doesn't have members that fully  
overlap "int I".

-Chris




More information about the cfe-dev mailing list