LLVM CFG PRINTER
Information
- LLVM version:
9.0.0svn
; - CMake version:
3.13.4
; - Some classes like
ConstantExpr
,ConstantAggregate
andPHINode
are recursively built by using its own operands; - I use the same labels assigned by the llvm on the Basic Blocks to identify each node;
Compilation
Compilation outside the LLVM
export LLVM_DIR=<path to llvm build>
cd <printer base dir>
mkdir build
cd build
cmake ..
make
Compilation inside the LLVM
To add the Pass to the llvm compilation tree:
cp BitcodePrinter <path to llvm source>/llvm/lib/Transforms/
- Add
add_subdirectory(BitcodePrinter)
to<path to llvm source>/llvm/lib/Transforms/CMakeLists.txt
Then, we can compile the llvm normally (now with our pass included):
cd <path to llvm source>
mkdir build
cd build
cmake .. -G "Unix Makefiles"
make
Execution
Outside the LLVM compilation
opt -load BitcodePrinter/LLVMBitcodePrinter.so -bitcode-printer < <filename>.bc
Inside the LLVM compilation
opt -bytecode-printer < <filename>.bc
Execution option
The generated .dot files will be in the same directory that the command was run with the name <function name>.dot
. If you want to add a suffix name in the name of the .dot
output files, you can use the -s <suffix>
option:
opt -load BitcodePrinter/LLVMBitcodePrinter.so -bitcode-printer -s <suffix> < <filename>.bc
The resulting files now will have the name <suffix>_<function name>.dot
.