Live TopThe Reaching Definitions Problem

The Reaching Definitions Problem

  1. To give you a sense that data flow analysis is a technique that can be applied to many problems (not just identifying available expressions), I'd like to consider one more problem related to common sub-expression elimination.
  2. Recognizing which instances of a common sub-expression are redundant isn't enough to enable us to eliminate the redundant expressions. We also have to make sure that the code generated for certain instances of common sub-expressions leaves their values in places (temporaries) from which they can be retrieved when redundant instances are encountered.

    This can get tricky. In the example program, for instance, we somehow have to arrange to use the same temporary to hold z/n when evaluated before the loop and at the end of the loop.

  3. One simple solution to this difficulty would be to ensure that the code generator used the same temporary for all instances of any expression that appears repeatedly in a program.

    This puts more constraints on the code generator than necessary. In the example, there is no reason to put the result of the first instance of y*z in the same location as the result of the instance used for the while loop boolean. Only the value produced for the boolean is used to eliminate evaluation of a redundant CSE.

  4. So, we would like to figure out which instances of a CSE are interconnected in the sense that their results have to be left in a common location so that this location can be known when redundant instances are encountered.
  5. Somewhat surprisingly, this turns into another data flow problem:

  6. With all this said, the equations needed are almost identical to those for AVAIL.
    assignment statements
    Given an assignment of the form

    < p1 > x := exp < p2 >

    REACHING(p2) = ( REACHING(p1) + { GEN(exp) } -
    { other instances of GEN(exp) } - KILL(x))
    if statement
    Given an if statement of the form:

    < p0 > if exp then < p1 > stmt1 < p3 >
    else < p2 > stmt2 < p4 >
    end < p5 >

    REACHING( p5 ) = REACHING( p3 ) U REACHING( p4 )
    REACHING( p1 ) = REACHING( p2 ) = REACHING( p0 ) -
    {  other instances of subexpressions of exp } + {  GEN(exp)  }
    while loop
    Given a while loop of the form:

    < p0 > while < p1 > exp do
    < p2 > stmt < p3 >
    end < p4 >

    REACHING( p1 ) = ( REACHING( p0 ) U REACHING( p3 ))
    REACHING( p2 ) = REACHING( p4 ) = REACHING( p1 ) -
    {  other instances of subexpressions of exp } + {  GEN(exp)  }

  7. There is one interesting difference between the equations for the reaching definitions problem and those we wrote for the available expressions problem. Reaching definitions uses set union while available expressions uses intersection. This reflects the fact that determining available expressions requires "MUST" information. An expression must be evaluated on all program paths to be available. Reaching definitions, on the other hand, involves "MAY" information. A definition reaches a program point if it may be the last instance evaluated on a path to that program point.

Computer Science 434
Department of Computer Science
Williams College

Live TopThe Reaching Definitions Problem