1 // 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 
9 // RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%S/Inputs/cxx-class.profdata -fno-exceptions -target %itanium_abi_triple > %tuse
10 // RUN: FileCheck --input-file=%tuse -check-prefix=CTRUSE %s
11 // RUN: FileCheck --input-file=%tuse -check-prefix=DTRUSE %s
12 // RUN: FileCheck --input-file=%tuse -check-prefix=MTHUSE %s
13 // RUN: FileCheck --input-file=%tuse -check-prefix=WRPUSE %s
14 
15 class Simple {
16   int Member;
17 public:
18   // CTRGEN-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
19   // CTRUSE-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
20   // CTRGEN: store {{.*}} @[[SCC:__llvm_profile_counters__ZN6SimpleC2Ei]], i64 0, i64 0
21   explicit Simple(int Member) : Member(Member) {
22     // CTRGEN: store {{.*}} @[[SCC]], i64 0, i64 1
23     // CTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]]
24     if (Member) {}
25     // CTRGEN-NOT: store {{.*}} @[[SCC]],
26     // CTRUSE-NOT: br {{.*}} !prof ![0-9]+
27     // CTRUSE: ret
28   }
29   // CTRUSE: ![[SC1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
30 
31   // DTRGEN-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
32   // DTRUSE-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
33   // DTRGEN: store {{.*}} @[[SDC:__llvm_profile_counters__ZN6SimpleD2Ev]], i64 0, i64 0
34   ~Simple() {
35     // DTRGEN: store {{.*}} @[[SDC]], i64 0, i64 1
36     // DTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]]
37     if (Member) {}
38     // DTRGEN-NOT: store {{.*}} @[[SDC]],
39     // DTRUSE-NOT: br {{.*}} !prof ![0-9]+
40     // DTRUSE: ret
41   }
42   // DTRUSE: ![[SD1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
43 
44   // MTHGEN-LABEL: define {{.*}} @_ZN6Simple6methodEv(
45   // MTHUSE-LABEL: define {{.*}} @_ZN6Simple6methodEv(
46   // MTHGEN: store {{.*}} @[[SMC:__llvm_profile_counters__ZN6Simple6methodEv]], i64 0, i64 0
47   void method() {
48     // MTHGEN: store {{.*}} @[[SMC]], i64 0, i64 1
49     // MTHUSE: br {{.*}} !prof ![[SM1:[0-9]+]]
50     if (Member) {}
51     // MTHGEN-NOT: store {{.*}} @[[SMC]],
52     // MTHUSE-NOT: br {{.*}} !prof ![0-9]+
53     // MTHUSE: ret
54   }
55   // MTHUSE: ![[SM1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
56 };
57 
58 // WRPGEN-LABEL: define {{.*}} @_Z14simple_wrapperv(
59 // WRPUSE-LABEL: define {{.*}} @_Z14simple_wrapperv(
60 // WRPGEN: store {{.*}} @[[SWC:__llvm_profile_counters__Z14simple_wrapperv]], i64 0, i64 0
61 void simple_wrapper() {
62   // WRPGEN: store {{.*}} @[[SWC]], i64 0, i64 1
63   // WRPUSE: br {{.*}} !prof ![[SW1:[0-9]+]]
64   for (int I = 0; I < 100; ++I) {
65     Simple S(I);
66     S.method();
67   }
68   // WRPGEN-NOT: store {{.*}} @[[SWC]],
69   // WRPUSE-NOT: br {{.*}} !prof ![0-9]+
70   // WRPUSE: ret
71 }
72 // WRPUSE: ![[SW1]] = metadata !{metadata !"branch_weights", i32 101, i32 2}
73 
74 int main(int argc, const char *argv[]) {
75   simple_wrapper();
76   return 0;
77 }
78