[LLVMdev] Calling Conventions Cont'd

Jon Sargeant delta17 at cox.net
Mon Apr 14 11:25:28 PDT 2008

Duncan Sands wrote:
> Hi Jon,
>> What is the correct procedure for translating a function signature from 
>> a high-order language to LLVM?
> you have to do it carefully so that LLVM will end up producing object code
> that conforms to the platform ABI.  For example, suppose you are using cdecl
> with a small struct (a pair of ints, say).  Then your function should get two
> integer parameters, which LLVM will assign to registers.  If using a large
> struct then use byval which will pass it on the stack.
> I know this is painful, hopefully LLVM will get some helpers for this one
> day.  The reason is that some ABIs make distinctions that don't exist at
> the LLVM level.  For example at least one ABI says that "complex"
> ( { double, double } ) should be passed differently to a struct containing
> a pair of doubles.

Ugh, this isn't what I wanted to hear.  Passing "complex" differently 
than a structure containing two doubles is a bad design, but alas, 
calling conventions are beyond our control.  How many special cases like 
this are there?  If "complex" is the only special case, LLVM could 
provide a complex type, which behaves like {double,double} in all 
respects except for calls.  I recommend handling calling conventions 
entirely in the back end.  Apart from calling conventions, the front end 
doesn't need to know the specific target, only the data layout and which 
intrinsics the target supports.  This approach makes a clean division 
between the front end and back end.

Best Regards,

More information about the llvm-dev mailing list