1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s 2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s 3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s 4 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG 5 // 6 // expected-no-diagnostics 7 // REQUIRES: x86-registered-target 8 #ifndef HEADER 9 #define HEADER 10 // CHECK: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* } 11 // CHECK-DAG: [[IMPLICIT_BARRIER_LOC:@.+]] = private unnamed_addr constant %{{.+}} { i32 0, i32 66, i32 0, i32 0, i8* 12 // CHECK-DAG: [[I:@.+]] = global i8 1, 13 // CHECK-DAG: [[J:@.+]] = global i8 2, 14 // CHECK-DAG: [[K:@.+]] = global i8 3, 15 16 // CHECK-LABEL: define {{.*void}} @{{.*}}without_schedule_clause{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) 17 void without_schedule_clause(float *a, float *b, float *c, float *d) { 18 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) 19 #pragma omp for nowait 20 // CHECK: call void @__kmpc_for_static_init_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 34, i32* [[IS_LAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]], i32 1, i32 1) 21 // UB = min(UB, GlobalUB) 22 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]] 23 // CHECK-NEXT: [[UBCMP:%.+]] = icmp sgt i32 [[UB]], 4571423 24 // CHECK-NEXT: br i1 [[UBCMP]], label [[UB_TRUE:%[^,]+]], label [[UB_FALSE:%[^,]+]] 25 // CHECK: [[UBRESULT:%.+]] = phi i32 [ 4571423, [[UB_TRUE]] ], [ [[UBVAL:%[^,]+]], [[UB_FALSE]] ] 26 // CHECK-NEXT: store i32 [[UBRESULT]], i32* [[OMP_UB]] 27 // CHECK-NEXT: [[LB:%.+]] = load i32, i32* [[OMP_LB]] 28 // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]] 29 // Loop header 30 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]] 31 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]] 32 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]] 33 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]] 34 for (int i = 33; i < 32000000; i += 7) { 35 // CHECK: [[LOOP1_BODY]] 36 // Start of body: calculate i from IV: 37 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]] 38 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 7 39 // CHECK-NEXT: [[CALC_I_2:%.+]] = add nsw i32 33, [[CALC_I_1]] 40 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]] 41 // ... loop body ... 42 // End of body: store into a[i]: 43 // CHECK: store float [[RESULT:%.+]], float* {{%.+}} 44 // CHECK-NOT: !llvm.mem.parallel_loop_access 45 a[i] = b[i] * c[i] * d[i]; 46 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}} 47 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1 48 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]] 49 // CHECK-NEXT: br label %{{.+}} 50 } 51 // CHECK: [[LOOP1_END]] 52 // CHECK: call void @__kmpc_for_static_fini([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]]) 53 // CHECK-NOT: __kmpc_barrier 54 // CHECK: ret void 55 } 56 57 // CHECK-LABEL: define {{.*void}} @{{.*}}static_not_chunked{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) 58 void static_not_chunked(float *a, float *b, float *c, float *d) { 59 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) 60 #pragma omp for schedule(static) 61 // CHECK: call void @__kmpc_for_static_init_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 34, i32* [[IS_LAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]], i32 1, i32 1) 62 // UB = min(UB, GlobalUB) 63 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]] 64 // CHECK-NEXT: [[UBCMP:%.+]] = icmp sgt i32 [[UB]], 4571423 65 // CHECK-NEXT: br i1 [[UBCMP]], label [[UB_TRUE:%[^,]+]], label [[UB_FALSE:%[^,]+]] 66 // CHECK: [[UBRESULT:%.+]] = phi i32 [ 4571423, [[UB_TRUE]] ], [ [[UBVAL:%[^,]+]], [[UB_FALSE]] ] 67 // CHECK-NEXT: store i32 [[UBRESULT]], i32* [[OMP_UB]] 68 // CHECK-NEXT: [[LB:%.+]] = load i32, i32* [[OMP_LB]] 69 // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]] 70 // Loop header 71 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]] 72 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]] 73 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]] 74 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]] 75 for (int i = 32000000; i > 33; i += -7) { 76 // CHECK: [[LOOP1_BODY]] 77 // Start of body: calculate i from IV: 78 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]] 79 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 7 80 // CHECK-NEXT: [[CALC_I_2:%.+]] = sub nsw i32 32000000, [[CALC_I_1]] 81 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]] 82 // ... loop body ... 83 // End of body: store into a[i]: 84 // CHECK: store float [[RESULT:%.+]], float* {{%.+}} 85 // CHECK-NOT: !llvm.mem.parallel_loop_access 86 a[i] = b[i] * c[i] * d[i]; 87 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}} 88 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1 89 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]] 90 // CHECK-NEXT: br label %{{.+}} 91 } 92 // CHECK: [[LOOP1_END]] 93 // CHECK: call void @__kmpc_for_static_fini([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]]) 94 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]]) 95 // CHECK: ret void 96 } 97 98 // CHECK-LABEL: define {{.*void}} @{{.*}}static_chunked{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) 99 void static_chunked(float *a, float *b, float *c, float *d) { 100 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) 101 #pragma omp for schedule(static, 5) 102 // CHECK: call void @__kmpc_for_static_init_4u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 33, i32* [[IS_LAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]], i32 1, i32 5) 103 // UB = min(UB, GlobalUB) 104 // CHECK: [[UB:%.+]] = load i32, i32* [[OMP_UB]] 105 // CHECK-NEXT: [[UBCMP:%.+]] = icmp ugt i32 [[UB]], 16908288 106 // CHECK-NEXT: br i1 [[UBCMP]], label [[UB_TRUE:%[^,]+]], label [[UB_FALSE:%[^,]+]] 107 // CHECK: [[UBRESULT:%.+]] = phi i32 [ 16908288, [[UB_TRUE]] ], [ [[UBVAL:%[^,]+]], [[UB_FALSE]] ] 108 // CHECK-NEXT: store i32 [[UBRESULT]], i32* [[OMP_UB]] 109 // CHECK-NEXT: [[LB:%.+]] = load i32, i32* [[OMP_LB]] 110 // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]] 111 112 // Outer loop header 113 // CHECK: [[O_IV:%.+]] = load i32, i32* [[OMP_IV]] 114 // CHECK-NEXT: [[O_UB:%.+]] = load i32, i32* [[OMP_UB]] 115 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ule i32 [[O_IV]], [[O_UB]] 116 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]] 117 118 // Loop header 119 // CHECK: [[O_LOOP1_BODY]] 120 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]] 121 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]] 122 // CHECK-NEXT: [[CMP:%.+]] = icmp ule i32 [[IV]], [[UB]] 123 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]] 124 for (unsigned i = 131071; i <= 2147483647; i += 127) { 125 // CHECK: [[LOOP1_BODY]] 126 // Start of body: calculate i from IV: 127 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]] 128 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul i32 [[IV1_1]], 127 129 // CHECK-NEXT: [[CALC_I_2:%.+]] = add i32 131071, [[CALC_I_1]] 130 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]] 131 // ... loop body ... 132 // End of body: store into a[i]: 133 // CHECK: store float [[RESULT:%.+]], float* {{%.+}} 134 // CHECK-NOT: !llvm.mem.parallel_loop_access 135 a[i] = b[i] * c[i] * d[i]; 136 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}} 137 // CHECK-NEXT: [[ADD1_2:%.+]] = add i32 [[IV1_2]], 1 138 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]] 139 // CHECK-NEXT: br label %{{.+}} 140 } 141 // CHECK: [[LOOP1_END]] 142 // Update the counters, adding stride 143 // CHECK: [[LB:%.+]] = load i32, i32* [[OMP_LB]] 144 // CHECK-NEXT: [[ST:%.+]] = load i32, i32* [[OMP_ST]] 145 // CHECK-NEXT: [[ADD_LB:%.+]] = add i32 [[LB]], [[ST]] 146 // CHECK-NEXT: store i32 [[ADD_LB]], i32* [[OMP_LB]] 147 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]] 148 // CHECK-NEXT: [[ST:%.+]] = load i32, i32* [[OMP_ST]] 149 // CHECK-NEXT: [[ADD_UB:%.+]] = add i32 [[UB]], [[ST]] 150 // CHECK-NEXT: store i32 [[ADD_UB]], i32* [[OMP_UB]] 151 152 // CHECK: [[O_LOOP1_END]] 153 // CHECK: call void @__kmpc_for_static_fini([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]]) 154 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]]) 155 // CHECK: ret void 156 } 157 158 // CHECK-LABEL: define {{.*void}} @{{.*}}dynamic1{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) 159 void dynamic1(float *a, float *b, float *c, float *d) { 160 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) 161 #pragma omp for schedule(dynamic) 162 // CHECK: call void @__kmpc_dispatch_init_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 35, i64 0, i64 16908287, i64 1, i64 1) 163 // 164 // CHECK: [[HASWORK:%.+]] = call i32 @__kmpc_dispatch_next_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32* [[OMP_ISLAST:%[^,]+]], i64* [[OMP_LB:%[^,]+]], i64* [[OMP_UB:%[^,]+]], i64* [[OMP_ST:%[^,]+]]) 165 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ne i32 [[HASWORK]], 0 166 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]] 167 168 // Loop header 169 // CHECK: [[O_LOOP1_BODY]] 170 // CHECK: [[LB:%.+]] = load i64, i64* [[OMP_LB]] 171 // CHECK-NEXT: store i64 [[LB]], i64* [[OMP_IV:[^,]+]] 172 // CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]] 173 174 // CHECK-NEXT: [[UB:%.+]] = load i64, i64* [[OMP_UB]] 175 // CHECK-NEXT: [[CMP:%.+]] = icmp ule i64 [[IV]], [[UB]] 176 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]] 177 for (unsigned long long i = 131071; i < 2147483647; i += 127) { 178 // CHECK: [[LOOP1_BODY]] 179 // Start of body: calculate i from IV: 180 // CHECK: [[IV1_1:%.+]] = load i64, i64* [[OMP_IV]] 181 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul i64 [[IV1_1]], 127 182 // CHECK-NEXT: [[CALC_I_2:%.+]] = add i64 131071, [[CALC_I_1]] 183 // CHECK-NEXT: store i64 [[CALC_I_2]], i64* [[LC_I:.+]] 184 // ... loop body ... 185 // End of body: store into a[i]: 186 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}!llvm.mem.parallel_loop_access 187 a[i] = b[i] * c[i] * d[i]; 188 // CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]{{.*}} 189 // CHECK-NEXT: [[ADD1_2:%.+]] = add i64 [[IV1_2]], 1 190 // CHECK-NEXT: store i64 [[ADD1_2]], i64* [[OMP_IV]] 191 // CHECK-NEXT: br label %{{.+}} 192 } 193 // CHECK: [[LOOP1_END]] 194 // CHECK: [[O_LOOP1_END]] 195 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]]) 196 // CHECK: ret void 197 } 198 199 // CHECK-LABEL: define {{.*void}} @{{.*}}guided7{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) 200 void guided7(float *a, float *b, float *c, float *d) { 201 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) 202 #pragma omp for schedule(guided, 7) 203 // CHECK: call void @__kmpc_dispatch_init_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 36, i64 0, i64 16908287, i64 1, i64 7) 204 // 205 // CHECK: [[HASWORK:%.+]] = call i32 @__kmpc_dispatch_next_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32* [[OMP_ISLAST:%[^,]+]], i64* [[OMP_LB:%[^,]+]], i64* [[OMP_UB:%[^,]+]], i64* [[OMP_ST:%[^,]+]]) 206 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ne i32 [[HASWORK]], 0 207 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]] 208 209 // Loop header 210 // CHECK: [[O_LOOP1_BODY]] 211 // CHECK: [[LB:%.+]] = load i64, i64* [[OMP_LB]] 212 // CHECK-NEXT: store i64 [[LB]], i64* [[OMP_IV:[^,]+]] 213 // CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]] 214 215 // CHECK-NEXT: [[UB:%.+]] = load i64, i64* [[OMP_UB]] 216 // CHECK-NEXT: [[CMP:%.+]] = icmp ule i64 [[IV]], [[UB]] 217 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]] 218 for (unsigned long long i = 131071; i < 2147483647; i += 127) { 219 // CHECK: [[LOOP1_BODY]] 220 // Start of body: calculate i from IV: 221 // CHECK: [[IV1_1:%.+]] = load i64, i64* [[OMP_IV]] 222 // CHECK-NEXT: [[CALC_I_1:%.+]] = mul i64 [[IV1_1]], 127 223 // CHECK-NEXT: [[CALC_I_2:%.+]] = add i64 131071, [[CALC_I_1]] 224 // CHECK-NEXT: store i64 [[CALC_I_2]], i64* [[LC_I:.+]] 225 // ... loop body ... 226 // End of body: store into a[i]: 227 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}!llvm.mem.parallel_loop_access 228 a[i] = b[i] * c[i] * d[i]; 229 // CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]{{.*}} 230 // CHECK-NEXT: [[ADD1_2:%.+]] = add i64 [[IV1_2]], 1 231 // CHECK-NEXT: store i64 [[ADD1_2]], i64* [[OMP_IV]] 232 // CHECK-NEXT: br label %{{.+}} 233 } 234 // CHECK: [[LOOP1_END]] 235 // CHECK: [[O_LOOP1_END]] 236 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]]) 237 // CHECK: ret void 238 } 239 240 // CHECK-LABEL: define {{.*void}} @{{.*}}test_auto{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) 241 void test_auto(float *a, float *b, float *c, float *d) { 242 unsigned int x = 0; 243 unsigned int y = 0; 244 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) 245 #pragma omp for schedule(auto) collapse(2) 246 // CHECK: call void @__kmpc_dispatch_init_8([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 38, i64 0, i64 [[LAST_ITER:%[^,]+]], i64 1, i64 1) 247 // 248 // CHECK: [[HASWORK:%.+]] = call i32 @__kmpc_dispatch_next_8([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32* [[OMP_ISLAST:%[^,]+]], i64* [[OMP_LB:%[^,]+]], i64* [[OMP_UB:%[^,]+]], i64* [[OMP_ST:%[^,]+]]) 249 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ne i32 [[HASWORK]], 0 250 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]] 251 252 // Loop header 253 // CHECK: [[O_LOOP1_BODY]] 254 // CHECK: [[LB:%.+]] = load i64, i64* [[OMP_LB]] 255 // CHECK-NEXT: store i64 [[LB]], i64* [[OMP_IV:[^,]+]] 256 // CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]] 257 258 // CHECK-NEXT: [[UB:%.+]] = load i64, i64* [[OMP_UB]] 259 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i64 [[IV]], [[UB]] 260 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]] 261 // FIXME: When the iteration count of some nested loop is not a known constant, 262 // we should pre-calculate it, like we do for the total number of iterations! 263 for (char i = static_cast<char>(y); i <= '9'; ++i) 264 for (x = 11; x > 0; --x) { 265 // CHECK: [[LOOP1_BODY]] 266 // Start of body: indices are calculated from IV: 267 // CHECK: store i8 {{%[^,]+}}, i8* {{%[^,]+}} 268 // CHECK: store i32 {{%[^,]+}}, i32* {{%[^,]+}} 269 // ... loop body ... 270 // End of body: store into a[i]: 271 // CHECK: store float [[RESULT:%.+]], float* {{%.+}} 272 // CHECK-NOT: !llvm.mem.parallel_loop_access 273 a[i] = b[i] * c[i] * d[i]; 274 // CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]{{.*}} 275 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i64 [[IV1_2]], 1 276 // CHECK-NEXT: store i64 [[ADD1_2]], i64* [[OMP_IV]] 277 // CHECK-NEXT: br label %{{.+}} 278 } 279 // CHECK: [[LOOP1_END]] 280 // CHECK: [[O_LOOP1_END]] 281 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]]) 282 // CHECK: ret void 283 } 284 285 // CHECK-LABEL: define {{.*void}} @{{.*}}runtime{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}}) 286 void runtime(float *a, float *b, float *c, float *d) { 287 int x = 0; 288 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]]) 289 #pragma omp for collapse(2) schedule(runtime) 290 // CHECK: call void @__kmpc_dispatch_init_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 37, i32 0, i32 199, i32 1, i32 1) 291 // 292 // CHECK: [[HASWORK:%.+]] = call i32 @__kmpc_dispatch_next_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32* [[OMP_ISLAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]]) 293 // CHECK-NEXT: [[O_CMP:%.+]] = icmp ne i32 [[HASWORK]], 0 294 // CHECK-NEXT: br i1 [[O_CMP]], label %[[O_LOOP1_BODY:[^,]+]], label %[[O_LOOP1_END:[^,]+]] 295 296 // Loop header 297 // CHECK: [[O_LOOP1_BODY]] 298 // CHECK: [[LB:%.+]] = load i32, i32* [[OMP_LB]] 299 // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]] 300 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]] 301 302 // CHECK-NEXT: [[UB:%.+]] = load i32, i32* [[OMP_UB]] 303 // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]] 304 // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]] 305 for (unsigned char i = '0' ; i <= '9'; ++i) 306 for (x = -10; x < 10; ++x) { 307 // CHECK: [[LOOP1_BODY]] 308 // Start of body: indices are calculated from IV: 309 // CHECK: store i8 {{%[^,]+}}, i8* {{%[^,]+}} 310 // CHECK: store i32 {{%[^,]+}}, i32* {{%[^,]+}} 311 // ... loop body ... 312 // End of body: store into a[i]: 313 // CHECK: store float [[RESULT:%.+]], float* {{%.+}} 314 // CHECK-NOT: !llvm.mem.parallel_loop_access 315 a[i] = b[i] * c[i] * d[i]; 316 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}} 317 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1 318 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]] 319 // CHECK-NEXT: br label %{{.+}} 320 } 321 // CHECK: [[LOOP1_END]] 322 // CHECK: [[O_LOOP1_END]] 323 // CHECK: call {{.+}} @__kmpc_barrier([[IDENT_T_TY]]* [[IMPLICIT_BARRIER_LOC]], i32 [[GTID]]) 324 // CHECK: ret void 325 } 326 327 // CHECK-LABEL: test_precond 328 void test_precond() { 329 // CHECK: [[A_ADDR:%.+]] = alloca i8, 330 // CHECK: [[I_ADDR:%.+]] = alloca i8, 331 char a = 0; 332 // CHECK: store i8 0, 333 // CHECK: store i32 334 // CHECK: store i8 335 // CHECK: [[A:%.+]] = load i8, i8* [[A_ADDR]], 336 // CHECK: [[CONV:%.+]] = sext i8 [[A]] to i32 337 // CHECK: [[CMP:%.+]] = icmp slt i32 [[CONV]], 10 338 // CHECK: br i1 [[CMP]], label %[[PRECOND_THEN:[^,]+]], label %[[PRECOND_END:[^,]+]] 339 // CHECK: [[PRECOND_THEN]] 340 // CHECK: call void @__kmpc_for_static_init_4 341 #pragma omp for 342 for(char i = a; i < 10; ++i); 343 // CHECK: call void @__kmpc_for_static_fini 344 // CHECK: [[PRECOND_END]] 345 } 346 347 // TERM_DEBUG-LABEL: foo 348 int foo() {return 0;}; 349 350 // TERM_DEBUG-LABEL: parallel_for 351 void parallel_for(float *a) { 352 #pragma omp parallel 353 #pragma omp for schedule(static, 5) 354 // TERM_DEBUG-NOT: __kmpc_global_thread_num 355 // TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]] 356 // TERM_DEBUG: invoke i32 {{.*}}foo{{.*}}() 357 // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]], 358 // TERM_DEBUG-NOT: __kmpc_global_thread_num 359 // TERM_DEBUG: call void @__kmpc_for_static_fini({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]] 360 // TERM_DEBUG: call {{.+}} @__kmpc_barrier({{.+}}), !dbg [[DBG_LOC_CANCEL:![0-9]+]] 361 // TERM_DEBUG: [[TERM_LPAD]] 362 // TERM_DEBUG: call void @__clang_call_terminate 363 // TERM_DEBUG: unreachable 364 for (unsigned i = 131071; i <= 2147483647; i += 127) 365 a[i] += foo(); 366 } 367 // Check source line corresponds to "#pragma omp for schedule(static, 5)" above: 368 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-15]], 369 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-16]], 370 // TERM_DEBUG-DAG: [[DBG_LOC_CANCEL]] = !DILocation(line: [[@LINE-17]], 371 372 char i = 1, j = 2, k = 3; 373 // CHECK-LABEL: for_with_global_lcv 374 void for_with_global_lcv() { 375 // CHECK: [[I_ADDR:%.+]] = alloca i8, 376 // CHECK: [[J_ADDR:%.+]] = alloca i8, 377 378 // CHECK: call void @__kmpc_for_static_init_4( 379 // CHECK-NOT: [[I]] 380 // CHECK: store i8 %{{.+}}, i8* [[I_ADDR]] 381 // CHECK-NOT: [[I]] 382 // CHECK: [[I_VAL:%.+]] = load i8, i8* [[I_ADDR]], 383 // CHECK-NOT: [[I]] 384 // CHECK: store i8 [[I_VAL]], i8* [[K]] 385 // CHECK-NOT: [[I]] 386 // CHECK: call void @__kmpc_for_static_fini( 387 // CHECK: call void @__kmpc_barrier( 388 #pragma omp for 389 for (i = 0; i < 2; ++i) { 390 k = i; 391 } 392 // CHECK: call void @__kmpc_for_static_init_4( 393 // CHECK-NOT: [[J]] 394 // CHECK: store i8 %{{.+}}, i8* [[J_ADDR]] 395 // CHECK-NOT: [[J]] 396 // CHECK: [[J_VAL:%.+]] = load i8, i8* [[J_ADDR]], 397 // CHECK-NOT: [[J]] 398 // CHECK: store i8 [[J_VAL]], i8* [[K]] 399 // CHECK-NOT: [[J]] 400 // CHECK: call void @__kmpc_for_static_fini( 401 #pragma omp for collapse(2) 402 for (int i = 0; i < 2; ++i) 403 for (j = 0; j < 2; ++j) { 404 k = i; 405 k = j; 406 } 407 char &cnt = i; 408 #pragma omp for 409 for (cnt = 0; cnt < 2; ++cnt) 410 k = cnt; 411 } 412 413 // CHECK-LABEL: for_with_references 414 void for_with_references() { 415 // CHECK: [[I:%.+]] = alloca i8, 416 // CHECK: [[CNT:%.+]] = alloca i8*, 417 // CHECK: [[CNT_PRIV:%.+]] = alloca i8, 418 // CHECK: call void @__kmpc_for_static_init_4( 419 // CHECK-NOT: load i8, i8* [[CNT]], 420 // CHECK: call void @__kmpc_for_static_fini( 421 char i = 0; 422 char &cnt = i; 423 #pragma omp for 424 for (cnt = 0; cnt < 2; ++cnt) 425 k = cnt; 426 } 427 428 struct Bool { 429 Bool(bool b) : b(b) {} 430 operator bool() const { return b; } 431 const bool b; 432 }; 433 434 template <typename T> 435 struct It { 436 It() : p(0) {} 437 It(const It &, int = 0) ; 438 template <typename U> 439 It(U &, int = 0) ; 440 It &operator=(const It &); 441 It &operator=(It &); 442 ~It() {} 443 444 It(T *p) : p(p) {} 445 446 operator T *&() { return p; } 447 operator T *() const { return p; } 448 T *operator->() const { return p; } 449 450 It &operator++() { ++p; return *this; } 451 It &operator--() { --p; return *this; } 452 It &operator+=(unsigned n) { p += n; return *this; } 453 It &operator-=(unsigned n) { p -= n; return *this; } 454 455 T *p; 456 }; 457 458 template <typename T> 459 It<T> operator+(It<T> a, typename It<T>::difference_type n) { return a.p + n; } 460 461 template <typename T> 462 It<T> operator+(typename It<T>::difference_type n, It<T> a) { return a.p + n; } 463 464 template <typename T> 465 It<T> operator-(It<T> a, typename It<T>::difference_type n) { return a.p - n; } 466 467 typedef Bool BoolType; 468 469 template <typename T> 470 BoolType operator<(It<T> a, It<T> b) { return a.p < b.p; } 471 472 void loop_with_It(It<char> begin, It<char> end) { 473 #pragma omp for 474 for (It<char> it = begin; it < end; ++it) { 475 *it = 0; 476 } 477 } 478 479 // CHECK-LABEL: loop_with_It 480 // CHECK: call i32 @__kmpc_global_thread_num( 481 // CHECK: call void @__kmpc_for_static_init_8( 482 // CHECK: call void @__kmpc_for_static_fini( 483 484 void loop_with_stmt_expr() { 485 #pragma omp for 486 for (int i = __extension__({float b = 0;b; }); i < __extension__({double c = 1;c; }); i += __extension__({char d = 1; d; })) 487 ; 488 } 489 // CHECK-LABEL: loop_with_stmt_expr 490 // CHECK: call i32 @__kmpc_global_thread_num( 491 // CHECK: call void @__kmpc_for_static_init_4( 492 // CHECK: call void @__kmpc_for_static_fini( 493 494 #endif // HEADER 495