Set function entry counts with -fprofile-instr-use.
This generates function entry counts from instrumentation profiles.
llvm-svn: 238360
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index c972443..f182a46 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -773,6 +773,8 @@
// 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/clang/test/Profile/Inputs/func-entry.proftext b/clang/test/Profile/Inputs/func-entry.proftext
new file mode 100644
index 0000000..f7c2052
--- /dev/null
+++ b/clang/test/Profile/Inputs/func-entry.proftext
@@ -0,0 +1,10 @@
+foo
+0
+1
+1000
+
+main
+4
+2
+1
+10000
diff --git a/clang/test/Profile/func-entry.c b/clang/test/Profile/func-entry.c
new file mode 100644
index 0000000..4f91cbe
--- /dev/null
+++ b/clang/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}