Skip to content

A toy implementation about Program Dependence Graph using LLVM

Notifications You must be signed in to change notification settings

zhaosiying12138/PDG_demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDG_demo

A toy implementation about Program Dependence Graph using LLVM by zhaosiying12138.

File Organization

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

Usage

Step 1: Make a testfile

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

Step 2: Build Pass

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

Control Dependence Graph Demo

Link

《零基础入门控制依赖图构建的理论与实践》

Acknownledgement

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!!!

About

A toy implementation about Program Dependence Graph using LLVM

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published