[PATCH] D80711: Utility to dump .dot representation of SelectionDAG without firing viewer

Madhur Amilkanthwar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 29 04:18:29 PDT 2020


madhur13490 updated this revision to Diff 267170.
madhur13490 marked an inline comment as done.
madhur13490 edited the summary of this revision.
madhur13490 added a comment.

Addressing comments by arsenm


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80711/new/

https://reviews.llvm.org/D80711

Files:
  llvm/include/llvm/CodeGen/SelectionDAG.h
  llvm/include/llvm/Support/GraphWriter.h
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
@@ -158,6 +158,22 @@
 #endif  // NDEBUG
 }
 
+/// Just dump dot graph to a user-provided path and title.
+/// This doesn't open the dot viewer program and
+/// helps visualization when outside debugging session.
+/// FileName expects absolute path. If provided
+/// without any path separators then the file
+/// will be created in the current directory.
+/// Error will be emitted if the path is insane.
+void SelectionDAG::dumpDotGraph(const Twine &FileName, const Twine &Title) {
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  DumpDotGraph(this, FileName, Title);
+#else
+  errs() << "SelectionDAG::DumpDotGraph is only available in debug builds or "
+         << "when LLVM_ENABLE_DUMP is ON.\n";
+#endif // NDEBUG
+}
+
 // This overload is defined out-of-line here instead of just using a
 // default parameter because this is easiest for gdb to call.
 void SelectionDAG::viewGraph() {
Index: llvm/include/llvm/Support/GraphWriter.h
===================================================================
--- llvm/include/llvm/Support/GraphWriter.h
+++ llvm/include/llvm/Support/GraphWriter.h
@@ -341,6 +341,8 @@
     } else if (EC) {
       errs() << "error writing into file" << "\n";
       return "";
+    } else {
+      errs() << "writing to the newly created file " << Filename << "\n";
     }
   }
   raw_fd_ostream O(FD, /*shouldClose=*/ true);
@@ -356,6 +358,14 @@
   return Filename;
 }
 
+/// EmitDotGraph - Just emit a dot graph to the user-provided file name.
+template <typename GraphType>
+LLVM_DUMP_METHOD void DumpDotGraph(const GraphType &G, const Twine &FileName,
+                                   const Twine &Title, bool ShortNames = false,
+                                   const Twine &Name = "") {
+  llvm::WriteGraph(G, Name, ShortNames, Title, FileName.str());
+}
+
 /// ViewGraph - Emit a dot graph, run 'dot', run gv on the postscript file,
 /// then cleanup.  For use from the debugger.
 ///
Index: llvm/include/llvm/CodeGen/SelectionDAG.h
===================================================================
--- llvm/include/llvm/CodeGen/SelectionDAG.h
+++ llvm/include/llvm/CodeGen/SelectionDAG.h
@@ -432,6 +432,15 @@
   ProfileSummaryInfo *getPSI() const { return PSI; }
   BlockFrequencyInfo *getBFI() const { return BFI; }
 
+  /// Just dump dot graph to a user-provided path and title.
+  /// This doesn't open the dot viewer program and
+  /// helps visualization when outside debugging session.
+  /// FileName expects absolute path. If provided
+  /// without any path separators then the file
+  /// will be created in the current directory.
+  /// Error will be emitted if the path is insane.
+  void dumpDotGraph(const Twine &FileName, const Twine &Title);
+
   /// Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
   void viewGraph(const std::string &Title);
   void viewGraph();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80711.267170.patch
Type: text/x-patch
Size: 3093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200529/7d450eb3/attachment.bin>


More information about the llvm-commits mailing list