CD Questions (Unit-6)
CD Questions (Unit-6)
8. Create basic blocks and control flow graph for the following code: (6 Marks)
int fib(int m)
{
int f1=0, f2=1, f3, i ;
if (m<=1)
{
return m;
}
else
{
for(i=2; i<=m; i++)
{
f3=f1+f2;
f1=f2;
f2=f1;
}
return f3;
}
}
9. Find the liveness and next use information for following three-address code: (6
Marks)
(1) t1 = 4 * i
(2) t2 = a[t1]
(3) t3 = 4 * i
(4) t4 = b[t3]
(5) t5 = t2 * t4
(6) t6 = prod + t5
(7) prod = t6
(8) t7 = i + 1
(9) i = t7
10. Construct a DAG for the following basic block and also generate the code for
the same using two registers. (6 Marks)
t1 = a + b
t2 = c + d
t3 = e - t2
t4 = t1 - t3
11. Construct a DAG for the given expression and also generate the code for the
same using two registers. (6 Marks)
( a - b ) + c * ( d / e)
12. What is loop in flow graph? Discuss flow graph and its use in code optimization
with appropriate example. (6 Marks)