Program-wide Analysis and Optimization
4-5
4
NOTE. The optimized replacements for fee.o and foo.o are present in
the linked program but never appear in the current working directory.
Profiling Your Program
Compiling for Profile Instrumentation with -fprof
As mentioned above, information on the runtime behavior of the program
can be used by the compilation system during the global decision making
and optimization step. To instrument a program, use the
fprof option in
addition to
fdb when compiling:
ic960 -Yd,mypdb -fdb -fprof -c foo.c
See Chapters 2 and 3 for more on the fprof option. This command causes
profile instrumentation to be inserted into
foo.o so that when the linked
program is executed, a profile can be collected. Using runtime profiles to
influence the final optimization of your program requires you to build the
program twice: once to insert the instrumentation, as described here, and
then again so that the compilation system can substitute modules that are
recompiled with optimizations appropriate to their runtime behavior.
Collecting a Profile
If
a program that contains one or more modules compiled with fprof is
linked with the standard libraries and then executed, a file named
default.pf containing the profile for those modules is automatically
produced when the program exits. This is a “raw” profile containing
program counters that log how many times various statements in the
source program have been executed.
If you are not using the standard libraries, you must insert a call to a
routine that creates the profile in an appropriate point in the program
source code. For instructions on this step, see the section titled Runtime
Support for Profile Collection (page 4-15).