Yet another learning path to the heart of the LLVM compiler infrastructure.
-
llvm-first-step - the simplest
llvm
demo: just reads a bitcode file and outs how many basic blocks are in every function. -
llvm-front-clang-demo - let's see how to deal with
clang-lib
: lexer, parser, diagnostics, traversing the AST, etc. The most interesting example is declared-methods-c.cpp that demonstrates how to distinguish declarations from definitions. -
llvm-ir-custom-passes - a collection of analysis and optimization passes for the
opt
tool. You can start from the FunctionArgumentUsagePass analysis pass that diagnoses type mismatches around function calls. The idea is borrowed from the task Writing your own Analysis Pass, course CSCI565 Compilers Design.P.S. There is an instruction how to build the passes as a part of the LLVM build tree and a patch for LLVM sources which can help you register the passes.
-
llvm-backend-x86-machine-pass - a collection of machine passes for the
X86
backend. Passes demonstrate how to deal with the code generation, data-flow analysis, register allocation, MC layer and other cool back-end stuff.P.S. There is an instruction how to build the machine passes as a part of the LLVM build tree and a patch for LLVM sources which can help you register the passes.
-
llvm-ir-tests - a bunch of source code (C/C++) and .bc files to test the compiler infrastructure.
-
llvm-unit-tests - in the XXI century without unit tests? No way! There are all unit tests for the code in the repository. The directory matches to the
unittests
one from the LLVM source tree.
I wish to thank Bruno Cardoso Lopes and Rafael Auler, the authors of Getting Started with LLVM Core Libraries. Their book is the best introduction in the LLVM infrastructure I met. Some examples from the book were used as a kick-starters for the project.
You need CMake to build the experiments (those parts which don't
have to be built as parts of the LLVM source tree). The variable LLVM_INSTALL_PREFIX
must point to the parent directory of an LLVM installation.
Note: The build type of the experiments should correspond to the build type of the LLVM installation taken in account otherwise a number of linker errors will occur at least, if you are using the MSVC compiler.
# mkdir build
# cd build
# cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_INSTALL_PREFIX="<PATH_TO_YOUR_LLVM>" -G"Ninja" ..
# cmake --build .
Now the unit tests can be starting from the build/llvm-unit-tests
dir:
# cd llvm-unit-tests
# ctest -V
...
100% tests passed, 0 tests failed out of ...