On 20/02/2008, Chris Lattner <sabre at nondot.org>
wrote:> 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.
Am I correct in thinking that it's the X86CallingConv.td file that
needs to changed? I've had a look at it and I think I can figure out
how to write the calling convention, but I'm a bit lost trying to
integrate it into the rest of the code. In particular, how do I assign
an integer for use in the setCallingConv(unsigned CC) method?
>
> > 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.
>
I need the multiple return values so I guess I'll wait until 2.3
before converting to llvm but I'll still try to get the calling
convention to work in the mean time.
> -Chris
>
> --
> http://nondot.org/sabre/
> http://llvm.org/
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
Thanks for the help.