I have read about "Whole Program Optimization" (wpo) and "Link Time Code Generation" (ltcg).
I wonder is there more inter-module-analysis going on if I pass all sources at once to the compiler from the cli (like "g++ a.cpp b.cpp")?
Or is that just going to enable one of those flags?
Is there a difference between compilers for this?
For instance can the intel compiler benefit from such practice while other compilers don't?
I wonder is there more inter-module-analysis going on if I pass all sources at once to the compiler from the cli (like "g++ a.cpp b.cpp")?
For GCC, no, doing that does not enable any WPO, each translation unit is processed separately, in isolation. I'm 99% sure the same is true for Clang, and 90% sure it's true for most other compilers.
With GCC, to enable inter-module optimisation you need to request it explicitly via the -flto
switch, which still processes each translation unit in isolation, but additional information is written to the object file and then when they are linked together further optimisation passes are done to produce the final output.
At least for GCC, yes (if you supply the correct compiler flags).
The compiler performs optimization based on the knowledge it has of the program. Using the -funit-at-a-time
flag will allow the compiler to consider information gained from later functions in the file when compiling a function. Compiling multiple files at once to a single output file (and using -funit-at-a-time
) will allow the compiler to use information gained from all of the files when compiling each of them.
Source: GCC optimization options
Though compiling all filed individually and enabling LTO should conceputally give very similar (or identical) results.
Intel C++ Compiler(ICC) supports this as a part Interprocedural Optimization. As Jonathan mentioned, each source file is compiled with IPO and stores them in a mock object file. Intel linking tool must be used to link the mock object files. During the linking phase, the compiler is invoked for one final time (when build with IPO) to perform interprocedural optimization across all mock object files. More information is available on this is documented at https://software.intel.com/en-us/node/459446.