Justin Bogner | 2e5d484 | 2015-04-30 22:58:28 +0000 | [diff] [blame] | 1 | // Tests for instrumentation of C++11 range-for |
| 2 | |
Rong Xu | 9837ef5 | 2016-02-04 18:39:09 +0000 | [diff] [blame] | 3 | // 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 Bogner | 2e5d484 | 2015-04-30 22:58:28 +0000 | [diff] [blame] | 4 | // 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 Xu | 9c6f153 | 2016-03-02 20:59:36 +0000 | [diff] [blame] | 7 | // 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 Bogner | 2e5d484 | 2015-04-30 22:58:28 +0000 | [diff] [blame] | 8 | // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s |
| 9 | |
Xinliang David Li | ddbdb1e | 2015-12-15 00:33:12 +0000 | [diff] [blame] | 10 | // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer |
Justin Bogner | 2e5d484 | 2015-04-30 22:58:28 +0000 | [diff] [blame] | 11 | |
David Blaikie | ea3e51d | 2015-06-29 17:29:50 +0000 | [diff] [blame] | 12 | // CHECK-LABEL: define {{.*}}void @_Z9range_forv() |
Justin Bogner | 2e5d484 | 2015-04-30 22:58:28 +0000 | [diff] [blame] | 13 | // PGOGEN: store {{.*}} @[[RFC]], i64 0, i64 0 |
| 14 | void 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 | |
| 41 | int main(int argc, const char *argv[]) { |
| 42 | range_for(); |
| 43 | return 0; |
| 44 | } |