[LLVMdev] Adding a custom calling convention
Evan Cheng
evan.cheng at apple.com
Thu Feb 21 14:54:20 PST 2008
On Feb 20, 2008, at 11:25 AM, Raja Mukherji wrote:
> 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
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
>
>
>>
>>> 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.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list