[llvm] 624dbfc - [Coroutines][New pass manager] Move CoroElide pass to right position
Jun Ma via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 1 05:53:39 PST 2020
Author: Jun Ma
Date: 2020-03-01T21:48:24+08:00
New Revision: 624dbfcc1b81520d2211d43a759f817d0b131de0
URL: https://github.com/llvm/llvm-project/commit/624dbfcc1b81520d2211d43a759f817d0b131de0
DIFF: https://github.com/llvm/llvm-project/commit/624dbfcc1b81520d2211d43a759f817d0b131de0.diff
LOG: [Coroutines][New pass manager] Move CoroElide pass to right position
Differential Revision: https://reviews.llvm.org/D75345
Added:
Modified:
clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/test/Transforms/Coroutines/ex2.ll
llvm/test/Transforms/Coroutines/ex3.ll
Removed:
################################################################################
diff --git a/clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp b/clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp
index aed2cf13f892..cea71a1acc6b 100644
--- a/clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp
+++ b/clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp
@@ -14,14 +14,14 @@
// The first coro-split pass enqueues a second run of the entire CGSCC pipeline.
// CHECK: Starting CGSCC pass manager run.
// CHECK: Running pass: CoroSplitPass on (_Z3foov)
-// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on (_Z3foov)
+// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on {{.*}}_Z3foov{{.*}}
// CHECK: Finished CGSCC pass manager run.
//
// The second coro-split pass splits coroutine 'foo' into funclets
// 'foo.resume', 'foo.destroy', and 'foo.cleanup'.
// CHECK: Starting CGSCC pass manager run.
// CHECK: Running pass: CoroSplitPass on (_Z3foov)
-// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on (_Z3foov)
+// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on {{.*}}_Z3foov{{.*}}
// CHECK: Finished CGSCC pass manager run.
//
// CHECK: Running pass:{{.*}}CoroCleanupPass
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index f4806b2db3c8..eb5b3a61fa89 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -561,6 +561,9 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
EnableMSSALoopDependency, DebugLogging));
}
+ if (PTO.Coroutines)
+ FPM.addPass(CoroElidePass());
+
for (auto &C : ScalarOptimizerLateEPCallbacks)
C(FPM, Level);
@@ -847,10 +850,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
MainCGPipeline.addPass(AttributorCGSCCPass());
- if (PTO.Coroutines) {
+ if (PTO.Coroutines)
MainCGPipeline.addPass(CoroSplitPass());
- MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(CoroElidePass()));
- }
// Now deduce any function attributes based in the current code.
MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
diff --git a/llvm/test/Transforms/Coroutines/ex2.ll b/llvm/test/Transforms/Coroutines/ex2.ll
index cd7d8d2a20ed..584bc909a4eb 100644
--- a/llvm/test/Transforms/Coroutines/ex2.ll
+++ b/llvm/test/Transforms/Coroutines/ex2.ll
@@ -40,8 +40,14 @@ entry:
%hdl = call i8* @f(i32 4)
call void @llvm.coro.resume(i8* %hdl)
call void @llvm.coro.resume(i8* %hdl)
+ %to = icmp eq i8* %hdl, null
+ br i1 %to, label %return, label %destroy
+destroy:
call void @llvm.coro.destroy(i8* %hdl)
+ br label %return
+return:
ret i32 0
+; CHECK-NOT: call i8* @CustomAlloc
; CHECK: call void @print(i32 4)
; CHECK-NEXT: call void @print(i32 5)
; CHECK-NEXT: call void @print(i32 6)
diff --git a/llvm/test/Transforms/Coroutines/ex3.ll b/llvm/test/Transforms/Coroutines/ex3.ll
index 50ce19e26372..85cf53fb576d 100644
--- a/llvm/test/Transforms/Coroutines/ex3.ll
+++ b/llvm/test/Transforms/Coroutines/ex3.ll
@@ -6,11 +6,17 @@ define i8* @f(i32 %n) {
entry:
%id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
%size = call i32 @llvm.coro.size.i32()
+ %need.dyn.alloc = call i1 @llvm.coro.alloc(token %id)
+ br i1 %need.dyn.alloc, label %dyn.alloc, label %coro.begin
+dyn.alloc:
%alloc = call i8* @malloc(i32 %size)
- %hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %alloc)
+ br label %coro.begin
+coro.begin:
+ %phi = phi i8* [ null, %entry ], [ %alloc, %dyn.alloc ]
+ %hdl = call noalias i8* @llvm.coro.begin(token %id, i8* %phi)
br label %loop
loop:
- %n.val = phi i32 [ %n, %entry ], [ %inc, %loop.resume ]
+ %n.val = phi i32 [ %n, %coro.begin ], [ %inc, %loop.resume ]
call void @print(i32 %n.val) #4
%0 = call i8 @llvm.coro.suspend(token none, i1 false)
switch i8 %0, label %suspend [i8 0, label %loop.resume
@@ -37,8 +43,15 @@ entry:
%hdl = call i8* @f(i32 4)
call void @llvm.coro.resume(i8* %hdl)
call void @llvm.coro.resume(i8* %hdl)
+ %c = ptrtoint i8* %hdl to i64
+ %to = icmp eq i64 %c, 0
+ br i1 %to, label %return, label %destroy
+destroy:
call void @llvm.coro.destroy(i8* %hdl)
+ br label %return
+return:
ret i32 0
+; CHECK-NOT: i8* @malloc
; CHECK: call void @print(i32 4)
; CHECK-NEXT: call void @print(i32 -5)
; CHECK-NEXT: call void @print(i32 5)
More information about the llvm-commits
mailing list