Add call graph edges based on direct calls.

We were adding call graph edges based on seeing a function_ref. Instead,
we'll only add them now based on a direct apply of a function_ref.

Also a minor refactoring to move the code that walks the blocks and
instructions of a function into its own method.

Swift SVN r21243
This commit is contained in:
Mark Lacey
2014-08-15 23:29:37 +00:00
parent 1d97e5eb38
commit f1f3025838

View File

@@ -47,12 +47,7 @@ namespace swift {
CallGraphSorter<SILFunction*> sorter;
for (auto &Caller : *M)
for (auto &BB : Caller)
for (auto &I : BB)
if (FunctionRefInst *FRI = dyn_cast<FunctionRefInst>(&I)) {
SILFunction *Callee = FRI->getReferencedFunction();
sorter.addEdge(&Caller, Callee);
}
addEdgesForFunction(sorter, &Caller);
sorter.sort(BottomUpFunctionOrder);
@@ -66,6 +61,16 @@ namespace swift {
}
virtual void invalidate(SILFunction*, InvalidationKind K) { invalidate(K); }
private:
void addEdgesForFunction(CallGraphSorter<SILFunction *> &sorter,
SILFunction *Caller) {
for (auto &BB : *Caller)
for (auto &I : BB)
if (auto *AI = dyn_cast<ApplyInst>(&I))
if (auto *FRI = dyn_cast<FunctionRefInst>(AI->getCallee()))
sorter.addEdge(Caller, FRI->getReferencedFunction());
}
};
} // end namespace swift