ARM Technical Support Knowledge Articles

OPTIMIZE DIRECTIVE

Applies to: C251 C Compiler

Answer


Information in this article applies to:


QUESTION

How do I change optimization levels ?

ANSWER

The OPTIMIZE directive set the optimization level and emphasis.

Abbreviation: OT

Arguments: A decimal number between 0 and 7 enclosed in parentheses. In addition, OPTIMIZE (SIZE) or OPTIMIZE (SPEED) may be used to select whether the optimization emphasis should be placed on code size or on execution speed.

Each higher optimization level contains all of the characteristics of the preceding lower optimization level.

Level O

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

Simple Access Optimizing: The compiler optimizes 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.

Level 1

Dead Code Elimination: Unused code fragments and artifacts are eliminated.

Jump Negation: Conditional jumps are closely examined to see if they can be streamlined or eliminated by the inversion of the test logic.

Level 2

Data Overlaying: Data and bit segments suitable for static overlay are indentifed and internally marked. The L251 linker/locator has the capability, through global data flow analysis, of selecting the segments which can then be overlaid.

Peephole Optimizing: Redundant MOV instructions are removed. This include 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.

Level 3

Register Variables: Automatic variables and functions are calculated only once when possible. Reservation of data memory for these variables is omitted.

Level 4

Extended Access Optimizing: Variables from the IDATA, XDATA, PDATA, and CODE areas are directly included 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 a function are calculated only one 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 as jump tables or jump strings.

Level 5

Life Variable Analysis: Removes redundant and dead store operations to automatic variables.

Level 6

Constant 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 execustion time can be saved.

Level 7

Common 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, it will replace one code sequence by a jump instruction to the other equivalent code sequence. This situation arises many times with switch/case statements, for example. While analyzing the code, the compiler also tries to replace instruction sequences with cheaper instructions.

Example:

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

MORE INFORMATION

Article last edited on: 2005-07-18 09:47:00

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential