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)
28 S(const S
&s
, T t
= T()) : f(s
.f
+ t
) {}
29 operator T() { return T(); }
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]] }
48 T t_var
__attribute__((aligned(128))) = T();
50 S
<T
> s_arr
[] = {1, 2};
52 #pragma omp taskloop lastprivate(t_var, vec, s_arr, s_arr, var, var)
53 for (int i
= 0; i
< 10; ++i
) {
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:@.+]](
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:@.+]])
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)
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
92 // LAMBDA: load double, ptr %
93 // LAMBDA: store volatile double %
94 // LAMBDA: load i32, ptr %
95 // LAMBDA: store i32 %
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:@.+]])
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:]]}}
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)
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
138 // BLOCKS: load double, ptr %
139 // BLOCKS: store volatile double %
140 // BLOCKS: load i32, ptr %
141 // BLOCKS: store i32 %
154 S
<double> s_arr
[] = {1, 2};
156 #pragma omp taskloop lastprivate(var, t_var, s_arr, vec, s_arr, var, sivar)
157 for (int i
= 0; i
< 10; ++i
) {
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]],
191 // Returns struct kmp_task_t {
192 // [[KMP_TASK_T]] task_data;
193 // [[KMP_TASK_MAIN_TY]] privates;
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.
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
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]])
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]],
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
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]],
260 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
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
288 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
289 // CHECK: load i32, ptr %
290 // CHECK: store i32 %{{.+}}, ptr %
293 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
294 // CHECK: icmp eq ptr %
296 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
297 // CHECK: load i32, ptr %
298 // CHECK: store i32 %{{.+}}, ptr %
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
314 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr
315 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i64 1
316 // CHECK: icmp eq ptr %
319 // CHECK: getelementptr inbounds [[PRIVATES_MAIN_TY]], ptr %{{.+}}, i32 0, i32 1
320 // CHECK: call {{.*}} [[S_DOUBLE_TY_CONSTR]](ptr
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]])
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]],
358 // Returns struct kmp_task_t {
359 // [[KMP_TASK_T_TY]] task_data;
360 // [[KMP_TASK_TMAIN_TY]] privates;
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
376 // Constructors for s_arr and var.
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
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]],
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
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]],
422 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
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
444 // CHECK: load i32, ptr %
445 // CHECK: store i32 %{{.+}}, ptr %
446 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
449 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
450 // CHECK: icmp eq ptr %
452 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} %
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
468 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr
469 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i64 1
470 // CHECK: icmp eq ptr %
473 // CHECK: getelementptr inbounds [[PRIVATES_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 3
474 // CHECK: call {{.*}} [[S_INT_TY_CONSTR]](ptr
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]])
492 // ARRAY-LABEL: array_func
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
)
516 // LOOP: call ptr @__kmpc_omp_task_alloc(
517 // LOOP: call void @__kmpc_taskloop(
519 #pragma omp taskloop lastprivate(i)
520 for (i
= 0; i
< 10; ++i
)