[PATCH] D18516: [PGO] Fix name encoding for ObjC-like functions

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 08:34:47 PDT 2016


vsk created this revision.
vsk added a reviewer: davidxl.
vsk added a subscriber: llvm-commits.

Function names in ObjC can have spaces in them. This interacts poorly with name compression, which uses spaces to separate PGO names. Fix the issue by using a different separator and add a test.

I chose "\01" as the separator because 1) it's non-printable, 2) we strip it from PGO names, and 3) it's the next natural choice once "\00" is discarded (that one's overloaded).

http://reviews.llvm.org/D18516

Files:
  lib/ProfileData/InstrProf.cpp
  unittests/ProfileData/InstrProfTest.cpp

Index: unittests/ProfileData/InstrProfTest.cpp
===================================================================
--- unittests/ProfileData/InstrProfTest.cpp
+++ unittests/ProfileData/InstrProfTest.cpp
@@ -893,7 +893,7 @@
     OS << "func_" << I;
     FuncNames1.push_back(OS.str());
     str.clear();
-    OS << "fooooooooooooooo_" << I;
+    OS << "f oooooooooooooo_" << I;
     FuncNames1.push_back(OS.str());
     str.clear();
     OS << "BAR_" << I;
@@ -931,7 +931,7 @@
       StringRef R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[0]));
       ASSERT_EQ(StringRef("func_0"), R);
       R = Symtab.getFuncName(IndexedInstrProf::ComputeHash(FuncNames1[1]));
-      ASSERT_EQ(StringRef("fooooooooooooooo_0"), R);
+      ASSERT_EQ(StringRef("f oooooooooooooo_0"), R);
       for (int I = 0; I < 3; I++) {
         std::string N[4];
         N[0] = FuncNames1[2 * I];
Index: lib/ProfileData/InstrProf.cpp
===================================================================
--- lib/ProfileData/InstrProf.cpp
+++ lib/ProfileData/InstrProf.cpp
@@ -160,7 +160,7 @@
                               bool doCompression, std::string &Result) {
   uint8_t Header[16], *P = Header;
   std::string UncompressedNameStrings =
-      join(NameStrs.begin(), NameStrs.end(), StringRef(" "));
+      join(NameStrs.begin(), NameStrs.end(), StringRef("\01"));
 
   unsigned EncLen = encodeULEB128(UncompressedNameStrings.length(), P);
   P += EncLen;
@@ -238,7 +238,7 @@
     }
     // Now parse the name strings.
     SmallVector<StringRef, 0> Names;
-    NameStrings.split(Names, ' ');
+    NameStrings.split(Names, '\01');
     for (StringRef &Name : Names)
       Symtab.addFuncName(Name);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18516.51792.patch
Type: text/x-patch
Size: 1697 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160328/8f760880/attachment.bin>


More information about the llvm-commits mailing list