Using the C Compiler
• Level 2 - Optimize more (default): Enables more optimizations to reduce the memory footprint and/or execution time. This is the default optimization level.
• Level 3 - Optimize most: This is the highest optimization level. Use this level when your program/hardware has become too slow to meet your real-time requirements.
• Custom optimization: you can enable/disable specific optimizations on the Custom optimization page.
Optimization pragmas
If you specify a certain optimization, all code in the module is subject to that optimization. Within the C source file you can overrule the C compiler options for optimizations with
#pragma optimize flag and
#pragma endoptimize
. Nesting is allowed:
#pragma optimize e /* Enable expression
... simplification */
... C source ...
...
#pragma optimize c /* Enable common expression
... elimination. Expression
... C source ... simplification still enabled */
...
#pragma endoptimize /* Disable common expression
... elimination */
#pragma endoptimize /* Disable expression
... simplification */
The compiler optimizes the code between the pragma pair as specified.
You can enable or disable the optimizations described in the following subsection. The command line option for each optimization is given in brackets.
4.6.1. Generic Optimizations (frontend)
Common subexpression elimination (CSE) (option -Oc/-OC)
The compiler detects repeated use of the same (sub-)expression. Such a "common" expression is replaced by a variable that is initialized with the value of the expression to avoid recomputation. This method is called common subexpression elimination (CSE).
Expression simplification (option -Oe/-OE)
Multiplication by 0 or 1 and additions or subtractions of 0 are removed. Such useless expressions may be introduced by macros or by the compiler itself (for example, array subscripting).
Constant propagation (option -Op/-OP)
A variable with a known value is replaced by that value.
185