Add globals graphs to all three passes
authorChris Lattner <sabre@nondot.org>
Sat, 9 Nov 2002 21:12:07 +0000 (21:12 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 9 Nov 2002 21:12:07 +0000 (21:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4663 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/DataStructure.h
include/llvm/Analysis/DataStructure/DataStructure.h
lib/Analysis/DataStructure/BottomUpClosure.cpp
lib/Analysis/DataStructure/Local.cpp
lib/Analysis/DataStructure/Printer.cpp
lib/Analysis/DataStructure/TopDownClosure.cpp

index 71bf5128eca6a45cff287178d0781a4ea04e0d26..ea1c2ae19222d612850c7227427df7dee4ed8649 100644 (file)
@@ -46,6 +46,8 @@ public:
     return *I->second;
   }
 
+  DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
   // print - Print out the analysis results...
   void print(std::ostream &O, const Module *M) const;
 
@@ -66,6 +68,7 @@ public:
 class BUDataStructures : public Pass {
   // DSInfo, one graph for each function
   std::map<const Function*, DSGraph*> DSInfo;
+  DSGraph *GlobalsGraph;
 public:
   ~BUDataStructures() { releaseMemory(); }
 
@@ -78,7 +81,9 @@ public:
     return *I->second;
   }
 
-   // print - Print out the analysis results...
+  DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
+  // print - Print out the analysis results...
   void print(std::ostream &O, const Module *M) const;
 
   // If the pass pipeline is done with this pass, we can release our memory...
@@ -101,6 +106,7 @@ class TDDataStructures : public Pass {
   // DSInfo, one graph for each function
   std::map<const Function*, DSGraph*> DSInfo;
   std::set<const Function*> GraphDone;
+  DSGraph *GlobalsGraph;
 public:
   ~TDDataStructures() { releaseMemory(); }
 
@@ -113,6 +119,8 @@ public:
     return *I->second;
   }
 
+  DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
   // print - Print out the analysis results...
   void print(std::ostream &O, const Module *M) const;
 
index 71bf5128eca6a45cff287178d0781a4ea04e0d26..ea1c2ae19222d612850c7227427df7dee4ed8649 100644 (file)
@@ -46,6 +46,8 @@ public:
     return *I->second;
   }
 
+  DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
   // print - Print out the analysis results...
   void print(std::ostream &O, const Module *M) const;
 
@@ -66,6 +68,7 @@ public:
 class BUDataStructures : public Pass {
   // DSInfo, one graph for each function
   std::map<const Function*, DSGraph*> DSInfo;
+  DSGraph *GlobalsGraph;
 public:
   ~BUDataStructures() { releaseMemory(); }
 
@@ -78,7 +81,9 @@ public:
     return *I->second;
   }
 
-   // print - Print out the analysis results...
+  DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
+  // print - Print out the analysis results...
   void print(std::ostream &O, const Module *M) const;
 
   // If the pass pipeline is done with this pass, we can release our memory...
@@ -101,6 +106,7 @@ class TDDataStructures : public Pass {
   // DSInfo, one graph for each function
   std::map<const Function*, DSGraph*> DSInfo;
   std::set<const Function*> GraphDone;
+  DSGraph *GlobalsGraph;
 public:
   ~TDDataStructures() { releaseMemory(); }
 
@@ -113,6 +119,8 @@ public:
     return *I->second;
   }
 
+  DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
   // print - Print out the analysis results...
   void print(std::ostream &O, const Module *M) const;
 
index d57b6186f86f145d063814217e732cf3349e556b..ade6ca68a5c1be1a42f4c7d3e1bb0a79708b8843 100644 (file)
@@ -18,6 +18,18 @@ X("budatastructure", "Bottom-up Data Structure Analysis Closure");
 
 using namespace DS;
 
+// run - Calculate the bottom up data structure graphs for each function in the
+// program.
+//
+bool BUDataStructures::run(Module &M) {
+  GlobalsGraph = new DSGraph();
+
+  // Simply calculate the graphs for each function...
+  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+    if (!I->isExternal())
+      calculateGraph(*I);
+  return false;
+}
 
 // releaseMemory - If the pass pipeline is done with this pass, we can release
 // our memory... here...
@@ -30,17 +42,8 @@ void BUDataStructures::releaseMemory() {
   // Empty map so next time memory is released, data structures are not
   // re-deleted.
   DSInfo.clear();
-}
-
-// run - Calculate the bottom up data structure graphs for each function in the
-// program.
-//
-bool BUDataStructures::run(Module &M) {
-  // Simply calculate the graphs for each function...
-  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-    if (!I->isExternal())
-      calculateGraph(*I);
-  return false;
+  delete GlobalsGraph;
+  GlobalsGraph = 0;
 }
 
 DSGraph &BUDataStructures::calculateGraph(Function &F) {
@@ -52,6 +55,7 @@ DSGraph &BUDataStructures::calculateGraph(Function &F) {
 
   // Copy the local version into DSInfo...
   Graph = new DSGraph(getAnalysis<LocalDataStructures>().getDSGraph(F));
+  Graph->setGlobalsGraph(GlobalsGraph);
 
 #if 0
   // Populate the GlobalsGraph with globals from this one.
index e159a6087e85f8a26f85cb47f39a0a1c3c8a4ff0..311810644a450dfbff18889d5a4d912eb1c93547 100644 (file)
@@ -409,6 +409,16 @@ void GraphBuilder::visitCastInst(CastInst &CI) {
 // LocalDataStructures Implementation
 //===----------------------------------------------------------------------===//
 
+bool LocalDataStructures::run(Module &M) {
+  GlobalsGraph = new DSGraph();
+
+  // Calculate all of the graphs...
+  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
+    if (!I->isExternal())
+      DSInfo.insert(std::make_pair(I, new DSGraph(*I, GlobalsGraph)));
+  return false;
+}
+
 // releaseMemory - If the pass pipeline is done with this pass, we can release
 // our memory... here...
 //
@@ -423,13 +433,3 @@ void LocalDataStructures::releaseMemory() {
   delete GlobalsGraph;
   GlobalsGraph = 0;
 }
-
-bool LocalDataStructures::run(Module &M) {
-  GlobalsGraph = new DSGraph();
-
-  // Calculate all of the graphs...
-  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-    if (!I->isExternal())
-      DSInfo.insert(std::make_pair(I, new DSGraph(*I, GlobalsGraph)));
-  return false;
-}
index 962a0935e09e2e523f5d7dc1b8fde370271f34d7..bbd9c2d18b22a61b0678195f84e8d30ea530536b 100644 (file)
@@ -181,6 +181,16 @@ static void printCollection(const Collection &C, std::ostream &O,
       }
     }
 
+  DSGraph &GG = C.getGlobalsGraph();
+  TotalNumNodes  += GG.getGraphSize();
+  TotalCallNodes += GG.getFunctionCalls().size();
+  if (OnlyPrintMain) {
+    GG.writeGraphToFile(O, Prefix+"GlobalsGraph");
+  } else {
+    O << "Skipped Writing '" << Prefix << "GlobalsGraph.dot'... ["
+      << GG.getGraphSize() << "+" << GG.getFunctionCalls().size() << "]\n";
+  }
+
   O << "\nGraphs contain [" << TotalNumNodes << "+" << TotalCallNodes 
     << "] nodes total" << std::endl;
 }
index b4b43f77c59cd0b20c75bd34c6bddec64d5edb06..1da43e5634ff81ae4b3a823d439d4235bf33188b 100644 (file)
 static RegisterAnalysis<TDDataStructures>
 Y("tddatastructure", "Top-down Data Structure Analysis Closure");
 
-// releaseMemory - If the pass pipeline is done with this pass, we can release
-// our memory... here...
-//
-void TDDataStructures::releaseMemory() {
-  for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
-         E = DSInfo.end(); I != E; ++I)
-    delete I->second;
-
-  // Empty map so next time memory is released, data structures are not
-  // re-deleted.
-  DSInfo.clear();
-}
-
 // run - Calculate the top down data structure graphs for each function in the
 // program.
 //
 bool TDDataStructures::run(Module &M) {
   BUDataStructures &BU = getAnalysis<BUDataStructures>();
+  GlobalsGraph = new DSGraph();
 
   // Calculate top-down from main...
   if (Function *F = M.getMainFunction())
@@ -43,9 +31,26 @@ bool TDDataStructures::run(Module &M) {
   for (Module::reverse_iterator I = M.rbegin(), E = M.rend(); I != E; ++I)
     if (!I->isExternal())
       calculateGraph(*I);
+
+  GraphDone.clear();    // Free temporary memory...
   return false;
 }
 
+// releaseMemory - If the pass pipeline is done with this pass, we can release
+// our memory... here...
+//
+void TDDataStructures::releaseMemory() {
+  for (std::map<const Function*, DSGraph*>::iterator I = DSInfo.begin(),
+         E = DSInfo.end(); I != E; ++I)
+    delete I->second;
+
+  // Empty map so next time memory is released, data structures are not
+  // re-deleted.
+  DSInfo.clear();
+  delete GlobalsGraph;
+  GlobalsGraph = 0;
+}
+
 /// ResolveCallSite - This method is used to link the actual arguments together
 /// with the formal arguments for a function call in the top-down closure.  This
 /// method assumes that the call site arguments have been mapped into nodes
@@ -77,6 +82,7 @@ DSGraph &TDDataStructures::getOrCreateDSGraph(Function &F) {
   if (G == 0) { // Not created yet?  Clone BU graph...
     G = new DSGraph(getAnalysis<BUDataStructures>().getDSGraph(F));
     G->getAuxFunctionCalls().clear();
+    G->setGlobalsGraph(GlobalsGraph);
   }
   return *G;
 }