User manual

Table Of Contents
mikroC PRO for PIC32
MikroElektronika
159
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 PIC32, 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.
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 SSA_Test(int y, int k) {
if (y+k)
asm nop
}
void main() {
SSA_Test(5,5);
}
With SSA enabled, this example is consisted of 3 asm instructions:
;Example.c, 25 :: if (y+k)
0x9D000000 0x033A1021 ADDU R2, R25, R26
0x9D000004 0x10400002 BEQ R2, R0, L_SSA_Test0
0x9D000008 0x70000000 NOP
L__SSA_Test3: