Optimizer

The C51 compiler is an optimizing compiler. This means that the compiler takes certain steps to ensure that the code that is generated and output to the object file is the most efficient (smaller and/or faster) code possible. The compiler analyzes the generated code to produce more efficient instruction sequences. This ensures that your C51 program runs as quickly as possible.

The C51 compiler provides six different levels of optimizing. Each increasing level includes the optimizations of levels below it. You may wish to refer to the “OPTIMIZE” directive in the “Compiling with C51” chapter.

The following is a list of several of the optimizations performed by C51.

General Optimizations

Optimization

Description

Constant Folding

Several constant values occurring in an expression or address calculation are combined as a constant.

Jump Optimizing

Jumps are inverted or extended to the final target address when the program efficiency is thereby increased.

Dead Code Elimination

Code which cannot be reached (dead code) is removed from the program.

Register Variables

Automatic variables and function arguments are located in registers when possible. Reservation of data memory for these variables is omitted.

Parameter Passing Via Registers

A maximum of three function arguments can be passed in registers.

Global Common Subexpression Elimination

Identical subexpressions or address calculations that occur multiple times in a function are recognized and calculated only once when possible.

8051-Specific Optimizations

Optimization

Description

Peephole Optimization

Complex operations are replaced by simplified operations when memory space or execution time can be saved as a result.

Extended Access Optimizing

Constants and variables are included directly in operations.

Data Overlaying

Data and bit segments of functions are identified as OVERLAYABLE and are overlaid with other data and bit segments by the L51 Linker/Locator.

Case/Switch Optimizing

Any switch and case statements are optimized by using a jump table or string of jumps.

Options for Code Generation

Optimization

Description

OPTIMIZE(SIZE)

Common C operations are replaced by subprograms. Program code is thereby reduced.

NOAREGS

C51 no longer uses absolute register access. Program code is independent of the register bank.

NOREGPARMS

Parameter passing is always performed in local data segments. The program code is compatible to earlier versions of C51.