145 lines · plain
1; Tests that the number elided coroutine is record correctly.2; REQUIRES: asserts3;4; RUN: opt < %s -S \5; RUN: -passes='cgscc(inline,function(coro-elide,dce),inline,function(coro-elide,dce))' -stats 2>&1 \6; RUN: | FileCheck %s7; RUN: opt < %s --disable-output \8; RUN: -passes='cgscc(inline,function(coro-elide,dce),inline,function(coro-elide,dce))' \9; RUN: -coro-elide-info-output-file=%t && \10; RUN: cat %t \11; RUN: | FileCheck %s --check-prefix=FILE12 13; CHECK: 2 coro-elide - The # of coroutine get elided.14; FILE: Elide f in callResume15; FILE: Elide f in callResumeMultiRetDommmed16 17declare void @print(i32) nounwind18 19; resume part of the coroutine20define fastcc void @f.resume(ptr dereferenceable(1)) {21 tail call void @print(i32 0)22 ret void23}24 25; destroy part of the coroutine26define fastcc void @f.destroy(ptr) {27 tail call void @print(i32 1)28 ret void29}30 31; cleanup part of the coroutine32define fastcc void @f.cleanup(ptr) {33 tail call void @print(i32 2)34 ret void35}36 37@f.resumers = internal constant [3 x ptr] [ptr @f.resume,38 ptr @f.destroy,39 ptr @f.cleanup]40 41; a coroutine start function42define ptr @f() {43entry:44 %id = call token @llvm.coro.id(i32 0, ptr null,45 ptr @f,46 ptr @f.resumers)47 %alloc = call i1 @llvm.coro.alloc(token %id)48 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)49 ret ptr %hdl50}51 52define void @callResume() {53entry:54 %hdl = call ptr @f()55 56 %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)57 call fastcc void %0(ptr %hdl)58 59 %1 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)60 call fastcc void %1(ptr %hdl)61 62 ret void63}64 65define void @callResumeMultiRet(i1 %b) {66entry:67 %hdl = call ptr @f()68 %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)69 call fastcc void %0(ptr %hdl)70 br i1 %b, label %destroy, label %ret71 72destroy:73 %1 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)74 call fastcc void %1(ptr %hdl)75 ret void76 77ret:78 ret void79}80 81define void @callResumeMultiRetDommmed(i1 %b) {82entry:83 %hdl = call ptr @f()84 %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)85 call fastcc void %0(ptr %hdl)86 %1 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)87 call fastcc void %1(ptr %hdl)88 br i1 %b, label %destroy, label %ret89 90destroy:91 ret void92 93ret:94 ret void95}96 97define void @eh() personality ptr null {98entry:99 %hdl = call ptr @f()100 101 %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)102 invoke void %0(ptr %hdl)103 to label %cont unwind label %ehcleanup104cont:105 ret void106 107ehcleanup:108 %tok = cleanuppad within none []109 cleanupret from %tok unwind to caller110}111 112; no devirtualization here, since coro.begin info parameter is null113define void @no_devirt_info_null() {114entry:115 %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)116 %hdl = call ptr @llvm.coro.begin(token %id, ptr null)117 118 %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)119 call fastcc void %0(ptr %hdl)120 121 %1 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)122 call fastcc void %1(ptr %hdl)123 124 ret void125}126 127; no devirtualization here, since coro.begin is not visible128define void @no_devirt_no_begin(ptr %hdl) {129entry:130 131 %0 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 0)132 call fastcc void %0(ptr %hdl)133 134 %1 = call ptr @llvm.coro.subfn.addr(ptr %hdl, i8 1)135 call fastcc void %1(ptr %hdl)136 137 ret void138}139 140declare token @llvm.coro.id(i32, ptr, ptr, ptr)141declare ptr @llvm.coro.begin(token, ptr)142declare ptr @llvm.coro.frame()143declare ptr @llvm.coro.subfn.addr(ptr, i8)144declare i1 @llvm.coro.alloc(token)145