This patch implements a DDG printer pass that generates a graph in the DOT description language, providing a more visually appealing representation of the DDG. Similar to the CFG DOT printer, this functionality is provided under an option called -dot-ddg and can be generated in a less verbose mode under -dot-ddg-only option.
[nit] The initializer ("") is useless? std::string default-initializes to an empty string.
[suggestion] Instead of count, you can use llvm::enumerate. I think it's nicer to check at for "not the first" at the beginning instead of the last element at the end.
There also is an interleave function in STLExtras.h for uses cases like this.
[style] Space between includes and namespace?
Why does a getter set a field value?
Does this const_cast exist to add const qualifier?
Could you split this up?
if (Count != PNodes.size()) OS << "\n";
Interesting! Thanks for pointing out those utilities! I'll use interleave.
Good question :)
When printing pi-blocks we would like to show the member nodes being enclosed by the pi-node. However, since the member nodes are also part of the graph, they will get visited during the walk and get dumped into the resulting dot file. To solve this, I'm trying to hide the member nodes from the walk (via isNodeHidden()) when they get visited and then print them as part of printing the pi-block node.
The problem I encountered was that, isNodeHidden() only takes a graph node as a parameter, but for me to know whether a node belongs to a pi-block I need to get access to the graph that contains the nodes. To get around this, I'm caching a pointer to the graph when the getGraphName gets called and use it when isNodeHidden is invoked....yikes!
A cleaner solution (and one that may have other uses in the future) is to make isNodeHidden() take a graph object as argument (similar to getNodeLabel(), and getGraphName()). I'll update the patch to include that change.
No. The static_cast is used because the getInstructions() is a member function of SimpleDDGNode but not DDGNode.