It is possible to generate CFG + Callgraph in one file?

The Requirement:

I want a CFG + Callgraph per-module like:

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 ''...
Writing '._ZZ4mainENK3$'...
Writing ''...

The reason that I used -enable-new-pm=0: clang - LLVM doesn't generate CFG - Stack Overflow

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.


  • 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)