From: Easwaran Raman Date: Sat, 12 Dec 2015 00:31:02 +0000 (+0000) Subject: Attach maximum function count to Module when using PGO mode X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94f51f428aa7db5ba4543f02698d752ff9b4970a;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255397 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 29c5f3eed5..8d7254904a 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -376,6 +376,9 @@ void CodeGenModule::Release() { } if (PGOReader && PGOStats.hasDiagnostics()) PGOStats.reportDiagnostics(getDiags(), getCodeGenOpts().MainFileName); + // In PGO mode, attach maximum function count to the module. + if (PGOReader) + getModule().setMaximumFunctionCount(PGOReader->getMaximumFunctionCount()); EmitCtorList(GlobalCtors, "llvm.global_ctors"); EmitCtorList(GlobalDtors, "llvm.global_dtors"); EmitGlobalAnnotations(); diff --git a/test/CodeGen/pgo-max-function-count.c b/test/CodeGen/pgo-max-function-count.c new file mode 100644 index 0000000000..b60a4671eb --- /dev/null +++ b/test/CodeGen/pgo-max-function-count.c @@ -0,0 +1,9 @@ +// RUN: %clang -fprofile-generate -o %t -O2 %s +// RUN: env LLVM_PROFILE_FILE=%t.profraw %t +// RUN: llvm-profdata merge -o %t.profdata %t.profraw +// RUN: %clang -fprofile-use=%t.profdata -o - -S -emit-llvm %s | FileCheck %s +// Check +int main() { + return 0; +} +// CHECK: !{{[0-9]+}} = !{i32 1, !"MaxFunctionCount", i32 1}