Mikroelektronika MIKROE-442 Datenbogen
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
161
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 modifies 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 definition of each variable in a program becomes unique.
At a joining point of the control flow graph where two or more different definitions of a variable meet, a hypothetical
function called a phi-function is inserted so that these multiple definitions are merged.
In mikroBasic 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 flow 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:
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
0x0100 0x45000B ADD W10, W11, W0