blob: 8a2afbd4341dd631df2e3aede75de95fbea75aa0 [file] [log] [blame]
Carlo Bertolliba1487b2017-10-04 14:12:09 +00001// 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
13int a[100];
14
15// CK1: define {{.*}}i32 @{{.+}}teams_argument_globali(
16int 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
Alexey Bataev50a1c782017-12-01 21:31:08 +000028 // CK1: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 4, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 {{.+}}, i32 {{.+}})
Carlo Bertolliba1487b2017-10-04 14:12:09 +000029
30 // CK1: call void @[[OFFL1:.+]](i{{32|64}} [[TE_PAR]], i{{32|64}} [[TH_PAR]],
31 #pragma omp target
32 #pragma omp teams distribute num_teams(te), thread_limit(th)
33 for(int i = 0; i < n; i++) {
34 a[i] = 0;
35 }
36
Alexey Bataev50a1c782017-12-01 21:31:08 +000037 // CK1: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
Carlo Bertolliba1487b2017-10-04 14:12:09 +000038 // CK1: call void @[[OFFL2:.+]](i{{64|32}} %{{.+}})
39 #pragma omp target
40 {{{
41 #pragma omp teams distribute
42 for(int i = 0; i < n; i++) {
43 a[i] = 0;
44 }
45 }}}
46
47 // outlined target regions
48 // CK1: define internal void @[[OFFL1]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], i{{32|64}} {{.+}}, {{.+}})
49 // CK1: [[TE_ADDR:%.+]] = alloca i{{32|64}},
50 // CK1: [[TH_ADDR:%.+]] = alloca i{{32|64}},
51 // CK1: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]],
52 // CK1: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]],
53 // CK1-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to
54 // CK1-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to
55 // CK1-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]],
56 // CK1-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]],
57 // CK1-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]],
58 // CK1-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]],
59 // CK1: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]])
60 // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
61 // CK1: ret void
62
63 // CK1: define internal void @[[OUTL1]]({{.+}})
64 // CK1: call void @__kmpc_for_static_init_4(
65 // CK1: call void @__kmpc_for_static_fini(
66 // CK1: ret void
67
68 // CK1: define internal void @[[OFFL2]]({{.+}}, {{.+}})
69 // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL2:.+]] to {{.+}}, {{.+}}, {{.+}})
70 // CK1: ret void
71
72 // CK1: define internal void @[[OUTL2]]({{.+}})
73 // CK1: call void @__kmpc_for_static_init_4(
74 // CK1: call void @__kmpc_for_static_fini(
75 // CK1: ret void
76
77 return a[0];
78}
79
80#endif // CK1
81
82// Test host codegen.
83// 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
84// 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
85// 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
86// 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
87// 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
88// 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
89#ifdef CK2
90
91// CK2: define {{.*}}i32 @{{.+}}teams_local_argv(
92int teams_local_arg(void) {
93 int n = 100;
94 int a[n];
95
Alexey Bataev50a1c782017-12-01 21:31:08 +000096 // CK2: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
Carlo Bertolliba1487b2017-10-04 14:12:09 +000097 // CK2: call void @[[OFFL1:.+]](i{{64|32}} %{{.+}})
98 #pragma omp target
99 #pragma omp teams distribute
100 for(int i = 0; i < n; i++) {
101 a[i] = 0;
102 }
103
104 // outlined target region
105 // CK2: define internal void @[[OFFL1]]({{.+}}, {{.+}})
106 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
107 // CK2: ret void
108
109 // CK2: define internal void @[[OUTL1]]({{.+}})
110 // CK2: call void @__kmpc_for_static_init_4(
111 // CK2: call void @__kmpc_for_static_fini(
112 // CK2: ret void
113
114 return a[0];
115}
116#endif // CK2
117
118// Test host codegen.
119// 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
120// 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
121// 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
122// 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
123// 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
124// 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
125#ifdef CK3
126
127// CK3: [[SSI:%.+]] = type { [{{.+}} x i32], float }
128
129template <typename T, int X, long long Y>
130struct SS{
131 T a[X];
132 float b;
133 // CK3: define {{.*}}i32 @{{.+}}foo{{.+}}(
134 int foo(void) {
135
Alexey Bataev50a1c782017-12-01 21:31:08 +0000136 // CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
Carlo Bertolliba1487b2017-10-04 14:12:09 +0000137 // CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}})
138 #pragma omp target
139 #pragma omp teams distribute
140 for(int i = 0; i < X; i++) {
141 a[i] = (T)0;
142 }
143
144 // outlined target region
145 // CK3: define internal void @[[OFFL1]]([[SSI]]* {{.+}})
146 // CK3: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
147 // CK3: ret void
148
149 // CK3: define internal void @[[OUTL1]]({{.+}})
150 // CK3: call void @__kmpc_for_static_init_4(
151 // CK3: call void @__kmpc_for_static_fini(
152 // CK3: ret void
153
154 return a[0];
155 }
156};
157
158int teams_template_struct(void) {
159 SS<int, 123, 456> V;
160 return V.foo();
161
162}
163#endif // CK3
164
165// Test host codegen.
166// 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
167// 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
168// 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
169// 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
170// 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
171// 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
172
173#ifdef CK4
174
175template <typename T, int n>
176int tmain(T argc) {
177 T a[n];
178 int te = n/128;
179 int th = 128;
180#pragma omp target
181#pragma omp teams distribute num_teams(te) thread_limit(th)
182 for(int i = 0; i < n; i++) {
183 a[i] = (T)0;
184 }
185 return 0;
186}
187
188int main (int argc, char **argv) {
189 int n = 100;
190 int a[n];
191#pragma omp target
192#pragma omp teams distribute
193 for(int i = 0; i < n; i++) {
194 a[i] = 0;
195 }
196 return tmain<int, 10>(argc);
197}
198
199// CK4: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}})
Alexey Bataev50a1c782017-12-01 21:31:08 +0000200// CK4: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0)
Carlo Bertolliba1487b2017-10-04 14:12:09 +0000201// CK4: call void @[[OFFL1:.+]]({{.+}})
202// CK4: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}})
203// CK4: ret
204
205// CK4: define {{.*}}void @[[OFFL1]]({{.+}})
206// CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}})
207// CK4: ret void
208
209// CK4: define internal void @[[OUTL1]]({{.+}})
210// CK4: call void @__kmpc_for_static_init_4(
211// CK4: call void @__kmpc_for_static_fini(
212// CK4: ret void
213
214// CK4: define {{.*}}i32 @[[TMAIN]]({{.+}})
Alexey Bataev50a1c782017-12-01 21:31:08 +0000215// CK4: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 {{.+}}, i32 {{.+}})
Carlo Bertolliba1487b2017-10-04 14:12:09 +0000216// CK4: call void @[[OFFLT:.+]]({{.+}})
217// CK4: ret
218// CK4-NEXT: }
219
220// CK4: define {{.*}}void @[[OFFLT]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], {{.+}})
221// CK4: [[TE_ADDR:%.+]] = alloca i{{32|64}},
222// CK4: [[TH_ADDR:%.+]] = alloca i{{32|64}},
223// CK4: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]],
224// CK4: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]],
225// CK4-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to
226// CK4-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to
227// CK4-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]],
228// CK4-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]],
229// CK4-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]],
230// CK4-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]],
231// CK4: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]])
232// CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT:.+]] to {{.+}}, {{.+}}, {{.+}})
233// CK4: ret void
234
235// CK4: define internal void @[[OUTLT]]({{.+}})
236// CK4: call void @__kmpc_for_static_init_4(
237// CK4: call void @__kmpc_for_static_fini(
238// CK4: ret void
239
240#endif // CK4
241#endif