User manual

mikroBasic PRO for PIC32
MikroElektronika
163
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 mikroBasic 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:
program Example
sub procedure SSA_Test(dim y as integer, dim k as integer)
if (y+k) then
asm
nop
end asm
end if
end sub
main:
SSA_Test(5,5)
end.
With SSA enabled, sub procedure SSA_Test this example is consisted of 3 asm instructions:
;Example.mbas, 29 :: if (y+k) then
0x9D000000 0x033A1021 ADDU R2, R25, R26