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 parallel for 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: [[OMP_UB:%.omp.comb.ub]] = alloca i32,
37     // CK1: store i32 56087, i32* [[OMP_UB]],
38     // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i32* [[OMP_UB]],
39     // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
40     // CK1: call void @__kmpc_for_static_fini(
41     // CK1: ret void
42 
43     // CK1: define internal void @[[PAR_OUTL1]]({{.+}})
44     // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
45     // CK1: call void @__kmpc_for_static_fini(
46     // CK1: ret void
47 
48     return a[0][0];
49   }
50 };
51 
52 int teams_template_struct(void) {
53   SS<int, 123, 456> V;
54   return V.foo();
55 
56 }
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 parallel for 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 parallel for 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.comb.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_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
110 // CK2: call void @__kmpc_for_static_fini(
111 // CK2: ret void
112 
113 // CK2: define internal void @[[PAR_OUTL1]]({{.+}})
114 // CK2: call void @__kmpc_for_static_init_{{[4|8]}}({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
115 // CK2: call void @__kmpc_for_static_fini(
116 // CK2: ret void
117 
118 
119 // CK2: define {{.*}}i32 @[[TMAIN]]({{.+}})
120 // CK2: call i32 @__tgt_target_teams(
121 // CK2: call void @[[OFFLT1:.+]]({{.+}})
122 // CK2:  ret
123 // CK2-NEXT: }
124 
125 // CK2:  define {{.*}}void @[[OFFLT1]]({{.+}})
126 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT1:.+]] to {{.+}},
127 // CK2: ret void
128 
129 // CK2: define internal void @[[OUTLT1]]({{.+}})
130 // discard loop variables not needed here
131 // CK2: [[OMP_UB:%.omp.comb.ub]] = alloca i32,
132 // CK2: store i32 {{.+}}, i32* [[OMP_UB]],
133 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i32* [[OMP_UB]],
134 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[TPAR_OUTL1:.+]] to
135 // CK2: call void @__kmpc_for_static_fini(
136 // CK2: ret void
137 
138 // CK2: define internal void @[[TPAR_OUTL1]]({{.+}})
139 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
140 // CK2: call void @__kmpc_for_static_fini(
141 // CK2: ret void
142 
143 #endif // CK2
144 #endif // #ifndef HEADER
145