@@ -324,32 +324,44 @@ void MLInlineAdvisor::onSuccessfulInlining(const MLInlineAdvice &Advice,
324324 FAM.invalidate (*Caller, PA);
325325 }
326326 Advice.updateCachedCallerFPI (FAM);
327- int64_t IRSizeAfter =
328- getIRSize (*Caller) + (CalleeWasDeleted ? 0 : Advice.CalleeIRSize );
329- CurrentIRSize += IRSizeAfter - (Advice.CallerIRSize + Advice.CalleeIRSize );
327+ if (Caller == Callee) {
328+ assert (!CalleeWasDeleted);
329+ // We double-counted CallerAndCalleeEdges - since the caller and callee
330+ // would be the same
331+ assert (Advice.CallerAndCalleeEdges % 2 == 0 );
332+ CurrentIRSize += getIRSize (*Caller) - Advice.CallerIRSize ;
333+ EdgeCount += getCachedFPI (*Caller).DirectCallsToDefinedFunctions -
334+ Advice.CallerAndCalleeEdges / 2 ;
335+ // The NodeCount would stay the same.
336+ } else {
337+ int64_t IRSizeAfter =
338+ getIRSize (*Caller) + (CalleeWasDeleted ? 0 : Advice.CalleeIRSize );
339+ CurrentIRSize += IRSizeAfter - (Advice.CallerIRSize + Advice.CalleeIRSize );
340+
341+ // We can delta-update module-wide features. We know the inlining only
342+ // changed the caller, and maybe the callee (by deleting the latter). Nodes
343+ // are simple to update. For edges, we 'forget' the edges that the caller
344+ // and callee used to have before inlining, and add back what they currently
345+ // have together.
346+ int64_t NewCallerAndCalleeEdges =
347+ getCachedFPI (*Caller).DirectCallsToDefinedFunctions ;
348+
349+ // A dead function's node is not actually removed from the call graph until
350+ // the end of the call graph walk, but the node no longer belongs to any
351+ // valid SCC.
352+ if (CalleeWasDeleted) {
353+ --NodeCount;
354+ NodesInLastSCC.erase (CG.lookup (*Callee));
355+ DeadFunctions.insert (Callee);
356+ } else {
357+ NewCallerAndCalleeEdges +=
358+ getCachedFPI (*Callee).DirectCallsToDefinedFunctions ;
359+ }
360+ EdgeCount += (NewCallerAndCalleeEdges - Advice.CallerAndCalleeEdges );
361+ }
330362 if (CurrentIRSize > SizeIncreaseThreshold * InitialIRSize)
331363 ForceStop = true ;
332364
333- // We can delta-update module-wide features. We know the inlining only changed
334- // the caller, and maybe the callee (by deleting the latter).
335- // Nodes are simple to update.
336- // For edges, we 'forget' the edges that the caller and callee used to have
337- // before inlining, and add back what they currently have together.
338- int64_t NewCallerAndCalleeEdges =
339- getCachedFPI (*Caller).DirectCallsToDefinedFunctions ;
340-
341- // A dead function's node is not actually removed from the call graph until
342- // the end of the call graph walk, but the node no longer belongs to any valid
343- // SCC.
344- if (CalleeWasDeleted) {
345- --NodeCount;
346- NodesInLastSCC.erase (CG.lookup (*Callee));
347- DeadFunctions.insert (Callee);
348- } else {
349- NewCallerAndCalleeEdges +=
350- getCachedFPI (*Callee).DirectCallsToDefinedFunctions ;
351- }
352- EdgeCount += (NewCallerAndCalleeEdges - Advice.CallerAndCalleeEdges );
353365 assert (CurrentIRSize >= 0 && EdgeCount >= 0 && NodeCount >= 0 );
354366}
355367
0 commit comments