HP aC++/HP C A.06.28 Programmer's Guide Integrity servers (769150-001, March 2014)

7 Optimizing HP aC++ Programs
HP C/HP aC++ provides options to the aCC command and pragmas to control optimization. The
following sections introduce the basic concepts of optimizing your HP aC++ code for improved
efficiency:
“Requesting Optimization” (page 156)
“Setting Basic Optimization Levels” (page 156)
Additional Options for Finer Control” (page 157)
“Profile-Based Optimization” (page 158)
“Pragmas That Control Optimization” (page 160)
Requesting Optimization
By default, the compiler performs constant folding and simple register assignment. There are several
ways to increase and control the level of optimization performed on your program.
Setting Basic Optimization Levels
HP aC++ provides four basic levels of optimization, the higher the level the more optimization
performed and the longer the optimization takes.
You can specify an option on the aCC command line or in the CXXOPTS environment variable.
Example:
aCC -O prog.C
Compiles prog.C and optimizes the program at the default level 1.
Level 1 Optimization
Level 1 optimization includes branch optimization, dead code elimination, faster register allocation,
instruction scheduling, and peephole (statement-by-statement) optimization. Use +O1 to get level
1 optimization. Level 1 is the default.
Level 1 optimization produces faster programs than without optimization and compiles faster than
level 2 optimization. Programs compiled at level 1 can be used with the HP Distributed Debugging
Environment (DDE) debugger. Use the debugger option -g0 or -g1.
Level 2 Optimization
Level 2 optimization includes level 1 optimization, along with optimizations performed over entire
functions in a single file. Level 2 optimizes loops in order to reduce pipeline stalls and analyzes
data-flow, memory usage, loops, and expressions. Use -O or +O2 to get level 2 optimization.
Specifically, level 2 provides the following:
Coloring register allocation.
Induction variable elimination and strength reduction.
Local and global common subexpression elimination.
Advanced constant folding and propagation. (Simple constant folding is done by default.)
Loop invariant code motion.
Store/copy optimization.
Unused definition elimination.
156 Optimizing HP aC++ Programs