1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -enable-coroutines -passes='default<O2>' -S | FileCheck %s
3 target datalayout = "E-p:32:32"
5 define i8* @f(i8* %buffer, i32 %n, i8** swifterror %errorslot) {
7 ; CHECK-NEXT: coro.return:
8 ; CHECK-NEXT: [[N_VAL_SPILL_ADDR:%.*]] = bitcast i8* [[BUFFER:%.*]] to i32*
9 ; CHECK-NEXT: store i32 [[N:%.*]], i32* [[N_VAL_SPILL_ADDR]], align 4
10 ; CHECK-NEXT: tail call void @print(i32 [[N]])
11 ; CHECK-NEXT: store i8* null, i8** [[ERRORSLOT:%.*]], align 4
12 ; CHECK-NEXT: tail call void @maybeThrow(i8** nonnull swifterror [[ERRORSLOT]])
13 ; CHECK-NEXT: [[TMP0:%.*]] = load i8*, i8** [[ERRORSLOT]], align 4
14 ; CHECK-NEXT: tail call void @logError(i8* [[TMP0]])
15 ; CHECK-NEXT: store i8* [[TMP0]], i8** [[ERRORSLOT]], align 4
16 ; CHECK-NEXT: ret i8* bitcast (i8* (i8*, i1, i8**)* @f.resume.0 to i8*)
19 %id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i1, i8**)* @f_prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
20 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
24 %n.val = phi i32 [ %n, %entry ], [ %inc, %resume ]
25 call void @print(i32 %n.val)
26 call void @maybeThrow(i8** swifterror %errorslot)
27 %errorload1 = load i8*, i8** %errorslot
28 call void @logError(i8* %errorload1)
29 %suspend_result = call { i1, i8** } (...) @llvm.coro.suspend.retcon.i1p0p0i8()
30 %unwind0 = extractvalue { i1, i8** } %suspend_result, 0
31 br i1 %unwind0, label %cleanup, label %resume
34 %inc = add i32 %n.val, 1
38 call i1 @llvm.coro.end(i8* %hdl, i1 0)
42 ; TODO: figure out a way to eliminate this
45 define i8* @g(i8* %buffer, i32 %n) {
47 ; CHECK-NEXT: coro.return:
48 ; CHECK-NEXT: [[TMP0:%.*]] = alloca swifterror i8*, align 4
49 ; CHECK-NEXT: [[N_VAL_SPILL_ADDR:%.*]] = bitcast i8* [[BUFFER:%.*]] to i32*
50 ; CHECK-NEXT: store i32 [[N:%.*]], i32* [[N_VAL_SPILL_ADDR]], align 4
51 ; CHECK-NEXT: tail call void @print(i32 [[N]])
52 ; CHECK-NEXT: store i8* null, i8** [[TMP0]], align 4
53 ; CHECK-NEXT: call void @maybeThrow(i8** nonnull swifterror [[TMP0]])
54 ; CHECK-NEXT: [[TMP1:%.*]] = load i8*, i8** [[TMP0]], align 4
55 ; CHECK-NEXT: [[DOTSPILL_ADDR:%.*]] = getelementptr inbounds i8, i8* [[BUFFER]], i32 4
56 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8* [[DOTSPILL_ADDR]] to i8**
57 ; CHECK-NEXT: store i8* [[TMP1]], i8** [[TMP2]], align 4
58 ; CHECK-NEXT: call void @logError(i8* [[TMP1]])
59 ; CHECK-NEXT: ret i8* bitcast (i8* (i8*, i1)* @g.resume.0 to i8*)
62 %errorslot = alloca swifterror i8*, align 4
63 store i8* null, i8** %errorslot
64 %id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i1)* @g_prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
65 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
69 %n.val = phi i32 [ %n, %entry ], [ %inc, %resume ]
70 call void @print(i32 %n.val)
71 call void @maybeThrow(i8** swifterror %errorslot)
72 %errorload1 = load i8*, i8** %errorslot
73 call void @logError(i8* %errorload1)
74 %unwind0 = call i1 (...) @llvm.coro.suspend.retcon.i1()
75 br i1 %unwind0, label %cleanup, label %resume
78 %inc = add i32 %n.val, 1
82 call i1 @llvm.coro.end(i8* %hdl, i1 0)
88 declare token @llvm.coro.id.retcon(i32, i32, i8*, i8*, i8*, i8*)
89 declare i8* @llvm.coro.begin(token, i8*)
90 declare { i1, i8** } @llvm.coro.suspend.retcon.i1p0p0i8(...)
91 declare i1 @llvm.coro.suspend.retcon.i1(...)
92 declare i1 @llvm.coro.end(i8*, i1)
93 declare i8* @llvm.coro.prepare.retcon(i8*)
95 declare i8* @f_prototype(i8*, i1 zeroext, i8** swifterror)
96 declare i8* @g_prototype(i8*, i1 zeroext)
98 declare noalias i8* @allocate(i32 %size)
99 declare void @deallocate(i8* %ptr)
101 declare void @print(i32)
102 declare void @maybeThrow(i8** swifterror)
103 declare void @logError(i8*)