return *I->second;
}
+ DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
// print - Print out the analysis results...
void print(std::ostream &O, const Module *M) const;
class BUDataStructures : public Pass {
// DSInfo, one graph for each function
std::map<const Function*, DSGraph*> DSInfo;
+ DSGraph *GlobalsGraph;
public:
~BUDataStructures() { releaseMemory(); }
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...
// DSInfo, one graph for each function
std::map<const Function*, DSGraph*> DSInfo;
std::set<const Function*> GraphDone;
+ DSGraph *GlobalsGraph;
public:
~TDDataStructures() { releaseMemory(); }
return *I->second;
}
+ DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
// print - Print out the analysis results...
void print(std::ostream &O, const Module *M) const;
return *I->second;
}
+ DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
// print - Print out the analysis results...
void print(std::ostream &O, const Module *M) const;
class BUDataStructures : public Pass {
// DSInfo, one graph for each function
std::map<const Function*, DSGraph*> DSInfo;
+ DSGraph *GlobalsGraph;
public:
~BUDataStructures() { releaseMemory(); }
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...
// DSInfo, one graph for each function
std::map<const Function*, DSGraph*> DSInfo;
std::set<const Function*> GraphDone;
+ DSGraph *GlobalsGraph;
public:
~TDDataStructures() { releaseMemory(); }
return *I->second;
}
+ DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
+
// print - Print out the analysis results...
void print(std::ostream &O, const Module *M) const;
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...
// 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) {
// 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.
// 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...
//
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;
-}
}
}
+ 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;
}
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())
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
if (G == 0) { // Not created yet? Clone BU graph...
G = new DSGraph(getAnalysis<BUDataStructures>().getDSGraph(F));
G->getAuxFunctionCalls().clear();
+ G->setGlobalsGraph(GlobalsGraph);
}
return *G;
}