Consider the following intermediate program in three address code p = a - b q…

2017

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?

  1. A.

    p1 = a - b

    q1 = p1 * c

    p1 = u * v

    q1 = p1 + q1

  2. B.

    p3 = a - b
    q4 = p3 * c
    p4 = u * v
    q5 = p4 + q4

  3. C.

    p1 = a - b
    q1 = p2 * c
    p3 = u * v
    q2 = p4 + q3

  4. D.

    p1 = a - b
    q1 = p * c
    p2 = u * v
    q2 = p + q

Attempted by 136 students.

Show answer & explanation

Correct answer: B

Key insight: in static single assignment (SSA) each variable is assigned exactly once. Rename each assignment and update uses so they refer to the correct definition.

  • Rename the first assignment: p3 = a - b

  • Use that p in the next statement: q4 = p3 * c

  • Rename the second p assignment: p4 = u * v

  • Finally use the second p and the earlier q: q5 = p4 + q4

Resulting SSA form:

  • p3 = a - b

  • q4 = p3 * c

  • p4 = u * v

  • q5 = p4 + q4

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir