Does -fomit-frame-pointer always omit the frame pointer? Is there ever a situation where both the pc and fp need to be setup? Does dynamic stack growth force the fp to be setup? Asking specifically for MIPS32. Thanks!
Does -fomit-frame-pointer *always* omit the fp?
1.2k views Asked by brooksbp AtThere are 3 answers
No, the frame pointer is not normally needed. The compiler may access local variables relative to the stack pointer and does not need a special frame pointer.
Nevertheless, the standard frame pointer setup sequence can help when debugging a crashed program (even when not compiled with -g
), because the debugger can use the frame pointer information to reconstruct the call stack. With no frame pointer it has no information to figure out where one stack frame starts and the next ends.
So, when using -fomit-frame-pointer
you are trading performance for much more difficult debugging in case of a crash. If your code's performance critical parts are smallish loops and don't call any functions, then omitting the frame pointer will bring little advantage, either.
The frame pointer is not really needed for correct execution, except sometimes for exception unwind. Dynamic stack growth usually requires some kind of a frame pointer, but it is not tied to a particular register, but rather allocated through normal data flow analysis.
Basically,
-fomit-frame-pointer
demotes the FP from a fixed register assignment to a pseudo register and makes initialisation subject to dead store elimination. So the answer to the first question is no, it doesn't omit it always.