Consider the following intermediate program in three address code
p = a - b q = p * c p = u * v q = p + q
Which one of the following corresponds to a static single assignment form of the above code?
View worked solution
Answer: B
In Static Single Assignment (SSA) form, the following two rules must be satisfied:
- Each variable is assigned exactly once.
- Every variable must be defined before it is used in any expression.
Let's convert the given intermediate code step-by-step by subscripting the variables to ensure unique definitions:
-
Statement 1:
p = a - b
This is the first definition ofp. Let's name this version .
-
Statement 2:
q = p * c
This is the first definition ofq. Let's name this version . Thepon the right-hand side refers to the most recent definition ofp, which is .
-
Statement 3:
p = u * v
This is a new definition ofp. We must use a new version name, say .
-
Statement 4:
q = p + q
This is a new definition ofq. We name this version .- The
pon the right-hand side refers to the most recent definition ofp, which is . - The
qon the right-hand side refers to the most recent definition ofq, which is .
- The
Combining these, the valid SSA form is:
p3 = a - b
q4 = p3 * c
p4 = u * v
q5 = p4 + q4
This matches Option B.
Elimination of other options:
- Option A: Both
p1andq1are assigned multiple times, violating the single assignment rule. - Option C: Variables
p2,p4, andq3are used on the right-hand side without being defined first. - Option D: The original un-subscripted variables
pandqare used on the right-hand side instead of their SSA-defined versions.
Free practice · Your answers on this page are not saved.
