[llvm] r275247 - [ThinLTO/gold] ThinLTO internalization fixes

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 20:42:41 PDT 2016


Author: tejohnson
Date: Tue Jul 12 22:42:41 2016
New Revision: 275247

URL: http://llvm.org/viewvc/llvm-project?rev=275247&view=rev
Log:
[ThinLTO/gold] ThinLTO internalization fixes

Internalization was missing cases where we originally had a local symbol
that was promoted eagerly but not actually exported. This is because we
were only internalizing the set of global (non-local) symbols that were
PREVAILAING_DEF_IRONLY. Instead, collect the set of global symbols that
are referenced outside of a single IR file, and skip internalization for
those.

Modified:
    llvm/trunk/test/tools/gold/X86/thinlto.ll
    llvm/trunk/test/tools/gold/X86/thinlto_internalize.ll
    llvm/trunk/tools/gold/gold-plugin.cpp

Modified: llvm/trunk/test/tools/gold/X86/thinlto.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/thinlto.ll?rev=275247&r1=275246&r2=275247&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/X86/thinlto.ll (original)
+++ llvm/trunk/test/tools/gold/X86/thinlto.ll Tue Jul 12 22:42:41 2016
@@ -62,6 +62,8 @@
 ; BACKEND1-NEXT: </MODULE_STRTAB_BLOCK
 ; BACKEND1-NEXT: <GLOBALVAL_SUMMARY_BLOCK
 ; BACKEND1-NEXT: <VERSION
+; One of these will be a COMBINED_ORIGINAL_NAME since f can be internalized.
+; BACKEND1-NEXT: <COMBINED
 ; BACKEND1-NEXT: <COMBINED
 ; BACKEND1-NEXT: <COMBINED
 ; BACKEND1-NEXT: </GLOBALVAL_SUMMARY_BLOCK

Modified: llvm/trunk/test/tools/gold/X86/thinlto_internalize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/gold/X86/thinlto_internalize.ll?rev=275247&r1=275246&r2=275247&view=diff
==============================================================================
--- llvm/trunk/test/tools/gold/X86/thinlto_internalize.ll (original)
+++ llvm/trunk/test/tools/gold/X86/thinlto_internalize.ll Tue Jul 12 22:42:41 2016
@@ -11,11 +11,18 @@
 ; f() should be internalized and eliminated after inlining
 ; CHECK-NOT: @f()
 
+; h() should be internalized after promotion, and eliminated after inlining
+; CHECK-NOT: @h.llvm.
+
 target triple = "x86_64-unknown-linux-gnu"
 define i32 @g() {
   call void @f()
+  call void @h()
   ret i32 0
 }
 define void @f() {
   ret void
 }
+define internal void @h() {
+  ret void
+}

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=275247&r1=275246&r2=275247&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Tue Jul 12 22:42:41 2016
@@ -1323,10 +1323,9 @@ static ld_plugin_status thinLTOLink(raw_
   // interfaces with gold.
   DenseMap<void *, std::unique_ptr<PluginInputFile>> HandleToInputFile;
 
-  // Keep track of internalization candidates as well as those that may not
-  // be internalized because they are refereneced from other IR modules.
-  DenseSet<GlobalValue::GUID> Internalize;
-  DenseSet<GlobalValue::GUID> CrossReferenced;
+  // Keep track of symbols that must not be internalized because they
+  // are referenced outside of a single IR module.
+  DenseSet<GlobalValue::GUID> Preserve;
 
   ModuleSummaryIndex CombinedIndex;
   uint64_t NextModuleId = 0;
@@ -1352,23 +1351,17 @@ static ld_plugin_status thinLTOLink(raw_
     if (Index)
       CombinedIndex.mergeFrom(std::move(Index), ++NextModuleId);
 
-    // Look for internalization candidates based on gold's symbol resolution
-    // information. Also track symbols referenced from other IR modules.
+    // Use gold's symbol resolution information to identify symbols referenced
+    // by more than a single IR module (before importing, which is checked
+    // separately).
     for (auto &Sym : F.syms) {
       ld_plugin_symbol_resolution Resolution =
           (ld_plugin_symbol_resolution)Sym.resolution;
-      if (Resolution == LDPR_PREVAILING_DEF_IRONLY)
-        Internalize.insert(GlobalValue::getGUID(Sym.name));
-      if (Resolution == LDPR_RESOLVED_IR || Resolution == LDPR_PREEMPTED_IR)
-        CrossReferenced.insert(GlobalValue::getGUID(Sym.name));
+      if (Resolution != LDPR_PREVAILING_DEF_IRONLY)
+        Preserve.insert(GlobalValue::getGUID(Sym.name));
     }
   }
 
-  // Remove symbols referenced from other IR modules from the internalization
-  // candidate set.
-  for (auto &S : CrossReferenced)
-    Internalize.erase(S);
-
   // Collect for each module the list of function it defines (GUID ->
   // Summary).
   StringMap<std::map<GlobalValue::GUID, GlobalValueSummary *>>
@@ -1387,7 +1380,7 @@ static ld_plugin_status thinLTOLink(raw_
     const auto &ExportList = ExportLists.find(ModuleIdentifier);
     return (ExportList != ExportLists.end() &&
             ExportList->second.count(GUID)) ||
-           !Internalize.count(GUID);
+           Preserve.count(GUID);
   };
 
   // Use global summary-based analysis to identify symbols that can be




More information about the llvm-commits mailing list