Adding a custom calling convention

Hi all,
I was wondering what the best way of adding a custom calling convention in llvm?

In particular, for the x86 platform, I want:

on entry

esi = size of argument block
edi = address of argument block
ecx = callee object

and on return

eax = status code
ebx = possible one-shot continuation
ecx = returned value
edx = returned reference

I only want it to work in a JIT fashion so no persistence in bitcode
files is necessary.

Thanks,
Raja Mukherji

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

> 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@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Thanks for the help.

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

Yes, you need to modify X86CallingConv.td and maybe X86ISelLowering. Just define a new CC inheriting from CallingConv.

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?

Something like this?
  CCIfType<[i32], CCAssignToReg<[EDI, ESI, EDX, ECX, R8D]>>,

That means if it's a i32 parameter, it will be in one of these registers (well up to 5).

Don't worry about getting everything right the first time. You can submit small patches and there are lots of folks here who will be happy to get you moving along.

Evan