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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/include/llvm/Analysis/DDG.h | ||
---|---|---|
476 | [nit] The initializer ("") is useless? std::string default-initializes to an empty string. | |
481 | [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. | |
llvm/include/llvm/Analysis/DDGPrinter.h | ||
22 | [style] Space between includes and namespace? | |
46 | Why does a getter set a field value? | |
llvm/lib/Analysis/DDGPrinter.cpp | ||
110 | Does this const_cast exist to add const qualifier? | |
118 | Could you split this up? if (Count != PNodes.size()) OS << "\n"; |
Thanks for the review @Meinersbur and sorry for taking so long to address your comments.
llvm/include/llvm/Analysis/DDG.h | ||
---|---|---|
481 | Interesting! Thanks for pointing out those utilities! I'll use interleave. | |
llvm/include/llvm/Analysis/DDGPrinter.h | ||
46 | 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. | |
llvm/lib/Analysis/DDGPrinter.cpp | ||
110 | No. The static_cast is used because the getInstructions() is a member function of SimpleDDGNode but not DDGNode. |
Thanks, LGTM.
llvm/include/llvm/Analysis/DDG.h | ||
---|---|---|
489 | llvm::interleaveComma does that without an additional lambda. |
I think I have a fix (please see the updated patch), but don't have access to a windows machine to verify. Would you be able to try building with MSVC and let me know if it passes?
Test coverage for the DDG functionality has been added under LIT and unittests. I've opened https://reviews.llvm.org/D93949 to add a test and verify the formatting of the dot file produced when using -dot-ddg.
[nit] The initializer ("") is useless? std::string default-initializes to an empty string.