Re: demonstration of proper tail calls
Chris Lattner <[email protected]>
| Newsgroups | gmane.comp.lang.c-- |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 4 May 2004, Fergus Henderson wrote: > On 29-Apr-2004, Chris Lattner <[email protected]> wrote: >> If there is a real need for it we can always add a bit to the >> call instruction to allow the front-end to indicate that it is always safe >> to do a tail call (even if there are stack allocations), but I'm not sure >> this is really desirable or safe. > > IMHO this is indeed desirable, since there are situations in which > it is easy for the front-end to provide that the call is safe, but much > harder for the back-end to do the same proof. Agreed. > <snip> > then after the call to bar(), the front-end can be sure that once bar() > has returned, there are no more references to the parameter X, because > this is enforced by the front-end's language rules which guarantee that > references are only passed downwards. So the front-end knows that foo's > stack frame can be deallocated. But generally the back-end can't easily > determine this. Having the front-end generate code in such a way that > the back-end can easily recognize this fact becomes quite awkward. Great point. FWIW, we just released LLVM 1.5: http://mail.cs.uiuc.edu/pipermail/llvm-announce/2005-May/000016.html LLVM 1.5 includes the ability for front-ends to indicate that function calls to not access their caller stack frames (the tail marker) to handle cases like the above. In addition, it supports general proper tail calls: http://llvm.cs.uiuc.edu/releases/1.5/docs/ReleaseNotes.html#tailcalls ... as was requested on this list. Cheers, -Chris -- http://nondot.org/sabre/ http://llvm.cs.uiuc.edu/