Programs on this project are divided into the three parts.
- Compiler(
src/core
)- This is for making the main compiler that uses optimization passes.
- Also, there is a backend that translates IR code to Assembly.
- Optimization(
src/passes
)- It contains every optimization created by ourselves.
- Also, there are several passes from TA's repository.
- Test(
src/test
)- It contains codes for testing (unit tests(googletest + shell) and case tests).
- It will be used to make the vanilla compiler to compare with (default).
- Case tests are done concurrently.
To execute a c code, we need to turn it into a machine friendly language. It can be done with gcc compiler easily, but it's too easy that it's hard to expect good performance.
Our compiler will read the same c code to make better assembly code using LLVM optimization. It will first transfer c code into ll with llc in LLVM. Then it will apply optimization passes, and transfer to assembly language using the backend. To execute assembly and measure the cost, we need an interpreter, which is also included in our project.
Our test code will compare the outputs and costs between the optimized compiler and vanilla one. The vanilla compiler does not optimize anything. The test program will compare two outputs and interpreter's logs from each assembly code.
-
Build
./configure.sh <LLVM-BIN> <THREADS NUM(default is 8 if omitted)> make #or make all
./configure.sh
is to generate a properMakefile
inside the repository. The<THREADS NUM>
is used for the concurrent case test.make
command will automatically build 3 executable programs insidebin
directory: sf-compiler-team7, interpret, sf-compiler-test-team7, sf-compiler-vanilla. -
Test
make test
The code
make test
command will check if the compiler runs with no error with given test cases. It will also compare performance with thenopass
option compiler.If you want to compare the results between
[ALL PASSES] - [SOME PASSES]
and[ALL PASSES]
, then you can use:make test PASSES="WeirdArith,PackRegister"
-
sf-compiler-team7 (./bin/)
./bin/sf-compiler-team7 <input.ll> -o <output.s> -d <output.ll>
Our compiler compiles IR code(.ll) to assembly code(.s). It links
read
andwrite
functions in the LLVM library, applies passes, and then translates to assembly code. "-o" flag specifies the name of the output assembly file. If it is not given, it will be set to default value "a.s". "-d" flag is optional. It specifies the name for output IR code. If it is given, it also prints IR code which the optimization passes are applied from the original IR code.Also, with the
except
flag, we can choose which passes not to apply while compiling. To apply none of the pass, we can usenopass
option../bin/sf-compiler-team7 input.ll -o output.s -d output.ll -except "WeirdArith,PackRegister" ./bin/sf-compiler-team7 input.ll -o output.s -d output.ll -nopass
-
checker.sh, single_checker.sh (./test/)
./test/checker.sh <testcase path>
This is a shell script which
make test
command calls. It checks every given testcase directory. There are.c
,.ll
and.s
files on each src folder, which are the compilation results from thenopass
option compiler. It first translates IR(.ll
) code to assembly code using our compiler: sf-compiler-team7. It will check if the outputs of two assembly codes are the same values, and compare their costs.If you want to compare the results between
[ALL PASSES] - [SOME PASSES]
and[ALL PASSES]
, then you can use:./test/checker.sh <testcase path> WeirdArith,PackRegister
If you want to run a single testcase, then please use single_checker.sh by
./test/single_checker.sh <single testcase dir>
-
sf-compiler-test-team7 (./bin/)
./bin/sf-compiler-test-team7
This is googletest. It contains an unit test for
ReorderMemAccess
. -
test-gen.sh (./test/)
./test/test-gen.sh <testcase dir> [<llvm bin path>]
This program generates
.ll
and.s
files from.c
using the vanilla compiler. After that, it becomes a valid testcase folder. If the llvm bin path is not passed, then it contruct a testcase structure at the given testcase dir using./test/template.c
. -
plot.py (./test/)
python3 ./test/plot.py
This program generates a graph plot from the output logs of
make test
(orsingle_checker.sh
). One should installpython3
,numpy
,matplotlib
in order to run this.