new front-end: ksi + few questions
Fergus Henderson
fjh@cs.mu.oz.au
Sun Sep 23 04:36:00 GMT 2001
[I'm cross-posting this to both the c-- and gcc mailing lists]
On 21-Sep-2001, Doug Moen <doug@moens.org> wrote:
> Ksi is pretty cool. It's just a thin wrapper around the GCC tree language,
> with a lispy syntax. It's primitive, poorly documented, not quite ready
> for prime time. It doesn't meet my requirements, because AFAIK GCC still
> doesn't provide a fully general tail call mechanism, so I'd have to use
> the trampoline trick with Ksi.
In GCC >= 3.0, GCC now supports "sibling calls", i.e. tail call optimization
for tail calls that are not directly recursive, but which instead call
a different function.
There are still some limitations, e.g. (1) it doesn't work for varargs
function calls, (2) it doesn't work if you have taken the address of a
local variable, and (3) I think it doesn't always work if the caller
argument types don't match the callee argument types. But the situation
is a lot better than in GCC < 3.0.
For (2) it is fairly straight-forward to add a hook to GCC's interface
with the language front-end to allow the front-end to tell GCC to do
an optimized tail call even if the optimization appears unsafe, due to
taking the address of local variables. I have a patch floating around
somewhere against a pre-3.0 version of GCC that implements that, although
I have yet to merge that change into 3.0 or the latest development sources,
or to test it thoroughly.
Problems (1) and (3) are very hard to solve with standard calling
conventions, but someone else on the GCC list said they were working on
implementing a special calling convention that would solve those problems.
(Routines using this calling convention would have to be marked with
a function attribute and would not be compatible with the standard
calling convention.) I don't know how far that work has progressed.
> What would be cooler is if the GCC internals were extended to provide
> the expressive power of C--.
I proposed on the GCC list a few months ago that GNU C be extended with
support for forcing tail calls even if the address of a local variable
was taken. There was considerable discussion, some in favour of it, some
against, but the eventual concensus was that it should first be added
as a hook in GCC's interface with the compiler front-end, and only after
that change was integrated into GCC should we consider extending GNU C.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: < http://www.cs.mu.oz.au/~fjh > | -- the last words of T. S. Garp.
More information about the Gcc
mailing list