Monday Feb 16, 2009

Feedback

Another useful optimization option available with Sun Studio compilers is profile feedback.

This option can be especially helpful with codes that contain a lot of branching. The compiler is unable to determine from the source code alone which branches in an IF or CASE statement are the most likely to be taken. Using the profile feedback feature, you can run an instrumented version of the code using typical data to collect statistics on code coverage and branching, and then recompile the code using this collected data.

Darryl Gove has a great description of profile feedback in his book Solaris Application Programming.

With profile feedback, the compiler is better able to do certain optimizations that it cannot do by just analyzing the source code:

  • Layout the compiled code so that branches are rarely taken. The most frequent branches "fall-through" to the next memory location, avoiding a fetch and branch to a distant location.
  • Inline routines called many times. This avoids costly function calls.
  • Move infrequently executed code out of the "hot" parts of the code. This improves utilization of the instruction cache.
  • Lots more optimizations based on how variables are and are not utilized, based on the mostly likely paths the program will take

Of course, all these optimizations will depend on the typicality of the test data collected in the profile. Some cases it might be useful to identify a set of "typical data", collect data for each set, and compile multiple versions using each profile. Of course, this all depends on the application.

To use profile feedback, the compilation is in three phases:

  1. Compile with -xprofile=collect to produce an instrumented executable.
  2. Run the instrumented executable with a typical data set to create a performance profile.
  3. Recompile with -xprofile=use and -xO5 to produce the optimized executable

 % cc -xO3 -xprofile=collect:/tmp/profile myapp.c
 % a.out
 % cc -xO5 -xprofile=use:/tmp/profile -o myapp myapp.c


Read about profile feedback in the compiler man pages: C++, C, Fortran
About


Deep thoughts on compiling C, C++, and Fortran codes with Oracle Solaris Studio compilers, especially optimization and parallelization, from the Solaris Studio documentation lead, Richard Friedman. Email him at
Richard dot Friedman at Oracle dot com

When Run Was A Compiler

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today