Skip to content

Commit

Permalink
Update edge removal API in call graph.
Browse files Browse the repository at this point in the history
Add a parameter for a function the call site is in, rather than using
the call site to determine the function.

This is necessary for enabling invalidation of call graph information
for individual functions. If we're not maintaining the call graph during
a pass, we may delete an instruction and be left with a dangling pointer
in the call graph edge. This allows us to still remove the edge properly
without trying to look at the instruction it represents.
  • Loading branch information
rudkx committed Nov 3, 2015
1 parent bc679c1 commit d36dac6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/swift/SILAnalysis/CallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class CallGraph {
/// caller or callee edges.
void removeNode(CallGraphNode *Node);

void removeEdge(CallGraphEdge *Edge);
void removeEdgeFromFunction(CallGraphEdge *Edge, SILFunction *F);
void removeEdgesForApply(FullApplySite AI);

// Query funtions for getting nodes and edges from the call graph.
Expand Down Expand Up @@ -586,7 +586,7 @@ class CallGraphEditor {
if (CG) {
if (auto AI = FullApplySite::isa(I))
if (auto *Edge = CG->tryGetCallGraphEdge(AI))
CG->removeEdge(Edge);
CG->removeEdgeFromFunction(Edge, I->getFunction());
}
}

Expand Down
14 changes: 7 additions & 7 deletions lib/SILAnalysis/CallGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,18 +355,18 @@ void CallGraph::addEdgesForApply(FullApplySite Apply,
++NumAppliesWithEdges;
}

void CallGraph::removeEdge(CallGraphEdge *Edge) {
void CallGraph::removeEdgeFromFunction(CallGraphEdge *Edge, SILFunction *F) {
// Remove the edge from all the potential callee call graph nodes.
auto CalleeSet = Edge->getCalleeSet();
for (auto *CalleeNode : CalleeSet)
CalleeNode->removeCallerEdge(Edge);

// Remove the edge from the caller's call graph node.
auto Apply = Edge->getApply();
auto *CallerNode = getCallGraphNode(Apply.getFunction());
auto *CallerNode = getCallGraphNode(F);
CallerNode->removeCalleeEdge(Edge);

// Remove the mapping from the apply to this edge.
auto Apply = Edge->getApply();
ApplyToEdgeMap.erase(Apply);

// Call the destructor for the edge. The memory will be reclaimed
Expand Down Expand Up @@ -398,7 +398,7 @@ void CallGraph::removeNode(CallGraphNode *Node) {
// apply is known to the call graph.
void CallGraph::removeEdgesForApply(FullApplySite AI) {
assert(ApplyToEdgeMap.count(AI) && "Expected apply to be in edge map!");
removeEdge(ApplyToEdgeMap[AI]);
removeEdgeFromFunction(ApplyToEdgeMap[AI], AI.getFunction());
}

void CallGraph::addEdges(SILFunction *F) {
Expand Down Expand Up @@ -777,7 +777,7 @@ void CallGraphEditor::replaceApplyWithNew(FullApplySite Old,
return;

if (auto *Edge = CG->tryGetCallGraphEdge(Old))
CG->removeEdge(Edge);
CG->removeEdgeFromFunction(Edge, Old.getFunction());

CG->addEdgesForApply(New);
}
Expand All @@ -788,7 +788,7 @@ void CallGraphEditor::replaceApplyWithNew(FullApplySite Old,
return;

if (auto *Edge = CG->tryGetCallGraphEdge(Old))
CG->removeEdge(Edge);
CG->removeEdgeFromFunction(Edge, Old.getFunction());

for (auto NewApply : NewApplies)
CG->addEdgesForApply(NewApply);
Expand All @@ -813,7 +813,7 @@ void CallGraphEditor::removeAllCalleeEdgesFrom(SILFunction *F) {
auto &CalleeEdges = CG->getCallGraphNode(F)->getCalleeEdges();
while (!CalleeEdges.empty()) {
auto *Edge = *CalleeEdges.begin();
CG->removeEdge(Edge);
CG->removeEdgeFromFunction(Edge, F);
}
}

Expand Down

0 comments on commit d36dac6

Please sign in to comment.