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?

Answer: B. p3 = a - b q4 = p3 * c p4 = u * v q5 = p4 + q4CONCEPT: Static single assignment (SSA) gives every definition a distinct versioned name. Each use must refer to the version produced by the definition that…

  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 171 students.

Show answer & explanation

Correct answer: B

CONCEPT: Static single assignment (SSA) gives every definition a distinct versioned name. Each use must refer to the version produced by the definition that reaches that program point; the particular subscripts are arbitrary, but definition-use links are not.

APPLICATION: Trace the four statements in source order and create a fresh name at each assignment.

  1. The first definition of p becomes p3 = a - b.

  2. The next statement uses that reaching definition, so it becomes q4 = p3 * c.

  3. The later assignment to p creates a new version: p4 = u * v.

  4. The final statement uses the newest p and the earlier q, so it becomes q5 = p4 + q4.

CROSS-CHECK: The left-hand names p3, q4, p4, and q5 each occur as a definition exactly once. Every right-hand version has already been defined, and the final expression preserves the original dependence on the second p value and the first q value.

Therefore the SSA form is 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: Iocl Engineers Officers Grade A Paper 2

Loading lesson…