[llvm-commits] [llvm] r55807 - in /llvm/trunk: lib/Target/X86/X86CallingConv.td lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/2007-08-13-SpillerReuse.ll test/CodeGen/X86/2008-02-22-ReMatBug.ll test/CodeGen/X86/coalescer-commute3.ll test/Cod

Duncan Sands baldrick at free.fr
Mon Sep 22 04:32:54 PDT 2008


Hi Arnold,

> Nested function trampolines are currently not supported by fastcc when
> -tailcallopt is enabled because i don't know the implications of
> trampolines.

trampolines work like this.  Suppose you have a function
  i32 @f(i8* nest, i32, i32)
Then a trampoline lets you call it as if it didn't take
the first parameter (the one marked with the nest attribute),
i.e. as if it looked like this:
  i32 @f_tramp(i32, i32)
The value V to be passed as the i8* is specified when you
create the trampoline.  The trampoline intrinsic hands
you a pointer P to a i32(i32, i32) function.  If someone
does a call i32(i32, i32)* P(i32 x, i32 y) then the trampoline
magic splices in the value for V, and the effect is as if you
called @f(i8* V, i32 x, i32 y).  Yes, this is actually useful :)

How is this implemented?  The code generators create a bit
of executable code on the stack that does:

  load V into ecx <= register reserved by trampoline
  jump to @f

The pointer P returned by the trampoline intrinsic points
to the "load V into ecx" instruction on the stack.  A call
to P then results in a call to @f with V held in ecx.  And
that's it.  I have no idea how this interacts with tail
calls.  Since the call to the trampoline is always an indirect
call, maybe it never gets turned into a tail call?

Ciao,

Duncan.



More information about the llvm-commits mailing list