@@ -505,9 +505,8 @@ class CallsiteContextGraph {
505
505
// / we were able to identify the call chain through intermediate tail calls.
506
506
// / In the latter case new context nodes are added to the graph for the
507
507
// / 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.
511
510
bool
512
511
calleesMatch (CallTy Call, EdgeIter &EI,
513
512
MapVector<CallInfo, ContextNode *> &TailCallToContextNodeMap);
@@ -1835,12 +1834,11 @@ void CallsiteContextGraph<DerivedCCG, FuncTy,
1835
1834
assert (Node->Clones .empty ());
1836
1835
// Check all node callees and see if in the same function.
1837
1836
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) {
1839
1839
auto Edge = *EI;
1840
- if (!Edge->Callee ->hasCall ()) {
1841
- ++EI;
1840
+ if (!Edge->Callee ->hasCall ())
1842
1841
continue ;
1843
- }
1844
1842
assert (NodeToCallingFunc.count (Edge->Callee ));
1845
1843
// Check if the called function matches that of the callee node.
1846
1844
if (calleesMatch (Call, EI, TailCallToContextNodeMap))
@@ -1889,16 +1887,12 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::calleesMatch(
1889
1887
// calls between the profiled caller and callee.
1890
1888
std::vector<std::pair<CallTy, FuncTy *>> FoundCalleeChain;
1891
1889
if (!calleeMatchesFunc (Call, ProfiledCalleeFunc, CallerFunc,
1892
- FoundCalleeChain)) {
1893
- ++EI;
1890
+ FoundCalleeChain))
1894
1891
return false ;
1895
- }
1896
1892
1897
1893
// The usual case where the profiled callee matches that of the IR/summary.
1898
- if (FoundCalleeChain.empty ()) {
1899
- ++EI;
1894
+ if (FoundCalleeChain.empty ())
1900
1895
return true ;
1901
- }
1902
1896
1903
1897
auto AddEdge = [Edge, &EI](ContextNode *Caller, ContextNode *Callee) {
1904
1898
auto *CurEdge = Callee->findEdgeFromCaller (Caller);
@@ -1960,6 +1954,13 @@ bool CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::calleesMatch(
1960
1954
Edge->Callee ->eraseCallerEdge (Edge.get ());
1961
1955
EI = Edge->Caller ->CalleeEdges .erase (EI);
1962
1956
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
+
1963
1964
return true ;
1964
1965
}
1965
1966
0 commit comments