[llvm-dev] best way to represent function call with new stack in LLVM IR?

whitequark via llvm-dev llvm-dev at lists.llvm.org
Thu May 10 19:35:06 PDT 2018


On 2018-05-11 02:28, Andrew Kelley via llvm-dev wrote:
> In the Zig frontend, we know at compile-time the entire call graph.
> This means we know stack size for all functions and therefore the
> upper bound stack usage.
> 
> [snip]
>  1. Is there a way to accomplish this with existing LLVM API?

You should use the @llvm.stacksave and @llvm.stackrestore intrinsic.
It is only legal to pass a value returned by stacksave to stackrestore.
If you need more control, consider @llvm.read_register and
@llvm.write_register intrinsics, which allow arbitrary manipulation
of the stack pointer (but, I think, will inhibit optimizations more).

-- 
whitequark


More information about the llvm-dev mailing list