Repository for understanding and writing LLVM passes.
This needs ~40GB disk space and compilation time of ~90min.
-
Download LLVM-8.0.0, clang-8.0.0
-
Unzip the LLVM and Clang source files
tar xf llvm-8.0.0.src.tar.xz tar xf cfe-8.0.0.src.tar.xz mv cfe-8.0.0.src llvm-8.0.0.src/tools/clang
-
Create your target build folder and make
mkdir llvm-8.0.0.obj cd llvm-8.0.0.obj cmake -DCMAKE_BUILD_TYPE=Debug ../llvm-8.0.0.src (or add "-DCMAKE_BUILD_TYPE:STRING=Release" for releae version) make -j8
-
Add paths for LLVM and Clang
export LLVM_SRC=your_path_to_llvm-8.0.0.src export LLVM_OBJ=your_path_to_llvm-8.0.0.obj export LLVM_DIR=your_path_to_llvm-8.0.0.obj export PATH=$LLVM_DIR/bin:$PATH
The folder examples contains a couple of example .c
files which you can play with.
LLVM passes run on bitcode file. Here, we explain how to convert a C
file to bitcode file.
clang -c -emit-llvm <path_to_c_file> -o <path_to_output_bitcode_file>
Example:
cd examples
clang -c -emit-llvm simple.c -o simple.bc
The folder llvm_passes contains various sample LLVM passes.