Everything

 

-O


This option specifies the optimization level or the details of each optimization items.

[Specification format]

-O[level]
-O[item[=value][,item[=value]]...]

 

-

Interpretation when omitted

Optimization that is effective for both the object size and execution speed is done. (It is the same result as when the -Odefault option is specified).

[Detailed description]

-

This option specifies the optimization level or the details of each optimization items.

-

The items that can be specified as level are shown below.
An error will occur if any other item is specified.

default

Default

Does optimization that is effective for both the object size and execution speed.

size

Optimization with the object size precedence

Regards reducing the ROM/RAM capacity as important and performs the maximum optimization that is effective for general programs.

speed

Optimization with the execution speed precedence

Regards improving the execution speed as important and performs the maximum optimization that is effective for general programs.

nothing

Optimization with debugging precedence

Regards debugging as important and suppresses all optimization including default optimization.

 

-

If level and item are omitted, compilation is as if "size" has been specified.

-

The items that can be specified as item and value are shown below.
An error will occur if any other item is specified.

Optimization Item (item)

Parameter (value)

Description

unroll

0 to 4294967295

(Integer value)

Loop expansion

The loop statements (for, while, and do-while) are expanded.

Use value to specify the maximum rate of increase in code size after loop expansion.

A value of 0 set as value has the same meaning as a value of 1.

If value is omitted, it is assumed that "2" has been specified.

This item is valid when the -Osize, -Ospeed, or -Odefault option is specified.

delete_static_func

on or off

Deleting unused static functions

If value is omitted, it is assumed that "on" has been specified.

inline_level

0 to 3

(Integer value)

Inline expansion for functions

value signifies the level of the expansion.

0: Suppresses all inline expansion including the function for which "#pragma inline" is specified.

1: Performs inline expansion for only a function for which "#pragma inline" is specified.

2: Distinguishes a function that is the target of expansion automatically and expands it.

3: Distinguishes the function that is the target of expansion automatically and expands it, while minimizing the increase in code size.

However, if 1 to 3 is specified, the function that is specified by "#pragma inline" may not be expanded according to the content of the function and the status of compilation.

If value is omitted, it is assumed that 2 has been specified.

This item is valid when the -Osize, -Ospeed, or -Odefault option is specified.

inline_size

0 to 65535

(Integer value)

Size for inline expansion

Specify the maximum increasing rate (%) of the code size up to which inline expansion is performed.

When 100 is specified, functions are expanded inline until the code size increases by 100%.

If value is omitted, it is assumed that 100 has been specified.

This item is valid when the -Oinline=2 option is specified (including when the -Ospped option is specified).

pipeline

[V1.03 or later]

on or off

Pipeline optimization

If value is omitted, it is assumed that "on" has been specified.

This item is valid when the -Osize, -Ospeed, or -Odefault option is specified.

tail_call

on or off

Replacement of a function call at the end of a function with br instruction

If "on" is specified, then if there is a function call at the end of a function, and certain conditions are met, a br instruction will be generated for that call rather than a call instruction. The ret code will be removed, reducing the code size.

However, some debug functions cannot be used.

If value is omitted, it is assumed that "on" has been specified.

merge_files

-

Merging of multiple files before compilation

If this option is omitted, compilation is done in input file units without merging the files.

Multiple C source files are merged then compiled, and output as a single file.

The output file name is the specified output file name when -o is specified. When -o is not specified, the output file name becomes the file name according to the interpretation when -o is omitted for the C source file name that has been specified first.

When there is only one input file or this option is specified simultaneously with -P, this option is invalid.

When this option is specified simultaneously with -S or -c, an empty file is created and its file name is in accordance with the interpretation when -o is omitted for the C source file name that has been specified second or later.

When this option is specified simultaneously with -Oinline_level, inline expansion is performed between files.

When linking an object file created with this option specified, operation is not guaranteed if linker option -delete, -rename, or -replace is specified simultaneously.

intermodule

-

Global optimization execution

The main optimization contents are the following.

-

Optimization using alias analysis between procedures

-

Propagation of constants, such as parameters and return values

whole_program

-

Optimization assuming that the whole program consists only of the input file

If this option is omitted, it is not assumed that the whole program consists only of the target file for compilation.

The compilation is performed assuming that the following conditions are met. Operation is not guaranteed if these conditions are not met.

-

The values and addresses of extern variables defined in the files to be compiled will not be modified or referenced from outside those files.

-

If a file to be compiled calls a function defined outside the files to be compiled, the called function will never call a function in the files to be compiled.

 

If this option is specified, it is assumed that the -Ointermodule option is specified.

If two or more C source files are input, it is assumed that the -Omerge_files option is specified.

alias

ansi or noansi

Optimization considering the type pointed to by pointers

If this option is omitted, noansi is assumed.

same_code

[V1.02 or later]

on or off

The multiple same instruction sequences that are found within a single section of the compilation unit are integrated into a function.

If value is omitted, it is assumed that on is specified.

This option is valid when the -Osize, -Ospeed, or -Odefault option is specified.

branch_chaining

[V1.10 or later]

on or off

Optimization by reducing the branch instruction code size

This option uses a branch instruction whose code size is small. To use a branch instruction whose code size is small, a branch destination may be another branch instruction which shares the same destination, not a direct branch to the final destination.

As a result, although this option reduces the code size, it also lowers the execution speed.

Note that using this optimization without specifying the -g_line option may affect the behavior of single-step execution.

If the value is omitted, it is assumed that on has been specified.

This option is valid when the -Osize or -Odefault option is specified.

align

[V1.10 or later]

on or off

Optimization by changing the alignment condition

The number of generated instructions is decreased, the code size is reduced and the execution speed is increased by changing the variable alignment condition and then combining multiple accesses into one when, for example, accessing contiguous areas in a structure-type variable.

As a result of changing the alignment condition, padding data is filled in and the amount of consumption may increase in the data storage area.

If value is omitted, it is assumed that on has been specified.

This option is valid when the -Osize, -Ospeed, or -Odefault option is specified.

This option is invalid if the -stuff option is specified at the same time.

 

-

If this option is specified more than once for the same item, the option specified last will be valid.

-

According to the -Olevel setting, each -Oitem item is set to the value shown in the following.

The -Oitem items not listed in the table are not affected by the -Olevel setting.

Note that optimization through the -Olevel setting does not precisely match the optimization result obtained by specifying each -Oitem value separately. For example, when the -Odefault level is specified as -Olevel and then each -Oitem is separately set to match the corresponding item value for the -Osize level, the optimization result is not equivalent to that obtained when -Osize is specified from the beginning.

Optimization Item (item)

Optimization Level (level)

-Osize

-Ospeed

-Odefault

-Onothing

unroll

1

2

1

1

delete_static_func

on

on

on

off

inline_level

3

2

3

-

inline_size

0

100

0

-

tail_call

on

on

on

off

pipeline

on

on

on

off

same_code

on

off

off

off

branch_chaining

on

off

on

off

align

on

on

off

off

[Example of use]

-

To perform optimization with the object size precedence, describe as:

>ccrl -Osize -cpu=S2 -dev=dr5f100pj.dvf main.c

 

-

To perform global execution, describe as

-

Optimization using alias analysis between procedures

> ccrl -cpu=S2 im1.c -Odelete_static_func=off,intermodule

<C source code>

extern long x[2];
extern int y[2];
static long func1(long *a, int *b) {
    *a=0;
    *b=1;
    return *a;
}
long func2(void) {
    return func1(&x[0], &y[1]);
}

<Output code>

_func1@1:
    .STACK _func1@1 = 6
    movw de, ax
    push bc
    pop hl
    clrw ax
    movw [de+0x02], ax
    movw [de], ax
    onew ax
    movw [hl], ax
    clrw bc         ; 0 is directly assigned because a and b point to different 
    clrw ax         ; addresses.
    ret

 

-

Propagation of constants, such as parameters and return values

> ccrl -cpu=S2 im2.c -Oinline_level=1,intermodule

<C source code>

static __near int func(int x, int y, int z) {
    return z-x-y;
}
int func2(void) {
    return func(3,4,8);
}

<Output code>

    .SECTION .text,TEXT
_func@1:
    .STACK _func@1 = 4
    onew ax         ; 1(=8-3-4) is directly assigned.
    ret
    .SECTION .textf,TEXTF
_func2:
    .STACK _func2 = 4
    movw de, #0x0008
    movw bc, #0x0004
    movw ax, #0x0003
    br !_func@1

 

-

To perform optimization considering the type pointed to by pointers, describe as:

> ccrl -cpu=S2 al1.c -Oalias=ansi

<C source code>

long x, n;
void func(short *ps)
{
    n = 1;
    *ps = 2;
    x = n;
}

<Output code>

As ps and n have different types, the value of n will not be affected by "ps = 2;". Therefore, the value used for assignment in "n = 1" is used again at (A).

(When "ps = 2;" changes the value of n, the result will be changed.)

_func:
    .STACK _func = 4
    movw de, ax
    clrw ax
    movw bc, ax
    movw !LOWW(_n+0x00002), ax
    onew ax
    movw hl, ax
    movw !LOWW(_n), ax
    onew ax
    incw ax
    movw [de], ax
    movw ax, bc     ; (A) The value used for assignment in n = 1 is used again.
    movw !LOWW(_x+0x00002), ax
    movw ax, hl     ; (A)
    movw !LOWW(_x), ax
    ret

[Caution]

When source-level debugging is performed using an optimized object code, take account of the following ramifications.

-

A variable may not be read or written at the location where that variable is referenced in the source program because an expression has been transformed (copy propagation, common subexpression recognition, etc.) due to optimization.

-

Step execution may not be performed according to the source program because statements have been optimized (code sharing, elimination, rearrangement, etc.).
In addition, a breakpoint may not be set for a particular statement. For example, if a statement has been deleted, a breakpoint cannot be set at that statement.

-

There is a possibility that the variable's available range (range in which the variable can be referenced in the program) or variable's location (register or memory location) is changed due to optimization (rearrangement of statements, register allocation, etc.) of statements or variables.

-

Step execution for an inline-expanded statement is performed not at the inline-expanded part but within the inline expansion source function.
Since calling of the inline-expanded function is deleted, a breakpoint cannot be set there.

-

Since a great amount of memory is consumed to process debugging information at compilation, it may result in "out of memory".