static void D() { }
static void Y() { D(); }
static void X() { Y(); }
static void C() { D(); X(); }
static void B() { C(); }
static void S() { D(); }
static void P() { S(); }
static void O() { P(); }
static void N() { O(); }
static void M() { N(); }
static void G() { M(); }
static void A() { B(); G(); }
int main() {
A();
}
それで
$ clang++ -S -emit-llvm main1.cpp -o - | opt -analyze -dot-callgraph
$ dot -Tpng -ocallgraph.png callgraph.dot
いくつかの光沢のある画像が得られます(main
外部リンケージがあり、その翻訳単位の外部からも呼び出される可能性があるため、「外部ノード」があります):

c++filt
関連する関数とクラスのマングルされていない名前を取得できるように、これを で後処理することをお勧めします。以下のように
#include <vector>
struct A {
A(int);
void f(); // not defined, prevents inlining it!
};
int main() {
std::vector<A> v;
v.push_back(42);
v[0].f();
}
$ clang++ -S -emit-llvm main1.cpp -o - |
opt -analyze -std-link-opts -dot-callgraph
$ cat callgraph.dot |
c++filt |
sed 's,>,\\>,g; s,-\\>,->,g; s,<,\\<,g' |
gawk '/external node/{id=$1} $1 != id' |
dot -Tpng -ocallgraph.png
この美しさをもたらします (最適化をオンにしないとサイズが大きすぎます!)

その神秘的な名前のない関数 はNode0x884c4e0
、定義が不明な関数によって呼び出されると想定されるプレースホルダーです。