[PATCH] D85564: [IR] Add an option to preserve llvm prefix for global identifier

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 15:54:24 PDT 2020


steven_wu created this revision.
steven_wu added reviewers: tejohnson, mehdi_amini, evgeny777.
Herald added subscribers: ributzka, dexonsmith, jkorous, hiraditya.
Herald added a project: LLVM.
steven_wu requested review of this revision.

Provide an option to preserve llvm prefix for global identifier so "\01"
prefix can be preserved when computing GUID. With "\01" prefix
preserved, we can get different GUID for "_NAME" and "\01_NAME", which
are different symbols.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85564

Files:
  llvm/include/llvm/IR/GlobalValue.h
  llvm/lib/IR/Globals.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/test/ThinLTO/X86/mangled_symbol.ll


Index: llvm/test/ThinLTO/X86/mangled_symbol.ll
===================================================================
--- llvm/test/ThinLTO/X86/mangled_symbol.ll
+++ llvm/test/ThinLTO/X86/mangled_symbol.ll
@@ -7,8 +7,10 @@
 
 ; INTERNALIZED: define internal void @extern_not_mangled
 ; INTERNALIZED: define internal void @"\01_extern_mangled"
+; INTERNALIZED: define internal void @_extern_mangled
 ; EXPORTED: define void @extern_not_mangled
 ; EXPORTED: define void @"\01_extern_mangled"
+; EXPORTED: define internal void @_extern_mangled
 
 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.11.0"
@@ -24,3 +26,8 @@
 define void @"\01_extern_mangled"() {
   ret void
 }
+
+; _extern_mangled is different from "\01_extern_mangled"
+define void @_extern_mangled() {
+  ret void
+}
Index: llvm/lib/ProfileData/InstrProf.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProf.cpp
+++ llvm/lib/ProfileData/InstrProf.cpp
@@ -220,7 +220,8 @@
                            GlobalValue::LinkageTypes Linkage,
                            StringRef FileName,
                            uint64_t Version LLVM_ATTRIBUTE_UNUSED) {
-  return GlobalValue::getGlobalIdentifier(RawFuncName, Linkage, FileName);
+  return GlobalValue::getGlobalIdentifier(RawFuncName, Linkage, FileName,
+                                          /*PreservePrefix=*/false);
 }
 
 // Strip NumPrefix level of directory name from PathNameStr. If the number of
Index: llvm/lib/IR/Globals.cpp
===================================================================
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -131,12 +131,13 @@
 
 std::string GlobalValue::getGlobalIdentifier(StringRef Name,
                                              GlobalValue::LinkageTypes Linkage,
-                                             StringRef FileName) {
+                                             StringRef FileName,
+                                             bool PreservePrefix) {
 
   // Value 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 (Name[0] == '\1')
+  if (!PreservePrefix && Name[0] == '\1')
     Name = Name.substr(1);
 
   std::string NewName = std::string(Name);
@@ -155,7 +156,8 @@
 
 std::string GlobalValue::getGlobalIdentifier() const {
   return getGlobalIdentifier(getName(), getLinkage(),
-                             getParent()->getSourceFileName());
+                             getParent()->getSourceFileName(),
+                             /*PreservePrefix=*/true);
 }
 
 StringRef GlobalValue::getSection() const {
Index: llvm/include/llvm/IR/GlobalValue.h
===================================================================
--- llvm/include/llvm/IR/GlobalValue.h
+++ llvm/include/llvm/IR/GlobalValue.h
@@ -491,7 +491,8 @@
   /// \c Linkage. The value is defined in module \c FileName.
   static std::string getGlobalIdentifier(StringRef Name,
                                          GlobalValue::LinkageTypes Linkage,
-                                         StringRef FileName);
+                                         StringRef FileName,
+                                         bool PreservePrefix = true);
 
   /// Return the modified name for this global value suitable to be
   /// used as the key for a global lookup (e.g. profile or ThinLTO).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85564.284081.patch
Type: text/x-patch
Size: 3545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200807/96b781ee/attachment.bin>


More information about the llvm-commits mailing list