retagged by
13,555 views
26 26 votes

For a statement $S$ in a program, in the context of liveness analysis, the following sets are defined:

$\text{USE}(S)$ : the set of variables used in $S$

$\text{IN}(S)$ : the set of variables that are live at the entry of $S$

$\text{OUT}(S)$ : the set of variables that are live at the exit of $S$

Consider a basic block that consists of two statements, $S_1$ followed by $S_2$. Which one of the following statements is correct?

  1. $\text{OUT($S_1$)} = \text{IN ($S_2$)}$
  2. $\text{OUT ($S_1$)} = \text{IN ($S_1$)} \cup \text{ USE ($S_1$)}$
  3. $\text{OUT ($S_1$)} = \text{IN ($S_2$) }\cup \text{ OUT ($S_2$)}$
  4. $\text{OUT ($S_1$)} = \text{USE ($S_1$)} \cup \text{IN ($S_2$)}$

4 Answers

Best answer
5 5 votes

Given:

Let’s assume the following two statements:

  • S1: a = b + c + d

  • S2: z = b + c + m

Note: Since S1 is followed directly by S2 with nothing in between, OUT(S1) = IN(S2) by definition of basic blocks in liveness analysis.

Also, OUT(S1) and OUT(S2) can be any subset of variables used in S1 or S2, respectively, depending on what variables are live after those statements. That’s why we are free to assume reasonable values for them during elimination.

Now, we evaluate each option:


Option B: OUT(S1) = IN(S1) ∪ USE(S1)

LHS = OUT(S1)
Assume OUT(S1) = {b} (as explained above)

RHS = IN(S1) ∪ USE(S1)
IN(S1) = {b} (assumed)
USE(S1) = {b, c, d}
RHS = {b} ∪ {b, c, d} = {b, c, d}

LHS = {b}
RHS = {b, c, d}
LHS ≠ RHS → Incorrect


Option C: OUT(S1) = IN(S2) ∪ OUT(S2)

LHS = OUT(S1)
Assume OUT(S1) = {b, d}

RHS = IN(S2) ∪ OUT(S2)
IN(S2) = {b, d} (from previous logic)
OUT(S2) = {b, c, m} (assumed live variables)
RHS = {b, d} ∪ {b, c, m} = {b, c, d, m}

LHS = {b, d}
RHS = {b, c, d, m}
LHS ≠ RHS → Incorrect


Option D: OUT(S1) = USE(S1) ∪ IN(S2)

LHS = OUT(S1)
Assume OUT(S1) = {d}

RHS = USE(S1) ∪ IN(S2)
USE(S1) = {b, c, d}
IN(S2) = {d}
RHS = {b, c, d} ∪ {d} = {b, c, d}

LHS = {d}
RHS = {b, c, d}
LHS ≠ RHS → Incorrect


Option A: OUT(S1) = IN(S2)

LHS = OUT(S1)
RHS = IN(S2)
Since S1 is immediately followed by S2, we know OUT(S1) = IN(S2) directly

LHS = RHS → Correct Answer

selected by
24 24 votes

When a statement $S_2$ immediately follows another statement $S_1,$ in a basic block, all variables that are live at exit of $S_1$ must be live at entry of $S_2$ (no intermediate place where they can get killed) and no other variable can be live at entry of $S_2$ as a basic block is always single entry and single exit.

So, $\text{OUT($S_1$)} = \text{IN ($S_2$)}$

Correct option: A

Liveness Analysis Slides

edited by
Answer:
Position:
Show:

Related questions

42 42 votes
3 answers 3 answers
20.3k
20.3k views
Arjun asked Feb 18, 2021
20,285 views
​​​​​​Consider the following $\text{ANSI C}$ code segment:z=x + 3 + y->f1 + y->f2; for (i = 0; i < 200; i = i + 2) { if (z i) { p = p + x + 3; q = q + y->f1; } else { p ...
1 1 vote
1 answers 1 answer
2.7k
2.7k views
palashbehra5 asked Jan 11, 2022
2,664 views
A variable v is live at a program point p if some path from p to program exit contains an r-value occurrence of v which is not preceded by an l-value occurrence of v . Th...
73 73 votes
5 answers 5 answers
38.7k
38.7k views
Misbah Ghaya asked Feb 13, 2015
38,674 views
A variable $x$ is said to be live at a statement $s_{i}$ in a program if the following three conditions hold simultaneously:There exists a statement $S_{j}$ that uses $x$...
22 22 votes
3 answers 3 answers
14.1k
14.1k views
Arjun asked Feb 18, 2021
14,098 views
Consider the following augmented grammar with $\{ \#, @, <, >, a, b, c \}$ as the set of terminals. $$\begin{array}{l} S’ \rightarrow S \\ S \rightarrow S \# cS \\ S \rig...