blob: a61557a9619cfd932c02ebb66db2fa503192ca7b [file] [log] [blame]
Justin Bogner2e5d4842015-04-30 22:58:28 +00001// Tests for instrumentation of C++11 range-for
2
Rong Xu9837ef52016-02-04 18:39:09 +00003// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument=clang > %tgen
Justin Bogner2e5d4842015-04-30 22:58:28 +00004// RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
5
6// RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
Rong Xu9c6f1532016-03-02 20:59:36 +00007// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse
Justin Bogner2e5d4842015-04-30 22:58:28 +00008// RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
9
Xinliang David Liddbdb1e2015-12-15 00:33:12 +000010// PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
Justin Bogner2e5d4842015-04-30 22:58:28 +000011
David Blaikieea3e51d2015-06-29 17:29:50 +000012// CHECK-LABEL: define {{.*}}void @_Z9range_forv()
Justin Bogner2e5d4842015-04-30 22:58:28 +000013// PGOGEN: store {{.*}} @[[RFC]], i64 0, i64 0
14void range_for() {
15 int arr[] = {1, 2, 3, 4, 5};
16 int sum = 0;
17 // PGOGEN: store {{.*}} @[[RFC]], i64 0, i64 1
18 // PGOUSE: br {{.*}} !prof ![[RF1:[0-9]+]]
19 for (auto i : arr) {
20 // PGOGEN: store {{.*}} @[[RFC]], i64 0, i64 2
21 // PGOUSE: br {{.*}} !prof ![[RF2:[0-9]+]]
22 if (i == 3)
23 continue;
24 sum += i;
25 // PGOGEN: store {{.*}} @[[RFC]], i64 0, i64 3
26 // PGOUSE: br {{.*}} !prof ![[RF3:[0-9]+]]
27 if (sum >= 7)
28 break;
29 }
30
31 // PGOGEN: store {{.*}} @[[RFC]], i64 0, i64 4
32 // PGOUSE: br {{.*}} !prof ![[RF4:[0-9]+]]
33 if (sum) {}
34}
35
36// PGOUSE-DAG: ![[RF1]] = !{!"branch_weights", i32 5, i32 1}
37// PGOUSE-DAG: ![[RF2]] = !{!"branch_weights", i32 2, i32 4}
38// PGOUSE-DAG: ![[RF3]] = !{!"branch_weights", i32 2, i32 3}
39// PGOUSE-DAG: ![[RF4]] = !{!"branch_weights", i32 2, i32 1}
40
41int main(int argc, const char *argv[]) {
42 range_for();
43 return 0;
44}