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
22 template <typename T, int X, long long Y>
23 struct SS{
24 T a[X][Y];
25
26 // CK1: define {{.*}}i32 @{{.+}}foo{{.+}}(
fooSS27 int foo(void) {
28
29 // CK1: call i32 @__tgt_target_teams_mapper(%struct.ident_t* @{{.+}},
30 // CK1: call void @[[OFFL1:.+]](
31 #pragma omp target
32 #pragma omp teams distribute simd collapse(2)
33 for(int i = 0; i < X; i++) {
34 for(int j = 0; j < Y; j++) {
35 a[i][j] = (T)0;
36 }
37 }
38 // CK1: define internal void @[[OFFL1]](
39 // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL1:.+]] to {{.+}},
40 // CK1: ret void
41
42 // CK1: define internal void @[[OUTL1]]({{.+}})
43 // discard loop variables not needed here
44 // CK1: = alloca i32,
45 // CK1: = alloca i32,
46 // CK1: = alloca i32,
47 // CK1: = alloca i32,
48 // CK1: [[OMP_UB:%.+]] = alloca i32,
49 // CK1: store i32 56087, i32* [[OMP_UB]],
50 // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i32* [[OMP_UB]],
51 // CK1: call void @__kmpc_for_static_fini(
52 // CK1: ret void
53
54 return a[0][0];
55 }
56 };
57
teams_template_struct(void)58 int teams_template_struct(void) {
59 SS<int, 123, 456> V;
60 return V.foo();
61
62 }
63
64 // CK1: !{!"llvm.loop.vectorize.enable", i1 true}
65 #endif // CK1
66
67 // Test host codegen.
68 // 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
69 // 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
70 // 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
71 // 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
72 // 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
73 // 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
74
75 // 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
76 // 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
77 // 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
78 // 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
79 // 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
80 // 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
81 // SIMD-ONLY1-NOT: {{__kmpc|__tgt}}
82 #ifdef CK2
83
84 template <typename T, int n, int m>
tmain(T argc)85 int tmain(T argc) {
86 T a[n][m];
87 #pragma omp target
88 #pragma omp teams distribute simd collapse(2)
89 for(int i = 0; i < n; i++) {
90 for(int j = 0; j < m; j++) {
91 a[i][j] = (T)0;
92 }
93 }
94 return 0;
95 }
96
main(int argc,char ** argv)97 int main (int argc, char **argv) {
98 int n = 100;
99 int m = 2;
100 int a[n][m];
101 #pragma omp target
102 #pragma omp teams distribute simd collapse(2)
103 for(int i = 0; i < n; i++) {
104 for(int j = 0; j < m; j++) {
105 a[i][j] = 0;
106 }
107 }
108 return tmain<int, 10, 2>(argc);
109 }
110
111 // CK2: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}})
112 // CK2: call i32 @__tgt_target_teams_mapper(%struct.ident_t* @{{.+}},
113 // CK2: call void @[[OFFL1:.+]]({{.+}})
114 // CK2: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}})
115 // CK2: ret
116
117 // CK2: define {{.*}}void @[[OFFL1]]({{.+}})
118 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 5, {{.+}} @[[OUTL1:.+]] to {{.+}},
119 // CK2: ret void
120
121 // CK2: define internal void @[[OUTL1]]({{.+}})
122 // CK2: [[OMP_UB:%.omp.ub]] = alloca i64,
123 // CK2: store i64 {{.+}}, i64* [[OMP_UB]],
124 // CK2: call void @__kmpc_for_static_init_8({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i64* [[OMP_UB]],
125 // CK2: call void @__kmpc_for_static_fini(
126 // CK2: ret void
127 // CK2: define {{.*}}i32 @[[TMAIN]]({{.+}})
128 // CK2: call i32 @__tgt_target_teams_mapper(%struct.ident_t* @{{.+}},
129 // CK2: call void @[[OFFLT1:.+]]({{.+}})
130 // CK2: ret
131 // CK2-NEXT: }
132
133 // CK2: define {{.*}}void @[[OFFLT1]]({{.+}})
134 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT1:.+]] to {{.+}},
135 // CK2: ret void
136
137 // CK2: define internal void @[[OUTLT1]]({{.+}})
138 // discard loop variables not needed here
139 // CK2: [[OMP_UB:%.omp.ub]] = alloca i32,
140 // CK2: store i32 {{.+}}, i32* [[OMP_UB]],
141 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i32* [[OMP_UB]],
142 // CK2: call void @__kmpc_for_static_fini(
143 // CK2: ret void
144
145 // CK2: !{!"llvm.loop.vectorize.enable", i1 true}
146 #endif // CK2
147 #endif // #ifndef HEADER
148