1 ; Tests that coro-split removes cleanup code after coro.end in resume functions
2 ; and retains it in the start function.
3 ; RUN: opt < %s -coro-split -S | FileCheck %s
5 define i8* @f(i1 %val) "coroutine.presplit"="1" personality i32 3 {
7 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
8 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
9 call void @print(i32 0)
10 br i1 %val, label %resume, label %susp
13 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
14 switch i8 %0, label %suspend [i8 0, label %resume
17 invoke void @print(i32 1) to label %suspend unwind label %lpad
20 call i1 @llvm.coro.end(i8* %hdl, i1 0)
21 call void @print(i32 0) ; should not be present in f.resume
25 %lpval = landingpad { i8*, i32 }
28 call void @print(i32 2)
29 %need.resume = call i1 @llvm.coro.end(i8* null, i1 true)
30 br i1 %need.resume, label %eh.resume, label %cleanup.cont
33 call void @print(i32 3) ; should not be present in f.resume
37 resume { i8*, i32 } %lpval
40 ; Verify that start function contains both print calls the one before and after coro.end
41 ; CHECK-LABEL: define i8* @f(
42 ; CHECK: invoke void @print(i32 1)
43 ; CHECK: to label %AfterCoroEnd unwind label %lpad
45 ; CHECK: AfterCoroEnd:
46 ; CHECK: call void @print(i32 0)
50 ; CHECK-NEXT: %lpval = landingpad { i8*, i32 }
52 ; CHECK-NEXT: call void @print(i32 2)
53 ; CHECK-NEXT: call void @print(i32 3)
54 ; CHECK-NEXT: resume { i8*, i32 } %lpval
56 define i8* @f2(i1 %val) "coroutine.presplit"="1" personality i32 4 {
58 %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
59 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
60 call void @print(i32 0)
61 br i1 %val, label %resume, label %susp
64 %0 = call i8 @llvm.coro.suspend(token none, i1 false)
65 switch i8 %0, label %suspend [i8 0, label %resume
68 invoke void @print(i32 1) to label %suspend unwind label %lpad
71 call i1 @llvm.coro.end(i8* %hdl, i1 0)
72 call void @print(i32 0) ; should not be present in f.resume
76 %tok = cleanuppad within none []
77 call void @print(i32 2)
78 %unused = call i1 @llvm.coro.end(i8* null, i1 true) [ "funclet"(token %tok) ]
79 cleanupret from %tok unwind label %cleanup.cont
82 %tok2 = cleanuppad within none []
83 call void @print(i32 3) ; should not be present in f.resume
84 cleanupret from %tok2 unwind to caller
87 ; Verify that start function contains both print calls the one before and after coro.end
88 ; CHECK-LABEL: define i8* @f2(
89 ; CHECK: invoke void @print(i32 1)
90 ; CHECK: to label %AfterCoroEnd unwind label %lpad
92 ; CHECK: AfterCoroEnd:
93 ; CHECK: call void @print(i32 0)
97 ; CHECK-NEXT: %tok = cleanuppad within none []
98 ; CHECK-NEXT: call void @print(i32 2)
99 ; CHECK-NEXT: call void @print(i32 3)
100 ; CHECK-NEXT: cleanupret from %tok unwind to caller
102 ; VERIFY Resume Parts
104 ; Verify that resume function does not contains both print calls appearing after coro.end
105 ; CHECK-LABEL: define internal fastcc void @f.resume
106 ; CHECK: invoke void @print(i32 1)
107 ; CHECK: to label %CoroEnd unwind label %lpad
110 ; CHECK-NEXT: ret void
113 ; CHECK-NEXT: %lpval = landingpad { i8*, i32 }
114 ; CHECK-NEXT: cleanup
115 ; CHECK-NEXT: call void @print(i32 2)
116 ; CHECK-NEXT: resume { i8*, i32 } %lpval
118 ; Verify that resume function does not contains both print calls appearing after coro.end
119 ; CHECK-LABEL: define internal fastcc void @f2.resume
120 ; CHECK: invoke void @print(i32 1)
121 ; CHECK: to label %CoroEnd unwind label %lpad
124 ; CHECK-NEXT: ret void
127 ; CHECK-NEXT: %tok = cleanuppad within none []
128 ; CHECK-NEXT: call void @print(i32 2)
129 ; CHECK-NEXT: cleanupret from %tok unwind to caller
131 declare i8* @llvm.coro.free(token, i8*)
132 declare i32 @llvm.coro.size.i32()
133 declare i8 @llvm.coro.suspend(token, i1)
134 declare void @llvm.coro.resume(i8*)
135 declare void @llvm.coro.destroy(i8*)
137 declare token @llvm.coro.id(i32, i8*, i8*, i8*)
138 declare i8* @llvm.coro.alloc(token)
139 declare i8* @llvm.coro.begin(token, i8*)
140 declare i1 @llvm.coro.end(i8*, i1)
142 declare noalias i8* @malloc(i32)
143 declare void @print(i32)
144 declare void @free(i8*)