Expression Simplifier

The expression simplifier provides a very important service to pass writers. Our experience with the class project showed that source-to-source transformations implemented within GCC often resulted in large, unreadable expressions. GCC does not provide a symbolic expression simplifier and the students determined it would not be easy to add one given the problems we have mentioned with GCC's IR. The Cetus API, however, made it possible to add a powerful expression simplifier with a modest effort. While it is not as powerful as the simplifiers provided by math packages, such as Maple, Matlab, or Mathematica, it does reduce the expressions to a canonical form and has been able to eliminate the redundancy in the expressions we have encountered in our experiments. Expression simplification enhances the readability of the compiler output and enables other optimizations because it transforms the program into a canonical form. For instance, idiom recognition and induction variable substitution benefited most from the expression simplifier. Recognition is easier because there are fewer complicated expressions to analyze and all expressions have a consistent structure. Substitution can create very long expressions that make later passes less effective unless it is immediately followed by simplification.

To use the expression simplifier, you first create a Simplifier object, then you call its run method on an expression. The Simplifier will not modify the original expression, and instead returns a new, simplified expression.

/* The following code prints 13. */

BinaryExpression a = new BinaryExpression(new IntegerLiteral(3), BinaryOperator.ADD, new IntegerLiteral(4));
BinaryExpression bexpr = new BinaryExpression(a, BinaryOperator.ADD, new IntegerLiteral(6));

(new Simplifier()).run(bexpr).print(System.out);

The Simplifier constructor has some parameters that determine how it should simplify the expression. From experience with the class project, we found that some passes require certain forms of simplification that are not appropriate for other passes. For example, some people are reluctant to simplify floating point expressions because they may no longer have the exact value of the original expression.

The different parameters to the Simplifier will be documented here after they are finalized.