mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Remove a source of potential non-determinism in call graph construction.
Sort call graph nodes in the CalleeSet (which is a SmallPtrSet) by the ordinal we've assigned before iterating over them. The caller edge list will change to a SmallPtrSet soon as well, and technically this won't be necessary at that point, but I will probably leave the sorting in as it doesn't hurt anything and will ensure that if we need to change data structures again we'll continue to be deterministic. Swift SVN r26091
This commit is contained in:
@@ -169,6 +169,17 @@ bool CallGraph::tryGetCalleeSet(SILValue Callee,
|
||||
}
|
||||
}
|
||||
|
||||
static void orderCallees(const CallGraphEdge::CalleeSetType &Callees,
|
||||
llvm::SmallVectorImpl<CallGraphNode *> &OrderedNodes) {
|
||||
for (auto *Node : Callees)
|
||||
OrderedNodes.push_back(Node);
|
||||
|
||||
std::sort(OrderedNodes.begin(), OrderedNodes.end(),
|
||||
[](CallGraphNode *left, CallGraphNode *right) {
|
||||
return left->getOrdinal() < right->getOrdinal();
|
||||
});
|
||||
}
|
||||
|
||||
void CallGraph::addEdgesForApply(ApplyInst *AI, CallGraphNode *CallerNode) {
|
||||
CallGraphEdge::CalleeSetType CalleeSet;
|
||||
bool Complete = false;
|
||||
@@ -179,7 +190,11 @@ void CallGraph::addEdgesForApply(ApplyInst *AI, CallGraphNode *CallerNode) {
|
||||
"Added apply that already has an edge node!\n");
|
||||
ApplyToEdgeMap[AI] = Edge;
|
||||
CallerNode->addCalleeEdge(Edge);
|
||||
for (auto *CalleeNode : CalleeSet)
|
||||
|
||||
llvm::SmallVector<CallGraphNode *, 4> OrderedNodes;
|
||||
orderCallees(CalleeSet, OrderedNodes);
|
||||
|
||||
for (auto *CalleeNode : OrderedNodes)
|
||||
CalleeNode->addCallerEdge(Edge);
|
||||
|
||||
// TODO: Compute this from the call graph itself after stripping
|
||||
@@ -221,17 +236,6 @@ void CallGraph::addEdges(SILFunction *F) {
|
||||
}
|
||||
}
|
||||
|
||||
static void orderCallees(const CallGraphEdge::CalleeSetType &Callees,
|
||||
llvm::SmallVectorImpl<CallGraphNode *> &OrderedNodes) {
|
||||
for (auto *Node : Callees)
|
||||
OrderedNodes.push_back(Node);
|
||||
|
||||
std::sort(OrderedNodes.begin(), OrderedNodes.end(),
|
||||
[](CallGraphNode *left, CallGraphNode *right) {
|
||||
return left->getOrdinal() < right->getOrdinal();
|
||||
});
|
||||
}
|
||||
|
||||
/// Finds SCCs in the call graph. Our call graph has an unconventional
|
||||
/// form where each edge of the graph is really a multi-edge that can
|
||||
/// point to multiple call graph nodes in the case where we can call
|
||||
|
||||
Reference in New Issue
Block a user