cxx-class.cpp revision 6bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89
1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Tests for instrumentation of C++ methods, constructors, and destructors.
2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-generate -fno-exceptions -target %itanium_abi_triple > %tgen
4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: FileCheck --input-file=%tgen -check-prefix=CTRGEN %s
5d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: FileCheck --input-file=%tgen -check-prefix=DTRGEN %s
6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: FileCheck --input-file=%tgen -check-prefix=MTHGEN %s
7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: FileCheck --input-file=%tgen -check-prefix=WRPGEN %s
8d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
9d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: llvm-profdata merge %S/Inputs/cxx-class.proftext -o %t.profdata
10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -fno-exceptions -target %itanium_abi_triple > %tuse
11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: FileCheck --input-file=%tuse -check-prefix=CTRUSE %s
12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: FileCheck --input-file=%tuse -check-prefix=DTRUSE %s
13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: FileCheck --input-file=%tuse -check-prefix=MTHUSE %s
14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// RUN: FileCheck --input-file=%tuse -check-prefix=WRPUSE %s
15d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class Simple {
17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  int Member;
18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)public:
19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // CTRGEN-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // CTRUSE-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // CTRGEN: store {{.*}} @[[SCC:__llvm_profile_counters__ZN6SimpleC2Ei]], i64 0, i64 0
22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  explicit Simple(int Member) : Member(Member) {
23d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // CTRGEN: store {{.*}} @[[SCC]], i64 0, i64 1
24d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)    // 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  }
30  // CTRUSE: ![[SC1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
31
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  }
43  // DTRUSE: ![[SD1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
44
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  }
56  // MTHUSE: ![[SM1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
57};
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}
73// WRPUSE: ![[SW1]] = metadata !{metadata !"branch_weights", i32 101, i32 2}
74
75int main(int argc, const char *argv[]) {
76  simple_wrapper();
77  return 0;
78}
79