blob: ab90d195cdc6ce3d4d76cc174c093c91c85306a8 [file] [log] [blame]
Justin Bogner52a6a972014-03-11 04:37:49 +00001// Tests for instrumentation of C++ methods, constructors, and destructors.
Justin Bogner81c22c22014-01-23 02:54:27 +00002
Sean Silva1e51ac22016-04-23 02:11:16 +00003// RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument=clang -triple %itanium_abi_triple > %tgen
Justin Bogner81c22c22014-01-23 02:54:27 +00004// 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
Vedant Kumar7f809b22017-02-24 01:15:19 +00008// RUN: FileCheck --input-file=%tgen -check-prefix=VCTRGEN %s
9// RUN: FileCheck --input-file=%tgen -check-prefix=VDTRGEN %s
Justin Bogner81c22c22014-01-23 02:54:27 +000010
Justin Bogner534f14a2014-04-17 22:49:06 +000011// RUN: llvm-profdata merge %S/Inputs/cxx-class.proftext -o %t.profdata
Sean Silva1e51ac22016-04-23 02:11:16 +000012// RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -triple %itanium_abi_triple > %tuse
Justin Bogner81c22c22014-01-23 02:54:27 +000013// RUN: FileCheck --input-file=%tuse -check-prefix=CTRUSE %s
14// RUN: FileCheck --input-file=%tuse -check-prefix=DTRUSE %s
15// RUN: FileCheck --input-file=%tuse -check-prefix=MTHUSE %s
16// RUN: FileCheck --input-file=%tuse -check-prefix=WRPUSE %s
Vedant Kumar7f809b22017-02-24 01:15:19 +000017// RUN: FileCheck --input-file=%tuse -check-prefix=VCTRUSE %s
18// RUN: FileCheck --input-file=%tuse -check-prefix=VDTRUSE %s
Justin Bogner81c22c22014-01-23 02:54:27 +000019
20class Simple {
Justin Bogner81c22c22014-01-23 02:54:27 +000021public:
Vedant Kumar7f809b22017-02-24 01:15:19 +000022 int Member;
Justin Bogner81c22c22014-01-23 02:54:27 +000023 // CTRGEN-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
24 // CTRUSE-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
Xinliang David Liddbdb1e2015-12-15 00:33:12 +000025 // CTRGEN: store {{.*}} @[[SCC:__profc__ZN6SimpleC2Ei]], i64 0, i64 0
Justin Bogner81c22c22014-01-23 02:54:27 +000026 explicit Simple(int Member) : Member(Member) {
27 // CTRGEN: store {{.*}} @[[SCC]], i64 0, i64 1
28 // CTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]]
29 if (Member) {}
30 // CTRGEN-NOT: store {{.*}} @[[SCC]],
31 // CTRUSE-NOT: br {{.*}} !prof ![0-9]+
Justin Bogner49e453f2014-01-23 04:41:06 +000032 // CTRUSE: ret
Justin Bogner81c22c22014-01-23 02:54:27 +000033 }
Nico Weber2a4e7042020-10-27 09:18:42 -040034 // CTRUSE: ![[SC1]] = !{!"branch_weights", i32 100, i32 2}
Justin Bogner81c22c22014-01-23 02:54:27 +000035
36 // DTRGEN-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
37 // DTRUSE-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
Xinliang David Liddbdb1e2015-12-15 00:33:12 +000038 // DTRGEN: store {{.*}} @[[SDC:__profc__ZN6SimpleD2Ev]], i64 0, i64 0
Justin Bogner81c22c22014-01-23 02:54:27 +000039 ~Simple() {
40 // DTRGEN: store {{.*}} @[[SDC]], i64 0, i64 1
41 // DTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]]
42 if (Member) {}
43 // DTRGEN-NOT: store {{.*}} @[[SDC]],
44 // DTRUSE-NOT: br {{.*}} !prof ![0-9]+
Justin Bogner49e453f2014-01-23 04:41:06 +000045 // DTRUSE: ret
Justin Bogner81c22c22014-01-23 02:54:27 +000046 }
Nico Weber2a4e7042020-10-27 09:18:42 -040047 // DTRUSE: ![[SD1]] = !{!"branch_weights", i32 100, i32 2}
Justin Bogner81c22c22014-01-23 02:54:27 +000048
49 // MTHGEN-LABEL: define {{.*}} @_ZN6Simple6methodEv(
50 // MTHUSE-LABEL: define {{.*}} @_ZN6Simple6methodEv(
Xinliang David Liddbdb1e2015-12-15 00:33:12 +000051 // MTHGEN: store {{.*}} @[[SMC:__profc__ZN6Simple6methodEv]], i64 0, i64 0
Justin Bogner81c22c22014-01-23 02:54:27 +000052 void method() {
53 // MTHGEN: store {{.*}} @[[SMC]], i64 0, i64 1
54 // MTHUSE: br {{.*}} !prof ![[SM1:[0-9]+]]
55 if (Member) {}
56 // MTHGEN-NOT: store {{.*}} @[[SMC]],
57 // MTHUSE-NOT: br {{.*}} !prof ![0-9]+
Justin Bogner49e453f2014-01-23 04:41:06 +000058 // MTHUSE: ret
Justin Bogner81c22c22014-01-23 02:54:27 +000059 }
Nico Weber2a4e7042020-10-27 09:18:42 -040060 // MTHUSE: ![[SM1]] = !{!"branch_weights", i32 100, i32 2}
Justin Bogner81c22c22014-01-23 02:54:27 +000061};
62
Vedant Kumar7f809b22017-02-24 01:15:19 +000063class Derived : virtual public Simple {
64public:
65 // VCTRGEN-LABEL: define {{.*}} @_ZN7DerivedC1Ev(
66 // VCTRUSE-LABEL: define {{.*}} @_ZN7DerivedC1Ev(
67 // VCTRGEN: store {{.*}} @[[SCC:__profc__ZN7DerivedC1Ev]], i64 0, i64 0
68 Derived() : Simple(0) {
69 // VCTRGEN: store {{.*}} @[[SCC]], i64 0, i64 1
70 // VCTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]]
71 if (Member) {}
72 // VCTRGEN-NOT: store {{.*}} @[[SCC]],
73 // VCTRUSE-NOT: br {{.*}} !prof ![0-9]+
74 // VCTRUSE: ret
75 }
Nico Weber2a4e7042020-10-27 09:18:42 -040076 // VCTRUSE: ![[SC1]] = !{!"branch_weights", i32 100, i32 2}
Vedant Kumar7f809b22017-02-24 01:15:19 +000077
78 // VDTRGEN-LABEL: define {{.*}} @_ZN7DerivedD2Ev(
79 // VDTRUSE-LABEL: define {{.*}} @_ZN7DerivedD2Ev(
80 // VDTRGEN: store {{.*}} @[[SDC:__profc__ZN7DerivedD2Ev]], i64 0, i64 0
81 ~Derived() {
82 // VDTRGEN: store {{.*}} @[[SDC]], i64 0, i64 1
83 // VDTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]]
84 if (Member) {}
85 // VDTRGEN-NOT: store {{.*}} @[[SDC]],
86 // VDTRUSE-NOT: br {{.*}} !prof ![0-9]+
87 // VDTRUSE: ret
88 }
Nico Weber2a4e7042020-10-27 09:18:42 -040089 // VDTRUSE: ![[SD1]] = !{!"branch_weights", i32 100, i32 2}
Vedant Kumar7f809b22017-02-24 01:15:19 +000090};
91
Justin Bogner81c22c22014-01-23 02:54:27 +000092// WRPGEN-LABEL: define {{.*}} @_Z14simple_wrapperv(
93// WRPUSE-LABEL: define {{.*}} @_Z14simple_wrapperv(
Xinliang David Liddbdb1e2015-12-15 00:33:12 +000094// WRPGEN: store {{.*}} @[[SWC:__profc__Z14simple_wrapperv]], i64 0, i64 0
Justin Bogner81c22c22014-01-23 02:54:27 +000095void simple_wrapper() {
96 // WRPGEN: store {{.*}} @[[SWC]], i64 0, i64 1
97 // WRPUSE: br {{.*}} !prof ![[SW1:[0-9]+]]
98 for (int I = 0; I < 100; ++I) {
Vedant Kumar7f809b22017-02-24 01:15:19 +000099 Derived d;
Justin Bogner81c22c22014-01-23 02:54:27 +0000100 Simple S(I);
101 S.method();
102 }
103 // WRPGEN-NOT: store {{.*}} @[[SWC]],
104 // WRPUSE-NOT: br {{.*}} !prof ![0-9]+
Justin Bogner49e453f2014-01-23 04:41:06 +0000105 // WRPUSE: ret
Justin Bogner81c22c22014-01-23 02:54:27 +0000106}
Nico Weber2a4e7042020-10-27 09:18:42 -0400107// WRPUSE: ![[SW1]] = !{!"branch_weights", i32 101, i32 2}
Justin Bogner81c22c22014-01-23 02:54:27 +0000108
109int main(int argc, const char *argv[]) {
110 simple_wrapper();
111 return 0;
112}