[cfe-dev] struct copy

Argiris Kirtzidis akyrtzi at gmail.com
Sun Sep 28 09:48:58 PDT 2008

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:

union U { int u1; char u2; };
struct S {
   int x1;
   char x2;
   union U u;

Here's what llvm-gcc produces:
    %struct.S = type { i32, i8, %struct.U }
    %struct.U = type { i32 }

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) ?
Can't the backend get a load/store of a large struct and based on type 
information as the above , lower it accordingly (memcpy, field copies, 
etc..) ?


More information about the cfe-dev mailing list