Flow graphs and Basic BlocksTopValue Numbering (cont.)

Value Numbering (cont.)

  1. Value number identifies common subexpressions, by using a table lookup mechanism to associate numbers with instances of expressions in a program in such a way that:
  2. The algorithm proceeds assigning value numbers while traversing a sequence of statements that must be executed sequentially.

  3. This scheme will work fairly well for straight line code containing nothing but references to simple, local variables. In the real world, unfortunately, there are a few more complications to deal with.

  4. The handling of array elements is a fine example of the conservative nature of the analysis algorithms one uses when performing optimization. Such algorithms do not give exact information, but they only make "safe" mistakes. In this case, the algorithm will often fail to identify pairs of expressions that actually are CSE's. The result will be that the code generated will be less efficient (but correct!). On the other hand, the alternative of sometimes accidentally concluding that two expressions are CSE's when they are not is unacceptable. It would result in the generation of incorrect (though efficient) code.

  5. BUT WAIT! It get's worse. We still need to account for control structures and method invocations.

  6. Let's put off control structures for a few more moments.

  7. Finally, if we encounter an invocation, we must:

Computer Science 434
Department of Computer Science
Williams College

Flow graphs and Basic BlocksTopValue Numbering (cont.)