Add support for 'rename'
[oota-llvm.git] / lib / Analysis / DataStructure / Printer.cpp
index 9902906e19af14056ad03778d0b291e5b29c9dc0..e25bc4c43264d39c28ce4bf461d970869a7f5cec 100644 (file)
 #include "Support/Statistic.h"
 #include <fstream>
 #include <sstream>
-
-namespace llvm {
+using namespace llvm;
 
 // OnlyPrintMain - The DataStructure printer exposes this option to allow
 // printing of only the graph for "main".
 //
 namespace {
   cl::opt<bool> OnlyPrintMain("only-print-main-ds", cl::ReallyHidden);
-  Statistic<> MaxGraphSize   ("dsnode", "Maximum graph size");
-  Statistic<> NumFoldedNodes ("dsnode", "Number of folded nodes (in final graph)");
+  cl::opt<bool> DontPrintAnything("dont-print-ds", cl::ReallyHidden);
+  Statistic<> MaxGraphSize   ("dsa", "Maximum graph size");
+  Statistic<> NumFoldedNodes ("dsa", "Number of folded nodes (in final graph)");
 }
 
 void DSNode::dump() const { print(std::cerr, 0); }
@@ -73,6 +73,7 @@ static std::string getCaption(const DSNode *N, const DSGraph *G) {
   return OS.str();
 }
 
+namespace llvm {
 template<>
 struct DOTGraphTraits<const DSGraph*> : public DefaultDOTGraphTraits {
   static std::string getGraphName(const DSGraph *G) {
@@ -132,12 +133,12 @@ struct DOTGraphTraits<const DSGraph*> : public DefaultDOTGraphTraits {
         else
           Label = I->first->getName() + " ret node";
         // Output the return node...
-        GW.emitSimpleNode((void*)1, "plaintext=circle", Label);
+        GW.emitSimpleNode((void*)I->first, "plaintext=circle", Label);
 
         // Add edge from return node to real destination
         int RetEdgeDest = I->second.getOffset() >> DS::PointerShift;;
         if (RetEdgeDest == 0) RetEdgeDest = -1;
-        GW.emitEdge((void*)1, -1, I->second.getNode(),
+        GW.emitEdge((void*)I->first, -1, I->second.getNode(),
                     RetEdgeDest, "arrowtail=tee,color=gray63");
       }
 
@@ -179,6 +180,7 @@ struct DOTGraphTraits<const DSGraph*> : public DefaultDOTGraphTraits {
     }
   }
 };
+}   // end namespace llvm
 
 void DSNode::print(std::ostream &O, const DSGraph *G) const {
   GraphWriter<const DSGraph *> W(O, G);
@@ -247,10 +249,12 @@ static void printCollection(const Collection &C, std::ostream &O,
           << Gr.getGraphSize() << "+" << NumCalls << "]\n";
       }
 
-      if (MaxGraphSize < Gr.getNodes().size())
-        MaxGraphSize = Gr.getNodes().size();
-      for (unsigned i = 0, e = Gr.getNodes().size(); i != e; ++i)
-        if (Gr.getNodes()[i]->isNodeCompletelyFolded())
+      unsigned GraphSize = Gr.getGraphSize();
+      if (MaxGraphSize < GraphSize) MaxGraphSize = GraphSize;
+
+      for (DSGraph::node_iterator NI = Gr.node_begin(), E = Gr.node_end();
+           NI != E; ++NI)
+        if ((*NI)->isNodeCompletelyFolded())
           ++NumFoldedNodes;
     }
 
@@ -271,15 +275,23 @@ static void printCollection(const Collection &C, std::ostream &O,
 
 // print - Print out the analysis results...
 void LocalDataStructures::print(std::ostream &O, const Module *M) const {
+  if (DontPrintAnything) return;
   printCollection(*this, O, M, "ds.");
 }
 
 void BUDataStructures::print(std::ostream &O, const Module *M) const {
+  if (DontPrintAnything) return;
   printCollection(*this, O, M, "bu.");
 }
 
 void TDDataStructures::print(std::ostream &O, const Module *M) const {
+  if (DontPrintAnything) return;
   printCollection(*this, O, M, "td.");
 }
 
-} // End llvm namespace
+void CompleteBUDataStructures::print(std::ostream &O, const Module *M) const {
+  if (DontPrintAnything) return;
+  printCollection(*this, O, M, "cbu.");
+}
+
+