Add globals graphs to all three passes
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4663 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/DataStructure/BottomUpClosure.cpp b/lib/Analysis/DataStructure/BottomUpClosure.cpp
index d57b618..ade6ca6 100644
--- a/lib/Analysis/DataStructure/BottomUpClosure.cpp
+++ b/lib/Analysis/DataStructure/BottomUpClosure.cpp
@@ -18,6 +18,18 @@
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 @@
// 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 @@
// 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.
diff --git a/lib/Analysis/DataStructure/Local.cpp b/lib/Analysis/DataStructure/Local.cpp
index e159a60..3118106 100644
--- a/lib/Analysis/DataStructure/Local.cpp
+++ b/lib/Analysis/DataStructure/Local.cpp
@@ -409,6 +409,16 @@
// 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 @@
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;
-}
diff --git a/lib/Analysis/DataStructure/Printer.cpp b/lib/Analysis/DataStructure/Printer.cpp
index 962a093..bbd9c2d 100644
--- a/lib/Analysis/DataStructure/Printer.cpp
+++ b/lib/Analysis/DataStructure/Printer.cpp
@@ -181,6 +181,16 @@
}
}
+ 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;
}
diff --git a/lib/Analysis/DataStructure/TopDownClosure.cpp b/lib/Analysis/DataStructure/TopDownClosure.cpp
index b4b43f7..1da43e5 100644
--- a/lib/Analysis/DataStructure/TopDownClosure.cpp
+++ b/lib/Analysis/DataStructure/TopDownClosure.cpp
@@ -16,6 +16,26 @@
static RegisterAnalysis<TDDataStructures>
Y("tddatastructure", "Top-down Data Structure Analysis Closure");
+// 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())
+ calculateGraph(*F);
+
+ // Next calculate the graphs for each function unreachable function...
+ 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...
//
@@ -27,23 +47,8 @@
// 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>();
-
- // Calculate top-down from main...
- if (Function *F = M.getMainFunction())
- calculateGraph(*F);
-
- // Next calculate the graphs for each function unreachable function...
- for (Module::reverse_iterator I = M.rbegin(), E = M.rend(); I != E; ++I)
- if (!I->isExternal())
- calculateGraph(*I);
- return false;
+ delete GlobalsGraph;
+ GlobalsGraph = 0;
}
/// ResolveCallSite - This method is used to link the actual arguments together
@@ -77,6 +82,7 @@
if (G == 0) { // Not created yet? Clone BU graph...
G = new DSGraph(getAnalysis<BUDataStructures>().getDSGraph(F));
G->getAuxFunctionCalls().clear();
+ G->setGlobalsGraph(GlobalsGraph);
}
return *G;
}