Using Profile-guided Optimization

The following is an example of the basic PGO phases:

Instrumentation Compilation and Linking

Use -prof_gen[x] to produce an executable with instrumented information.

IA-32 Systems

prompt>icc -prof_gen -c a1.cpp a2.cpp a3.cpp
prompt>
icc a1.o a2.o a3.o

Itanium(TM)-based Systems

prompt>ecc -prof_gen -c a1.cpp a2.cpp a3.cpp
prompt>
ecc a1.o a2.o a3.o

In place of the second command, you could use the linker directly to produce the instrumented program.

Instrumented Execution

Run your instrumented program with a representative set of data to create a dynamic information file.

prompt>a.out

The resulting dynamic information file has a unique name and .dyn suffix every time you run a.out. The instrumented file helps predict how the program runs with a particular set of data. You can run the program more than once with different input data.

Feedback Compilation

Compile and link the source files with -prof_use to use the dynamic information to optimize your program according to its profile:

 IA-32 Systems

prompt>icc -prof_use -ipo a1.cpp a2.cpp a3.cpp
 

Itanium(TM)-based Systems

prompt>ecc -prof_use -ipo a1.cpp a2.cpp a3.cpp

Besides the optimization, the compiler produces a pgopti.dpi file. You typically specify the default optimizations (-O2) for phase 1, and specify more advanced optimizations (-ip or -ipo) for phase 3. This example used -O2 in phase 1 and -O2 -ip in phase 3.

Note

The compiler ignores the -ip or the -ipo options with -prof_gen[x].