A toy implementation about Program Dependence Graph using LLVM by zhaosiying12138.
demo/test.c : original C test file
demo/test_opt.ll & test_opt_cfg.png: the LLVM IR & CFG generated by Clang and Graphviz
demo/test_opt_with_header.ll & demo/test_opt_with_header_cfg.png: add unique ENTRY and STOP Basic Block to test_opt.ll [manually]
demo/zsy_test_cdg_auto_generated.dot & zsy_test_cdg_auto_generated.png: the CDG dotfile and pic generated by our tools after the analysis
clang -Xclang -disable-O0-optnone -S -O0 -emit-llvm test.c -o test_tmp.ll
opt -S -simplifycfg test_tmp.ll -o test_opt.ll
opt -dot-cfg test_opt.ll > /dev/null
dot -T png -o test_opt_cfg.png .zsy_test.dot
sxiv test_opt_cfg.png
mkdir build
cd build
cmake ..
make -j 65535
Step 3: Call opt to enable our PDG-Pass to analysis LLVM IR and construct the Control Dependence Graph
opt --enable-new-pm --load-pass-plugin /your_path_to_PDG_demo/build/PDGAnalyzer.so --passes="pdg-analyzer" --disable-output /your_path_to_PDG_demo/demo/test_opt_with_header.ll
dot -T png -o /your_path_to_PDG_demo/demo/zsy_test_cdg_auto_generated.png zsy_test_cdg_auto_generated.dot
sxiv zsy_test_cdg_auto_generated.png
Thanks for the help of https://github.com/PacktPublishing/LLVM-Techniques-Tips-and-Best-Practices-Clang-and-Middle-End-Libraries/tree/main/Chapter09 to let me get started in writing the LLVM Pass from ZERO!
This is my first LLVM Pass written in my life!!!