Small PostDominatorTree improvements
authorTobias Grosser <grosser@fim.uni-passau.de>
Mon, 30 Nov 2009 12:06:37 +0000 (12:06 +0000)
committerTobias Grosser <grosser@fim.uni-passau.de>
Mon, 30 Nov 2009 12:06:37 +0000 (12:06 +0000)
 * Do not SEGFAULT if tree entryNode() is NULL
 * Print function names in dotty printer

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90130 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/PostDominators.h
lib/Analysis/DomPrinter.cpp

index 42a16e74a247e5fcada65a42dcea7e74727a5e63..ea14b2da9ce97b5761ba2165fbe4192454ec7a20 100644 (file)
@@ -81,7 +81,10 @@ template <> struct GraphTraits<PostDominatorTree*>
   }
 
   static nodes_iterator nodes_begin(PostDominatorTree *N) {
-    return df_begin(getEntryNode(N));
+    if (getEntryNode(N))
+      return df_begin(getEntryNode(N));
+    else
+      return df_end(getEntryNode(N));
   }
 
   static nodes_iterator nodes_end(PostDominatorTree *N) {
index f1b44d0356ea3d48ed09b8be1be03b8aacb9e70f..ebfba7ef0f61ebb082cea111d8947f7155e75ab4 100644 (file)
@@ -85,9 +85,11 @@ struct GenericGraphViewer : public FunctionPass {
 
   virtual bool runOnFunction(Function &F) {
     Analysis *Graph;
-
+    std::string Title, GraphName;
     Graph = &getAnalysis<Analysis>();
-    ViewGraph(Graph, Name, OnlyBBS);
+    GraphName = DOTGraphTraits<Analysis*>::getGraphName(Graph);
+    Title = GraphName + " for '" + F.getNameStr() + "' function";
+    ViewGraph(Graph, Name, OnlyBBS, Title);
 
     return false;
   }
@@ -163,8 +165,12 @@ struct GenericGraphPrinter : public FunctionPass {
     raw_fd_ostream File(Filename.c_str(), ErrorInfo);
     Graph = &getAnalysis<Analysis>();
 
+    std::string Title, GraphName;
+    GraphName = DOTGraphTraits<Analysis*>::getGraphName(Graph);
+    Title = GraphName + " for '" + F.getNameStr() + "' function";
+
     if (ErrorInfo.empty())
-      WriteGraph(File, Graph, OnlyBBS);
+      WriteGraph(File, Graph, OnlyBBS, Name, Title);
     else
       errs() << "  error opening file for writing!";
     errs() << "\n";