blob: 21cbbd68320a408f406bb74feb9885c10a0c1027 [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// Tests for instrumentation of C++ methods, constructors, and destructors.
2
3// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-generate -fno-exceptions -target %itanium_abi_triple > %tgen
4// RUN: FileCheck --input-file=%tgen -check-prefix=CTRGEN %s
5// RUN: FileCheck --input-file=%tgen -check-prefix=DTRGEN %s
6// RUN: FileCheck --input-file=%tgen -check-prefix=MTHGEN %s
7// RUN: FileCheck --input-file=%tgen -check-prefix=WRPGEN %s
8
Stephen Hines6bcf27b2014-05-29 04:14:42 -07009// RUN: llvm-profdata merge %S/Inputs/cxx-class.proftext -o %t.profdata
10// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -fno-exceptions -target %itanium_abi_triple > %tuse
Stephen Hines651f13c2014-04-23 16:59:28 -070011// RUN: FileCheck --input-file=%tuse -check-prefix=CTRUSE %s
12// RUN: FileCheck --input-file=%tuse -check-prefix=DTRUSE %s
13// RUN: FileCheck --input-file=%tuse -check-prefix=MTHUSE %s
14// RUN: FileCheck --input-file=%tuse -check-prefix=WRPUSE %s
15
16class Simple {
17 int Member;
18public:
19 // CTRGEN-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
20 // CTRUSE-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
21 // CTRGEN: store {{.*}} @[[SCC:__llvm_profile_counters__ZN6SimpleC2Ei]], i64 0, i64 0
22 explicit Simple(int Member) : Member(Member) {
23 // CTRGEN: store {{.*}} @[[SCC]], i64 0, i64 1
24 // CTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]]
25 if (Member) {}
26 // CTRGEN-NOT: store {{.*}} @[[SCC]],
27 // CTRUSE-NOT: br {{.*}} !prof ![0-9]+
28 // CTRUSE: ret
29 }
Stephen Hines0e2c34f2015-03-23 12:09:02 -070030 // CTRUSE: ![[SC1]] = !{!"branch_weights", i32 100, i32 2}
Stephen Hines651f13c2014-04-23 16:59:28 -070031
32 // DTRGEN-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
33 // DTRUSE-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
34 // DTRGEN: store {{.*}} @[[SDC:__llvm_profile_counters__ZN6SimpleD2Ev]], i64 0, i64 0
35 ~Simple() {
36 // DTRGEN: store {{.*}} @[[SDC]], i64 0, i64 1
37 // DTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]]
38 if (Member) {}
39 // DTRGEN-NOT: store {{.*}} @[[SDC]],
40 // DTRUSE-NOT: br {{.*}} !prof ![0-9]+
41 // DTRUSE: ret
42 }
Stephen Hines0e2c34f2015-03-23 12:09:02 -070043 // DTRUSE: ![[SD1]] = !{!"branch_weights", i32 100, i32 2}
Stephen Hines651f13c2014-04-23 16:59:28 -070044
45 // MTHGEN-LABEL: define {{.*}} @_ZN6Simple6methodEv(
46 // MTHUSE-LABEL: define {{.*}} @_ZN6Simple6methodEv(
47 // MTHGEN: store {{.*}} @[[SMC:__llvm_profile_counters__ZN6Simple6methodEv]], i64 0, i64 0
48 void method() {
49 // MTHGEN: store {{.*}} @[[SMC]], i64 0, i64 1
50 // MTHUSE: br {{.*}} !prof ![[SM1:[0-9]+]]
51 if (Member) {}
52 // MTHGEN-NOT: store {{.*}} @[[SMC]],
53 // MTHUSE-NOT: br {{.*}} !prof ![0-9]+
54 // MTHUSE: ret
55 }
Stephen Hines0e2c34f2015-03-23 12:09:02 -070056 // MTHUSE: ![[SM1]] = !{!"branch_weights", i32 100, i32 2}
Stephen Hines651f13c2014-04-23 16:59:28 -070057};
58
59// WRPGEN-LABEL: define {{.*}} @_Z14simple_wrapperv(
60// WRPUSE-LABEL: define {{.*}} @_Z14simple_wrapperv(
61// WRPGEN: store {{.*}} @[[SWC:__llvm_profile_counters__Z14simple_wrapperv]], i64 0, i64 0
62void simple_wrapper() {
63 // WRPGEN: store {{.*}} @[[SWC]], i64 0, i64 1
64 // WRPUSE: br {{.*}} !prof ![[SW1:[0-9]+]]
65 for (int I = 0; I < 100; ++I) {
66 Simple S(I);
67 S.method();
68 }
69 // WRPGEN-NOT: store {{.*}} @[[SWC]],
70 // WRPUSE-NOT: br {{.*}} !prof ![0-9]+
71 // WRPUSE: ret
72}
Stephen Hines0e2c34f2015-03-23 12:09:02 -070073// WRPUSE: ![[SW1]] = !{!"branch_weights", i32 101, i32 2}
Stephen Hines651f13c2014-04-23 16:59:28 -070074
75int main(int argc, const char *argv[]) {
76 simple_wrapper();
77 return 0;
78}