Questions: Live Variable Analysis

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

Consider this code sequence: `x = 5; y = x + 1; x = 10; return y;`. Is x live immediately after the statement `x = 5`?

ANo, because x is eventually overwritten by `x = 10` before the function returns
BNo, because only y is returned, so x's value is irrelevant throughout
CYes, because x holds a value that was just assigned and therefore must be live
DYes, because the next statement `y = x + 1` uses x before x is overwritten
Question 2 Multiple Choice

Why does live variable analysis propagate information backward through the control flow graph, unlike most forward dataflow analyses?

ABecause register allocation is performed in reverse program order by convention
BBecause dead code elimination removes instructions starting from the end of basic blocks
CBecause a variable's liveness at a point depends on whether future statements use it, which requires knowing what comes after
DBecause the gen and kill sets can only be computed after the interference graph is constructed
Question 3 True / False

Two variables that are assigned values at different points in a program cannot interfere with each other in register allocation, since they are live at different times.

TTrue
FFalse
Question 4 True / False

An assignment to a variable that is not live after the assignment can always be safely removed, because the assigned value will never be read.

TTrue
FFalse
Question 5 Short Answer

Explain why live variable analysis flows backward rather than forward through the control flow graph, and how the definition of liveness determines this direction.

Think about your answer, then reveal below.