This is the mail archive of the
mailing list for the GCC project.
Re: On inlining in C++
- From: Richard Guenther <rguenth at tat dot physik dot uni-tuebingen dot de>
- To: Thomas Kunert <kunert at physik dot tu-dresden dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 5 Aug 2003 10:19:14 +0200 (CEST)
- Subject: Re: On inlining in C++
> As a C++ programmer I would like to ask you to retain a mechanism to tell
> the compiler "Inline at least everything I marked as inline." Currently,
> this mechanism is -finline-limit=1000000.
> Correct decisions about efficient inlining depend on many parameters the
> compiler does not know, e.g.
In general the compiler could know, at least if including profiling
> - How much time takes one call of the function. This time in general depends
> on the actual parameters and cannot be guessed by the compiler.
For constants it knows, for others we'd have value range profiling.
>- How much total time does the code spent in the function. If this time is
> only a few micro seconds, there is absolutely no point in inlining.
No, its the other way around - if the time spent in the function is very
short, its a good candidate for inlining (because function call overhead
may be comparable to actual runtime).
>- From how many places the function is being called throughout the program.
> - How often the function is called from a certain position.
> The programmer has the complete picture. He has an idea about the actual
> parameters passed to the function. He can actually measure the time.
> He knows if some function is critical or not.
For the last two points you made the problem is, that there is no
(portable) way to tell the compiler to inline into certain positions or in
certain cases. It is only the compiler that can do this sort of context
dependend inlining decision.
> Maybe someday in the distant future compilers are smart enough to find out
> these things. But currently I strongly prefer to control inlining myself,
> because in most cases I know better. The compiler should be allowed to
> overrule my decision only if it can prove me wrong.
The C++ standard does not specify a way to tell (or hint) the compiler to
inline a certain function call. So for a large amount of cases you
absolutely _have_ to rely on the compiler to decide. Or you'll pay for at
Richard Guenther <richard dot guenther at uni-tuebingen dot de>