• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Tests for instrumentation of C++11 range-for
2 
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
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
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
8 // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
9 
10 // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
11 
12 // CHECK-LABEL: define {{.*}}void @_Z9range_forv()
13 // PGOGEN: store {{.*}} @[[RFC]], i64 0, i64 0
range_for()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 
main(int argc,const char * argv[])41 int main(int argc, const char *argv[]) {
42   range_for();
43   return 0;
44 }
45