Skip to content

Commit 31897e6

Browse files
authored
[LTO][Pipelines][Coro] De-duplicate Coro passes (#128654)
``` if (!isLTOPostLink(Phase)) CoroPM.addPass(CoroEarlyPass()); if (!isLTOPreLink(Phase)) // Other Coro passes ``` Followup to #126168.
1 parent 8fc8a84 commit 31897e6

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

Diff for: llvm/lib/Passes/PassBuilderPipelines.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -419,14 +419,16 @@ static bool isLTOPostLink(ThinOrFullLTOPhase Phase) {
419419

420420
// Helper to wrap conditionally Coro passes.
421421
static CoroConditionalWrapper buildCoroWrapper(ThinOrFullLTOPhase Phase) {
422-
// TODO: Skip passes according to Phase.
423422
ModulePassManager CoroPM;
424-
CoroPM.addPass(CoroEarlyPass());
425-
CGSCCPassManager CGPM;
426-
CGPM.addPass(CoroSplitPass());
427-
CoroPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
428-
CoroPM.addPass(CoroCleanupPass());
429-
CoroPM.addPass(GlobalDCEPass());
423+
if (!isLTOPostLink(Phase))
424+
CoroPM.addPass(CoroEarlyPass());
425+
if (!isLTOPreLink(Phase)) {
426+
CGSCCPassManager CGPM;
427+
CGPM.addPass(CoroSplitPass());
428+
CoroPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
429+
CoroPM.addPass(CoroCleanupPass());
430+
CoroPM.addPass(GlobalDCEPass());
431+
}
430432
return CoroConditionalWrapper(std::move(CoroPM));
431433
}
432434

@@ -1010,7 +1012,7 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
10101012
MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(
10111013
RequireAnalysisPass<ShouldNotRunFunctionPassesAnalysis, Function>()));
10121014

1013-
if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
1015+
if (!isLTOPreLink(Phase)) {
10141016
MainCGPipeline.addPass(CoroSplitPass(Level != OptimizationLevel::O0));
10151017
MainCGPipeline.addPass(CoroAnnotationElidePass());
10161018
}
@@ -1060,7 +1062,7 @@ PassBuilder::buildModuleInlinerPipeline(OptimizationLevel Level,
10601062
buildFunctionSimplificationPipeline(Level, Phase),
10611063
PTO.EagerlyInvalidateAnalyses));
10621064

1063-
if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
1065+
if (!isLTOPreLink(Phase)) {
10641066
MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(
10651067
CoroSplitPass(Level != OptimizationLevel::O0)));
10661068
MPM.addPass(
@@ -1120,7 +1122,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11201122
// Do basic inference of function attributes from known properties of system
11211123
// libraries and other oracles.
11221124
MPM.addPass(InferFunctionAttrsPass());
1123-
MPM.addPass(CoroEarlyPass());
1125+
if (!isLTOPostLink(Phase))
1126+
MPM.addPass(CoroEarlyPass());
11241127

11251128
FunctionPassManager EarlyFPM;
11261129
EarlyFPM.addPass(EntryExitInstrumenterPass(/*PostInlining=*/false));
@@ -1283,7 +1286,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
12831286
// and argument promotion.
12841287
MPM.addPass(DeadArgumentEliminationPass());
12851288

1286-
if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
1289+
if (!isLTOPreLink(Phase))
12871290
MPM.addPass(CoroCleanupPass());
12881291

12891292
// Optimize globals now that functions are fully simplified.
@@ -1948,9 +1951,6 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
19481951
return MPM;
19491952
}
19501953

1951-
// TODO: Skip to match buildCoroWrapper.
1952-
MPM.addPass(CoroEarlyPass());
1953-
19541954
// Optimize globals to try and fold them into constants.
19551955
MPM.addPass(GlobalOptPass());
19561956

Diff for: llvm/test/LTO/X86/coro.ll

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
; RUN: llvm-as %s -o %t1.bc
1+
; RUN: opt %s -passes='lto-pre-link<O0>' -S -o %t1.ll
2+
; RUN: FileCheck %s --check-prefixes=CHECK,PRELINK --implicit-check-not="call void @llvm.coro" --input-file=%t1.ll
3+
; RUN: llvm-as %t1.ll -o %t1.bc
24
; RUN: llvm-lto2 run %t1.bc -o %t2.o -r=%t1.bc,test,plx -r=%t1.bc,extern_func,plx -save-temps
35
; RUN: llvm-dis %t2.o.0.5.precodegen.bc -o - | FileCheck %s --implicit-check-not="call void @llvm.coro"
46

@@ -7,7 +9,9 @@ target triple = "x86_64-unknown-fuchsia"
79

810
declare void @extern_func()
911

10-
; CHECK: define {{.*}} void @test(
12+
; CHECK: define{{.*}} void @test(
13+
; PRELINK: call ptr @llvm.coro.subfn.addr
14+
; PRELINK: call ptr @llvm.coro.subfn.addr
1115
define void @test(ptr %hdl) {
1216
call void @llvm.coro.resume(ptr %hdl)
1317
call void @llvm.coro.destroy(ptr %hdl)

Diff for: llvm/test/Other/new-pm-defaults.ll

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,13 @@
230230
; CHECK-O-NEXT: Running pass: PostOrderFunctionAttrsPass
231231
; CHECK-O-NEXT: Running pass: RequireAnalysisPass<{{.*}}ShouldNotRunFunctionPassesAnalysis
232232
; CHECK-O-NEXT: Running analysis: ShouldNotRunFunctionPassesAnalysis
233-
; CHECK-O-NEXT: Running pass: CoroSplitPass
234-
; CHECK-O-NEXT: Running pass: CoroAnnotationElidePass
233+
; CHECK-DEFAULT-NEXT: Running pass: CoroSplitPass
234+
; CHECK-DEFAULT-NEXT: Running pass: CoroAnnotationElidePass
235235
; CHECK-O-NEXT: Running pass: InvalidateAnalysisPass<{{.*}}ShouldNotRunFunctionPassesAnalysis
236236
; CHECK-O-NEXT: Invalidating analysis: ShouldNotRunFunctionPassesAnalysis
237237
; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
238238
; CHECK-O-NEXT: Running pass: DeadArgumentEliminationPass
239-
; CHECK-O-NEXT: Running pass: CoroCleanupPass
239+
; CHECK-DEFAULT-NEXT: Running pass: CoroCleanupPass
240240
; CHECK-O-NEXT: Running pass: GlobalOptPass
241241
; CHECK-O-NEXT: Running pass: GlobalDCEPass
242242
; CHECK-DEFAULT-NEXT: Running pass: EliminateAvailableExternallyPass

Diff for: llvm/test/Other/new-pm-lto-defaults.ll

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
; CHECK-O1-NEXT: Running analysis: TargetLibraryAnalysis
6868
; CHECK-O-NEXT: Running pass: GlobalSplitPass
6969
; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass
70-
; CHECK-O23SZ-NEXT: Running pass: CoroEarlyPass
7170
; CHECK-O1-NEXT: Running pass: LowerTypeTestsPass
7271
; CHECK-O23SZ-NEXT: Running pass: GlobalOptPass
7372
; CHECK-O23SZ-NEXT: Running pass: PromotePass

0 commit comments

Comments
 (0)