Register coloring is an optimization specific to DSP56800E development. The compiler assigns two (or more) register variables to the same register, if the code does not use the variables at the same time. The code of the following listing does not use variables i and j at the same time, so the compiler could store them in the same register:
However, if the code included the expression MyFunc (i+j), the variables would be in use at the same time. The compiler would store the two variables in different registers.
For DSP56800E development, you can instruct the compiler to:
- Store all local variables on the stack. — (That is, do not perform register coloring.) The compiler loads and stores local variables when you read them and write to them. You may prefer this behavior during debugging, because it guarantees meaningful values for all variables, from initialization through the end of the function. To have the compiler behave this way, specify Optimizations Off, in the Global Optimizations settings panel.
- Place as many local variables as possible in registers. — (That is, do perform register coloring.) To have the compiler behave this way, specify optimization Level 1 or higher, in the Global Optimizations settings panel.
Note: Optimizations Off is best for code that you will debug after compilation. Other optimization levels include register coloring. If you compile code with an optimization level greater than 0 and then debug the code, register coloring could produce unexpected results.
Variables declared volatile (or those that have the address taken) are not kept in registers and may be useful in the presence of interrupts.
- Run Peephole Optimization. — The compiler eliminates some compare instructions and improves branch sequences. Peephole optimizations are small and local optimizations that eliminate some compare instructions and improve branch sequences. To have the compiler behave this way, specify optimization Levels 1 through 4, in the Global Optimizations settings panel.