betterIR is my personal research and development lab where I implement various compiler optimizations as out-of-tree LLVM passes. Currently, this repository implements:
- Liveness analysis
- Dead code elimination
- Dead store elimination
To build this project, the following dependencies are required:
- CMake 3.0.0+
- LLVM >= 8.0
- Python 3.x.x (to run the tester)
Follow the steps below to compile this project: 0. Navigate to the root directory of this repository after cloning it.
- In the
CMakeLists.txt, specify the path tollvm xand set the path to the LLVM_INS variable. - Set the version of LLVM that you gen for finding the CMake package of the appropriate version.
mkdir build && cd build && cmake ..make
Assuming the build was successful, you will see a directory called lib containing the shared object libraries for each of the built passes.
The passes may either be run manually by using the LLVM's opt tool:
opt -load-pass-plugin <path-to-shared-object-file> -passes=<name-of-pass> <input-IR-file> -S -o <output-IR-file> -debug
Alternatively, the tester may also be used to optimize a collection of files:
- Configure
tests/config.json:tests-dir: full path to the directory containing the test suite for the pass. The directory must contain the directoriesinputandoutput, where theinputdirectory contains*.llfiles which will be optimized.opt: full path to the LLVM's optimizer executable.lib-path: path to the pass' shared object file
- Run
python3 tests/tester.py tests/config.json