Related articles |
---|
Detailed algorithms on inline optimization pengyu.ut@gmail.com (Peng Yu) (2010-01-18) |
Re: Detailed algorithms on inline optimization bobduff@shell01.TheWorld.com (Robert A Duff) (2010-01-19) |
Re: Detailed algorithms on inline optimization holgersiegel74@yahoo.de (Holger Siegel) (2010-01-20) |
Re: Detailed algorithms on inline optimization bobduff@shell01.TheWorld.com (Robert A Duff) (2010-01-19) |
Re: Detailed algorithms on inline optimization gneuner2@comcast.net (George Neuner) (2010-01-19) |
Re: Detailed algorithms on inline optimization miles@gnu.org (Miles Bader) (2010-01-20) |
Re: Detailed algorithms on inline optimization rangsynth@gmail.com (Robin Holmes) (2010-01-20) |
Re: Detailed algorithms on inline optimization jeremy.wright@microfocus.com (Jeremy Wright) (2010-01-20) |
Re: Detailed algorithms on inline optimization dot@dotat.at (Tony Finch) (2010-01-21) |
Re: Detailed algorithms on inline optimization bear@sonic.net (Ray) (2010-01-21) |
Re: Detailed algorithms on inline optimization bobduff@shell01.TheWorld.com (Robert A Duff) (2010-01-21) |
Re: Detailed algorithms on inline optimization cdodd@acm.org (Chris Dodd) (2010-01-23) |
Re: Detailed algorithms on inline optimization mcrodgers@gmail.com (Martin Rodgers) (2010-01-24) |
Re: Detailed algorithms on inline optimization anton@mips.complang.tuwien.ac.at (2010-01-25) |
[6 later articles] |
From: | Jeremy Wright <jeremy.wright@microfocus.com> |
Newsgroups: | comp.compilers |
Date: | Wed, 20 Jan 2010 09:59:18 +0000 (UTC) |
Organization: | Compilers Central |
References: | 10-01-063 |
Keywords: | code, optimize |
Posted-Date: | 21 Jan 2010 01:00:37 EST |
>> [True. Does anyone do that, inline the first few times though and
>> then punt to the normal routine? -John]
Muchnick (Advanced Compiler Design and Implementation) proposes that
the "normal" version of actually is inlined once or twice. This
reduces the number of recursive calls by a factor of about 2 ( or 3)
and gives you all the advantages of function inlining for each logical
recursion.
> Yeah, I was kind of impressed by the Verdix Ada compiler (years ago).
> A recursive Factorial function, something like:
>
> function Factorial (N : Natural) return Positive is
> begin
> if N = 0 then
> return 1;
> else
> return N * Factorial(N-1);
> end if;
> end Factorial;
> And then a call like "X := Factorial(7);" would compile into a "move
> 5040 into X" instruction. It had inlined 7 levels, and then
> constant-folded it. Factorial(8) didn't do that.
>
> I think 7 levels is excessive -- I'd choose 1, or maybe 2, because
> you're not normally going to be able to constant-fold the whole thing
> away.
You could do this by an analogous method to loop peeling. Inline
f(n). If the code expansion is within a limit, then inline f(n - 1)
and so on. For factorial, there will be no code expansion after the
first inline, and so it will continue until there are no calls left.
Jeremy Wright
Return to the
comp.compilers page.
Search the
comp.compilers archives again.