[PATCH] D116054: Avoid duplicating uniqueness in ThinLTO when unique internal linkage names are used

Sriraman Tallam via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 20 12:57:19 PST 2021


tmsriram created this revision.
tmsriram added reviewers: tejohnson, wmi.
Herald added subscribers: ormris, steven_wu, hiraditya, inglorion.
tmsriram requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Option -funique-internal-linkage-names already creates unique names for internal functions.

With ThinLTO,  importing internal linkage functions uniqueifies their names to avoid two such functions from different modules colliding.  However, -funique-internal-linkage-names already does that independently.  This simple patch checks if unique names are already present before adding a unique suffix.

The benefits are that this reduces .strtab size.


https://reviews.llvm.org/D116054

Files:
  llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
  llvm/test/ThinLTO/X86/export.ll


Index: llvm/test/ThinLTO/X86/export.ll
===================================================================
--- llvm/test/ThinLTO/X86/export.ll
+++ llvm/test/ThinLTO/X86/export.ll
@@ -7,6 +7,8 @@
 ; RUN: llvm-lto -thinlto-action=promote %t1.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s
 ; CHECK-DAG: @staticvar.llvm.0 = hidden global
 ; CHECK-DAG: define hidden void @staticfunc.llvm.0
+; CHECK-DAG: define hidden void @uniqstaticfunc.__uniq.12345
+; CHECK-NOT: define hidden void @uniqstaticfunc.__uniq.12345.llvm.
 
 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"
@@ -16,6 +18,7 @@
 define void @callstaticfunc() #0 {
 entry:
   call void @staticfunc()
+  call void @uniqstaticfunc.__uniq.12345()
   ret void
 }
 
@@ -24,3 +27,9 @@
   %0 = load i32, i32* @staticvar, align 4
   ret void
 }
+
+define internal void @uniqstaticfunc.__uniq.12345() #0 {
+entry:
+  %0 = load i32, i32* @staticvar, align 4
+  ret void
+}
Index: llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
+++ llvm/lib/Transforms/Utils/FunctionImportUtils.cpp
@@ -260,7 +260,11 @@
   if (GV.hasLocalLinkage() && shouldPromoteLocalToGlobal(&GV, VI)) {
     // Save the original name string before we rename GV below.
     auto Name = GV.getName().str();
-    GV.setName(getPromotedName(&GV));
+    // With -funique-internal-linkage-names, local functions already get unique
+    // names.  To avoid duplication, check if this suffix does not exist before
+    // uniqueifying the name.  This will directly reduce .strtab size.
+    if (Name.find(".__uniq.") == std::string::npos)
+      GV.setName(getPromotedName(&GV));
     GV.setLinkage(getLinkage(&GV, /* DoPromote */ true));
     assert(!GV.hasLocalLinkage());
     GV.setVisibility(GlobalValue::HiddenVisibility);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116054.395513.patch
Type: text/x-patch
Size: 1967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211220/5ddbecff/attachment.bin>


More information about the llvm-commits mailing list