1

The Requirement:

I want a CFG + Callgraph per-module like:

https://github.com/rust-lang/rustc-dev-guide/blob/master/src/mir/mir_cfg.svg


What Have I Tried?

I discovered that opt could generate a Callgraph and a CFG from LLVM-IR using two -dot-cfg and -dot-callgraph command-line options. But there is a problem: -dot-cfg and -dot-callgraph are two separate options that don't care about each other. Consider the following C++ code:

int main() { [] {} (); }

When I try to generate a CFG + Callgraph using those two options:

$ clang++ -S -emit-llvm Main.C
$ opt -enable-new-pm=0 -dot-cfg -dot-callgraph Main.ll
Writing '.main.dot'...
Writing '._ZZ4mainENK3$_0clEv.dot'...
Writing 'Main.ll.callgraph.dot'...

The reason that I used -enable-new-pm=0: https://stackoverflow.com/a/67578423/9248466

It will generate three separate files: one for the calls graph and others for the CFG(one file per function).


Possible Solution:

One possible solution(and my last bullet) is to merge the files manually.


Environment:

  • LLVM Toolchain Version:
    • Clang: 16.0.0-++20220814102906+6afcc4a459ea-1~exp1~20220814222919.677
    • Opt: 16.0.0 (x86_64-pc-linux-gnu, westmere)
  • OS: Debian 10 buster, x86_64 Linux 4.19.0-21-amd64
  • GraphVIZ: 2.40.1-6+deb10u1
    • dot: graphviz version 2.40.1 (20161225.0304)
markalex
  • 8,623
  • 2
  • 7
  • 32
Ghasem Ramezani
  • 2,683
  • 1
  • 13
  • 32

0 Answers0