r255918 - Attach maximum function count to Module when using PGO mode.

Easwaran Raman via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 17 11:14:27 PST 2015


Author: eraman
Date: Thu Dec 17 13:14:27 2015
New Revision: 255918

URL: http://llvm.org/viewvc/llvm-project?rev=255918&view=rev
Log:
Attach maximum function count to Module when using PGO mode.

This sets the maximum entry count among all functions in the program to the module using module flags. This allows the optimizer to use this information.

Differential Revision: http://reviews.llvm.org/D15163

Added:
    cfe/trunk/test/Profile/Inputs/max-function-count.proftext
    cfe/trunk/test/Profile/max-function-count.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=255918&r1=255917&r2=255918&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Dec 17 13:14:27 2015
@@ -375,8 +375,11 @@ void CodeGenModule::Release() {
     if (llvm::Function *CudaDtorFunction = CUDARuntime->makeModuleDtorFunction())
       AddGlobalDtor(CudaDtorFunction);
   }
-  if (PGOReader && PGOStats.hasDiagnostics())
-    PGOStats.reportDiagnostics(getDiags(), getCodeGenOpts().MainFileName);
+  if (PGOReader) {
+    getModule().setMaximumFunctionCount(PGOReader->getMaximumFunctionCount());
+    if (PGOStats.hasDiagnostics())
+      PGOStats.reportDiagnostics(getDiags(), getCodeGenOpts().MainFileName);
+  }
   EmitCtorList(GlobalCtors, "llvm.global_ctors");
   EmitCtorList(GlobalDtors, "llvm.global_dtors");
   EmitGlobalAnnotations();

Added: cfe/trunk/test/Profile/Inputs/max-function-count.proftext
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/Inputs/max-function-count.proftext?rev=255918&view=auto
==============================================================================
--- cfe/trunk/test/Profile/Inputs/max-function-count.proftext (added)
+++ cfe/trunk/test/Profile/Inputs/max-function-count.proftext Thu Dec 17 13:14:27 2015
@@ -0,0 +1,26 @@
+begin
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+1
+0
+
+main
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+1
+
+end
+# Func Hash:
+10
+# Num Counters:
+2
+# Counter Values:
+2
+2
+

Added: cfe/trunk/test/Profile/max-function-count.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/max-function-count.c?rev=255918&view=auto
==============================================================================
--- cfe/trunk/test/Profile/max-function-count.c (added)
+++ cfe/trunk/test/Profile/max-function-count.c Thu Dec 17 13:14:27 2015
@@ -0,0 +1,24 @@
+// Test that maximum function counts are set correctly.
+
+// RUN: llvm-profdata merge %S/Inputs/max-function-count.proftext -o %t.profdata
+// RUN: %clang %s -o - -mllvm -disable-llvm-optzns -emit-llvm -S -fprofile-instr-use=%t.profdata | FileCheck %s
+//
+int begin(int i) {
+  if (i)
+    return 0;
+  return 1;
+}
+
+int end(int i) {
+  if (i)
+    return 0;
+  return 1;
+}
+
+int main(int argc, const char *argv[]) {
+  begin(0);
+  end(1);
+  end(1);
+  return 0;
+}
+// CHECK: !{{[0-9]+}} = !{i32 1, !"MaxFunctionCount", i32 2}




More information about the cfe-commits mailing list