113 lines · cpp
1// Tests for instrumentation of C++ methods, constructors, and destructors.2 3// RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument=clang -triple %itanium_abi_triple > %tgen4// RUN: FileCheck --input-file=%tgen -check-prefix=CTRGEN %s5// RUN: FileCheck --input-file=%tgen -check-prefix=DTRGEN %s6// RUN: FileCheck --input-file=%tgen -check-prefix=MTHGEN %s7// RUN: FileCheck --input-file=%tgen -check-prefix=WRPGEN %s8// RUN: FileCheck --input-file=%tgen -check-prefix=VCTRGEN %s9// RUN: FileCheck --input-file=%tgen -check-prefix=VDTRGEN %s10 11// RUN: llvm-profdata merge %S/Inputs/cxx-class.proftext -o %t.profdata12// RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument-use=clang -fprofile-instrument-use-path=%t.profdata -triple %itanium_abi_triple > %tuse13// RUN: FileCheck --input-file=%tuse -check-prefix=CTRUSE %s14// RUN: FileCheck --input-file=%tuse -check-prefix=DTRUSE %s15// RUN: FileCheck --input-file=%tuse -check-prefix=MTHUSE %s16// RUN: FileCheck --input-file=%tuse -check-prefix=WRPUSE %s17// RUN: FileCheck --input-file=%tuse -check-prefix=VCTRUSE %s18// RUN: FileCheck --input-file=%tuse -check-prefix=VDTRUSE %s19 20class Simple {21public:22 int Member;23 // CTRGEN-LABEL: define {{.*}} @_ZN6SimpleC2Ei(24 // CTRUSE-LABEL: define {{.*}} @_ZN6SimpleC2Ei(25 // CTRGEN: store {{.*}} @[[SCC:__profc__ZN6SimpleC2Ei]]26 explicit Simple(int Member) : Member(Member) {27 // CTRGEN: store {{.*}} @[[SCC]], i32 0, i32 128 // CTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]]29 if (Member) {}30 // CTRGEN-NOT: store {{.*}} @[[SCC]],31 // CTRUSE-NOT: br {{.*}} !prof ![0-9]+32 // CTRUSE: ret33 }34 // CTRUSE: ![[SC1]] = !{!"branch_weights", i32 100, i32 2}35 36 // DTRGEN-LABEL: define {{.*}} @_ZN6SimpleD2Ev(37 // DTRUSE-LABEL: define {{.*}} @_ZN6SimpleD2Ev(38 // DTRGEN: store {{.*}} @[[SDC:__profc__ZN6SimpleD2Ev]]39 ~Simple() {40 // DTRGEN: store {{.*}} @[[SDC]], i32 0, i32 141 // DTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]]42 if (Member) {}43 // DTRGEN-NOT: store {{.*}} @[[SDC]],44 // DTRUSE-NOT: br {{.*}} !prof ![0-9]+45 // DTRUSE: ret46 }47 // DTRUSE: ![[SD1]] = !{!"branch_weights", i32 100, i32 2}48 49 // MTHGEN-LABEL: define {{.*}} @_ZN6Simple6methodEv(50 // MTHUSE-LABEL: define {{.*}} @_ZN6Simple6methodEv(51 // MTHGEN: store {{.*}} @[[SMC:__profc__ZN6Simple6methodEv]]52 void method() {53 // MTHGEN: store {{.*}} @[[SMC]], i32 0, i32 154 // MTHUSE: br {{.*}} !prof ![[SM1:[0-9]+]]55 if (Member) {}56 // MTHGEN-NOT: store {{.*}} @[[SMC]],57 // MTHUSE-NOT: br {{.*}} !prof ![0-9]+58 // MTHUSE: ret59 }60 // MTHUSE: ![[SM1]] = !{!"branch_weights", i32 100, i32 2}61};62 63class Derived : virtual public Simple {64public:65 // VCTRGEN-LABEL: define {{.*}} @_ZN7DerivedC1Ev(66 // VCTRUSE-LABEL: define {{.*}} @_ZN7DerivedC1Ev(67 // VCTRGEN: store {{.*}} @[[SCC:__profc__ZN7DerivedC1Ev]]68 Derived() : Simple(0) {69 // VCTRGEN: store {{.*}} @[[SCC]], i32 0, i32 170 // VCTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]]71 if (Member) {}72 // VCTRGEN-NOT: store {{.*}} @[[SCC]],73 // VCTRUSE-NOT: br {{.*}} !prof ![0-9]+74 // VCTRUSE: ret75 }76 // VCTRUSE: ![[SC1]] = !{!"branch_weights", i32 100, i32 2}77 78 // VDTRGEN-LABEL: define {{.*}} @_ZN7DerivedD2Ev(79 // VDTRUSE-LABEL: define {{.*}} @_ZN7DerivedD2Ev(80 // VDTRGEN: store {{.*}} @[[SDC:__profc__ZN7DerivedD2Ev]]81 ~Derived() {82 // VDTRGEN: store {{.*}} @[[SDC]], i32 0, i32 183 // VDTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]]84 if (Member) {}85 // VDTRGEN-NOT: store {{.*}} @[[SDC]],86 // VDTRUSE-NOT: br {{.*}} !prof ![0-9]+87 // VDTRUSE: ret88 }89 // VDTRUSE: ![[SD1]] = !{!"branch_weights", i32 100, i32 2}90};91 92// WRPGEN-LABEL: define {{.*}} @_Z14simple_wrapperv(93// WRPUSE-LABEL: define {{.*}} @_Z14simple_wrapperv(94// WRPGEN: store {{.*}} @[[SWC:__profc__Z14simple_wrapperv]]95void simple_wrapper() {96 // WRPGEN: store {{.*}} @[[SWC]], i32 0, i32 197 // WRPUSE: br {{.*}} !prof ![[SW1:[0-9]+]]98 for (int I = 0; I < 100; ++I) {99 Derived d;100 Simple S(I);101 S.method();102 }103 // WRPGEN-NOT: store {{.*}} @[[SWC]],104 // WRPUSE-NOT: br {{.*}} !prof ![0-9]+105 // WRPUSE: ret106}107// WRPUSE: ![[SW1]] = !{!"branch_weights", i32 101, i32 2}108 109int main(int argc, const char *argv[]) {110 simple_wrapper();111 return 0;112}113