Re-enable 91381 with fixes.
[oota-llvm.git] / lib / Analysis / DomPrinter.cpp
index f7918177ccaa3b4dcef5feb95bce70a952b81be2..32b8994f0289bb0338eacfc2deeea97d1e2f41f4 100644 (file)
@@ -19,7 +19,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/DomPrinter.h"
-
 #include "llvm/Pass.h"
 #include "llvm/Function.h"
 #include "llvm/Analysis/CFGPrinter.h"
@@ -31,46 +30,55 @@ using namespace llvm;
 namespace llvm {
 template<>
 struct DOTGraphTraits<DomTreeNode*> : public DefaultDOTGraphTraits {
-  static std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph,
-                                  bool ShortNames) {
+
+  DOTGraphTraits (bool isSimple=false)
+    : DefaultDOTGraphTraits(isSimple) {}
+
+  std::string getNodeLabel(DomTreeNode *Node, DomTreeNode *Graph) {
 
     BasicBlock *BB = Node->getBlock();
 
     if (!BB)
       return "Post dominance root node";
 
-    return DOTGraphTraits<const Function*>::getNodeLabel(BB, BB->getParent(),
-                                                         ShortNames);
+
+    if (isSimple())
+      return DOTGraphTraits<const Function*>
+              ::getSimpleNodeLabel(BB, BB->getParent());
+    else
+      return DOTGraphTraits<const Function*>
+              ::getCompleteNodeLabel(BB, BB->getParent());
   }
 };
 
 template<>
 struct DOTGraphTraits<DominatorTree*> : public DOTGraphTraits<DomTreeNode*> {
 
+  DOTGraphTraits (bool isSimple=false)
+    : DOTGraphTraits<DomTreeNode*>(isSimple) {}
+
   static std::string getGraphName(DominatorTree *DT) {
     return "Dominator tree";
   }
 
-  static std::string getNodeLabel(DomTreeNode *Node,
-                                  DominatorTree *G,
-                                  bool ShortNames) {
-    return DOTGraphTraits<DomTreeNode*>::getNodeLabel(Node, G->getRootNode(),
-                                                      ShortNames);
+  std::string getNodeLabel(DomTreeNode *Node, DominatorTree *G) {
+    return DOTGraphTraits<DomTreeNode*>::getNodeLabel(Node, G->getRootNode());
   }
 };
 
 template<>
 struct DOTGraphTraits<PostDominatorTree*>
   : public DOTGraphTraits<DomTreeNode*> {
+
+  DOTGraphTraits (bool isSimple=false)
+    : DOTGraphTraits<DomTreeNode*>(isSimple) {}
+
   static std::string getGraphName(PostDominatorTree *DT) {
     return "Post dominator tree";
   }
-  static std::string getNodeLabel(DomTreeNode *Node,
-                                  PostDominatorTree *G,
-                                  bool ShortNames) {
-    return DOTGraphTraits<DomTreeNode*>::getNodeLabel(Node,
-                                                      G->getRootNode(),
-                                                      ShortNames);
+
+  std::string getNodeLabel(DomTreeNode *Node, PostDominatorTree *G ) {
+    return DOTGraphTraits<DomTreeNode*>::getNodeLabel(Node, G->getRootNode());
   }
 };
 }
@@ -78,19 +86,19 @@ struct DOTGraphTraits<PostDominatorTree*>
 namespace {
 template <class Analysis, bool OnlyBBS>
 struct GenericGraphViewer : public FunctionPass {
-
-  static char ID;
   std::string Name;
 
-  GenericGraphViewer(std::string GraphName) : FunctionPass(&ID) {
+  GenericGraphViewer(std::string GraphName, const void *ID) : FunctionPass(ID) {
     Name = GraphName;
   }
 
   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;
   }
@@ -104,27 +112,27 @@ struct GenericGraphViewer : public FunctionPass {
 struct DomViewer
   : public GenericGraphViewer<DominatorTree, false> {
   static char ID;
-  DomViewer() : GenericGraphViewer<DominatorTree, false>("dom"){}
+  DomViewer() : GenericGraphViewer<DominatorTree, false>("dom", &ID){}
 };
 
 struct DomOnlyViewer
   : public GenericGraphViewer<DominatorTree, true> {
   static char ID;
-  DomOnlyViewer() : GenericGraphViewer<DominatorTree, true>("domonly"){}
+  DomOnlyViewer() : GenericGraphViewer<DominatorTree, true>("domonly", &ID){}
 };
 
 struct PostDomViewer
   : public GenericGraphViewer<PostDominatorTree, false> {
   static char ID;
   PostDomViewer() :
-    GenericGraphViewer<PostDominatorTree, false>("postdom"){}
+    GenericGraphViewer<PostDominatorTree, false>("postdom", &ID){}
 };
 
 struct PostDomOnlyViewer
   : public GenericGraphViewer<PostDominatorTree, true> {
   static char ID;
   PostDomOnlyViewer() :
-    GenericGraphViewer<PostDominatorTree, true>("postdomonly"){}
+    GenericGraphViewer<PostDominatorTree, true>("postdomonly", &ID){}
 };
 } // end anonymous namespace
 
@@ -150,10 +158,10 @@ namespace {
 template <class Analysis, bool OnlyBBS>
 struct GenericGraphPrinter : public FunctionPass {
 
-  static char ID;
   std::string Name;
 
-  GenericGraphPrinter(std::string GraphName) : FunctionPass(&ID) {
+  GenericGraphPrinter(std::string GraphName, const void *ID)
+    : FunctionPass(ID) {
     Name = GraphName;
   }
 
@@ -166,8 +174,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";
@@ -183,27 +195,27 @@ struct GenericGraphPrinter : public FunctionPass {
 struct DomPrinter
   : public GenericGraphPrinter<DominatorTree, false> {
   static char ID;
-  DomPrinter() : GenericGraphPrinter<DominatorTree, false>("dom"){}
+  DomPrinter() : GenericGraphPrinter<DominatorTree, false>("dom", &ID) {}
 };
 
 struct DomOnlyPrinter
   : public GenericGraphPrinter<DominatorTree, true> {
   static char ID;
-  DomOnlyPrinter() : GenericGraphPrinter<DominatorTree, true>("domonly"){}
+  DomOnlyPrinter() : GenericGraphPrinter<DominatorTree, true>("domonly", &ID) {}
 };
 
 struct PostDomPrinter
   : public GenericGraphPrinter<PostDominatorTree, false> {
   static char ID;
   PostDomPrinter() :
-    GenericGraphPrinter<PostDominatorTree, false>("postdom"){}
+    GenericGraphPrinter<PostDominatorTree, false>("postdom", &ID) {}
 };
 
 struct PostDomOnlyPrinter
   : public GenericGraphPrinter<PostDominatorTree, true> {
   static char ID;
   PostDomOnlyPrinter() :
-    GenericGraphPrinter<PostDominatorTree, true>("postdomonly"){}
+    GenericGraphPrinter<PostDominatorTree, true>("postdomonly", &ID) {}
 };
 } // end anonymous namespace