]> granicus.if.org Git - clang/commitdiff
Set function entry counts with -fprofile-instr-use.
authorDiego Novillo <dnovillo@google.com>
Wed, 27 May 2015 21:58:42 +0000 (21:58 +0000)
committerDiego Novillo <dnovillo@google.com>
Wed, 27 May 2015 21:58:42 +0000 (21:58 +0000)
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

lib/CodeGen/CodeGenPGO.cpp
test/Profile/Inputs/func-entry.proftext [new file with mode: 0644]
test/Profile/func-entry.c [new file with mode: 0644]

index c97244328d379cd15d6237540f1f6d37b0261de3..f182a469b3a41a57d11f2d8eca93c0551c82252f 100644 (file)
@@ -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 (file)
index 0000000..f7c2052
--- /dev/null
@@ -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 (file)
index 0000000..4f91cbe
--- /dev/null
@@ -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}