C251 User's Guide

OPTIMIZE Compiler Directive

Abbreviation

OT

Arguments

A decimal number specifying the optimization level. Valid values are [0..9]. Optional argument.
A string specifying the optimization emphasis, whether on code size or execution speed. Valid values are [SIZE|SPEED]. Optional argument.

Default

OPTIMIZE (7, SPEED)

µVision

Options — C251 Compiler — Optimization — Optimization Level / Emphasis.

Description

The OPTIMIZE directive sets the optimization level and emphasis.

LevelDescription
0Constant Folding: The compiler performs calculations, which reduce expressions to numeric constants where possible. This includes calculations of run-time addresses.

Simple Access Optimizing: The compiler optimizes the access of internal data and bit addresses in the 251 system.

Jump Optimizing: The compiler always extends jumps to the final target. Jumps to jumps are deleted.
1Dead Code Elimination: Unused code fragments and artifacts are eliminated.

Jump Negation: Conditional jumps are closely examined to find out whether they can be streamlined or eliminated by the inversion of the test logic.
2Data Overlaying: Data and bit segments suitable for static overlay are identified and marked internally. The L251 linker/locator has the capability, through global data flow analysis, of selecting segments, which then can be overlaid.

Peephole Optimizing: Redundant MOV instructions are removed. This includes unnecessary loading of objects from the memory as well as load operations with constants. Complex operations are replaced by simple operations when memory space or execution time can be saved.
3Register Variables: Automatic variables and function arguments are located in registers when possible. A reservation of data memory for these variables is omitted.
4Extended Access Optimizing: Variables from the IDATA, XDATA, PDATA and CODE areas are included directly in operations. The use of intermediate registers is not necessary, most of the time.

Local and Global Common Subexpression Elimination: Identical sub-expressions within a function are calculated only once when possible. The intermediate result is stored in a register and used instead of a new calculation.

Case/Switch Optimizing: Code involving switch and case statements is optimized in jump tables or jump strings.
5Life Variable Analysis: Removes redundant and dead store operations to automatic variables.
6Constant Propagation: The values of expressions are tracked and, when possible, constant values are inserted instead of variable accesses.

Peephole Optimizing: Redundant MOV instructions are removed. This includes unnecessary loading of objects from the memory as well as load operations with constants. Complex operations are replaced by simple operations when memory space or execution time can be saved.
7Common Tail Merging and Instruction Simplification: The compiler analyzes the generated code function by function and tries to find common heads and tails. If the compiler detects common code sequences, then it will replace one code sequence by a jump instruction to the other equivalent code sequence. For example, as in switch/case statements. While analyzing the code, the compiler also tries to replace instruction sequences with cheaper instructions.
8Common Block Subroutines (Linker Optimization): Recurring instruction sequences are detected and converted into subroutines. The C251 Compiler rearranges code to obtain larger recurring sequences.
9Rearrange Code (Linker Optimization): When detecting common block subroutines, code is rearranged to obtain larger recurring sequences.

Note

  • Optimization Level 8 and 9 are available only when enabling Linker Code Packing in µVision. This option invokes the directive OBJECTADVANCED.
  • Each optimization level contains all characteristics of the preceding lower optimization levels. For example, OPTIMIZE level 9 includes all optimizations from level 0 to 8.
  • Developers can change the optimization level on a function-by-function basis. Example:
    #pragma OT(3)
    void funct_1 (void)
    {
    ...
    }
    
    #pragma OT(9)
    void func_2 (void)
    {
    ...
    }
    
  • Currently there is no difference between SIZE and SPEED emphasis.
See Also

OBJECTADVANCED

Example
C251 SAMPLE.C OPTIMIZE (size)
C251 SAMPLE.C OPTIMIZE (6, speed)
#pragma ot(4)
#pragma ot(size)