[llvm-dev] alloca behavior in llvm IR

林政宗 via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 16 05:51:53 PST 2020


Thanks, Tim.


When there are dynamic allocas, is it always that the compiler will insert @llvm.stacksave() and @llvm.stackrestore()?
When there is a need to insert @llvm.stacksave() and @llvm.stackrestore(), how does the compiler decide where it should insert them?
 


Best Regards,
Jerry

















At 2020-12-15 17:20:34, "Tim Northover" <t.p.northover at gmail.com> wrote:
>On Tue, 15 Dec 2020 at 02:45, 林政宗 <jackie_linzz at 126.com> wrote:
>> How would the compiler compute the address of "a"?  Would the compiler access "a" through the frame pointer?
>
>That's usually what happens, yes. Sometimes it may be yet another
>pointer called a "base pointer" though (for example
>https://godbolt.org/z/1z3WYM computes var's address from x19 because
>the stack was realigned so the offset from the frame pointer is no
>longer a compile-time constant).
>
>> if that's true, when will the frame pointer be set?
>
>It's generally set in prologue code emitted by XYZFrameLowering.cpp.
>
>> And when is a frame pointer is needed?
>
>That's not an easy question to answer I'm afraid. Some platforms
>always require a frame pointer (to improve back-traces for example),
>otherwise there's a whole host of odd edge-cases in what functions
>need that add a frame pointer to the mix.
>
>For example the function that makes the decision on AArch64 is here:
>https://github.com/llvm/llvm-project/blob/9c328e7afafd15795fed54e3b0c1c5bd4fa97dfa/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp#L297
>
>Cheers.
>
>Tim.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201216/53c690e1/attachment.html>


More information about the llvm-dev mailing list