[PATCH] Set function entry count.

Diego Novillo dnovillo at google.com
Tue May 26 09:58:23 PDT 2015


Hi dexonsmith,

I don't particularly like this approach.

The change in linkage for link once symbols is needed for ELF targets.
Although the symbol is only associated once, the discarded symbols
still occupy memory. This causes duplicate count problem at runtime
because the raw profile contains multiple copies of the same data
record (see https://llvm.org/bugs/show_bug.cgi?id=23499 for details).

http://reviews.llvm.org/D10035

Files:
  lib/CodeGen/CodeGenPGO.cpp
  test/Profile/cxx-linkage.cpp
  test/Profile/cxx-templates.cpp

Index: lib/CodeGen/CodeGenPGO.cpp
===================================================================
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -66,7 +66,8 @@
   else if (Linkage == llvm::GlobalValue::AvailableExternallyLinkage)
     Linkage = llvm::GlobalValue::LinkOnceODRLinkage;
   else if (Linkage == llvm::GlobalValue::InternalLinkage ||
-           Linkage == llvm::GlobalValue::ExternalLinkage)
+           Linkage == llvm::GlobalValue::ExternalLinkage ||
+           Linkage == llvm::GlobalValue::LinkOnceODRLinkage)
     Linkage = llvm::GlobalValue::PrivateLinkage;
 
   auto *Value =
@@ -773,6 +774,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) {
Index: test/Profile/cxx-linkage.cpp
===================================================================
--- test/Profile/cxx-linkage.cpp
+++ test/Profile/cxx-linkage.cpp
@@ -3,7 +3,7 @@
 // CHECK: @__llvm_profile_name__Z3foov = private constant [7 x i8] c"_Z3foov"
 // CHECK: @__llvm_profile_name__Z8foo_weakv = weak hidden constant [12 x i8] c"_Z8foo_weakv"
 // CHECK: @__llvm_profile_name_main = private constant [4 x i8] c"main"
-// CHECK: @__llvm_profile_name__Z10foo_inlinev = linkonce_odr hidden constant [15 x i8] c"_Z10foo_inlinev"
+// CHECK: @__llvm_profile_name__Z10foo_inlinev = private constant [15 x i8] c"_Z10foo_inlinev"
 
 void foo(void) { }
 
Index: test/Profile/cxx-templates.cpp
===================================================================
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -10,8 +10,8 @@
 // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
 
-// T0GEN: @[[T0C:__llvm_profile_counters__Z4loopILj0EEvv]] = linkonce_odr hidden global [2 x i64] zeroinitializer
-// T100GEN: @[[T100C:__llvm_profile_counters__Z4loopILj100EEvv]] = linkonce_odr hidden global [2 x i64] zeroinitializer
+// T0GEN: @[[T0C:__llvm_profile_counters__Z4loopILj0EEvv]] = private global [2 x i64] zeroinitializer
+// T100GEN: @[[T100C:__llvm_profile_counters__Z4loopILj100EEvv]] = private global [2 x i64] zeroinitializer
 
 // T0GEN-LABEL: define linkonce_odr void @_Z4loopILj0EEvv()
 // T0USE-LABEL: define linkonce_odr void @_Z4loopILj0EEvv()

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10035.26519.patch
Type: text/x-patch
Size: 2519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150526/e29cfedb/attachment.bin>


More information about the cfe-commits mailing list