[llvm-dev] conceiving of a frontend feature which requires LLVM support: builtin to determine stack size upper bound

Andrew Kelley via llvm-dev llvm-dev at lists.llvm.org
Sat Oct 21 10:43:10 PDT 2017


Here is a feature I would like to introduce to my frontend:

A builtin function to calculate the upper bound of the stack size of any
given function.

The idea here is that, if we do not have any:
 * external library calls
 * alloca
 * indirect function calls
 * non-tail-recursion
 * inline assembly that modifies the stack pointer

Then, we can look at a given function and determine precisely how much
stack space is needed to spawn a thread to run that function. This provides
two benefits:
 * Statically guarantee that stack overflow will not occur
 * Threads can have smaller stack sizes, lowering the cost of creating a
thread

This feature requires tight coupling with LLVM, because:
 * We need to know the stack size post-optimizations
 * Frontend needs to make a compile error if non-tail-recursion occurs, but
LLVM might introduce (or remove?) tail recursion, and so we would need to
capture this error from LLVM and report it back in the frontend.


What do you think? Is this feature reasonable to achieve with LLVM and in
scope of the LLVM project?

I would propose an LLVM builtin function to perform this calculation, and I
can work on a proof-of-concept if llvm-dev thinks this idea is worth
pursuing.


Upstream issue: https://github.com/zig-lang/zig/issues/157
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171021/01fedbb5/attachment.html>


More information about the llvm-dev mailing list