Skip to content
Official PYQ · 2015

GATE CS 2015 Set 1 Q50 — Data Flow Analyses: Constant Propagation, Liveness, CSE

Explain with AI

A variable xx is said to be live at a statement sis_{i} in a program if the following three conditions hold simultaneously:

  1. There exists a statement SjS_{j} that uses xx
  2. There is a path from SiS_{i} to SjS_{j} in the flow graph corresponding to the program
  3. The path has no intervening assignment to xx including at SiS_{i} and SjS_{j}

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

Choose one option
View worked solution

Answer: C

A variable is live at a point in a program if there is a path from that point to a use of the variable along which it is not redefined.

Let us analyze the control flow graph (CFG) and the liveness of variables at the exit of basic blocks 2 and 3:

  1. Basic Block 4 (B4B_4):
    • Contains the statement: y = r * u
    • Since both rr and uu are used here, they must be live at the entry of B4B_4. Thus, Live-in(B4)={r,u}\text{Live-in}(B_4) = \{r, u\}.
  2. Basic Block 2 (B2B_2):
    • Contains:
      s = p + q
      r = r + s
    • The control flows from B2B_2 directly to B4B_4. Therefore, the live variables at the exit of B2B_2 are the same as the live-in variables of B4B_4, which are {r,u}\{r, u\}.
  3. Basic Block 3 (B3B_3):
    • Contains:
      t = q - r
      u = t * v
    • The control flows from B3B_3 directly to B4B_4. Therefore, the live variables at the exit of B3B_3 are also the same as the live-in variables of B4B_4, which are {r,u}\{r, u\}.

Thus, the variables live both at the exit of the statements in basic block 2 and basic block 3 are r and u.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Data Flow Analyses: Constant Propagation, Liveness, CSE questions