1 ; RUN: opt -mtriple='arm64-' %s -S -passes='module(coro-early),cgscc(coro-split,simplifycfg)' -o - | FileCheck %s
2 ; RUN: opt -mtriple='x86_64' %s -S -passes='module(coro-early),cgscc(coro-split,simplifycfg)' -o - | FileCheck %s
3 ; RUN: opt -mtriple='i386-' %s -S -passes='module(coro-early),cgscc(coro-split,simplifycfg)' -o - | FileCheck %s --check-prefix=NOENTRY
4 ; RUN: opt -mtriple='armv7-' %s -S -passes='module(coro-early),cgscc(coro-split,simplifycfg)' -o - | FileCheck %s --check-prefix=NOENTRY
5 ; NOENTRY-NOT: OP_llvm_entry_value
7 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
9 ; This coroutine has one split point and two variables defined by:
10 ; %var_with_dbg_value, which has multiple dbg.value intrinsics associated with
11 ; it, one per split point.
12 ; %var_with_dbg_declare, which has a single dbg.declare intrinsic associated
13 ; with it at the coroutine entry.
14 ; We check that, for each funclet, the debug intrinsics are propagated properly AND that
15 ; an `entry_value` operation is created.
16 define swifttailcc void @coroutineA(ptr swiftasync %arg) !dbg !48 {
17 %var_with_dbg_value = alloca ptr, align 8
18 %var_with_dbg_declare = alloca ptr, align 8
19 call void @llvm.dbg.declare(metadata ptr %var_with_dbg_declare, metadata !500, metadata !DIExpression()), !dbg !54
20 call void @llvm.dbg.value(metadata ptr %var_with_dbg_value, metadata !50, metadata !DIExpression(DW_OP_deref)), !dbg !54
21 %i2 = call token @llvm.coro.id.async(i32 16, i32 16, i32 0, ptr nonnull @coroutineATu)
22 %i3 = call ptr @llvm.coro.begin(token %i2, ptr null)
23 ; CHECK-LABEL: define {{.*}} @coroutineA(
24 ; CHECK-SAME: ptr swiftasync %[[frame_ptr:.*]])
25 ; CHECK: @llvm.dbg.declare(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
26 ; CHECK-SAME: DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)
27 ; CHECK: @llvm.dbg.value(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
28 ; CHECK-SAME: DW_OP_plus_uconst, 16, DW_OP_deref)
29 ; CHECK: call {{.*}} @swift_task_switch
31 %i7 = call ptr @llvm.coro.async.resume(), !dbg !54
32 %i10 = call { ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0s(i32 0, ptr %i7, ptr nonnull @__swift_async_resume_get_context, ptr nonnull @coroutineA.1, ptr %i7, i64 0, i64 0, ptr %arg), !dbg !54
33 %i11 = extractvalue { ptr } %i10, 0, !dbg !54
34 %i12 = call ptr @__swift_async_resume_get_context(ptr %i11), !dbg !54
35 call void @dont_optimize(ptr %var_with_dbg_value, ptr %var_with_dbg_declare)
36 call void @llvm.dbg.value(metadata ptr %var_with_dbg_value, metadata !50, metadata !DIExpression(DW_OP_deref)), !dbg !54
37 %i17 = load i32, ptr getelementptr inbounds (<{i32, i32}>, ptr @coroutineBTu, i64 0, i32 1), align 8, !dbg !54
38 call void @llvm.dbg.value(metadata !DIArgList(ptr %var_with_dbg_value, i32 %i17), metadata !501, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_deref)), !dbg !54
39 %i18 = zext i32 %i17 to i64, !dbg !54
40 %i19 = call swiftcc ptr @swift_task_alloc(i64 %i18), !dbg !54
42 ; CHECK-LABEL: define {{.*}} @coroutineATY0_(
43 ; CHECK-SAME: ptr swiftasync %[[frame_ptr:.*]])
44 ; CHECK: @llvm.dbg.declare(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
45 ; CHECK-SAME: DW_OP_LLVM_entry_value, 1, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)
46 ; CHECK: @llvm.dbg.value(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
47 ; CHECK-SAME: DW_OP_LLVM_entry_value, 1, DW_OP_plus_uconst, 16, DW_OP_deref)
48 ; CHECK: @llvm.dbg.value(metadata !DIArgList(ptr %[[frame_ptr]], i32 %{{.*}}), {{.*}} !DIExpression(
49 ; CHECK-SAME: DW_OP_LLVM_arg, 0, DW_OP_plus_uconst, 16, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_deref)
50 ; CHECK: call {{.*}} @coroutineB
52 %i23 = call ptr @llvm.coro.async.resume(), !dbg !54
53 %i25 = getelementptr inbounds <{ ptr, ptr }>, ptr %i19, i64 0, i32 1, !dbg !54
54 store ptr %i23, ptr %i25, align 8, !dbg !54
55 %i27 = call { ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0s(i32 0, ptr %i23, ptr nonnull @__swift_async_resume_project_context, ptr nonnull @coroutineA.0, ptr nonnull @coroutineB, ptr nonnull %i19), !dbg !54
56 %i28 = extractvalue { ptr } %i27, 0, !dbg !54
57 %i29 = call ptr @__swift_async_resume_project_context(ptr %i28), !dbg !54
58 call swiftcc void @swift_task_dealloc(ptr nonnull %i19), !dbg !54
59 call void @dont_optimize(ptr %var_with_dbg_value, ptr %var_with_dbg_declare)
60 call void @llvm.dbg.value(metadata ptr %var_with_dbg_value, metadata !50, metadata !DIExpression(DW_OP_deref)), !dbg !54
62 ; CHECK-LABEL: define {{.*}} @coroutineATQ1_(
63 ; CHECK-SAME: ptr swiftasync %[[frame_ptr:.*]])
64 ; Note the extra level of indirection that shows up here!
65 ; CHECK: @llvm.dbg.declare(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
66 ; CHECK-SAME: DW_OP_LLVM_entry_value, 1, DW_OP_deref, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)
67 ; CHECK: @llvm.dbg.value(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
68 ; CHECK-SAME: DW_OP_LLVM_entry_value, 1, DW_OP_deref, DW_OP_plus_uconst, 16, DW_OP_deref)
69 ; CHECK: call {{.*}} @swift_task_switch
71 %i31 = call ptr @llvm.coro.async.resume(), !dbg !54
72 %i33 = call { ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0s(i32 0, ptr %i31, ptr nonnull @__swift_async_resume_get_context, ptr nonnull @coroutineA.1, ptr %i31, i64 0, i64 0, ptr %i29), !dbg !54
73 %i34 = extractvalue { ptr } %i33, 0, !dbg !54
74 %i35 = call ptr @__swift_async_resume_get_context(ptr %i34), !dbg !54
75 %i45 = call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr %i3, i1 false, ptr nonnull @coroutineA.0.1, ptr undef, ptr undef), !dbg !54
78 ; CHECK-LABEL: define {{.*}} @coroutineATY2_(
79 ; CHECK-SAME: ptr swiftasync %[[frame_ptr:.*]])
80 ; CHECK: @llvm.dbg.declare(metadata ptr %[[frame_ptr]], {{.*}} !DIExpression(
81 ; CHECK-SAME: DW_OP_LLVM_entry_value, 1, DW_OP_plus_uconst, 16, DW_OP_plus_uconst, 8)
84 ; Everything from here on is just support code for the coroutines.
86 @coroutineBTu = global <{i32, i32}> <{ i32 trunc (i64 sub (i64 ptrtoint (ptr @"coroutineB" to i64), i64 ptrtoint (ptr @"coroutineBTu" to i64)) to i32), i32 16 }>, align 8
87 @coroutineATu = global <{i32, i32}> <{ i32 trunc (i64 sub (i64 ptrtoint (ptr @"coroutineA" to i64), i64 ptrtoint (ptr @"coroutineATu" to i64)) to i32), i32 16 }>, align 8
89 define weak_odr hidden ptr @__swift_async_resume_get_context(ptr %arg) !dbg !64 {
90 ret ptr %arg, !dbg !65
92 define hidden swifttailcc void @coroutineA.1(ptr %arg, i64 %arg1, i64 %arg2, ptr %arg3) !dbg !66 {
93 musttail call swifttailcc void @swift_task_switch(ptr swiftasync %arg3, ptr %arg, i64 %arg1, i64 %arg2), !dbg !67
97 define weak_odr hidden ptr @__swift_async_resume_project_context(ptr %arg) !dbg !68 {
98 %i1 = load ptr, ptr %arg, align 8, !dbg !69
99 %i2 = call ptr @llvm.swift.async.context.addr(), !dbg !69
100 store ptr %i1, ptr %i2, align 8, !dbg !69
101 ret ptr %i1, !dbg !69
103 define hidden swifttailcc void @coroutineA.0(ptr %arg, ptr %arg1) !dbg !70 {
104 musttail call swifttailcc void %arg(ptr swiftasync %arg1), !dbg !71
107 define hidden swifttailcc void @coroutineA.0.1(ptr %arg, ptr %arg1) !dbg !72 {
108 musttail call swifttailcc void %arg(ptr swiftasync %arg1), !dbg !73
111 define swifttailcc void @coroutineB(ptr swiftasync %arg) !dbg !37 {
112 %i2 = call token @llvm.coro.id.async(i32 16, i32 16, i32 0, ptr nonnull @coroutineBTu)
113 %i3 = call ptr @llvm.coro.begin(token %i2, ptr null)
114 %i6 = getelementptr inbounds <{ ptr, ptr }>, ptr %arg, i64 0, i32 1, !dbg !42
115 %i712 = load ptr, ptr %i6, align 8, !dbg !42
116 %i10 = call i1 (ptr, i1, ...) @llvm.coro.end.async(ptr %i3, i1 false, ptr nonnull @coroutineB.0, ptr %i712, ptr %arg), !dbg !42
117 unreachable, !dbg !42
119 define hidden swifttailcc void @coroutineB.0(ptr %arg, ptr %arg1) !dbg !44 {
120 musttail call swifttailcc void %arg(ptr swiftasync %arg1), !dbg !47
124 declare i1 @llvm.coro.end.async(ptr, i1, ...)
125 declare ptr @llvm.coro.async.resume()
126 declare ptr @llvm.coro.begin(token, ptr writeonly)
127 declare ptr @llvm.swift.async.context.addr()
128 declare swiftcc ptr @swift_task_alloc(i64)
129 declare swiftcc void @swift_task_dealloc(ptr)
130 declare swifttailcc void @swift_task_switch(ptr, ptr, i64, i64)
131 declare token @llvm.coro.id.async(i32, i32, i32, ptr)
132 declare void @dont_optimize(ptr, ptr)
133 declare void @llvm.dbg.declare(metadata, metadata, metadata)
134 declare void @llvm.dbg.value(metadata, metadata, metadata)
135 declare { ptr } @llvm.coro.suspend.async.sl_p0s(i32, ptr, ptr, ...)
137 !llvm.module.flags = !{!6, !7}
138 !llvm.dbg.cu = !{!16}
140 !6 = !{i32 7, !"Dwarf Version", i32 4}
141 !7 = !{i32 2, !"Debug Info Version", i32 3}
143 !50 = !DILocalVariable(name: "k1", scope: !48, file: !17, line: 7, type: !53)
144 !500 = !DILocalVariable(name: "k2", scope: !48, file: !17, line: 7, type: !53)
145 !501 = !DILocalVariable(name: "k3", scope: !48, file: !17, line: 7, type: !53)
148 !16 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !17, producer: "", emissionKind: FullDebug)
149 !17 = !DIFile(filename: "blah", directory: "")
151 !53 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Klass")
152 !46 = !DISubroutineType(types: null)
154 !64 = distinct !DISubprogram(linkageName: "blah", file: !17, type: !46, unit: !16)
155 !68 = distinct !DISubprogram(linkageName: "blah", file: !17, type: !46, unit: !16)
156 !66 = distinct !DISubprogram(linkageName: "coroutineA", file: !17, type: !46, unit: !16)
157 !70 = distinct !DISubprogram(linkageName: "coroutineA", file: !17, type: !46, unit: !16)
158 !72 = distinct !DISubprogram(linkageName: "coroutineA", file: !17, type: !46, unit: !16)
159 !48 = distinct !DISubprogram(linkageName: "coroutineA", file: !17, type: !46, unit: !16, retainedNodes: !49)
160 !37 = distinct !DISubprogram(linkageName: "coroutineB", file: !17, type: !46, unit: !16)
161 !44 = distinct !DISubprogram(linkageName: "coroutineB", file: !17, type: !46, unit: !16)
162 !65 = !DILocation(line: 0, scope: !64)
163 !67 = !DILocation(line: 0, scope: !66)
164 !69 = !DILocation(line: 0, scope: !68)
165 !71 = !DILocation(line: 0, scope: !70)
166 !73 = !DILocation(line: 0, scope: !72)
167 !54 = !DILocation(line: 6, scope: !48)
168 !42 = !DILocation(line: 3, scope: !37)
169 !47 = !DILocation(line: 0, scope: !44)