1 ; RUN: opt < %s -coro-split -coro-cleanup -S | FileCheck %s
2 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-apple-macosx10.12.0"
5 define {i8*, i32*} @f(i8* %buffer, i32* %ptr) "coroutine.presplit"="1" {
7 %temp = alloca i32, align 4
8 %id = call token @llvm.coro.id.retcon.once(i32 8, i32 8, i8* %buffer, i8* bitcast (void (i8*, i1)* @prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
9 %hdl = call i8* @llvm.coro.begin(token %id, i8* null)
10 %oldvalue = load i32, i32* %ptr
11 store i32 %oldvalue, i32* %temp
12 %unwind = call i1 (...) @llvm.coro.suspend.retcon.i1(i32* %temp)
13 br i1 %unwind, label %cleanup, label %cont
16 %newvalue = load i32, i32* %temp
17 store i32 %newvalue, i32* %ptr
21 call i1 @llvm.coro.end(i8* %hdl, i1 0)
25 ; CHECK-LABEL: define { i8*, i32* } @f(i8* %buffer, i32* %ptr)
27 ; CHECK-NEXT: [[ALLOC:%.*]] = call i8* @allocate(i32 16)
28 ; CHECK-NEXT: [[T0:%.*]] = bitcast i8* %buffer to i8**
29 ; CHECK-NEXT: store i8* [[ALLOC]], i8** [[T0]]
30 ; CHECK-NEXT: [[FRAME:%.*]] = bitcast i8* [[ALLOC]] to [[FRAME_T:%.*]]*
31 ; CHECK-NEXT: %temp = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 1
32 ; CHECK-NEXT: [[SPILL:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 0
33 ; CHECK-NEXT: store i32* %ptr, i32** [[SPILL]]
34 ; CHECK-NEXT: %oldvalue = load i32, i32* %ptr
35 ; CHECK-NEXT: store i32 %oldvalue, i32* %temp
36 ; CHECK-NEXT: [[T0:%.*]] = insertvalue { i8*, i32* } { i8* bitcast (void (i8*, i1)* @f.resume.0 to i8*), i32* undef }, i32* %temp, 1
37 ; CHECK-NEXT: ret { i8*, i32* } [[T0]]
40 ; CHECK-LABEL: define internal void @f.resume.0(i8* noalias nonnull %0, i1 zeroext %1)
42 ; CHECK-NEXT: [[T0:%.*]] = bitcast i8* %0 to [[FRAME_T:%.*]]**
43 ; CHECK-NEXT: [[FRAME:%.*]] = load [[FRAME_T]]*, [[FRAME_T]]** [[T0]]
44 ; CHECK-NEXT: bitcast [[FRAME_T]]* [[FRAME]] to i8*
45 ; CHECK-NEXT: %temp = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 1
46 ; CHECK-NEXT: br i1 %1,
48 ; CHECK-NEXT: [[TEMP_SLOT:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 1
49 ; CHECK-NEXT: [[PTR_SLOT:%.*]] = getelementptr inbounds [[FRAME_T]], [[FRAME_T]]* [[FRAME]], i32 0, i32 0
50 ; CHECK-NEXT: [[PTR_RELOAD:%.*]] = load i32*, i32** [[PTR_SLOT]]
51 ; CHECK-NEXT: %newvalue = load i32, i32* [[TEMP_SLOT]]
52 ; CHECK-NEXT: store i32 %newvalue, i32* [[PTR_RELOAD]]
53 ; CHECK-NEXT: br label
55 ; CHECK-NEXT: [[T0:%.*]] = bitcast [[FRAME_T]]* [[FRAME]] to i8*
56 ; CHECK-NEXT: call fastcc void @deallocate(i8* [[T0]])
57 ; CHECK-NEXT: ret void
60 declare token @llvm.coro.id.retcon.once(i32, i32, i8*, i8*, i8*, i8*)
61 declare i8* @llvm.coro.begin(token, i8*)
62 declare i1 @llvm.coro.suspend.retcon.i1(...)
63 declare i1 @llvm.coro.end(i8*, i1)
65 declare void @prototype(i8*, i1 zeroext)
67 declare noalias i8* @allocate(i32 %size)
68 declare fastcc void @deallocate(i8* %ptr)
70 declare void @print(i32)