ravi
ravi copied to clipboard
OP_TAILCALL optimization for tail recursion
Can't you make LLVM generate a tailcall function (incompatible with C calling standards) and a wrapper C function (incompatible with tailcall), and pick one of them depending on OP_TAILCALL vs OP_CALL?
http://lua-users.org/lists/lua-l/2015-03/msg00282.html
I also have many other things to finish before I can spare time to look at this issue as I don't have use cases where I need deep recursion.
- I don't see the issue.
- Can't LLVM optimize a tail call (I mean LLVM's tail calls have a different calling convention which breaks the ABI - but listen to this thought) IF you have both a tail-call-version of the function AND a normal-call-version of the function? The normal-call-version would call the tail-call-version from its return, which would workaround the ABI break. On OP_TAILCALL, you would use the tail-call-version, and on OP_CALL, the normal-call wrapper.
(Then again I don't know much about LLVM, so this is mostly a guess)
Thanks for the ideas - I haven't really explored this deeply. My initial thoughts were to just support the recursive case which can be implemented by doing what Lua does - adjust the stack and then jump to the beginning of the current function.