1 // expected-no-diagnostics
2 #ifndef HEADER
3 #define HEADER
4 // Test host codegen.
5 // 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
6 // 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
7 // 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
8 // 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
9 // 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
10 // 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
11 #ifdef CK1
12 
13 int a[100];
14 
15 // CK1: define {{.*}}i32 @{{.+}}teams_argument_globali(
16 int teams_argument_global(int n){
17   int te = n / 128;
18   int th = 128;
19   // discard n_addr
20   // CK1: alloca i32,
21   // CK1: [[TE:%.+]] = alloca i32,
22   // CK1: [[TH:%.+]] = alloca i32,
23   // CK1: [[TE_CAST:%.+]] = alloca i{{32|64}},
24   // CK1: [[TH_CAST:%.+]] = alloca i{{32|64}},
25   // CK1: [[TE_PAR:%.+]] = load{{.+}}, {{.+}} [[TE_CAST]],
26   // CK1: [[TH_PAR:%.+]] = load{{.+}}, {{.+}} [[TH_CAST]],
27 
28   // CK1: call i32 @__tgt_target(i64 -1, i8* @{{[^,]+}}, i32 4, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0))
29 
30   // CK1: call void @[[OFFL1:.+]](i{{32|64}} [[TE_PAR]], i{{32|64}} [[TH_PAR]],
31   #pragma omp target
32   #pragma omp teams distribute parallel for num_teams(te), thread_limit(th)
33   for(int i = 0; i < n; i++) {
34     a[i] = 0;
35     #pragma omp cancel for
36   }
37 
38   // CK1: call i32 @__tgt_target(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0))
39   // CK1: call void @[[OFFL2:.+]](i{{64|32}} %{{.+}})
40   #pragma omp target
41   {{{
42   #pragma omp teams distribute parallel for
43   for(int i = 0; i < n; i++) {
44     a[i] = 0;
45   }
46   }}}
47 
48   // outlined target regions
49   // CK1: define internal void @[[OFFL1]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], i{{32|64}} {{.+}}, {{.+}})
50   // CK1: [[TE_ADDR:%.+]] = alloca i{{32|64}},
51   // CK1: [[TH_ADDR:%.+]] = alloca i{{32|64}},
52   // CK1: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]],
53   // CK1: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]],
54   // CK1-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to
55   // CK1-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to
56   // CK1-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]],
57   // CK1-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]],
58   // CK1-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]],
59   // CK1-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]],
60   // CK1: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]])
61   // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
62   // CK1: ret void
63 
64   // CK1: define internal void @[[OUTL1]]({{.+}})
65   // CK1: call void @__kmpc_for_static_init_4(
66   // CK1: call void {{.+}} @__kmpc_fork_call(
67   // CK1: call void @__kmpc_for_static_fini(
68   // CK1: ret void
69 
70   // CK1: define internal void @[[OFFL2]]({{.+}}, {{.+}})
71   // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL2:.+]] to {{.+}}, {{.+}}, {{.+}})
72   // CK1: ret void
73 
74   // CK1: define internal void @[[OUTL2]]({{.+}})
75   // CK1: call void @__kmpc_for_static_init_4(
76   // CK1: call void {{.+}} @__kmpc_fork_call(
77   // CK1: call void @__kmpc_for_static_fini(
78   // CK1: ret void
79 
80   return a[0];
81 }
82 
83 #endif // CK1
84 
85 // Test host codegen.
86 // 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
87 // 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
88 // 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
89 // 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
90 // 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
91 // 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
92 #ifdef CK2
93 
94 // CK2: define {{.*}}i32 @{{.+}}teams_local_argv(
95 int teams_local_arg(void) {
96   int n = 100;
97   int a[n];
98 
99   // CK2: call i32 @__tgt_target(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0))
100   // CK2: call void @[[OFFL1:.+]](i{{64|32}} %{{.+}})
101   #pragma omp target
102   #pragma omp teams distribute parallel for
103   for(int i = 0; i < n; i++) {
104     a[i] = 0;
105   }
106 
107   // outlined target region
108   // CK2: define internal void @[[OFFL1]]({{.+}}, {{.+}})
109   // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
110   // CK2: ret void
111 
112   // CK2: define internal void @[[OUTL1]]({{.+}})
113   // CK2: call void @__kmpc_for_static_init_4(
114   // CK2: call void {{.+}} @__kmpc_fork_call(
115   // CK2: call void @__kmpc_for_static_fini(
116   // CK2: ret void
117 
118   return a[0];
119 }
120 #endif // CK2
121 
122 // Test host codegen.
123 // RUN: %clang_cc1 -DCK3 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK3 --check-prefix CK3-64
124 // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
125 // RUN: %clang_cc1 -DCK3 -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 CK3 --check-prefix CK3-64
126 // RUN: %clang_cc1 -DCK3 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK3 --check-prefix CK3-32
127 // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
128 // RUN: %clang_cc1 -DCK3 -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 CK3 --check-prefix CK3-32
129 #ifdef CK3
130 
131 // CK3: [[SSI:%.+]] = type { [{{.+}} x i32], float }
132 
133 template <typename T, int X, long long Y>
134 struct SS{
135   T a[X];
136   float b;
137   // CK3: define {{.*}}i32 @{{.+}}foo{{.+}}(
138   int foo(void) {
139 
140   // CK3: call i32 @__tgt_target(i64 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0))
141   // CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}})
142     #pragma omp target
143     #pragma omp teams distribute parallel for
144     for(int i = 0; i < X; i++) {
145       a[i] = (T)0;
146     }
147 
148       // outlined target region
149   // CK3: define internal void @[[OFFL1]]([[SSI]]* {{.+}})
150   // CK3: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
151   // CK3: ret void
152 
153   // CK3: define internal void @[[OUTL1]]({{.+}})
154   // CK3: call void @__kmpc_for_static_init_4(
155   // CK3: call void {{.+}} @__kmpc_fork_call(
156   // CK3: call void @__kmpc_for_static_fini(
157   // CK3: ret void
158 
159     return a[0];
160   }
161 };
162 
163 int teams_template_struct(void) {
164   SS<int, 123, 456> V;
165   return V.foo();
166 
167 }
168 #endif // CK3
169 
170 // Test host codegen.
171 // RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-64
172 // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
173 // RUN: %clang_cc1 -DCK4 -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 CK4 --check-prefix CK4-64
174 // RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-32
175 // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
176 // RUN: %clang_cc1 -DCK4 -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 CK4 --check-prefix CK4-32
177 
178 #ifdef CK4
179 
180 template <typename T, int n>
181 int tmain(T argc) {
182   T a[n];
183   int te = n/128;
184   int th = 128;
185 #pragma omp target
186 #pragma omp teams distribute parallel for num_teams(te) thread_limit(th)
187   for(int i = 0; i < n; i++) {
188     a[i] = (T)0;
189   }
190   return 0;
191 }
192 
193 int main (int argc, char **argv) {
194   int n = 100;
195   int a[n];
196 #pragma omp target
197 #pragma omp teams distribute parallel for
198   for(int i = 0; i < n; i++) {
199     a[i] = 0;
200   }
201   return tmain<int, 10>(argc);
202 }
203 
204 // CK4:  define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}})
205 // CK4:   call i32 @__tgt_target(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0)
206 // CK4: call void @[[OFFL1:.+]]({{.+}})
207 // CK4: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}})
208 // CK4:  ret
209 
210 // CK4:  define {{.*}}void @[[OFFL1]]({{.+}})
211 // CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
212 // CK4: ret void
213 
214 // CK4: define internal void @[[OUTL1]]({{.+}})
215 // CK4: call void @__kmpc_for_static_init_4(
216 // CK4: call void {{.+}} @__kmpc_fork_call(
217 // CK4: call void @__kmpc_for_static_fini(
218 // CK4: ret void
219 
220 // CK4:  define {{.*}}i32 @[[TMAIN]]({{.+}})
221 // CK4:   call i32 @__tgt_target(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0))
222 // CK4: call void @[[OFFLT:.+]]({{.+}})
223 // CK4:  ret
224 // CK4-NEXT: }
225 
226 // CK4: define {{.*}}void @[[OFFLT]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], {{.+}})
227 // CK4: [[TE_ADDR:%.+]] = alloca i{{32|64}},
228 // CK4: [[TH_ADDR:%.+]] = alloca i{{32|64}},
229 // CK4: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]],
230 // CK4: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]],
231 // CK4-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to
232 // CK4-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to
233 // CK4-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]],
234 // CK4-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]],
235 // CK4-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]],
236 // CK4-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]],
237 // CK4: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]])
238 // CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT:.+]] to {{.+}}, {{.+}}, {{.+}})
239 // CK4: ret void
240 
241 // CK4: define internal void @[[OUTLT]]({{.+}})
242 // CK4: call void @__kmpc_for_static_init_4(
243 // CK4: call void {{.+}} @__kmpc_fork_call(
244 // CK4: call void @__kmpc_for_static_fini(
245 // CK4: ret void
246 
247 #endif // CK4
248 #endif
249