in Compiler Design
524 views
1 vote
1 vote

Consider below two question :-

https://gateoverflow.in/39675/gate-2016-1-19

https://gateoverflow.in/8365/gate2015-1_55

Q1 >> Consider the following code segment.

x = u - t;
y = x * v; 
x = y + w;
y = t - z; 
y = x * y;

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

Here answer is 10.

Solution is 

x(temp3) = u(temp1) - t(temp2);
y(temp5) = x * v(temp4); 
x(temp7) = y + w(temp6);
y(temp9) = t - z(temp8); 
y(temp10) = x * y;

so ans should be.10

Q2> The least number of temporary variables required to create a three-address code in static single assignment form for the expression q  + r / 3 + s - t * 5 + u * v/w is__________________.

here answer is 8.

Solution:- 

t1 = r/3; 
t2 = t*5; 
t3 = u*v; 
t4 = t3/w; 
t5 = q + t1; 
t6 = t5 + s; 
t7 = t6 - t2; 
t8 = t7 + t4

In Q1 we are allocating a new variable to each variable, but in the second we are not so, like we are not allocating temp variable to "r", whereas in Solution 1 we have allocated temp variable to u and t both. Even both are using static single assignment?

in Compiler Design
524 views

4 Comments

x(temp3) = u(temp1) - t(temp2);

He means to say that

temp1 = u

temp2 = t

temp3 = temp1 - temp2

then x should also be initialized like,

temp1 = u

temp 2 = t

temp 3 = x

temp 3 = temp1 - temp2  // now it is not SSA.

or you want to say that x is implicitly converted to temp3....

0
0
q  + r / 3 + s - t * 5 + u * v/w

if above is written in below formate then what will be the total number of variable and total number of temporary variable required

a = r/3

b = t * 5

c = u * v

d = c / w

e = q + a

f = e + s

g = f - b

h = g + d

?
0
0

The first question is asking for total variables that will be required to convert it to SSA. The solution is not giving the SSA, but only counting the total variables required.

See Arjun sir's comment: https://gateoverflow.in/39675/gate-2016-1-19?show=42261#c42261

0
0

Please log in or register to answer this question.

Related questions