From: Diego Novillo Date: Wed, 27 May 2015 21:58:42 +0000 (+0000) Subject: Set function entry counts with -fprofile-instr-use. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d19add92787c0c2cf53f24ac0d3e33a4a7cb88ee;p=clang Set function entry counts with -fprofile-instr-use. This generates function entry counts from instrumentation profiles. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238360 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index c97244328d..f182a469b3 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -773,6 +773,8 @@ CodeGenPGO::applyFunctionAttributes(llvm::IndexedInstrProfReader *PGOReader, // Turn on Cold attribute for cold functions. // FIXME: 1% is from preliminary tuning on SPEC, it may not be optimal. Fn->addFnAttr(llvm::Attribute::Cold); + + Fn->setEntryCount(FunctionCount); } void CodeGenPGO::emitCounterIncrement(CGBuilderTy &Builder, const Stmt *S) { diff --git a/test/Profile/Inputs/func-entry.proftext b/test/Profile/Inputs/func-entry.proftext new file mode 100644 index 0000000000..f7c2052035 --- /dev/null +++ b/test/Profile/Inputs/func-entry.proftext @@ -0,0 +1,10 @@ +foo +0 +1 +1000 + +main +4 +2 +1 +10000 diff --git a/test/Profile/func-entry.c b/test/Profile/func-entry.c new file mode 100644 index 0000000000..4f91cbe968 --- /dev/null +++ b/test/Profile/func-entry.c @@ -0,0 +1,19 @@ +// Test that function entry counts are set correctly. + +// RUN: llvm-profdata merge %S/Inputs/func-entry.proftext -o %t.profdata +// RUN: %clang %s -o - -mllvm -disable-llvm-optzns -emit-llvm -S -fprofile-instr-use=%t.profdata | FileCheck %s + +void foo(void); + +// CHECK: define void @foo() #0 !prof [[FOO:![0-9]+]] +void foo() { return; } + +// CHECK: define i32 @main() #1 !prof [[MAIN:![0-9]+]] +int main() { + int i; + for (i = 0; i < 10000; i++) foo(); + return 0; +} + +// CHECK: [[FOO]] = !{!"function_entry_count", i64 1000} +// CHECK: [[MAIN]] = !{!"function_entry_count", i64 1}