User manual

158
mikoC PRO for dsPIC
MikroElektronika
Single Static Assignment Optimization
Introduction
In compiler design, static single assignment form (often abbreviated as SSA form or SSA) is an intermediate
representation (IR) in which every variable is assigned exactly once.
An SSA-based compiler modies the program representation so that every time a variable is assigned in the original
program, a new version of the variable is created.
A new version of the variable is distinguished (renamed) by subscripting the variable name with its version number or
an index, so that every denition of each variable in a program becomes unique.
At a joining point of the control ow graph where two or more different denitions of a variable meet, a hypothetical
function called a phi-function is inserted so that these multiple denitions are merged.
In mikroC PRO for dsPIC, SSA's main goal is in allocating local variables into the RX space (instead onto the frame).
To do that, SSA has to make an alias and data ow analysis of the Control Flow Graph.
Besides these savings, there are a number of compiler optimization algorithms enhanced by the use of SSA, like :
- Constant Propagation
- Dead Code Elimination
- Global Value Numbering
- Register Allocation
Changes that SSA brings is also in the way in which routine parameters are passed. When the SSA is enabled,
parameters are passed through a part of the RX space which is reserved exclusively for this purpose (W10-W13 for
dsPIC).
Allocating local variables and parameters in RX space has its true meaning for those architectures with hardware
frame.
Enabling SSA optimization in compiler is done by checking box from the Output Settings Menu.
Lets consider a trivial case :
void main() {
int y,k;
if(y+k)
asm nop;
}
With SSA enabled, this example is consisted of 3 asm instructions :
;rbuild.c,10 :: if(y+k)
0x0212 0x408002 ADD _WREG1, _WREG2, _WREG0
0x0214 0x320001 BRA Z L_main0
L__main2:
;rbuild.c,11 :: asm nop;
0x0216 0x000000 NOP