Clang Project

clang_source_code/test/OpenMP/teams_distribute_parallel_for_simd_dist_schedule_codegen.cpp
1// expected-no-diagnostics
2#ifndef HEADER
3#define HEADER
4
5// Test host codegen.
6// RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-64
7// RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
8// RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-64
9// RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-32
10// RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
11// RUN: %clang_cc1 -DCK1 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK1 --check-prefix CK1-32
12
13// RUN: %clang_cc1 -DCK1 -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
14// RUN: %clang_cc1 -DCK1 -fopenmp-simd -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
15// RUN: %clang_cc1 -DCK1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
16// RUN: %clang_cc1 -DCK1 -verify -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
17// RUN: %clang_cc1 -DCK1 -fopenmp-simd -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
18// RUN: %clang_cc1 -DCK1 -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
19// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
20#ifdef CK1
21
22template <typename T, int X, long long Y>
23struct SS{
24  T a[X];
25  float b;
26  // CK1: define {{.*}}i32 @{{.+}}foo{{.+}}(
27  int foo(void) {
28
29  // CK1: call i32 @__tgt_target_teams(
30  // CK1: call void @[[OFFL1:.+]](
31    #pragma omp target
32    #pragma omp teams distribute parallel for simd
33    for(int i = 0; i < X; i++) {
34      a[i] = (T)0;
35    }
36  // CK1: call i32 @__tgt_target_teams(
37  // CK1: call void @[[OFFL2:.+]](
38    #pragma omp target
39    #pragma omp teams distribute parallel for simd dist_schedule(static)
40    for(int i = 0; i < X; i++) {
41      a[i] = (T)0;
42    }
43  // CK1: call i32 @__tgt_target_teams(
44  // CK1: call void @[[OFFL3:.+]](
45    #pragma omp target
46    #pragma omp teams distribute parallel for simd dist_schedule(static, X/2)
47    for(int i = 0; i < X; i++) {
48      a[i] = (T)0;
49    }
50  // CK1: define internal void @[[OFFL1]](
51  // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL1:.+]] to {{.+}},
52  // CK1: ret void
53
54  // CK1: define internal void @[[OUTL1]]({{.+}})
55  // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92
56  // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
57  // CK1: call void @__kmpc_for_static_fini(
58  // CK1: ret void
59
60  // CK1: define internal void @[[PAR_OUTL1]]({{.+}})
61  // CK1: call void @__kmpc_for_static_init_4(
62  // CK1: call void @__kmpc_for_static_fini(
63  // CK1: ret void
64
65  // CK1: define internal void @[[OFFL2]](
66  // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL2:.+]] to {{.+}},
67  // CK1: ret void
68
69  // CK1: define internal void @[[OUTL2]]({{.+}})
70  // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92
71  // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL2:.+]] to
72  // CK1: call void @__kmpc_for_static_fini(
73  // CK1: ret void
74
75  // CK1: define internal void @[[PAR_OUTL2]]({{.+}})
76  // CK1: call void @__kmpc_for_static_init_4(
77  // CK1: call void @__kmpc_for_static_fini(
78  // CK1: ret void
79
80
81  // CK1: define internal void @[[OFFL3]](
82  // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL3:.+]] to {{.+}},
83  // CK1: ret void
84
85  // CK1: define internal void @[[OUTL3]]({{.+}})
86  // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 91
87  // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL3:.+]] to
88  // CK1: call void @__kmpc_for_static_fini(
89  // CK1: ret void
90
91  // CK1: define internal void @[[PAR_OUTL3]]({{.+}})
92  // CK1: call void @__kmpc_for_static_init_4(
93  // CK1: call void @__kmpc_for_static_fini(
94  // CK1: ret void
95
96    return a[0];
97  }
98};
99
100int teams_template_struct(void) {
101  SS<int, 123, 456> V;
102  return V.foo();
103
104}
105
106// CK1: !{!"llvm.loop.vectorize.enable", i1 true}
107
108#endif // CK1
109
110// Test host codegen.
111// RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-64
112// RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
113// RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-64
114// RUN: %clang_cc1 -DCK2 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-32
115// RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
116// RUN: %clang_cc1 -DCK2 -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CK2 --check-prefix CK2-32
117
118// RUN: %clang_cc1 -DCK2 -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s
119// RUN: %clang_cc1 -DCK2 -fopenmp-simd -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
120// RUN: %clang_cc1 -DCK2 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
121// RUN: %clang_cc1 -DCK2 -verify -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY1 %s
122// RUN: %clang_cc1 -DCK2 -fopenmp-simd -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
123// RUN: %clang_cc1 -DCK2 -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY1 %s
124// SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
125#ifdef CK2
126
127template <typename T, int n>
128int tmain(T argc) {
129  T a[n];
130  int m = 10;
131#pragma omp target
132#pragma omp teams distribute parallel for simd
133  for(int i = 0; i < n; i++) {
134    a[i] = (T)0;
135  }
136#pragma omp target
137#pragma omp teams distribute parallel for simd dist_schedule(static)
138  for(int i = 0; i < n; i++) {
139    a[i] = (T)0;
140  }
141#pragma omp target
142#pragma omp teams distribute parallel for simd dist_schedule(static, m)
143  for(int i = 0; i < n; i++) {
144    a[i] = (T)0;
145  }
146  return 0;
147}
148
149int main (int argc, char **argv) {
150  int n = 100;
151  int a[n];
152  int m = 10;
153#pragma omp target
154#pragma omp teams distribute parallel for simd
155  for(int i = 0; i < n; i++) {
156    a[i] = 0;
157  }
158#pragma omp target
159#pragma omp teams distribute parallel for simd dist_schedule(static)
160  for(int i = 0; i < n; i++) {
161    a[i] = 0;
162  }
163#pragma omp target
164#pragma omp teams distribute parallel for simd dist_schedule(static, m)
165  for(int i = 0; i < n; i++) {
166    a[i] = 0;
167  }
168  return tmain<int, 10>(argc);
169}
170
171// CK2: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}})
172// CK2: call i32 @__tgt_target_teams(
173// CK2: call void @[[OFFL1:.+]]({{.+}})
174// CK2: call i32 @__tgt_target_teams(
175// CK2: call void @[[OFFL2:.+]]({{.+}})
176// CK2: call i32 @__tgt_target_teams(
177// CK2: call void @[[OFFL3:.+]]({{.+}})
178// CK2: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}})
179// CK2: ret
180
181// CK2:  define {{.*}}void @[[OFFL1]]({{.+}})
182// CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL1:.+]] to {{.+}},
183// CK2: ret void
184
185// CK2: define internal void @[[OUTL1]]({{.+}})
186// CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92
187// CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
188// CK2: call void @__kmpc_for_static_fini(
189// CK2: ret void
190
191// CK2: define internal void @[[PAR_OUTL1]]({{.+}})
192// CK2: call void @__kmpc_for_static_init_4(
193// CK2: call void @__kmpc_for_static_fini(
194// CK2: ret void
195
196// CK2: define {{.*}}void @[[OFFL2]]({{.+}})
197// CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL2:.+]] to {{.+}},
198// CK2: ret void
199
200// CK2: define internal void @[[OUTL2]]({{.+}})
201// CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92
202// CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL2:.+]] to
203// CK2: call void @__kmpc_for_static_fini(
204// CK2: ret void
205
206// CK2: define internal void @[[PAR_OUTL2]]({{.+}})
207// CK2: call void @__kmpc_for_static_init_4(
208// CK2: call void @__kmpc_for_static_fini(
209// CK2: ret void
210
211// CK2:  define {{.*}}void @[[OFFL3]]({{.+}})
212// CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 4, {{.+}} @[[OUTL3:.+]] to {{.+}},
213// CK2: ret void
214
215// CK2: define internal void @[[OUTL3]]({{.+}})
216// CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 91
217// CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL3:.+]] to
218// CK2: call void @__kmpc_for_static_fini(
219// CK2: ret void
220
221// CK2: define internal void @[[PAR_OUTL3]]({{.+}})
222// CK2: call void @__kmpc_for_static_init_4(
223// CK2: call void @__kmpc_for_static_fini(
224// CK2: ret void
225
226// CK2: define {{.*}}i32 @[[TMAIN]]({{.+}})
227// CK2: call i32 @__tgt_target_teams(
228// CK2: call void @[[OFFLT1:.+]]({{.+}})
229// CK2: call i32 @__tgt_target_teams(
230// CK2: call void @[[OFFLT2:.+]]({{.+}})
231// CK2: call i32 @__tgt_target_teams(
232// CK2: call void @[[OFFLT3:.+]]({{.+}})
233// CK2:  ret
234// CK2-NEXT: }
235
236// CK2:  define {{.*}}void @[[OFFLT1]]({{.+}})
237// CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT1:.+]] to {{.+}},
238// CK2: ret void
239
240// CK2: define internal void @[[OUTLT1]]({{.+}})
241// CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92
242// CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTLT1:.+]] to
243// CK2: call void @__kmpc_for_static_fini(
244// CK2: ret void
245
246// CK2: define internal void @[[PAR_OUTLT1]]({{.+}})
247// CK2: call void @__kmpc_for_static_init_4(
248// CK2: call void @__kmpc_for_static_fini(
249// CK2: ret void
250
251// CK2:  define {{.*}}void @[[OFFLT2]]({{.+}})
252// CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT2:.+]] to {{.+}},
253// CK2: ret void
254
255// CK2: define internal void @[[OUTLT2]]({{.+}})
256// CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92
257// CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTLT2:.+]] to
258// CK2: call void @__kmpc_for_static_fini(
259// CK2: ret void
260
261// CK2: define internal void @[[PAR_OUTLT2]]({{.+}})
262// CK2: call void @__kmpc_for_static_init_4(
263// CK2: call void @__kmpc_for_static_fini(
264// CK2: ret void
265
266// CK2:  define {{.*}}void @[[OFFLT3]]({{.+}})
267// CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 {{.+}}, {{.+}} @[[OUTLT3:.+]] to {{.+}},
268// CK2: ret void
269
270// CK2: define internal void @[[OUTLT3]]({{.+}})
271// CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 91
272// CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTLT3:.+]] to
273// CK2: call void @__kmpc_for_static_fini(
274// CK2: ret void
275
276// CK2: define internal void @[[PAR_OUTLT3]]({{.+}})
277// CK2: call void @__kmpc_for_static_init_4(
278// CK2: call void @__kmpc_for_static_fini(
279// CK2: ret void
280
281// CK2: !{!"llvm.loop.vectorize.enable", i1 true}
282
283#endif // CK2
284#endif // #ifndef HEADER
285