@@ -187,8 +187,8 @@ unsigned MLInlineAdvisor::getInitialFunctionLevel(const Function &F) const {
187
187
return CG.lookup (F) ? FunctionLevels.at (CG.lookup (F)) : 0 ;
188
188
}
189
189
190
- void MLInlineAdvisor::onPassEntry (LazyCallGraph::SCC *LastSCC ) {
191
- if (!LastSCC || ForceStop)
190
+ void MLInlineAdvisor::onPassEntry (LazyCallGraph::SCC *CurSCC ) {
191
+ if (!CurSCC || ForceStop)
192
192
return ;
193
193
FPICache.clear ();
194
194
// Function passes executed between InlinerPass runs may have changed the
@@ -206,23 +206,18 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) {
206
206
// care about the nature of the Edge (call or ref). `FunctionLevels`-wise, we
207
207
// record them at the same level as the original node (this is a choice, may
208
208
// need revisiting).
209
- NodeCount -= static_cast <int64_t >(NodesInLastSCC.size ());
210
209
while (!NodesInLastSCC.empty ()) {
211
210
const auto *N = *NodesInLastSCC.begin ();
211
+ assert (!N->isDead ());
212
212
NodesInLastSCC.erase (N);
213
- // The Function wrapped by N could have been deleted since we last saw it.
214
- if (N->isDead ()) {
215
- assert (!N->getFunction ().isDeclaration ());
216
- continue ;
217
- }
218
- ++NodeCount;
219
213
EdgeCount += getLocalCalls (N->getFunction ());
220
214
const auto NLevel = FunctionLevels.at (N);
221
215
for (const auto &E : *(*N)) {
222
216
const auto *AdjNode = &E.getNode ();
223
217
assert (!AdjNode->isDead () && !AdjNode->getFunction ().isDeclaration ());
224
218
auto I = AllNodes.insert (AdjNode);
225
219
if (I.second ) {
220
+ ++NodeCount;
226
221
NodesInLastSCC.insert (AdjNode);
227
222
FunctionLevels[AdjNode] = NLevel;
228
223
}
@@ -235,31 +230,29 @@ void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *LastSCC) {
235
230
// (Re)use NodesInLastSCC to remember the nodes in the SCC right now,
236
231
// in case the SCC is split before onPassExit and some nodes are split out
237
232
assert (NodesInLastSCC.empty ());
238
- for (const auto &N : *LastSCC )
233
+ for (const auto &N : *CurSCC )
239
234
NodesInLastSCC.insert (&N);
240
235
}
241
236
242
- void MLInlineAdvisor::onPassExit (LazyCallGraph::SCC *LastSCC ) {
237
+ void MLInlineAdvisor::onPassExit (LazyCallGraph::SCC *CurSCC ) {
243
238
// No need to keep this around - function passes will invalidate it.
244
239
if (!KeepFPICache)
245
240
FPICache.clear ();
246
- if (!LastSCC || ForceStop)
241
+ if (!CurSCC || ForceStop)
247
242
return ;
248
243
// Keep track of the nodes and edges we last saw. Then, in onPassEntry,
249
244
// we update the node count and edge count from the subset of these nodes that
250
245
// survived.
251
246
EdgesOfLastSeenNodes = 0 ;
252
247
253
248
// Check on nodes that were in SCC onPassEntry
254
- for (auto I = NodesInLastSCC.begin (); I != NodesInLastSCC.end ();) {
255
- if ((*I)->isDead ())
256
- NodesInLastSCC.erase (*I++);
257
- else
258
- EdgesOfLastSeenNodes += getLocalCalls ((*I++)->getFunction ());
249
+ for (const LazyCallGraph::Node *N : NodesInLastSCC) {
250
+ assert (!N->isDead ());
251
+ EdgesOfLastSeenNodes += getLocalCalls (N->getFunction ());
259
252
}
260
253
261
254
// Check on nodes that may have got added to SCC
262
- for (const auto &N : *LastSCC ) {
255
+ for (const auto &N : *CurSCC ) {
263
256
assert (!N.isDead ());
264
257
auto I = NodesInLastSCC.insert (&N);
265
258
if (I.second )
@@ -306,11 +299,18 @@ void MLInlineAdvisor::onSuccessfulInlining(const MLInlineAdvice &Advice,
306
299
int64_t NewCallerAndCalleeEdges =
307
300
getCachedFPI (*Caller).DirectCallsToDefinedFunctions ;
308
301
309
- if (CalleeWasDeleted)
302
+ // A dead function's node is not actually removed from the call graph until
303
+ // the end of the call graph walk, but the node no longer belongs to any valid
304
+ // SCC.
305
+ if (CalleeWasDeleted) {
310
306
--NodeCount;
311
- else
307
+ LazyCallGraph::Node *CalleeN = CG.lookup (*Callee);
308
+ NodesInLastSCC.erase (CalleeN);
309
+ AllNodes.erase (CalleeN);
310
+ } else {
312
311
NewCallerAndCalleeEdges +=
313
312
getCachedFPI (*Callee).DirectCallsToDefinedFunctions ;
313
+ }
314
314
EdgeCount += (NewCallerAndCalleeEdges - Advice.CallerAndCalleeEdges );
315
315
assert (CurrentIRSize >= 0 && EdgeCount >= 0 && NodeCount >= 0 );
316
316
}
@@ -484,8 +484,7 @@ void MLInlineAdvisor::print(raw_ostream &OS) const {
484
484
OS << " \n " ;
485
485
OS << " [MLInlineAdvisor] FuncLevels:\n " ;
486
486
for (auto I : FunctionLevels)
487
- OS << (I.first ->isDead () ? " <deleted>" : I.first ->getFunction ().getName ())
488
- << " : " << I.second << " \n " ;
487
+ OS << I.first ->getFunction ().getName () << " : " << I.second << " \n " ;
489
488
490
489
OS << " \n " ;
491
490
}
0 commit comments