Clang Project

clang_source_code/test/OpenMP/taskgroup_task_reduction_codegen.cpp
1// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -x c++ -emit-llvm %s -o - | FileCheck %s
2// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
3// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4// RUN: %clang_cc1 -fopenmp -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple x86_64-apple-darwin10 | FileCheck %s --check-prefix=CHECK --check-prefix=DEBUG
5
6// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -x c++ -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
7// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -emit-pch -o %t %s
8// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-apple-darwin10 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
9// RUN: %clang_cc1 -fopenmp-simd -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple x86_64-apple-darwin10 | FileCheck --check-prefix SIMD-ONLY0 %s
10// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
11// expected-no-diagnostics
12#ifndef HEADER
13#define HEADER
14
15// CHECK-DAG: @reduction_size.[[ID:.+]]_[[CID:[0-9]+]].artificial.
16// CHECK-DAG: @reduction_size.[[ID]]_[[CID]].artificial..cache.
17
18struct S {
19  int a;
20  S() : a(0) {}
21  S(const S&) {}
22  S& operator=(const S&) {return *this;}
23  ~S() {}
24  friend S operator+(const S&a, const S&b) {return a;}
25};
26
27int main(int argc, char **argv) {
28  int a;
29  float b;
30  S c[5];
31  short d[argc];
32#pragma omp taskgroup task_reduction(+: a, b, argc)
33  {
34#pragma omp taskgroup task_reduction(-:c, d)
35    ;
36  }
37  return 0;
38}
39// CHECK-LABEL: @main
40// CHECK:       alloca i32,
41// CHECK:       [[ARGC_ADDR:%.+]] = alloca i32,
42// CHECK:       [[ARGV_ADDR:%.+]] = alloca i8**,
43// CHECK:       [[A:%.+]] = alloca i32,
44// CHECK:       [[B:%.+]] = alloca float,
45// CHECK:       [[C:%.+]] = alloca [5 x %struct.S],
46// CHECK:       [[RD_IN1:%.+]] = alloca [3 x [[T1:%[^,]+]]],
47// CHECK:       [[TD1:%.+]] = alloca i8*,
48// CHECK:       [[RD_IN2:%.+]] = alloca [2 x [[T2:%[^,]+]]],
49// CHECK:       [[TD2:%.+]] = alloca i8*,
50
51// CHECK:       [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%struct.ident_t*
52// CHECK:       [[VLA:%.+]] = alloca i16, i64 [[VLA_SIZE:%[^,]+]],
53
54// CHECK:       call void @__kmpc_taskgroup(%struct.ident_t* {{[^,]+}}, i32 [[GTID]])
55// CHECK-DAG:   [[BC_A:%.+]] = bitcast i32* [[A]] to i8*
56// CHECK-DAG:   store i8* [[BC_A]], i8** [[A_REF:[^,]+]],
57// CHECK-DAG:   [[A_REF]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPA:%[^,]+]], i32 0, i32 0
58// CHECK-DAG:   [[GEPA]] = getelementptr inbounds [3 x [[T1]]], [3 x [[T1]]]* [[RD_IN1]], i64 0, i64
59// CHECK-DAG:   [[TMP6:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPA]], i32 0, i32 1
60// CHECK-DAG:   store i64 4, i64* [[TMP6]],
61// CHECK-DAG:   [[TMP7:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPA]], i32 0, i32 2
62// CHECK-DAG:   store i8* bitcast (void (i8*)* @[[AINIT:.+]] to i8*), i8** [[TMP7]],
63// CHECK-DAG:   [[TMP8:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPA]], i32 0, i32 3
64// CHECK-DAG:   store i8* null, i8** [[TMP8]],
65// CHECK-DAG:   [[TMP9:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPA]], i32 0, i32 4
66// CHECK-DAG:   store i8* bitcast (void (i8*, i8*)* @[[ACOMB:.+]] to i8*), i8** [[TMP9]],
67// CHECK-DAG:   [[TMP10:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPA]], i32 0, i32 5
68// CHECK-DAG:   [[TMP11:%.+]] = bitcast i32* [[TMP10]] to i8*
69// CHECK-DAG:   call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP11]], i8 0, i64 4, i1 false)
70// CHECK-DAG:   [[TMP13:%.+]] = bitcast float* [[B]] to i8*
71// CHECK-DAG:   store i8* [[TMP13]], i8** [[TMP12:%[^,]+]],
72// CHECK-DAG:   [[TMP12]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPB:%[^,]+]], i32 0, i32 0
73// CHECK-DAG:   [[GEPB]] = getelementptr inbounds [3 x [[T1]]], [3 x [[T1]]]* [[RD_IN1]], i64 0, i64
74// CHECK-DAG:   [[TMP14:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPB]], i32 0, i32 1
75// CHECK-DAG:   store i64 4, i64* [[TMP14]],
76// CHECK-DAG:   [[TMP15:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPB]], i32 0, i32 2
77// CHECK-DAG:   store i8* bitcast (void (i8*)* @[[BINIT:.+]] to i8*), i8** [[TMP15]],
78// CHECK-DAG:   [[TMP16:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPB]], i32 0, i32 3
79// CHECK-DAG:   store i8* null, i8** [[TMP16]],
80// CHECK-DAG:   [[TMP17:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPB]], i32 0, i32 4
81// CHECK-DAG:   store i8* bitcast (void (i8*, i8*)* @[[BCOMB:.+]] to i8*), i8** [[TMP17]],
82// CHECK-DAG:   [[TMP18:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPB]], i32 0, i32 5
83// CHECK-DAG:   [[TMP19:%.+]] = bitcast i32* [[TMP18]] to i8*
84// CHECK-DAG:   call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP19]], i8 0, i64 4, i1 false)
85// CHECK-DAG:   [[TMP21:%.+]] = bitcast i32* [[ARGC_ADDR]] to i8*
86// CHECK-DAG:   store i8* [[TMP21]], i8** [[TMP20:%[^,]+]],
87// CHECK-DAG:   [[TMP20]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPARGC:%[^,]+]], i32 0, i32 0
88// CHECK-DAG:   [[GEPARGC]] = getelementptr inbounds [3 x [[T1]]], [3 x [[T1]]]* [[RD_IN1]], i64 0, i64
89// CHECK-DAG:   [[TMP22:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPARGC]], i32 0, i32 1
90// CHECK-DAG:   store i64 4, i64* [[TMP22]],
91// CHECK-DAG:   [[TMP23:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPARGC]], i32 0, i32 2
92// CHECK-DAG:   store i8* bitcast (void (i8*)* @[[ARGCINIT:.+]] to i8*), i8** [[TMP23]],
93// CHECK-DAG:   [[TMP24:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPARGC]], i32 0, i32 3
94// CHECK-DAG:   store i8* null, i8** [[TMP24]],
95// CHECK-DAG:   [[TMP25:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPARGC]], i32 0, i32 4
96// CHECK-DAG:   store i8* bitcast (void (i8*, i8*)* @[[ARGCCOMB:.+]] to i8*), i8** [[TMP25]],
97// CHECK-DAG:   [[TMP26:%.+]] = getelementptr inbounds [[T1]], [[T1]]* [[GEPARGC]], i32 0, i32 5
98// CHECK-DAG:   [[TMP27:%.+]] = bitcast i32* [[TMP26]] to i8*
99// CHECK-DAG:   call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP27]], i8 0, i64 4, i1 false)
100// CHECK-DAG:   [[TMP28:%.+]] = bitcast [3 x [[T1]]]* [[RD_IN1]] to i8*
101// CHECK-DAG:   [[TMP29:%.+]] = call i8* @__kmpc_task_reduction_init(i32 [[GTID]], i32 3, i8* [[TMP28]])
102// DEBUG-DAG:   call void @llvm.dbg.declare(metadata i8** [[TD1]],
103// CHECK-DAG:   store i8* [[TMP29]], i8** [[TD1]],
104// CHECK-DAG:   call void @__kmpc_taskgroup(%struct.ident_t* {{[^,]+}}, i32 [[GTID]])
105// CHECK-DAG:   [[TMP31:%.+]] = bitcast [5 x %struct.S]* [[C]] to i8*
106// CHECK-DAG:   store i8* [[TMP31]], i8** [[TMP30:%[^,]+]],
107// CHECK-DAG:   [[TMP30]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPC:%[^,]+]], i32 0, i32 0
108// CHECK-DAG:   [[GEPC]] = getelementptr inbounds [2 x [[T2]]], [2 x [[T2]]]* [[RD_IN2]], i64 0, i64
109// CHECK-DAG:   [[TMP32:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPC]], i32 0, i32 1
110// CHECK-DAG:   store i64 20, i64* [[TMP32]],
111// CHECK-DAG:   [[TMP33:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPC]], i32 0, i32 2
112// CHECK-DAG:   store i8* bitcast (void (i8*)* @[[CINIT:.+]] to i8*), i8** [[TMP33]],
113// CHECK-DAG:   [[TMP34:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPC]], i32 0, i32 3
114// CHECK-DAG:   store i8* bitcast (void (i8*)* @[[CFINI:.+]] to i8*), i8** [[TMP34]],
115// CHECK-DAG:   [[TMP35:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPC]], i32 0, i32 4
116// CHECK-DAG:   store i8* bitcast (void (i8*, i8*)* @[[CCOMB:.+]] to i8*), i8** [[TMP35]],
117// CHECK-DAG:   [[TMP36:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPC]], i32 0, i32 5
118// CHECK-DAG:   [[TMP37:%.+]] = bitcast i32* [[TMP36]] to i8*
119// CHECK-DAG:   call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP37]], i8 0, i64 4, i1 false)
120// CHECK-DAG:   [[TMP39:%.+]] = bitcast i16* [[VLA]] to i8*
121// CHECK-DAG:   store i8* [[TMP39]], i8** [[TMP38:%[^,]+]],
122// CHECK-DAG:   [[TMP38]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPVLA:%[^,]+]], i32 0, i32 0
123// CHECK-DAG:   [[GEPVLA]] = getelementptr inbounds [2 x [[T2]]], [2 x [[T2]]]* [[RD_IN2]], i64 0, i64
124// CHECK-DAG:   [[TMP40:%.+]] = mul nuw i64 [[VLA_SIZE]], 2
125// CHECK-DAG:   [[TMP41:%.+]] = udiv exact i64 [[TMP40]], ptrtoint (i16* getelementptr (i16, i16* null, i32 1) to i64)
126// CHECK-DAG:   [[TMP42:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPVLA]], i32 0, i32 1
127// CHECK-DAG:   store i64 [[TMP40]], i64* [[TMP42]],
128// CHECK-DAG:   [[TMP43:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPVLA]], i32 0, i32 2
129// CHECK-DAG:   store i8* bitcast (void (i8*)* @[[VLAINIT:.+]] to i8*), i8** [[TMP43]],
130// CHECK-DAG:   [[TMP44:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPVLA]], i32 0, i32 3
131// CHECK-DAG:   store i8* null, i8** [[TMP44]],
132// CHECK-DAG:   [[TMP45:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPVLA]], i32 0, i32 4
133// CHECK-DAG:   store i8* bitcast (void (i8*, i8*)* @[[VLACOMB:.+]] to i8*), i8** [[TMP45]],
134// CHECK-DAG:   [[TMP46:%.+]] = getelementptr inbounds [[T2]], [[T2]]* [[GEPVLA]], i32 0, i32 5
135// CHECK-DAG:   store i32 1, i32* [[TMP46]],
136// CHECK:       [[TMP47:%.+]] = bitcast [2 x [[T2]]]* [[RD_IN2]] to i8*
137// CHECK:       [[TMP48:%.+]] = call i8* @__kmpc_task_reduction_init(i32 [[GTID]], i32 2, i8* [[TMP47]])
138// CHECK:       store i8* [[TMP48]], i8** [[TD2]],
139// CHECK:       call void @__kmpc_end_taskgroup(%struct.ident_t* {{[^,]+}}, i32 [[GTID]])
140// CHECK:       call void @__kmpc_end_taskgroup(%struct.ident_t* {{[^,]+}}, i32 [[GTID]])
141
142// CHECK-DAG: define internal void @[[AINIT]](i8*)
143// CHECK-DAG: store i32 0, i32* %
144// CHECK-DAG: ret void
145// CHECK-DAG: }
146
147// CHECK-DAG: define internal void @[[ACOMB]](i8*, i8*)
148// CHECK-DAG: add nsw i32 %
149// CHECK-DAG: store i32 %
150// CHECK-DAG: ret void
151// CHECK-DAG: }
152
153// CHECK-DAG: define internal void @[[BINIT]](i8*)
154// CHECK-DAG: store float 0.000000e+00, float* %
155// CHECK-DAG: ret void
156// CHECK-DAG: }
157
158// CHECK-DAG: define internal void @[[BCOMB]](i8*, i8*)
159// CHECK-DAG: fadd float %
160// CHECK-DAG: store float %
161// CHECK-DAG: ret void
162// CHECK-DAG: }
163
164// CHECK-DAG: define internal void @[[ARGCINIT]](i8*)
165// CHECK-DAG: store i32 0, i32* %
166// CHECK-DAG: ret void
167// CHECK-DAG: }
168
169// CHECK-DAG: define internal void @[[ARGCCOMB]](i8*, i8*)
170// CHECK-DAG: add nsw i32 %
171// CHECK-DAG: store i32 %
172// CHECK-DAG: ret void
173// CHECK-DAG: }
174
175// CHECK-DAG: define internal void @[[CINIT]](i8*)
176// CHECK-DAG: phi %struct.S* [
177// CHECK-DAG: call {{.+}}(%struct.S* {{.+}})
178// CHECK-DAG: br i1 %
179// CHECK-DAG: ret void
180// CHECK-DAG: }
181
182// CHECK-DAG: define internal void @[[CFINI]](i8*)
183// CHECK-DAG: phi %struct.S* [
184// CHECK-DAG: call {{.+}}(%struct.S* {{.+}})
185// CHECK-DAG: br i1 %
186// CHECK-DAG: ret void
187// CHECK-DAG: }
188
189// CHECK-DAG: define internal void @[[CCOMB]](i8*, i8*)
190// CHECK-DAG: phi %struct.S* [
191// CHECK-DAG: phi %struct.S* [
192// CHECK-DAG: call {{.+}}(%struct.S* {{.+}}, %struct.S* {{.+}}, %struct.S* {{.+}})
193// CHECK-DAG: call {{.+}}(%struct.S* {{.+}}, %struct.S* {{.+}})
194// CHECK-DAG: call {{.+}}(%struct.S* {{.+}})
195// CHECK-DAG: br i1 %
196// CHECK-DAG: ret void
197// CHECK_DAG: }
198
199// CHECK-DAG: define internal void @[[VLAINIT]](i8*)
200// CHECK-DAG: call i32 @__kmpc_global_thread_num(%struct.ident_t* {{[^,]+}})
201// CHECK-DAG: call i8* @__kmpc_threadprivate_cached(%struct.ident_t*
202// CHECK-DAG: phi i16* [
203// CHECK-DAG: store i16 0, i16* %
204// CHECK-DAG: br i1 %
205// CHECK-DAG: ret void
206// CHECK-DAG: }
207
208// CHECK-DAG: define internal void @[[VLACOMB]](i8*, i8*)
209// CHECK-DAG: call i32 @__kmpc_global_thread_num(%struct.ident_t* {{[^,]+}})
210// CHECK-DAG: call i8* @__kmpc_threadprivate_cached(%struct.ident_t*
211// CHECK-DAG: phi i16* [
212// CHECK-DAG: phi i16* [
213// CHECK-DAG: sext i16 %{{.+}} to i32
214// CHECK-DAG: add nsw i32 %
215// CHECK-DAG: trunc i32 %{{.+}} to i16
216// CHECK-DAG: store i16 %
217// CHECK_DAG: br i1 %
218// CHECK-DAG: ret void
219// CHECK-DAG: }
220#endif
221
222// DEBUG-LABEL: distinct !DICompileUnit
223// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[AINIT]]",
224// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[ACOMB]]",
225// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[BINIT]]",
226// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[BCOMB]]",
227// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[ARGCINIT]]",
228// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[ARGCCOMB]]",
229// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[CINIT]]",
230// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[CFINI]]",
231// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[CCOMB]]",
232// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[VLAINIT]]",
233// DEBUG-DAG: distinct !DISubprogram(linkageName: "[[VLACOMB]]",
234