[llvm-dev] alloca behavior in llvm IR
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Tue Dec 15 01:20:34 PST 2020
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.
More information about the llvm-dev
mailing list