Skip to content

Commit a988a3f

Browse files
[Coroutines] Make CoroSplit properly update CallGraph
1 parent 34e3007 commit a988a3f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,12 +2079,13 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
20792079
return Shape;
20802080
}
20812081

2082-
static void updateCallGraphAfterCoroutineSplit(
2082+
static LazyCallGraph::SCC &updateCallGraphAfterCoroutineSplit(
20832083
LazyCallGraph::Node &N, const coro::Shape &Shape,
20842084
const SmallVectorImpl<Function *> &Clones, LazyCallGraph::SCC &C,
20852085
LazyCallGraph &CG, CGSCCAnalysisManager &AM, CGSCCUpdateResult &UR,
20862086
FunctionAnalysisManager &FAM) {
20872087

2088+
auto *CurrentSCC = &C;
20882089
if (!Clones.empty()) {
20892090
switch (Shape.ABI) {
20902091
case coro::ABI::Switch:
@@ -2104,13 +2105,16 @@ static void updateCallGraphAfterCoroutineSplit(
21042105
}
21052106

21062107
// Let the CGSCC infra handle the changes to the original function.
2107-
updateCGAndAnalysisManagerForCGSCCPass(CG, C, N, AM, UR, FAM);
2108+
CurrentSCC = &updateCGAndAnalysisManagerForCGSCCPass(CG, *CurrentSCC, N, AM,
2109+
UR, FAM);
21082110
}
21092111

21102112
// Do some cleanup and let the CGSCC infra see if we've cleaned up any edges
21112113
// to the split functions.
21122114
postSplitCleanup(N.getFunction());
2113-
updateCGAndAnalysisManagerForFunctionPass(CG, C, N, AM, UR, FAM);
2115+
CurrentSCC = &updateCGAndAnalysisManagerForFunctionPass(CG, *CurrentSCC, N,
2116+
AM, UR, FAM);
2117+
return *CurrentSCC;
21142118
}
21152119

21162120
/// Replace a call to llvm.coro.prepare.retcon.
@@ -2199,6 +2203,7 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C,
21992203
if (Coroutines.empty() && PrepareFns.empty())
22002204
return PreservedAnalyses::all();
22012205

2206+
auto *CurrentSCC = &C;
22022207
// Split all the coroutines.
22032208
for (LazyCallGraph::Node *N : Coroutines) {
22042209
Function &F = N->getFunction();
@@ -2210,7 +2215,8 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C,
22102215
coro::Shape Shape =
22112216
splitCoroutine(F, Clones, FAM.getResult<TargetIRAnalysis>(F),
22122217
OptimizeFrame, MaterializableCallback);
2213-
updateCallGraphAfterCoroutineSplit(*N, Shape, Clones, C, CG, AM, UR, FAM);
2218+
CurrentSCC = &updateCallGraphAfterCoroutineSplit(
2219+
*N, Shape, Clones, *CurrentSCC, CG, AM, UR, FAM);
22142220

22152221
auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
22162222
ORE.emit([&]() {
@@ -2222,14 +2228,14 @@ PreservedAnalyses CoroSplitPass::run(LazyCallGraph::SCC &C,
22222228

22232229
if (!Shape.CoroSuspends.empty()) {
22242230
// Run the CGSCC pipeline on the original and newly split functions.
2225-
UR.CWorklist.insert(&C);
2231+
UR.CWorklist.insert(CurrentSCC);
22262232
for (Function *Clone : Clones)
22272233
UR.CWorklist.insert(CG.lookupSCC(CG.get(*Clone)));
22282234
}
22292235
}
22302236

22312237
for (auto *PrepareFn : PrepareFns) {
2232-
replaceAllPrepares(PrepareFn, CG, C);
2238+
replaceAllPrepares(PrepareFn, CG, *CurrentSCC);
22332239
}
22342240

22352241
return PreservedAnalyses::none();

0 commit comments

Comments
 (0)