[llvm] r255365 - [PGO] Stop using invalid char in instr variable names.

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 11 11:53:19 PST 2015


Author: davidxl
Date: Fri Dec 11 13:53:19 2015
New Revision: 255365

URL: http://llvm.org/viewvc/llvm-project?rev=255365&view=rev
Log:
[PGO] Stop using invalid char in instr variable names.

Before the patch, -fprofile-instr-generate compile will fail
if no integrated-as is specified when the file contains
any static functions (the -S output is also invalid).

This patch fixed the issue. With the change, the index format
version will be bumped up by 1. Backward compatibility is 
preserved with this change.

Differential Revision: http://reviews.llvm.org/D15243



Added:
    llvm/trunk/test/tools/llvm-profdata/Inputs/compat.profdata.v4   (with props)
Modified:
    llvm/trunk/include/llvm/ProfileData/InstrProf.h
    llvm/trunk/lib/ProfileData/InstrProf.cpp
    llvm/trunk/test/Transforms/PGOProfile/Inputs/criticaledge.proftext
    llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll
    llvm/trunk/test/tools/llvm-profdata/compat.proftext

Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=255365&r1=255364&r2=255365&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Fri Dec 11 13:53:19 2015
@@ -30,7 +30,7 @@
 #include <system_error>
 #include <vector>
 
-#define INSTR_PROF_INDEX_VERSION 3
+#define INSTR_PROF_INDEX_VERSION 4
 namespace llvm {
 
 class Function;

Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=255365&r1=255364&r2=255365&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Fri Dec 11 13:53:19 2015
@@ -74,14 +74,15 @@ namespace llvm {
 
 std::string getPGOFuncName(StringRef RawFuncName,
                            GlobalValue::LinkageTypes Linkage,
-                           StringRef FileName,
-                           uint64_t Version LLVM_ATTRIBUTE_UNUSED) {
+                           StringRef FileName, uint64_t Version) {
 
   // Function names may be prefixed with a binary '1' to indicate
   // that the backend should not modify the symbols due to any platform
   // naming convention. Do not include that '1' in the PGO profile name.
   if (RawFuncName[0] == '\1')
     RawFuncName = RawFuncName.substr(1);
+  const char *Unknown = (Version <= 3 ? "<unknown>:" : "__unknown__");
+  const char *Sep = (Version <= 3 ? ":" : "__");
 
   std::string FuncName = RawFuncName;
   if (llvm::GlobalValue::isLocalLinkage(Linkage)) {
@@ -90,9 +91,9 @@ std::string getPGOFuncName(StringRef Raw
     // that it will stay the same, e.g., if the files are checked out from
     // version control in different locations.
     if (FileName.empty())
-      FuncName = FuncName.insert(0, "<unknown>:");
+      FuncName = FuncName.insert(0, Unknown);
     else
-      FuncName = FuncName.insert(0, FileName.str() + ":");
+      FuncName = FuncName.insert(0, FileName.str() + Sep);
   }
   return FuncName;
 }

Modified: llvm/trunk/test/Transforms/PGOProfile/Inputs/criticaledge.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/Inputs/criticaledge.proftext?rev=255365&r1=255364&r2=255365&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/Inputs/criticaledge.proftext (original)
+++ llvm/trunk/test/Transforms/PGOProfile/Inputs/criticaledge.proftext Fri Dec 11 13:53:19 2015
@@ -10,7 +10,7 @@ test_criticalEdge
 2
 1
 
-<stdin>:bar
+<stdin>__bar
 12884901887
 1
 7

Modified: llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll?rev=255365&r1=255364&r2=255365&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll (original)
+++ llvm/trunk/test/Transforms/PGOProfile/criticaledge.ll Fri Dec 11 13:53:19 2015
@@ -5,7 +5,7 @@ target datalayout = "e-m:e-i64:64-f80:12
 target triple = "x86_64-unknown-linux-gnu"
 
 ; GEN: @__llvm_profile_name_test_criticalEdge = private constant [17 x i8] c"test_criticalEdge"
-; GEN: @"__llvm_profile_name_<stdin>:bar" = private constant [11 x i8] c"<stdin>:bar"
+; GEN: @"__llvm_profile_name_<stdin>__bar" = private constant [12 x i8] c"<stdin>__bar"
 
 define i32 @test_criticalEdge(i32 %i, i32 %j) {
 entry:
@@ -99,7 +99,7 @@ return:
 
 define internal i32 @bar(i32 %i) {
 entry:
-; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @"__llvm_profile_name_<stdin>:bar", i32 0, i32 0), i64 12884901887, i32 1, i32 0)
+; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @"__llvm_profile_name_<stdin>__bar", i32 0, i32 0), i64 12884901887, i32 1, i32 0)
   ret i32 %i
 }
 

Added: llvm/trunk/test/tools/llvm-profdata/Inputs/compat.profdata.v4
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/Inputs/compat.profdata.v4?rev=255365&view=auto
==============================================================================
Binary file - no diff available.

Propchange: llvm/trunk/test/tools/llvm-profdata/Inputs/compat.profdata.v4
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: llvm/trunk/test/tools/llvm-profdata/compat.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-profdata/compat.proftext?rev=255365&r1=255364&r2=255365&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-profdata/compat.proftext (original)
+++ llvm/trunk/test/tools/llvm-profdata/compat.proftext Fri Dec 11 13:53:19 2015
@@ -65,3 +65,10 @@ large_numbers
 # FORMATV2-NEXT: Maximum internal block count: 1000000
 
 
+# RUN: llvm-profdata show %S/Inputs/compat.profdata.v4 -all-functions --counts | FileCheck %s -check-prefix=FORMATV4
+# FORMATV4:  instrprof.c__foo_static:
+# FORMATV4-NEXT:    Hash: 0x000000000000000a
+# FORMATV4-NEXT:    Counters: 2
+# FORMATV4-NEXT:    Function count: 500500
+# FORMATV4-NEXT:    Block counts: [180100]
+




More information about the llvm-commits mailing list