r238360 - Set function entry counts with -fprofile-instr-use.

Diego Novillo dnovillo at google.com
Wed May 27 14:58:42 PDT 2015


Author: dnovillo
Date: Wed May 27 16:58:42 2015
New Revision: 238360

URL: http://llvm.org/viewvc/llvm-project?rev=238360&view=rev
Log:
Set function entry counts with -fprofile-instr-use.

This generates function entry counts from instrumentation profiles.

Added:
    cfe/trunk/test/Profile/Inputs/func-entry.proftext
    cfe/trunk/test/Profile/func-entry.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenPGO.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=238360&r1=238359&r2=238360&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Wed May 27 16:58:42 2015
@@ -773,6 +773,8 @@ CodeGenPGO::applyFunctionAttributes(llvm
     // 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) {

Added: cfe/trunk/test/Profile/Inputs/func-entry.proftext
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/Inputs/func-entry.proftext?rev=238360&view=auto
==============================================================================
--- cfe/trunk/test/Profile/Inputs/func-entry.proftext (added)
+++ cfe/trunk/test/Profile/Inputs/func-entry.proftext Wed May 27 16:58:42 2015
@@ -0,0 +1,10 @@
+foo
+0
+1
+1000
+
+main
+4
+2
+1
+10000

Added: cfe/trunk/test/Profile/func-entry.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/func-entry.c?rev=238360&view=auto
==============================================================================
--- cfe/trunk/test/Profile/func-entry.c (added)
+++ cfe/trunk/test/Profile/func-entry.c Wed May 27 16:58:42 2015
@@ -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}





More information about the cfe-commits mailing list