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 }
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 }
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 firstprivate(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 {{.*}}i32 @__kmpc_master(
68 // LAMBDA-NEXT: [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
69 // LAMBDA-NEXT: br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
71 // LAMBDA: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 96, i64 1, ptr [[TASK_ENTRY:@[^ ]+]])
72 // LAMBDA: [[PRIVATES:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i{{.+}} 0, i{{.+}} 1
73 // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
74 // LAMBDA: [[G_VAL:%.+]] = load volatile double, ptr @{{.*}}
75 // LAMBDA: store volatile double [[G_VAL]], ptr [[G_PRIVATE_ADDR]]
77 // LAMBDA: [[SIVAR_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
78 // LAMBDA: [[SIVAR_VAL:%.+]] = load i{{[0-9]+}}, ptr @{{.+}},
79 // LAMBDA: store i{{[0-9]+}} [[SIVAR_VAL]], ptr [[SIVAR_PRIVATE_ADDR]]
81 // LAMBDA: call void @__kmpc_taskloop(ptr @{{.+}}, i32 %{{.+}}, ptr [[RES]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr null)
82 // LAMBDA: call {{.*}}void @__kmpc_end_master(
83 // LAMBDA-NEXT: br label {{%?}}[[EXIT]]
86 #pragma omp master taskloop firstprivate(g, sivar)
87 for (int i
= 0; i
< 10; ++i
) {
88 // LAMBDA: define {{.+}} void [[INNER_LAMBDA:@.+]](ptr {{[^,]*}} [[ARG_PTR:%.+]])
89 // LAMBDA: store ptr [[ARG_PTR]], ptr [[ARG_PTR_REF:%.+]],
90 // LAMBDA: [[ARG_PTR:%.+]] = load ptr, ptr [[ARG_PTR_REF]]
91 // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
92 // LAMBDA: [[G_REF:%.+]] = load ptr, ptr [[G_PTR_REF]]
93 // LAMBDA: store volatile double 2.0{{.+}}, ptr [[G_REF]]
95 // LAMBDA: store ptr %{{.+}}, ptr %{{.+}},
96 // LAMBDA: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
99 // LAMBDA: store double 1.0{{.+}}, ptr %{{.+}},
100 // LAMBDA: store i{{[0-9]+}} 11, ptr %{{.+}},
101 // LAMBDA: call void [[INNER_LAMBDA]](ptr
110 #elif defined(BLOCKS)
111 // BLOCKS: [[G:@.+]] ={{.*}} global double
112 // BLOCKS: [[SIVAR:@.+]] = internal global i{{[0-9]+}} 0,
113 // BLOCKS-LABEL: @main
114 // BLOCKS: call void {{%.+}}(ptr
116 // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(ptr
117 // BLOCKS: [[RES:%.+]] = call {{.*}}i32 @__kmpc_master(
118 // BLOCKS-NEXT: [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
119 // BLOCKS-NEXT: br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
121 // BLOCKS: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 96, i64 1, ptr [[TASK_ENTRY:@[^ ]+]])
122 // BLOCKS: [[PRIVATES:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i{{.+}} 0, i{{.+}} 1
123 // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
124 // BLOCKS: [[G_VAL:%.+]] = load volatile double, ptr @{{.+}},
125 // BLOCKS: store volatile double [[G_VAL]], ptr [[G_PRIVATE_ADDR]]
127 // BLOCKS: [[SIVAR_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
128 // BLOCKS: [[SIVAR_VAL:%.+]] = load i{{[0-9]+}}, ptr @{{.+}},
129 // BLOCKS: store i{{[0-9]+}} [[SIVAR_VAL]], ptr [[SIVAR_PRIVATE_ADDR]],
130 // BLOCKS: call void @__kmpc_taskloop(ptr @{{.+}}, i32 %{{.+}}, ptr [[RES]], i32 1, ptr %{{.+}}, ptr %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, ptr null)
131 // BLOCKS: call {{.*}}void @__kmpc_end_master(
132 // BLOCKS-NEXT: br label {{%?}}[[EXIT]]
135 #pragma omp master taskloop firstprivate(g, sivar)
136 for (int i
= 0; i
< 10; ++i
) {
137 // BLOCKS: define {{.+}} void {{@.+}}(ptr
138 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
139 // BLOCKS: store volatile double 2.0{{.+}}, ptr
140 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
141 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
142 // BLOCKS: store i{{[0-9]+}} 22, ptr
143 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
146 // BLOCKS: store ptr %{{.+}}, ptr %{{.+}},
147 // BLOCKS: store ptr %{{.+}}, ptr %{{.+}},
148 // BLOCKS: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
151 // BLOCKS: store double 1.0{{.+}}, ptr %{{.+}},
152 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
153 // BLOCKS: store i{{[0-9]+}} 11, ptr %{{.+}},
154 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
155 // BLOCKS: call void {{%.+}}(ptr
168 S
<double> s_arr
[] = {1, 2};
170 #pragma omp master taskloop firstprivate(var, t_var, s_arr, vec, s_arr, var, sivar)
171 for (int i
= 0; i
< 10; ++i
) {
180 // CHECK: [[SIVAR:.+]] = internal global i{{[0-9]+}} 0,
181 // CHECK: define{{.*}} i{{[0-9]+}} @main()
182 // CHECK: alloca [[S_DOUBLE_TY]],
183 // CHECK: [[TEST:%.+]] = alloca [[S_DOUBLE_TY]],
184 // CHECK: [[T_VAR_ADDR:%.+]] = alloca i32,
185 // CHECK: [[VEC_ADDR:%.+]] = alloca [2 x i32],
186 // CHECK: [[S_ARR_ADDR:%.+]] = alloca [2 x [[S_DOUBLE_TY]]],
187 // CHECK: [[VAR_ADDR:%.+]] = alloca [[S_DOUBLE_TY]],
188 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[LOC:@.+]])
190 // CHECK: call {{.*}} [[S_DOUBLE_TY_COPY_CONSTR:@.+]](ptr {{[^,]*}} [[TEST]],
192 // CHECK: [[RES:%.+]] = call {{.*}}i32 @__kmpc_master(
193 // CHECK-NEXT: [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
194 // CHECK-NEXT: br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:.+]]
196 // Store original variables in capture struct.
197 // CHECK: [[S_ARR_REF:%.+]] = getelementptr inbounds nuw [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
198 // CHECK: store ptr [[S_ARR_ADDR]], ptr [[S_ARR_REF]],
199 // CHECK: [[VAR_REF:%.+]] = getelementptr inbounds nuw [[CAP_MAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 1
200 // CHECK: store ptr [[VAR_ADDR]], ptr [[VAR_REF]],
203 // Returns struct kmp_task_t {
204 // [[KMP_TASK_T]] task_data;
205 // [[KMP_TASK_MAIN_TY]] privates;
207 // CHECK: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[LOC]], i32 [[GTID]], i32 9, i64 120, i64 16, ptr [[TASK_ENTRY:@[^ ]+]])
209 // Fill kmp_task_t->shareds by copying from original capture argument.
210 // CHECK: [[TASK:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
211 // CHECK: [[SHAREDS_REF_ADDR:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
212 // CHECK: [[SHAREDS_REF:%.+]] = load ptr, ptr [[SHAREDS_REF_ADDR]],
213 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[SHAREDS_REF]], ptr align 8 %{{.+}}, i64 16, i1 false)
215 // Initialize kmp_task_t->privates with default values (no init for simple types, default constructors for classes).
216 // Also copy address of private copy to the corresponding shareds reference.
217 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
219 // Constructors for s_arr and var.
221 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
222 // CHECK: call void [[S_DOUBLE_TY_COPY_CONSTR]](ptr {{[^,]*}} [[S_ARR_CUR:%[^,]+]],
223 // CHECK: getelementptr [[S_DOUBLE_TY]], ptr [[S_ARR_CUR]], i{{.+}} 1
224 // CHECK: getelementptr [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} 1
229 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
230 // CHECK-NEXT: call void [[S_DOUBLE_TY_COPY_CONSTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]], ptr {{.*}},
233 // CHECK: [[PRIVATE_T_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
234 // CHECK-NEXT: [[T_VAR:%.+]] = load i32, ptr %{{.+}},
235 // CHECK-NEXT: store i32 [[T_VAR]], ptr [[PRIVATE_T_VAR_REF]],
238 // CHECK: [[PRIVATE_VEC_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
239 // CHECK: call void @llvm.memcpy.p0.p0.i64(
242 // CHECK: [[PRIVATE_SIVAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 4
243 // CHECK-NEXT: [[SIVAR:%.+]] = load i{{.+}}, ptr @{{.+}},
244 // CHECK-NEXT: store i32 [[SIVAR]], ptr [[PRIVATE_SIVAR_REF]],
246 // Provide pointer to destructor function, which will destroy private variables at the end of the task.
247 // CHECK: [[DESTRUCTORS_REF:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{.+}} 0, i{{.+}} 3
248 // CHECK: store ptr [[DESTRUCTORS:@.+]], ptr [[DESTRUCTORS_REF]],
251 // 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:@.+]])
252 // CHECK: call {{.*}}void @__kmpc_end_master(
253 // CHECK-NEXT: br label {{%?}}[[EXIT]]
256 // CHECK: = call noundef i{{.+}} [[TMAIN_INT:@.+]]()
258 // No destructors must be called for private copies of s_arr and var.
259 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
260 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
261 // CHECK: call void [[S_DOUBLE_TY_DESTR:@.+]](ptr
262 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
263 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
267 // 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)
268 // CHECK: [[PRIVATES:%.+]] = load ptr, ptr
269 // CHECK: [[PRIV_S_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 0
270 // CHECK: [[ARG3:%.+]] = load ptr, ptr %{{.+}},
271 // CHECK: store ptr [[PRIV_S_VAR]], ptr [[ARG3]],
272 // CHECK: [[PRIV_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 1
273 // CHECK: [[ARG1:%.+]] = load ptr, ptr {{.+}},
274 // CHECK: store ptr [[PRIV_VAR]], ptr [[ARG1]],
275 // CHECK: [[PRIV_T_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 2
276 // CHECK: [[ARG2:%.+]] = load ptr, ptr %{{.+}},
277 // CHECK: store ptr [[PRIV_T_VAR]], ptr [[ARG2]],
278 // CHECK: [[PRIV_VEC:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 3
279 // CHECK: [[ARG4:%.+]] = load ptr, ptr %{{.+}},
280 // CHECK: store ptr [[PRIV_VEC]], ptr [[ARG4]],
281 // CHECK: [[PRIV_SIVAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 4
282 // CHECK: [[ARG5:%.+]] = load ptr, ptr %{{.+}},
283 // CHECK: store ptr [[PRIV_SIVAR]], ptr [[ARG5]],
286 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
289 // CHECK: [[PRIV_VAR_ADDR:%.+]] = alloca ptr,
290 // CHECK: [[PRIV_T_VAR_ADDR:%.+]] = alloca ptr,
291 // CHECK: [[PRIV_S_ARR_ADDR:%.+]] = alloca ptr,
292 // CHECK: [[PRIV_VEC_ADDR:%.+]] = alloca ptr,
293 // CHECK: [[PRIV_SIVAR_ADDR:%.+]] = alloca ptr,
294 // CHECK: store ptr [[PRIVATES_MAP_FN]], ptr [[MAP_FN_ADDR:%.+]],
295 // CHECK: [[MAP_FN:%.+]] = load ptr, ptr [[MAP_FN_ADDR]],
297 // 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]])
299 // CHECK: [[PRIV_VAR:%.+]] = load ptr, ptr [[PRIV_VAR_ADDR]],
300 // CHECK: [[PRIV_T_VAR:%.+]] = load ptr, ptr [[PRIV_T_VAR_ADDR]],
301 // CHECK: [[PRIV_S_ARR:%.+]] = load ptr, ptr [[PRIV_S_ARR_ADDR]],
302 // CHECK: [[PRIV_VEC:%.+]] = load ptr, ptr [[PRIV_VEC_ADDR]],
303 // CHECK: [[PRIV_SIVAR:%.+]] = load ptr, ptr [[PRIV_SIVAR_ADDR]],
305 // Privates actually are used.
306 // CHECK-DAG: [[PRIV_VAR]]
307 // CHECK-DAG: [[PRIV_T_VAR]]
308 // CHECK-DAG: [[PRIV_S_ARR]]
309 // CHECK-DAG: [[PRIV_VEC]]
310 // CHECK-DAG: [[PRIV_SIVAR]]
314 // CHECK: define internal void [[MAIN_DUP]](ptr noundef %0, ptr noundef %1, i32 noundef %2)
315 // CHECK: getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr %{{.+}}, i32 0, i32 1
316 // CHECK: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr %{{.+}}, i32 0, i32 0
317 // CHECK: getelementptr inbounds [2 x [[S_DOUBLE_TY]]], ptr %{{.+}}, i32 0, i32 0
318 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i64 2
322 // CHECK: call {{.*}} [[S_DOUBLE_TY_COPY_CONSTR]](ptr
323 // CHECK: getelementptr [[S_DOUBLE_TY]], ptr %{{.+}}, i32 1
324 // CHECK: icmp eq ptr %
327 // CHECK: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr %{{.+}}, i32 0, i32 1
328 // CHECK: call {{.*}} [[S_DOUBLE_TY_COPY_CONSTR]](ptr
331 // CHECK: define internal noundef i32 [[DESTRUCTORS]](i32 noundef %0, ptr noalias noundef %1)
332 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES_KMP_TASK:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
333 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
334 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
335 // CHECK: call void [[S_DOUBLE_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
336 // CHECK: getelementptr inbounds [2 x [[S_DOUBLE_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
337 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} 2
338 // CHECK: [[PRIVATE_S_ARR_ELEM_REF:%.+]] = getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} -1
339 // CHECK: call void [[S_DOUBLE_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_S_ARR_ELEM_REF]])
344 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
345 // CHECK: alloca [[S_INT_TY]],
346 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
347 // CHECK: [[T_VAR_ADDR:%.+]] = alloca i32, align 128
348 // CHECK: [[VEC_ADDR:%.+]] = alloca [2 x i32],
349 // CHECK: [[S_ARR_ADDR:%.+]] = alloca [2 x [[S_INT_TY]]],
350 // CHECK: [[VAR_ADDR:%.+]] = alloca [[S_INT_TY]],
351 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[LOC:@.+]])
353 // CHECK: call {{.*}} [[S_INT_TY_COPY_CONSTR:@.+]](ptr {{[^,]*}} [[TEST]],
355 // Store original variables in capture struct.
356 // CHECK: [[S_ARR_REF:%.+]] = getelementptr inbounds nuw [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 0
357 // CHECK: store ptr [[S_ARR_ADDR]], ptr [[S_ARR_REF]],
358 // CHECK: [[VAR_REF:%.+]] = getelementptr inbounds nuw [[CAP_TMAIN_TY]], ptr %{{.+}}, i{{[0-9]+}} 0, i{{[0-9]+}} 1
359 // CHECK: store ptr [[VAR_ADDR]], ptr [[VAR_REF]],
362 // Returns struct kmp_task_t {
363 // [[KMP_TASK_T_TY]] task_data;
364 // [[KMP_TASK_TMAIN_TY]] privates;
366 // CHECK: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[LOC]], i32 [[GTID]], i32 9, i64 256, i64 16, ptr [[TASK_ENTRY:@[^ ]+]])
368 // Fill kmp_task_t->shareds by copying from original capture argument.
369 // CHECK: [[TASK:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
370 // CHECK: [[SHAREDS_REF_ADDR:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
371 // CHECK: [[SHAREDS_REF:%.+]] = load ptr, ptr [[SHAREDS_REF_ADDR]],
372 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[SHAREDS_REF]], ptr align 8 %{{.+}}, i64 16, i1 false)
374 // Initialize kmp_task_t->privates with default values (no init for simple types, default constructors for classes).
375 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
378 // CHECK: [[PRIVATE_T_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
379 // CHECK-NEXT: [[T_VAR:%.+]] = load i32, ptr %{{.+}}, align 128
380 // CHECK-NEXT: store i32 [[T_VAR]], ptr [[PRIVATE_T_VAR_REF]], align 128
383 // CHECK: [[PRIVATE_VEC_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
384 // CHECK: call void @llvm.memcpy.p0.p0.i64(
386 // Constructors for s_arr and var.
388 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
389 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
390 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} 2
391 // CHECK: call void [[S_INT_TY_COPY_CONSTR]](ptr {{[^,]*}} [[S_ARR_CUR:%[^,]+]],
392 // CHECK: getelementptr [[S_INT_TY]], ptr [[S_ARR_CUR]], i{{.+}} 1
397 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
398 // CHECK-NEXT: call void [[S_INT_TY_COPY_CONSTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]],
400 // Provide pointer to destructor function, which will destroy private variables at the end of the task.
401 // CHECK: [[DESTRUCTORS_REF:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{.+}} 0, i{{.+}} 3
402 // CHECK: store ptr [[DESTRUCTORS:@.+]], ptr [[DESTRUCTORS_REF]],
405 // 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:@.+]])
407 // No destructors must be called for private copies of s_arr and var.
408 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
409 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
410 // CHECK: call void [[S_INT_TY_DESTR:@.+]](ptr noundef
411 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
412 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
416 // 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)
417 // CHECK: [[PRIVATES:%.+]] = load ptr, ptr
418 // CHECK: [[PRIV_T_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 0
419 // CHECK: [[ARG1:%.+]] = load ptr, ptr %{{.+}},
420 // CHECK: store ptr [[PRIV_T_VAR]], ptr [[ARG1]],
421 // CHECK: [[PRIV_VEC:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 1
422 // CHECK: [[ARG2:%.+]] = load ptr, ptr %{{.+}},
423 // CHECK: store ptr [[PRIV_VEC]], ptr [[ARG2]],
424 // CHECK: [[PRIV_S_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 2
425 // CHECK: [[ARG3:%.+]] = load ptr, ptr %{{.+}},
426 // CHECK: store ptr [[PRIV_S_VAR]], ptr [[ARG3]],
427 // CHECK: [[PRIV_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 3
428 // CHECK: [[ARG4:%.+]] = load ptr, ptr {{.+}},
429 // CHECK: store ptr [[PRIV_VAR]], ptr [[ARG4]],
432 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
434 // CHECK-DAG: [[PRIV_T_VAR_ADDR:%.+]] = alloca ptr,
435 // CHECK-DAG: [[PRIV_VEC_ADDR:%.+]] = alloca ptr,
436 // CHECK-DAG: [[PRIV_S_ARR_ADDR:%.+]] = alloca ptr,
437 // CHECK-DAG: [[PRIV_VAR_ADDR:%.+]] = alloca ptr,
438 // CHECK: store ptr [[PRIVATES_MAP_FN]], ptr [[MAP_FN_ADDR:%.+]],
439 // CHECK: [[MAP_FN:%.+]] = load ptr, ptr [[MAP_FN_ADDR]],
440 // CHECK: call void [[MAP_FN]](ptr %{{.+}}, ptr [[PRIV_T_VAR_ADDR]], ptr [[PRIV_VEC_ADDR]], ptr [[PRIV_S_ARR_ADDR]], ptr [[PRIV_VAR_ADDR]])
441 // CHECK: [[PRIV_T_VAR:%.+]] = load ptr, ptr [[PRIV_T_VAR_ADDR]],
442 // CHECK: [[PRIV_VEC:%.+]] = load ptr, ptr [[PRIV_VEC_ADDR]],
443 // CHECK: [[PRIV_S_ARR:%.+]] = load ptr, ptr [[PRIV_S_ARR_ADDR]],
444 // CHECK: [[PRIV_VAR:%.+]] = load ptr, ptr [[PRIV_VAR_ADDR]],
446 // Privates actually are used.
447 // CHECK-DAG: [[PRIV_VAR]]
448 // CHECK-DAG: [[PRIV_T_VAR]]
449 // CHECK-DAG: [[PRIV_S_ARR]]
450 // CHECK-DAG: [[PRIV_VEC]]
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 2
456 // CHECK: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 2
457 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr %{{.+}}, i32 0, i32 0
458 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i64 2
462 // CHECK: call {{.*}} [[S_INT_TY_COPY_CONSTR]](ptr
463 // CHECK: getelementptr [[S_INT_TY]], ptr %{{.+}}, i32 1
464 // CHECK: icmp eq ptr %
467 // CHECK: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr %{{.+}}, i32 0, i32 3
468 // CHECK: call {{.*}} [[S_INT_TY_COPY_CONSTR]](ptr
471 // CHECK: define internal noundef i32 [[DESTRUCTORS]](i32 noundef %0, ptr noalias noundef %1)
472 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES_KMP_TASK:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
473 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
474 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
475 // CHECK: call void [[S_INT_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
476 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
477 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} 2
478 // CHECK: [[PRIVATE_S_ARR_ELEM_REF:%.+]] = getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} -1
479 // CHECK: call void [[S_INT_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_S_ARR_ELEM_REF]])
486 // ARRAY-LABEL: array_func
494 void array_func(int n
, float a
[n
], St s
[2]) {
495 // ARRAY: call ptr @__kmpc_omp_task_alloc(
496 // ARRAY: call void @__kmpc_taskloop(
497 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
498 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
499 #pragma omp master taskloop firstprivate(a, s)
500 for (int i
= 0; i
< 10; ++i
)