This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Inlining heuristics for C++
On 09-Jul-2001, Mark Mitchell <mark@codesourcery.com> wrote:
>
> One long-term challenge is that we would like to inline when somehow
> that allows major simplifications. For example, if there is a giant
> function involving tons of calcuation, but we know that the argument
> is `3', and that means we can fold all the calculations, then we
> should do the inlining, even if the inlined function is nominally
> giant. I have no idea how to do this, though. It's probably not worth
> bothering about.
Another, similar case when you really want to inline are when the body
of the function contains a call to a virtual method (or other indirect
function call) and the type of the object and hence its vtable
(or the value of the function pointer) is known in the caller.
That's handy because you can then inline the virtual method
(or indirect function call), which may lead to further opportunities
for simplification.
For some applications this can really pay off significantly,
so it is worth doing in the long run, although right now
it's probably more important on just fixing the most egregariously
bad heuristics rather than trying
We do some of this kind of stuff in the Mercury compiler. For example,
we specialize function calls where one of the parameters is a known
higher-order term (a.k.a. closure; think of it as a known function
pointer). We also do "deforestation" optimization, which is
related to this idea of specializing calls where the caller has
information about a decision (e.g. a switch) in the callee.
There's a paper [1] on our web page which describes those and
some of the other optimizations that we do.
[1] "Optimization of Mercury programs", Simon Taylor,
Honours Report, The University of Melbourne, 1998.
<http://www.cs.mu.oz.au/research/mercury/information/papers/stayl_hons.ps.gz>
--
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.