@@ -1248,6 +1248,7 @@ static void handleNoSuspendCoroutine(coro::Shape &Shape) {
1248
1248
}
1249
1249
1250
1250
CoroBegin->eraseFromParent ();
1251
+ Shape.CoroBegin = nullptr ;
1251
1252
}
1252
1253
1253
1254
// SimplifySuspendPoint needs to check that there is no calls between
@@ -1970,9 +1971,17 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
1970
1971
}
1971
1972
1972
1973
// / Remove calls to llvm.coro.end in the original function.
1973
- static void removeCoroEnds (const coro::Shape &Shape) {
1974
- for (auto *End : Shape.CoroEnds ) {
1975
- replaceCoroEnd (End, Shape, Shape.FramePtr , /* in resume*/ false , nullptr );
1974
+ static void removeCoroEndsFromRampFunction (const coro::Shape &Shape) {
1975
+ if (Shape.ABI != coro::ABI::Switch) {
1976
+ for (auto *End : Shape.CoroEnds ) {
1977
+ replaceCoroEnd (End, Shape, Shape.FramePtr , /* in resume*/ false , nullptr );
1978
+ }
1979
+ } else {
1980
+ for (llvm::AnyCoroEndInst *End : Shape.CoroEnds ) {
1981
+ auto &Context = End->getContext ();
1982
+ End->replaceAllUsesWith (ConstantInt::getFalse (Context));
1983
+ End->eraseFromParent ();
1984
+ }
1976
1985
}
1977
1986
}
1978
1987
@@ -1981,18 +1990,6 @@ static void updateCallGraphAfterCoroutineSplit(
1981
1990
const SmallVectorImpl<Function *> &Clones, LazyCallGraph::SCC &C,
1982
1991
LazyCallGraph &CG, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR,
1983
1992
FunctionAnalysisManager &FAM) {
1984
- if (!Shape.CoroBegin )
1985
- return ;
1986
-
1987
- if (Shape.ABI != coro::ABI::Switch)
1988
- removeCoroEnds (Shape);
1989
- else {
1990
- for (llvm::AnyCoroEndInst *End : Shape.CoroEnds ) {
1991
- auto &Context = End->getContext ();
1992
- End->replaceAllUsesWith (ConstantInt::getFalse (Context));
1993
- End->eraseFromParent ();
1994
- }
1995
- }
1996
1993
1997
1994
if (!Clones.empty ()) {
1998
1995
switch (Shape.ABI ) {
@@ -2120,6 +2117,7 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C,
2120
2117
const coro::Shape Shape =
2121
2118
splitCoroutine (F, Clones, FAM.getResult <TargetIRAnalysis>(F),
2122
2119
OptimizeFrame, MaterializableCallback);
2120
+ removeCoroEndsFromRampFunction (Shape);
2123
2121
updateCallGraphAfterCoroutineSplit (*N, Shape, Clones, C, CG, AM, UR, FAM);
2124
2122
2125
2123
ORE.emit ([&]() {
0 commit comments