xref: /llvm-project/llvm/test/Transforms/Coroutines/coro-split-eh-01.ll (revision 51d5d7bbae92493a5bfa7cc6b519de8a5bb32fdb)
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 -passes='cgscc(coro-split),simplifycfg,early-cse' -S | FileCheck %s
4
5define ptr @f2(i1 %val) presplitcoroutine personality i32 4 {
6entry:
7  %id = call token @llvm.coro.id(i32 0, ptr null, ptr null, ptr null)
8  %hdl = call ptr @llvm.coro.begin(token %id, ptr null)
9  call void @print(i32 0)
10  br i1 %val, label %resume, label %susp
11
12susp:
13  %0 = call i8 @llvm.coro.suspend(token none, i1 false)
14  switch i8 %0, label %suspend [i8 0, label %resume
15                                i8 1, label %suspend]
16resume:
17  invoke void @print(i32 1) to label %suspend unwind label %lpad
18
19suspend:
20  call i1 @llvm.coro.end(ptr %hdl, i1 0, token none)
21  call void @print(i32 0) ; should not be present in f.resume
22  ret ptr %hdl
23
24lpad:
25  %tok = cleanuppad within none []
26  call void @print(i32 2)
27  %unused = call i1 @llvm.coro.end(ptr null, i1 true, token none) [ "funclet"(token %tok) ]
28  cleanupret from %tok unwind label %cleanup.cont
29
30cleanup.cont:
31  %tok2 = cleanuppad within none []
32  call void @print(i32 3) ; should not be present in f.resume
33  cleanupret from %tok2 unwind to caller
34}
35
36; Verify that start function contains both print calls the one before and after coro.end
37; CHECK-LABEL: define ptr @f2(
38; CHECK: invoke void @print(i32 1)
39; CHECK:   to label %AfterCoroEnd unwind label %lpad
40
41; CHECK: AfterCoroEnd:
42; CHECK:   call void @print(i32 0)
43; CHECK:   ret ptr %hdl
44
45; CHECK:      lpad:
46; CHECK-NEXT:   %tok = cleanuppad within none []
47; CHECK-NEXT:   call void @print(i32 2)
48; CHECK-NEXT:   call void @print(i32 3)
49; CHECK-NEXT:   cleanupret from %tok unwind to caller
50
51; VERIFY Resume Parts
52
53; Verify that resume function does not contains both print calls appearing after coro.end
54; CHECK-LABEL: define internal fastcc void @f2.resume
55; CHECK: invoke void @print(i32 1)
56; CHECK:   to label %CoroEnd unwind label %lpad
57
58; CHECK:      CoroEnd:
59; CHECK-NEXT:   ret void
60
61; CHECK:      lpad:
62; CHECK-NEXT:   %tok = cleanuppad within none []
63; CHECK-NEXT:   call void @print(i32 2)
64; Checks that the coroutine would be marked as done if it exits in unwinding path.
65; CHECK-NEXT:   store ptr null, ptr %hdl, align 8
66; CHECK-NEXT:   cleanupret from %tok unwind to caller
67
68declare ptr @llvm.coro.free(token, ptr)
69declare i32 @llvm.coro.size.i32()
70declare i8  @llvm.coro.suspend(token, i1)
71declare void @llvm.coro.resume(ptr)
72declare void @llvm.coro.destroy(ptr)
73
74declare token @llvm.coro.id(i32, ptr, ptr, ptr)
75declare ptr @llvm.coro.alloc(token)
76declare ptr @llvm.coro.begin(token, ptr)
77declare i1 @llvm.coro.end(ptr, i1, token)
78
79declare noalias ptr @malloc(i32)
80declare void @print(i32)
81declare void @free(ptr)
82