blob: 266c921456d1855cd13b982b45149fdb4aee81ec [file] [log] [blame]
Justin Bogneref512b92014-01-06 22:27:43 +00001// Test that instrumentation based profiling feeds branch prediction
2// correctly. This tests both generation of profile data and use of the same,
3// and the input file for the -fprofile-instr-use case is expected to be result
4// of running the program generated by the -fprofile-instr-generate case. As
5// such, main() should call every function in this test.
6
NAKAMURA Takumif0f82172014-01-07 00:59:39 +00007// FIXME: Don't seek bb labels, like "if.else"
8// REQUIRES: asserts
9
Justin Bogneref512b92014-01-06 22:27:43 +000010// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate | FileCheck -check-prefix=PGOGEN %s
11// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate | FileCheck -check-prefix=PGOGEN-EXC %s
12
13// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%S/Inputs/instr-profile.pgodata | FileCheck -check-prefix=PGOUSE %s
14// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%S/Inputs/instr-profile.pgodata | FileCheck -check-prefix=PGOUSE-EXC %s
15
16// PGOGEN: @[[THC:__llvm_pgo_ctr[0-9]*]] = private global [11 x i64] zeroinitializer
17// PGOGEN-EXC: @[[THC:__llvm_pgo_ctr[0-9]*]] = private global [11 x i64] zeroinitializer
18
19// PGOGEN-LABEL: @_Z6throwsv()
20// PGOUSE-LABEL: @_Z6throwsv()
21// PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0
22void throws() {
23 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 1
24 // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]]
25 for (int i = 0; i < 100; ++i) {
26 try {
27 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5
28 // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]]
29 if (i % 3) {
30 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 6
31 // PGOUSE: br {{.*}} !prof ![[TH3:[0-9]+]]
32 if (i < 50)
33 throw 1;
34 } else {
35 // The catch block may be emitted after the throw above, we can skip it
36 // by looking for an else block, but this will break if anyone puts an
37 // else in the catch
38 // PGOUSE: if.else{{.*}}:
39 // PGOGEN: if.else{{.*}}:
40
41 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 7
42 // PGOUSE: br {{.*}} !prof ![[TH4:[0-9]+]]
43 if (i >= 50)
44 throw 0;
45 }
46 } catch (int e) {
47 // PGOUSE-EXC: catch{{.*}}:
48 // PGOGEN-EXC: catch{{.*}}:
49
50 // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 8
51 // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 9
52 // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]]
53 if (e) {}
54 }
55 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4
56
57 // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 10
58 // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]]
59 if (i < 100) {}
60 }
61
62 // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
63 // PGOUSE: ret void
64}
65
66// PGOUSE-DAG: ![[TH1]] = metadata !{metadata !"branch_weights", i32 101, i32 2}
67// PGOUSE-DAG: ![[TH2]] = metadata !{metadata !"branch_weights", i32 67, i32 35}
68// PGOUSE-DAG: ![[TH3]] = metadata !{metadata !"branch_weights", i32 34, i32 34}
69// PGOUSE-DAG: ![[TH4]] = metadata !{metadata !"branch_weights", i32 18, i32 18}
70// PGOUSE-EXC: ![[TH5]] = metadata !{metadata !"branch_weights", i32 34, i32 18}
71// PGOUSE-DAG: ![[TH6]] = metadata !{metadata !"branch_weights", i32 101, i32 1}
72
73int main(int argc, const char *argv[]) {
74 throws();
75 return 0;
76}