1 // RUN: %clang_cc1 -fopenmp -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu -fnoopenmp-use-tls -std=c++98 | FileCheck %s
2 
3 // RUN: %clang_cc1 -fopenmp-simd -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu -fnoopenmp-use-tls -std=c++98 | FileCheck --check-prefix SIMD-ONLY0 %s
4 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
5 // expected-no-diagnostics
6 
7 struct S {
8   float a;
SS9   S() : a(0.0f) {}
~SS10   ~S() {}
11 };
12 
13 #pragma omp declare reduction(+:S:omp_out.a += omp_in.a) initializer(omp_priv = omp_orig)
14 
15 float g;
16 
17 int a;
18 #pragma omp threadprivate(a)
main(int argc,char * argv[])19 int main (int argc, char *argv[])
20 {
21 int   i, n;
22 float a[100], b[100], sum, e[argc + 100];
23 S c[100];
24 float &d = g;
25 
26 /* Some initializations */
27 n = 100;
28 for (i=0; i < n; i++)
29   a[i] = b[i] = i * 1.0;
30 sum = 0.0;
31 
32 #pragma omp master taskloop reduction(+:sum, c[:n], d, e)
33   for (i=0; i < n; i++) {
34     sum = sum + (a[i] * b[i]);
35     c[i].a = i*i;
36     d += i*i;
37     e[i] = i;
38   }
39 
40 }
41 
42 // CHECK-LABEL: @main(
43 // CHECK:    [[RETVAL:%.*]] = alloca i32,
44 // CHECK:    [[ARGC_ADDR:%.*]] = alloca i32,
45 // CHECK:    [[ARGV_ADDR:%.*]] = alloca i8**,
46 // CHECK:    [[I:%.*]] = alloca i32,
47 // CHECK:    [[N:%.*]] = alloca i32,
48 // CHECK:    [[A:%.*]] = alloca [100 x float],
49 // CHECK:    [[B:%.*]] = alloca [100 x float],
50 // CHECK:    [[SUM:%.*]] = alloca float,
51 // CHECK:    [[SAVED_STACK:%.*]] = alloca i8*,
52 // CHECK:    [[C:%.*]] = alloca [100 x %struct.S],
53 // CHECK:    [[D:%.*]] = alloca float*,
54 // CHECK:    [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]],
55 // CHECK:    [[DOTRD_INPUT_:%.*]] = alloca [4 x %struct.kmp_taskred_input_t],
56 // CHECK:    alloca i32,
57 // CHECK:    [[DOTCAPTURE_EXPR_:%.*]] = alloca i32,
58 // CHECK:    [[DOTCAPTURE_EXPR_9:%.*]] = alloca i32,
59 // CHECK:    [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t*
60 // CHECK:    store i32 0, i32* [[RETVAL]],
61 // CHECK:    store i32 [[ARGC:%.*]], i32* [[ARGC_ADDR]],
62 // CHECK:    store i8** [[ARGV:%.*]], i8*** [[ARGV_ADDR]],
63 // CHECK:    [[TMP1:%.*]] = load i32, i32* [[ARGC_ADDR]],
64 // CHECK:    [[ADD:%.*]] = add nsw i32 [[TMP1]], 100
65 // CHECK:    [[TMP2:%.*]] = zext i32 [[ADD]] to i64
66 // CHECK:    [[VLA:%.+]] = alloca float, i64 %
67 
68 // CHECK:       [[RES:%.+]] = call {{.*}}i32 @__kmpc_master(
69 // CHECK-NEXT:  [[IS_MASTER:%.+]] = icmp ne i32 [[RES]], 0
70 // CHECK-NEXT:  br i1 [[IS_MASTER]], label {{%?}}[[THEN:.+]], label {{%?}}[[EXIT:[^,]+]]
71 // CHECK:       [[THEN]]
72 // CHECK:    call void @__kmpc_taskgroup(%struct.ident_t*
73 // CHECK-DAG:    [[TMP21:%.*]] = bitcast float* [[SUM]] to i8*
74 // CHECK-DAG:    store i8* [[TMP21]], i8** [[TMP20:%[^,]+]],
75 // CHECK-DAG:    [[TMP20]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_:%.+]], i32 0, i32 0
76 // CHECK-DAG:    [[TMP21:%.*]] = bitcast float* [[SUM]] to i8*
77 // CHECK-DAG:    store i8* [[TMP21]], i8** [[TMP20:%[^,]+]],
78 // CHECK-DAG:    [[TMP20]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 1
79 // CHECK-DAG:    [[TMP22:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 2
80 // CHECK-DAG:    store i64 4, i64* [[TMP22]],
81 // CHECK-DAG:    [[TMP23:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 3
82 // CHECK-DAG:    store i8* bitcast (void (i8*, i8*)* @[[RED_INIT1:.+]] to i8*), i8** [[TMP23]],
83 // CHECK-DAG:    [[TMP24:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 4
84 // CHECK-DAG:    store i8* null, i8** [[TMP24]],
85 // CHECK-DAG:    [[TMP25:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 5
86 // CHECK-DAG:    store i8* bitcast (void (i8*, i8*)* @[[RED_COMB1:.+]] to i8*), i8** [[TMP25]],
87 // CHECK-DAG:    [[TMP26:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 6
88 // CHECK-DAG:    [[TMP27:%.*]] = bitcast i32* [[TMP26]] to i8*
89 // CHECK-DAG:    call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP27]], i8 0, i64 4, i1 false)
90 // CHECK-DAG:    [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 0
91 // CHECK-DAG:    [[LB_ADD_LEN:%.*]] = add nsw i64 -1, %
92 // CHECK-DAG:    [[ARRAYIDX6:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 [[LB_ADD_LEN]]
93 // CHECK-DAG:    [[TMP31:%.*]] = bitcast %struct.S* [[ARRAYIDX5]] to i8*
94 // CHECK-DAG:    store i8* [[TMP31]], i8** [[TMP28:%[^,]+]],
95 // CHECK-DAG:    [[TMP28]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_4:%.+]], i32 0, i32 0
96 // CHECK-DAG:    [[TMP31:%.*]] = bitcast %struct.S* [[ARRAYIDX5]] to i8*
97 // CHECK-DAG:    store i8* [[TMP31]], i8** [[TMP28:%[^,]+]],
98 // CHECK-DAG:    [[TMP28]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 1
99 // CHECK-DAG:    [[TMP32:%.*]] = ptrtoint %struct.S* [[ARRAYIDX6]] to i64
100 // CHECK-DAG:    [[TMP33:%.*]] = ptrtoint %struct.S* [[ARRAYIDX5]] to i64
101 // CHECK-DAG:    [[TMP34:%.*]] = sub i64 [[TMP32]], [[TMP33]]
102 // CHECK-DAG:    [[TMP35:%.*]] = sdiv exact i64 [[TMP34]], ptrtoint (%struct.S* getelementptr (%struct.S, %struct.S* null, i32 1) to i64)
103 // CHECK-DAG:    [[TMP36:%.*]] = add nuw i64 [[TMP35]], 1
104 // CHECK-DAG:    [[TMP37:%.*]] = mul nuw i64 [[TMP36]], ptrtoint (%struct.S* getelementptr (%struct.S, %struct.S* null, i32 1) to i64)
105 // CHECK-DAG:    store i64 [[TMP37]], i64* [[TMP38:%[^,]+]],
106 // CHECK-DAG:    [[TMP38]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 2
107 // CHECK-DAG:    [[TMP39:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 3
108 // CHECK-DAG:    store i8* bitcast (void (i8*, i8*)* @[[RED_INIT2:.+]] to i8*), i8** [[TMP39]],
109 // CHECK-DAG:    [[TMP40:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 4
110 // CHECK-DAG:    store i8* bitcast (void (i8*)* @[[RED_FINI2:.+]] to i8*), i8** [[TMP40]],
111 // CHECK-DAG:    [[TMP41:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 5
112 // CHECK-DAG:    store i8* bitcast (void (i8*, i8*)* @[[RED_COMB2:.+]] to i8*), i8** [[TMP41]],
113 // CHECK-DAG:    [[TMP42:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 6
114 // CHECK-DAG:    store i32 1, i32* [[TMP42]],
115 // CHECK-DAG:    [[TMP44:%.*]] = load float*, float** [[D]],
116 // CHECK-DAG:    [[TMP45:%.*]] = bitcast float* [[TMP44]] to i8*
117 // CHECK-DAG:    store i8* [[TMP45]], i8** [[TMP43:%[^,]+]],
118 // CHECK-DAG:    [[TMP43]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_7:%.+]], i32 0, i32 0
119 // CHECK-DAG:    [[TMP45:%.*]] = bitcast float* [[TMP44]] to i8*
120 // CHECK-DAG:    store i8* [[TMP45]], i8** [[TMP43:%[^,]+]],
121 // CHECK-DAG:    [[TMP43]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 1
122 // CHECK-DAG:    [[TMP46:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 2
123 // CHECK-DAG:    store i64 4, i64* [[TMP46]],
124 // CHECK-DAG:    [[TMP47:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 3
125 // CHECK-DAG:    store i8* bitcast (void (i8*, i8*)* @[[RED_INIT3:.+]] to i8*), i8** [[TMP47]],
126 // CHECK-DAG:    [[TMP48:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 4
127 // CHECK-DAG:    store i8* null, i8** [[TMP48]],
128 // CHECK-DAG:    [[TMP49:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 5
129 // CHECK-DAG:    store i8* bitcast (void (i8*, i8*)* @[[RED_COMB3:.+]] to i8*), i8** [[TMP49]],
130 // CHECK-DAG:    [[TMP50:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 6
131 // CHECK-DAG:    [[TMP51:%.*]] = bitcast i32* [[TMP50]] to i8*
132 // CHECK-DAG:    call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP51]], i8 0, i64 4, i1 false)
133 // CHECK-DAG:    [[TMP53:%.*]] = bitcast float* [[VLA]] to i8*
134 // CHECK-DAG:    store i8* [[TMP53]], i8** [[TMP52:%[^,]+]],
135 // CHECK-DAG:    [[TMP52]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_8:%.+]], i32 0, i32 0
136 // CHECK-DAG:    [[TMP53:%.*]] = bitcast float* [[VLA]] to i8*
137 // CHECK-DAG:    store i8* [[TMP53]], i8** [[TMP52:%[^,]+]],
138 // CHECK-DAG:    [[TMP52]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 1
139 // CHECK-DAG:    [[TMP54:%.*]] = mul nuw i64 [[TMP2]], 4
140 // CHECK-DAG:    [[TMP55:%.*]] = udiv exact i64 [[TMP54]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
141 // CHECK-DAG:    store i64 [[TMP54]], i64* [[TMP56:%[^,]+]],
142 // CHECK-DAG:    [[TMP56]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 2
143 // CHECK-DAG:    [[TMP57:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 3
144 // CHECK-DAG:    store i8* bitcast (void (i8*, i8*)* @[[RED_INIT4:.+]] to i8*), i8** [[TMP57]],
145 // CHECK-DAG:    [[TMP58:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 4
146 // CHECK-DAG:    store i8* null, i8** [[TMP58]],
147 // CHECK-DAG:    [[TMP59:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 5
148 // CHECK-DAG:    store i8* bitcast (void (i8*, i8*)* @[[RED_COMB4:.+]] to i8*), i8** [[TMP59]],
149 // CHECK-DAG:    [[TMP60:%.*]] = getelementptr inbounds %struct.kmp_taskred_input_t, %struct.kmp_taskred_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 6
150 // CHECK-DAG:    store i32 1, i32* [[TMP60]],
151 // CHECK-DAG:    [[DOTRD_INPUT_GEP_]] = getelementptr inbounds [4 x %struct.kmp_taskred_input_t], [4 x %struct.kmp_taskred_input_t]* [[DOTRD_INPUT_]], i64 0, i64
152 // CHECK-DAG:    [[DOTRD_INPUT_GEP_4]] = getelementptr inbounds [4 x %struct.kmp_taskred_input_t], [4 x %struct.kmp_taskred_input_t]* [[DOTRD_INPUT_]], i64 0, i64
153 // CHECK-DAG:    [[DOTRD_INPUT_GEP_7]] = getelementptr inbounds [4 x %struct.kmp_taskred_input_t], [4 x %struct.kmp_taskred_input_t]* [[DOTRD_INPUT_]], i64 0, i64
154 // CHECK-DAG:    [[DOTRD_INPUT_GEP_8]] = getelementptr inbounds [4 x %struct.kmp_taskred_input_t], [4 x %struct.kmp_taskred_input_t]* [[DOTRD_INPUT_]], i64 0, i64
155 // CHECK:    [[TMP61:%.*]] = bitcast [4 x %struct.kmp_taskred_input_t]* [[DOTRD_INPUT_]] to i8*
156 // CHECK:    [[TMP62:%.*]] = call i8* @__kmpc_taskred_init(i32 [[TMP0]], i32 4, i8* [[TMP61]])
157 // CHECK:    [[TMP63:%.*]] = load i32, i32* [[N]],
158 // CHECK:    store i32 [[TMP63]], i32* [[DOTCAPTURE_EXPR_]],
159 // CHECK:    [[TMP64:%.*]] = load i32, i32* [[DOTCAPTURE_EXPR_]],
160 // CHECK:    [[SUB:%.*]] = sub nsw i32 [[TMP64]], 0
161 // CHECK:    [[DIV:%.*]] = sdiv i32 [[SUB]], 1
162 // CHECK:    [[SUB12:%.*]] = sub nsw i32 [[DIV]], 1
163 // CHECK:    store i32 [[SUB12]], i32* [[DOTCAPTURE_EXPR_9]],
164 // CHECK:    [[TMP65:%.*]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* {{.+}}, i32 [[TMP0]], i32 1, i64 888, i64 40, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* @[[TASK:.+]] to i32 (i32, i8*)*))
165 // CHECK:    call void @__kmpc_taskloop(%struct.ident_t* {{.+}}, i32 [[TMP0]], i8* [[TMP65]], i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, i8* null)
166 // CHECK:    call void @__kmpc_end_taskgroup(%struct.ident_t*
167 // CHECK:  call {{.*}}void @__kmpc_end_master(
168 // CHECK-NEXT:  br label {{%?}}[[EXIT]]
169 // CHECK:       [[EXIT]]
170 
171 // CHECK:    ret i32
172 
173 // CHECK: define internal void @[[RED_INIT1]](i8* noalias %{{.+}}, i8* noalias %{{.+}})
174 // CHECK: store float 0.000000e+00, float* %
175 // CHECK: ret void
176 
177 // CHECK: define internal void @[[RED_COMB1]](i8* %0, i8* %1)
178 // CHECK: fadd float %
179 // CHECK: store float %{{.+}}, float* %
180 // CHECK: ret void
181 
182 // CHECK: define internal void @[[RED_INIT2]](i8* noalias %{{.+}}, i8* noalias %{{.+}})
183 // CHECK: call i8* @__kmpc_threadprivate_cached(
184 // CHECK-NOT: call i8* @__kmpc_threadprivate_cached(
185 // CHECK: call void [[OMP_INIT1:@.+]](
186 // CHECK: ret void
187 
188 // CHECK: define internal void [[OMP_COMB1:@.+]](%struct.S* noalias %0, %struct.S* noalias %1)
189 // CHECK: fadd float %
190 
191 // CHECK: define internal void [[OMP_INIT1]](%struct.S* noalias %0, %struct.S* noalias %1)
192 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(
193 
194 // CHECK: define internal void @[[RED_FINI2]](i8* %0)
195 // CHECK: call i8* @__kmpc_threadprivate_cached(
196 // CHECK: call void @
197 // CHECK: ret void
198 
199 // CHECK: define internal void @[[RED_COMB2]](i8* %0, i8* %1)
200 // CHECK: call i8* @__kmpc_threadprivate_cached(
201 // CHECK: call void [[OMP_COMB1]](
202 // CHECK: ret void
203 
204 // CHECK: define internal void @[[RED_INIT3]](i8* noalias %{{.+}}, i8* noalias %{{.+}})
205 // CHECK: store float 0.000000e+00, float* %
206 // CHECK: ret void
207 
208 // CHECK: define internal void @[[RED_COMB3]](i8* %0, i8* %1)
209 // CHECK: fadd float %
210 // CHECK: store float %{{.+}}, float* %
211 // CHECK: ret void
212 
213 // CHECK: define internal void @[[RED_INIT4]](i8* noalias %{{.+}}, i8* noalias %{{.+}})
214 // CHECK: call i8* @__kmpc_threadprivate_cached(
215 // CHECK: store float 0.000000e+00, float* %
216 // CHECK: ret void
217 
218 // CHECK: define internal void @[[RED_COMB4]](i8* %0, i8* %1)
219 // CHECK: call i8* @__kmpc_threadprivate_cached(
220 // CHECK: fadd float %
221 // CHECK: store float %{{.+}}, float* %
222 // CHECK: ret void
223 
224 // CHECK-NOT: call i8* @__kmpc_threadprivate_cached(
225 // CHECK: call i8* @__kmpc_task_reduction_get_th_data(
226 // CHECK: call i8* @__kmpc_threadprivate_cached(
227 // CHECK: call i8* @__kmpc_task_reduction_get_th_data(
228 // CHECK-NOT: call i8* @__kmpc_threadprivate_cached(
229 // CHECK: call i8* @__kmpc_task_reduction_get_th_data(
230 // CHECK: call i8* @__kmpc_threadprivate_cached(
231 // CHECK: call i8* @__kmpc_task_reduction_get_th_data(
232 // CHECK-NOT: call i8* @__kmpc_threadprivate_cached(
233 
234 // CHECK-DAG: distinct !DISubprogram(linkageName: "[[TASK]]", scope: !
235 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT1]]"
236 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB1]]"
237 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT2]]"
238 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_FINI2]]"
239 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB2]]"
240 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT3]]"
241 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB3]]"
242 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT4]]"
243 // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB4]]"
244