<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 10, 2018 at 10:35 PM, whitequark <span dir="ltr"><<a href="mailto:whitequark@whitequark.org" target="_blank">whitequark@whitequark.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>On 2018-05-11 02:28, Andrew Kelley via llvm-dev wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span>
In the Zig frontend, we know at compile-time the entire call graph.<br>
This means we know stack size for all functions and therefore the<br>
upper bound stack usage.<br>
<br></span>
[snip]<span><br>
 1. Is there a way to accomplish this with existing LLVM API?<br>
</span></blockquote>
<br>
You should use the @llvm.stacksave and @llvm.stackrestore intrinsic.<br>
It is only legal to pass a value returned by stacksave to stackrestore.<br>
If you need more control, consider @llvm.read_register and<br>
@llvm.write_register intrinsics, which allow arbitrary manipulation<br>
of the stack pointer (but, I think, will inhibit optimizations more).<span class="gmail-m_-2736878726406490178HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>Thanks,I'll try this:<br><br>%0 = @llvm.stacksave<br>@llvm.write_register ; set the new stack pointer<br></div><div>call ; hopefully this uses the new stack pointer for stack arguments<br></div><div>@llvm.stackrestore %0<br></div><div><br>Looks like `llvm.write_register` only works on ARM, AArch64, PowerPC and x86_64. This is concerning - do the other architectures not allow modification of the stack register? Or is this a TODO item in LLVM?<br><br><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-m_-2736878726406490178HOEnZb"><font color="#888888">
<br>
-- <br>
whitequark<br>
</font></span></blockquote></div><br></div></div>