Redirected
retagged by
12,044 views
12 votes
12 votes

Consider the control flow graph shown.

Which one of the following choices correctly lists the set of live variables at the exit point of each basic block?

  1. $\text{B1: { }, B2: {a}, B3: {a}, B4: {a}}$
  2. $\text{B1: {i, j}, B2: {a}, B3: {a}, B4: {i}}$
  3. $\text{B1: {a, i, j}, B2: {a, i, j}, B3: {a, i}, B4: {a}}$
  4. $\text{B1: {a, i, j}, B2: {a, j}, B3: {a, j}, B4: {a, i, j}}$
retagged by

4 Answers

8 votes
8 votes

We can say that a variable ‘v’ is live(at a statement ‘n’) if there exists a path in CFG from this statement to another statement ‘m’ such that ‘v’ is used in ‘m’ and for each n <= k < m and v is not defined in any statement k. simply, a variable is live(at a statement/point) if there exists a path in CFG where it is used before its modifying.

This question can be solved by definition and by using the algorithm.

Here, they’ve asked live variables at exit point of each basic block.

For B1 : there are 2 paths at exit of B1;

  1. B2, B3, B4 : In this path ‘i’, ‘j’ are live as they both are used before modifying. ‘a’ is not live as it is            modified(defined) in B3 before being used in B4.
  2. B2, B4 : In this path ‘i’, ‘j’ & ‘a’ all three are live as all these are used before being modified (defined).

       Thus, set of live variables at exit of B1 is {${a,i,j}$}.

For B2 : again there are 2 paths at exit of B2;

  1. B3, B4 : In this path, only ‘j’ is live because ‘a’ & ‘i’ both are dead as they have been defined before  usage in B3 & B4 respectively and ‘j’ is being used before modifiying in B2 (we can reach B2 from B4 as there is loop).
  2. B4 : after B2,  there’s a direct path to B4. Here, ‘a’ & ‘j’ are live because they are being used before definition in B4 & B2 respectively and ‘i’ is dead because it is being defined before use in B4.

       Thus, set of live variables at exit of B2 is {${a,j}$}.

For B3 : In path B4 B2 B4 or B4 B2 B3, ‘a’ & ‘j’ are live and ‘i’ is dead because ‘i’ is defined before use in B4.

              Thus, set of live variables at exit of B3 is {${a,j}$}.

For B4 : liveness analyisis is same as for B1 because paths at exit of B4 (B2 B3 B4 & B2 B4) are same for B1

              except for EXIT (which doesn’t change the ans).


              Thus, set of live variables at exit of B4 is {${a,i,j}$}.

edited by
4 votes
4 votes

Since the CFG contains loop we may require multiple backward iterations to identify live variables at each block

See the pictures below to see the iterations

since the live variables do not change in round 3 therefore we can stop after round 3.

Now in the question “live variable at the exit points of each basic block “is asked ,so basically we have to give the live variable in OUT of each basic block after iteration 3 

therefor D) B1:{a,i,j},B2:{a,j},B3:{a.j},B4:{a,i,j} is the correct answer

 

edited by
3 votes
3 votes

Then one iteration more to update the value .

 

Then after that if we do one more iteration it will give same out to each block .

So the answer is option D .

Answer:

Related questions