A variable x is said to be live at a statement si in a program if the…

2015

A variable x is said to be live at a statement si in a program if the following three conditions hold simultaneously:

There exists a statement sj that uses x

There is a path from si to sj in the flow graph corresponding to the program

The path has no intervening assignment to x including at si and sj

image.png

The variables which are live both at the statement in basic block 2 and at the statement in basic block 3 of the above control flow graph are

  1. A.

    p, s, u

  2. B.

    r, s, u

  3. C.

    r, u

  4. D.

    q, v

Attempted by 22 students.

Show answer & explanation

Correct answer: C

Live variable analysis tracks variables used before redefinition. In Block 2, v = r + u uses r and u, making them live at the entry of Block 2. In Block 3, q = s * u uses s and u. Additionally, paths from Block 3 lead to Block 4 where v and r are used, so they remain live at the entry of Block 3. Comparing the sets {r, u} for Block 2 and {s, u, v, r} for Block 3 reveals the common live variables are r and u.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir