public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How does inline definitions affect inlining heuristics for C++?
@ 2012-10-29 12:14 Ulf Magnusson
  2012-10-30  6:30 ` Ángel González
  0 siblings, 1 reply; 2+ messages in thread
From: Ulf Magnusson @ 2012-10-29 12:14 UTC (permalink / raw)
  To: gcc-help

Hi,

When not using whole program or link-time optimization, the body of a
function must be available to the compiler for it to be able to inline
calls the function when compiling a TU. Hence, you might want to put a
function that is used in multiple TUs in a header file to give the
compiler the opportunity to inline it. However, this forces you to
make the function inline, as multiple definitions of non-inline
functions is not allowed. It seems inline might be used for two
different purposes here:

(1) To make the function body available to the compiler to give it the
opportunity to inline.
(2) To give the compiler a hint to inline the function.

But what if you trust the compiler to make the right decision for the
function and don't want to influence the inlining heuristics? I.e.,
what if you only want (1) and not (2)?

Which brings me to my questions:

 - How does making a function inline influence GCC's inlining
heuristics for C++?
 - If it does influence the inlining heuristics in some significant
way, then is there some way to get (1) without (2) being forced upon
you?

(Oh, and please point out if I lied anywhere. :)

Cheers,
Ulf

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

* Re: How does inline definitions affect inlining heuristics for C++?
  2012-10-29 12:14 How does inline definitions affect inlining heuristics for C++? Ulf Magnusson
@ 2012-10-30  6:30 ` Ángel González
  0 siblings, 0 replies; 2+ messages in thread
From: Ángel González @ 2012-10-30  6:30 UTC (permalink / raw)
  To: Ulf Magnusson; +Cc: gcc-help

On 28/10/12 14:12, Ulf Magnusson wrote:
> Hi,
>
> When not using whole program or link-time optimization, the body of a
> function must be available to the compiler for it to be able to inline
> calls the function when compiling a TU. Hence, you might want to put a
> function that is used in multiple TUs in a header file to give the
> compiler the opportunity to inline it. However, this forces you to
> make the function inline, as multiple definitions of non-inline
> functions is not allowed. It seems inline might be used for two
> different purposes here:
>
> (1) To make the function body available to the compiler to give it the
> opportunity to inline.
> (2) To give the compiler a hint to inline the function.
>
> But what if you trust the compiler to make the right decision for the
> function and don't want to influence the inlining heuristics? I.e.,
> what if you only want (1) and not (2)?
>
> Which brings me to my questions:
>
>  - How does making a function inline influence GCC's inlining
> heuristics for C++?
>  - If it does influence the inlining heuristics in some significant
> way, then is there some way to get (1) without (2) being forced upon
> you?
>
> (Oh, and please point out if I lied anywhere. :)
>
> Cheers,
> Ulf
I guess you may place the function in the common section so that both
instances can get coalesced.
Still, that's not something I'd encourage you to do.

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

end of thread, other threads:[~2012-10-28 15:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-29 12:14 How does inline definitions affect inlining heuristics for C++? Ulf Magnusson
2012-10-30  6:30 ` Ángel González

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