forcing tail/sibling call optimization

Mark Probst schani@mips.complang.tuwien.ac.at
Sun Nov 26 11:55:00 GMT 2000


On Sun, Nov 26, 2000 at 11:31:25AM -0800, Per Bothner wrote:
> I'm concerned that on many machines the default calling convention
> may make tail-call optimization difficult.  To make tail-call
> optimization practical (or at least efficient) you may want to use
> a non-default calling convention.
> 
> Specifically, the traditional C calling convention has the caller
> pop the arguments from the stack after the function returns.  This
> is needed to handle varags.  Safe and efficient tail-call
> elimination assumes the callee pops the arguments.

correct. in order to handle tail-call varargs as well, you must
additionally pass an implicit parameter containing the number of
vararg bytes or a pointer to the position in the stack where the last
argument is stored.

as i have already pointed out, i have implemented such a calling
convention in gcc. the implementation is still very crude, some small
details are not yet done, and i haven't done any larger tests, but it
works on alpha and i386 for simple cases.

> This means that syntax associated with the call site is not enough.
> You also (or instead) need some annotation when the called function
> is compiled.  Because of the need to handle unknown functions,
> that annotation needs to be an attribute of the function *type*.

also correct. i have used an __attribute__((tailcall)). both the
caller and the callee must have this attribute (if the callee is a
function pointer, its type must be attributed).

i would rather solve the last few remaining issues clean the
implementation up before i give it away but if anybody is really
interested, i'd be glad to mail the patch.

bye
schani

-- 
Mark Probst
Student, Programmer, Juggler
http://www.complang.tuwien.ac.at/~schani/


More information about the Gcc mailing list