1 // expected-no-diagnostics 2 #ifndef HEADER 3 #define HEADER 4 // Test host codegen. 5 // 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 6 // 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 7 // 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 8 // 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 9 // 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 10 // 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 11 #ifdef CK1 12 13 int a[100]; 14 15 // CK1: define {{.*}}i32 @{{.+}}teams_argument_globali( 16 int teams_argument_global(int n){ 17 int te = n / 128; 18 int th = 128; 19 // discard n_addr 20 // CK1: alloca i32, 21 // CK1: [[TE:%.+]] = alloca i32, 22 // CK1: [[TH:%.+]] = alloca i32, 23 // CK1: [[TE_CAST:%.+]] = alloca i{{32|64}}, 24 // CK1: [[TH_CAST:%.+]] = alloca i{{32|64}}, 25 // CK1: [[TE_PAR:%.+]] = load{{.+}}, {{.+}} [[TE_CAST]], 26 // CK1: [[TH_PAR:%.+]] = load{{.+}}, {{.+}} [[TH_CAST]], 27 28 // CK1: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 4, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0) 29 30 // CK1: call void @[[OFFL1:.+]](i{{32|64}} [[TE_PAR]], i{{32|64}} [[TH_PAR]], 31 #pragma omp target 32 #pragma omp teams distribute parallel for simd num_teams(te), thread_limit(th) simdlen(64) 33 for(int i = 0; i < n; i++) { 34 a[i] = 0; 35 } 36 37 int i; 38 // CK1: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0) 39 // CK1: call void @[[OFFL2:.+]]( 40 #pragma omp target 41 {{{ 42 #pragma omp teams distribute parallel for simd safelen(4) aligned(a) linear(i) 43 for(i = 0; i < n; i++) { 44 a[i] = 0; 45 } 46 }}} 47 // outlined target regions 48 // CK1: define internal void @[[OFFL1]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], i{{32|64}} {{.+}}, {{.+}}) 49 // CK1: [[TE_ADDR:%.+]] = alloca i{{32|64}}, 50 // CK1: [[TH_ADDR:%.+]] = alloca i{{32|64}}, 51 // CK1: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]], 52 // CK1: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]], 53 // CK1-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to 54 // CK1-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to 55 // CK1-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]], 56 // CK1-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]], 57 // CK1-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]], 58 // CK1-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]], 59 // CK1: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]]) 60 // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}}) 61 // CK1: ret void 62 63 // CK1: define internal void @[[OUTL1]]({{.+}}) 64 // CK1: call void @__kmpc_for_static_init_4( 65 // CK1: call void {{.+}} @__kmpc_fork_call( 66 // CK1: call void @__kmpc_for_static_fini( 67 // CK1: ret void 68 69 // CK1: define internal void @[[OFFL2]]({{.+}}, {{.+}}) 70 // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL2:.+]] to {{.+}}, {{.+}}, {{.+}}) 71 // CK1: ret void 72 73 // CK1: define internal void @[[OUTL2]]({{.+}}) 74 // CK1: call void @__kmpc_for_static_init_4( 75 // CK1: call void {{.+}} @__kmpc_fork_call( 76 // CK1: call void @__kmpc_for_static_fini( 77 // CK1: ret void 78 79 return a[0]; 80 } 81 82 // CK1-DAG: !{!"llvm.loop.vectorize.enable", i1 true} 83 // CK1-DAG: !{!"llvm.loop.vectorize.width", i32 4} 84 // CK1-DAG: !{!"llvm.loop.vectorize.width", i32 64} 85 86 #endif // CK1 87 88 // Test host codegen. 89 // 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 90 // 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 91 // 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 92 // 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 93 // 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 94 // 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 95 #ifdef CK2 96 97 // CK2: define {{.*}}i32 @{{.+}}teams_local_argv( 98 int teams_local_arg(void) { 99 int n = 100; 100 int a[n], i; 101 102 // CK2: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 4, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0) 103 // CK2: call void @[[OFFL1:.+]]( 104 #pragma omp target 105 #pragma omp teams distribute parallel for simd safelen(4) aligned(a) linear(i) 106 for(i = 0; i < n; i++) { 107 a[i] = 0; 108 } 109 110 // outlined target region 111 // CK2: define internal void @[[OFFL1]]({{.+}}, {{.+}}) 112 // CK2: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 4, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}}) 113 // CK2: ret void 114 115 // CK2: define internal void @[[OUTL1]]({{.+}}) 116 // CK2: call void @__kmpc_for_static_init_4( 117 // CK2: call void {{.+}} @__kmpc_fork_call( 118 // CK2: call void @__kmpc_for_static_fini( 119 // CK2: ret void 120 121 return a[0]; 122 } 123 124 // CK2-DAG: !{!"llvm.loop.vectorize.enable", i1 true} 125 // CK2-DAG: !{!"llvm.loop.vectorize.width", i32 4} 126 127 #endif // CK2 128 129 // Test host codegen. 130 // RUN: %clang_cc1 -DCK3 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK3 --check-prefix CK3-64 131 // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s 132 // RUN: %clang_cc1 -DCK3 -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 CK3 --check-prefix CK3-64 133 // RUN: %clang_cc1 -DCK3 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK3 --check-prefix CK3-32 134 // RUN: %clang_cc1 -DCK3 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s 135 // RUN: %clang_cc1 -DCK3 -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 CK3 --check-prefix CK3-32 136 #ifdef CK3 137 138 // CK3: [[SSI:%.+]] = type { [{{.+}} x i32], float } 139 140 template <typename T, int X, long long Y> 141 struct SS{ 142 T a[X]; 143 float b; 144 // CK3: define {{.*}}i32 @{{.+}}foo{{.+}}( 145 int foo(void) { 146 int i; 147 // CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0) 148 // CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}}) 149 #pragma omp target 150 #pragma omp teams distribute parallel for simd safelen(4) aligned(a) linear(i) 151 for(i = 0; i < X; i++) { 152 a[i] = (T)0; 153 } 154 155 // outlined target region 156 // CK3: define internal void @[[OFFL1]]([[SSI]]* {{.+}}) 157 // CK3: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}}) 158 // CK3: ret void 159 160 // CK3: define internal void @[[OUTL1]]({{.+}}) 161 // CK3: call void @__kmpc_for_static_init_4( 162 // CK3: call void {{.+}} @__kmpc_fork_call( 163 // CK3: call void @__kmpc_for_static_fini( 164 // CK3: ret void 165 166 return a[0]; 167 } 168 }; 169 170 int teams_template_struct(void) { 171 SS<int, 123, 456> V; 172 return V.foo(); 173 174 } 175 176 // CK3-DAG: !{!"llvm.loop.vectorize.enable", i1 true} 177 // CK3-DAG: !{!"llvm.loop.vectorize.width", i32 4} 178 #endif // CK3 179 180 // Test host codegen. 181 // RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-64 182 // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s 183 // RUN: %clang_cc1 -DCK4 -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 CK4 --check-prefix CK4-64 184 // RUN: %clang_cc1 -DCK4 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CK4 --check-prefix CK4-32 185 // RUN: %clang_cc1 -DCK4 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s 186 // RUN: %clang_cc1 -DCK4 -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 CK4 --check-prefix CK4-32 187 188 #ifdef CK4 189 190 template <typename T, int n> 191 int tmain(T argc) { 192 T a[n]; 193 int te = n/128; 194 int th = 128; 195 #pragma omp target 196 #pragma omp teams distribute parallel for simd num_teams(te) thread_limit(th) simdlen(64) 197 for(int i = 0; i < n; i++) { 198 a[i] = (T)0; 199 } 200 return 0; 201 } 202 203 int main (int argc, char **argv) { 204 int n = 100; 205 int a[n], i; 206 #pragma omp target 207 #pragma omp teams distribute parallel for simd safelen(4) aligned(a) linear(i) 208 for(i = 0; i < n; i++) { 209 a[i] = 0; 210 } 211 return tmain<int, 10>(argc); 212 } 213 214 // CK4: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}}) 215 // CK4: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 4, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0) 216 // CK4: call void @[[OFFL1:.+]]({{.+}}) 217 // CK4: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}}) 218 // CK4: ret 219 220 // CK4: define {{.*}}void @[[OFFL1]]({{.+}}) 221 // CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 4, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}}) 222 // CK4: ret void 223 224 // CK4: define internal void @[[OUTL1]]({{.+}}) 225 // CK4: call void @__kmpc_for_static_init_4( 226 // CK4: call void {{.+}} @__kmpc_fork_call( 227 // CK4: call void @__kmpc_for_static_fini( 228 // CK4: ret void 229 230 // CK4: define {{.*}}i32 @[[TMAIN]]({{.+}}) 231 // CK4: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0) 232 // CK4: call void @[[OFFLT:.+]]({{.+}}) 233 // CK4: ret 234 // CK4-NEXT: } 235 236 // CK4: define {{.*}}void @[[OFFLT]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], {{.+}}) 237 // CK4: [[TE_ADDR:%.+]] = alloca i{{32|64}}, 238 // CK4: [[TH_ADDR:%.+]] = alloca i{{32|64}}, 239 // CK4: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]], 240 // CK4: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]], 241 // CK4-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to 242 // CK4-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to 243 // CK4-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]], 244 // CK4-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]], 245 // CK4-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]], 246 // CK4-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]], 247 // CK4: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]]) 248 // CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT:.+]] to {{.+}}, {{.+}}, {{.+}}) 249 // CK4: ret void 250 251 // CK4: define internal void @[[OUTLT]]({{.+}}) 252 // CK4: call void @__kmpc_for_static_init_4( 253 // CK4: call void {{.+}} @__kmpc_fork_call( 254 // CK4: call void @__kmpc_for_static_fini( 255 // CK4: ret void 256 257 // CK4-DAG: !{!"llvm.loop.vectorize.enable", i1 true} 258 // CK4-DAG: !{!"llvm.loop.vectorize.width", i32 4} 259 // CK4-DAG: !{!"llvm.loop.vectorize.width", i32 64} 260 261 #endif // CK4 262 #endif 263 264