Home | History | Annotate | Download | only in Profile
      1 // Test instrumentation of C++ exception handling constructs.
      2 
      3 // FIXME: Don't seek bb labels, like "if.else"
      4 // REQUIRES: asserts
      5 
      6 // RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN %s
      7 // RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN-EXC %s
      8 
      9 // RUN: llvm-profdata merge %S/Inputs/cxx-throws.proftext -o %t.profdata
     10 // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE %s
     11 // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE-EXC %s
     12 
     13 // PGOGEN: @[[THC:__llvm_profile_counters__Z6throwsv]] = hidden global [9 x i64] zeroinitializer
     14 // PGOGEN-EXC: @[[THC:__llvm_profile_counters__Z6throwsv]] = hidden global [9 x i64] zeroinitializer
     15 
     16 // PGOGEN-LABEL: @_Z6throwsv()
     17 // PGOUSE-LABEL: @_Z6throwsv()
     18 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0
     19 void throws() {
     20   // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 1
     21   // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]]
     22   for (int i = 0; i < 100; ++i) {
     23     try {
     24       // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 3
     25       // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]]
     26       if (i % 3) {
     27         // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4
     28         // PGOUSE: br {{.*}} !prof ![[TH3:[0-9]+]]
     29         if (i < 50)
     30           throw 1;
     31       } else {
     32         // The catch block may be emitted after the throw above, we can skip it
     33         // by looking for an else block, but this will break if anyone puts an
     34         // else in the catch
     35         // PGOUSE: if.else{{.*}}:
     36         // PGOGEN: if.else{{.*}}:
     37 
     38         // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5
     39         // PGOUSE: br {{.*}} !prof ![[TH4:[0-9]+]]
     40         if (i >= 50)
     41           throw 0;
     42       }
     43     } catch (int e) {
     44       // PGOUSE-EXC: catch{{.*}}:
     45       // PGOGEN-EXC: catch{{.*}}:
     46 
     47       // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 6
     48       // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 7
     49       // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]]
     50       if (e) {}
     51     }
     52     // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 2
     53 
     54     // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 8
     55     // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]]
     56     if (i < 100) {}
     57   }
     58 
     59   // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
     60   // PGOUSE: ret void
     61 }
     62 
     63 // PGOUSE-DAG: ![[TH1]] = metadata !{metadata !"branch_weights", i32 101, i32 2}
     64 // PGOUSE-DAG: ![[TH2]] = metadata !{metadata !"branch_weights", i32 67, i32 35}
     65 // PGOUSE-DAG: ![[TH3]] = metadata !{metadata !"branch_weights", i32 34, i32 34}
     66 // PGOUSE-DAG: ![[TH4]] = metadata !{metadata !"branch_weights", i32 18, i32 18}
     67 // PGOUSE-EXC: ![[TH5]] = metadata !{metadata !"branch_weights", i32 34, i32 18}
     68 // PGOUSE-DAG: ![[TH6]] = metadata !{metadata !"branch_weights", i32 101, i32 1}
     69 
     70 int main(int argc, const char *argv[]) {
     71   throws();
     72   return 0;
     73 }
     74