Substantially cleanup/speedup the eq graphs pass by walking the callgraph

a DSGraph at a time instead of a function at a time.  This is also more
correct, though it doesn't seem to fix any programs.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17435 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2004-11-02 17:51:11 +00:00
parent e09e21dd1b
commit 033a7d5389
2 changed files with 44 additions and 49 deletions

View File

@@ -93,11 +93,10 @@ namespace PA {
private: private:
void buildIndirectFunctionSets(Module &M); void buildIndirectFunctionSets(Module &M);
unsigned processSCC(DSGraph &FG, Function &F, std::vector<Function*> &Stack, unsigned processSCC(DSGraph &FG, std::vector<DSGraph*> &Stack,
unsigned &NextID, unsigned &NextID,
std::map<Function*, unsigned> &ValMap); std::map<DSGraph*, unsigned> &ValMap);
void processGraph(DSGraph &FG);
void processGraph(DSGraph &FG, Function &F);
DSGraph &getOrCreateGraph(Function &F); DSGraph &getOrCreateGraph(Function &F);
}; };

View File

@@ -86,20 +86,20 @@ bool PA::EquivClassGraphs::runOnModule(Module &M) {
buildIndirectFunctionSets(M); buildIndirectFunctionSets(M);
// Stack of functions used for Tarjan's SCC-finding algorithm. // Stack of functions used for Tarjan's SCC-finding algorithm.
std::vector<Function*> Stack; std::vector<DSGraph*> Stack;
std::map<Function*, unsigned> ValMap; std::map<DSGraph*, unsigned> ValMap;
unsigned NextID = 1; unsigned NextID = 1;
if (Function *Main = M.getMainFunction()) { if (Function *Main = M.getMainFunction()) {
if (!Main->isExternal()) if (!Main->isExternal())
processSCC(getOrCreateGraph(*Main), *Main, Stack, NextID, ValMap); processSCC(getOrCreateGraph(*Main), Stack, NextID, ValMap);
} else { } else {
std::cerr << "Fold Graphs: No 'main' function found!\n"; std::cerr << "Fold Graphs: No 'main' function found!\n";
} }
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (!I->isExternal() && !ValMap.count(I)) if (!I->isExternal())
processSCC(getOrCreateGraph(*I), *I, Stack, NextID, ValMap); processSCC(getOrCreateGraph(*I), Stack, NextID, ValMap);
DEBUG(CheckAllGraphs(&M, *this)); DEBUG(CheckAllGraphs(&M, *this));
@@ -272,19 +272,19 @@ DSGraph &PA::EquivClassGraphs::getOrCreateGraph(Function &F) {
} }
unsigned PA::EquivClassGraphs::processSCC(DSGraph &FG, Function &F, unsigned PA::EquivClassGraphs::
std::vector<Function*> &Stack, processSCC(DSGraph &FG, std::vector<DSGraph*> &Stack, unsigned &NextID,
unsigned &NextID, std::map<DSGraph*, unsigned> &ValMap) {
std::map<Function*,unsigned> &ValMap){ std::map<DSGraph*, unsigned>::iterator It = ValMap.lower_bound(&FG);
DEBUG(std::cerr << " ProcessSCC for function " << F.getName() << "\n"); if (It != ValMap.end() && It->first == &FG)
std::map<Function*, unsigned>::iterator It = ValMap.lower_bound(&F);
if (It != ValMap.end() && It->first == &F)
return It->second; return It->second;
DEBUG(std::cerr << " ProcessSCC for function " << FG.getFunctionNames()
<< "\n");
unsigned Min = NextID++, MyID = Min; unsigned Min = NextID++, MyID = Min;
ValMap[&F] = Min; ValMap[&FG] = Min;
Stack.push_back(&F); Stack.push_back(&FG);
// The edges out of the current node are the call site targets... // The edges out of the current node are the call site targets...
for (unsigned i = 0, e = FG.getFunctionCalls().size(); i != e; ++i) { for (unsigned i = 0, e = FG.getFunctionCalls().size(); i != e; ++i) {
@@ -295,21 +295,21 @@ unsigned PA::EquivClassGraphs::processSCC(DSGraph &FG, Function &F,
for (tie(I, E) = getActualCallees().equal_range(Call); I != E; ++I) for (tie(I, E) = getActualCallees().equal_range(Call); I != E; ++I)
if (!I->second->isExternal()) { if (!I->second->isExternal()) {
// Process the callee as necessary. // Process the callee as necessary.
unsigned M = processSCC(getOrCreateGraph(*I->second), *I->second, unsigned M = processSCC(getOrCreateGraph(*I->second),
Stack, NextID, ValMap); Stack, NextID, ValMap);
if (M < Min) Min = M; if (M < Min) Min = M;
} }
} }
assert(ValMap[&F] == MyID && "SCC construction assumption wrong!"); assert(ValMap[&FG] == MyID && "SCC construction assumption wrong!");
if (Min != MyID) if (Min != MyID)
return Min; // This is part of a larger SCC! return Min; // This is part of a larger SCC!
// If this is a new SCC, process it now. // If this is a new SCC, process it now.
bool IsMultiNodeSCC = false; bool IsMultiNodeSCC = false;
while (Stack.back() != &F) { while (Stack.back() != &FG) {
DSGraph *NG = &getOrCreateGraph(*Stack.back()); DSGraph *NG = Stack.back();
ValMap[Stack.back()] = ~0U; ValMap[NG] = ~0U;
// Since all SCCs must be the same as those found in CBU, we do not need to // Since all SCCs must be the same as those found in CBU, we do not need to
// do any merging. Make sure all functions in the SCC share the same graph. // do any merging. Make sure all functions in the SCC share the same graph.
@@ -321,25 +321,24 @@ unsigned PA::EquivClassGraphs::processSCC(DSGraph &FG, Function &F,
Stack.pop_back(); Stack.pop_back();
processGraph(FG, F); processGraph(FG);
ValMap[&F] = ~0U; ValMap[&FG] = ~0U;
return MyID; return MyID;
} }
/// processGraph - Process the CBU graphs for the program in bottom-up order on /// processGraph - Process the CBU graphs for the program in bottom-up order on
/// the SCC of the __ACTUAL__ call graph. This builds final folded CBU graphs. /// the SCC of the __ACTUAL__ call graph. This builds final folded CBU graphs.
void PA::EquivClassGraphs::processGraph(DSGraph &G, Function &F) { void PA::EquivClassGraphs::processGraph(DSGraph &G) {
DEBUG(std::cerr << " ProcessGraph for function " << F.getName() << "\n"); DEBUG(std::cerr << " ProcessGraph for function "
<< G.getFunctionNames() << "\n");
hash_set<Instruction*> calls; hash_set<Instruction*> calls;
DSGraph* CallerGraph = &getOrCreateGraph(F);
// Else we need to inline some callee graph. Visit all call sites. // Else we need to inline some callee graph. Visit all call sites.
// The edges out of the current node are the call site targets... // The edges out of the current node are the call site targets...
for (unsigned i=0, e = CallerGraph->getFunctionCalls().size(); i != e; ++i) { for (unsigned i=0, e = G.getFunctionCalls().size(); i != e; ++i) {
const DSCallSite &CS = CallerGraph->getFunctionCalls()[i]; const DSCallSite &CS = G.getFunctionCalls()[i];
Instruction *TheCall = CS.getCallSite().getInstruction(); Instruction *TheCall = CS.getCallSite().getInstruction();
assert(calls.insert(TheCall).second && assert(calls.insert(TheCall).second &&
@@ -369,21 +368,19 @@ void PA::EquivClassGraphs::processGraph(DSGraph &G, Function &F) {
// including self-recursion have been folded in the equiv classes. // including self-recursion have been folded in the equiv classes.
// //
CalleeGraph = &getOrCreateGraph(*CalleeFunc); CalleeGraph = &getOrCreateGraph(*CalleeFunc);
if (CalleeGraph != CallerGraph) { if (CalleeGraph != &G) {
++NumFoldGraphInlines; ++NumFoldGraphInlines;
CallerGraph->mergeInGraph(CS, *CalleeFunc, *CalleeGraph, G.mergeInGraph(CS, *CalleeFunc, *CalleeGraph,
DSGraph::KeepModRefBits | DSGraph::KeepModRefBits | DSGraph::StripAllocaBit |
DSGraph::StripAllocaBit | DSGraph::DontCloneCallNodes |
DSGraph::DontCloneCallNodes | DSGraph::DontCloneAuxCallNodes);
DSGraph::DontCloneAuxCallNodes);
DEBUG(std::cerr << " Inlining graph [" << i << "/" << e-1 DEBUG(std::cerr << " Inlining graph [" << i << "/" << e-1
<< ":" << TNum << "/" << Num-1 << "] for " << ":" << TNum << "/" << Num-1 << "] for "
<< CalleeFunc->getName() << "[" << CalleeFunc->getName() << "["
<< CalleeGraph->getGraphSize() << "+" << CalleeGraph->getGraphSize() << "+"
<< CalleeGraph->getAuxFunctionCalls().size() << CalleeGraph->getAuxFunctionCalls().size()
<< "] into '" /*<< CallerGraph->getFunctionNames()*/ << "' [" << "] into '" /*<< G.getFunctionNames()*/ << "' ["
<< CallerGraph->getGraphSize() << "+" << G.getGraphSize() << "+" << G.getAuxFunctionCalls().size()
<< CallerGraph->getAuxFunctionCalls().size()
<< "]\n"); << "]\n");
} }
} }
@@ -400,26 +397,25 @@ void PA::EquivClassGraphs::processGraph(DSGraph &G, Function &F) {
} }
// Recompute the Incomplete markers. // Recompute the Incomplete markers.
assert(CallerGraph->getInlinedGlobals().empty()); assert(G.getInlinedGlobals().empty());
CallerGraph->maskIncompleteMarkers(); G.maskIncompleteMarkers();
CallerGraph->markIncompleteNodes(DSGraph::MarkFormalArgs); G.markIncompleteNodes(DSGraph::MarkFormalArgs);
// Delete dead nodes. Treat globals that are unreachable but that can // Delete dead nodes. Treat globals that are unreachable but that can
// reach live nodes as live. // reach live nodes as live.
CallerGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals); G.removeDeadNodes(DSGraph::KeepUnreachableGlobals);
// When this graph is finalized, clone the globals in the graph into the // When this graph is finalized, clone the globals in the graph into the
// globals graph to make sure it has everything, from all graphs. // globals graph to make sure it has everything, from all graphs.
DSScalarMap &MainSM = CallerGraph->getScalarMap(); ReachabilityCloner RC(*G.getGlobalsGraph(), G, DSGraph::StripAllocaBit);
ReachabilityCloner RC(*CallerGraph->getGlobalsGraph(), *CallerGraph,
DSGraph::StripAllocaBit);
// Clone everything reachable from globals in the function graph into the // Clone everything reachable from globals in the function graph into the
// globals graph. // globals graph.
DSScalarMap &MainSM = G.getScalarMap();
for (DSScalarMap::global_iterator I = MainSM.global_begin(), for (DSScalarMap::global_iterator I = MainSM.global_begin(),
E = MainSM.global_end(); I != E; ++I) E = MainSM.global_end(); I != E; ++I)
RC.getClonedNH(MainSM[*I]); RC.getClonedNH(MainSM[*I]);
DEBUG(std::cerr << " -- DONE ProcessGraph for function " DEBUG(std::cerr << " -- DONE ProcessGraph for function "
<< F.getName() << "\n"); << G.getFunctionNames() << "\n");
} }