The Keil compiler has extensive optimizations, including unused code segments
and code that cannot be reached. Here is a summary -
- Common Block Subroutines (Level 9)
Recurring instruction sequences are detected and converted into subroutines. The Cx51 Compiler rearranges code to obtain larger recurring sequences.
- Common Block Subroutines (Linker Optimization) (Level 9)
Recurring instruction sequences are detected and converted into subroutines. The linker rearranges code to obtain larger recurring sequences.
- Common Tail Merging (Level 8)
When there are multiple calls to a single function, some of the setup code can be reused, thereby reducing program size.
- Constant Folding (Level 0)
The compiler performs calculations that reduce expressions to numeric constants, where possible. This includes calculations of run-time addresses.
- Dead Code Elimination (Level 1)
Unused code fragments, artifacts, and code which cannot be reached is removed.
- Extended Index Access Optimizing (Level 7)
DPTR is used for register variables where appropriate. Pointer and array access are optimized for both execution speed and code size.
- Global Common Subexpression Elimination (Level 5)
The compiler detects multiple uses of the same expression or subexpression within a function. The value is calculated only once and stored in a register for reuse where appropriate.
- Jump Negation (Level 1)
Conditional jumps are closely examined to see if they can be streamlined or eliminated by the inversion of the test logic.
- Jump Optimizing (Level 0)
The compiler always extends jumps to the final target. Jumps to jumps are eliminated.
- Local Common Subexpression Elimination (Level 4)
The compiler detects multiple uses of the same expression or subexpression. The value is calculated only once and reused where possible. Superfluous expression calculations are eliminated from the code.
- Loop Rotation (Level 6)
Program loops are rotated if the resulting program code is faster and more efficient. The loop expression of for and while loops is evaluated once at the top of the loop and then at the bottom of the loop. This optimization generates more code but speeds up execution.
- Rearrange Code (Linker Optimization) (Level 10)
When detecting common block subroutines, code is rearranged to obtain larger recurring sequences.
- Register Variables (Level 4)
Automatic variables and up to three function arguments may be located in registers. No data memory is reserved for variables located in registers.
- Reuse of Common Entry Code (Linker Optimization) (Level 8)
Entry code is reused when multiple calls are made to a single function. Reusing common entry code reduces program size.
- Reuse of Common Exit Code (Linker Optimization) (Level 11)
Identical exit sequences are reused. This may reduce the size of common block subroutines.
- Simple Access Optimizing (Level 0)
The compiler optimizes access of internal data and bit addresses in the 8051 system.
- Simple Loop Optimizing (Level 4)
Program loops that fill a memory range with a constant are converted and optimized.
- Common Block Subroutines (Level 9)
It is NOT good to mess around in generated code.There are some optimization settingd in PSSoC Creator, one of them is to remove dead code which indeed will remove all unnecessary functions.
To be found under Project -> Build Settings -> Linker
Dana was 2 mins faster and a lot more detailled...
As Bob points out tool generated code generally speaking will get regenerated
on next build. Trying to override the tool can get some unpredictable results. You
can generally count on todays tools to eliminate unused code. That certainly is
the case with Keil. Bob can speak to the effecacy of GNU.
Note on debugging, generally turn optimization off in compiler when debugging,
then turn it on for final builds. Not this potentially affects SW timing loops, and code
performance when disabled, keep that in mind.
Thanks for the quick response. I think I didn't express my question accurately. I'm not looking for code optimization, I'm looking to eliminate the code generated for the USBUART that I don't need. There are C and H files for things like audio, HID, etc that don't apply to anything we're doing. Can't I eliminate those files some way, maybe in the configuration IDE? I only want to use the cdc functionality. We need all the space we can get.
Code optimization and reduction somewhat vague terms.
The compiler will eliminate unused code, as well as optimize the
If you need a precise answer you might post a case at Keil and ask what
the granularity of code will be eliminated, if unused, Eg,. does it work
down to the individual API call ? Clearly if certain APIs use common
code fragments what does the compiler do ? Can it still eliminate part
of the API code ?
By the way, your post is in the wrong forum, should be in PSOC Creator forum.