@@ -326,6 +326,14 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
326
326
// with the CB BB ('Entry') between which the inlined callee will be pasted.
327
327
Successors.insert (succ_begin (&CallSiteBB), succ_end (&CallSiteBB));
328
328
329
+ // the outcome of the inlining may be that some edges get lost (DCEd BBs
330
+ // because inlining brought some constant, for example). We don't know which
331
+ // edges will be removed, so we list all of them as potentially removable.
332
+ for (auto *Succ : successors (&CallSiteBB))
333
+ DomTreeUpdates.emplace_back (DominatorTree::UpdateKind::Delete,
334
+ const_cast <BasicBlock *>(&CallSiteBB),
335
+ const_cast <BasicBlock *>(Succ));
336
+
329
337
// Inlining only handles invoke and calls. If this is an invoke, and inlining
330
338
// it pulls another invoke, the original landing pad may get split, so as to
331
339
// share its content with other potential users. So the edge up to which we
@@ -336,6 +344,11 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
336
344
if (const auto *II = dyn_cast<InvokeInst>(&CB)) {
337
345
const auto *UnwindDest = II->getUnwindDest ();
338
346
Successors.insert (succ_begin (UnwindDest), succ_end (UnwindDest));
347
+ // Same idea as above, we pretend we lose all these edges.
348
+ for (auto *Succ : successors (UnwindDest))
349
+ DomTreeUpdates.emplace_back (DominatorTree::UpdateKind::Delete,
350
+ const_cast <BasicBlock *>(UnwindDest),
351
+ const_cast <BasicBlock *>(Succ));
339
352
}
340
353
341
354
// Exclude the CallSiteBB, if it happens to be its own successor (1-BB loop).
@@ -356,6 +369,30 @@ FunctionPropertiesUpdater::FunctionPropertiesUpdater(
356
369
FPI.updateForBB (*BB, -1 );
357
370
}
358
371
372
+ DominatorTree &FunctionPropertiesUpdater::getUpdatedDominatorTree (
373
+ FunctionAnalysisManager &FAM) const {
374
+ auto &DT =
375
+ FAM.getResult <DominatorTreeAnalysis>(const_cast <Function &>(Caller));
376
+
377
+ SmallVector<DominatorTree::UpdateType, 2 > FinalDomTreeUpdates;
378
+
379
+ for (auto &Upd : DomTreeUpdates)
380
+ FinalDomTreeUpdates.push_back (Upd);
381
+
382
+ DenseSet<const BasicBlock *> Inserted;
383
+ for (auto *Succ : successors (&CallSiteBB))
384
+ if (Inserted.insert (Succ).second )
385
+ FinalDomTreeUpdates.push_back ({DominatorTree::UpdateKind::Insert,
386
+ const_cast <BasicBlock *>(&CallSiteBB),
387
+ const_cast <BasicBlock *>(Succ)});
388
+
389
+ DT.applyUpdates (FinalDomTreeUpdates);
390
+ #ifdef EXPENSIVE_CHECKS
391
+ assert (DT.verify (DominatorTree::VerificationLevel::Full));
392
+ #endif
393
+ return DT;
394
+ }
395
+
359
396
void FunctionPropertiesUpdater::finish (FunctionAnalysisManager &FAM) const {
360
397
// Update feature values from the BBs that were copied from the callee, or
361
398
// might have been modified because of inlining. The latter have been
@@ -383,8 +420,7 @@ void FunctionPropertiesUpdater::finish(FunctionAnalysisManager &FAM) const {
383
420
// remove E.
384
421
SetVector<const BasicBlock *> Reinclude;
385
422
SetVector<const BasicBlock *> Unreachable;
386
- const auto &DT =
387
- FAM.getResult <DominatorTreeAnalysis>(const_cast <Function &>(Caller));
423
+ auto &DT = getUpdatedDominatorTree (FAM);
388
424
389
425
if (&CallSiteBB != &*Caller.begin ())
390
426
Reinclude.insert (&*Caller.begin ());
@@ -427,6 +463,9 @@ void FunctionPropertiesUpdater::finish(FunctionAnalysisManager &FAM) const {
427
463
428
464
const auto &LI = FAM.getResult <LoopAnalysis>(const_cast <Function &>(Caller));
429
465
FPI.updateAggregateStats (Caller, LI);
466
+ #ifdef EXPENSIVE_CHECKS
467
+ assert (isUpdateValid (Caller, FPI, FAM));
468
+ #endif
430
469
}
431
470
432
471
bool FunctionPropertiesUpdater::isUpdateValid (Function &F,
0 commit comments