[PATCH] D32145: [Dominator] Add a way to dump a `dot` representation of the dominator tree

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 17:46:28 PDT 2017


davide created this revision.

This is very similar to what we do for CFG and SelectionDAG.
I find it very useful when I'm in VisualStudio (or any other debugger). I can just print `DT.viewGraph()` and that pops a new window with the dom displayed. As far as I can tell the only other way to dump the dom is manually using `DT.print(dbgs())`, which for large dominator trees is not that readable.


https://reviews.llvm.org/D32145

Files:
  include/llvm/IR/Dominators.h
  lib/Analysis/DomPrinter.cpp


Index: lib/Analysis/DomPrinter.cpp
===================================================================
--- lib/Analysis/DomPrinter.cpp
+++ lib/Analysis/DomPrinter.cpp
@@ -80,6 +80,22 @@
 };
 }
 
+void DominatorTree::viewGraph(const Twine &Name, const Twine &Title) {
+#ifndef NDEBUG
+  ViewGraph(this, Name, false, Title);
+#else
+  errs() << "build with NDEBUG\n";
+#endif  // NDEBUG
+}
+
+void DominatorTree::viewGraph() {
+#ifndef NDEBUG
+  this->viewGraph("my dom", "dom");
+#else
+  errs() << "build with NDEBUG\n";
+#endif  // NDEBUG
+}
+
 namespace {
 struct DominatorTreeWrapperPassAnalysisGraphTraits {
   static DominatorTree *getGraph(DominatorTreeWrapperPass *DTWP) {
Index: include/llvm/IR/Dominators.h
===================================================================
--- include/llvm/IR/Dominators.h
+++ include/llvm/IR/Dominators.h
@@ -157,6 +157,10 @@
   /// This should only be used for debugging as it aborts the program if the
   /// verification fails.
   void verifyDomTree() const;
+
+  // Pop up a GraphViz/gv window with the Dominator Tree rendered using `dot`.
+  void viewGraph(const Twine &Name, const Twine &Title);
+  void viewGraph();
 };
 
 //===-------------------------------------


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32145.95516.patch
Type: text/x-patch
Size: 1218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170418/711f6352/attachment.bin>


More information about the llvm-commits mailing list