public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Inlining heuristics for C++
@ 2001-07-10 14:53 mike stump
  2001-07-10 15:04 ` Daniel Berlin
  0 siblings, 1 reply; 28+ messages in thread
From: mike stump @ 2001-07-10 14:53 UTC (permalink / raw)
  To: dan, gcc

> To: gcc@gcc.gnu.org
> From: Daniel Berlin <dan@cgsoftware.com>
> Date: Mon, 09 Jul 2001 21:46:59 -0400

> Right now, they are horrific.

You should have seen it before we limited the growth of the function
being inlined into.  :-(

Anyway, would be nice if someone could take a pass through the
literature and find the good stuff that describes when to do it and
when not to and give us pointers to it.

^ permalink raw reply	[flat|nested] 28+ messages in thread
* Re: Inlining heuristics for C++
@ 2001-07-09 21:49 dewar
  2001-07-09 22:17 ` Daniel Berlin
  0 siblings, 1 reply; 28+ messages in thread
From: dewar @ 2001-07-09 21:49 UTC (permalink / raw)
  To: carlo, dan; +Cc: gcc

<<to thank you for writing this (I mean that).  I am reassured too, that
functions marked as inline still WILL be inlined.  If you add point 2)
>>

Personally, I don't feel that such reassurance is necessary. Obviously
a compiler is not required to inline things that are marked as inlined
(since basically inlining is semantically neutral). It is perfectly
reasonable for a compiler to take an inlining request as basically
a request to inline *if* time performance is improved, I think it is
always fine for a compiler to ignore an inlining request if inlining
would be detrimental to both time and space performance.

^ permalink raw reply	[flat|nested] 28+ messages in thread
* Re: Inlining heuristics for C++
@ 2001-07-09 20:13 dewar
  2001-07-09 20:23 ` Joe Buck
  0 siblings, 1 reply; 28+ messages in thread
From: dewar @ 2001-07-09 20:13 UTC (permalink / raw)
  To: dan, fjh; +Cc: gcc

Generally there is no point in inlining large functions at all. The 
overhead these days of a call is not that great. 10,000 insns seems
a silly limit, perhaps two orders of magnitude two large.

The style in Ada is for people to use pragma Inline to specify what should
be inlined, and programmers generally specify only very small functions for
inlining.

We consistently find that the use of -O3 is a bad idea and pessimizes most
code, we advise all our users against using any implicit inlining. This is
with GCC 2.8.1, but I would guess that the same advice applies (perhaps even
more so) to GCC 3.x (we have not made -O3 measurements here with Ada).

^ permalink raw reply	[flat|nested] 28+ messages in thread
* Inlining heuristics for C++
@ 2001-07-09 18:47 Daniel Berlin
  2001-07-09 19:22 ` Fergus Henderson
                   ` (3 more replies)
  0 siblings, 4 replies; 28+ messages in thread
From: Daniel Berlin @ 2001-07-09 18:47 UTC (permalink / raw)
  To: gcc

Right now, they are horrific.

As I recently posted, a simple 5 line C++ program using map and string
in normal ways gets inlined from 300 insns to 15k.

This is because we have a few major deficiencies in our inlining
heuristics.

Mainly, we never consider *not* inlining something unless we can't for some
reason (IE it's a varargs function), or we've hit the limit of a
supposed 10000 insns (which really translated into 15k in reality).

Consider the following:

1 main function.

using namespace std;
int main(void)
{
        map<string, string> simple;
        simple["test"]="test";
}

We'll ignore what happens if we init with arguments that could be
inlined. 

We proceed to recursively inline 128 functions into this simple main function
operator call. (Bet you didn't think there were 128 functions you could
inline here)

Why?
Because we never make *any* choices.
Until main is 15k insns long, we won't stop inlining.

We literally inline *everything* we still have the tree's for.

We'll even inline if say, the destruction function for foo or a string
is 50 times bigger than the function it's being inlined into.

I've got a very simple heuristic that says "don't inline things <some
configurable number currently defaulting to 10> times bigger than we
were when we started inlining, into us" I.E. don't inline a 100
statement function into a 10 statement one.

This is effectively expressing the rule: "Small functions should be
inlined into larger ones.  Larger functions should not be inlined into
small ones".

Where what is considered "larger" is fudged by a factor.

If you have a one line member, that calls a huge function, whatever
*calls* that member will inline the member, and then whatever that member calls
will probably beinlined, but the the externally visible member call itself (ie the non-inlined one) will not
inline the huge function into itself.

Which seems to make sense to me.

However, this doesn't control code growth, it could inline a lot of
small functions until it hits the limit.

So the other heuristic i've added controls code growth by saying we don't
want to increase the number of statements in the function by more than
a factor of x over what we started with (when we started inlining).

An expression of the rule: "Don't make the function more than x times bigger than
it originally was".

By comparison, Right now we only have one rule "Don't make the function larger than
MAX_INLINE_INSNS".

So we end up, even with simple looking code, with functions that are
generally MAX_INLINE_INSNS long.

And take *forever* to compile.

Are these generally acceptable heuristics to add?
They seem pretty common sense to me, maybe i'm missing something
however, I wanted to check before I submitted a patch.
They certainly reduce compile time, and only seem to stop inlining
huge functions into smaller ones. Which are the cases where the
performance probably didn't increase, since we are recursively
inlining (and thus, if there were relatively larger functions calling
the smaller one, both the smaller one, and what it called, would be
inlined back into that function, obviating the real need to inline the
larger into the smaller on it's own). 

--Dan
-- 
"I can levitate birds.  No one cares.
"-Steven Wright

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2001-07-11 14:27 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <87r8vpo8rw.fsf@cgsoftware.com.suse.lists.egcs>
     [not found] ` <20010710122244.A14584@hg.cs.mu.oz.au.suse.lists.egcs>
2001-07-10  2:42   ` Inlining heuristics for C++ Andi Kleen
2001-07-10 14:16     ` Hartmut Schirmer
2001-07-11 14:27       ` Fergus Henderson
2001-07-10 14:53 mike stump
2001-07-10 15:04 ` Daniel Berlin
  -- strict thread matches above, loose matches on Subject: below --
2001-07-09 21:49 dewar
2001-07-09 22:17 ` Daniel Berlin
2001-07-09 20:13 dewar
2001-07-09 20:23 ` Joe Buck
2001-07-09 18:47 Daniel Berlin
2001-07-09 19:22 ` Fergus Henderson
2001-07-09 20:18   ` Daniel Berlin
2001-07-09 23:30   ` Mark Mitchell
2001-07-09 19:56 ` Carlo Wood
2001-07-09 20:31   ` Daniel Berlin
2001-07-09 21:05     ` Carlo Wood
2001-07-09 21:26       ` Daniel Berlin
2001-07-09 21:45         ` Carlo Wood
2001-07-09 20:05 ` Timothy J. Wood
2001-07-09 20:34   ` Daniel Berlin
2001-07-09 23:26 ` Mark Mitchell
2001-07-09 23:37   ` Daniel Jacobowitz
2001-07-10  0:00   ` Fergus Henderson
2001-07-10  0:13     ` Daniel Berlin
2001-07-10  0:09   ` Daniel Berlin
2001-07-10  0:20   ` Daniel Berlin
2001-07-10  0:30   ` Daniel Berlin
2001-07-10  2:47   ` Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).