A function order list is a text file that specifies the order in which the linker should link the non-static functions of your program. This improves the performance of your program by reducing paging and improving code locality. Profile-guided optimizations support the generation of a function order list to be used by the linker. The compiler determines the order using profile information.
To enable the Intel® C++ Compiler and proforder tool to generate a function order list, you must use the -prof_gen[x] and -prof_dir options described in the table below.
Option | Description |
---|---|
-prof_gen[x] | Generates an instrumented object file and creates a static profile information file (.spi), which contains source position information for the calls of each compiled function. This information, combined with the dynamic profile information from the .dpi file, enables optimized ordering of functions. When you use -prof_gen[x] instead of -prof_gen[x], you can use the proforder tool to create a function order list for the linker. However, -prof_gen[x] also requires more memory at runtime, produces larger .dyn files, and disables execution of parallel make files. |
-prof_dir dirname | Specifies the directory where .dyn files are to be created. The default is the directory where the program is compiled. The specified directory must already exist. You should specify the same -prof_dir option for both the instrumentation and feedback compilations. If you move the .dyn files, you need to specify the new path. |
You will need to use the utilities profmerge and proforder described in Utilities for Profile-Guided Optimization.
Use the following guidelines to create a function order list:
The order list only affects the order of non-static functions.
Do not use -prof_gen[x] to compile two files from the same program simultaneously. This means that you cannot use the -prof_gen[x] option with parallel makefile utilities.
You must compile to enable function-level linking. This option is active when you specify -O, -O1, -O2, or -O3.
Assume you have a C program that consists of files file1.c and file2.c and that you have created a directory for the profile data files in c:/profdata. Do the following to generate and use a function order list.
Compile your program by specifying -prof_gen[x]
and -prof_dir:
IA-32 Systems
prompt>icc -oMYPROG -prof_genx
-prof_dir /home/usr/profdata file1.c file2.c
Itanium(TM)-based Systems
prompt>ecc -oMYPROG -prof_genx
-prof_dir /home/usr/profdata file1.c file2.c
Run the instrumented program on one or more sets
of input data
prompt>./MYPROG
The program produces a .dyn file each time it is executed.
Merge the data from one or more runs of the instrumented
program using the profmerge tool to produce the
pgopti.dpi file.
prompt>profmerge -prof_dir
/home/usr/profdata
Generate the function order list using the proforder tool. By default, the function order list
is produced in the file proford.txt.
prompt>proforder -prof_dir
/home/usr/profdata -o MYPROG.txt
Compile your application with profile feedback
by specifying the -prof_use and the /ORDER
option to the linker. Again, use the -prof_dir
option to specify the location of the profile files.
IA-32 Systems
prompt>icc -oMYPROG -prof_use
-prof_dir /home/usr/profdata file1.c file2.c -link /ORDER:@MYPROG.txt
Itanium(TM)-based Systems
prompt>ecc -oMYPROG -prof_use
-prof_dir /home/usr/profdata file1.c file2.c -link /ORDER:@MYPROG.txt
The Intel C++ Compiler provides two methods of optimizing the layout of functions in the executable:
use of a function order list
use of -ipo
Each method has its advantages. A function order list, created with proforder, enables you to optimize the layout of non-static functions; that is, external and library functions whose names are exposed to the linker. The linker cannot directly affect the layout order for static functions because the names of these functions are not available in the object files.
On the other hand, using -ipo allows you to optimize the layout of all static or extern functions compiled with the Intel C++ Compiler. The compiler cannot affect the layout order for functions it does not compile, such as library functions. The function layout optimization is performed automatically when IPO is active.
Function Type | Code Layout with -ipo | Function Ordering with proforder |
---|---|---|
Static | X | No effect. |
Extern | X | X |
Library | No effect. | X |
As part of the instrumented execution phase of profile-guided optimization, the instrumented program writes profile data to the dynamic information file (.dyn file). The file is written after the instrumented program returns normally from main() or calls the standard C exit function. For programs that do not terminate normally, the _PGOPTI_Prof_Dump function is provided. During the instrumentation compilation ( -prof_gen ), you can add a call to this function to your program. You should add the following function prototype prior to the call:
void _cdec _PGOPTI_Prof_Dump(void);
Note
You must remove the call or comment it out prior to the feedback compilation with -prof_use.