<br><br><div class="gmail_quote">On Sun, Apr 3, 2011 at 2:58 AM, David Terei <span dir="ltr"><<a href="mailto:davidterei@gmail.com">davidterei@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Yiannis,<br>
<br>
As has been said GHC had this problem (I'm the author of GHC's LLVM<br>
backend). GHC uses 4 pinned registers on x86-32 and 16 on x86-64. The<br>
solution is to use a custom calling convention. I would argue that<br>
this is a better solution then having the registers completely<br>
reserved as in the middle of a function llvm can spill those registers<br>
to free them up for temporary use. Also, if when generating code you<br>
know that one of the pinned registers doesn't actually store anything<br>
useful for this function then you can avoid passing it on to the next<br>
function so that the register will be free to use during the function.<br>
<br>
Here is a link to the original discussion about this problem and the solution:<br>
<br>
<a href="http://nondot.org/sabre/LLVMNotes/GlobalRegisterVariables.txt" target="_blank">http://nondot.org/sabre/LLVMNotes/GlobalRegisterVariables.txt</a><br>
<br>
You should also check out the GHC calling convention as there is a<br>
good chance you could use it to get what you want and not have to<br>
modify llvm at all. The calling conventions for X86 are defined in<br>
'lib/Target/X86/X86CallingConv.td' in a very easy to read format.<br>
<br>
On X86-64 the arguments are passed in R13, RBP, R12, RBX, R14, RSI,<br>
RDI, R8, R9, R15, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, in that order.<br>
<br>
So lets say the compiler you are trying to work with currently stores<br>
a Sp and a Hp in %R13 and %R12 respectively. You could define your<br>
functions like so:<br>
<br>
function cc 10 void f (Sp, tmp1, Hp) {<br>
  [...]<br>
  tail call g (Sp', undef, Hp');<br>
  ret void;<br>
}<br>
<br>
Cheers,<br>
<font color="#888888">David<br>
</font><div><div></div><br></div></blockquote><div>Hey people,<br><br>It has been some time since the last email on this topic. Since then i have successfully used your advice and implemented a custom calling convention for my backend that adheres to the runtime system's ABI. To summarize what i do: i have three virtual registers (HP, P, NSP) pinned to some physical registers by defining it in the custom calling convention. I have also defined a custom return cc in order to guarantee that the physical registers also have the correct values on exit of the function. In that way i am sure that the registers are updated both on entrance and exit and that is exactly what i want.<br>
<br>The problem with that is the case of an 'invoke' call. According to the semantics of the invoke instruction the return value is not available  when a stack unwind happens. From the Language Reference Manual:<br>
 "For the purposes of the SSA form, the definition of the value returned by the
   '<tt><span>invoke</span></tt>' instruction is deemed to occur on the edge from the current
   block to the "normal" label. If the callee unwinds then no return value is
   available."<br><br>In that case, how can i get the values of the pinned registers, i.e. HP, P and NSP, needed in the Fail code block?  <br><br><br>Cheers,<br>Yiannis<br></div></div>