how does an optimizing c++ compiler reuse stack slots of a function?

后端 未结 3 1344
心在旅途
心在旅途 2020-12-11 11:33

How does an optimizing c++ compiler determine when a stack slot of a function(part of stack frame of a function) is no longer needed by that function, so it can reuse its me

3条回答
  •  情深已故
    2020-12-11 12:23

    If I understand the question correctly, this is about call chaining, i.e. invoking function from function without allocating new stack frame.

    This is possible when the call can be transformed into tail call - the last op before return. This way all local variables (stack) are already out of scope, so the space can be reused. Compiler then generates a jump instead of call instruction. The original return return address is still at the proper place on the stack.

    I probably glossed over lots of details here, but that's the idea.

提交回复
热议问题