Giter Club home page Giter Club logo

pdg_demo's Introduction

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

pdg_demo's People

Contributors

zhaosiying12138 avatar zhaoyuanchu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.