[llvm-commits] [llvm-gcc-4.2] r46164 - in /llvm-gcc-4.2/trunk/gcc/config/i386: llvm-i386-target.h llvm-i386.cpp

Duncan Sands baldrick at free.fr
Tue Jan 22 23:23:53 PST 2008


> Okay, well we already get many other x86-64 issues wrong already, but  
> Evan is chipping away at it.  How do you pass an array by value in C?  
> Example please,

I find the x86-64 ABI hard to interpret, but it seems to say that
aggregates are classified recursively, so it looks like a struct
containing a small integer array should be passed in integer registers.

Also, it is easy in Ada: the compiler passes small arrays by value,
for example:

package Arr is
   type ByValArray is array (1 .. 2) of Short_Integer;
   function PassArrayByVal (A : ByValArray) return Short_Integer;
end;

package body Arr is
   function PassArrayByVal (A : ByValArray) return Short_Integer is
   begin
      return A(1) + A(2);
   end;
end;

->

define i16 @arr__passarraybyval(i32 %a.0.0) signext nounwind  {

(Here presumably the i32 was synthesized by llvm-convert from the
two element array of shorts passed by value).

Can you please clarify the roles of llvm-gcc and the code generators
in getting ABI compatibility.  When generating IR for x86-64, llvm-gcc
sometimes chops by-value structs into pieces, and sometimes passes the
struct as a byval parameter.  Since it chops up all-integer structs,
and this corresponds more or less to what the ABI says, I assumed this
was an attempt to get ABI correctness.  Especially as the code generators
don't seem to bother themselves with following the details of the ABI (yet),
and just push byval parameters onto the stack.  Since you say

>> This is an optimization, not a correctness issue

I guess this means that the plan is to teach the codegenerators how to
pass any aggregate byval in an ABI conformant way (not the case right now),
but still do some chopping up in the front-end to help the optimizers.
Of course this chopping up needs to be done carefully so the final result
squirted out by the codegenerators (once they are ABI conformant) is the
same as if the chopping had not been done...  Is this chopping really a
big win?  Is it not possible to get an equivalent level of optimization
by enhancing alias analysis?

Ciao,

Duncan.



More information about the llvm-commits mailing list