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: forcing tail/sibling call optimization

Mark Mitchell <> writes:

 > >>>>> "Andi" == Andi Kleen <> writes:
 >     Andi> Problem I see with that is diagnostics again: e.g. someone
 >     Andi> depends on a particular call being a tail call and not
 >     Andi> allocating new storage.
 > The ANSI/ISO C way of doing this would be a #pragma (or _Pragma) near
 > the call site.  In GCC, we could do that, or we could do something
 > like:
 >   __tailcall__ (xyz (foo));
 > or something.  But that magic should be only used for warnings -- it
 > should not be used to have the compiler generate different code.

Not only should it not be used for generating different code, it
*cannot* be used for generating different code.

The caller of xyz (call it f) would have to jump to xyz.  The caller
of f is going to pop f's args when f returns.  How is the caller going
to pop off the right amount of space after f's effectively changed the
amount of space that it's using?  If xyz uses the same amount of stack
space as f, then it's possible.  The nature of the specific
instructions used for manipulating the stack could make it possible.
But I don't see how it can work in general.

Harvey Stein
Bloomberg LP

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