Dumping control flow graph after each optimization pass

Dear devs,

I wanted to know if it is possible to dump the control flow graph
representation of functions before/after each optimization pass.

I found that it is possible to dump the intermediate representation
after each optimization pass using the flags -mllvm -print-after-all.
I also found that it is possible to dump the control flow graph from
the LLVM IR using the command opt -dot-cfg.

I tried to split the output of the -print-after-all flag and saved it
to multiple files.
However, when I run the opt -dot-cfg command on each of those files,
it fails because some variables are not defined.

I wanted to know if it is possible to dump the LLVM IR after every
optimization pass that could then be passed on to opt to dump the
control flow graph representation.
Or is it possible to just dump the control flow graph representation
itself after each optimization pass ?

Please let me know

Thank you

The problem is probably that --print-after-all is not dumping the whole module, e.g. after a function pass it only dumps the function. -mllvm -print-module-scope should force printing of the entire module.