This topic discusses how to use IPO from a command line. For specific information on using IPO from within an Integrated Development Environment (IDE), refer to the appropriate section in Building Applications.
The steps to enable IPO for compilations targeted for IA-32, Intel® 64, and IA-64 architectures are the same: compile and link.
First, compile your source files with -ipo (Linux* and Mac OS* X) or /Qipo (Windows*) as demonstrated below:
Operating System |
Example Command |
---|---|
Linux and Mac OS X |
icpc -ipo -c a.cpp b.cpp c.cpp |
Windows* |
icl /Qipo /c a.cpp b.cpp c.cpp |
The output of the above example command differs according to operating system:
Linux and Mac OS X: The commands produce a.o, b.o, and c.o object files.
Windows: The commands produce a.obj, b.obj, and c.obj object files.
Use -c (Linux and Mac OS X) or /c (Windows) to stop compilation after generating .o or .obj files. The output files contain compiler intermediate representation (IR) corresponding to the compiled source files. (See the section below on capturing the intermediate IPO output.)
Second, link the resulting files. The following example command will produce an executable named app:
Operating System |
Example Command |
---|---|
Linux and Mac OS X |
icpc -o app a.o b.o c.o |
Windows |
icl /Feapp a.obj b.obj c.obj |
The command invoke the compiler on the objects containing IR and creates a new list of objects to be linked. Alternately, you can use the xild (Linux and Mac OS X) or xilink (Windows) tool, with the appropriate linking options.
The separate compile and link commands demonstrated above can be combined into a single command, as shown in the following examples:
Operating System |
Example Command |
---|---|
Linux and Mac OS X |
icpc -ipo -o app a.cpp b.cpp c.cpp |
Windows |
icl /Qipo /Feapp a.cpp b.cpp c.cpp |
The icl/icpc command, shown in the examples above, calls GCC ld (Linux and Mac OS X) or Microsoft* link.exe (Windows only) to link the specified object files and produce the executable application, which is specified by the -o (Linux and Mac OS X) or /Fe (Windows) option.
Linux and Mac OS X: Using icpc allows the compiler to use standard C++ libraries automatically; icc will not use the standard C++ libraries automatically.
The Intel linking tools emulate the behavior of compiling at -O0 (Linux and Mac OS X) and /Od (Windows).
Multi-file IPO is applied only to the source files that have intermediate representation (IR); otherwise, the object file passes to link stage.
The -ipo-c (Linux and Mac OS X) or /Qipo-c (Windows*) and -ipo-S (Linux and Mac OS X) or /Qipo-S (Windows) options are useful for analyzing the effects of multi-file IPO, or when experimenting with multi-file IPO between modules that do not make up a complete program.
Use the -ipo-c option to optimize across files and produce an object file. The option performs optimizations as described for the -ipo option but stops prior to the final link stage, leaving an optimized object file. The default name for this file is ipo_out.s (Linux and Mac OS X) or ipo_out.obj (Windows).
Use the -ipo-S option to optimize across files and produce an assembly file. The option performs optimizations as described for -ipo, but stops prior to the final link stage, leaving an optimized assembly file. The default name for this file is ipo_out.s (Linux) or ipo_out.asm (Windows).
For both options, you can use the -o (Linux and Mac OS X) or /Fe (Windows) option to specify a different name.
These options generate multiple outputs if multi-object IPO is being used. The name of the first file is taken from the value of the -o (Linux and Mac OS X) or /Fe (Windows) option.
The names of subsequent files are derived from the first file with an appended numeric value to the file name. For example, if the first object file is named foo.o (Linux and Mac OS X) or foo.obj (Windows), the second object file will be named foo1.o or foo1.obj.
You can use the object file generated with the -ipo-c (Linux and Mac OS X) or /Qipo-c (Windows) option, but you will not get the same benefits from the optimizations applied that would otherwise if the whole program analysis condition had been satisfied.
The object file created using the -ipo-c option is a real object file, in contrast to the mock file normally generated using IPO; however, the generated object file is significantly different than the mock object file. It does not contain the IR information needed to fully optimize the application using IPO.
The compiler generates a message indicating the name of each object or assembly file it generates. These files can be added to the real link step to build the final application.
On systems based on IA-64 architecture, the -auto-ilp32 (Linux) or /Qauto-ilp32 (Windows) option specifies interprocedural analysis over the whole program. The option enables specific interprocedural whole-program analysis and then continues with the next statement. Because this optimization requires interprocedural analysis over the whole program, you must use this option with the -ipo (Linux) or /Qipo (Windows) option.
On systems based on Intel® 64 architecture, this option has no effect unless -xSSE3 or -axSSE3 (Linux and Mac OS X) or /QxSSE3 or /QaxSSE3 (Windows) is also specified.