SPRU514Z July 2001 – October 2023 SM320F28335-EP
The --opt_for_space option increases the level of code-size optimizations performed by the compiler. These optimizations are done at the expense of performance. The optimizations include procedural abstraction where common blocks of code are replaced with function calls. For example, prolog and epilog code, certain intrinsics, and other common code sequences, can be replaced with calls to functions that are defined in the run-time library. It is necessary to link with the supplied run-time library when using the --opt_for_space option. It is not necessary to use optimization to invoke the --opt_for_space option.
To illustrate how the --opt_for_space option works, the following describes how prolog and epilog code can be replaced. This code is changed to function calls depending on the number of SOE registers, the size of the frame, and whether a frame pointer is used. These functions are defined in each file with the --opt_for_space option, as shown below:
_prolog_c28x_1
_prolog_c28x_2
_prolog_c28x_3
_epilog_c28x_1
_epilog_c28x_2
Suppose the following C code is compiled with the --opt_for_space option.
extern int x, y, *ptr;
extern int foo();
int main(int a, int b, int c)
{
ptr[50] = foo();
y = ptr[50] + x + y + a +b + c;
}
The resulting output will be as follows:
FP .set XAR2
.global _prolog_c28x_1
.global _prolog_c28x_2
.global _prolog_c28x_3
.global _epilog_c28x_1
.global _epilog_c28x_2
.sect ".text"
.global _main
;***************************************************************
;* FNAME: _main FR SIZE: 6 *
;* *
;* FUNCTION ENVIRONMENT *
;* *
;* FUNCTION PROPERTIES *
;* 0 Parameter, 0 Auto, 6 SOE *
;***************************************************************
_main:
FFC XAR7,_prolog_c28x_1
MOVZ AR3,AR4 ; |5|
MOVZ AR2,AH ; |5|
MOVZ AR1,AL ; |5|
LCR #_foo ; |6|
; call occurs [#_foo] ; |6|
MOVW DP,#_ptr
MOVL XAR6,@_ptr ; |6|
MOVB XAR0,#50 ; |6|
MOVW DP,#_y
MOV *+XAR6[AR0],AL ; |6|
MOV AH,@_y ; |7|
MOVW DP,#_x
ADD AH,AL ; |7|
ADD AH,@_x ; |7|
ADD AH,AR3 ; |7|
ADD AH,AR1 ; |7|
ADD AH,AR2 ; |7|
MOVB AL,#0
MOVW DP,#_y
MOV @_y,AH ; |7|
FFC XAR7,_epilog_c28x_1
LRETR
; return occurs