TopThe Reaching Definitions ProblemLive "variable" analysis

Live "variable" analysis

  1. The last step in this process is to actually assign temporaries to the groups of related instances found using the results of the "reaching definitions" analysis.
  2. The standard approach to this problem is based on graph-coloring:
  3. Coloring a graph is an NP-complete problem, but this doesn't seem to bother anyone. Using simple, greedy heuristics apparently works well in progress.
  4. The issue I want you to think about, is how to we determine which nodes in the graph to connect. That is, how to we decide if the value produced by an instance of an expression may be used in the future.
  5. Once again, we can answer the problem using the data-flow analysis approach.
  6. Recall from the discussion of Reaching definitions that once we have solved the Available expressions problem we can identify instances of CSE's as uses and definitions.
  7. To figure out what values must be kept in temporaries at a particular point we will solve a problem that might be called "reachable uses" (but is actually called "live variables"). Basically, for each program point we will determine the set of CSE instances that are a) uses and b) reachable from the program point through an execution path that does not include any other definition of the expression.
  8. Once again, it helps to have some auxiliary functions:
    use(exp)
    will be the set of redundant CSE instances occurring as sub-expressions of exp
    kill(exp)
    will be the set of all redundant CSE instances that are textually equivalent to any non-redundant CSE instance appearing as a sub-expression of exp
  9. Then, the equations for determining which instances are "LIVE" at a particular point are:
    assignment statements
    Given an assignment of the form

    < p1 > x := exp < p2 >

    LIVE(p1) = LIVE(p2) + use(exp) - kill(exp)
    if statement
    Given an if statement of the form:

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

    It must be the case that:
    LIVE( p0 ) = LIVE( p1 ) + LIVE( p2 ) + use(exp)
    LIVE( p3 ) = LIVE( p4 ) = LIVE( p5 )
    while loop
    Given a while loop of the form:

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

    it must be the case that:
    LIVE( p0 ) = LIVE( p1 ) + LIVE( p3 ) + use( exp )
    LIVE( p2 ) = LIVE( p0 )
  10. The values needed by two expression instances that are live at a given program point must not be assigned to the same temporaries (unless the instances are instances of the same CSE).

    So, the "liveness" information gives you what is needed to build an interference graph and do temporary (i.e. register) allocation.

  11. All the data-flow problems used to do redundant CSE elimination obviously have a lot in common. There are some important differences:

    These categories are used to partition data-flow analysis problems into four groups (of which you have seen everything but a backwards-must example).


Computer Science 434
Department of Computer Science
Williams College

TopThe Reaching Definitions ProblemLive "variable" analysis