[LLVMdev] Destination register needs to be valid after callee saved register restore when tail calling
Arnold Schwaighofer
arnold.schwaighofer at gmail.com
Thu Aug 9 06:28:33 PDT 2007
On 8 Aug 2007, at 21:12, Anton Korobeynikov wrote:
> Hello, Arnold.
>
>> with the sentence i tried to express the question whether there is a
>> way to persuade the code generator to use another register to load
>> (or
>> move) the function pointer to (right before the callee saved register
>> restore) but thinking a little further that's nonsense.
> Why don't define some special op for callee address and custom
> lower it?
> I really suggest you to look into eh_return. It's used in some pretty
> tricky situtation inside eh runtime: it it used to return from some eh
> runtime code. We already know, how much we should unwind the stack,
> and
> what is the handler (sounds similar, right?). Also %eax and %edx are
> used to return eh data and should be preserved in such function.
> So, in
> general, code for eh_return looks like (intel notation here):
>
> mov ecx, ebp
> add ecx, offset
> mov [ecx], handler
> .... (just usual epilogue)
> mov esp, ecx
> ret
Aaaah, yes now i understand i was missing the movrr in
X86RegisterInfo.cpp.
And yes that's probably a much cleaner way of doing it.
The TC_RETURN would take a register (containing the calleeaddress)/or
the callee TargetGlobalAdress/TargetExternalSymbol and the size of
the stack adjustment (difference between caller/callee args)
TAILCALL would then be lowered to loading the callee address to a
register (if its dynamic). and increasing esp+4.
in X86RegisterInfo.cpp we would then have
if (RetOpcode== X86::TC_RETURN){
if (isDynamicCallee(RetOpCode)
add esp {stack adjustment tailcall}
mov esp {register from TAILCALL}
} else
// remove the ret
jmp _targetfunction
}
resulting code
mov ecx _targetfunction #load callee
epilogue
sub esp 4 # TAILCALL stackslot for eip
add esp 8 #caller has 2 more arg
mov esp ecx
ret
if the targetfunction is known
epilogue
#TAILCALL
add esp 8
jmp _targetfunction
Lowering of TAILCALL would also take caring of adjusting the argument
stores.
More information about the llvm-dev
mailing list