diff --git a/specification/ch_2.xml b/specification/ch_2.xml index 21afab8..500d3a5 100644 --- a/specification/ch_2.xml +++ b/specification/ch_2.xml @@ -6637,6 +6637,44 @@ s6 - 72 (stored) +
+ Tail-Call Optimization + + When the last action of a function F is + to perform a function call to a function + G, and optionally return the value + returned from G, a compiler may perform a + tail-call optimization so long as the + optimization is undetectable by the caller of + G. The full details of and requirements + for tail-call optimization will not be described here, but in + essence F removes its stack frame and + issues a direct branch to G, which reuses + the stack space and the saved link register so that + G eventually returns to the caller of + F. + + + When the call from F to + G is not local, and + F is a TOC-preserving function, tail-call + optimization is disallowed because F and + G may have different TOC pointers. + Tail-call optimization cannot guarantee that the correct TOC + will be restored when G returns. + + + When the call from F to + G is local, and F is + a TOC-preserving function, but G is + not a TOC-preserving function, then + tail-call optimization is again disallowed. In this case, + G may have placed any value into register + r2, and the correct TOC will not be restored when + G returns. + +
Coding Examples