[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp DataStructure.cpp EquivClassGraphs.cpp Steensgaard.cpp TopDownClosure.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sat Apr 2 11:17:31 PST 2005
Changes in directory llvm/lib/Analysis/DataStructure:
CompleteBottomUp.cpp updated: 1.29 -> 1.30
DataStructure.cpp updated: 1.236 -> 1.237
EquivClassGraphs.cpp updated: 1.40 -> 1.41
Steensgaard.cpp updated: 1.59 -> 1.60
TopDownClosure.cpp updated: 1.85 -> 1.86
---
Log message:
Change the ActualCallees callgraph from hash_multimap<Instruction,Function>
to std::set<std::pair<Inst,Func>> to avoid duplicate entries.
This speeds up the CompleteBU pass from 1.99s to .15s on povray and the
eqgraph passes from 1.5s to .16s on the same.
---
Diffs of the changes: (+41 -79)
CompleteBottomUp.cpp | 45 ++++++++--------------------------------
DataStructure.cpp | 2 -
EquivClassGraphs.cpp | 8 +++----
Steensgaard.cpp | 8 ++-----
TopDownClosure.cpp | 57 +++++++++++++++++++++------------------------------
5 files changed, 41 insertions(+), 79 deletions(-)
Index: llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp
diff -u llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp:1.29 llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp:1.30
--- llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp:1.29 Thu Mar 24 12:42:51 2005
+++ llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp Sat Apr 2 13:17:17 2005
@@ -13,6 +13,7 @@
//
//===----------------------------------------------------------------------===//
+#define DEBUG_TYPE "cbudatastructure"
#include "llvm/Analysis/DataStructure/DataStructure.h"
#include "llvm/Module.h"
#include "llvm/Analysis/DataStructure/DSGraph.h"
@@ -37,39 +38,8 @@
GlobalsGraph = new DSGraph(BU.getGlobalsGraph(), GlobalECs);
GlobalsGraph->setPrintAuxCalls();
-#if 1 // REMOVE ME EVENTUALLY
- // FIXME: TEMPORARY (remove once finalization of indirect call sites in the
- // globals graph has been implemented in the BU pass)
- TDDataStructures &TD = getAnalysis<TDDataStructures>();
-
- ActualCallees.clear();
-
- // The call graph extractable from the TD pass is _much more complete_ and
- // trustable than that generated by the BU pass so far. Until this is fixed,
- // we hack it like this:
- for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI) {
- if (MI->isExternal()) continue;
- const std::list<DSCallSite> &CSs = TD.getDSGraph(*MI).getFunctionCalls();
-
- for (std::list<DSCallSite>::const_iterator CSI = CSs.begin(), E = CSs.end();
- CSI != E; ++CSI) {
- Instruction *TheCall = CSI->getCallSite().getInstruction();
-
- if (CSI->isIndirectCall()) { // indirect call: insert all callees
- std::vector<Function*> Callees;
- CSI->getCalleeNode()->addFullFunctionList(Callees);
- for (unsigned i = 0, e = Callees.size(); i != e; ++i)
- ActualCallees.insert(std::make_pair(TheCall, Callees[i]));
- } else { // direct call: insert the single callee directly
- ActualCallees.insert(std::make_pair(TheCall,
- CSI->getCalleeFunc()));
- }
- }
- }
-#else
// Our call graph is the same as the BU data structures call graph
ActualCallees = BU.getActualCallees();
-#endif
std::vector<DSGraph*> Stack;
hash_map<DSGraph*, unsigned> ValMap;
@@ -150,8 +120,9 @@
Instruction *Call = CI->getCallSite().getInstruction();
// Loop over all of the actually called functions...
- ActualCalleesTy::iterator I, E;
- for (tie(I, E) = ActualCallees.equal_range(Call); I != E; ++I)
+ ActualCalleesTy::iterator I = callee_begin(Call), E = callee_end(Call);
+ for (; I != E && I->first == Call; ++I) {
+ assert(I->first == Call && "Bad callee construction!");
if (!I->second->isExternal()) {
DSGraph &Callee = getOrCreateGraph(*I->second);
unsigned M;
@@ -163,6 +134,7 @@
M = It->second;
if (M < Min) Min = M;
}
+ }
}
assert(ValMap[&FG] == MyID && "SCC construction assumption wrong!");
@@ -225,10 +197,11 @@
// Inline direct calls as well as indirect calls because the direct
// callee may have indirect callees and so may have changed.
//
- ActualCalleesTy::iterator I, E;
- tie(I, E) = ActualCallees.equal_range(TheCall);
- unsigned TNum = 0, Num = std::distance(I, E);
+ ActualCalleesTy::iterator I = callee_begin(TheCall),E = callee_end(TheCall);
+ unsigned TNum = 0, Num = 0;
+ DEBUG(Num = std::distance(I, E));
for (; I != E; ++I, ++TNum) {
+ assert(I->first == TheCall && "Bad callee construction!");
Function *CalleeFunc = I->second;
if (!CalleeFunc->isExternal()) {
// Merge the callee's graph into this graph. This works for normal
Index: llvm/lib/Analysis/DataStructure/DataStructure.cpp
diff -u llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.236 llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.237
--- llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.236 Tue Mar 29 13:16:59 2005
+++ llvm/lib/Analysis/DataStructure/DataStructure.cpp Sat Apr 2 13:17:17 2005
@@ -2055,7 +2055,7 @@
GlobalNodes.push_back(std::make_pair(I->first, I->second.getNode()));
// Make sure that all globals are cloned over as roots.
- if (!(Flags & DSGraph::RemoveUnreachableGlobals)) {
+ if (!(Flags & DSGraph::RemoveUnreachableGlobals) && GlobalsGraph) {
DSGraph::ScalarMapTy::iterator SMI =
GlobalsGraph->getScalarMap().find(I->first);
if (SMI != GlobalsGraph->getScalarMap().end())
Index: llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp
diff -u llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp:1.40 llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp:1.41
--- llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp:1.40 Thu Mar 24 12:42:51 2005
+++ llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp Sat Apr 2 13:17:17 2005
@@ -339,8 +339,8 @@
Instruction *Call = CI->getCallSite().getInstruction();
// Loop over all of the actually called functions...
- ActualCalleesTy::const_iterator I, E;
- for (tie(I, E) = getActualCallees().equal_range(Call); I != E; ++I)
+ ActualCalleesTy::const_iterator I = callee_begin(Call),E = callee_end(Call);
+ for (; I != E; ++I)
if (!I->second->isExternal()) {
// Process the callee as necessary.
unsigned M = processSCC(getOrCreateGraph(*I->second),
@@ -414,8 +414,8 @@
// graph so we only need to do this once.
//
DSGraph* CalleeGraph = NULL;
- ActualCalleesTy::const_iterator I, E;
- tie(I, E) = getActualCallees().equal_range(TheCall);
+ ActualCalleesTy::const_iterator I = callee_begin(TheCall);
+ ActualCalleesTy::const_iterator E = callee_end(TheCall);
unsigned TNum, Num;
// Loop over all potential callees to find the first non-external callee.
Index: llvm/lib/Analysis/DataStructure/Steensgaard.cpp
diff -u llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.59 llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.60
--- llvm/lib/Analysis/DataStructure/Steensgaard.cpp:1.59 Tue Mar 29 13:16:59 2005
+++ llvm/lib/Analysis/DataStructure/Steensgaard.cpp Sat Apr 2 13:17:18 2005
@@ -25,11 +25,10 @@
namespace {
class Steens : public ModulePass, public AliasAnalysis {
DSGraph *ResultGraph;
- DSGraph *GlobalsGraph; // FIXME: Eliminate globals graph stuff from DNE
EquivalenceClasses<GlobalValue*> GlobalECs; // Always empty
public:
- Steens() : ResultGraph(0), GlobalsGraph(0) {}
+ Steens() : ResultGraph(0) {}
~Steens() {
releaseMyMemory();
assert(ResultGraph == 0 && "releaseMemory not called?");
@@ -116,8 +115,7 @@
// Create a new, empty, graph...
ResultGraph = new DSGraph(GlobalECs, getTargetData());
- GlobalsGraph = new DSGraph(GlobalECs, getTargetData());
- ResultGraph->setGlobalsGraph(GlobalsGraph);
+ ResultGraph->spliceFrom(LDS.getGlobalsGraph());
// Loop over the rest of the module, merging graphs for non-external functions
// into this graph.
@@ -186,7 +184,7 @@
// Remove any nodes that are dead after all of the merging we have done...
// FIXME: We should be able to disable the globals graph for steens!
- ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
+ //ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
DEBUG(print(std::cerr, &M));
return false;
Index: llvm/lib/Analysis/DataStructure/TopDownClosure.cpp
diff -u llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.85 llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.86
--- llvm/lib/Analysis/DataStructure/TopDownClosure.cpp:1.85 Wed Mar 23 22:22:04 2005
+++ llvm/lib/Analysis/DataStructure/TopDownClosure.cpp Sat Apr 2 13:17:18 2005
@@ -58,9 +58,9 @@
// program.
//
bool TDDataStructures::runOnModule(Module &M) {
- BUDataStructures &BU = getAnalysis<BUDataStructures>();
- GlobalECs = BU.getGlobalECs();
- GlobalsGraph = new DSGraph(BU.getGlobalsGraph(), GlobalECs);
+ BUInfo = &getAnalysis<BUDataStructures>();
+ GlobalECs = BUInfo->getGlobalECs();
+ GlobalsGraph = new DSGraph(BUInfo->getGlobalsGraph(), GlobalECs);
GlobalsGraph->setPrintAuxCalls();
// Figure out which functions must not mark their arguments complete because
@@ -95,8 +95,6 @@
// calculate a post-order traversal, then reverse it.
hash_set<DSGraph*> VisitedGraph;
std::vector<DSGraph*> PostOrder;
- const BUDataStructures::ActualCalleesTy &ActualCallees =
- getAnalysis<BUDataStructures>().getActualCallees();
#if 0
{TIME_REGION(XXX, "td:Copy graphs");
@@ -114,11 +112,11 @@
// Calculate top-down from main...
if (Function *F = M.getMainFunction())
- ComputePostOrder(*F, VisitedGraph, PostOrder, ActualCallees);
+ ComputePostOrder(*F, VisitedGraph, PostOrder);
// Next calculate the graphs for each unreachable function...
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
- ComputePostOrder(*I, VisitedGraph, PostOrder, ActualCallees);
+ ComputePostOrder(*I, VisitedGraph, PostOrder);
VisitedGraph.clear(); // Release memory!
}
@@ -167,8 +165,7 @@
void TDDataStructures::ComputePostOrder(Function &F,hash_set<DSGraph*> &Visited,
- std::vector<DSGraph*> &PostOrder,
- const BUDataStructures::ActualCalleesTy &ActualCallees) {
+ std::vector<DSGraph*> &PostOrder) {
if (F.isExternal()) return;
DSGraph &G = getOrCreateDSGraph(F);
if (Visited.count(&G)) return;
@@ -177,13 +174,11 @@
// Recursively traverse all of the callee graphs.
for (DSGraph::fc_iterator CI = G.fc_begin(), E = G.fc_end(); CI != E; ++CI) {
Instruction *CallI = CI->getCallSite().getInstruction();
- std::pair<BUDataStructures::ActualCalleesTy::const_iterator,
- BUDataStructures::ActualCalleesTy::const_iterator>
- IP = ActualCallees.equal_range(CallI);
-
- for (BUDataStructures::ActualCalleesTy::const_iterator I = IP.first;
- I != IP.second; ++I)
- ComputePostOrder(*I->second, Visited, PostOrder, ActualCallees);
+ BUDataStructures::ActualCalleesTy::const_iterator I =
+ BUInfo->callee_begin(CallI), E = BUInfo->callee_end(CallI);
+
+ for (; I != E; ++I)
+ ComputePostOrder(*I->second, Visited, PostOrder);
}
PostOrder.push_back(&G);
@@ -315,9 +310,6 @@
// callee graphs.
if (DSG.fc_begin() == DSG.fc_end()) return;
- const BUDataStructures::ActualCalleesTy &ActualCallees =
- getAnalysis<BUDataStructures>().getActualCallees();
-
// Loop over all the call sites and all the callees at each call site, and add
// edges to the CallerEdges structure for each callee.
for (DSGraph::fc_iterator CI = DSG.fc_begin(), E = DSG.fc_end();
@@ -334,27 +326,26 @@
Instruction *CallI = CI->getCallSite().getInstruction();
// For each function in the invoked function list at this call site...
- std::pair<BUDataStructures::ActualCalleesTy::const_iterator,
- BUDataStructures::ActualCalleesTy::const_iterator>
- IP = ActualCallees.equal_range(CallI);
+ BUDataStructures::ActualCalleesTy::const_iterator IPI =
+ BUInfo->callee_begin(CallI), IPE = BUInfo->callee_end(CallI);
// Skip over all calls to this graph (SCC calls).
- while (IP.first != IP.second && &getDSGraph(*IP.first->second) == &DSG)
- ++IP.first;
+ while (IPI != IPE && &getDSGraph(*IPI->second) == &DSG)
+ ++IPI;
// All SCC calls?
- if (IP.first == IP.second) continue;
+ if (IPI == IPE) continue;
- Function *FirstCallee = IP.first->second;
- ++IP.first;
+ Function *FirstCallee = IPI->second;
+ ++IPI;
// Skip over more SCC calls.
- while (IP.first != IP.second && &getDSGraph(*IP.first->second) == &DSG)
- ++IP.first;
+ while (IPI != IPE && &getDSGraph(*IPI->second) == &DSG)
+ ++IPI;
// If there is exactly one callee from this call site, remember the edge in
// CallerEdges.
- if (IP.first == IP.second) {
+ if (IPI == IPE) {
if (!FirstCallee->isExternal())
CallerEdges[&getDSGraph(*FirstCallee)]
.push_back(CallerCallEdge(&DSG, &*CI, FirstCallee));
@@ -367,9 +358,9 @@
// so we build up a new, private, graph that represents the calls of all
// calls to this set of functions.
std::vector<Function*> Callees;
- IP = ActualCallees.equal_range(CallI);
- for (BUDataStructures::ActualCalleesTy::const_iterator I = IP.first;
- I != IP.second; ++I)
+ for (BUDataStructures::ActualCalleesTy::const_iterator I =
+ BUInfo->callee_begin(CallI), E = BUInfo->callee_end(CallI);
+ I != E; ++I)
if (!I->second->isExternal())
Callees.push_back(I->second);
std::sort(Callees.begin(), Callees.end());
More information about the llvm-commits
mailing list