[LLVMdev] Explicit register usage in LLVM assembly

Yiannis Tsiouris yiannis.tsiouris at gmail.com
Sun Apr 3 05:21:59 PDT 2011


On 04/03/2011 02:58 AM, David Terei wrote:
> Hi Yiannis,
>
> As has been said GHC had this problem (I'm the author of GHC's LLVM
> backend). GHC uses 4 pinned registers on x86-32 and 16 on x86-64. The
> solution is to use a custom calling convention. I would argue that
> this is a better solution then having the registers completely
> reserved as in the middle of a function llvm can spill those registers
> to free them up for temporary use. Also, if when generating code you
> know that one of the pinned registers doesn't actually store anything
> useful for this function then you can avoid passing it on to the next
> function so that the register will be free to use during the function.
>
> Here is a link to the original discussion about this problem and the solution:
>
> http://nondot.org/sabre/LLVMNotes/GlobalRegisterVariables.txt
>
> You should also check out the GHC calling convention as there is a
> good chance you could use it to get what you want and not have to
> modify llvm at all. The calling conventions for X86 are defined in
> 'lib/Target/X86/X86CallingConv.td' in a very easy to read format.
>
> On X86-64 the arguments are passed in R13, RBP, R12, RBX, R14, RSI,
> RDI, R8, R9, R15, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, in that order.
>
> So lets say the compiler you are trying to work with currently stores
> a Sp and a Hp in %R13 and %R12 respectively. You could define your
> functions like so:
>
> function cc 10 void f (Sp, tmp1, Hp) {
>   [...]
>   tail call g (Sp', undef, Hp');
>   ret void;
> }
>
> Cheers,
> David
>   
Hi,
  
I 'll work further on what you and Frits van Bommel suggested. Using a
custom calling convention seems like a reasonable approach after some
minor research on how that could be done with LLVM. By the way, great
work on your thesis, David! :-)

Thank you for your suggestions,
~y.



More information about the llvm-dev mailing list