Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / OpenMP / taskloop_lastprivate_codegen.cpp
blob96a974dc38858c9c083ceff762d6f1ae7d66ed9b
1 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-apple-darwin10 -emit-pch -o %t %s
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck %s
4 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -std=c++11 -DLAMBDA -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=LAMBDA %s
5 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -fblocks -DBLOCKS -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=BLOCKS %s
6 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -std=c++11 -DARRAY -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=ARRAY %s
7 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp -x c++ -std=c++11 -DLOOP -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=LOOP %s
9 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
10 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-apple-darwin10 -emit-pch -o %t %s
11 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -std=c++11 -include-pch %t -verify -Wno-vla %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
12 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -std=c++11 -DLAMBDA -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
13 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -fblocks -DBLOCKS -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
14 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -std=c++11 -DARRAY -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
15 // RUN: %clang_cc1 -verify -Wno-vla -fopenmp-simd -x c++ -std=c++11 -DLOOP -triple x86_64-apple-darwin10 -emit-llvm %s -o - | FileCheck -check-prefix=SIMD-ONLY0 %s
16 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
17 // expected-no-diagnostics
19 #if !defined(ARRAY) && !defined(LOOP)
20 #ifndef HEADER
21 #define HEADER
23 template <class T>
24 struct S {
25 T f;
26 S(T a) : f(a) {}
27 S() : f() {}
28 S(const S &s, T t = T()) : f(s.f + t) {}
29 operator T() { return T(); }
30 ~S() {}
33 volatile double g;
35 // CHECK-DAG: [[KMP_TASK_T_TY:%.+]] = type { ptr, ptr, i32, %union{{.+}}, %union{{.+}}, i64, i64, i64, i32, ptr }
36 // CHECK-DAG: [[S_DOUBLE_TY:%.+]] = type { double }
37 // CHECK-DAG: [[PRIVATES_MAIN_TY:%.+]] = type {{.?}}{ [2 x [[S_DOUBLE_TY]]], [[S_DOUBLE_TY]], i32, [2 x i32]
38 // CHECK-DAG: [[CAP_MAIN_TY:%.+]] = type { ptr, ptr, ptr, ptr, ptr }
39 // CHECK-DAG: [[KMP_TASK_MAIN_TY:%.+]] = type { [[KMP_TASK_T_TY]], [[PRIVATES_MAIN_TY]] }
40 // CHECK-DAG: [[S_INT_TY:%.+]] = type { i32 }
41 // CHECK-DAG: [[CAP_TMAIN_TY:%.+]] = type { ptr, ptr, ptr, ptr }
42 // CHECK-DAG: [[PRIVATES_TMAIN_TY:%.+]] = type { i32, [2 x i32], [2 x [[S_INT_TY]]], [[S_INT_TY]], [104 x i8] }
43 // CHECK-DAG: [[KMP_TASK_TMAIN_TY:%.+]] = type { [[KMP_TASK_T_TY]], [{{[0-9]+}} x i8], [[PRIVATES_TMAIN_TY]] }
44 template <typename T>
45 T tmain() {
46 S<T> ttt;
47 S<T> test;
48 T t_var __attribute__((aligned(128))) = T();
49 T vec[] = {1, 2};
50 S<T> s_arr[] = {1, 2};
51 S<T> var(3);
52 #pragma omp taskloop lastprivate(t_var, vec, s_arr, s_arr, var, var)
53 for (int i = 0; i < 10; ++i) {
54 vec[0] = t_var;
55 s_arr[0] = var;
57 return T();
60 int main() {
61 static int sivar;
62 #ifdef LAMBDA
63 // LAMBDA: [[G:@.+]] ={{.*}} global double
64 // LAMBDA: [[SIVAR:@.+]] = internal global i{{[0-9]+}} 0,
65 // LAMBDA-LABEL: @main
66 // LAMBDA: call{{( x86_thiscallcc)?}} void [[OUTER_LAMBDA:@.+]](
67 [&]() {
68 // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
69 // LAMBDA: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 96, i64 16, ptr [[TASK_ENTRY:@.+]])
70 // LAMBDA: [[PRIVATES:%.+]] = getelementptr inbounds %{{.+}}, ptr %{{.+}}, i{{.+}} 0, i{{.+}} 1
72 // LAMBDA: call void @__kmpc_taskloop(ptr @{{.+}}, i32 %{{.+}}, ptr [[RES]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr [[MAIN_DUP:@.+]])
73 // LAMBDA: ret
74 #pragma omp taskloop lastprivate(g, sivar)
75 for (int i = 0; i < 10; ++i) {
76 // LAMBDA: define {{.+}} void [[INNER_LAMBDA:@.+]]({{.+}} [[ARG_PTR:%.+]])
77 // LAMBDA: store ptr [[ARG_PTR]], ptr [[ARG_PTR_REF:%.+]],
78 // LAMBDA: [[ARG_PTR:%.+]] = load ptr, ptr [[ARG_PTR_REF]]
79 // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds %{{.+}}, ptr [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
80 // LAMBDA: [[G_REF:%.+]] = load ptr, ptr [[G_PTR_REF]]
81 // LAMBDA: store double 2.0{{.+}}, ptr [[G_REF]]
83 // LAMBDA: store ptr %{{.+}}, ptr %{{.+}},
84 // LAMBDA: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
85 g = 1;
86 sivar = 11;
87 // LAMBDA: store double 1.0{{.+}}, ptr %{{.+}},
88 // LAMBDA: store i{{[0-9]+}} 11, ptr %{{.+}},
89 // LAMBDA: call void [[INNER_LAMBDA]]({{.+}}
90 // LAMBDA: icmp ne i32 %{{.+}}, 0
91 // LAMBDA: br i1
92 // LAMBDA: load double, ptr %
93 // LAMBDA: store volatile double %
94 // LAMBDA: load i32, ptr %
95 // LAMBDA: store i32 %
96 // LAMBDA: ret
97 [&]() {
98 g = 2;
99 sivar = 22;
100 }();
102 }();
103 return 0;
104 #elif defined(BLOCKS)
105 // BLOCKS: [[G:@.+]] ={{.*}} global double
106 // BLOCKS: [[SIVAR:@.+]] = internal global i{{[0-9]+}} 0,
107 // BLOCKS-LABEL: @main
108 // BLOCKS: call void {{%.+}}(ptr
110 // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(ptr
111 // BLOCKS: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 96, i64 16, ptr [[TASK_ENTRY:@.+]])
112 // BLOCKS: [[PRIVATES:%.+]] = getelementptr inbounds %{{.+}}, ptr %{{.+}}, i{{.+}} 0, i{{.+}} 1
113 // BLOCKS: call void @__kmpc_taskloop(ptr @{{.+}}, i32 %{{.+}}, ptr [[RES]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr [[MAIN_DUP:@.+]])
114 // BLOCKS: ret
115 #pragma omp taskloop lastprivate(g, sivar)
116 for (int i = 0; i < 10; ++i) {
117 // BLOCKS: define {{.+}} void {{@.+}}(ptr
118 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
119 // BLOCKS: store double 2.0{{.+}}, ptr
120 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
121 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
122 // BLOCKS: store i{{[0-9]+}} 22, ptr
123 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
124 // BLOCKS: ret
126 // BLOCKS: store ptr %{{.+}}, ptr %{{.+}},
127 // BLOCKS: store ptr %{{.+}}, ptr %{{.+}},
128 // BLOCKS: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
129 g = 1;
130 sivar = 11;
131 // BLOCKS: store double 1.0{{.+}}, ptr %{{.+}},
132 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
133 // BLOCKS: store i{{[0-9]+}} 11, ptr %{{.+}},
134 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
135 // BLOCKS: call void {{%.+}}(ptr
136 // BLOCKS: icmp ne i32 %{{.+}}, 0
137 // BLOCKS: br i1
138 // BLOCKS: load double, ptr %
139 // BLOCKS: store volatile double %
140 // BLOCKS: load i32, ptr %
141 // BLOCKS: store i32 %
143 g = 2;
144 sivar = 22;
145 }();
147 }();
148 return 0;
149 #else
150 S<double> ttt;
151 S<double> test;
152 int t_var = 0;
153 int vec[] = {1, 2};
154 S<double> s_arr[] = {1, 2};
155 S<double> var(3);
156 #pragma omp taskloop lastprivate(var, t_var, s_arr, vec, s_arr, var, sivar)
157 for (int i = 0; i < 10; ++i) {
158 vec[0] = t_var;
159 s_arr[0] = var;
160 sivar = 33;
162 return tmain<int>();
163 #endif
166 // CHECK: [[SIVAR:.+]] = internal global i{{[0-9]+}} 0,
167 // CHECK: define{{.*}} i{{[0-9]+}} @main()
168 // CHECK: alloca [[S_DOUBLE_TY]],
169 // CHECK: [[TEST:%.+]] = alloca [[S_DOUBLE_TY]],
170 // CHECK: [[T_VAR_ADDR:%.+]] = alloca i32,
171 // CHECK: [[VEC_ADDR:%.+]] = alloca [2 x i32],
172 // CHECK: [[S_ARR_ADDR:%.+]] = alloca [2 x [[S_DOUBLE_TY]]],
173 // CHECK: [[VAR_ADDR:%.+]] = alloca [[S_DOUBLE_TY]],
174 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[LOC:@.+]])
176 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR:@.+]](ptr {{[^,]*}} [[TEST]])
178 // Store original variables in capture struct.
179 // CHECK: [[VEC_REF:%.+]] = getelementptr inbounds [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
180 // CHECK: store ptr [[VEC_ADDR]], ptr [[VEC_REF]],
181 // CHECK: [[T_VAR_REF:%.+]] = getelementptr inbounds [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 1
182 // CHECK: store ptr [[T_VAR_ADDR]], ptr [[T_VAR_REF]],
183 // CHECK: [[S_ARR_REF:%.+]] = getelementptr inbounds [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
184 // CHECK: store ptr [[S_ARR_ADDR]], ptr [[S_ARR_REF]],
185 // CHECK: [[VAR_REF:%.+]] = getelementptr inbounds [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 3
186 // CHECK: store ptr [[VAR_ADDR]], ptr [[VAR_REF]],
187 // CHECK: [[SIVAR_REF:%.+]] = getelementptr inbounds [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 4
188 // CHECK: store ptr [[SIVAR]], ptr [[SIVAR_REF]],
190 // Allocate task.
191 // Returns struct kmp_task_t {
192 // [[KMP_TASK_T]] task_data;
193 // [[KMP_TASK_MAIN_TY]] privates;
194 // };
195 // CHECK: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[LOC]], i32 [[GTID]], i32 9, i64 120, i64 40, ptr [[TASK_ENTRY:@[^ ]+]])
197 // Fill kmp_task_t->shareds by copying from original capture argument.
198 // CHECK: [[TASK:%.+]] = getelementptr inbounds [[KMP_TASK_MAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
199 // CHECK: [[SHAREDS_REF_ADDR:%.+]] = getelementptr inbounds [[KMP_TASK_T_TY]], ptr [[TASK]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
200 // CHECK: [[SHAREDS_REF:%.+]] = load ptr, ptr [[SHAREDS_REF_ADDR]],
201 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[SHAREDS_REF]], ptr align 8 %{{.+}}, i64 40, i1 false)
203 // Initialize kmp_task_t->privates with default values (no init for simple types, default constructors for classes).
204 // Also copy address of private copy to the corresponding shareds reference.
205 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds [[KMP_TASK_MAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
207 // Constructors for s_arr and var.
208 // s_arr;
209 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
210 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr {{[^,]*}} [[S_ARR_CUR:%[^,]+]])
211 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr [[S_ARR_CUR]], i{{.+}} 1
212 // CHECK: icmp eq
213 // CHECK: br i1
215 // var;
216 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
217 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
219 // t_var;
220 // vec;
221 // sivar;
223 // Provide pointer to destructor function, which will destroy private variables at the end of the task.
224 // CHECK: [[DESTRUCTORS_REF:%.+]] = getelementptr inbounds [[KMP_TASK_T_TY]], ptr [[TASK]], i{{.+}} 0, i{{.+}} 3
225 // CHECK: store ptr [[DESTRUCTORS:@.+]], ptr [[DESTRUCTORS_REF]],
227 // Start task.
228 // CHECK: call void @__kmpc_taskloop(ptr [[LOC]], i32 [[GTID]], ptr [[RES]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr [[MAIN_DUP:@.+]])
230 // CHECK: = call noundef i{{.+}} [[TMAIN_INT:@.+]]()
232 // No destructors must be called for private copies of s_arr and var.
233 // CHECK-NOT: getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
234 // CHECK-NOT: getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
235 // CHECK: call void [[S_DOUBLE_TY_DESTR:@.+]](ptr
236 // CHECK-NOT: getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
237 // CHECK-NOT: getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
238 // CHECK: ret
241 // CHECK: define internal void [[PRIVATES_MAP_FN:@.+]](ptr noalias noundef %0, ptr noalias noundef %1, ptr noalias noundef %2, ptr noalias noundef %3, ptr noalias noundef %4, ptr noalias noundef %5)
242 // CHECK: [[PRIVATES:%.+]] = load ptr, ptr
243 // CHECK: [[PRIV_S_VAR:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 0
244 // CHECK: [[ARG3:%.+]] = load ptr, ptr %{{.+}},
245 // CHECK: store ptr [[PRIV_S_VAR]], ptr [[ARG3]],
246 // CHECK: [[PRIV_VAR:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 1
247 // CHECK: [[ARG1:%.+]] = load ptr, ptr {{.+}},
248 // CHECK: store ptr [[PRIV_VAR]], ptr [[ARG1]],
249 // CHECK: [[PRIV_T_VAR:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 2
250 // CHECK: [[ARG2:%.+]] = load ptr, ptr %{{.+}},
251 // CHECK: store ptr [[PRIV_T_VAR]], ptr [[ARG2]],
252 // CHECK: [[PRIV_VEC:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 3
253 // CHECK: [[ARG4:%.+]] = load ptr, ptr %{{.+}},
254 // CHECK: store ptr [[PRIV_VEC]], ptr [[ARG4]],
255 // CHECK: [[PRIV_SIVAR:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 4
256 // CHECK: [[ARG5:%.+]] = load ptr, ptr %{{.+}},
257 // CHECK: store ptr [[PRIV_SIVAR]], ptr [[ARG5]],
258 // CHECK: ret void
260 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
262 // CHECK: %__context
263 // CHECK: [[PRIV_VAR_ADDR:%.+]] = alloca ptr,
264 // CHECK: [[PRIV_T_VAR_ADDR:%.+]] = alloca ptr,
265 // CHECK: [[PRIV_S_ARR_ADDR:%.+]] = alloca ptr,
266 // CHECK: [[PRIV_VEC_ADDR:%.+]] = alloca ptr,
267 // CHECK: [[PRIV_SIVAR_ADDR:%.+]] = alloca ptr,
268 // CHECK: store ptr [[PRIVATES_MAP_FN]], ptr [[MAP_FN_ADDR:%.+]],
269 // CHECK: [[MAP_FN:%.+]] = load ptr, ptr [[MAP_FN_ADDR]],
271 // CHECK: call void [[MAP_FN]](ptr %{{.+}}, ptr [[PRIV_VAR_ADDR]], ptr [[PRIV_T_VAR_ADDR]], ptr [[PRIV_S_ARR_ADDR]], ptr [[PRIV_VEC_ADDR]], ptr [[PRIV_SIVAR_ADDR]])
273 // CHECK: [[PRIV_VAR:%.+]] = load ptr, ptr [[PRIV_VAR_ADDR]],
274 // CHECK: [[PRIV_T_VAR:%.+]] = load ptr, ptr [[PRIV_T_VAR_ADDR]],
275 // CHECK: [[PRIV_S_ARR:%.+]] = load ptr, ptr [[PRIV_S_ARR_ADDR]],
276 // CHECK: [[PRIV_VEC:%.+]] = load ptr, ptr [[PRIV_VEC_ADDR]],
277 // CHECK: [[PRIV_SIVAR:%.+]] = load ptr, ptr [[PRIV_SIVAR_ADDR]],
279 // Privates actually are used.
280 // CHECK-DAG: [[PRIV_VAR]]
281 // CHECK-DAG: [[PRIV_T_VAR]]
282 // CHECK-DAG: [[PRIV_S_ARR]]
283 // CHECK-DAG: [[PRIV_VEC]]
284 // CHECK-DAG: [[PRIV_SIVAR]]
286 // CHECK: icmp ne i32 %{{.+}}, 0
287 // CHECK-NEXT: br i1
288 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
289 // CHECK: load i32, ptr %
290 // CHECK: store i32 %{{.+}}, ptr %
291 // CHECK: phi ptr
292 // CHECK: phi ptr
293 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
294 // CHECK: icmp eq ptr %
295 // CHECK-NEXT: br i1
296 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
297 // CHECK: load i32, ptr %
298 // CHECK: store i32 %{{.+}}, ptr %
299 // CHECK: br label
300 // CHECK: ret
302 // CHECK: define internal void [[MAIN_DUP]](ptr noundef %0, ptr noundef %1, i32 noundef %2)
303 // CHECK: getelementptr inbounds [[KMP_TASK_MAIN_TY]], ptr %{{.+}}, i32 0, i32 0
304 // CHECK: getelementptr inbounds [[KMP_TASK_T_TY]], ptr %{{.+}}, i32 0, i32 8
305 // CHECK: load i32, ptr %
306 // CHECK: store i32 %{{.+}}, ptr %
307 // CHECK: getelementptr inbounds [[KMP_TASK_MAIN_TY]], ptr %{{.+}}, i32 0, i32 1
308 // CHECK: getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr %{{.+}}, i32 0, i32 0
309 // CHECK: getelementptr inbounds [2 x [[S_DOUBLE_TY]]], ptr %{{.+}}, i32 0, i32 0
310 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i64 2
311 // CHECK: br label %
313 // CHECK: phi ptr
314 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr
315 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i64 1
316 // CHECK: icmp eq ptr %
317 // CHECK: br i1 %
319 // CHECK: getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr %{{.+}}, i32 0, i32 1
320 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr
321 // CHECK: ret void
323 // CHECK: define internal noundef i32 [[DESTRUCTORS]](i32 noundef %0, ptr noalias noundef %1)
324 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds [[KMP_TASK_MAIN_TY]], ptr [[RES_KMP_TASK:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
325 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
326 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
327 // CHECK: call {{.*}} [[S_DOUBLE_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
328 // CHECK: getelementptr inbounds [2 x [[S_DOUBLE_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
329 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} 2
330 // CHECK: [[PRIVATE_S_ARR_ELEM_REF:%.+]] = getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} -1
331 // CHECK: call {{.*}} [[S_DOUBLE_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_S_ARR_ELEM_REF]])
332 // CHECK: icmp eq
333 // CHECK: br i1
334 // CHECK: ret i32
336 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
337 // CHECK: alloca [[S_INT_TY]],
338 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
339 // CHECK: [[T_VAR_ADDR:%.+]] = alloca i32, align 128
340 // CHECK: [[VEC_ADDR:%.+]] = alloca [2 x i32],
341 // CHECK: [[S_ARR_ADDR:%.+]] = alloca [2 x [[S_INT_TY]]],
342 // CHECK: [[VAR_ADDR:%.+]] = alloca [[S_INT_TY]],
343 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[LOC:@.+]])
345 // CHECK: call {{.*}} [[S_INT_TY_CONSTR:@.+]](ptr {{[^,]*}} [[TEST]])
347 // Store original variables in capture struct.
348 // CHECK: [[VEC_REF:%.+]] = getelementptr inbounds [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
349 // CHECK: store ptr [[VEC_ADDR]], ptr [[VEC_REF]],
350 // CHECK: [[T_VAR_REF:%.+]] = getelementptr inbounds [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 1
351 // CHECK: store ptr [[T_VAR_ADDR]], ptr [[T_VAR_REF]],
352 // CHECK: [[S_ARR_REF:%.+]] = getelementptr inbounds [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
353 // CHECK: store ptr [[S_ARR_ADDR]], ptr [[S_ARR_REF]],
354 // CHECK: [[VAR_REF:%.+]] = getelementptr inbounds [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 3
355 // CHECK: store ptr [[VAR_ADDR]], ptr [[VAR_REF]],
357 // Allocate task.
358 // Returns struct kmp_task_t {
359 // [[KMP_TASK_T_TY]] task_data;
360 // [[KMP_TASK_TMAIN_TY]] privates;
361 // };
362 // CHECK: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[LOC]], i32 [[GTID]], i32 9, i64 256, i64 32, ptr [[TASK_ENTRY:@[^ ]+]])
364 // Fill kmp_task_t->shareds by copying from original capture argument.
365 // CHECK: [[TASK:%.+]] = getelementptr inbounds [[KMP_TASK_TMAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
366 // CHECK: [[SHAREDS_REF_ADDR:%.+]] = getelementptr inbounds [[KMP_TASK_T_TY]], ptr [[TASK]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
367 // CHECK: [[SHAREDS_REF:%.+]] = load ptr, ptr [[SHAREDS_REF_ADDR]],
368 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[SHAREDS_REF]], ptr align 8 %{{.+}}, i64 32, i1 false)
370 // Initialize kmp_task_t->privates with default values (no init for simple types, default constructors for classes).
371 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds [[KMP_TASK_TMAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
373 // t_var;
374 // vec;
376 // Constructors for s_arr and var.
377 // a_arr;
378 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
379 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
380 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} 2
381 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr {{[^,]*}} [[S_ARR_CUR:%[^,]+]])
382 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr [[S_ARR_CUR]], i{{.+}} 1
383 // CHECK: icmp eq
384 // CHECK: br i1
386 // var;
387 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
388 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
390 // Provide pointer to destructor function, which will destroy private variables at the end of the task.
391 // CHECK: [[DESTRUCTORS_REF:%.+]] = getelementptr inbounds [[KMP_TASK_T_TY]], ptr [[TASK]], i{{.+}} 0, i{{.+}} 3
392 // CHECK: store ptr [[DESTRUCTORS:@.+]], ptr [[DESTRUCTORS_REF]],
394 // Start task.
395 // CHECK: call void @__kmpc_taskloop(ptr [[LOC]], i32 [[GTID]], ptr [[RES]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr [[TMAIN_DUP:@.+]])
397 // No destructors must be called for private copies of s_arr and var.
398 // CHECK-NOT: getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
399 // CHECK-NOT: getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
400 // CHECK: call void [[S_INT_TY_DESTR:@.+]](ptr noundef
401 // CHECK-NOT: getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
402 // CHECK-NOT: getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
403 // CHECK: ret
406 // CHECK: define internal void [[PRIVATES_MAP_FN:@.+]](ptr noalias noundef %0, ptr noalias noundef %1, ptr noalias noundef %2, ptr noalias noundef %3, ptr noalias noundef %4)
407 // CHECK: [[PRIVATES:%.+]] = load ptr, ptr
408 // CHECK: [[PRIV_T_VAR:%.+]] = getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 0
409 // CHECK: [[ARG1:%.+]] = load ptr, ptr %{{.+}},
410 // CHECK: store ptr [[PRIV_T_VAR]], ptr [[ARG1]],
411 // CHECK: [[PRIV_VEC:%.+]] = getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 1
412 // CHECK: [[ARG2:%.+]] = load ptr, ptr %{{.+}},
413 // CHECK: store ptr [[PRIV_VEC]], ptr [[ARG2]],
414 // CHECK: [[PRIV_S_VAR:%.+]] = getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 2
415 // CHECK: [[ARG3:%.+]] = load ptr, ptr %{{.+}},
416 // CHECK: store ptr [[PRIV_S_VAR]], ptr [[ARG3]],
417 // CHECK: [[PRIV_VAR:%.+]] = getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 3
418 // CHECK: [[ARG4:%.+]] = load ptr, ptr {{.+}},
419 // CHECK: store ptr [[PRIV_VAR]], ptr [[ARG4]],
420 // CHECK: ret void
422 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
423 // CHECK: %__context
424 // CHECK-DAG: [[PRIV_T_VAR_ADDR:%.+]] = alloca ptr,
425 // CHECK-DAG: [[PRIV_VEC_ADDR:%.+]] = alloca ptr,
426 // CHECK-DAG: [[PRIV_S_ARR_ADDR:%.+]] = alloca ptr,
427 // CHECK-DAG: [[PRIV_VAR_ADDR:%.+]] = alloca ptr,
428 // CHECK: store ptr [[PRIVATES_MAP_FN]], ptr [[MAP_FN_ADDR:%.+]],
429 // CHECK: [[MAP_FN:%.+]] = load ptr, ptr [[MAP_FN_ADDR]],
430 // CHECK: call void [[MAP_FN]](ptr %{{.+}}, ptr [[PRIV_T_VAR_ADDR]], ptr [[PRIV_VEC_ADDR]], ptr [[PRIV_S_ARR_ADDR]], ptr [[PRIV_VAR_ADDR]])
431 // CHECK: [[PRIV_T_VAR:%.+]] = load ptr, ptr [[PRIV_T_VAR_ADDR]],
432 // CHECK: [[PRIV_VEC:%.+]] = load ptr, ptr [[PRIV_VEC_ADDR]],
433 // CHECK: [[PRIV_S_ARR:%.+]] = load ptr, ptr [[PRIV_S_ARR_ADDR]],
434 // CHECK: [[PRIV_VAR:%.+]] = load ptr, ptr [[PRIV_VAR_ADDR]],
436 // Privates actually are used.
437 // CHECK-DAG: [[PRIV_VAR]]
438 // CHECK-DAG: [[PRIV_T_VAR]]
439 // CHECK-DAG: [[PRIV_S_ARR]]
440 // CHECK-DAG: [[PRIV_VEC]]
442 // CHECK: icmp ne i32 %{{.+}}, 0
443 // CHECK-NEXT: br i1
444 // CHECK: load i32, ptr %
445 // CHECK: store i32 %{{.+}}, ptr %
446 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
447 // CHECK: phi ptr
448 // CHECK: phi ptr
449 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
450 // CHECK: icmp eq ptr %
451 // CHECK-NEXT: br i1
452 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
453 // CHECK: br label
454 // CHECK: ret
456 // CHECK: define internal void [[TMAIN_DUP]](ptr noundef %0, ptr noundef %1, i32 noundef %2)
457 // CHECK: getelementptr inbounds [[KMP_TASK_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 0
458 // CHECK: getelementptr inbounds [[KMP_TASK_T_TY]], ptr %{{.+}}, i32 0, i32 8
459 // CHECK: load i32, ptr %
460 // CHECK: store i32 %{{.+}}, ptr %
461 // CHECK: getelementptr inbounds [[KMP_TASK_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 2
462 // CHECK: getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 2
463 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr %{{.+}}, i32 0, i32 0
464 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i64 2
465 // CHECK: br label %
467 // CHECK: phi ptr
468 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr
469 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i64 1
470 // CHECK: icmp eq ptr %
471 // CHECK: br i1 %
473 // CHECK: getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 3
474 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr
475 // CHECK: ret void
477 // CHECK: define internal noundef i32 [[DESTRUCTORS]](i32 noundef %0, ptr noalias noundef %1)
478 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds [[KMP_TASK_TMAIN_TY]], ptr [[RES_KMP_TASK:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
479 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
480 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
481 // CHECK: call void [[S_INT_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
482 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
483 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} 2
484 // CHECK: [[PRIVATE_S_ARR_ELEM_REF:%.+]] = getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} -1
485 // CHECK: call void [[S_INT_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_S_ARR_ELEM_REF]])
486 // CHECK: icmp eq
487 // CHECK: br i1
488 // CHECK: ret i32
490 #endif
491 #elif defined(ARRAY)
492 // ARRAY-LABEL: array_func
493 struct St {
494 int a, b;
495 St() : a(0), b(0) {}
496 St(const St &) {}
497 ~St() {}
500 void array_func(int n, float a[n], St s[2]) {
501 // ARRAY: call ptr @__kmpc_omp_task_alloc(
502 // ARRAY: call void @__kmpc_taskloop(
503 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
504 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
505 // ARRAY: icmp ne i32 %{{.+}}, 0
506 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
507 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
508 #pragma omp taskloop lastprivate(a, s)
509 for (int i = 0; i < 10; ++i)
512 #else
514 // LOOP-LABEL: loop
515 void loop() {
516 // LOOP: call ptr @__kmpc_omp_task_alloc(
517 // LOOP: call void @__kmpc_taskloop(
518 int i;
519 #pragma omp taskloop lastprivate(i)
520 for (i = 0; i < 10; ++i)
523 #endif