| United States-English |
|
|
|
![]() |
HP C/HP-UX Programmer's Guide: HP-UX Systems > Chapter 4 Optimizing
HP C Programs Profile-Based Optimization |
|
Profile-based optimization (PBO) is a set of performance-improving code transformations based on the run-time characteristics of your application. There are three steps involved in performing this optimization:
Invoke profile-based optimization through HP C by using any level of optimization and the +I and +P options on the cc command line. When you use PBO, compile times are faster and link times are slower because code generation happens at link time. To instrument your program, use the +I option as follows: cc -Aa +I -O -c sample.c cc -o sample.exe +I -O sample.o The first command line uses the -O option to perform level 2 optimization and instruments the code. The -c option in the first command line suppresses linking and creates an intermediate object file called sample.o. The.o file can be used later in the optimization phase, avoiding a second compile. The second command line uses the -o option to link sample.o into sample.exe. The +I option instruments sample.exe with data collection code. Note that instrumented programs run slower than non-instrumented programs. Only use instrumented code to collect statistics for profile-based optimization. To collect execution profile statistics, run your instrumented program with representative data as follows: sample.exe < input.file1 sample.exe < input.file2 This step creates and logs the profile statistics to a file, by default called flow.data. You can use this data collection file to store the statistics from multiple test runs of different programs that you may have instrumented. To optimize the program based on the previously collected run-time profile statistics, relink the program as follows: cc -o sample.exe +P -O sample.o An alternative to this procedure is to recompile the source file in the optimization step: cc -o sample.exe +I -0 sample.c sample.exe < input.file1 cc -o sample.exe +P -O sample.c Profile-based optimization stores execution profile data in a disk file. By default, this file is called flow.data and is located in your current working directory. You can override the default name of the profile data file. This is useful when working on large programs or on projects with many different program files. You can use the FLOW_DATA environment variable to specify the name of the profile data file with either the +I or +P options. You can use the +df command-line option to specify the name of the profile data file with the +P option. The +df option takes precedence over the FLOW_DATA environment variable. In the following example, the FLOW_DATA environment variable is set to override the flow.data file name. The profile data is stored instead in /users/profiles/prog.data. % setenv FLOW_DATA /users/profiles/prog.data In the next example, the +df option uses /users/profiles/prog.data to override the flow.data file name. % cc -Aa -c +I +O3 sample.c You can maintain both instrumented and optimized versions of a program. You might keep an instrumented version of the program on hand for development use, and several optimized versions on hand for performance testing and program distribution. Care must be taken when maintaining different versions of the executable file because the instrumented program file name is used as the key identifier when storing execution profile data in the data file. The optimizer must know what this key identifier name is in order to find the execution profile data. By default, the key identifier name used to retrieve the profile data is the instrumented program file name used to run the program for data collection. When you optimize a program file and the optimized program file name is different from the instrumented program file name, you must use the +pgm option. Specify the instrumented program file name with this option. The optimizer uses this value as the key identifier to retrieve execution profile data. In the following example, the instrumented program file name is sample.inst. The optimized program file name is sample.opt. The +pgm name option is used to pass the instrumented program name to the optimizer: % cc -Aa -c +I +O3 sample.c When using profile-based optimization, please note the following:
For more information on profile-based optimization, see the HP-UX Linker and Libraries Online User Guide. HP C compiler provides the flexibility of choosing to generate PA-RISC machine code (SOMs) directly instead of the compiler’s intermediate code (ISOMs) during the compilation phase itself. The existing behavior of the compiler has been to generate intermediate code when PBO options (+I, +P) are used and the final code generation will happen during link-phase, unless +Oreusedir= is used. At this stage, linker calls ucomp. An obvious disadvantage is, even when a single file is changed code generation for all other files will happen during link-phase. This makes the overall compile-link time significantly high. As an enhancement to the current behavior, compiler will generate the PA-RISC machine code (SOM) whenever the newly introduced PBO options are used. This does not require code generation to happen during link-phase as the compiler itself would have converted the intermediate code (ISOM) into machine code (SOM) by calling ucomp. The following lists the newly introduced PBO options:
The above new options correspond to (though building SOMs instead of ISOMs):
As seen above, the behavior of the new +Oprofile options are equivalent to the existing PBO options. Except that whenever +Oprofile is used compiler calls ucomp to convert intermediate code into machine code. Performing PBO as earlier is not changed. There is no behavior change when +I/+P and any other old options are used in the command line. The cc driver calls ld to generate ISOMs. The options +pgm and -tu will work with the new options.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||