Docsity

Partial Redundancy Elimination: Techniques for Efficient Expression Evaluation, Slides of Compilers

Partial preview of the text

Download Partial Redundancy Elimination: Techniques for Efficient Expression Evaluation and more Slides Compilers in PDF only on Docsity!

Partial Redundancy Elimination

Finding the Right Place to Evaluate Expressions Four Necessary Data-Flow Problems

Role of PRE

  • Generalizes:
    1. Moving loop-invariant computations outside the loop.
    2. Eliminating common subexpressions.
    3. True partial redundancy: an expression is sometimes available, sometimes not.

Example: Loop-Invariant Code

Motion

4

t = x+y

= x+y (^) = t

Example: Common Subexpression

Elimination

5

= x+y = x+y

= x+y

t = x+y t = x+y

= t

Modifying the Flow Graph

  1. Add a new block along an edge.
    • Only necessary if the edge enters a block with several predecessors.
  2. Duplicate blocks so an expression x+y is evaluated only along paths where it is needed.

Example: Node Splitting

8

t = x+y

= t

= x+y

= x+y

= x+y

t = x+y

Da Plan Boss --- Da Plan

  1. Determine for each expression the earliest place(s) it can be computed while still being sure that it will be used.
  2. Postpone the expressions as long as possible without introducing redundancy.
  • We trade space for time --- an expression can be computed in many places, but never if it is already computed.

The Guarantee

  • No expression is computed at a place where it its value might have been computed previously, and preserved instead. - Even along a subset of the possible paths.

Anticipated Expressions

  • Expression x+y is anticipated at a point if x+y is certain to be evaluated along any computation path, before any recomputation of x or y.
  • An example of the fourth kind of DF schema: backwards-intersection.

Example: Anticipated Expressions

14

= x+y = x+y

x+y is anticipatedhere and could be = x+y

computed now rather than later.

= x+y

x+y is anticipated here, but is also available. No computa- tion is needed.

Computing Anticipated Expressions

  • Direction = backwards.
  • Meet = intersection.
  • Boundary condition: IN[exit] = ∅.
  • Transfer function: IN[B] = (OUT[B] – Def(B)) ∪ Use(B)

Example: Anticipated Expressions

17

= x+y

= x+y

Anticipated

Backwards; Intersection; IN[B] = (OUT[B] – Def(B)) ∪ Use(B)Docsity.com

“Available” Expressions

  • x+y is in Kill(B) if x or y is defined, and x+y is not later recomputed (same as previously).
  • Confluence = intersection.
  • Transfer function:

OUT[B] = (IN[B] ∪ INANTICIPATED[B]) – Kill(B)

Earliest Placement

  • x+y is in Earliest[B] if it is anticipated at the beginning of B but not “available” there. - That is: when we compute anticipated expressions, x+y is in IN[B], but - When we compute “available” expressions, x+y is not in IN[B].
  • I.e., x+y is anticipated at B, but not anticipated at OUT of some predecessor.