]> granicus.if.org Git - clang/commitdiff
Attach maximum function count to Module when using PGO mode.
authorEaswaran Raman <eraman@google.com>
Thu, 17 Dec 2015 19:14:27 +0000 (19:14 +0000)
committerEaswaran Raman <eraman@google.com>
Thu, 17 Dec 2015 19:14:27 +0000 (19:14 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255918 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/Profile/Inputs/max-function-count.proftext [new file with mode: 0644]
test/Profile/max-function-count.c [new file with mode: 0644]

index 3b3fc877bf47dfefab428ba01923de0bb509ff13..173b0dcba1c2524811ffb77277b247a54ea5e30f 100644 (file)
@@ -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();
diff --git a/test/Profile/Inputs/max-function-count.proftext b/test/Profile/Inputs/max-function-count.proftext
new file mode 100644 (file)
index 0000000..c744f7a
--- /dev/null
@@ -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
+
diff --git a/test/Profile/max-function-count.c b/test/Profile/max-function-count.c
new file mode 100644 (file)
index 0000000..39490d7
--- /dev/null
@@ -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}