# Static Single Assignment (with relevant examples)

**Static Single Assignment** was presented in 1988 by Barry K. Rosen, Mark N, Wegman, and F. Kenneth Zadeck.

In compiler design, **Static Single Assignment** ( shortened SSA) is a means of structuring the IR (intermediate representation) such that every variable is allotted a value only once and every variable is defined before it’s use. The prime use of SSA is it simplifies and improves the results of compiler optimisation algorithms, simultaneously by simplifying the variable properties. Some Algorithms improved by application of SSA –

**Constant Propagation –**

Translation of calculations from runtime to compile time. E.g. – the instruction v = 2*7+13 is treated like v = 27**Value Range Propagation –**

Finding the possible range of values a calculation could result in.**Dead Code Elimination –**

Removing the code which is not accessible and will have no effect on results whatsoever.**Strength Reduction –**

Replacing computationally expensive calculations by inexpensive ones.**Register Allocation –**

Optimising the use of registers for calculations.

Any code can be converted to SSA form by simply replacing the target variable of each code segment with a new variable and substituting each use of a variable with the new edition of the variable reaching that point. Versions are created by splitting the original variables existing in IR and are represented by original name with a subscript such that every variable gets its own version.

**Example #1:**

Convert the following code segment to SSA form:

x = y - z s = x + s x = s + p s = z * q s = x * s

**Solution:**

x = y - z s_{2}= x + s x_{2}= s_{2}+ p s_{3}= z * q s_{4}= x_{2}* s_{3}

Here x,y,z,s,p,q are original variables and x_{2}, s_{2}, s_{3}, s_{4} are versions of x and s.

**Example #2:**

Convert the following code segment to SSA form:

a = s - b q = a * e a = q + d q = b - c q = a * q

**Solution:**

a = s - b q = a * e a_{2}= q + d q_{2}= b - c q_{3}= a_{2}* q_{2}

Here a,b,c,d,e,q,s are original variables and a_{2}, q_{2}, q_{3} are versions of a and q.