return true;
}
-static bool removeEmptyCleanup(CleanupReturnInst *RI) {
+static bool removeEmptyCleanup(CleanupReturnInst *RI, DomTreeUpdater *DTU) {
// If this is a trivial cleanup pad that executes no instructions, it can be
// eliminated. If the cleanup pad continues to the caller, any predecessor
// that is an EH pad will be updated to continue to the caller and any
}
}
+ std::vector<DominatorTree::UpdateType> Updates;
+
for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE;) {
// The iterator must be updated here because we are removing this pred.
BasicBlock *PredBB = *PI++;
if (UnwindDest == nullptr) {
- removeUnwindEdge(PredBB);
+ if (DTU)
+ DTU->applyUpdatesPermissive(Updates);
+ Updates.clear();
+ removeUnwindEdge(PredBB, DTU);
++NumInvokes;
} else {
Instruction *TI = PredBB->getTerminator();
TI->replaceUsesOfWith(BB, UnwindDest);
+ Updates.push_back({DominatorTree::Delete, PredBB, BB});
+ Updates.push_back({DominatorTree::Insert, PredBB, UnwindDest});
}
}
- // The cleanup pad is now unreachable. Zap it.
- BB->eraseFromParent();
+ if (DTU) {
+ DTU->applyUpdatesPermissive(Updates);
+ DTU->deleteBB(BB);
+ } else
+ // The cleanup pad is now unreachable. Zap it.
+ BB->eraseFromParent();
+
return true;
}
if (mergeCleanupPad(RI))
return true;
- if (removeEmptyCleanup(RI))
+ if (removeEmptyCleanup(RI, DTU))
return true;
return false;
; Tests that the dynamic allocation and deallocation of the coroutine frame is
; elided and any tail calls referencing the coroutine frame has the tail
; call attribute removed.
-; RUN: opt < %s -S -inline -coro-elide -instsimplify -simplifycfg | FileCheck %s
+; RUN: opt < %s -S -inline -coro-elide -instsimplify -simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s
; RUN: opt < %s -S \
; RUN: -passes='cgscc(inline,function(coro-elide,instsimplify,simplify-cfg))' \
; RUN: -aa-pipeline='basic-aa' | FileCheck %s