Using Profile-Guided Optimization: An Example

The following is an example of the basic PGO phases:

1.   Instrumentation Compilation and Linking—Use -prof_gen to produce an executable with instrumented information; for example:

IA-32 applications:

prompt> ifc -prof_gen -c a1.f a2.f a3.f

prompt> ifc a1.o a2.o a3.o

Itanium(TM)-based applications:

prompt>efc -prof_gen -c a1.f a2.f a3.f

prompt>efc a1.o a2.o a3.o

In place of the second command, you could use the linker (ld) directly to produce the instrumented program. If you do this, make sure you link with the libirc.a library.

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

prompt>a1

     The resulting dynamic information file has a unique name and .dyn suffix every time you run a1. 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.

3.   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 applications:

prompt>ifc -prof_use -ipo a1.f a2.f a3.f

Itanium-based applications:

prompt>efc -prof_use -ipo a1.f a2.f a3.f

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 the -ip in phase 3.

Note   
The compiler ignores the -ip or the -ipo options with -prof_gen.

The goal of function splitting is to improve the locality of executed instructions. Function splitting achieves this goal by splitting the non-executed code from the executed code. The executed code is emitted for each function, while the non-executed code is grouped together in a separate text section.