[PATCH] D89617: Append "uniq" before symbol names hash with -funique-internal-linkage-names

Sriraman Tallam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 16 23:57:51 PDT 2020


tmsriram created this revision.
tmsriram added reviewers: wmi, mtrofin, efriedma, rnk.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
tmsriram requested review of this revision.

TLDR;  Prepend the module name hash with a fixed string "uniq" which helps tools that consume sampled profiles and attribute it to functions to understand that this symbol belongs to a unique internal linkage type symbol.

Symbols with suffixes can result from various optimizations in the compiler.  Function Multiversioning, function splitting, parameter constant propogation, unique internal linkage names.

External tools like sampled profile aggregators  combine profiles from multiple runs of a binary.  They use various heuristics with symbols that have suffixes to try and attribute the profile to the right function instance.  For instance multi-versioned symbols like foo.avx, foo.sse4.2, etc even though different should be attributed to the same source function if a single function is versioned, using attribute target_clones (supported in GCC but yet to land in LLVM).  Similarly, functions that are split (split part having a .cold suffix) could have profiles for both the original and split symbols but would be aggregated and attributed to the original function that was split.

Unique internal linkage functions however have different source  instances and the aggregator must not put them together but attribute it to the appropriate function instance.  To be sure that we are dealing with a symbol of a unique internal linkage function, we would like to prepend the hash with a known string "uniq" which these tools can check to understand the suffix type.


https://reviews.llvm.org/D89617

Files:
  clang/test/CodeGen/unique-internal-linkage-names.cpp
  llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
  llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll


Index: llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
===================================================================
--- llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
+++ llvm/test/Transforms/UniqueInternalLinkageNames/unique_symbol_names.ll
@@ -9,5 +9,5 @@
   ret i32 0
 }
 
-; CHECK: @glob.6ae72bb15a7d1834b42ae042a58f7a4d = internal global
-; CHECK: define internal i32 @foo.6ae72bb15a7d1834b42ae042a58f7a4d()
+; CHECK: @glob.uniq6ae72bb15a7d1834b42ae042a58f7a4d = internal global
+; CHECK: define internal i32 @foo.uniq6ae72bb15a7d1834b42ae042a58f7a4d()
Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
===================================================================
--- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -27,7 +27,9 @@
   Md5.final(R);
   SmallString<32> Str;
   llvm::MD5::stringifyResult(R, Str);
-  std::string ModuleNameHash = (Twine(".") + Twine(Str)).str();
+  // Append "uniq" before the hash for tools like profilers to understand that
+  // this symbol is of internal linkage type.
+  std::string ModuleNameHash = (Twine(".uniq") + Twine(Str)).str();
   bool Changed = false;
 
   // Append the module hash to all internal linkage functions.
Index: clang/test/CodeGen/unique-internal-linkage-names.cpp
===================================================================
--- clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -53,15 +53,15 @@
 // PLAIN: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // PLAIN: define internal i32 @_ZL4mverv()
 // PLAIN: define internal i32 @_ZL4mverv.sse4.2()
-// UNIQUE: @_ZL4glob.{{[0-9a-f]+}} = internal global
-// UNIQUE: @_ZZ8retAnonMvE5fGlob.{{[0-9a-f]+}} = internal global
-// UNIQUE: @_ZN12_GLOBAL__N_16anon_mE.{{[0-9a-f]+}} = internal global
-// UNIQUE: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
-// UNIQUE: define internal i32 @_ZN12_GLOBAL__N_14getMEv.{{[0-9a-f]+}}
+// UNIQUE: @_ZL4glob.uniq{{[0-9a-f]+}} = internal global
+// UNIQUE: @_ZZ8retAnonMvE5fGlob.uniq{{[0-9a-f]+}} = internal global
+// UNIQUE: @_ZN12_GLOBAL__N_16anon_mE.uniq{{[0-9a-f]+}} = internal global
+// UNIQUE: define internal i32 @_ZL3foov.uniq{{[0-9a-f]+}}()
+// UNIQUE: define internal i32 @_ZN12_GLOBAL__N_14getMEv.uniq{{[0-9a-f]+}}
 // UNIQUE: define weak_odr i32 ()* @_ZL4mverv.resolver()
-// UNIQUE: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
-// UNIQUE: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
-// UNIQUEO1: define internal i32 @_ZL3foov.{{[0-9a-f]+}}()
+// UNIQUE: define internal i32 @_ZL4mverv.uniq{{[0-9a-f]+}}()
+// UNIQUE: define internal i32 @_ZL4mverv.sse4.2.uniq{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL3foov.uniq{{[0-9a-f]+}}()
 // UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
-// UNIQUEO1: define internal i32 @_ZL4mverv.{{[0-9a-f]+}}()
-// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.{{[0-9a-f]+}}
+// UNIQUEO1: define internal i32 @_ZL4mverv.uniq{{[0-9a-f]+}}()
+// UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.uniq{{[0-9a-f]+}}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89617.298809.patch
Type: text/x-patch
Size: 3150 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201017/0991890a/attachment-0001.bin>


More information about the llvm-commits mailing list