< Compile Options / Optimize Options >
[Format]
[Description]
-  | This option makes the compiler perform optimization on the assumption that all source files have been input.  | 
 
[Remarks]
-  | When this option is specified, do not include C++ language source files among the input files.  | 
 
-  | When this option is specified, do not specify -lang=cpp or -lang=ecpp.  | 
 
-  | Specifying this option also makes the ip_optimize option effective, and if multiple source files are input, the merge_files option is also effective.  | 
 
-  | When this option is specified, compilation is on the assumption that the conditions listed below are satisfied. Correct operation is not guaranteed otherwise.  | 
 
-  | Values and addresses of extern variables defined in the target source files will not be modified or referred to by other files.  | 
 
-  | Functions within the target source file will not be called from within other files, although functions in other files can be called from within the target source files.  | 
 
[Example]
[wp.c] 
extern void g(void); 
int func(void) 
{
    static int a = 0; 
    a++;      // (1) Write a value to a. 
    g();      // (2) Call g(). 
    return a; // (3) Call a. 
} 
  
[Without whole_program] 
The compiler assumes that (2) will change the value of a since function g() may call function func(), and generates a code to read the value of a in (3). 
_func: 
        PUSH.L R6 
        MOV.L  #__$a$1,R6 
        MOV.L  [R6],R14 
        ADD    #1,R14 
        MOV.L  R14,[R6]     ; (1) 
        BSR    _g           ; (2) 
        MOV.L  [R6],R1      ; (3) 
        RTSD   #4,R6-R6 
  
[With whole_program] 
The compiler assumes that function g() will not call function func() and thus (2) will not change the value of a. As a result, the compiler does not read the value of a in (3) and instead generates a code to use the value written to a in (1). 
_func: 
        PUSH.L R6 
        MOV.L  #__$a$1,R14 
        MOV.L  [R14],R6 
        ADD    #1,R6 
        MOV.L  R6,[R14]     ; (1) 
        BSR    _g           ; (2) 
        MOV.L  R6,R1        ; (3) 
        RTSD   #4,R6-R6 
  
 |