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