HP aC++/HP C A.06.20 Programmer's Guide

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 201)
“Setting Basic Optimization Levels” (page 201)
Additional Options for Finer Control” (page 202)
“Profile-Based Optimization” (page 204)
“Pragmas That Control Optimization” (page 207)
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.
Requesting Optimization 201