Skip to content

Commit 624dbfc

Browse files
committed
[Coroutines][New pass manager] Move CoroElide pass to right position
Differential Revision: https://reviews.llvm.org/D75345
1 parent 44d8367 commit 624dbfc

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
// The first coro-split pass enqueues a second run of the entire CGSCC pipeline.
1515
// CHECK: Starting CGSCC pass manager run.
1616
// CHECK: Running pass: CoroSplitPass on (_Z3foov)
17-
// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on (_Z3foov)
17+
// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on {{.*}}_Z3foov{{.*}}
1818
// CHECK: Finished CGSCC pass manager run.
1919
//
2020
// The second coro-split pass splits coroutine 'foo' into funclets
2121
// 'foo.resume', 'foo.destroy', and 'foo.cleanup'.
2222
// CHECK: Starting CGSCC pass manager run.
2323
// CHECK: Running pass: CoroSplitPass on (_Z3foov)
24-
// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on (_Z3foov)
24+
// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on {{.*}}_Z3foov{{.*}}
2525
// CHECK: Finished CGSCC pass manager run.
2626
//
2727
// CHECK: Running pass:{{.*}}CoroCleanupPass

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
561561
EnableMSSALoopDependency, DebugLogging));
562562
}
563563

564+
if (PTO.Coroutines)
565+
FPM.addPass(CoroElidePass());
566+
564567
for (auto &C : ScalarOptimizerLateEPCallbacks)
565568
C(FPM, Level);
566569

@@ -847,10 +850,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
847850

848851
MainCGPipeline.addPass(AttributorCGSCCPass());
849852

850-
if (PTO.Coroutines) {
853+
if (PTO.Coroutines)
851854
MainCGPipeline.addPass(CoroSplitPass());
852-
MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(CoroElidePass()));
853-
}
854855

855856
// Now deduce any function attributes based in the current code.
856857
MainCGPipeline.addPass(PostOrderFunctionAttrsPass());

llvm/test/Transforms/Coroutines/ex2.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ entry:
4040
%hdl = call i8* @f(i32 4)
4141
call void @llvm.coro.resume(i8* %hdl)
4242
call void @llvm.coro.resume(i8* %hdl)
43+
%to = icmp eq i8* %hdl, null
44+
br i1 %to, label %return, label %destroy
45+
destroy:
4346
call void @llvm.coro.destroy(i8* %hdl)
47+
br label %return
48+
return:
4449
ret i32 0
50+
; CHECK-NOT: call i8* @CustomAlloc
4551
; CHECK: call void @print(i32 4)
4652
; CHECK-NEXT: call void @print(i32 5)
4753
; CHECK-NEXT: call void @print(i32 6)

llvm/test/Transforms/Coroutines/ex3.ll

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ define i8* @f(i32 %n) {
66
entry:
77
%id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
88
%size = call i32 @llvm.coro.size.i32()
9+
%need.dyn.alloc = call i1 @llvm.coro.alloc(token %id)
10+
br i1 %need.dyn.alloc, label %dyn.alloc, label %coro.begin
11+
dyn.alloc:
912
%alloc = call i8* @malloc(i32 %size)
10-
%hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %alloc)
13+
br label %coro.begin
14+
coro.begin:
15+
%phi = phi i8* [ null, %entry ], [ %alloc, %dyn.alloc ]
16+
%hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %phi)
1117
br label %loop
1218
loop:
13-
%n.val = phi i32 [ %n, %entry ], [ %inc, %loop.resume ]
19+
%n.val = phi i32 [ %n, %coro.begin ], [ %inc, %loop.resume ]
1420
call void @print(i32 %n.val) #4
1521
%0 = call i8 @llvm.coro.suspend(token none, i1 false)
1622
switch i8 %0, label %suspend [i8 0, label %loop.resume
@@ -37,8 +43,15 @@ entry:
3743
%hdl = call i8* @f(i32 4)
3844
call void @llvm.coro.resume(i8* %hdl)
3945
call void @llvm.coro.resume(i8* %hdl)
46+
%c = ptrtoint i8* %hdl to i64
47+
%to = icmp eq i64 %c, 0
48+
br i1 %to, label %return, label %destroy
49+
destroy:
4050
call void @llvm.coro.destroy(i8* %hdl)
51+
br label %return
52+
return:
4153
ret i32 0
54+
; CHECK-NOT: i8* @malloc
4255
; CHECK: call void @print(i32 4)
4356
; CHECK-NEXT: call void @print(i32 -5)
4457
; CHECK-NEXT: call void @print(i32 5)

0 commit comments

Comments
 (0)