Skip to content

Commit f9bee35

Browse files
committed
[Pipelines] Hoist CoroEarly as a module pass
This change could reduce the time we call `declaresCoroEarlyIntrinsics`. And it is helpful for future changes. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D123925
1 parent 2d92ee9 commit f9bee35

19 files changed

+30
-24
lines changed

llvm/include/llvm/Transforms/Coroutines/CoroEarly.h

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

2222
namespace llvm {
2323

24-
class Function;
24+
class Module;
2525

2626
struct CoroEarlyPass : PassInfoMixin<CoroEarlyPass> {
27-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
27+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
2828
static bool isRequired() { return true; }
2929
};
3030
} // end namespace llvm

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
853853
// Do basic inference of function attributes from known properties of system
854854
// libraries and other oracles.
855855
MPM.addPass(InferFunctionAttrsPass());
856+
MPM.addPass(CoroEarlyPass());
856857

857858
// Create an early function pass manager to cleanup the output of the
858859
// frontend.
@@ -863,7 +864,6 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
863864
EarlyFPM.addPass(SimplifyCFGPass());
864865
EarlyFPM.addPass(SROAPass());
865866
EarlyFPM.addPass(EarlyCSEPass());
866-
EarlyFPM.addPass(CoroEarlyPass());
867867
if (Level == OptimizationLevel::O3)
868868
EarlyFPM.addPass(CallSiteSplittingPass());
869869

@@ -1825,7 +1825,7 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
18251825
}
18261826

18271827
ModulePassManager CoroPM;
1828-
CoroPM.addPass(createModuleToFunctionPassAdaptor(CoroEarlyPass()));
1828+
CoroPM.addPass(CoroEarlyPass());
18291829
CGSCCPassManager CGPM;
18301830
CGPM.addPass(CoroSplitPass());
18311831
CoroPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ MODULE_PASS("canonicalize-aliases", CanonicalizeAliasesPass())
5050
MODULE_PASS("cg-profile", CGProfilePass())
5151
MODULE_PASS("check-debugify", NewPMCheckDebugifyPass())
5252
MODULE_PASS("constmerge", ConstantMergePass())
53+
MODULE_PASS("coro-early", CoroEarlyPass())
5354
MODULE_PASS("cross-dso-cfi", CrossDSOCFIPass())
5455
MODULE_PASS("deadargelim", DeadArgumentEliminationPass())
5556
MODULE_PASS("debugify", NewPMDebugifyPass())
@@ -251,7 +252,6 @@ FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass())
251252
FUNCTION_PASS("consthoist", ConstantHoistingPass())
252253
FUNCTION_PASS("constraint-elimination", ConstraintEliminationPass())
253254
FUNCTION_PASS("chr", ControlHeightReductionPass())
254-
FUNCTION_PASS("coro-early", CoroEarlyPass())
255255
FUNCTION_PASS("coro-elide", CoroElidePass())
256256
FUNCTION_PASS("coro-cleanup", CoroCleanupPass())
257257
FUNCTION_PASS("correlated-propagation", CorrelatedValuePropagationPass())

llvm/lib/Transforms/Coroutines/CoroEarly.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,15 @@ static bool declaresCoroEarlyIntrinsics(const Module &M) {
238238
"llvm.coro.suspend"});
239239
}
240240

241-
PreservedAnalyses CoroEarlyPass::run(Function &F, FunctionAnalysisManager &) {
242-
Module &M = *F.getParent();
243-
if (!declaresCoroEarlyIntrinsics(M) || !Lowerer(M).lowerEarlyIntrinsics(F))
241+
PreservedAnalyses CoroEarlyPass::run(Module &M, ModuleAnalysisManager &) {
242+
if (!declaresCoroEarlyIntrinsics(M))
243+
return PreservedAnalyses::all();
244+
245+
Lowerer L(M);
246+
bool Changed = false;
247+
for (auto &F : M)
248+
Changed |= L.lowerEarlyIntrinsics(F);
249+
if (Changed)
244250
return PreservedAnalyses::all();
245251

246252
PreservedAnalyses PA;

llvm/test/Other/new-pm-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
9797
; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
9898
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
99+
; CHECK-O-NEXT: Running pass: CoroEarlyPass
99100
; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
100101
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
101102
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
@@ -104,7 +105,6 @@
104105
; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
105106
; CHECK-O-NEXT: Running pass: EarlyCSEPass
106107
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
107-
; CHECK-O-NEXT: Running pass: CoroEarlyPass
108108
; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
109109
; CHECK-O-NEXT: Running pass: OpenMPOptPass
110110
; CHECK-EP-PIPELINE-EARLY-SIMPLIFICATION-NEXT: Running pass: NoOpModulePass

llvm/test/Other/new-pm-thinlto-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
6363
; CHECK-PRELINK-O-NODIS-NEXT: Running analysis: InnerAnalysisManagerProxy
6464
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
65+
; CHECK-O-NEXT: Running pass: CoroEarlyPass
6566
; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
6667
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
6768
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
@@ -70,7 +71,6 @@
7071
; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
7172
; CHECK-O-NEXT: Running pass: EarlyCSEPass
7273
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
73-
; CHECK-O-NEXT: Running pass: CoroEarlyPass
7474
; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
7575
; CHECK-O-NEXT: Running pass: OpenMPOptPass
7676
; CHECK-POSTLINK-O-NEXT: Running pass: LowerTypeTestsPass

llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis
3333
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
3434
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
35+
; CHECK-O-NEXT: Running pass: CoroEarlyPass
3536
; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
3637
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
3738
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
@@ -40,7 +41,6 @@
4041
; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
4142
; CHECK-O-NEXT: Running pass: EarlyCSEPass
4243
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
43-
; CHECK-O-NEXT: Running pass: CoroEarlyPass
4444
; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
4545
; CHECK-O-NEXT: Running pass: OpenMPOptPass
4646
; CHECK-O-NEXT: Running pass: LowerTypeTestsPass

llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
3535
; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
3636
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
37+
; CHECK-O-NEXT: Running pass: CoroEarlyPass
3738
; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
3839
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
3940
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
@@ -42,7 +43,6 @@
4243
; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
4344
; CHECK-O-NEXT: Running pass: EarlyCSEPass
4445
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
45-
; CHECK-O-NEXT: Running pass: CoroEarlyPass
4646
; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
4747
; CHECK-O-NEXT: Running pass: InstCombinePass on foo
4848
; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on foo

llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
3434
; CHECK-O-NEXT: Running analysis: InnerAnalysisManagerProxy
3535
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
36+
; CHECK-O-NEXT: Running pass: CoroEarlyPass
3637
; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
3738
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
3839
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
@@ -41,7 +42,6 @@
4142
; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
4243
; CHECK-O-NEXT: Running pass: EarlyCSEPass
4344
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
44-
; CHECK-O-NEXT: Running pass: CoroEarlyPass
4545
; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
4646
; CHECK-O-NEXT: Running pass: OpenMPOptPass
4747
; CHECK-O-NEXT: Running pass: IPSCCPPass

llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
; CHECK-EP-PIPELINE-START-NEXT: Running pass: NoOpModulePass
3333
; CHECK-O-NEXT: Running pass: InferFunctionAttrsPass
3434
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
35+
; CHECK-O-NEXT: Running pass: CoroEarlyPass
3536
; CHECK-O-NEXT: Running pass: LowerExpectIntrinsicPass
3637
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
3738
; CHECK-O-NEXT: Running analysis: TargetIRAnalysis
@@ -40,7 +41,6 @@
4041
; CHECK-O-NEXT: Running analysis: DominatorTreeAnalysis
4142
; CHECK-O-NEXT: Running pass: EarlyCSEPass
4243
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis
43-
; CHECK-O-NEXT: Running pass: CoroEarlyPass
4444
; CHECK-O3-NEXT: Running pass: CallSiteSplittingPass
4545
; CHECK-O-NEXT: Running pass: InstCombinePass on foo
4646
; CHECK-O-NEXT: Running analysis: OptimizationRemarkEmitterAnalysis on foo

llvm/test/Transforms/Coroutines/coro-debug-O2.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split,coro-split),function(sroa)' --reuse-storage-in-coroutine-frame -S | FileCheck %s
1+
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split),function(sroa)' --reuse-storage-in-coroutine-frame -S | FileCheck %s
22

33
; Checks whether the dbg.declare for `__promise` remains valid under O2.
44

llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
1+
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
22

33
; Checks whether the dbg.declare for `__coro_frame` are created.
44

llvm/test/Transforms/Coroutines/coro-debug-dbg.addr-swift.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
; create the debug_value for us, make sure that we propagate llvm.dbg.addr into
66
; the beginning coroutine and all other funclets.
77

8-
; RUN: opt %s -passes='function(coro-early),cgscc(coro-split,simplifycfg)' -S | FileCheck %s
8+
; RUN: opt %s -passes='module(coro-early),cgscc(coro-split,simplifycfg)' -S | FileCheck %s
99

1010
; CHECK-LABEL: define swifttailcc void @"$s10async_args14withGenericArgyyxnYalF"(%swift.context* swiftasync %0, %swift.opaque* noalias %1, %swift.type* %T){{.*}} {
1111
; CHECK: call void @llvm.dbg.declare(metadata %swift.context** [[CORO_CTX:%[a-z0-9\.]+]],

llvm/test/Transforms/Coroutines/coro-debug-dbg.addr.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
; create the debug_value for us, make sure that we propagate llvm.dbg.addr into
66
; the beginning coroutine and all other funclets.
77

8-
; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
8+
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
99

1010
; This file is based on coro-debug-frame-variable.ll.
1111
; CHECK: define internal fastcc void @f.resume(%f.Frame* noalias nonnull align 16 dereferenceable(80) %FramePtr) !dbg ![[RESUME_FN_DBG_NUM:[0-9]+]]

llvm/test/Transforms/Coroutines/coro-debug-dbg.values-not_used_in_frame.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; Tests whether resume function would remain dbg.value infomation if corresponding values are not used in the frame.
2-
; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
2+
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
33
;
44
; This file is based on coro-debug-frame-variable.ll.
55
; CHECK: define internal fastcc void @f.resume(%f.Frame* noalias nonnull align 16 dereferenceable(80) %FramePtr) !dbg ![[RESUME_FN_DBG_NUM:[0-9]+]]

llvm/test/Transforms/Coroutines/coro-debug-dbg.values.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; Tests whether resume function would remain dbg.value infomation.
2-
; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
2+
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split,coro-split)' -S | FileCheck %s
33
;
44
; This file is based on coro-debug-frame-variable.ll.
55
; CHECK: define internal fastcc void @f.resume(%f.Frame* noalias nonnull align 16 dereferenceable(80) %FramePtr) !dbg ![[RESUME_FN_DBG_NUM:[0-9]+]]

llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split),function(simplifycfg,early-cse)' -S | FileCheck %s
2+
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split),function(simplifycfg,early-cse)' -S | FileCheck %s
33
target datalayout = "E-p:64:64"
44

55
%swift.type = type { i64 }

llvm/test/Transforms/Coroutines/coro-split-recursive.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: opt -passes='function(coro-early),cgscc(coro-split)' -opaque-pointers=0 -S < %s | FileCheck %s
2-
; RUN: opt -passes='function(coro-early),cgscc(coro-split)' -opaque-pointers=1 -S < %s | FileCheck %s
1+
; RUN: opt -passes='module(coro-early),cgscc(coro-split)' -opaque-pointers=0 -S < %s | FileCheck %s
2+
; RUN: opt -passes='module(coro-early),cgscc(coro-split)' -opaque-pointers=1 -S < %s | FileCheck %s
33

44
declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*)
55

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>' -enable-coroutines \
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='function(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),function(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)