How does the frame-pointer work?

2

In the official GCC documentation there is a option that allows you to remove the frame-pointer when not needed.

  • What does the frame-pointer do?
  • How to remove this pointer can improve performance?
asked by anonymous 16.02.2017 / 11:49

1 answer

4

I do not know how much you know these lower level things and how memory works. This may help if you do not know much.

The frame pointer , or base pointer as it is also called, is a sub-stack of the stack where you have the data of a function.

FP is the address where the current function starts. It is used to easily return to the original location on the call as the execution of this function ends, especially in the occurrence of an exception ( unwinding ). It is also used as the base address for calculating the various elements that the function allocates, so the code can have relative addresses.

There are some rare situations where you do not need to keep that number in a register by releasing it to another task. It is rarer still to have the need to use this register for something else, so the optimization is almost harmless or of very rare advantage.

debug usually uses this register for your control. Omitting it makes your use unfeasible.

Fixed-size frames architectures do not need this, and architectures that have their own handling for stack frame can not receive this optimization.

The bottom line is that this optimization is almost unnecessary.

    
17.02.2017 / 12:40