IPO Compilation Model

For the topics in this section, the term IPO generally refers to multi-file IPO.

When you use the -ipo option, the compiler collects information from individual program modules of a program. Using this information, the compiler performs optimizations across modules. In order to do this, the -ipo option is applied to both the compilation phase and the link phase.

One of the main benefits of IPO is that it enables more inlining. For information on inlining and the minimum inlining criteria, see Criteria for Inline Function Expansion and Controlling Inline Expansion of User Functions. Inlining and other optimizations are improved by profile information. For a description of how to use IPO with profile information for further optimization, see Example of Profile-Guided Optimization.

Compilation Phase

When using IPO, as each source file is compiled, the compiler stores an intermediate representation (IR) of the source code in the object file, which includes summary information used for optimization.

By default, the compiler produces "mock" object files during the compilation phase of IPO. Generating mock files instead of real object files reduces the time spent in the IPO compilation phase. Each mock object file contains the IR for its corresponding source file, but no real code or data. These mock objects must be linked using the -ipo option or the xild tool. (See Creating a Multifile IPO Executable with xild.)

Note
Failure to link "mock" objects with the -ipo option or xild will result in linkage errors. There are situations where mock object files cannot be used. See Compilation with Real Object Files for more information.

Linkage Phase

When you invoke the linker, adding -ipo to the command line causes the compiler to be invoked a final time before the linker. The compiler performs IPO across all object files that have an IR. The compiler first analyzes all of the summary information, and then finishes compiling the pieces of the application for which it has IR. Having global information about the application while it is compiling individual pieces can improve the quality of optimization.

Note
The compiler does not support multifile IPO for static libraries (.a files). See Compilation with Real Object Files for more information.

When you use the -ipo option, the compiler attempts to detect a whole program automatically. If a whole program is detected, the interprocedural constant propagation, stack frame alignment, data layout and padding of common blocks perform more efficiently, while more dead functions get deleted. This option is safe.