tail calls are only implemented for fastcall calling convention if i remeber right from my inquiries. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091112/e8f1dd2a/attachment.html>
I've run into some issues with tail calls in the past, make sure you are doing the following: 1. Call should be marked with tail (obviously) 2. Next statement after tail call should be 'return void' 3. Use fast call convention for tail calls 4. Make sure the function you are calling doesn't use the 'noreturn' attribute. 5. Turn on tail calls in llc (if using the static compiler), with '-tailcallopt' option. Point 4 is the one that caused me trouble for some time. Unfortunately it causes a bad interaction with the optimiser, specifically the 'simplifycfg' pass. What seems to happen is that since the function you are calling is marked with 'noreturn', the simplifycfg pass will then put a 'unreachable' statement after the tail call to that function. This stuffs up the tail call though as the llc compiler requires tail calls be followed by a 'return void' statement. In my case this caused my compiled programs to segfault if the llvm optimiser was run on them. I haven't fully investigated this yet so not really sure if it is specific to my case or applies universally but it sure did cause me some pains for a while. 2009/11/12 Paul Davey <plmdvy at gmail.com>:> tail calls are only implemented for fastcall calling convention if i remeber > right from my inquiries. > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
Resent, to the list this time instead of David (sorry for the duplicate)... On Thu, Nov 12, 2009 at 9:57 PM, David Terei <davidterei at gmail.com> wrote:> I've run into some issues with tail calls in the past, make sure you > are doing the following: > > 1. Call should be marked with tail (obviously) > 2. Next statement after tail call should be 'return void' > 3. Use fast call convention for tail calls > 4. Make sure the function you are calling doesn't use the 'noreturn' attribute. > 5. Turn on tail calls in llc (if using the static compiler), with > '-tailcallopt' option. > > Point 4 is the one that caused me trouble for some time. Unfortunately > it causes a bad interaction with the optimiser, specifically the > 'simplifycfg' pass. What seems to happen is that since the function > you are calling is marked with 'noreturn', the simplifycfg pass will > then put a 'unreachable' statement after the tail call to that > function. This stuffs up the tail call though as the llc compiler > requires tail calls be followed by a 'return void' statement. In my > case this caused my compiled programs to segfault if the llvm > optimiser was run on them.Just to make sure, but if a tail call function returns a value, can you not just return that value directly by your function and have tail calls still work?
On Friday 13 November 2009 09:40:02 OvermindDL1 wrote:> Just to make sure, but if a tail call function returns a value, can > you not just return that value directly by your function and have tail > calls still work?Yes, that is correct. You may like to look at the implementation in HLVM which handles struct return types as well: http://hlvm.forge.ocamlcore.org/ -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e
On Friday 13 November 2009 04:57:43 David Terei wrote:> I've run into some issues with tail calls in the past, make sure you > are doing the following: > > 1. Call should be marked with tail (obviously) > 2. Next statement after tail call should be 'return void' > 3. Use fast call convention for tail calls > 4. Make sure the function you are calling doesn't use the 'noreturn' > attribute. 5. Turn on tail calls in llc (if using the static compiler), > with > '-tailcallopt' option. > > Point 4 is the one that caused me trouble for some time. Unfortunately > it causes a bad interaction with the optimiser, specifically the > 'simplifycfg' pass. What seems to happen is that since the function > you are calling is marked with 'noreturn', the simplifycfg pass will > then put a 'unreachable' statement after the tail call to that > function. This stuffs up the tail call though as the llc compiler > requires tail calls be followed by a 'return void' statement. In my > case this caused my compiled programs to segfault if the llvm > optimiser was run on them.Isn't that a bug in LLVM?> I haven't fully investigated this yet so not really sure if it is > specific to my case or applies universally but it sure did cause me > some pains for a while.HLVM is certainly abiding by the requirements for tail calls or they wouldn't be working with the JIT and unoptimized static compilation. The problem only appears when the code is run through "opt". However, I am assuming that this segmentation fault is the result of a broken tail call. Perhaps it is something else... -- Dr Jon Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/?e