3.4. Controlling Optimization

The following command-line options control optimization behavior.

cl2000 Option (and alias)

c29clang Option

--opt_level=<off|0|1|2|3> (-O<off|0|1|2|3>

-O<0|1|2|3|fast|g|s|z>

--opt_level=4 (-O4)

Not available; link-time

optimization not supported

The cl2000 compiler supports several levels of optimization beginning with --opt_level=off, or “no optimization,” up to -O4, which enables cl2000’s link time program optimization capability.

The c29clang compiler supports a variety of different optimization options, including:

  • -O0 - no optimization; generates code that is debug-friendly.

  • -O1 or -O - restricted optimizations, providing a good trade-off between code size and debuggability.

  • -O2 - most optimizations enabled with an eye towards preserving a reasonable compile-time.

  • -O3 - in addition to optimizations available at -O2, -O3 enables optimizations that take longer to perform, trading an increase in compile-time for potential performance improvements.

  • -Ofast - enables all optimizations from -O3 along with other aggressive optimizations that may realize additional performance gains, but also may violate strict compliance with language standards.

  • -Og - enables most optimizations from -O1, but may disable some optimizations to improve debuggability.

  • -Os - enables all optimizations from -O2 plus some additional optimizations intended to reduce code size while mitigating negative effects on performance.

  • -Oz - enables all optimizations from -Os plus additional optimizations to further reduce code size with the risk of sacrificing performance.

The ability to debug a program becomes more challenging at higher levels of optimization.

cl2000 Option (and alias)

c29clang Option

--opt_for_speed=<0|1|2|3|4|5>

(-mf=<0|1|2|3|4|5>)

-O<z|s|3|fast>

--opt_level=4 (-O4)

--opt_for_speed=<0|1|2|3|4|5>

(-mf=<0|1|2|3|4|5>)

Not available; link-time

optimization not supported

The cl2000 compiler supports an --opt_for_speed option, which allows you to select a code size versus performance “trade-off” level, n, which informs the compiler about how aggressive it can be when optimizing for improved performance at the risk of increasing code size. The available values for n range from 0, which favors optimizations geared towards reducing code size with a high risk of degrading performance, to 5, which favors optimizations intended to improve performance with a high risk of increasing code size.

Some of the c29clang compiler’s optimization options roughly correspond to the intended code size vs. performance trade-off that is embodied in the use of cl2000’s --opt_for_speed and --opt_level options. The following is an approximate mapping:

  • -Oz - resembles using cl2000’s --opt_for_speed=0-1 in combination with --opt_level=2-3 since it favors code size reducing optimizations even if performance is degraded.

  • -Os - resembles using cl2000’s --opt_for_speed=2-3 in combination with --opt_level=2-3 since it favors code size reducing optimizations, but tries to preserve performance while doing so.

  • -O3 - resembles using cl2000’s --opt_for_speed=3-4 in combination with --opt_level=2-3 since it favors optimizations intended for improving performance, but tries to avoid increases in code size while doing so.

  • -Ofast - resembles using cl2000’s --opt_for_speed=4-5 in combination with --opt_level=2-3 since it favors optimizations intended for improving performance even if code size increases (Caution: the use of -Ofast may violate strict compliance with language standards).

cl2000 Option (and alias)

c29clang Option

--opt_for_space=<0|1|2|3>

-O<1|s|z>

The cl2000 compiler supports an --opt_for_space option, which is an older option for controlling code space.

The c29clang compiler reduces code size to different degrees when you use the -O, -Os, and -Oz options.

cl2000 Option

c29clang Option

--sat_reassoc=off (default) --sat_reassoc=on

not supported

The cl2000 compiler provides a --sat_reassoc option to enable or disable reassociation of saturating arithmetic. It is off by default.

The c29clang compiler does not support an analogous option.

cl2000 Option (and alias)

c29clang Option

--auto_inline=<size> (-oi<size>

-finline-limit=<size>

The cl2000 compiler provides the --auto_inline option, which, when used in combination with --opt_level=3, allows you to specify a size threshold for automatic inlining of functions that are not explicitly declared as “inline.”

The c29clang compiler supports an analogous option, -finline-limit, which allows you to specify a size threshold for functions that can be inlined, where <size> is the number of pseudo instructions.

The c29clang compiler also supports the always_inline (“__attribute__((always_inline))”) and noinline ( “__attribute__((noinline))”) function attributes that provide a means for you to control inlining on a function-specific basis. The c29clang compiler’s -fno-inline-functions option can be used to disable all inlining.

cl2000 Option (and alias)

c29clang Option

--disable_inlining

-fno-inline-functions

The cl2000 compiler provides the --disable_inlining option, which allows you prevent any inlining from being performed.

To prevent inlining with the c29clang compiler, use the -fno-inline-functions option.

cl2000 Option (and alias)

c29clang Option

--call_assumptions=<n> (-op<n>)

not supported

The cl2000 compiler provides the --call_assumptions option, which, when used in combination with --program_level_compile and --opt_level=3, allows you to provide additional information to the compiler about whether the functions defined in a given module are called from other modules and whether global variable definitions in a given module are referenced from other modules.

cl2000 Option (and alias)

c29clang Option

--gen_opt_info=<0|1|2>

(-on=<0|1|2>

-fsave-optimization-record

-foptimization-record-file=<filename>

-Rpass=<expr>

-Rpass-missed=<expr>

-Rpass-analysis=<expr>

The cl2000 compiler provides the --gen_opt_info option, which, when used in combination with --opt_level=3, causes the compiler to emit a human-readable optimization information file. The higher the value of the argument specified, the more verbose the optimization information provided will be.

The c29clang compiler does not provide an option that matches the exact behavior of cl2000’s --gen_opt_info, but c29clang reports optimization information via the following available options:

  • -fsave-optimization-record - writes optimization remarks to a YAML file

  • -foptimization-record-file - identifies the name of the YAML file written when using the -fsave-optimization-record option

  • -Rpass - given a regular expression string argument to identify the optimization pass(es) that you want information about, the -Rpass option writes informative remarks to stdout during compilation about when a specified optimization pass makes a transformation

  • -Rpass-missed - given a regular expression string argument to identify the optimization pass(es) that you want information about, the -Rpass-missed option writes informative remarks to stdout during compilation about when a specified optimization pass fails to make a transformation

  • -Rpass-analysis - given a regular expression string argument to identify the optimization pass(es) that you want information about, the -Rpass-analysis option writes informative remarks to stdout during compilation about why a specified optimization pass does or doesn’t perform a transformation

cl2000 Option (and alias)

c29clang Option

--optimizer_interlist (-os)

not supported

The cl2000 compiler provides the --optimizer_interlist option, which tells the compiler to keep an compiler-generated intermediate assembly source file that is annotated with interlisted comments corresponding C/C++ source code optimizations to the assembly code generated by the compiler.

The c29clang compiler does not provide an analogous option. However, you can use c29clang’s -Rpass, -Rpass-missed, and -Rpass-analysis options to gain more insight into which optimizations were performed and potential optimizations that were ruled out during compilation.

cl2000 Option (and alias)

c29clang Option

--program_level_compile (-pm)

not supported

The cl2000 compiler’s --program_level_compile option combines source files into a single compilation unit to enable the compiler’s program-level optimizations.

The c29clang compiler does not support link-time optimization.

cl2000 Option (and alias)

c29clang Option

--aliased_variables (-ma)

not supported

The cl2000 compiler’s -aliased_variables option instructs the compiler to assume that called functions are capable of creating hidden aliases. As a result, the compiler must assume worst-case aliasing. For example, the optimizer cannot assume that it knows the value stored in a local object if that local object might be accessed via a separate pointer.

The c29clang compiler does not provide an analogous option. However, c29clang’s -fstrict-aliasing and -fno-strict-aliasing options can be used to enable or disable optimizations based on type based alias analysis, but they don’t allow the compiler to violate the aliasing rules of C. Some aliasing behavior can also be controlled via c29clang’s optimization options.

cl2000 Option (and alias)

c29clang Option

--isr_save_vcu_regs={on|off}

not supported

The cl2000 compiler provides the --isr_save_vcu_regs compiler option, which generates instructions to save and restore VCU registers using the stack when interrupt service routines occur. This allows VCU code to be re-entrant. If an ISR interrupts a VCU computation, it will not impact results if this option is used.

The c29clang compiler does not provide an analogous option, because C29x devices do not contain VCU registers.