The point of this assignment is to familiarize you with the Machine SUIF compiler, which we'll use for several homework assignments on code analysis and optimization. For this first one, you'll
suif-setup script as described
there to define the environment variables needed for use of SUIF.
Also read the Machine
SUIF Overview document to find out how to compile and run a
program using Machine SUIF.
Next, log into drdoom.eecs.harvard.edu and copy the
directory ~cs253r/hw1 into your own area. For example,
use the command
cp -a ~cs253r/hw1 ~In the
hw1 directory, you'll find a subdirectory called
tidy (which is for part 2 of the assignment) and a make
file called Makefile.x86.
The latter contains rules for compiling a C program to Linux/x86
assembly code, using the passes described in the Machine SUIF overview
document. For example, if your test program is called
mysort.c, you can compile and run it like this:
make -f Makefile.x86 mysort.s gcc -o mysort mysort.s ./mysort zebra xylophone yurt wimplePart 1 of the assignment is to get set up and try running Machine SUIF on your little test program. Then mail in your
.c and
.s files to show you're playing along. (See below.)
tidy. It's
a nobbled version of the peep pass that's mentioned in
the overview document. Tidy walks over the control flow
graph of each procedure being compiled, and it uses information about
liveness of variables and register values to recognize and remove
unnecessary instructions.
Your job is to compile tidy, fix the bugs we've planted,
and extend it to handle a case that's described in the comments, but
not yet implemented in the code. We provide a SUIF intermediate file
called input.suif for your pass to read in and clean up.
We also give you the effectiveness statistics
(goodstats.txt) that the completed and debugged pass
should print, so you'll know when you're finished.
Before compiling tidy, make sure that you've set up your
environment for working with SUIF. Be sure that
$LOCAL_BASE points to a directory you can write it, and
that it has the necessary subdirectories (bin,
include, and solib). Go into your
tidy directory and run make. We haven't
introduced any syntactic errors, so that should build the pass and
install the results under $LOCAL_BASE.
To run the pass:
do_tidy -debug 1 -const_prop input.suif output.suifThe
-debug option causes statistics to be printed on
standard error when the pass ends. The file output.suif
is the tidied output file. Both .suif files are binary,
but you can dump their contents in a quasi-assembly format using the
do_print command:
do_print output.suif output.suif.txtYour assignment is to read and improve
tidy.cpp; that's
the only source file that we've broken. When you're finished, your
version of the pass should print statistics as good as (or better
than) those in goodstats.txt.
By default, Machine SUIF passes and libraries are built with debugging
information, so you can use GDB if you wish:
gdb do_tidyPlease work individually on this assignment. You'll need to consult the Machine SUIF documentation, particularly the documents about the "machine" library, the control-flow graph library, and the data-flow analysis library. As mentioned above, the
tidy pass is a thinly disguised,
broken version of the peep pass that comes with Machine
SUIF. Therefore, please don't look at the code for peep
until you've turned in your solution for this assignment.
What to turn in: Send an email message to Glenn containing three attachments:
.sfile produced by compiling your test
program with machine SUIF, and
tidy.cpp.