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 %s --check-prefix SIMD-ONLY
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 %s --check-prefix SIMD-ONLY
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 %s --check-prefix SIMD-ONLY
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 %s --check-prefix SIMD-ONLY
19 // SIMD-ONLY-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 teams distribute parallel for collapse(2)
32     for(int i = 0; i < X; i++) {
33       for(int j = 0; j < Y; j++) {
34         a[i][j] = (T)0;
35       }
36     }
37     // CK1: define internal void @[[OFFL1]](
38     // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL1:.+]] to {{.+}},
39     // CK1: ret void
40 
41     // CK1: define internal void @[[OUTL1]]({{.+}})
42     // discard loop variables not needed here
43     // CK1: [[OMP_UB:%.omp.comb.ub]] = alloca i32,
44     // CK1: store i32 56087, i32* [[OMP_UB]],
45     // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i32* [[OMP_UB]],
46     // CK1: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
47     // CK1: call void @__kmpc_for_static_fini(
48     // CK1: ret void
49 
50     // CK1: define internal void @[[PAR_OUTL1]]({{.+}})
51     // CK1: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
52     // CK1: call void @__kmpc_for_static_fini(
53     // CK1: ret void
54 
55     return a[0][0];
56   }
57 };
58 
teams_template_struct(void)59 int teams_template_struct(void) {
60   SS<int, 123, 456> V;
61   return V.foo();
62 
63 }
64 #endif // CK1
65 
66 // Test host codegen.
67 // 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
68 // 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
69 // 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
70 // 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
71 // 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
72 // 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
73 
74 // RUN: %clang_cc1 -DCK2 -verify -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix SIMD-ONLY
75 // 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
76 // 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 %s --check-prefix SIMD-ONLY
77 // RUN: %clang_cc1 -DCK2 -verify -fopenmp-simd -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix SIMD-ONLY
78 // 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
79 // 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 %s --check-prefix SIMD-ONLY
80 // SIMD-ONLY-NOT: {{__kmpc|__tgt}}
81 #ifdef CK2
82 
83 template <typename T, int n, int m>
tmain(T argc)84 int tmain(T argc) {
85   T a[n][m];
86   #pragma omp target 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] = (T)0;
90     }
91   }
92   return 0;
93 }
94 
main(int argc,char ** argv)95 int main (int argc, char **argv) {
96   int n = 100;
97   int m = 2;
98   int a[n][m];
99   #pragma omp target teams distribute parallel for collapse(2)
100   for(int i = 0; i < n; i++) {
101     for(int j = 0; j < m; j++) {
102       a[i][j] = 0;
103     }
104   }
105   return tmain<int, 10, 2>(argc);
106 }
107 
108 // CK2: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}})
109 // CK2: call i32 @__tgt_target_teams_mapper(%struct.ident_t* @{{.+}},
110 // CK2: call void @[[OFFL1:.+]]({{.+}})
111 // CK2: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}})
112 // CK2: ret
113 
114 // CK2:  define {{.*}}void @[[OFFL1]]({{.+}})
115 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 5, {{.+}} @[[OUTL1:.+]] to {{.+}},
116 // CK2: ret void
117 
118 // CK2: define internal void @[[OUTL1]]({{.+}})
119 // CK2: [[OMP_UB:%.omp.comb.ub]] = alloca i64,
120 // CK2: store i64 {{.+}}, i64* [[OMP_UB]],
121 // CK2: call void @__kmpc_for_static_init_8({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i64* [[OMP_UB]],
122 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[PAR_OUTL1:.+]] to
123 // CK2: call void @__kmpc_for_static_fini(
124 // CK2: ret void
125 
126 // CK2: define internal void @[[PAR_OUTL1]]({{.+}})
127 // CK2: call void @__kmpc_for_static_init_{{[4|8]}}({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
128 // CK2: call void @__kmpc_for_static_fini(
129 // CK2: ret void
130 
131 
132 // CK2: define {{.*}}i32 @[[TMAIN]]({{.+}})
133 // CK2: call i32 @__tgt_target_teams_mapper(%struct.ident_t* @{{.+}},
134 // CK2: call void @[[OFFLT1:.+]]({{.+}})
135 // CK2:  ret
136 // CK2-NEXT: }
137 
138 // CK2:  define {{.*}}void @[[OFFLT1]]({{.+}})
139 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT1:.+]] to {{.+}},
140 // CK2: ret void
141 
142 // CK2: define internal void @[[OUTLT1]]({{.+}})
143 // discard loop variables not needed here
144 // CK2: [[OMP_UB:%.omp.comb.ub]] = alloca i32,
145 // CK2: store i32 {{.+}}, i32* [[OMP_UB]],
146 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 92, {{.+}}, {{.+}}, i32* [[OMP_UB]],
147 // CK2: call void {{.*}} @__kmpc_fork_call({{.+}}, {{.+}}, {{.+}} @[[TPAR_OUTL1:.+]] to
148 // CK2: call void @__kmpc_for_static_fini(
149 // CK2: ret void
150 
151 // CK2: define internal void @[[TPAR_OUTL1]]({{.+}})
152 // CK2: call void @__kmpc_for_static_init_4({{.+}}, {{.+}}, i32 34, {{.+}}, {{.+}},
153 // CK2: call void @__kmpc_for_static_fini(
154 // CK2: ret void
155 
156 #endif // CK2
157 #endif // #ifndef HEADER
158