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
8 // 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
9 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-apple-darwin10 -emit-pch -o %t %s
10 // 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
11 // 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
12 // 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
13 // 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
14 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
15 // expected-no-diagnostics
26 S(const S
&s
, T t
= T()) : f(s
.f
+ t
) {}
27 operator T() { return T(); }
33 // CHECK-DAG: [[KMP_TASK_T_TY:%.+]] = type { ptr, ptr, i32, %union{{.+}}, %union{{.+}}, i64, i64, i64, i32, ptr }
34 // CHECK-DAG: [[S_DOUBLE_TY:%.+]] = type { double }
35 // CHECK-DAG: [[PRIVATES_MAIN_TY:%.+]] = type {{.?}}{ [2 x [[S_DOUBLE_TY]]], [[S_DOUBLE_TY]], i32, [2 x i32]
36 // CHECK-DAG: [[CAP_MAIN_TY:%.+]] = type { ptr, ptr, ptr, ptr, ptr }
37 // CHECK-DAG: [[KMP_TASK_MAIN_TY:%.+]] = type { [[KMP_TASK_T_TY]], [[PRIVATES_MAIN_TY]] }
38 // CHECK-DAG: [[S_INT_TY:%.+]] = type { i32 }
39 // CHECK-DAG: [[CAP_TMAIN_TY:%.+]] = type { ptr, ptr, ptr, ptr }
40 // CHECK-DAG: [[PRIVATES_TMAIN_TY:%.+]] = type { i32, [2 x i32], [2 x [[S_INT_TY]]], [[S_INT_TY]], [104 x i8] }
41 // CHECK-DAG: [[KMP_TASK_TMAIN_TY:%.+]] = type { [[KMP_TASK_T_TY]], [{{[0-9]+}} x i8], [[PRIVATES_TMAIN_TY]] }
46 T t_var
__attribute__((aligned(128))) = T();
48 S
<T
> s_arr
[] = {1, 2};
50 #pragma omp master taskloop simd lastprivate(t_var, vec, s_arr, s_arr, var, var)
51 for (int i
= 0; i
< 10; ++i
) {
61 // LAMBDA: [[G:@.+]] ={{.*}} global double
62 // LAMBDA: [[SIVAR:@.+]] = internal global i{{[0-9]+}} 0,
63 // LAMBDA-LABEL: @main
64 // LAMBDA: call{{( x86_thiscallcc)?}} void [[OUTER_LAMBDA:@.+]](
66 // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
67 // LAMBDA: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 96, i64 16, ptr [[TASK_ENTRY:@[^ ]+]])
68 // LAMBDA: [[PRIVATES:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i{{.+}} 0, i{{.+}} 1
70 // LAMBDA: call void @__kmpc_taskloop(ptr @{{.+}}, i32 %{{.+}}, ptr [[RES]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr [[MAIN_DUP:@.+]])
72 #pragma omp master taskloop simd lastprivate(g, sivar)
73 for (int i
= 0; i
< 10; ++i
) {
74 // LAMBDA: define {{.+}} void [[INNER_LAMBDA:@.+]]({{.+}} [[ARG_PTR:%.+]])
75 // LAMBDA: store ptr [[ARG_PTR]], ptr [[ARG_PTR_REF:%.+]],
76 // LAMBDA: [[ARG_PTR:%.+]] = load ptr, ptr [[ARG_PTR_REF]]
77 // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
78 // LAMBDA: [[G_REF:%.+]] = load ptr, ptr [[G_PTR_REF]]
79 // LAMBDA: store double 2.0{{.+}}, ptr [[G_REF]]
81 // LAMBDA: store ptr %{{.+}}, ptr %{{.+}},
82 // LAMBDA: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
85 // LAMBDA: store double 1.0{{.+}}, ptr %{{.+}},
86 // LAMBDA: store i{{[0-9]+}} 11, ptr %{{.+}},
87 // LAMBDA: call void [[INNER_LAMBDA]]({{.+}}
88 // LAMBDA: icmp ne i32 %{{.+}}, 0
90 // LAMBDA: load double, ptr %
91 // LAMBDA: store volatile double %
92 // LAMBDA: load i32, ptr %
93 // LAMBDA: store i32 %
102 #elif defined(BLOCKS)
103 // BLOCKS: [[G:@.+]] ={{.*}} global double
104 // BLOCKS: [[SIVAR:@.+]] = internal global i{{[0-9]+}} 0,
105 // BLOCKS-LABEL: @main
106 // BLOCKS: call void {{%.+}}(ptr
108 // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(ptr
109 // BLOCKS: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 96, i64 16, ptr [[TASK_ENTRY:@[^ ]+]])
110 // BLOCKS: [[PRIVATES:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i{{.+}} 0, i{{.+}} 1
111 // BLOCKS: call void @__kmpc_taskloop(ptr @{{.+}}, i32 %{{.+}}, ptr [[RES]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr [[MAIN_DUP:@.+]])
113 #pragma omp master taskloop simd lastprivate(g, sivar)
114 for (int i
= 0; i
< 10; ++i
) {
115 // BLOCKS: define {{.+}} void {{@.+}}(ptr
116 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
117 // BLOCKS: store double 2.0{{.+}}, ptr
118 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
119 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
120 // BLOCKS: store i{{[0-9]+}} 22, ptr
121 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
124 // BLOCKS: store ptr %{{.+}}, ptr %{{.+}},
125 // BLOCKS: store ptr %{{.+}}, ptr %{{.+}},
126 // BLOCKS: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
129 // BLOCKS: store double 1.0{{.+}}, ptr %{{.+}},
130 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
131 // BLOCKS: store i{{[0-9]+}} 11, ptr %{{.+}},
132 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
133 // BLOCKS: call void {{%.+}}(ptr
134 // BLOCKS: icmp ne i32 %{{.+}}, 0
136 // BLOCKS: load double, ptr %
137 // BLOCKS: store volatile double %
138 // BLOCKS: load i32, ptr %
139 // BLOCKS: store i32 %
152 S
<double> s_arr
[] = {1, 2};
154 #pragma omp master taskloop simd lastprivate(var, t_var, s_arr, vec, s_arr, var, sivar)
155 for (int i
= 0; i
< 10; ++i
) {
164 // CHECK: [[SIVAR:.+]] = internal global i{{[0-9]+}} 0,
165 // CHECK: define{{.*}} i{{[0-9]+}} @main()
166 // CHECK: alloca [[S_DOUBLE_TY]],
167 // CHECK: [[TEST:%.+]] = alloca [[S_DOUBLE_TY]],
168 // CHECK: [[T_VAR_ADDR:%.+]] = alloca i32,
169 // CHECK: [[VEC_ADDR:%.+]] = alloca [2 x i32],
170 // CHECK: [[S_ARR_ADDR:%.+]] = alloca [2 x [[S_DOUBLE_TY]]],
171 // CHECK: [[VAR_ADDR:%.+]] = alloca [[S_DOUBLE_TY]],
172 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[LOC:@.+]])
174 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR:@.+]](ptr {{[^,]*}} [[TEST]])
176 // Store original variables in capture struct.
177 // CHECK: [[VEC_REF:%.+]] = getelementptr inbounds nuw [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
178 // CHECK: store ptr [[VEC_ADDR]], ptr [[VEC_REF]],
179 // CHECK: [[T_VAR_REF:%.+]] = getelementptr inbounds nuw [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 1
180 // CHECK: store ptr [[T_VAR_ADDR]], ptr [[T_VAR_REF]],
181 // CHECK: [[S_ARR_REF:%.+]] = getelementptr inbounds nuw [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
182 // CHECK: store ptr [[S_ARR_ADDR]], ptr [[S_ARR_REF]],
183 // CHECK: [[VAR_REF:%.+]] = getelementptr inbounds nuw [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 3
184 // CHECK: store ptr [[VAR_ADDR]], ptr [[VAR_REF]],
185 // CHECK: [[SIVAR_REF:%.+]] = getelementptr inbounds nuw [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 4
186 // CHECK: store ptr [[SIVAR]], ptr [[SIVAR_REF]],
189 // Returns struct kmp_task_t {
190 // [[KMP_TASK_T]] task_data;
191 // [[KMP_TASK_MAIN_TY]] privates;
193 // CHECK: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[LOC]], i32 [[GTID]], i32 9, i64 120, i64 40, ptr [[TASK_ENTRY:@[^ ]+]])
195 // Fill kmp_task_t->shareds by copying from original capture argument.
196 // CHECK: [[TASK:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
197 // CHECK: [[SHAREDS_REF_ADDR:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
198 // CHECK: [[SHAREDS_REF:%.+]] = load ptr, ptr [[SHAREDS_REF_ADDR]],
199 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[SHAREDS_REF]], ptr align 8 %{{.+}}, i64 40, i1 false)
201 // Initialize kmp_task_t->privates with default values (no init for simple types, default constructors for classes).
202 // Also copy address of private copy to the corresponding shareds reference.
203 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
205 // Constructors for s_arr and var.
207 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
208 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr {{[^,]*}} [[S_ARR_CUR:%[^,]+]])
209 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr [[S_ARR_CUR]], i{{.+}} 1
214 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
215 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
221 // Provide pointer to destructor function, which will destroy private variables at the end of the task.
222 // CHECK: [[DESTRUCTORS_REF:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{.+}} 0, i{{.+}} 3
223 // CHECK: store ptr [[DESTRUCTORS:@.+]], ptr [[DESTRUCTORS_REF]],
226 // 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:@.+]])
228 // CHECK: = call noundef i{{.+}} [[TMAIN_INT:@.+]]()
230 // No destructors must be called for private copies of s_arr and var.
231 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
232 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
233 // CHECK: call void [[S_DOUBLE_TY_DESTR:@.+]](ptr
234 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
235 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
239 // 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)
240 // CHECK: [[PRIVATES:%.+]] = load ptr, ptr
241 // CHECK: [[PRIV_S_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 0
242 // CHECK: [[ARG3:%.+]] = load ptr, ptr %{{.+}},
243 // CHECK: store ptr [[PRIV_S_VAR]], ptr [[ARG3]],
244 // CHECK: [[PRIV_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 1
245 // CHECK: [[ARG1:%.+]] = load ptr, ptr {{.+}},
246 // CHECK: store ptr [[PRIV_VAR]], ptr [[ARG1]],
247 // CHECK: [[PRIV_T_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 2
248 // CHECK: [[ARG2:%.+]] = load ptr, ptr %{{.+}},
249 // CHECK: store ptr [[PRIV_T_VAR]], ptr [[ARG2]],
250 // CHECK: [[PRIV_VEC:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 3
251 // CHECK: [[ARG4:%.+]] = load ptr, ptr %{{.+}},
252 // CHECK: store ptr [[PRIV_VEC]], ptr [[ARG4]],
253 // CHECK: [[PRIV_SIVAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 4
254 // CHECK: [[ARG5:%.+]] = load ptr, ptr %{{.+}},
255 // CHECK: store ptr [[PRIV_SIVAR]], ptr [[ARG5]],
258 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
261 // CHECK: [[PRIV_VAR_ADDR:%.+]] = alloca ptr,
262 // CHECK: [[PRIV_T_VAR_ADDR:%.+]] = alloca ptr,
263 // CHECK: [[PRIV_S_ARR_ADDR:%.+]] = alloca ptr,
264 // CHECK: [[PRIV_VEC_ADDR:%.+]] = alloca ptr,
265 // CHECK: [[PRIV_SIVAR_ADDR:%.+]] = alloca ptr,
266 // CHECK: store ptr [[PRIVATES_MAP_FN]], ptr [[MAP_FN_ADDR:%.+]],
267 // CHECK: [[MAP_FN:%.+]] = load ptr, ptr [[MAP_FN_ADDR]],
269 // 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]])
271 // CHECK: [[PRIV_VAR:%.+]] = load ptr, ptr [[PRIV_VAR_ADDR]],
272 // CHECK: [[PRIV_T_VAR:%.+]] = load ptr, ptr [[PRIV_T_VAR_ADDR]],
273 // CHECK: [[PRIV_S_ARR:%.+]] = load ptr, ptr [[PRIV_S_ARR_ADDR]],
274 // CHECK: [[PRIV_VEC:%.+]] = load ptr, ptr [[PRIV_VEC_ADDR]],
275 // CHECK: [[PRIV_SIVAR:%.+]] = load ptr, ptr [[PRIV_SIVAR_ADDR]],
277 // Privates actually are used.
278 // CHECK-DAG: [[PRIV_VAR]]
279 // CHECK-DAG: [[PRIV_T_VAR]]
280 // CHECK-DAG: [[PRIV_S_ARR]]
281 // CHECK-DAG: [[PRIV_VEC]]
282 // CHECK-DAG: [[PRIV_SIVAR]]
284 // CHECK: icmp ne i32 %{{.+}}, 0
286 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
287 // CHECK: load i32, ptr %
288 // CHECK: store i32 %{{.+}}, ptr %
291 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
292 // CHECK: icmp eq ptr %
294 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
295 // CHECK: load i32, ptr %
296 // CHECK: store i32 %{{.+}}, ptr %
300 // CHECK: define internal void [[MAIN_DUP]](ptr noundef %0, ptr noundef %1, i32 noundef %2)
301 // CHECK: getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr %{{.+}}, i32 0, i32 0
302 // CHECK: getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr %{{.+}}, i32 0, i32 8
303 // CHECK: load i32, ptr %
304 // CHECK: store i32 %{{.+}}, ptr %
305 // CHECK: getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr %{{.+}}, i32 0, i32 1
306 // CHECK: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr %{{.+}}, i32 0, i32 0
307 // CHECK: getelementptr inbounds [2 x [[S_DOUBLE_TY]]], ptr %{{.+}}, i32 0, i32 0
308 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i64 2
312 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr
313 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i64 1
314 // CHECK: icmp eq ptr %
317 // CHECK: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr %{{.+}}, i32 0, i32 1
318 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr
321 // CHECK: define internal noundef i32 [[DESTRUCTORS]](i32 noundef %0, ptr noalias noundef %1)
322 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES_KMP_TASK:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
323 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
324 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
325 // CHECK: call {{.*}} [[S_DOUBLE_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
326 // CHECK: getelementptr inbounds [2 x [[S_DOUBLE_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
327 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} 2
328 // CHECK: [[PRIVATE_S_ARR_ELEM_REF:%.+]] = getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} -1
329 // CHECK: call {{.*}} [[S_DOUBLE_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_S_ARR_ELEM_REF]])
334 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
335 // CHECK: alloca [[S_INT_TY]],
336 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
337 // CHECK: [[T_VAR_ADDR:%.+]] = alloca i32, align 128
338 // CHECK: [[VEC_ADDR:%.+]] = alloca [2 x i32],
339 // CHECK: [[S_ARR_ADDR:%.+]] = alloca [2 x [[S_INT_TY]]],
340 // CHECK: [[VAR_ADDR:%.+]] = alloca [[S_INT_TY]],
341 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[LOC:@.+]])
343 // CHECK: call {{.*}} [[S_INT_TY_CONSTR:@.+]](ptr {{[^,]*}} [[TEST]])
345 // Store original variables in capture struct.
346 // CHECK: [[VEC_REF:%.+]] = getelementptr inbounds nuw [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
347 // CHECK: store ptr [[VEC_ADDR]], ptr [[VEC_REF]],
348 // CHECK: [[T_VAR_REF:%.+]] = getelementptr inbounds nuw [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 1
349 // CHECK: store ptr [[T_VAR_ADDR]], ptr [[T_VAR_REF]],
350 // CHECK: [[S_ARR_REF:%.+]] = getelementptr inbounds nuw [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 2
351 // CHECK: store ptr [[S_ARR_ADDR]], ptr [[S_ARR_REF]],
352 // CHECK: [[VAR_REF:%.+]] = getelementptr inbounds nuw [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 3
353 // CHECK: store ptr [[VAR_ADDR]], ptr [[VAR_REF]],
356 // Returns struct kmp_task_t {
357 // [[KMP_TASK_T_TY]] task_data;
358 // [[KMP_TASK_TMAIN_TY]] privates;
360 // CHECK: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[LOC]], i32 [[GTID]], i32 9, i64 256, i64 32, ptr [[TASK_ENTRY:@[^ ]+]])
362 // Fill kmp_task_t->shareds by copying from original capture argument.
363 // CHECK: [[TASK:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
364 // CHECK: [[SHAREDS_REF_ADDR:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
365 // CHECK: [[SHAREDS_REF:%.+]] = load ptr, ptr [[SHAREDS_REF_ADDR]],
366 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[SHAREDS_REF]], ptr align 8 %{{.+}}, i64 32, i1 false)
368 // Initialize kmp_task_t->privates with default values (no init for simple types, default constructors for classes).
369 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
374 // Constructors for s_arr and var.
376 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
377 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
378 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} 2
379 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr {{[^,]*}} [[S_ARR_CUR:%[^,]+]])
380 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr [[S_ARR_CUR]], i{{.+}} 1
385 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
386 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
388 // Provide pointer to destructor function, which will destroy private variables at the end of the task.
389 // CHECK: [[DESTRUCTORS_REF:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{.+}} 0, i{{.+}} 3
390 // CHECK: store ptr [[DESTRUCTORS:@.+]], ptr [[DESTRUCTORS_REF]],
393 // 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:@.+]])
395 // No destructors must be called for private copies of s_arr and var.
396 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
397 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
398 // CHECK: call void [[S_INT_TY_DESTR:@.+]](ptr noundef
399 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
400 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
404 // 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)
405 // CHECK: [[PRIVATES:%.+]] = load ptr, ptr
406 // CHECK: [[PRIV_T_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 0
407 // CHECK: [[ARG1:%.+]] = load ptr, ptr %{{.+}},
408 // CHECK: store ptr [[PRIV_T_VAR]], ptr [[ARG1]],
409 // CHECK: [[PRIV_VEC:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 1
410 // CHECK: [[ARG2:%.+]] = load ptr, ptr %{{.+}},
411 // CHECK: store ptr [[PRIV_VEC]], ptr [[ARG2]],
412 // CHECK: [[PRIV_S_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 2
413 // CHECK: [[ARG3:%.+]] = load ptr, ptr %{{.+}},
414 // CHECK: store ptr [[PRIV_S_VAR]], ptr [[ARG3]],
415 // CHECK: [[PRIV_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 3
416 // CHECK: [[ARG4:%.+]] = load ptr, ptr {{.+}},
417 // CHECK: store ptr [[PRIV_VAR]], ptr [[ARG4]],
420 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
422 // CHECK-DAG: [[PRIV_T_VAR_ADDR:%.+]] = alloca ptr,
423 // CHECK-DAG: [[PRIV_VEC_ADDR:%.+]] = alloca ptr,
424 // CHECK-DAG: [[PRIV_S_ARR_ADDR:%.+]] = alloca ptr,
425 // CHECK-DAG: [[PRIV_VAR_ADDR:%.+]] = alloca ptr,
426 // CHECK: store ptr [[PRIVATES_MAP_FN]], ptr [[MAP_FN_ADDR:%.+]],
427 // CHECK: [[MAP_FN:%.+]] = load ptr, ptr [[MAP_FN_ADDR]],
428 // CHECK: call void [[MAP_FN]](ptr %{{.+}}, ptr [[PRIV_T_VAR_ADDR]], ptr [[PRIV_VEC_ADDR]], ptr [[PRIV_S_ARR_ADDR]], ptr [[PRIV_VAR_ADDR]])
429 // CHECK: [[PRIV_T_VAR:%.+]] = load ptr, ptr [[PRIV_T_VAR_ADDR]],
430 // CHECK: [[PRIV_VEC:%.+]] = load ptr, ptr [[PRIV_VEC_ADDR]],
431 // CHECK: [[PRIV_S_ARR:%.+]] = load ptr, ptr [[PRIV_S_ARR_ADDR]],
432 // CHECK: [[PRIV_VAR:%.+]] = load ptr, ptr [[PRIV_VAR_ADDR]],
434 // Privates actually are used.
435 // CHECK-DAG: [[PRIV_VAR]]
436 // CHECK-DAG: [[PRIV_T_VAR]]
437 // CHECK-DAG: [[PRIV_S_ARR]]
438 // CHECK-DAG: [[PRIV_VEC]]
440 // CHECK: icmp ne i32 %{{.+}}, 0
442 // CHECK: load i32, ptr %
443 // CHECK: store i32 %{{.+}}, ptr %
444 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
447 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
448 // CHECK: icmp eq ptr %
450 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
454 // CHECK: define internal void [[TMAIN_DUP]](ptr noundef %0, ptr noundef %1, i32 noundef %2)
455 // CHECK: getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 0
456 // CHECK: getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr %{{.+}}, i32 0, i32 8
457 // CHECK: load i32, ptr %
458 // CHECK: store i32 %{{.+}}, ptr %
459 // CHECK: getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 2
460 // CHECK: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 2
461 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr %{{.+}}, i32 0, i32 0
462 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i64 2
466 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr
467 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i64 1
468 // CHECK: icmp eq ptr %
471 // CHECK: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 3
472 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr
475 // CHECK: define internal noundef i32 [[DESTRUCTORS]](i32 noundef %0, ptr noalias noundef %1)
476 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES_KMP_TASK:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
477 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
478 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
479 // CHECK: call void [[S_INT_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
480 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
481 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} 2
482 // CHECK: [[PRIVATE_S_ARR_ELEM_REF:%.+]] = getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} -1
483 // CHECK: call void [[S_INT_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_S_ARR_ELEM_REF]])
490 // ARRAY-LABEL: array_func
498 void array_func(int n
, float a
[n
], St s
[2]) {
499 // ARRAY: call ptr @__kmpc_omp_task_alloc(
500 // ARRAY: call void @__kmpc_taskloop(
501 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
502 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
503 // ARRAY: icmp ne i32 %{{.+}}, 0
504 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
505 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
506 #pragma omp master taskloop simd lastprivate(a, s)
507 for (int i
= 0; i
< 10; ++i
)