[LLVMdev] PSA: Perfectly forwarding thunks can now be expressed in LLVM IR with musttail and varargs

David Chisnall David.Chisnall at cl.cam.ac.uk
Thu Oct 9 01:51:11 PDT 2014


On 8 Oct 2014, at 18:19, Reid Kleckner <rnk at google.com> wrote:

> The one target I know about where varargs are passed differently from normal arguments is aarch64-apple-ios/macosx. After thinking a bit more, I think this forwarding thunk representation works fine even on that target. Typically a forwarding thunk is called indirectly, or at least through a bitcast, so the LLVM IR call site would look like:

MIPS also has some subtle (and annoying) differences between variadic and non-variadic function calls.  Most notably (o32-only) that the stack pointer will be in a different place in the callee for variadic and non-variadic calls.  

The variadic calling convention that we're using for our extension currently requires all variadic arguments to be spilled to the stack (we found this actually improves performance very slightly, as most things that use variadic functions call a function that takes a va_list argument and you can construct the va_list by just saving the stack pointer, but we did it for correctness and simplicity originally).  

Implementing perfect forwarding would require that the caller calls the thunk with the non-variadic calling convention and that the thunk is aware that it must (potentially) preserve some more registers.  In particular, it mustn't touch any of the argument registers for the specified calling convention, unless explicitly modifying those arguments.

David





More information about the llvm-dev mailing list