[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / task_firstprivate_codegen.cpp
blob49652f58fac5d15b7862c70314a894a625294937
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
16 #ifndef ARRAY
17 #ifndef HEADER
18 #define HEADER
20 template <class T>
21 struct S {
22 T f;
23 S(T a) : f(a) {}
24 S() : f() {}
25 S(const S &s, T t = T()) : f(s.f + t) {}
26 operator T() { return T(); }
27 ~S() {}
30 volatile double g;
32 // CHECK-DAG: [[KMP_TASK_T_TY:%.+]] = type { ptr, ptr, i32, %union{{.+}}, %union{{.+}} }
33 // CHECK-DAG: [[S_DOUBLE_TY:%.+]] = type { double }
34 // CHECK-DAG: [[PRIVATES_MAIN_TY:%.+]] = type {{.?}}{ [2 x [[S_DOUBLE_TY]]], [[S_DOUBLE_TY]], i32, [2 x i32]
35 // CHECK-DAG: [[CAP_MAIN_TY:%.+]] = type { i8 }
36 // CHECK-DAG: [[KMP_TASK_MAIN_TY:%.+]] = type { [[KMP_TASK_T_TY]], [[PRIVATES_MAIN_TY]] }
37 // CHECK-DAG: [[S_INT_TY:%.+]] = type { i32 }
38 // CHECK-DAG: [[CAP_TMAIN_TY:%.+]] = type { i8 }
39 // CHECK-DAG: [[PRIVATES_TMAIN_TY:%.+]] = type { i32, [2 x i32], [2 x [[S_INT_TY]]], [[S_INT_TY]], [104 x i8] }
40 // CHECK-DAG: [[KMP_TASK_TMAIN_TY:%.+]] = type { [[KMP_TASK_T_TY]], [{{[0-9]+}} x i8], [[PRIVATES_TMAIN_TY]] }
41 template <typename T>
42 T tmain() {
43 S<T> ttt;
44 S<T> test(ttt);
45 T t_var __attribute__((aligned(128))) = T();
46 T vec[] = {1, 2};
47 S<T> s_arr[] = {1, 2};
48 S<T> var(3);
49 #pragma omp task firstprivate(t_var, vec, s_arr, s_arr, var, var)
51 vec[0] = t_var;
52 s_arr[0] = var;
54 return T();
57 int main() {
58 static int sivar;
59 float local = 0;
60 #ifdef LAMBDA
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:@.+]](
65 [&]() {
66 // LAMBDA: define{{.*}} internal{{.*}} void [[OUTER_LAMBDA]](
67 // LAMBDA: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 56, i64 1, ptr [[TASK_ENTRY:@.+]])
68 // LAMBDA: [[PRIVATES:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i{{.+}} 0, i{{.+}} 1
69 // LAMBDA: [[G_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
70 // LAMBDA: [[G_VAL:%.+]] = load volatile double, ptr [[G]],
71 // LAMBDA: store volatile double [[G_VAL]], ptr [[G_PRIVATE_ADDR]]
73 // LAMBDA: [[SIVAR_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
74 // LAMBDA: [[SIVAR_VAL:%.+]] = load i{{[0-9]+}}, ptr [[SIVAR]],
75 // LAMBDA: store i{{[0-9]+}} [[SIVAR_VAL]], ptr [[SIVAR_PRIVATE_ADDR]]
77 // LAMBDA: [[LOCAL_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
78 // LAMBDA: store float %{{.+}}, ptr [[LOCAL_PRIVATE_ADDR]]
80 // LAMBDA: call i32 @__kmpc_omp_task(ptr @{{.+}}, i32 %{{.+}}, ptr [[RES]])
81 // LAMBDA: ret
82 #pragma omp task firstprivate(g, sivar, local)
84 // LAMBDA: define {{.+}} void [[INNER_LAMBDA:@.+]]({{.+}} [[ARG_PTR:%.+]])
85 // LAMBDA: store ptr [[ARG_PTR]], ptr [[ARG_PTR_REF:%.+]],
86 // LAMBDA: [[ARG_PTR:%.+]] = load ptr, ptr [[ARG_PTR_REF]]
87 // LAMBDA: [[G_PTR_REF:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[ARG_PTR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
88 // LAMBDA: [[G_REF:%.+]] = load ptr, ptr [[G_PTR_REF]]
89 // LAMBDA: store volatile double 2.0{{.+}}, ptr [[G_REF]]
91 // LAMBDA: store ptr %{{.+}}, ptr %{{.+}},
92 // LAMBDA: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
93 g = 1;
94 sivar = 11;
95 // LAMBDA: store double 1.0{{.+}}, ptr %{{.+}},
96 // LAMBDA: store i{{[0-9]+}} 11, ptr %{{.+}},
97 // LAMBDA: call void [[INNER_LAMBDA]]({{.+}}
98 // LAMBDA: ret
99 [&]() {
100 g = 2;
101 sivar = 22;
102 }();
104 }();
105 return 0;
106 #elif defined(BLOCKS)
107 // BLOCKS: [[G:@.+]] ={{.*}} global double
108 // BLOCKS: [[SIVAR:@.+]] = internal global i{{[0-9]+}} 0,
109 // BLOCKS-LABEL: @main
110 // BLOCKS: call void {{%.+}}(ptr
112 // BLOCKS: define{{.*}} internal{{.*}} void {{.+}}(ptr
113 // BLOCKS: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr @{{[^,]+}}, i32 %{{[^,]+}}, i32 1, i64 56, i64 1, ptr [[TASK_ENTRY:@[^ ]+]])
114 // BLOCKS: [[PRIVATES:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i{{.+}} 0, i{{.+}} 1
115 // BLOCKS: [[G_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
116 // BLOCKS: [[G_VAL:%.+]] = load volatile double, ptr [[G]],
117 // BLOCKS: store volatile double [[G_VAL]], ptr [[G_PRIVATE_ADDR]]
119 // BLOCKS: [[SIVAR_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
120 // BLOCKS: [[SIVAR_VAL:%.+]] = load i{{[0-9]+}}, ptr [[SIVAR]],
121 // BLOCKS: store i{{[0-9]+}} [[SIVAR_VAL]], ptr [[SIVAR_PRIVATE_ADDR]],
123 // BLOCKS: [[LOCAL_PRIVATE_ADDR:%.+]] = getelementptr inbounds nuw %{{.+}}, ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
124 // BLOCKS: store float %{{.+}}, ptr [[LOCAL_PRIVATE_ADDR]]
126 // BLOCKS: call i32 @__kmpc_omp_task(ptr @{{.+}}, i32 %{{.+}}, ptr [[RES]])
127 // BLOCKS: ret
128 #pragma omp task firstprivate(g, sivar, local)
130 // BLOCKS: define {{.+}} void {{@.+}}(ptr
131 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
132 // BLOCKS: store volatile double 2.0{{.+}}, ptr
133 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
134 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
135 // BLOCKS: store i{{[0-9]+}} 22, ptr
136 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
137 // BLOCKS: ret
139 // BLOCKS: store ptr %{{.+}}, ptr %{{.+}},
140 // BLOCKS: store ptr %{{.+}}, ptr %{{.+}},
141 // BLOCKS: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
142 g = 1;
143 sivar = 11;
144 // BLOCKS: store double 1.0{{.+}}, ptr %{{.+}},
145 // BLOCKS-NOT: [[G]]{{[[^:word:]]}}
146 // BLOCKS: store i{{[0-9]+}} 11, ptr %{{.+}},
147 // BLOCKS-NOT: [[SIVAR]]{{[[^:word:]]}}
148 // BLOCKS: call void {{%.+}}(ptr
150 g = 2;
151 sivar = 22;
152 }();
154 }();
155 return 0;
156 #else
157 S<double> ttt;
158 S<double> test(ttt);
159 int t_var = 0;
160 int vec[] = {1, 2};
161 S<double> s_arr[] = {1, 2};
162 S<double> var(3);
163 #pragma omp task firstprivate(t_var, s_arr, vec, sivar)
165 var.f = 1;
166 vec[0] = t_var;
167 s_arr[0] = S<double>(3);
168 sivar = 33;
170 return tmain<int>();
171 #endif
174 // CHECK: [[SIVAR_ADDR:.+]] = internal global i{{[0-9]+}} 0,
175 // CHECK: define{{.*}} i{{[0-9]+}} @main()
176 // CHECK: alloca [[S_DOUBLE_TY]],
177 // CHECK: [[TEST:%.+]] = alloca [[S_DOUBLE_TY]],
178 // CHECK: [[T_VAR_ADDR:%.+]] = alloca i32,
179 // CHECK: [[VEC_ADDR:%.+]] = alloca [2 x i32],
180 // CHECK: [[S_ARR_ADDR:%.+]] = alloca [2 x [[S_DOUBLE_TY]]],
181 // CHECK: [[VAR_ADDR:%.+]] = alloca [[S_DOUBLE_TY]],
182 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[LOC:@.+]])
184 // CHECK: call {{.*}} [[S_DOUBLE_TY_COPY_CONSTR:@.+]](ptr {{[^,]*}} [[TEST]],
186 // Allocate task.
187 // Returns struct kmp_task_t {
188 // [[KMP_TASK_T]] task_data;
189 // [[KMP_TASK_MAIN_TY]] privates;
190 // };
191 // CHECK: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[LOC]], i32 [[GTID]], i32 9, i64 80, i64 1, ptr [[TASK_ENTRY:@[^ ]+]])
192 // CHECK: [[TASK:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES]], i{{.+}} 0, i{{.+}} 0
194 // Initialize kmp_task_t->privates with default values (no init for simple types, default constructors for classes).
195 // Also copy address of private copy to the corresponding shareds reference.
196 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
198 // Constructors for s_arr and var.
199 // s_arr;
200 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
201 // CHECK: call void [[S_DOUBLE_TY_COPY_CONSTR]](ptr {{[^,]*}} [[S_ARR_CUR:%[^,]+]],
202 // CHECK: getelementptr [[S_DOUBLE_TY]], ptr [[S_ARR_CUR]], i{{.+}} 1
203 // CHECK: getelementptr [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} 1
204 // CHECK: icmp eq
205 // CHECK: br i1
207 // var;
208 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
209 // CHECK-NEXT: call void [[S_DOUBLE_TY_COPY_CONSTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]], ptr {{.*}}[[VAR_ADDR]],
211 // t_var;
212 // CHECK: [[PRIVATE_T_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
213 // CHECK-NEXT: [[T_VAR:%.+]] = load i32, ptr [[T_VAR_ADDR]],
214 // CHECK-NEXT: store i32 [[T_VAR]], ptr [[PRIVATE_T_VAR_REF]],
216 // vec;
217 // CHECK: [[PRIVATE_VEC_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
218 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(
220 // sivar;
221 // CHECK: [[PRIVATE_SIVAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 4
222 // CHECK-NEXT: [[SIVAR:%.+]] = load i32, ptr [[SIVAR_ADDR]],
223 // CHECK-NEXT: store i32 [[SIVAR]], ptr [[PRIVATE_SIVAR_REF]],
225 // Provide pointer to destructor function, which will destroy private variables at the end of the task.
226 // CHECK: [[DESTRUCTORS_REF:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{.+}} 0, i{{.+}} 3
227 // CHECK: store ptr [[DESTRUCTORS:@.+]], ptr [[DESTRUCTORS_REF]],
229 // Start task.
230 // CHECK: call i32 @__kmpc_omp_task(ptr [[LOC]], i32 [[GTID]], ptr [[RES]])
232 // CHECK: = call noundef i{{.+}} [[TMAIN_INT:@.+]]()
234 // No destructors must be called for private copies of s_arr and var.
235 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
236 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
237 // CHECK: call void [[S_DOUBLE_TY_DESTR:@.+]](ptr
238 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
239 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
240 // CHECK: ret
243 // 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)
244 // CHECK: [[PRIVATES:%.+]] = load ptr, ptr
245 // CHECK: [[PRIV_S_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 0
246 // CHECK: [[ARG3:%.+]] = load ptr, ptr %{{.+}},
247 // CHECK: store ptr [[PRIV_S_VAR]], ptr [[ARG3]],
248 // CHECK: [[PRIV_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 1
249 // CHECK: [[ARG1:%.+]] = load ptr, ptr {{.+}},
250 // CHECK: store ptr [[PRIV_VAR]], ptr [[ARG1]],
251 // CHECK: [[PRIV_T_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 2
252 // CHECK: [[ARG2:%.+]] = load ptr, ptr %{{.+}},
253 // CHECK: store ptr [[PRIV_T_VAR]], ptr [[ARG2]],
254 // CHECK: [[PRIV_VEC:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 3
255 // CHECK: [[ARG4:%.+]] = load ptr, ptr %{{.+}},
256 // CHECK: store ptr [[PRIV_VEC]], ptr [[ARG4]],
257 // CHECK: [[PRIV_SIVAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i32 0, i32 4
258 // CHECK: [[ARG5:%.+]] = load ptr, ptr %{{.+}},
259 // CHECK: store ptr [[PRIV_SIVAR]], ptr [[ARG5]],
260 // CHECK: ret void
262 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
264 // CHECK: %__context
265 // CHECK: [[PRIV_T_VAR_ADDR:%.+]] = alloca ptr,
266 // CHECK: [[PRIV_S_ARR_ADDR:%.+]] = alloca ptr,
267 // CHECK: [[PRIV_VEC_ADDR:%.+]] = alloca ptr,
268 // CHECK: [[PRIV_SIVAR_ADDR:%.+]] = alloca ptr,
269 // CHECK: [[PRIV_VAR_ADDR:%.+]] = alloca ptr,
270 // CHECK: store ptr [[PRIVATES_MAP_FN]], ptr [[MAP_FN_ADDR:%.+]],
271 // CHECK: [[MAP_FN:%.+]] = load ptr, ptr [[MAP_FN_ADDR]],
273 // CHECK: call void [[MAP_FN]](ptr %{{.+}}, ptr [[PRIV_T_VAR_ADDR]], ptr [[PRIV_S_ARR_ADDR]], ptr [[PRIV_VEC_ADDR]], ptr [[PRIV_SIVAR_ADDR]], ptr [[PRIV_VAR_ADDR]])
275 // CHECK: [[PRIV_T_VAR:%.+]] = load ptr, ptr [[PRIV_T_VAR_ADDR]],
276 // CHECK: [[PRIV_S_ARR:%.+]] = load ptr, ptr [[PRIV_S_ARR_ADDR]],
277 // CHECK: [[PRIV_VEC:%.+]] = load ptr, ptr [[PRIV_VEC_ADDR]],
278 // CHECK: [[PRIV_SIVAR:%.+]] = load ptr, ptr [[PRIV_SIVAR_ADDR]],
279 // CHECK: [[PRIV_VAR:%.+]] = load ptr, ptr [[PRIV_VAR_ADDR]],
281 // Privates actually are used.
282 // CHECK-DAG: [[PRIV_VAR]]
283 // CHECK-DAG: [[PRIV_T_VAR]]
284 // CHECK-DAG: [[PRIV_S_ARR]]
285 // CHECK-DAG: [[PRIV_VEC]]
286 // CHECK-DAG: [[PRIV_SIVAR]]
288 // CHECK: ret
290 // CHECK: define internal noundef i32 [[DESTRUCTORS]](i32 noundef %0, ptr noalias noundef %1)
291 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_MAIN_TY]], ptr [[RES_KMP_TASK:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
292 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
293 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_MAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
294 // CHECK: call void [[S_DOUBLE_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
295 // CHECK: getelementptr inbounds [2 x [[S_DOUBLE_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
296 // CHECK: getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} 2
297 // CHECK: [[PRIVATE_S_ARR_ELEM_REF:%.+]] = getelementptr inbounds [[S_DOUBLE_TY]], ptr %{{.+}}, i{{.+}} -1
298 // CHECK: call void [[S_DOUBLE_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_S_ARR_ELEM_REF]])
299 // CHECK: icmp eq
300 // CHECK: br i1
301 // CHECK: ret i32
303 // CHECK: define {{.*}} i{{[0-9]+}} [[TMAIN_INT]]()
304 // CHECK: alloca [[S_INT_TY]],
305 // CHECK: [[TEST:%.+]] = alloca [[S_INT_TY]],
306 // CHECK: [[T_VAR_ADDR:%.+]] = alloca i32, align 128
307 // CHECK: [[VEC_ADDR:%.+]] = alloca [2 x i32],
308 // CHECK: [[S_ARR_ADDR:%.+]] = alloca [2 x [[S_INT_TY]]],
309 // CHECK: [[VAR_ADDR:%.+]] = alloca [[S_INT_TY]],
310 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(ptr [[LOC:@.+]])
312 // CHECK: call {{.*}} [[S_INT_TY_COPY_CONSTR:@.+]](ptr {{[^,]*}} [[TEST]],
314 // Allocate task.
315 // Returns struct kmp_task_t {
316 // [[KMP_TASK_T_TY]] task_data;
317 // [[KMP_TASK_TMAIN_TY]] privates;
318 // };
319 // CHECK: [[RES:%.+]] = call ptr @__kmpc_omp_task_alloc(ptr [[LOC]], i32 [[GTID]], i32 9, i64 256, i64 1, ptr [[TASK_ENTRY:@[^ ]+]])
320 // CHECK: [[TASK:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
322 // Initialize kmp_task_t->privates with default values (no init for simple types, default constructors for classes).
323 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
325 // t_var;
326 // CHECK: [[PRIVATE_T_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 0
327 // CHECK-NEXT: [[T_VAR:%.+]] = load i32, ptr [[T_VAR_ADDR]], align 128
328 // CHECK-NEXT: store i32 [[T_VAR]], ptr [[PRIVATE_T_VAR_REF]], align 128
330 // vec;
331 // CHECK: [[PRIVATE_VEC_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 1
332 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(
334 // Constructors for s_arr and var.
335 // a_arr;
336 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
337 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
338 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} 2
339 // CHECK: call void [[S_INT_TY_COPY_CONSTR]](ptr {{[^,]*}} [[S_ARR_CUR:%[^,]+]],
340 // CHECK: getelementptr [[S_INT_TY]], ptr [[S_ARR_CUR]], i{{.+}} 1
341 // CHECK: icmp eq
342 // CHECK: br i1
344 // var;
345 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
346 // CHECK-NEXT: call void [[S_INT_TY_COPY_CONSTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]],
348 // Provide pointer to destructor function, which will destroy private variables at the end of the task.
349 // CHECK: [[DESTRUCTORS_REF:%.+]] = getelementptr inbounds nuw [[KMP_TASK_T_TY]], ptr [[TASK]], i{{.+}} 0, i{{.+}} 3
350 // CHECK: store ptr [[DESTRUCTORS:@.+]], ptr [[DESTRUCTORS_REF]],
352 // Start task.
353 // CHECK: call i32 @__kmpc_omp_task(ptr [[LOC]], i32 [[GTID]], ptr [[RES]])
355 // No destructors must be called for private copies of s_arr and var.
356 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
357 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
358 // CHECK: call void [[S_INT_TY_DESTR:@.+]](ptr
359 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
360 // CHECK-NOT: getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
361 // CHECK: ret
364 // 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)
365 // CHECK: [[PRIVATES:%.+]] = load ptr, ptr
366 // CHECK: [[PRIV_T_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 0
367 // CHECK: [[ARG1:%.+]] = load ptr, ptr %{{.+}},
368 // CHECK: store ptr [[PRIV_T_VAR]], ptr [[ARG1]],
369 // CHECK: [[PRIV_VEC:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 1
370 // CHECK: [[ARG2:%.+]] = load ptr, ptr %{{.+}},
371 // CHECK: store ptr [[PRIV_VEC]], ptr [[ARG2]],
372 // CHECK: [[PRIV_S_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 2
373 // CHECK: [[ARG3:%.+]] = load ptr, ptr %{{.+}},
374 // CHECK: store ptr [[PRIV_S_VAR]], ptr [[ARG3]],
375 // CHECK: [[PRIV_VAR:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i32 0, i32 3
376 // CHECK: [[ARG4:%.+]] = load ptr, ptr {{.+}},
377 // CHECK: store ptr [[PRIV_VAR]], ptr [[ARG4]],
378 // CHECK: ret void
380 // CHECK: define internal noundef i32 [[TASK_ENTRY]](i32 noundef %0, ptr noalias noundef %1)
381 // CHECK: %__context
382 // CHECK-DAG: [[PRIV_T_VAR_ADDR:%.+]] = alloca ptr,
383 // CHECK-DAG: [[PRIV_VEC_ADDR:%.+]] = alloca ptr,
384 // CHECK-DAG: [[PRIV_S_ARR_ADDR:%.+]] = alloca ptr,
385 // CHECK-DAG: [[PRIV_VAR_ADDR:%.+]] = alloca ptr,
386 // CHECK: store ptr [[PRIVATES_MAP_FN]], ptr [[MAP_FN_ADDR:%.+]],
387 // CHECK: [[MAP_FN:%.+]] = load ptr, ptr [[MAP_FN_ADDR]],
388 // CHECK: call void [[MAP_FN]](ptr %{{.+}}, ptr [[PRIV_T_VAR_ADDR]], ptr [[PRIV_VEC_ADDR]], ptr [[PRIV_S_ARR_ADDR]], ptr [[PRIV_VAR_ADDR]])
389 // CHECK: [[PRIV_T_VAR:%.+]] = load ptr, ptr [[PRIV_T_VAR_ADDR]],
390 // CHECK: [[PRIV_VEC:%.+]] = load ptr, ptr [[PRIV_VEC_ADDR]],
391 // CHECK: [[PRIV_S_ARR:%.+]] = load ptr, ptr [[PRIV_S_ARR_ADDR]],
392 // CHECK: [[PRIV_VAR:%.+]] = load ptr, ptr [[PRIV_VAR_ADDR]],
394 // Privates actually are used.
395 // CHECK-DAG: [[PRIV_VAR]]
396 // CHECK-DAG: [[PRIV_T_VAR]]
397 // CHECK-DAG: [[PRIV_S_ARR]]
398 // CHECK-DAG: [[PRIV_VEC]]
400 // CHECK: ret
402 // CHECK: define internal noundef i32 [[DESTRUCTORS]](i32 noundef %0, ptr noalias noundef %1)
403 // CHECK: [[PRIVATES:%.+]] = getelementptr inbounds nuw [[KMP_TASK_TMAIN_TY]], ptr [[RES_KMP_TASK:%.+]], i{{[0-9]+}} 0, i{{[0-9]+}} 2
404 // CHECK: [[PRIVATE_S_ARR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 2
405 // CHECK: [[PRIVATE_VAR_REF:%.+]] = getelementptr inbounds nuw [[PRIVATES_TMAIN_TY]], ptr [[PRIVATES]], i{{.+}} 0, i{{.+}} 3
406 // CHECK: call void [[S_INT_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_VAR_REF]])
407 // CHECK: getelementptr inbounds [2 x [[S_INT_TY]]], ptr [[PRIVATE_S_ARR_REF]], i{{.+}} 0, i{{.+}} 0
408 // CHECK: getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} 2
409 // CHECK: [[PRIVATE_S_ARR_ELEM_REF:%.+]] = getelementptr inbounds [[S_INT_TY]], ptr %{{.+}}, i{{.+}} -1
410 // CHECK: call void [[S_INT_TY_DESTR]](ptr {{[^,]*}} [[PRIVATE_S_ARR_ELEM_REF]])
411 // CHECK: icmp eq
412 // CHECK: br i1
413 // CHECK: ret i32
415 #endif
416 #else
417 // ARRAY-LABEL: array_func
418 struct St {
419 int a, b;
420 St() : a(0), b(0) {}
421 St(const St &) {}
422 ~St() {}
425 void array_func(int n, float a[n], St s[2], int(& p)[1]) {
426 // ARRAY: call ptr @__kmpc_omp_task_alloc(
427 // ARRAY: call i32 @__kmpc_omp_task(
428 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
429 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
430 // ARRAY: store ptr %{{.+}}, ptr %{{.+}},
431 #pragma omp task firstprivate(a, s, p)
434 #endif