in Compiler Design retagged by
209 views
0 votes
0 votes
Consider the following C code:

d=a+b

e=a-b

f=c+d

g=c-e

a=f+g

b=f-g

c=d+e

The minimum number of total variables required to convert the above code segment to static single assignment form is?

Ans given is 7 but how
in Compiler Design retagged by
209 views

1 comment

But there is e=a-b which means a is already assigned some value then a= f+g is violating the rule??
0
0

1 Answer

2 votes
2 votes

In Static Single Assignment when we assign the values, the variables to which the value is assigned should be unique.

What it means is that the variable which is on the LHS can't repeat in two different expressions, for example

$x = a+ b$

$x = y+ z$

would be invalid as x is being used twice to assign values in 2 expressions which is not unique.

Hence this would be corrected as follows

$temp_x1 = a+ b$

$temp_x2 = y+ z$

 

In the above question, there is no expression which is violating this rule, all 7 variables on 7 expressions are unique, hence we don’t need to introduce any new variables.

Hence, the minimum number of total variables required to convert the above code segment to a static single assignment form would be the same as the total number of unique variables present in the expressions which is 7.

Length of {a,b,c,d,e,f,g} = 7 values, hence Thala for a reason.

edited by