[llvm] r267543 - ThinLTOCodeGenerator: preserve linkonce when in "MustPreserved" set

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 03:35:02 PDT 2016


Author: mehdi_amini
Date: Tue Apr 26 05:35:01 2016
New Revision: 267543

URL: http://llvm.org/viewvc/llvm-project?rev=267543&view=rev
Log:
ThinLTOCodeGenerator: preserve linkonce when in "MustPreserved" set

If the linker specifically requested for a linkonce to be preserved,
we need to make sure we won't drop it even if all the uses in the
current module disappear.

From: Mehdi Amini <mehdi.amini at apple.com>

Modified:
    llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
    llvm/trunk/test/ThinLTO/X86/odr_resolution.ll

Modified: llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp?rev=267543&r1=267542&r2=267543&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp Tue Apr 26 05:35:01 2016
@@ -137,6 +137,7 @@ bool IsFirstDefinitionForLinker(const Gl
 static GlobalValue::LinkageTypes
 ResolveODR(const ModuleSummaryIndex &Index,
            const FunctionImporter::ExportSetTy &ExportList,
+           const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
            StringRef ModuleIdentifier, GlobalValue::GUID GUID,
            const GlobalValueSummary &GV) {
   auto HasMultipleCopies = [&](const GlobalValueSummaryList &GVSummaryList) {
@@ -163,7 +164,7 @@ ResolveODR(const ModuleSummaryIndex &Ind
     if (!HasMultipleCopies(GVSummaryList)) {
       // Exported LinkonceODR needs to be promoted to not be discarded
       if (GlobalValue::isDiscardableIfUnused(OriginalLinkage) &&
-          ExportList.count(GUID))
+          (ExportList.count(GUID) || GUIDPreservedSymbols.count(GUID)))
         return GlobalValue::WeakODRLinkage;
       break;
     }
@@ -187,6 +188,7 @@ ResolveODR(const ModuleSummaryIndex &Ind
 static void ResolveODR(
     const ModuleSummaryIndex &Index,
     const FunctionImporter::ExportSetTy &ExportList,
+    const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols,
     const GVSummaryMapTy &DefinedGlobals, StringRef ModuleIdentifier,
     std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> &ResolvedODR) {
   if (Index.modulePaths().size() == 1)
@@ -206,7 +208,7 @@ static void ResolveODR(
     if (GlobalInvolvedWithAlias.count(GV.second))
       continue;
     auto NewLinkage =
-        ResolveODR(Index, ExportList, ModuleIdentifier, GV.first, *GV.second);
+        ResolveODR(Index, ExportList, GUIDPreservedSymbols, ModuleIdentifier, GV.first, *GV.second);
     if (NewLinkage != GV.second->linkage()) {
       ResolvedODR[GV.first] = NewLinkage;
     }
@@ -681,13 +683,17 @@ void ThinLTOCodeGenerator::promote(Modul
                            ExportLists);
   auto &ExportList = ExportLists[ModuleIdentifier];
 
+  // Convert the preserved symbols set from string to GUID
+  auto GUIDPreservedSymbols =
+  computeGUIDPreservedSymbols(PreservedSymbols, TMBuilder.TheTriple);
+
   // Resolve the LinkOnceODR, trying to turn them into "available_externally"
   // where possible.
   // This is a compile-time optimization.
   // We use a std::map here to be able to have a defined ordering when
   // producing a hash for the cache entry.
   std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> ResolvedODR;
-  ResolveODR(Index, ExportList, ModuleToDefinedGVSummaries[ModuleIdentifier],
+  ResolveODR(Index, ExportList, GUIDPreservedSymbols, ModuleToDefinedGVSummaries[ModuleIdentifier],
              ModuleIdentifier, ResolvedODR);
   fixupODR(TheModule, ResolvedODR);
 
@@ -841,7 +847,7 @@ void ThinLTOCodeGenerator::run() {
         // We use a std::map here to be able to have a defined ordering when
         // producing a hash for the cache entry.
         std::map<GlobalValue::GUID, GlobalValue::LinkageTypes> ResolvedODR;
-        ResolveODR(*Index, ExportList, DefinedFunctions, ModuleIdentifier,
+        ResolveODR(*Index, ExportList, GUIDPreservedSymbols, DefinedFunctions, ModuleIdentifier,
                    ResolvedODR);
 
         // The module may be cached, this helps handling it.

Modified: llvm/trunk/test/ThinLTO/X86/odr_resolution.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/odr_resolution.ll?rev=267543&r1=267542&r2=267543&view=diff
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/odr_resolution.ll (original)
+++ llvm/trunk/test/ThinLTO/X86/odr_resolution.ll Tue Apr 26 05:35:01 2016
@@ -6,6 +6,8 @@
 ; Verify that only one ODR is selected across modules, but non ODR are not affected.
 ; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD1
 ; RUN: llvm-lto -thinlto-action=promote %t2.bc -thinlto-index=%t3.bc -o - | llvm-dis -o - | FileCheck %s --check-prefix=MOD2
+; When exported, we always preserve a linkonce
+; RUN: llvm-lto -thinlto-action=promote %t.bc -thinlto-index=%t3.bc -o - --exported-symbol=linkonceodrfuncInSingleModule | llvm-dis -o - | FileCheck %s --check-prefix=EXPORTED
 
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.11.0"
@@ -48,3 +50,9 @@ entry:
   ret void
 }
 
+; MOD1: define linkonce_odr void @linkonceodrfuncInSingleModule()
+; EXPORTED: define weak_odr void @linkonceodrfuncInSingleModule()
+define linkonce_odr void @linkonceodrfuncInSingleModule() #0 {
+entry:
+  ret void
+}




More information about the llvm-commits mailing list