[LLVMdev] Adding a custom calling convention

Chris Lattner sabre at nondot.org
Wed Feb 20 10:20:44 PST 2008


On Wed, 20 Feb 2008, Raja Mukherji wrote:
> Hi all,
> I was wondering what the best way of adding a custom calling convention in llvm?

It is quite easy to add custom calling conventions.  Check out how the 
various x86 fastcall, stdcall, etc things are handled.

> In particular, for the x86 platform, I want:
>
> on entry
>
> esi = size of argument block
> edi = address of argument block
> ecx = callee object

This is easy, just map the first three arguments to these registers, and 
pass these values in as the first three registers.

> and on return
>
> eax = status code
> ebx = possible one-shot continuation
> ecx = returned value
> edx = returned reference

This is harder, because LLVM can currently only return one value. 
Luckily, Devang is currently implementing support for multiple return 
values, so this should just be a matter of having the function return 
these four values and having the code generator map them as you want.  I'd 
expect this support to be complete in 2-3 months, hopefully for llvm 2.3.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list