@@ -505,9 +505,8 @@ class CallsiteContextGraph {
505505 // / we were able to identify the call chain through intermediate tail calls.
506506 // / In the latter case new context nodes are added to the graph for the
507507 // / identified tail calls, and their synthesized nodes are added to
508- // / TailCallToContextNodeMap. The EdgeIter is updated in either case to the
509- // / next element after the input position (either incremented or updated after
510- // / removing the old edge).
508+ // / TailCallToContextNodeMap. The EdgeIter is updated in the latter case for
509+ // / the updated edges and to prepare it for an increment in the caller.
511510 bool
512511 calleesMatch (CallTy Call, EdgeIter &EI,
513512 MapVector<CallInfo, ContextNode *> &TailCallToContextNodeMap);
@@ -1835,12 +1834,11 @@ void CallsiteContextGraph<DerivedCCG, FuncTy,
18351834 assert (Node->Clones .empty ());
18361835 // Check all node callees and see if in the same function.
18371836 auto Call = Node->Call .call ();
1838- for (auto EI = Node->CalleeEdges .begin (); EI != Node->CalleeEdges .end ();) {
1837+ for (auto EI = Node->CalleeEdges .begin (); EI != Node->CalleeEdges .end ();
1838+ ++EI) {
18391839 auto Edge = *EI;
1840- if (!Edge->Callee ->hasCall ()) {
1841- ++EI;
1840+ if (!Edge->Callee ->hasCall ())
18421841 continue ;
1843- }
18441842 assert (NodeToCallingFunc.count (Edge->Callee ));
18451843 // Check if the called function matches that of the callee node.
18461844 if (calleesMatch (Call, EI, TailCallToContextNodeMap))
@@ -1889,16 +1887,12 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::calleesMatch(
18891887 // calls between the profiled caller and callee.
18901888 std::vector<std::pair<CallTy, FuncTy *>> FoundCalleeChain;
18911889 if (!calleeMatchesFunc (Call, ProfiledCalleeFunc, CallerFunc,
1892- FoundCalleeChain)) {
1893- ++EI;
1890+ FoundCalleeChain))
18941891 return false ;
1895- }
18961892
18971893 // The usual case where the profiled callee matches that of the IR/summary.
1898- if (FoundCalleeChain.empty ()) {
1899- ++EI;
1894+ if (FoundCalleeChain.empty ())
19001895 return true ;
1901- }
19021896
19031897 auto AddEdge = [Edge, &EI](ContextNode *Caller, ContextNode *Callee) {
19041898 auto *CurEdge = Callee->findEdgeFromCaller (Caller);
@@ -1960,6 +1954,13 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::calleesMatch(
19601954 Edge->Callee ->eraseCallerEdge (Edge.get ());
19611955 EI = Edge->Caller ->CalleeEdges .erase (EI);
19621956
1957+ // To simplify the increment of EI in the caller, subtract one from EI.
1958+ // In the final AddEdge call we would have either added a new callee edge,
1959+ // to Edge->Caller, or found an existing one. Either way we are guaranteed
1960+ // that there is at least one callee edge.
1961+ assert (!Edge->Caller ->CalleeEdges .empty ());
1962+ --EI;
1963+
19631964 return true ;
19641965}
19651966
0 commit comments