[llvm-commits] patch: codegen non-exiting calls as tail, even if not tail in IR
Nick Lewycky
nicholas at mxc.ca
Sun Oct 14 20:44:40 PDT 2012
This patch teaches the LLVM codegen layer to try emitting calls to
'terminal' functions as tail calls, even if they aren't marked tail
calls in the IR. The motivation is to minimize the amount of extra
instructions emitted by clang's -fcatch-undefined-behavior flag (and
other tools like asan/msan/tsan, if run in a mode where they don't turn
off tail calls due to the loss of stacktrace info).
Why not mark them 'tail' in the IR? Because the IR definition states
that a tail call is one does not access any allocas or varargs in the
caller. This is good because it's defining an IR concept in terms of
other IR concepts, and I don't want to change it. BasicAA uses this for
example, by assuming that a call with 'tail' doesn't touch any alloca'd
memory.
What's a terminal function? One that is noreturn + nounwind. A function
that calls longjmp() will be marked nounwind by clang, and I can't tell
whether this is correct due to a lack of precision in the definition of
'nounwind' in the language reference.
At the machine level, it's safe to tail call to a function that accesses
its caller's stack, as long as we plan to never return.
Please review! The two cases that I'm concerned about are when the
callee calls longjmp(), and when the call is varargs. I think both of
these cases are fine without special handling, but I'd appreciate
someone double-checking that.
Nick
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tail-noreturn-1.patch
Type: text/x-patch
Size: 1540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121014/ff56134f/attachment.bin>
More information about the llvm-commits
mailing list