Skip to content

Commit 405bf90

Browse files
committed
[NFC] [Pipelines] Hoist CoroCleanup as Module Pass
This is similar to previous patch https://reviews.llvm.org/D123925. It could also reduce the time we call declaresCoroCleanupIntrinsics. And it is helpful for further changes. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D124362
1 parent 7d40f56 commit 405bf90

File tree

5 files changed

+17
-22
lines changed

5 files changed

+17
-22
lines changed

llvm/include/llvm/Transforms/Coroutines/CoroCleanup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
namespace llvm {
2020

21-
class Function;
21+
class Module;
2222

2323
struct CoroCleanupPass : PassInfoMixin<CoroCleanupPass> {
24-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
24+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
2525
static bool isRequired() { return true; }
2626
};
2727
} // end namespace llvm

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
989989
else
990990
MPM.addPass(buildInlinerPipeline(Level, Phase));
991991

992-
MPM.addPass(createModuleToFunctionPassAdaptor(CoroCleanupPass()));
992+
MPM.addPass(CoroCleanupPass());
993993

994994
if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
995995
MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
@@ -1836,7 +1836,7 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
18361836
CGSCCPassManager CGPM;
18371837
CGPM.addPass(CoroSplitPass());
18381838
CoroPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
1839-
CoroPM.addPass(createModuleToFunctionPassAdaptor(CoroCleanupPass()));
1839+
CoroPM.addPass(CoroCleanupPass());
18401840
CoroPM.addPass(GlobalDCEPass());
18411841
MPM.addPass(CoroConditionalWrapper(std::move(CoroPM)));
18421842

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ MODULE_PASS("cg-profile", CGProfilePass())
5151
MODULE_PASS("check-debugify", NewPMCheckDebugifyPass())
5252
MODULE_PASS("constmerge", ConstantMergePass())
5353
MODULE_PASS("coro-early", CoroEarlyPass())
54+
MODULE_PASS("coro-cleanup", CoroCleanupPass())
5455
MODULE_PASS("cross-dso-cfi", CrossDSOCFIPass())
5556
MODULE_PASS("deadargelim", DeadArgumentEliminationPass())
5657
MODULE_PASS("debugify", NewPMDebugifyPass())
@@ -253,7 +254,6 @@ FUNCTION_PASS("consthoist", ConstantHoistingPass())
253254
FUNCTION_PASS("constraint-elimination", ConstraintEliminationPass())
254255
FUNCTION_PASS("chr", ControlHeightReductionPass())
255256
FUNCTION_PASS("coro-elide", CoroElidePass())
256-
FUNCTION_PASS("coro-cleanup", CoroCleanupPass())
257257
FUNCTION_PASS("correlated-propagation", CorrelatedValuePropagationPass())
258258
FUNCTION_PASS("dce", DCEPass())
259259
FUNCTION_PASS("dfa-jump-threading", DFAJumpThreadingPass())

llvm/lib/Transforms/Coroutines/CoroCleanup.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace {
2323
struct Lowerer : coro::LowererBase {
2424
IRBuilder<> Builder;
2525
Lowerer(Module &M) : LowererBase(M), Builder(Context) {}
26-
bool lowerRemainingCoroIntrinsics(Function &F);
26+
void lower(Function &F);
2727
};
2828
}
2929

@@ -53,9 +53,7 @@ static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn) {
5353
SubFn->replaceAllUsesWith(Load);
5454
}
5555

56-
bool Lowerer::lowerRemainingCoroIntrinsics(Function &F) {
57-
bool Changed = false;
58-
56+
void Lowerer::lower(Function &F) {
5957
bool IsPrivateAndUnprocessed =
6058
F.hasFnAttribute(CORO_PRESPLIT_ATTR) && F.hasLocalLinkage();
6159

@@ -112,16 +110,11 @@ bool Lowerer::lowerRemainingCoroIntrinsics(Function &F) {
112110
break;
113111
}
114112
II->eraseFromParent();
115-
Changed = true;
116113
}
117114
}
118115

119-
if (Changed) {
120-
// After replacement were made we can cleanup the function body a little.
121-
simplifyCFG(F);
122-
}
123-
124-
return Changed;
116+
// After replacement were made we can cleanup the function body a little.
117+
simplifyCFG(F);
125118
}
126119

127120
static bool declaresCoroCleanupIntrinsics(const Module &M) {
@@ -132,12 +125,14 @@ static bool declaresCoroCleanupIntrinsics(const Module &M) {
132125
"llvm.coro.async.resume"});
133126
}
134127

135-
PreservedAnalyses CoroCleanupPass::run(Function &F,
136-
FunctionAnalysisManager &AM) {
137-
auto &M = *F.getParent();
138-
if (!declaresCoroCleanupIntrinsics(M) ||
139-
!Lowerer(M).lowerRemainingCoroIntrinsics(F))
128+
PreservedAnalyses CoroCleanupPass::run(Module &M,
129+
ModuleAnalysisManager &MAM) {
130+
if (!declaresCoroCleanupIntrinsics(M))
140131
return PreservedAnalyses::all();
141132

133+
Lowerer L(M);
134+
for (auto &F : M)
135+
L.lower(F);
136+
142137
return PreservedAnalyses::none();
143138
}

llvm/test/Transforms/Coroutines/smoketest.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
; RUN: opt < %s -disable-output -passes='default<O3>' \
1111
; RUN: -debug-pass-manager 2>&1 | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-OPT
1212
; RUN: opt < %s -disable-output -debug-pass-manager \
13-
; RUN: -passes='module(coro-early),function(coro-elide),cgscc(coro-split),function(coro-cleanup)' 2>&1 \
13+
; RUN: -passes='module(coro-early),function(coro-elide),cgscc(coro-split),module(coro-cleanup)' 2>&1 \
1414
; RUN: | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-OPT
1515

1616
; note that we run CoroElidePass before CoroSplitPass. This is because CoroElidePass is part of

0 commit comments

Comments
 (0)