HP C Programmer's Guide (92434-90009)

68 Chapter4
Optimizing HP C Programs
Profile-Based Optimization
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:
1.
Instrumentation
- Insert data collection code into the object program.
2.
Data Collection
- Run the program with representative data to collect execution
profile statistics.
3.
Optimization
- Generate optimized code based on the profile data.
Invoke profile-based optimization through HP C by using any level of optimization and the
+I and +P options on the cc command line.
Compile times will be fast and link times will be slow when using PBO because code
generation happens at link time.
Instrumenting the Code
To instrument your program, use the +I option as follows:
cc -Aa +I -O -c sample.c
Compile for instrumentation.
cc -o sample.exe +I -O sample.o
Link to make instrumented executable.
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.
+O[no]size The +Osize option suppresses optimizations that
significantly increase code size. The +Onosize option
does not prevent optimizations that can increase code
size. The default is +Onosize.
2, 3, 4
a. See <Undefined Cross-Reference> and the following section for details about advanced
optimization options.
Table 4-3. HP C Optimization Parameters
Option What It Does Level of Opt