This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: On inlining in C++

Richard Guenther wrote:
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

Sure, in principle. In theory. But that doesn't help today. I am with you when the compiler can _prove_ its decisions.

- 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.

- 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).

I talked about the total time over the full run of the program. If one saves half of a micro second, it is not worth the trouble.

- 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.

Of course there is:

inline void inline_f() {
// actual code

void noinline_f()

Then you can decide at each call if you want inlining or not. Or take
the pow() example from the beginning of the thread. It doesn't really matter
if it gets inlined for constant exponents, say pow(x,2), because everybody
already has functions pow2(x), pow3(x), ... :-)

Thomas Kunert

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]