brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 43bdaa9 Raw
45 lines · cpp
1// Tests for instrumentation of C++11 range-for2 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 > %tgen4// RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s5 6// RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata7// 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=clang -fprofile-instrument-use-path=%t.profdata > %tuse8// RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s9 10// PGOGEN: @[[RFC:__profc__Z9range_forv]] = {{(private|internal)}} global [5 x i64] zeroinitializer11 12// CHECK-LABEL: define {{.*}}void @_Z9range_forv()13// PGOGEN: store {{.*}} @[[RFC]]14void range_for() {15  int arr[] = {1, 2, 3, 4, 5};16  int sum = 0;17  // PGOGEN: store {{.*}} @[[RFC]], i32 0, i32 118  // PGOUSE: br {{.*}} !prof ![[RF1:[0-9]+]]19  for (auto i : arr) {20    // PGOGEN: store {{.*}} @[[RFC]], i32 0, i32 221    // PGOUSE: br {{.*}} !prof ![[RF2:[0-9]+]]22    if (i == 3)23      continue;24    sum += i;25    // PGOGEN: store {{.*}} @[[RFC]], i32 0, i32 326    // PGOUSE: br {{.*}} !prof ![[RF3:[0-9]+]]27    if (sum >= 7)28      break;29  }30 31  // PGOGEN: store {{.*}} @[[RFC]], i32 0, i32 432  // 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}45