Developed by Brian DeRenzi and Wenrui Gong
Owned by the Regents of the University of California
A zipped tarfile of this software as of 06/06/2005 is available here.
(Last updated 06/08/2005)
More SUIF passes here.
UCSB
ExPRESS Group
The JuanCSE is a compiler passes built on the SUIF 2 compiler infrastructure. For information on downloading, compiling and installing the SUIF infrastructure see this step by step guide. Juan comes from the Chinese word meaning Happiness.
The Common Subexpression Elimination (CSE) pass allows for a simple CSE optimization algorigthm to be run on the code. The CSE algorithm was adapted from one presented by Steven S. Muchnick in Advanced Compiler Design & Implementation (Morgan Kaufmann, 1997).
To install the JuanCSE pass, first double check that SUIF environment is completely setup and working
on your system. Once you are familiar with how the system works and have confirmed that all
environment variables and paths are setup correctly, extract the file in the usual way:
tar -xzf cse_06_06_2005.tar.gz
This will create a directory called cse in the current working directory.
Change into the cse directory and type make to compile the CSE pass.
NOTE: This will not work if the SUIF environment--and the subsequent environment variables--is not setup correctly. If there are any problems compiling, please double check your SUIF installation to ensure that it is properly configured.
The easiest way to use the JuanCSE pass is to create simple shell script to execute a series of SUIF
commands. The order of commands looks something like this:
c2suifsuifdriversuif2cc2suif command will compile the C programming file into the SUIF intermediate
representation. It is this representation (denoted by files ending in .suif) that the JuanCSE pass
operates on. An example is show below:bash$ c2suif test.c
The second step, executing suifdriver will be used to execute the various compiler passes
on the SUIF code. Each pass described below shows an example of how to use the suifdriver
program to inmport all of the necessary modules and execute the pass. In addition to executing the
suifdriver application in a multiple lined manner (as is described below), it is possible
to supply the execution string immediatly using the following syntax:
bash$ suifdrive -e "..."
Where the ... is replaced by the neccessary import, load, execute and save commnads.
To see the resulting C code, it is necessary to convert the SUIF code back to C code. This is done
using the suif2c program. The following example illustrates how easy this is to use:
bash$ c2suif -o test.out.c test.out.suif
The -o option merely allows the user to specify an output filename. Once the C code
is generated, it can be checked for accuracy. See the following sections for more specific
information about each pass.
The CSE pass is used by first importing the JuanCSE
module into the suifdriver application. Then, the juan_cse pass is
executed. This will preform very basic CSE on the code. For example:
bash$ suifdriver
import suifnodes basicnodes cfenodes utils transforms usefulpasses;
import JuanCSE;
load test.suif;
juan_cse;
save test.cse.suif
(CTRL-D to terminate)
This will import the necessary modules and passes, load in the test.suif file and execute
the CSE pass on the code, finally saving the suif file to test.cse.suif. From here, the
suif2c application can be used to conver the test.cse.suif file back to C.
Again, the easiest way to test the pass is to write a small test program to run through the pass.
A simple example program is show below:
int
test() {
int i, j, k, m=2, n=4;
i = m + n;
j = n + m;
k = m + n;
}
The pass should replace the recurring m + n with a single temporary variable.
To run this test, download the input test file, the
shell script, and the expected output.
Currently, a few improvements are planned. The SUIF infrastructure automatically converts all expressions to BinaryExpressions when it translates the C code to the SUIF intermediate represenation. We are currently working on a new pass which will rebuild the initial expressions so that more complex CSE can be performed, searching for parts of the larger expression. In addition, more testing is required on this pass to ensure that it works correctly.