Opt syntax for callgraph with new pass manager

Hi everyone,
I am looking at getting a call graph from a piece of C++ code with the opt command from llvm. I found some instructions which were written 7-8 years ago and tried following it. The following is what I have got.

$ clang++ -I …/include/ -S -emit-llvm test.cpp -o test.dot
$ opt -f -passes=dot-callgraph ./test.dot
opt: unknown pass name ‘dot-callgraph’

If I use ‘print-callgraph’ then I get a ascii file with “Call graph node” instructions in it.
But cannot get dot-callgraph work so far.
So, is anyone kind enough to advice how should the command syntax be like?
Thanks.

$ opt -passes=dot-callgraph /tmp/a.ll -disable-output
Writing '/tmp/a.ll.callgraph.dot'...

works for me, perhaps you’re using an old version?

This is my llvm version, i guess the version is kinda close to the latest. How do you think? Thanks!

$ opt --version
Ubuntu LLVM version 14.0.0

Optimized build.
Default target: x86_64-pc-linux-gnu

You can use godbolt to see which version of opt works, looks like it’s LLVM 15 where it first starts working: Compiler Explorer

Thank you, with your advice I eventually get opt working.
Now the problem is that after I installed graphviz and using “dot” to generate a picture from what “opt” had emitted, the chart is shrinked to 17% of original, and it became too blue to see. Not sure how to get it better… do you have any ideas?
Thanks.

17% of what original? I.e. what is “original” in your case? Can’t you just zoom in (if you use svg output then any zoom shouldn’t be a problem, although I don’t remember any issues with png’s either)?

I had a typo in previous reply. The picture contains quite a lot functions and “dot” thought the pic was too large, so it said it shrinked the pic to 17% of the size that it generated, and it was all done by “dot” so I couldn’t prevent it from doing so… After the shrink, so many lines and rectangles resided in small number of pixels that when I zoom in it just got too blurry to see function names.

Use svg format then (-Tsvg).

Before I can generate meaningful pic, I found a few function calls are not properly analyzed by “dot”. Acutally I am not sure if it’s with “dot” or “opt”.
For example the following parse() call will result in countless “bad label format” errors from “dot”.

Note: I was using version 15.x of clang and opt, while using graphviz 2.43.

Source code:

std::ifstream F("/home/xxx/test/example.json");
json J = json::parse(F);

After processed by “opt”, here is part of countless errors generated from “dot”:

Error: bad label format {std::__uniq_ptr_data<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >::create<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char const (&) [1]>(char const (&) [1])::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1}, true, false>::__uniq_ptr_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >::create<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char const (&) [1]>(char const (&) [1])::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1} const&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >::create<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char const (&) [1]>(char const (&) [1])::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1} const&)}
Error: bad label format {std::__uniq_ptr_impl<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >::create<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char const (&) [1]>(char const (&) [1])::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1}>::__uniq_ptr_impl<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >::create<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char const (&) [1]>(char const (&) [1])::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1} const&>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >::create<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char const (&) [1]>(char const (&) [1])::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)#1} const&)}