HP C Programmer's Guide (92434-90009)

70 Chapter4
Optimizing HP C Programs
Profile-Based Optimization
%cc -o sample.exe +I +03 sample.o
%sample.exe < input.file1
%mv flow.data /users/profile/prog.data
%cc -o sample.exe +df /users/profiles/prog.data +P +03 sample.o
Maintaining Instrumented and Optimized Program Files
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
%cc -o sample.inst +I +03 sample.o
%sample.inst < input.file1
%cc -o sample.opt +P +03 +pgm sample.inst sample.o
Profile-Based Optimization Notes
When using profile-based optimization, please note the following:
Because the linker performs code generation for profile-based optimization, linking
object files compiled with +I and +P takes more time than linking ordinary object files.
However, compile-times will be relatively fast. This is because the compiler is only
generating the intermediate code.
Profile-based optimization has a greater impact on application performance at each
higher level of optimization.
Profile-based optimization should be enabled during the final stages of application
development. To obtain the best performance, re-profile and re-optimize your
application after making source code changes.
If you use level-4 or profile-based optimization and do not use +DA to generate code for a
specific version of PA-RISC, note that code generation occurs at link time. Therefore,
the system on which you link, rather than compile, determines the object code
generated.
If you use level-4 or profile-based optimization and do not use +DS to specify instruction