1 // Test instrumentation of general constructs in C.
2
3 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument=clang | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOGEN %s
4
5 // RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
6 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
7 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v5 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
8 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
9 // Also check compatibility with older profiles.
10 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c %s -o - -emit-llvm -fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck -allow-deprecated-dag-overlap -check-prefix=PGOUSE %s
11
12 // PGOGEN: @[[SLC:__profc_simple_loops]] = private global [4 x i64] zeroinitializer
13 // PGOGEN: @[[IFC:__profc_conditionals]] = private global [13 x i64] zeroinitializer
14 // PGOGEN: @[[EEC:__profc_early_exits]] = private global [9 x i64] zeroinitializer
15 // PGOGEN: @[[JMC:__profc_jumps]] = private global [22 x i64] zeroinitializer
16 // PGOGEN: @[[SWC:__profc_switches]] = private global [19 x i64] zeroinitializer
17 // PGOGEN: @[[BSC:__profc_big_switch]] = private global [17 x i64] zeroinitializer
18 // PGOGEN: @[[BOC:__profc_boolean_operators]] = private global [14 x i64] zeroinitializer
19 // PGOGEN: @[[BLC:__profc_boolop_loops]] = private global [13 x i64] zeroinitializer
20 // PGOGEN: @[[COC:__profc_conditional_operator]] = private global [3 x i64] zeroinitializer
21 // PGOGEN: @[[DFC:__profc_do_fallthrough]] = private global [4 x i64] zeroinitializer
22 // PGOGEN: @[[MAC:__profc_main]] = private global [1 x i64] zeroinitializer
23 // PGOGEN: @[[STC:__profc_c_general.c_static_func]] = private global [2 x i64] zeroinitializer
24
25 // PGOGEN-LABEL: @simple_loops()
26 // PGOUSE-LABEL: @simple_loops()
27 // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 0
simple_loops()28 void simple_loops() {
29 int i;
30 // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 1
31 // PGOUSE: br {{.*}} !prof ![[SL1:[0-9]+]]
32 for (i = 0; i < 100; ++i) {
33 }
34 // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 2
35 // PGOUSE: br {{.*}} !prof ![[SL2:[0-9]+]]
36 while (i > 0)
37 i--;
38 // PGOGEN: store {{.*}} @[[SLC]], i64 0, i64 3
39 // PGOUSE: br {{.*}} !prof ![[SL3:[0-9]+]]
40 do {} while (i++ < 75);
41
42 // PGOGEN-NOT: store {{.*}} @[[SLC]],
43 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
44 }
45
46 // PGOGEN-LABEL: @conditionals()
47 // PGOUSE-LABEL: @conditionals()
48 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 0
conditionals()49 void conditionals() {
50 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 1
51 // PGOUSE: br {{.*}} !prof ![[IF1:[0-9]+]]
52 for (int i = 0; i < 100; ++i) {
53 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 2
54 // PGOUSE: br {{.*}} !prof ![[IF2:[0-9]+]]
55 if (i % 2) {
56 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 3
57 // PGOUSE: br {{.*}} !prof ![[IF3:[0-9]+]]
58 if (i) {}
59 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 4
60 // PGOUSE: br {{.*}} !prof ![[IF4:[0-9]+]]
61 } else if (i % 3) {
62 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 5
63 // PGOUSE: br {{.*}} !prof ![[IF5:[0-9]+]]
64 if (i) {}
65 } else {
66 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 6
67 // PGOUSE: br {{.*}} !prof ![[IF6:[0-9]+]]
68 if (i) {}
69 }
70
71 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 8
72 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 9
73 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 7
74 // PGOUSE: br {{.*}} !prof ![[IF7:[0-9]+]]
75 if (1 && i) {}
76 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 11
77 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 12
78 // PGOGEN: store {{.*}} @[[IFC]], i64 0, i64 10
79 // PGOUSE: br {{.*}} !prof ![[IF8:[0-9]+]]
80 if (0 || i) {}
81 }
82
83 // PGOGEN-NOT: store {{.*}} @[[IFC]],
84 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
85 }
86
87 // PGOGEN-LABEL: @early_exits()
88 // PGOUSE-LABEL: @early_exits()
89 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 0
early_exits()90 void early_exits() {
91 int i = 0;
92
93 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 1
94 // PGOUSE: br {{.*}} !prof ![[EE1:[0-9]+]]
95 if (i) {}
96
97 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 2
98 // PGOUSE: br {{.*}} !prof ![[EE2:[0-9]+]]
99 while (i < 100) {
100 i++;
101 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 3
102 // PGOUSE: br {{.*}} !prof ![[EE3:[0-9]+]]
103 if (i > 50)
104 break;
105 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 4
106 // PGOUSE: br {{.*}} !prof ![[EE4:[0-9]+]]
107 if (i % 2)
108 continue;
109 }
110
111 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 5
112 // PGOUSE: br {{.*}} !prof ![[EE5:[0-9]+]]
113 if (i) {}
114
115 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 6
116 do {
117 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 7
118 // PGOUSE: br {{.*}} !prof ![[EE6:[0-9]+]]
119 if (i > 75)
120 return;
121 else
122 i++;
123 // PGOUSE: br {{.*}} !prof ![[EE7:[0-9]+]]
124 } while (i < 100);
125
126 // PGOGEN: store {{.*}} @[[EEC]], i64 0, i64 8
127 // Never reached -> no weights
128 if (i) {}
129
130 // PGOGEN-NOT: store {{.*}} @[[EEC]],
131 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
132 }
133
134 // PGOGEN-LABEL: @jumps()
135 // PGOUSE-LABEL: @jumps()
136 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 0
jumps()137 void jumps() {
138 int i;
139
140 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 1
141 // PGOUSE: br {{.*}} !prof ![[JM1:[0-9]+]]
142 for (i = 0; i < 2; ++i) {
143 goto outofloop;
144 // Never reached -> no weights
145 if (i) {}
146 }
147 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 3
148 outofloop:
149 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 4
150 // PGOUSE: br {{.*}} !prof ![[JM2:[0-9]+]]
151 if (i) {}
152
153 goto loop1;
154
155 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 5
156 // PGOUSE: br {{.*}} !prof ![[JM3:[0-9]+]]
157 while (i) {
158 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 6
159 loop1:
160 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 7
161 // PGOUSE: br {{.*}} !prof ![[JM4:[0-9]+]]
162 if (i) {}
163 }
164
165 goto loop2;
166 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 8
167 first:
168 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 9
169 second:
170 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 10
171 third:
172 i++;
173 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 11
174 // PGOUSE: br {{.*}} !prof ![[JM5:[0-9]+]]
175 if (i < 3)
176 goto loop2;
177
178 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 12
179 // PGOUSE: br {{.*}} !prof ![[JM6:[0-9]+]]
180 while (i < 3) {
181 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 13
182 loop2:
183 // PGOUSE: switch {{.*}} [
184 // PGOUSE: ], !prof ![[JM7:[0-9]+]]
185 switch (i) {
186 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 15
187 case 0:
188 goto first;
189 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 16
190 case 1:
191 goto second;
192 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 17
193 case 2:
194 goto third;
195 }
196 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 14
197 }
198
199 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 18
200 // PGOUSE: br {{.*}} !prof ![[JM8:[0-9]+]]
201 for (i = 0; i < 10; ++i) {
202 goto withinloop;
203 // never reached -> no weights
204 if (i) {}
205 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 20
206 withinloop:
207 // PGOGEN: store {{.*}} @[[JMC]], i64 0, i64 21
208 // PGOUSE: br {{.*}} !prof ![[JM9:[0-9]+]]
209 if (i) {}
210 }
211
212 // PGOGEN-NOT: store {{.*}} @[[JMC]],
213 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
214 }
215
216 // PGOGEN-LABEL: @switches()
217 // PGOUSE-LABEL: @switches()
218 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 0
switches()219 void switches() {
220 static int weights[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5};
221
222 // No cases -> no weights
223 switch (weights[0]) {
224 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 2
225 default:
226 break;
227 }
228 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 1
229
230 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 3
231 // PGOUSE: br {{.*}} !prof ![[SW1:[0-9]+]]
232 for (int i = 0, len = sizeof(weights) / sizeof(weights[0]); i < len; ++i) {
233 // PGOUSE: switch {{.*}} [
234 // PGOUSE: ], !prof ![[SW2:[0-9]+]]
235 switch (i[weights]) {
236 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 5
237 case 1:
238 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 6
239 // PGOUSE: br {{.*}} !prof ![[SW3:[0-9]+]]
240 if (i) {}
241 // fallthrough
242 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 7
243 case 2:
244 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 8
245 // PGOUSE: br {{.*}} !prof ![[SW4:[0-9]+]]
246 if (i) {}
247 break;
248 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 9
249 case 3:
250 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 10
251 // PGOUSE: br {{.*}} !prof ![[SW5:[0-9]+]]
252 if (i) {}
253 continue;
254 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 11
255 case 4:
256 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 12
257 // PGOUSE: br {{.*}} !prof ![[SW6:[0-9]+]]
258 if (i) {}
259 // PGOUSE: switch {{.*}} [
260 // PGOUSE: ], !prof ![[SW7:[0-9]+]]
261 switch (i) {
262 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 14
263 case 6 ... 9:
264 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 15
265 // PGOUSE: br {{.*}} !prof ![[SW8:[0-9]+]]
266 if (i) {}
267 continue;
268 }
269 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 13
270
271 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 16
272 default:
273 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 17
274 // PGOUSE: br {{.*}} !prof ![[SW9:[0-9]+]]
275 if (i == len - 1)
276 return;
277 }
278 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 4
279 }
280
281 // PGOGEN: store {{.*}} @[[SWC]], i64 0, i64 18
282 // Never reached -> no weights
283 if (weights[0]) {}
284
285 // PGOGEN-NOT: store {{.*}} @[[SWC]],
286 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
287 }
288
289 // PGOGEN-LABEL: @big_switch()
290 // PGOUSE-LABEL: @big_switch()
291 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 0
big_switch()292 void big_switch() {
293 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 1
294 // PGOUSE: br {{.*}} !prof ![[BS1:[0-9]+]]
295 for (int i = 0; i < 32; ++i) {
296 // PGOUSE: switch {{.*}} [
297 // PGOUSE: ], !prof ![[BS2:[0-9]+]]
298 switch (1 << i) {
299 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 3
300 case (1 << 0):
301 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 4
302 // PGOUSE: br {{.*}} !prof ![[BS3:[0-9]+]]
303 if (i) {}
304 // fallthrough
305 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 5
306 case (1 << 1):
307 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 6
308 // PGOUSE: br {{.*}} !prof ![[BS4:[0-9]+]]
309 if (i) {}
310 break;
311 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 7
312 case (1 << 2) ... (1 << 12):
313 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 8
314 // PGOUSE: br {{.*}} !prof ![[BS5:[0-9]+]]
315 if (i) {}
316 break;
317 // The branch for the large case range above appears after the case body
318 // PGOUSE: br {{.*}} !prof ![[BS6:[0-9]+]]
319
320 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 9
321 case (1 << 13):
322 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 10
323 // PGOUSE: br {{.*}} !prof ![[BS7:[0-9]+]]
324 if (i) {}
325 break;
326 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 11
327 case (1 << 14) ... (1 << 28):
328 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 12
329 // PGOUSE: br {{.*}} !prof ![[BS8:[0-9]+]]
330 if (i) {}
331 break;
332 // The branch for the large case range above appears after the case body
333 // PGOUSE: br {{.*}} !prof ![[BS9:[0-9]+]]
334
335 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 13
336 case (1 << 29) ... ((1 << 29) + 1):
337 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 14
338 // PGOUSE: br {{.*}} !prof ![[BS10:[0-9]+]]
339 if (i) {}
340 break;
341 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 15
342 default:
343 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 16
344 // PGOUSE: br {{.*}} !prof ![[BS11:[0-9]+]]
345 if (i) {}
346 break;
347 }
348 // PGOGEN: store {{.*}} @[[BSC]], i64 0, i64 2
349 }
350
351 // PGOGEN-NOT: store {{.*}} @[[BSC]],
352 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
353 // PGOUSE: ret void
354 }
355
356 // PGOGEN-LABEL: @boolean_operators()
357 // PGOUSE-LABEL: @boolean_operators()
358 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 0
boolean_operators()359 void boolean_operators() {
360 int v;
361 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 1
362 // PGOUSE: br {{.*}} !prof ![[BO1:[0-9]+]]
363 for (int i = 0; i < 100; ++i) {
364 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 2
365 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 3
366 // PGOUSE: br {{.*}} !prof ![[BO2:[0-9]+]]
367 v = i % 3 || i;
368
369 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 4
370 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 5
371 // PGOUSE: br {{.*}} !prof ![[BO3:[0-9]+]]
372 v = i % 3 && i;
373
374 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 8
375 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 9
376 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 6
377 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 7
378 // PGOUSE: br {{.*}} !prof ![[BO4:[0-9]+]]
379 // PGOUSE: br {{.*}} !prof ![[BO5:[0-9]+]]
380 v = i % 3 || i % 2 || i;
381
382 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 12
383 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 13
384 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 10
385 // PGOGEN: store {{.*}} @[[BOC]], i64 0, i64 11
386 // PGOUSE: br {{.*}} !prof ![[BO6:[0-9]+]]
387 // PGOUSE: br {{.*}} !prof ![[BO7:[0-9]+]]
388 v = i % 2 && i % 3 && i;
389 }
390
391 // PGOGEN-NOT: store {{.*}} @[[BOC]],
392 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
393 }
394
395 // PGOGEN-LABEL: @boolop_loops()
396 // PGOUSE-LABEL: @boolop_loops()
397 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 0
boolop_loops()398 void boolop_loops() {
399 int i = 100;
400
401 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 2
402 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 3
403 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 1
404 // PGOUSE: br {{.*}} !prof ![[BL1:[0-9]+]]
405 // PGOUSE: br {{.*}} !prof ![[BL2:[0-9]+]]
406 while (i && i > 50)
407 i--;
408
409 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 5
410 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 6
411 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 4
412 // PGOUSE: br {{.*}} !prof ![[BL3:[0-9]+]]
413 // PGOUSE: br {{.*}} !prof ![[BL4:[0-9]+]]
414 while ((i % 2) || (i > 0))
415 i--;
416
417 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 8
418 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 9
419 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 7
420 // PGOUSE: br {{.*}} !prof ![[BL5:[0-9]+]]
421 // PGOUSE: br {{.*}} !prof ![[BL6:[0-9]+]]
422 for (i = 100; i && i > 50; --i);
423
424 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 11
425 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 12
426 // PGOGEN: store {{.*}} @[[BLC]], i64 0, i64 10
427 // PGOUSE: br {{.*}} !prof ![[BL7:[0-9]+]]
428 // PGOUSE: br {{.*}} !prof ![[BL8:[0-9]+]]
429 for (; (i % 2) || (i > 0); --i);
430
431 // PGOGEN-NOT: store {{.*}} @[[BLC]],
432 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
433 }
434
435 // PGOGEN-LABEL: @conditional_operator()
436 // PGOUSE-LABEL: @conditional_operator()
437 // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 0
conditional_operator()438 void conditional_operator() {
439 int i = 100;
440
441 // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 1
442 // PGOUSE: br {{.*}} !prof ![[CO1:[0-9]+]]
443 int j = i < 50 ? i : 1;
444
445 // PGOGEN: store {{.*}} @[[COC]], i64 0, i64 2
446 // PGOUSE: br {{.*}} !prof ![[CO2:[0-9]+]]
447 int k = i ?: 0;
448
449 // PGOGEN-NOT: store {{.*}} @[[COC]],
450 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
451 }
452
453 // PGOGEN-LABEL: @do_fallthrough()
454 // PGOUSE-LABEL: @do_fallthrough()
455 // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 0
do_fallthrough()456 void do_fallthrough() {
457 // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 1
458 // PGOUSE: br {{.*}} !prof ![[DF1:[0-9]+]]
459 for (int i = 0; i < 10; ++i) {
460 int j = 0;
461 // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 2
462 do {
463 // The number of exits out of this do-loop via the break statement
464 // exceeds the counter value for the loop (which does not include the
465 // fallthrough count). Make sure that does not violate any assertions.
466 // PGOGEN: store {{.*}} @[[DFC]], i64 0, i64 3
467 // PGOUSE: br {{.*}} !prof ![[DF3:[0-9]+]]
468 if (i < 8) break;
469 j++;
470 // PGOUSE: br {{.*}} !prof ![[DF2:[0-9]+]]
471 } while (j < 2);
472 }
473 }
474
475 // PGOGEN-LABEL: @static_func()
476 // PGOUSE-LABEL: @static_func()
477 // PGOGEN: store {{.*}} @[[STC]], i64 0, i64 0
static_func()478 static void static_func() {
479 // PGOGEN: store {{.*}} @[[STC]], i64 0, i64 1
480 // PGOUSE: br {{.*}} !prof ![[ST1:[0-9]+]]
481 for (int i = 0; i < 10; ++i) {
482 }
483 }
484
485 // PGOUSE-DAG: ![[SL1]] = !{!"branch_weights", i32 101, i32 2}
486 // PGOUSE-DAG: ![[SL2]] = !{!"branch_weights", i32 101, i32 2}
487 // PGOUSE-DAG: ![[SL3]] = !{!"branch_weights", i32 76, i32 2}
488
489 // PGOUSE-DAG: ![[EE1]] = !{!"branch_weights", i32 1, i32 2}
490 // PGOUSE-DAG: ![[EE2]] = !{!"branch_weights", i32 52, i32 1}
491 // PGOUSE-DAG: ![[EE3]] = !{!"branch_weights", i32 2, i32 51}
492 // PGOUSE-DAG: ![[EE4]] = !{!"branch_weights", i32 26, i32 26}
493 // PGOUSE-DAG: ![[EE5]] = !{!"branch_weights", i32 2, i32 1}
494 // PGOUSE-DAG: ![[EE6]] = !{!"branch_weights", i32 2, i32 26}
495 // PGOUSE-DAG: ![[EE7]] = !{!"branch_weights", i32 26, i32 1}
496
497 // PGOUSE-DAG: ![[IF1]] = !{!"branch_weights", i32 101, i32 2}
498 // PGOUSE-DAG: ![[IF2]] = !{!"branch_weights", i32 51, i32 51}
499 // PGOUSE-DAG: ![[IF3]] = !{!"branch_weights", i32 51, i32 1}
500 // PGOUSE-DAG: ![[IF4]] = !{!"branch_weights", i32 34, i32 18}
501 // PGOUSE-DAG: ![[IF5]] = !{!"branch_weights", i32 34, i32 1}
502 // PGOUSE-DAG: ![[IF6]] = !{!"branch_weights", i32 17, i32 2}
503 // PGOUSE-DAG: ![[IF7]] = !{!"branch_weights", i32 100, i32 2}
504 // PGOUSE-DAG: ![[IF8]] = !{!"branch_weights", i32 100, i32 2}
505
506 // PGOUSE-DAG: ![[JM1]] = !{!"branch_weights", i32 2, i32 1}
507 // PGOUSE-DAG: ![[JM2]] = !{!"branch_weights", i32 1, i32 2}
508 // PGOUSE-DAG: ![[JM3]] = !{!"branch_weights", i32 1, i32 2}
509 // PGOUSE-DAG: ![[JM4]] = !{!"branch_weights", i32 1, i32 2}
510 // PGOUSE-DAG: ![[JM5]] = !{!"branch_weights", i32 3, i32 2}
511 // PGOUSE-DAG: ![[JM6]] = !{!"branch_weights", i32 1, i32 2}
512 // PGOUSE-DAG: ![[JM7]] = !{!"branch_weights", i32 1, i32 2, i32 2, i32 2}
513 // PGOUSE-DAG: ![[JM8]] = !{!"branch_weights", i32 11, i32 2}
514 // PGOUSE-DAG: ![[JM9]] = !{!"branch_weights", i32 10, i32 2}
515
516 // PGOUSE-DAG: ![[SW1]] = !{!"branch_weights", i32 16, i32 1}
517 // PGOUSE-DAG: ![[SW2]] = !{!"branch_weights", i32 6, i32 2, i32 3, i32 4, i32 5}
518 // PGOUSE-DAG: ![[SW3]] = !{!"branch_weights", i32 1, i32 2}
519 // PGOUSE-DAG: ![[SW4]] = !{!"branch_weights", i32 3, i32 2}
520 // PGOUSE-DAG: ![[SW5]] = !{!"branch_weights", i32 4, i32 1}
521 // PGOUSE-DAG: ![[SW6]] = !{!"branch_weights", i32 5, i32 1}
522 // PGOUSE-DAG: ![[SW7]] = !{!"branch_weights", i32 1, i32 2, i32 2, i32 2, i32 2}
523 // PGOUSE-DAG: ![[SW8]] = !{!"branch_weights", i32 5, i32 1}
524 // PGOUSE-DAG: ![[SW9]] = !{!"branch_weights", i32 2, i32 5}
525
526 // PGOUSE-DAG: ![[BS1]] = !{!"branch_weights", i32 33, i32 2}
527 // PGOUSE-DAG: ![[BS2]] = !{!"branch_weights", i32 29, i32 2, i32 2, i32 2, i32 2, i32 1}
528 // PGOUSE-DAG: ![[BS3]] = !{!"branch_weights", i32 1, i32 2}
529 // PGOUSE-DAG: ![[BS4]] = !{!"branch_weights", i32 2, i32 2}
530 // PGOUSE-DAG: ![[BS5]] = !{!"branch_weights", i32 12, i32 1}
531 // PGOUSE-DAG: ![[BS6]] = !{!"branch_weights", i32 12, i32 3}
532 // PGOUSE-DAG: ![[BS7]] = !{!"branch_weights", i32 2, i32 1}
533 // PGOUSE-DAG: ![[BS8]] = !{!"branch_weights", i32 16, i32 1}
534 // PGOUSE-DAG: ![[BS9]] = !{!"branch_weights", i32 16, i32 14}
535 // PGOUSE-DAG: ![[BS10]] = !{!"branch_weights", i32 2, i32 1}
536 // PGOUSE-DAG: ![[BS11]] = !{!"branch_weights", i32 3, i32 1}
537
538 // PGOUSE-DAG: ![[BO1]] = !{!"branch_weights", i32 101, i32 2}
539 // PGOUSE-DAG: ![[BO2]] = !{!"branch_weights", i32 67, i32 35}
540 // PGOUSE-DAG: ![[BO3]] = !{!"branch_weights", i32 67, i32 35}
541 // PGOUSE-DAG: ![[BO4]] = !{!"branch_weights", i32 67, i32 35}
542 // PGOUSE-DAG: ![[BO5]] = !{!"branch_weights", i32 18, i32 18}
543 // PGOUSE-DAG: ![[BO6]] = !{!"branch_weights", i32 51, i32 51}
544 // PGOUSE-DAG: ![[BO7]] = !{!"branch_weights", i32 34, i32 18}
545 // PGOUSE-DAG: ![[BL1]] = !{!"branch_weights", i32 52, i32 1}
546 // PGOUSE-DAG: ![[BL2]] = !{!"branch_weights", i32 51, i32 2}
547 // PGOUSE-DAG: ![[BL3]] = !{!"branch_weights", i32 26, i32 27}
548 // PGOUSE-DAG: ![[BL4]] = !{!"branch_weights", i32 51, i32 2}
549 // PGOUSE-DAG: ![[BL5]] = !{!"branch_weights", i32 52, i32 1}
550 // PGOUSE-DAG: ![[BL6]] = !{!"branch_weights", i32 51, i32 2}
551 // PGOUSE-DAG: ![[BL7]] = !{!"branch_weights", i32 26, i32 27}
552 // PGOUSE-DAG: ![[BL8]] = !{!"branch_weights", i32 51, i32 2}
553 // PGOUSE-DAG: ![[CO1]] = !{!"branch_weights", i32 1, i32 2}
554 // PGOUSE-DAG: ![[CO2]] = !{!"branch_weights", i32 2, i32 1}
555
556 // PGOUSE-DAG: ![[DF1]] = !{!"branch_weights", i32 11, i32 2}
557 // PGOUSE-DAG: ![[DF2]] = !{!"branch_weights", i32 3, i32 3}
558 // PGOUSE-DAG: ![[DF3]] = !{!"branch_weights", i32 9, i32 5}
559
560 // PGOUSE-DAG: ![[ST1]] = !{!"branch_weights", i32 11, i32 2}
561
main(int argc,const char * argv[])562 int main(int argc, const char *argv[]) {
563 simple_loops();
564 conditionals();
565 early_exits();
566 jumps();
567 switches();
568 big_switch();
569 boolean_operators();
570 boolop_loops();
571 conditional_operator();
572 do_fallthrough();
573 static_func();
574 return 0;
575 }
576