Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider the control flow graph given below.

Control flow graph: ENTRY to B1 (a = b + c); B1 to B2 (d = a + e) and to B3 (e = a + f); B3 loops back to B1; B2 to B4 (g = d + e); B4 to EXIT

Which one of the following options is the set of live variables at the exit point of each basic block?

  • A.B1:{a, b, c, e, f}, B2:{d, e}, B3:{b, c, e, f}, B4:∅
  • B.B1:∅, B2:{d, e}, B3:{a, c, f}, B4:∅
  • C.B1:{a, b, c, e, f}, B2:{d, e}, B3:{c, e, f}, B4:∅
  • D.B1:∅, B2:{d, e, f}, B3:{a, b, c, e, f}, B4:∅

Answer: A

The live variables at block exits are B1:{a, b, c, e, f}, B2:{d, e}, B3:{b, c, e, f}, B4:∅.

Liveness flows backwards: OUT(B) is the union of IN over B's successors, and IN(B) = USE(B) ∪ (OUT(B) - DEF(B)). The edges are B1 → B2, B1 → B3, B3 → B1 and B2 → B4.

  • B4 (g = d + e) leads to EXIT, and g is never used: OUT(B4) = ∅, IN(B4) = {d, e}.
  • B2 (d = a + e): OUT(B2) = IN(B4) = {d, e}; IN(B2) = {a, e}.
  • B1 (a = b + c) and B3 (e = a + f) form a loop. Iterating to a fixed point: IN(B1) = {b, c, e, f} and IN(B3) = {a, b, c, f}.
  • OUT(B1) = IN(B2) ∪ IN(B3) = {a, b, c, e, f}; OUT(B3) = IN(B1) = {b, c, e, f}.

The options with B1:∅ ignore that a is used in both successors of B1. The option with B3:{c, e, f} drops b, which is live because B1, reached from B3, uses it.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.