293 views
0 0 votes

Consider the following basic block of Three-Address Code:

1. a = 1
2. b = a + 1
3. c = a + b
4. a = c + b
5. return a

A variable is live at a point if its current value will be used in the future before being redefined. Assuming only the variable $\mathrm{a}$ is live at the exit of this block, which variables are live immediately after statement $2$ has executed?

  1. $\{\mathrm{a, b}\}$
     
  2. $\{\mathrm{b, c}\}$
     
  3. $\{\mathrm{a}, \mathrm{b}, \mathrm{c}\}$
     
  4. $\{\mathrm{a, c}\}$

1 Answer

0 0 votes
After 5: $\{\mathrm{a}\}$ is live (given).

After 4: To compute $\mathrm{a=c+b}$, we need $\mathrm{c}$ and $\mathrm{b}$. So $\{\mathrm{c}, \mathrm{b}\}$ are live.

After 3: To compute $\mathrm{c}=\mathrm{a}+\mathrm{b}$, we need $\mathrm{a}$ and $\mathrm{b}$. However, $\mathrm{b}$ is also needed for the later instruction (line 4). So $\{\mathrm{a}, \mathrm{b}\}$ are live.

Immediately after statement 2, we need both $\mathrm{a}$ and $\mathrm{b}$ to satisfy the requirements of statements 3 and 4 .

The live set is $\{\mathrm{a}, \mathrm{b}\}$.
Answer:
Position:
Show:

Related questions

0 0 votes
1 1 answer
328
328 views
GO Classes asked Jan 27
328 views
Consider the following sequence of three-address code (TAC) instructions:1. i = 1 2. j = 1 3. t1 = 5 * i 4. t2 = t1 + j 5. a[t2] = 0 6. j = j + 1 7. if j <= 5 goto (3) 8....
2 2 votes
2 2 answers
319
319 views
GO Classes asked Jan 27
319 views
Consider the following grammar $G$ with start symbol $S$ :$$\begin{aligned}& S \rightarrow L=R \\& S \rightarrow R \\& L \rightarrow * R \\& L \rightarrow i d . \\& R \ri...
1 1 vote
2 2 answers
281
281 views
GO Classes asked Jan 27
281 views
Consider the following Syntax-Directed Translation (SDT) scheme with the grammar rules and actions provided below:$$\begin{aligned}& S \rightarrow S_1 \# T\left\{S . \mat...
2 2 votes
3 3 answers
362
362 views
GO Classes asked Jan 27
362 views
Consider the following lexical specification for a scanner:$\mathrm{KEYWORD\_IF: \verb|if|}$ $\mathrm{ID: [a-z][0-9]*}$ $\mathrm{NUM: [0-9]+}$ The scanner follows the Lon...