6

There is -view-cfg option (doc) in llvm's opt program, which enables me to view the Control Flow Graph via dot program. But the CFG in too big to be rendered as postscript from dot. I know that there is the xvcg utiity capable of displaying complex graphs, including CFG (and its man says "VCG tool - visualization of compiler graphs").

So, how can I output llvm's CFG in xvcg format?

osgx
  • 90,338
  • 53
  • 357
  • 513

1 Answers1

8

Directly generating .vcg files from LLVM will require heavy modifications to GraphWriter, which is very GraphViz-specific. Instead, it seems to me that the most straightforward solution will be to save a dot file (via -dot-cfg instead of -view-cfg) and then convert it, using something like Graph-Easy. From its documentation (emphasis mine):

It understands the following formats as input:

The output can be a dump of the graph in one of the following formats:

By the way, if you want to get a lot of graphs and prefer to see them before generating a lot of dot files, consider using a dot viewer which also allows you to save the file, such as my fork of xdot.py - or better yet, modify xdot.py so that it knows how to save in .vcg format itself, using Graph-Easy.

Another alternative to Graph-Easy appears to be dot2gdl.

Oak
  • 26,231
  • 8
  • 93
  • 152
  • Thanks! There is a feature of xvcg when working with large CFGs - you can interactively open some nodes to see contents of basic blocks, by default all blocks are collapsed. Is there such feature in xdot or in Graph-Easy? – osgx Jun 12 '13 at 21:12
  • @osgx that does sound useful. Graphviz itself has no such functionality, and xdot.py is actually a viewer for xdot files which are already after the layout stage, so it cannot help. I guess it's possible to write a viewer which will allow this by dynamically removing some of the nodes/edges and then use dot layout again, but I know of no such viewer. Maybe it's worth asking in a separate question, though... – Oak Jun 13 '13 at 06:37
  • Oak, the changing (rewrawing) of the graph may be not needed, even ability to draw graph in collapsed variant and per-node content viewing (as separate floating windows) will be great. PS there is another converter to vcg from dot ... – osgx Jun 13 '13 at 08:21
  • @osgx well, I guess you could massage any existing viewer to do that - xdot.py is particularly convenient because it's pure python and is already somewhat interactive - but I don't know of any viewer with such a built-in functionality. – Oak Jun 13 '13 at 08:24
  • Oak, xvcg is. Another converter to vcg from dot is dot2gdl. – osgx Jun 13 '13 at 08:25
  • @osgx I agree, if you need this functionality then stick with your viewer and just convert the dot files to vcg. – Oak Jun 13 '13 at 08:29
  • @osgx thanks, edited it into the answer for future reference. – Oak Jun 13 '13 at 08:31