[PATCH] D75345: [Coroutines][new pass manager] Move CoroElide pass to right position
JunMa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 28 05:28:13 PST 2020
junparser created this revision.
junparser added reviewers: modocache, wenlei.
Herald added subscribers: llvm-commits, hiraditya, EricWF.
Herald added a project: LLVM.
When test coroutines under new pass manager, we find that it is less powerful than legacy in coroutine frame elision.
That's because CoroElide executed right after CoroSplit instead of after series of optimization passes.
This patch move CoroElide same position as legacy
TestPlan: check-llvm, cppcoro
https://reviews.llvm.org/D75345
Files:
llvm/lib/Passes/PassBuilder.cpp
llvm/test/Transforms/Coroutines/ex2.ll
llvm/test/Transforms/Coroutines/ex3.ll
Index: llvm/test/Transforms/Coroutines/ex3.ll
===================================================================
--- llvm/test/Transforms/Coroutines/ex3.ll
+++ llvm/test/Transforms/Coroutines/ex3.ll
@@ -6,11 +6,17 @@
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 @@
%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)
Index: llvm/test/Transforms/Coroutines/ex2.ll
===================================================================
--- llvm/test/Transforms/Coroutines/ex2.ll
+++ llvm/test/Transforms/Coroutines/ex2.ll
@@ -40,8 +40,14 @@
%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)
Index: llvm/lib/Passes/PassBuilder.cpp
===================================================================
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -561,6 +561,9 @@
EnableMSSALoopDependency, DebugLogging));
}
+ if (PTO.Coroutines)
+ FPM.addPass(CoroElidePass());
+
for (auto &C : ScalarOptimizerLateEPCallbacks)
C(FPM, Level);
@@ -847,10 +850,8 @@
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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75345.247236.patch
Type: text/x-patch
Size: 2933 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200228/5dd7fbb6/attachment.bin>
More information about the llvm-commits
mailing list