mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user