cxx-class.cpp 3.0 KB

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