• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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* {{.+}})
without_schedule_clause(float * a,float * b,float * c,float * d)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* {{.+}})
static_not_chunked(float * a,float * b,float * c,float * d)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* {{.+}})
static_chunked(float * a,float * b,float * c,float * d)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(monotonic: static, 5)
102 // CHECK: call void @__kmpc_for_static_init_4u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 536870945, 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* {{.+}})
dynamic1(float * a,float * b,float * c,float * d)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(nonmonotonic: dynamic)
162 // CHECK: call void @__kmpc_dispatch_init_8u([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 1073741859, 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* {{.+}})
guided7(float * a,float * b,float * c,float * d)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* {{.+}})
test_auto(float * a,float * b,float * c,float * d)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* {{.+}})
runtime(float * a,float * b,float * c,float * d)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
test_precond()328 void test_precond() {
329   // CHECK: [[A_ADDR:%.+]] = alloca i8,
330   // CHECK: [[CAP:%.+]] = alloca i8,
331   // CHECK: [[I_ADDR:%.+]] = alloca i8,
332   char a = 0;
333   // CHECK: store i8 0,
334   // CHECK: store i32
335   // CHECK: store i8
336   // CHECK: [[A:%.+]] = load i8, i8* [[CAP]],
337   // CHECK: [[CONV:%.+]] = sext i8 [[A]] to i32
338   // CHECK: [[CMP:%.+]] = icmp slt i32 [[CONV]], 10
339   // CHECK: br i1 [[CMP]], label %[[PRECOND_THEN:[^,]+]], label %[[PRECOND_END:[^,]+]]
340   // CHECK: [[PRECOND_THEN]]
341   // CHECK: call void @__kmpc_for_static_init_4
342 #pragma omp for
343   for(char i = a; i < 10; ++i);
344   // CHECK: call void @__kmpc_for_static_fini
345   // CHECK: [[PRECOND_END]]
346 }
347 
348 // TERM_DEBUG-LABEL: foo
foo()349 int foo() {return 0;};
350 
351 // TERM_DEBUG-LABEL: parallel_for
parallel_for(float * a)352 void parallel_for(float *a) {
353 #pragma omp parallel
354 #pragma omp for schedule(static, 5)
355   // TERM_DEBUG-NOT: __kmpc_global_thread_num
356   // TERM_DEBUG:     call void @__kmpc_for_static_init_4u({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
357   // TERM_DEBUG:     invoke i32 {{.*}}foo{{.*}}()
358   // TERM_DEBUG:     unwind label %[[TERM_LPAD:.+]],
359   // TERM_DEBUG-NOT: __kmpc_global_thread_num
360   // TERM_DEBUG:     call void @__kmpc_for_static_fini({{.+}}), !dbg [[DBG_LOC_END:![0-9]+]]
361   // TERM_DEBUG:     call {{.+}} @__kmpc_barrier({{.+}}), !dbg [[DBG_LOC_CANCEL:![0-9]+]]
362   // TERM_DEBUG:     [[TERM_LPAD]]
363   // TERM_DEBUG:     call void @__clang_call_terminate
364   // TERM_DEBUG:     unreachable
365   for (unsigned i = 131071; i <= 2147483647; i += 127)
366     a[i] += foo();
367 }
368 // Check source line corresponds to "#pragma omp for schedule(static, 5)" above:
369 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-15]],
370 // TERM_DEBUG-DAG: [[DBG_LOC_END]] = !DILocation(line: [[@LINE-16]],
371 // TERM_DEBUG-DAG: [[DBG_LOC_CANCEL]] = !DILocation(line: [[@LINE-17]],
372 
373 char i = 1, j = 2, k = 3;
374 // CHECK-LABEL: for_with_global_lcv
for_with_global_lcv()375 void for_with_global_lcv() {
376 // CHECK: [[I_ADDR:%.+]] = alloca i8,
377 // CHECK: [[J_ADDR:%.+]] = alloca i8,
378 
379 // CHECK: call void @__kmpc_for_static_init_4(
380 // CHECK-NOT: [[I]]
381 // CHECK: store i8 %{{.+}}, i8* [[I_ADDR]]
382 // CHECK-NOT: [[I]]
383 // CHECK: [[I_VAL:%.+]] = load i8, i8* [[I_ADDR]],
384 // CHECK-NOT: [[I]]
385 // CHECK: store i8 [[I_VAL]], i8* [[K]]
386 // CHECK-NOT: [[I]]
387 // CHECK: call void @__kmpc_for_static_fini(
388 // CHECK: call void @__kmpc_barrier(
389 #pragma omp for
390   for (i = 0; i < 2; ++i) {
391     k = i;
392   }
393 // CHECK: call void @__kmpc_for_static_init_4(
394 // CHECK-NOT: [[J]]
395 // CHECK: store i8 %{{.+}}, i8* [[J_ADDR]]
396 // CHECK-NOT: [[J]]
397 // CHECK: [[J_VAL:%.+]] = load i8, i8* [[J_ADDR]],
398 // CHECK-NOT: [[J]]
399 // CHECK: store i8 [[J_VAL]], i8* [[K]]
400 // CHECK-NOT: [[J]]
401 // CHECK: call void @__kmpc_for_static_fini(
402 #pragma omp for collapse(2)
403   for (int i = 0; i < 2; ++i)
404   for (j = 0; j < 2; ++j) {
405     k = i;
406     k = j;
407   }
408   char &cnt = i;
409 #pragma omp for
410   for (cnt = 0; cnt < 2; ++cnt)
411     k = cnt;
412 }
413 
414 // CHECK-LABEL: for_with_references
for_with_references()415 void for_with_references() {
416 // CHECK: [[I:%.+]] = alloca i8,
417 // CHECK: [[CNT:%.+]] = alloca i8*,
418 // CHECK: [[CNT_PRIV:%.+]] = alloca i8,
419 // CHECK: call void @__kmpc_for_static_init_4(
420 // CHECK-NOT: load i8, i8* [[CNT]],
421 // CHECK: call void @__kmpc_for_static_fini(
422   char i = 0;
423   char &cnt = i;
424 #pragma omp for
425   for (cnt = 0; cnt < 2; ++cnt)
426     k = cnt;
427 }
428 
429 struct Bool {
BoolBool430   Bool(bool b) : b(b) {}
operator boolBool431   operator bool() const { return b; }
432   const bool b;
433 };
434 
435 template <typename T>
436 struct It {
ItIt437   It() : p(0) {}
438   It(const It &, int = 0) ;
439   template <typename U>
440   It(U &, int = 0) ;
441   It &operator=(const It &);
442   It &operator=(It &);
~ItIt443   ~It() {}
444 
ItIt445   It(T *p) : p(p) {}
446 
operator T*&It447   operator T *&() { return p; }
operator T*It448   operator T *() const { return p; }
operator ->It449   T *operator->() const { return p; }
450 
operator ++It451   It &operator++() { ++p; return *this; }
operator --It452   It &operator--() { --p; return *this; }
operator +=It453   It &operator+=(unsigned n) { p += n; return *this; }
operator -=It454   It &operator-=(unsigned n) { p -= n; return *this; }
455 
456   T *p;
457 };
458 
459 template <typename T>
operator +(It<T> a,typename It<T>::difference_type n)460 It<T> operator+(It<T> a, typename It<T>::difference_type n) { return a.p + n; }
461 
462 template <typename T>
operator +(typename It<T>::difference_type n,It<T> a)463 It<T> operator+(typename It<T>::difference_type n, It<T> a) { return a.p + n; }
464 
465 template <typename T>
operator -(It<T> a,typename It<T>::difference_type n)466 It<T> operator-(It<T> a, typename It<T>::difference_type n) { return a.p - n; }
467 
468 typedef Bool BoolType;
469 
470 template <typename T>
operator <(It<T> a,It<T> b)471 BoolType operator<(It<T> a, It<T> b) { return a.p < b.p; }
472 
loop_with_It(It<char> begin,It<char> end)473 void loop_with_It(It<char> begin, It<char> end) {
474 #pragma omp for
475   for (It<char> it = begin; it < end; ++it) {
476     *it = 0;
477   }
478 }
479 
480 // CHECK-LABEL: loop_with_It
481 // CHECK: call i32 @__kmpc_global_thread_num(
482 // CHECK: call void @__kmpc_for_static_init_8(
483 // CHECK: call void @__kmpc_for_static_fini(
484 
loop_with_stmt_expr()485 void loop_with_stmt_expr() {
486 #pragma omp for
487   for (int i = __extension__({float b = 0;b; }); i < __extension__({double c = 1;c; }); i += __extension__({char d = 1; d; }))
488     ;
489 }
490 // CHECK-LABEL: loop_with_stmt_expr
491 // CHECK: call i32 @__kmpc_global_thread_num(
492 // CHECK: call void @__kmpc_for_static_init_4(
493 // CHECK: call void @__kmpc_for_static_fini(
494 
495 
496 // CHECK-LABEL: fint
497 // CHECK: call {{.*}}i32 {{.*}}ftemplate
498 // CHECK: ret i32
499 
500 // CHECK: load i16, i16*
501 // CHECK: store i16 %
502 // CHECK: call void {{.+}}@__kmpc_fork_call(
503 // CHECK: call void @__kmpc_for_static_init_4(
504 template <typename T>
ftemplate()505 T ftemplate() {
506   short aa = 0;
507 
508 #pragma omp parallel for schedule(static, aa)
509   for (int i = 0; i < 100; i++) {
510   }
511   return T();
512 }
513 
fint(void)514 int fint(void) { return ftemplate<int>(); }
515 
516 #endif // HEADER
517