User: Password:
|
|
Subscribe / Log in / New account

Who is the best inliner of all?

Who is the best inliner of all?

Posted Jan 15, 2009 14:03 UTC (Thu) by kpfleming (subscriber, #23250)
Parent article: Who is the best inliner of all?

In addition, as I've been playing with GCC 4.3's --combine and -fwhole-program options lately over various code bases, I've found two things:

- GCC does an amazing job of poring over a complete 'program' and optimizing it when given the chance. Most programs (for perfectly valid reasons) are broken up into many source files for ease of maintenance, but this removes a large number of optimization opportunities. In the kernel, this means that the only functions that will ever be inlined are those defined in header files, so in a subsystem or driver that consists of 20+ sources files, when 50% of the functions in those files have only one or two call sites, they still don't get inlined.

- Allowing more aggressive optimization has actually found real bugs in some of the code bases I've been working on, as the compiler has been able to see inside called functions and then report useful things like uninitialized variable usage that it could not do before.


(Log in to post comments)

Who is the best inliner of all?

Posted Jan 15, 2009 14:56 UTC (Thu) by dwmw2 (subscriber, #2063) [Link]

"GCC does an amazing job of poring over a complete 'program' and optimizing it when given the chance. Most programs (for perfectly valid reasons) are broken up into many source files for ease of maintenance, but this removes a large number of optimization opportunities."
For the Linux kernel, this is especially true in file system code, I believe. At http://lwn.net/Articles/197097/ there is a reference to some work I did a while back on building the kernel with -fwhole-program --combine.

I should dig that out again.

"- Allowing more aggressive optimization has actually found real bugs in some of the code bases I've been working on, as the compiler has been able to see inside called functions and then report useful things like uninitialized variable usage that it could not do before."
Shows up a few compiler bugs too...

Who is the best inliner of all?

Posted Jan 16, 2009 19:16 UTC (Fri) by giraffedata (subscriber, #1954) [Link]

In the kernel, this means that the only functions that will ever be inlined are those defined in header files,

What about the the functions in the same .c file as their callers? There are plenty of those in the kernel.

Does -combine totally combine, like #including all the files into a master file, or does it keep them properly modular? I hate having inline functions in header files because the problems of interference between the header file and the file into which it is #included limits what the inline function can do. But if -combine solves that problem, I can see having usable source code libraries.

Who is the best inliner of all?

Posted Jan 16, 2009 21:02 UTC (Fri) by kpfleming (subscriber, #23250) [Link]

Sorry, I was unclear there: I should have said that the only functions *except those in the same source file*.

Regarding -combine, essentially what happens is that each source file is run through cpp separately, then the results are concatenated and fed to the compiler. This avoids preprocessor-level conflicts.

However, keep in mind that -combine alone, while it does provide some benefit, doesn't accomplish most of the desired result. -fwhole-program does that, because when there are multiple source modules, most of the functions will *not* be 'static', as they are cross-module references, and this can interfere with optimization and (especially) inlining. -fwhole-program overrides this, and forces everything to be 'static' scope except those items that are marked with the 'externally_visible' attribute. To gain the most benefits, you need to use both.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds