LLVM provides passes to perform analysis or tansformation on LLVM IR. These passes can be used to improve the performance of the code or to analyze the code for bottlenecks.
There are three types of passes in LLVM:
- Analysis Passes
- Transformation Passes
- Utility Passes
This repository contains 2 examples of analysis passes:
- ListFunction: Lists all the functions along with their argument size, basic block count and instruction count.
- StaticCallCounter: Counts the number of static calls to a function.
These passes are out-of-tree. Because adding any pass into LLVM requires building it again and again, which was not feasible for our case.
- LLVM 15.x.x
- clang
- Change the path of your LLVM installation directory in root CMakeLists.txt.
mkdir build
cd build
cmake ../
cmake --build .
opt -load-pass-plugin ./lib/libListFunction.so -passes=list-function -disable-output <input ll file>
opt -load-pass-plugin ./lib/libStaticCallCounter.so -passes=static-call-counter -disable-output <input ll file>