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