r199864 - CodeGen: Handle PGO counters for constructors and destructors

Justin Bogner mail at justinbogner.com
Wed Jan 22 18:54:27 PST 2014


Author: bogner
Date: Wed Jan 22 20:54:27 2014
New Revision: 199864

URL: http://llvm.org/viewvc/llvm-project?rev=199864&view=rev
Log:
CodeGen: Handle PGO counters for constructors and destructors

Added:
    cfe/trunk/test/CodeGenCXX/Inputs/instr-profile-class.pgodata
    cfe/trunk/test/CodeGenCXX/instr-profile-class.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=199864&r1=199863&r2=199864&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Wed Jan 22 20:54:27 2014
@@ -721,6 +721,9 @@ void CodeGenFunction::EmitConstructorBod
   if (IsTryBody)
     EnterCXXTryStmt(*cast<CXXTryStmt>(Body), true);
 
+  RegionCounter Cnt = getPGORegionCounter(Body);
+  Cnt.beginRegion(Builder);
+
   RunCleanupsScope RunCleanups(*this);
 
   // TODO: in restricted cases, we can emit the vbase initializers of
@@ -1319,6 +1322,9 @@ void CodeGenFunction::EmitDestructorBody
   case Dtor_Base:
     assert(Body);
 
+    RegionCounter Cnt = getPGORegionCounter(Body);
+    Cnt.beginRegion(Builder);
+
     // Enter the cleanup scopes for fields and non-virtual bases.
     EnterDtorCleanups(Dtor, Dtor_Base);
 

Added: cfe/trunk/test/CodeGenCXX/Inputs/instr-profile-class.pgodata
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/Inputs/instr-profile-class.pgodata?rev=199864&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/Inputs/instr-profile-class.pgodata (added)
+++ cfe/trunk/test/CodeGenCXX/Inputs/instr-profile-class.pgodata Wed Jan 22 20:54:27 2014
@@ -0,0 +1,20 @@
+_ZN6SimpleC2Ei 2
+100
+99
+
+_ZN6Simple6methodEv 2
+100
+99
+
+_ZN6SimpleD2Ev 2
+100
+99
+
+_ZN14simple_wrapperEv 4
+1
+100
+0
+0
+
+main 1
+1

Added: cfe/trunk/test/CodeGenCXX/instr-profile-class.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/instr-profile-class.cpp?rev=199864&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/instr-profile-class.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/instr-profile-class.cpp Wed Jan 22 20:54:27 2014
@@ -0,0 +1,82 @@
+// Test that instrumentation based profiling feeds branch prediction
+// correctly. This tests both generation of profile data and use of the same,
+// and the input file for the -fprofile-instr-use case is expected to be result
+// of running the program generated by the -fprofile-instr-generate case
+// (excepting no_usable_data). As such, main() should call every function in
+// this test.
+
+// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-generate -fno-exceptions -target %itanium_abi_triple > %tgen
+// RUN: FileCheck --input-file=%tgen -check-prefix=CTRGEN %s
+// RUN: FileCheck --input-file=%tgen -check-prefix=DTRGEN %s
+// RUN: FileCheck --input-file=%tgen -check-prefix=MTHGEN %s
+// RUN: FileCheck --input-file=%tgen -check-prefix=WRPGEN %s
+
+// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%S/Inputs/instr-profile-class.pgodata -fno-exceptions -target %itanium_abi_triple > %tuse
+// RUN: FileCheck --input-file=%tuse -check-prefix=CTRUSE %s
+// RUN: FileCheck --input-file=%tuse -check-prefix=DTRUSE %s
+// RUN: FileCheck --input-file=%tuse -check-prefix=MTHUSE %s
+// RUN: FileCheck --input-file=%tuse -check-prefix=WRPUSE %s
+
+class Simple {
+  int Member;
+public:
+  // CTRGEN-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
+  // CTRUSE-LABEL: define {{.*}} @_ZN6SimpleC2Ei(
+  // CTRGEN: store {{.*}} @[[SCC:__llvm_pgo_ctr[0-9]*]], i64 0, i64 0
+  explicit Simple(int Member) : Member(Member) {
+    // CTRGEN: store {{.*}} @[[SCC]], i64 0, i64 1
+    // CTRUSE: br {{.*}} !prof ![[SC1:[0-9]+]]
+    if (Member) {}
+    // CTRGEN-NOT: store {{.*}} @[[SCC]],
+    // CTRUSE-NOT: br {{.*}} !prof ![0-9]+
+    // CTRUSE: ret void
+  }
+  // CTRUSE: ![[SC1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
+
+  // DTRGEN-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
+  // DTRUSE-LABEL: define {{.*}} @_ZN6SimpleD2Ev(
+  // DTRGEN: store {{.*}} @[[SDC:__llvm_pgo_ctr[0-9]*]], i64 0, i64 0
+  ~Simple() {
+    // DTRGEN: store {{.*}} @[[SDC]], i64 0, i64 1
+    // DTRUSE: br {{.*}} !prof ![[SD1:[0-9]+]]
+    if (Member) {}
+    // DTRGEN-NOT: store {{.*}} @[[SDC]],
+    // DTRUSE-NOT: br {{.*}} !prof ![0-9]+
+    // DTRUSE: ret void
+  }
+  // DTRUSE: ![[SD1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
+
+  // MTHGEN-LABEL: define {{.*}} @_ZN6Simple6methodEv(
+  // MTHUSE-LABEL: define {{.*}} @_ZN6Simple6methodEv(
+  // MTHGEN: store {{.*}} @[[SMC:__llvm_pgo_ctr[0-9]*]], i64 0, i64 0
+  void method() {
+    // MTHGEN: store {{.*}} @[[SMC]], i64 0, i64 1
+    // MTHUSE: br {{.*}} !prof ![[SM1:[0-9]+]]
+    if (Member) {}
+    // MTHGEN-NOT: store {{.*}} @[[SMC]],
+    // MTHUSE-NOT: br {{.*}} !prof ![0-9]+
+    // MTHUSE: ret void
+  }
+  // MTHUSE: ![[SM1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
+};
+
+// WRPGEN-LABEL: define {{.*}} @_Z14simple_wrapperv(
+// WRPUSE-LABEL: define {{.*}} @_Z14simple_wrapperv(
+// WRPGEN: store {{.*}} @[[SWC:__llvm_pgo_ctr[0-9]*]], i64 0, i64 0
+void simple_wrapper() {
+  // WRPGEN: store {{.*}} @[[SWC]], i64 0, i64 1
+  // WRPUSE: br {{.*}} !prof ![[SW1:[0-9]+]]
+  for (int I = 0; I < 100; ++I) {
+    Simple S(I);
+    S.method();
+  }
+  // WRPGEN-NOT: store {{.*}} @[[SWC]],
+  // WRPUSE-NOT: br {{.*}} !prof ![0-9]+
+  // WRPUSE: ret void
+}
+// WRPUSE: ![[SW1]] = metadata !{metadata !"branch_weights", i32 100, i32 2}
+
+int main(int argc, const char *argv[]) {
+  simple_wrapper();
+  return 0;
+}





More information about the cfe-commits mailing list