Compiling C/C++ Code
3-5
Optimizing C/C++ Code
The options in Table 3–2 can improve performance but require certain charac-
teristics to be true, and are described below.
Table 3–2. Compiler Options for Performance
Option
Description
–o3
†
Represents the highest level of optimization available. Various
loop optimizations are performed, such as software pipelining,
unrolling, and SIMD. Various file level characteristics are also
used to improve performance.
–oi0
Disables all automatic size–controlled inlining, (which is en-
abled by –o3). User specified inlining of functions is still al-
lowed.
–pm
‡
Combines source files to perform program–level optimization by
allowing visibility to the entire application source.
† Although –o3 is preferable, at a minimum use the –o option.
‡ Use the –pm option for as much of your program as possible.
Table 3–3. Compiler Options That Slightly Degrade Performance and Improve Code Size
Option
Description
–mh <
n >
Allows speculative execution. The appropriate amount of pad-
ding must be available in data memory to insure correct execu-
tion. This is normally not a problem but must be adhered to.
–mi <
n>
Describes the interrupt threshold to the compiler. If you know
that NO interrupts will occur in your code, the compiler can
avoid enabling and disabling interrupts before and after soft-
ware pipelined loops for a code size and performance improve-
ment. In addition, there is potential for performance improve-
ment where interrupt registers may be utilized in high register
presure loops.
–ms0
–ms1
Optimizes primarily for performance, and secondly for code
size. Could be used on all but the most performance critical
routines.
–mt
Enables the compiler to use assumptions that allow it to be
more aggressive with certain optimizations. When used on lin-
ear assembly files, it acts like a .no_mdep directive that has
been defined for those linear assembly files.
–op2
Specifies that the module contains no functions or variables that
are called or modified from outside the source code provided to
the compiler. This improves variable analysis and allowed as-
sumptions.