Consider the control flow graph given below. Which one of the following…

2026

Consider the control flow graph given below.

image.png

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

  1. A.

    B1:{a, b, c, e, f}, B2:{d, e}, B3:{b, c, e, f}, B4:∅

  2. B.

    B1:∅, B2:{d, e}, B3:{a, c, f}, B4:∅

  3. C.

    B1:{a, b, c, e, f}, B2:{d, e}, B3:{c, e, f}, B4:∅

  4. D.

    B1:∅, B2:{d, e, f}, B3:{a, b, c, e, f}, B4:∅

Attempted by 18 students.

Show answer & explanation

Correct answer: A

Live Variable Analysis Solution

We perform backward data flow analysis to find the set of live variables at the exit of each basic block (LiveOut). A variable is live at a point if its value is used along some path from that point to the exit.

Step 1: Analyze Block B4

Statement: g = d + e

Uses: {d, e}, Defines: {g}

Successor: Exit (no live variables)

LiveOut(B4) = ∅

LiveIn(B4) = Uses ∪ (LiveOut(B4) - Defines) = {d, e} ∪ (∅ - {g}) = {d, e}

Step 2: Analyze Block B2

Statement: d = a + e

Uses: {a, e}, Defines: {d}

Successor: B4

LiveOut(B2) = LiveIn(B4) = {d, e}

LiveIn(B2) = {a, e} ∪ ({d, e} - {d}) = {a, e}

Step 3: Analyze Block B1 and B3 (Loop)

Block B1: a = b + c. Uses: {b, c}, Defines: {a}. Successors: B2, B3.

Block B3: e = a + f. Uses: {a, f}, Defines: {e}. Successor: B1.

Equations:

LiveOut(B1) = LiveIn(B2) ∪ LiveIn(B3) = {a, e} ∪ LiveIn(B3)

LiveIn(B1) = {b, c} ∪ (LiveOut(B1) - {a})

LiveIn(B3) = {a, f} ∪ (LiveIn(B1) - {e})

Solving the system:

1. LiveIn(B1) = {b, c} ∪ ({a, e} ∪ LiveIn(B3) - {a}) = {b, c, e} ∪ LiveIn(B3)

2. Substitute LiveIn(B3): LiveIn(B1) = {b, c, e} ∪ {a, f} ∪ (LiveIn(B1) - {e})

3. This implies LiveIn(B1) must contain {a, b, c, e, f}. Let's verify: LiveIn(B1) = {b, c, e, f}.

If LiveIn(B1) = {b, c, e, f}, then LiveIn(B3) = {a, f} ∪ ({b, c, e, f} - {e}) = {a, b, c, f}.

Then LiveOut(B1) = {a, e} ∪ {a, b, c, f} = {a, b, c, e, f}.

Check consistency: LiveIn(B1) = {b, c} ∪ ({a, b, c, e, f} - {a}) = {b, c, e, f}. Consistent.

Final Result

LiveOut(B1) = {a, b, c, e, f}

LiveOut(B2) = {d, e}

LiveOut(B3) = LiveIn(B1) = {b, c, e, f}

LiveOut(B4) = ∅

Explore the full course: Gate Guidance By Sanchit Sir