This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: proper tail recursion for gcc

On Thu, Jul 20, 2000 at 12:12:15PM -0700, Richard Henderson wrote:
> On Thu, Jul 20, 2000 at 11:21:51AM +0000, Mark Probst wrote:
> > i was referring to exactly this optimization. at least on the alpha,
> > for example, only calls to static functions are optimized, which is
> > not very helpful if you need separate compilation.
> This is required by the calling conventions.
> Given foo calls bar calls baz, if baz function is in a different file
> than bar, it might use a different $gp value.  If baz uses a different
> $gp value, then the $gp value on return to foo will be incorrect and
> foo may crash.

this is true if foo and bar are in the same compilation unit, because
in this case foo does not reload $gp after calling bar. but if foo
knew that bar might do a tail call to a non-static function, it could
reload $gp and everything would be fine.

as i understand it, this knowledge is available (or could be made
available) to foo only if bar is defined before foo. is this correct?
is there a way around this? if there is not, we would have to assume
that bar makes a tail-call to a non-static function. we could let the
programmer explicitly declare that it does not, if the reloading of
$gp should be avoided.


Mark Probst
Student, Programmer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]