In this programming assignment, you will implement several dataflow analyses and optimizations. These will build upon the code that you wrote for previous assignments.
You will implement a generic dataflow analysis framework and then instantiate it for several analyses: live variable analysis, available expressions, reaching definitions, and constant folding analysis. You will then use the result of these analyses to perform dead code elimination, common sub-expression elimination, loop-invariant code motion, constant folding, and strength reduction of induction variables.
The compiler will first parse the program, check for semantic error, generate intermediate code, and build the control flow graph. When invoked from the command line, the compiler must support the following optimizations:
dce", it must perform dead code elimination
cse", it must perform common subexpression elimination
lcm", it must perform loop-invariant code motion
cfo", it must perform constant folding
sri", it must perform strength reduction of induction variables
The compiler will perform the optimizations in the order they occur in the command line. The above arguments may be invoked multiple times in the same command line - in that case the compiler will execute them multiple times, in the order specified. It will only perform the analyses necessary for the optimizations requested.
Your dataflow analysis code will consist of an abstract dataflow analysis
IC.DFA.DFAEngine, and an abstract dataflow information class
The constructor of your dataflow information object must return the top
element in the lattice, and must have a
Meet method which takes
another dataflow information object as argument and returns the meet operation
between this object and the other object. It must also support an
method which tests if two dataflow information objects correspond to the same
element in the lattice.
The dataflow analysis class
DFAEngine has a method
which takes as argument a control flow graph which iteratively solves the
dataflow equations (using the worklist algorithm) and computes dataflow
information at each program point in the flow graph. The dataflow analysis class
also contains a
TransferFunction method which models the transfer
functions in the dataflow analysis framework. It takes a low-level IR
instruction and a dataflow information object as parameters and returns the
resulting dataflow information. You should allow your dataflow analysis class to
be instantiated either a a forward or as a backward analysis.
You will then use your dataflow analysis framework to implement several dataflow analyses and use their results for subsequent optimizations. There are four dataflow analyses that you will implement in this assignment:
Next, you will implement the following optimizations in the compiler:
Your compiler must still support the command line switches
-dump-cfg from last assignment, which produce textual outputs
of the low-level code and of the flow graph. In addition, your compiler will
detect function calls of the form
showDFAinfo() in the program and
will produce a textual output of the dataflow information at the program point
where the function is invoked. This function must not be moved out of loops,
as part of the loop invariant code motion transformation.
your files in
is your group identifier. Use the same directory structure for the electronic
submission as in the previous assignments :
src\ - all of your source code and class files;
doc\ - documentation, including your write-up and a
containing information on how to compile and run your project, a description
of the class hierarchy of your source code, brief
descriptions of the major classes, any known bugs;
test\ - test cases you used in testing your