introduce a new CallGraphSCC class, and pass it around

to CallGraphSCCPass's instead of passing around a
std::vector<CallGraphNode*>.  No functionality change,
but now we have a much tidier interface.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101558 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2010-04-16 22:42:17 +00:00
parent c7b65914e0
commit 2decb22222
10 changed files with 132 additions and 86 deletions
+34 -21
View File
@@ -81,9 +81,9 @@ public:
}
private:
bool RunPassOnSCC(Pass *P, std::vector<CallGraphNode*> &CurSCC,
bool RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
CallGraph &CG, bool &CallGraphUpToDate);
void RefreshCallGraph(std::vector<CallGraphNode*> &CurSCC, CallGraph &CG,
void RefreshCallGraph(CallGraphSCC &CurSCC, CallGraph &CG,
bool IsCheckingMode);
};
@@ -92,7 +92,7 @@ private:
char CGPassManager::ID = 0;
bool CGPassManager::RunPassOnSCC(Pass *P, std::vector<CallGraphNode*> &CurSCC,
bool CGPassManager::RunPassOnSCC(Pass *P, CallGraphSCC &CurSCC,
CallGraph &CG, bool &CallGraphUpToDate) {
bool Changed = false;
PMDataManager *PM = P->getAsPMDataManager();
@@ -125,8 +125,9 @@ bool CGPassManager::RunPassOnSCC(Pass *P, std::vector<CallGraphNode*> &CurSCC,
FPPassManager *FPP = (FPPassManager*)P;
// Run pass P on all functions in the current SCC.
for (unsigned i = 0, e = CurSCC.size(); i != e; ++i) {
if (Function *F = CurSCC[i]->getFunction()) {
for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
I != E; ++I) {
if (Function *F = (*I)->getFunction()) {
dumpPassInfo(P, EXECUTION_MSG, ON_FUNCTION_MSG, F->getName());
TimeRegion PassTimer(getPassTimer(FPP));
Changed |= FPP->runOnFunction(*F);
@@ -149,21 +150,24 @@ bool CGPassManager::RunPassOnSCC(Pass *P, std::vector<CallGraphNode*> &CurSCC,
/// FunctionPasses have potentially munged the callgraph, and can be used after
/// CallGraphSCC passes to verify that they correctly updated the callgraph.
///
void CGPassManager::RefreshCallGraph(std::vector<CallGraphNode*> &CurSCC,
void CGPassManager::RefreshCallGraph(CallGraphSCC &CurSCC,
CallGraph &CG, bool CheckingMode) {
DenseMap<Value*, CallGraphNode*> CallSites;
DEBUG(dbgs() << "CGSCCPASSMGR: Refreshing SCC with " << CurSCC.size()
<< " nodes:\n";
for (unsigned i = 0, e = CurSCC.size(); i != e; ++i)
CurSCC[i]->dump();
for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
I != E; ++I)
(*I)->dump();
);
bool MadeChange = false;
// Scan all functions in the SCC.
for (unsigned sccidx = 0, e = CurSCC.size(); sccidx != e; ++sccidx) {
CallGraphNode *CGN = CurSCC[sccidx];
unsigned FunctionNo = 0;
for (CallGraphSCC::iterator SCCIdx = CurSCC.begin(), E = CurSCC.end();
SCCIdx != E; ++SCCIdx, ++FunctionNo) {
CallGraphNode *CGN = *SCCIdx;
Function *F = CGN->getFunction();
if (F == 0 || F->isDeclaration()) continue;
@@ -282,14 +286,15 @@ void CGPassManager::RefreshCallGraph(std::vector<CallGraphNode*> &CurSCC,
// Periodically do an explicit clear to remove tombstones when processing
// large scc's.
if ((sccidx & 15) == 0)
if ((FunctionNo & 15) == 15)
CallSites.clear();
}
DEBUG(if (MadeChange) {
dbgs() << "CGSCCPASSMGR: Refreshed SCC is now:\n";
for (unsigned i = 0, e = CurSCC.size(); i != e; ++i)
CurSCC[i]->dump();
for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
I != E; ++I)
(*I)->dump();
} else {
dbgs() << "CGSCCPASSMGR: SCC Refresh didn't change call graph.\n";
}
@@ -302,14 +307,15 @@ bool CGPassManager::runOnModule(Module &M) {
CallGraph &CG = getAnalysis<CallGraph>();
bool Changed = doInitialization(CG);
std::vector<CallGraphNode*> CurSCC;
CallGraphSCC CurSCC(this);
// Walk the callgraph in bottom-up SCC order.
for (scc_iterator<CallGraph*> CGI = scc_begin(&CG), E = scc_end(&CG);
CGI != E;) {
// Copy the current SCC and increment past it so that the pass can hack
// on the SCC if it wants to without invalidating our iterator.
CurSCC = *CGI;
std::vector<CallGraphNode*> &NodeVec = *CGI;
CurSCC.initialize(&NodeVec[0], &NodeVec[0]+NodeVec.size());
++CGI;
@@ -333,9 +339,10 @@ bool CGPassManager::runOnModule(Module &M) {
std::string Functions;
#ifndef NDEBUG
raw_string_ostream OS(Functions);
for (unsigned i = 0, e = CurSCC.size(); i != e; ++i) {
if (i) OS << ", ";
CurSCC[i]->print(OS);
for (CallGraphSCC::iterator I = CurSCC.begin(), E = CurSCC.end();
I != E; ++I) {
if (I != CurSCC.begin()) OS << ", ";
(*I)->print(OS);
}
OS.flush();
#endif
@@ -397,6 +404,12 @@ bool CGPassManager::doFinalization(CallGraph &CG) {
return Changed;
}
//===----------------------------------------------------------------------===//
// CallGraphSCC Implementation
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// CallGraphSCCPass Implementation
//===----------------------------------------------------------------------===//
@@ -468,10 +481,10 @@ namespace {
AU.setPreservesAll();
}
bool runOnSCC(std::vector<CallGraphNode *> &SCC) {
bool runOnSCC(CallGraphSCC &SCC) {
Out << Banner;
for (unsigned i = 0, e = SCC.size(); i != e; ++i)
SCC[i]->getFunction()->print(Out);
for (CallGraphSCC::iterator I = SCC.begin(), E = SCC.end(); I != E; ++I)
(*I)->getFunction()->print(Out);
return false;
}
};