A variable is said to be live at a statement in a program if the following three conditions hold simultaneously:
- There exists a statement that uses
- There is a path from to in the flow graph corresponding to the program
- The path has no intervening assignment to including at and

The variables which are live both at the statement in basic block and at the statement in basic block of the above control flow graph are
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:
- Basic Block 4 ():
- Contains the statement:
y = r * u - Since both and are used here, they must be live at the entry of . Thus, .
- Contains the statement:
- Basic Block 2 ():
- Contains:
s = p + qr = r + s - The control flows from directly to . Therefore, the live variables at the exit of are the same as the live-in variables of , which are .
- Contains:
- Basic Block 3 ():
- Contains:
t = q - ru = t * v - The control flows from directly to . Therefore, the live variables at the exit of are also the same as the live-in variables of , which are .
- Contains:
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.
