[llvm-dev] best way to represent function call with new stack in LLVM IR?
Andrew Kelley via llvm-dev
llvm-dev at lists.llvm.org
Thu May 10 20:23:22 PDT 2018
On Thu, May 10, 2018 at 10:35 PM, whitequark <whitequark at whitequark.org>
wrote:
> 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).
>
Thanks,I'll try this:
%0 = @llvm.stacksave
@llvm.write_register ; set the new stack pointer
call ; hopefully this uses the new stack pointer for stack arguments
@llvm.stackrestore %0
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?
>
> --
> whitequark
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180510/b5220b90/attachment.html>
More information about the llvm-dev
mailing list