================
@@ -642,6 +650,37 @@ struct CallCoroDelete final : public EHScopeStack::Cleanup
{
CGF.Builder.SetInsertPoint(AfterFreeBB);
}
explicit CallCoroDelete(Stmt *DeallocStmt) : Deallocate(DeallocStmt) {}
+
+private:
+ // [dcl.fct.def.coroutine]: The coroutine state is destroyed when control
+ // flows off the end of the coroutine or the destroy member function of a
+ // coroutine handle that refers to the coroutine is invoked.
+ void EmitPreCleanupBB(CodeGenFunction &CGF) {
+ auto &Builder = CGF.Builder;
+ auto &Data = *CGF.CurCoro.Data;
+ auto *BodyDone = Data.BodyDone;
+ BasicBlock *SaveInsertBlock = Builder.GetInsertBlock();
+ BasicBlock *PreConvBB = BodyDone->getParent();
+ BasicBlock *AfterConvBB =
+ cast<llvm::BranchInst>(PreConvBB->getTerminator())->getSuccessor(1);
+ BasicBlock *CleanupBB = AfterConvBB->getSingleSuccessor();
+ BasicBlock *PreCleanupBB = CleanupBB->splitBasicBlock(
+ CleanupBB->getFirstNonPHIIt(), "pre.coro.cleanup", true);
+ Builder.SetInsertPoint(PreCleanupBB);
+ PreCleanupBB->getTerminator()->eraseFromParent();
+
+ auto *NeedCleanup = Builder.CreatePHI(
+ Builder.getInt1Ty(), llvm::pred_size(PreCleanupBB), "is.completed");
+ for (auto *Pred : llvm::predecessors(PreCleanupBB)) {
----------------
NewSigma wrote:
> The size of pred of PreCleanupBB shouldn't always be 1?
I missed that. Thanks.
> And what's the intention of EmitPreCleanupBB. I didn't understand it.
Since `SuspendBB` is now `pre.gro.conv`, we need a branching so that suspending
does not destroy the coroutine.
https://github.com/llvm/llvm-project/pull/151067
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits