[LLVMdev] Explicit register usage in LLVM assembly

Yiannis Tsiouris yiannis.tsiouris at gmail.com
Sat Jul 9 08:12:20 PDT 2011

Hash: SHA256

On 07/08/2011 10:30 PM, Frits van Bommel wrote:
> On 8 July 2011 21:10, Yiannis Tsiouris <yiannis.tsiouris at gmail.com> wrote:
>> 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:
>>  "For the purposes of the SSA form, the definition of the value returned by
>> the 'invoke' 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."
>> 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?
> You could store them in the exception, assuming your compiler is the
> one generating the code that throws it...
Hi Frits and thanks for your quick response,

Can you elaborate more on this idea? How could i do that?
Let me explain quickly how i handle the 'register pinning' and what is
the problem in case it was not clear in the beginning (in llvm pseudocode):

{i64, i64, i64, i64} @main(i64 %in_hp, i64 %in_p, i64 %in_sp) {
  ;; In the entry block:
  %hp = alloca i64
  store %in_hp -> %hp
  %p = alloca i64
  store %in_p  -> %p
  %sp = alloca i64
  store %in_sp -> %sp
  ;; before normal call
  %hp1 = load %hp
  %p1  = load %p
  %sp1 = load %sp
  {%hp2, %p2, %nsp2, %val} = call @foo(%hp1, %p1, %sp1, arg1, arg2)
  ;; in normal continuation
  store %hp2 -> %hp
  store %p2  -> %p
  store %sp2 -> %sp
  ;; before invoke call
  %hp3 = load %hp
  %p3  = load %p
  %sp3 = load %sp
  {%hp4, %p4, %nsp4, %val} = invoke @bar(%hp3, %p3, %sp3, ...) to label
%Continue unwind label %Cleanup
  ;; %Continue label (normal return)
  store %hp4 -> %hp
  store %p4  -> %p
  store %sp5 -> %sp
  ;; In this block i *cannot* access %hp4, %p4, %sp4
  ;; Return of main
  %hp5 = load %hp
  %p5  = load %p
  %sp5 = load %sp
  ret {%hp5, %p5, %sp5, 0}

The problem is that in the %Cleanup block i cannot perform the usual
store as the virtual registers %hp4, %p4, %sp4, are not available (due
to the semantics of the 'invoke' statement).

Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


More information about the llvm-dev mailing list