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 i; 18 int te = n / 128; 19 int th = 128; 20 // discard n_addr and i 21 // CK1: alloca i32, 22 // CK1: alloca i32, 23 // CK1: [[TE:%.+]] = alloca i32, 24 // CK1: [[TH:%.+]] = alloca i32, 25 // CK1: [[TE_CAST:%.+]] = alloca i{{32|64}}, 26 // CK1: [[TH_CAST:%.+]] = alloca i{{32|64}}, 27 // CK1: [[TE_PAR:%.+]] = load{{.+}}, {{.+}} [[TE_CAST]], 28 // CK1: [[TH_PAR:%.+]] = load{{.+}}, {{.+}} [[TH_CAST]], 29 30 // CK1: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 5, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 {{.+}}, i32 {{.+}}) 31 32 // CK1: call void @[[OFFL1:.+]](i{{32|64}} [[TE_PAR]], i{{32|64}} [[TH_PAR]], 33 #pragma omp target 34 #pragma omp teams distribute simd num_teams(te), thread_limit(th) aligned(a) simdlen(16) linear(i) 35 for(i = 0; i < n; i++) { 36 a[i] = 0; 37 } 38 39 // CK1: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 2, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0) 40 // CK1: call void @[[OFFL2:.+]](i{{64|32}} %{{.+}}) 41 #pragma omp target 42 {{{ 43 #pragma omp teams distribute simd safelen(32) 44 for(int i = 0; i < n; i++) { 45 a[i] = 0; 46 } 47 }}} 48 49 // outlined target regions 50 // CK1: define internal void @[[OFFL1]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], [100 x i{{32|64}}]* {{.+}}, i{{32|64}} {{.+}}, {{.+}}) 51 // CK1: [[TE_ADDR:%.+]] = alloca i{{32|64}}, 52 // CK1: [[TH_ADDR:%.+]] = alloca i{{32|64}}, 53 // CK1: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]], 54 // CK1: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]], 55 // CK1-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to 56 // CK1-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to 57 // CK1-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]], 58 // CK1-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]], 59 // CK1-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]], 60 // CK1-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]], 61 // CK1: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]]) 62 // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}}) 63 // CK1: ret void 64 65 // CK1: define internal void @[[OUTL1]]({{.+}}) 66 // CK1: call void @__kmpc_for_static_init_4( 67 // CK1: call void @__kmpc_for_static_fini( 68 // CK1: ret void 69 70 // CK1: define internal void @[[OFFL2]]({{.+}}, {{.+}}) 71 // CK1: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 2, {{.+}} @[[OUTL2:.+]] to {{.+}}, {{.+}}, {{.+}}) 72 // CK1: ret void 73 74 // CK1: define internal void @[[OUTL2]]({{.+}}) 75 // CK1: call void @__kmpc_for_static_init_4( 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.width", i32 16} 83 // CK1-DAG: !{!"llvm.loop.vectorize.enable", i1 true} 84 // CK1-DAG: !{!"llvm.loop.vectorize.width", i32 32} 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]; 101 102 // CK2: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0) 103 // CK2: call void @[[OFFL1:.+]](i{{64|32}} %{{.+}}) 104 #pragma omp target 105 #pragma omp teams distribute simd 106 for(int 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 3, {{.+}} @[[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_for_static_fini( 118 // CK2: ret void 119 120 return a[0]; 121 } 122 // CK2: !{!"llvm.loop.vectorize.enable", i1 true} 123 #endif // CK2 124 125 // Test host codegen. 126 // 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 127 // 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 128 // 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 129 // 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 130 // 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 131 // 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 132 #ifdef CK3 133 134 // CK3: [[SSI:%.+]] = type { [{{.+}} x i32], float } 135 136 template <typename T, int X, long long Y> 137 struct SS{ 138 T a[X]; 139 float b; 140 // CK3: define {{.*}}i32 @{{.+}}foo{{.+}}( 141 int foo(void) { 142 143 // CK3: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 1, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}@{{[^,]+}}, i32 0, i32 0), i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0) 144 // CK3: call void @[[OFFL1:.+]]([[SSI]]* %{{.+}}) 145 #pragma omp target 146 #pragma omp teams distribute simd 147 for(int i = 0; i < X; i++) { 148 a[i] = (T)0; 149 } 150 151 // outlined target region 152 // CK3: define internal void @[[OFFL1]]([[SSI]]* {{.+}}) 153 // CK3: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}}) 154 // CK3: ret void 155 156 // CK3: define internal void @[[OUTL1]]({{.+}}) 157 // CK3: call void @__kmpc_for_static_init_4( 158 // CK3: call void @__kmpc_for_static_fini( 159 // CK3: ret void 160 161 return a[0]; 162 } 163 }; 164 165 int teams_template_struct(void) { 166 SS<int, 123, 456> V; 167 return V.foo(); 168 169 } 170 // CK3: !{!"llvm.loop.vectorize.enable", i1 true} 171 #endif // CK3 172 173 // Test host codegen. 174 // 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 175 // 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 176 // 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 177 // 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 178 // 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 179 // 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 180 181 #ifdef CK4 182 183 template <typename T, int n> 184 int tmain(T argc) { 185 T a[n]; 186 int te = n/128; 187 int th = 128; 188 #pragma omp target 189 #pragma omp teams distribute simd num_teams(te) thread_limit(th) 190 for(int i = 0; i < n; i++) { 191 a[i] = (T)0; 192 } 193 return 0; 194 } 195 196 int main (int argc, char **argv) { 197 int n = 100; 198 int a[n]; 199 #pragma omp target 200 #pragma omp teams distribute simd 201 for(int i = 0; i < n; i++) { 202 a[i] = 0; 203 } 204 return tmain<int, 10>(argc); 205 } 206 207 // CK4: define {{.*}}i32 @{{[^,]+}}(i{{.+}}{{.+}} %[[ARGC:.+]], {{.+}}) 208 // CK4: call i32 @__tgt_target_teams(i64 -1, i8* @{{[^,]+}}, i32 3, i8** %{{[^,]+}}, i8** %{{[^,]+}}, i{{64|32}}* {{.+}}, i64* {{.+}}@{{[^,]+}}, i32 0, i32 0), i32 0, i32 0) 209 // CK4: call void @[[OFFL1:.+]]({{.+}}) 210 // CK4: {{%.+}} = call{{.*}} i32 @[[TMAIN:.+]]({{.+}}) 211 // CK4: ret 212 213 // CK4: define {{.*}}void @[[OFFL1]]({{.+}}) 214 // CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 3, {{.+}} @[[OUTL1:.+]] to {{.+}}, {{.+}}, {{.+}}) 215 // CK4: ret void 216 217 // CK4: define internal void @[[OUTL1]]({{.+}}) 218 // CK4: call void @__kmpc_for_static_init_4( 219 // CK4: call void @__kmpc_for_static_fini( 220 // CK4: ret void 221 222 // CK4: define {{.*}}i32 @[[TMAIN]]({{.+}}) 223 // 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), i32 {{.+}}, i32 {{.+}}) 224 // CK4: call void @[[OFFLT:.+]]({{.+}}) 225 // CK4: ret 226 // CK4-NEXT: } 227 228 // CK4: define {{.*}}void @[[OFFLT]](i{{32|64}} [[TE_ARG:%.+]], i{{32|64}} [[TH_ARG:%.+]], {{.+}}) 229 // CK4: [[TE_ADDR:%.+]] = alloca i{{32|64}}, 230 // CK4: [[TH_ADDR:%.+]] = alloca i{{32|64}}, 231 // CK4: store{{.+}} [[TE_ARG]], {{.+}} [[TE_ADDR]], 232 // CK4: store{{.+}} [[TH_ARG]], {{.+}} [[TH_ADDR]], 233 // CK4-64: [[TE_CONV:%.+]] = bitcast{{.+}} [[TE_ADDR]] to 234 // CK4-64: [[TH_CONV:%.+]] = bitcast{{.+}} [[TH_ADDR]] to 235 // CK4-64: [[TE_VAL:%.+]] = load i32, i32* [[TE_CONV]], 236 // CK4-64: [[TH_VAL:%.+]] = load i32, i32* [[TH_CONV]], 237 // CK4-32: [[TE_VAL:%.+]] = load i32, i32* [[TE_ADDR]], 238 // CK4-32: [[TH_VAL:%.+]] = load i32, i32* [[TH_ADDR]], 239 // CK4: {{%.+}} = call i32 @__kmpc_push_num_teams({{.+}}, {{.+}}, i32 [[TE_VAL]], i32 [[TH_VAL]]) 240 // CK4: call void {{.+}} @__kmpc_fork_teams({{.+}}, i32 1, {{.+}} @[[OUTLT:.+]] to {{.+}}, {{.+}}, {{.+}}) 241 // CK4: ret void 242 243 // CK4: define internal void @[[OUTLT]]({{.+}}) 244 // CK4: call void @__kmpc_for_static_init_4( 245 // CK4: call void @__kmpc_for_static_fini( 246 // CK4: ret void 247 248 // CK4: !{!"llvm.loop.vectorize.enable", i1 true} 249 #endif // CK4 250 #endif 251 252