For marking a call site as a tail call you have to call void setTailCall(bool isTC = true) on the CallInst. The calling convention of the function needs to be CallingConv::Fast (currently only fastcc calls are optimized) and the call has to be in tail position of course. To enable tail call optimization in an embedded vm i guess you would include llvm/Target/TargetOptions.h and set the static variable PerformTailCallOpt to true. Take this with a grain of salt or two since i have never done it ;) but i guess that setting those globals is what cl::ParseCommandLineOptions does in lli/llc.cpp. regards arnold> Quick question, how do you enable tail calls for the JIT when using > the API, not an external app; in my program it is all internal, > nothing external is called and the only thing I saw was that one > global on a quick look through. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On Fri, Sep 12, 2008 at 8:24 AM, Arnold Schwaighofer <arnold.schwaighofer at gmail.com> wrote:> For marking a call site as a tail call you have to call void > setTailCall(bool isTC = true) on the CallInst. The calling convention > of the function needs to be CallingConv::Fast (currently only fastcc > calls are optimized) and the call has to be in tail position of > course.The function performing the tail call also needs to be CallingConv::Fast. Some info about tail call optimization is located at <http://llvm.org/docs/CodeGenerator.html#tailcallopt>. Some examples are in > ls /llvm/test/CodeGen/X86/tailcall* regards arnold
Arnold Schwaighofer wrote:> Take this with a grain of salt or two since i have never done it ;) > but i guess that setting those globals is what > cl::ParseCommandLineOptions does in lli/llc.cpp.I can confirm that this is actually how it works (fastcc on the function + setTailCall on the call instruction + llvm::PerformTailCallOpt = true). I might add that of course you also have to make sure that the tail call is immediately before a ret instruction. :) Note that it also depends on the JIT for the target architecture whether this is actually supported. I verified that this does work on x86, -64. Not sure about the status on other archs, though, it seems that at least the LLVM 2.2 JIT didn't do any proper tail calls on ppc yet. Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr.Graef at t-online.de, ag at muwiinfa.geschichte.uni-mainz.de WWW: http://www.musikinformatik.uni-mainz.de/ag
Hi Albert, nice to see someone is using the tail call stuff. i am responsible for the mess (feature) ;). Tail call optimization currently (llvm 2.3) works (to varying degrees, see http://llvm.org/docs/CodeGenerator.html#tailcallopt) for x86(-64) and ppc32/64. x86 being more mature (testing) than ppc. ppc64 has received the least testing. regards