Re: Automatic accessor function inlining

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



LRN wrote:
file1.c:
static int _foobar;
int get_foobar () { return _foobar; }

file2.c:
...
   int x = get_foobar ();

Question: will gcc inline get_foobar()?

Without LTO (link-time optimization): No. get_foobar is in a different object file and the compiler has no chance to see this.

That's different if you use instead a macro in the header file (which by construction always is always inlined). The chances for inlining also increase, if you place the function in the header file (especially if you annotate the function to tell the compiler that it should be inlined).

With LTO, the compiler has the chance to inline functions across 'translation units', i.e. different object files. Whether it does depends - as with all inlining - on the optimization options (e.g. -O0 won't inline, -Os often does not inline [optimization for code size], but in your case it probably would) and on the code-size growth with inlining (inlining heuristic, tunable by some flags and parameters).

For LTO, see: http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fwhole_002dprogram-890

LTO is supported since GCC 4.5.

Tobias


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux