blob: 17f4d8c2e8d6ccd241ef68a3c88404b463aa18a3 [file] [log] [blame]
Justin Bogner52a6a972014-03-11 04:37:49 +00001// Test instrumentation of C++ exception handling constructs.
Justin Bogneref512b92014-01-06 22:27:43 +00002
NAKAMURA Takumif0f82172014-01-07 00:59:39 +00003// FIXME: Don't seek bb labels, like "if.else"
4// REQUIRES: asserts
5
Filipe Cabecinhasa0764302015-02-26 18:29:41 +00006// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -fexceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN %s
7// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -fexceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN-EXC %s
Justin Bogneref512b92014-01-06 22:27:43 +00008
Justin Bogner534f14a2014-04-17 22:49:06 +00009// RUN: llvm-profdata merge %S/Inputs/cxx-throws.proftext -o %t.profdata
Filipe Cabecinhasa0764302015-02-26 18:29:41 +000010// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -fcxx-exceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE %s
11// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -fcxx-exceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE-EXC %s
Justin Bogneref512b92014-01-06 22:27:43 +000012
Duncan P. N. Exon Smith91212202014-05-16 01:24:00 +000013// 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
Justin Bogneref512b92014-01-06 22:27:43 +000015
16// PGOGEN-LABEL: @_Z6throwsv()
17// PGOUSE-LABEL: @_Z6throwsv()
18// PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0
19void 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 {
Bob Wilsonbf854f02014-02-17 19:21:09 +000024 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 3
Justin Bogneref512b92014-01-06 22:27:43 +000025 // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]]
26 if (i % 3) {
Bob Wilsonbf854f02014-02-17 19:21:09 +000027 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4
Justin Bogneref512b92014-01-06 22:27:43 +000028 // 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
Bob Wilsonbf854f02014-02-17 19:21:09 +000038 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5
Justin Bogneref512b92014-01-06 22:27:43 +000039 // 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
Bob Wilsonbf854f02014-02-17 19:21:09 +000047 // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 6
48 // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 7
Justin Bogneref512b92014-01-06 22:27:43 +000049 // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]]
50 if (e) {}
51 }
Bob Wilsonbf854f02014-02-17 19:21:09 +000052 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 2
Justin Bogneref512b92014-01-06 22:27:43 +000053
Bob Wilsonbf854f02014-02-17 19:21:09 +000054 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 8
Justin Bogneref512b92014-01-06 22:27:43 +000055 // 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
Duncan P. N. Exon Smithb3a66692014-12-15 19:10:08 +000063// PGOUSE-DAG: ![[TH1]] = !{!"branch_weights", i32 101, i32 2}
64// PGOUSE-DAG: ![[TH2]] = !{!"branch_weights", i32 67, i32 35}
65// PGOUSE-DAG: ![[TH3]] = !{!"branch_weights", i32 34, i32 34}
66// PGOUSE-DAG: ![[TH4]] = !{!"branch_weights", i32 18, i32 18}
67// PGOUSE-EXC: ![[TH5]] = !{!"branch_weights", i32 34, i32 18}
68// PGOUSE-DAG: ![[TH6]] = !{!"branch_weights", i32 101, i32 1}
Justin Bogneref512b92014-01-06 22:27:43 +000069
70int main(int argc, const char *argv[]) {
71 throws();
72 return 0;
73}