
Using the Optimizer
SC100 C Compiler
5-7
The command line shown in Example 5-5 invokes the optimizer in global mode. The optimizer processes
all the specified source files together, applying the default Level 2 optimizations to all the modules in the
application.
Example 5-5. Invoking the optimizer in global mode
ccsc100 -Og -o file.eld file1.c file2.c file3.c
5.2.2 Optimizing for Space
Your application, or specific parts of it, may require code that occupies the least possible space in memory.
You can optimize the file(s) for space at the expense of speed. All optimizations are applied, with the
emphasis on functions which reduce code size.
To activate space optimization, specify the
-Os
option in the shell command line. See
Section 5.3.5,
“
Space Optimizations,
”
for details of the thresholds and optimization functions for this option.
5.2.3 Optimizing for Speed
You can optimize your application, or the parts of it which are speed-sensitive, to produce code that is fast
as opposed to small.
To optimize for speed, specify option
-Ot
,
-Ot1
or
-Ot2
in the shell command line, as illustrated in
Example 5-4 on page 5-6. The
-Ot2
option produces the fastest possible form of assembly object code,
with the least saving in memory size.
Each of these options will activate most of the main optimizations, with the emphasis on optimization for
speed rather than space. The difference between the options is in the thresholds at which the individual
optimizations are activated.
Section 5.3.4,
“
Time Optimizations,
”
lists the thresholds and describes how
the optimizations are activated for each option.
5.2.4 Using Global Optimization
Once you have optimized your individual source files and groups of files, you can invoke the optimizer in
global mode to ensure maximum optimization across the entire application, in order to produce the most
efficient code.
In global optimization mode, all the code in the application is processed by the compiler at the same time.
The optimizer has no need to make worst case assumptions since all the necessary information is available.
This enables the optimizer to achieve an extremely powerful level of optimization.
The main disadvantages of compiling in global optimization mode are the high consumption of resources
required, and the slow compilation time. In addition, because of the interdependency that global
optimization creates between all segments of the application, the entire application needs to be recompiled
if any one source code file is changed. For these reasons global optimization is generally used at the final
stage of development.
For a graphic representation of how the compiler operates in non-global and global optimization modes,
see
Section 3.2,
“
Invoking the Shell,
”
on page 3-10.