[llvm] r266170 - Move "ExternalSymbols" out of LTOInternalize (NFC)

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 12 22:36:06 PDT 2016


Author: mehdi_amini
Date: Wed Apr 13 00:36:06 2016
New Revision: 266170

URL: http://llvm.org/viewvc/llvm-project?rev=266170&view=rev
Log:
Move "ExternalSymbols" out of LTOInternalize (NFC)

This is not really related to internalization per se.

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

Modified:
    llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
    llvm/trunk/lib/LTO/LTOInternalize.cpp
    llvm/trunk/lib/LTO/LTOInternalize.h

Modified: llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOCodeGenerator.cpp?rev=266170&r1=266169&r2=266170&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/LTOCodeGenerator.cpp Wed Apr 13 00:36:06 2016
@@ -337,6 +337,23 @@ void LTOCodeGenerator::applyScopeRestric
   if (ScopeRestrictionsDone || !ShouldInternalize)
     return;
 
+  if (ShouldRestoreGlobalsLinkage) {
+    // Record the linkage type of non-local symbols so they can be restored
+    // prior
+    // to module splitting.
+    auto RecordLinkage = [&](const GlobalValue &GV) {
+      if (!GV.hasAvailableExternallyLinkage() && !GV.hasLocalLinkage() &&
+          GV.hasName())
+        ExternalSymbols.insert(std::make_pair(GV.getName(), GV.getLinkage()));
+    };
+    for (auto &GV : *MergedModule)
+      RecordLinkage(GV);
+    for (auto &GV : MergedModule->globals())
+      RecordLinkage(GV);
+    for (auto &GV : MergedModule->aliases())
+      RecordLinkage(GV);
+  }
+
   // Declare a callback for the internalize pass that will ask for every
   // candidate GlobalValue if it can be internalized or not.
   Mangler Mangler;
@@ -352,8 +369,7 @@ void LTOCodeGenerator::applyScopeRestric
     return MustPreserveSymbols.count(MangledName);
   };
 
-  LTOInternalize(*MergedModule, *TargetMach, MustPreserveGV, AsmUndefinedRefs,
-                 (ShouldRestoreGlobalsLinkage ? &ExternalSymbols : nullptr));
+  LTOInternalize(*MergedModule, *TargetMach, MustPreserveGV, AsmUndefinedRefs);
 
   ScopeRestrictionsDone = true;
 }

Modified: llvm/trunk/lib/LTO/LTOInternalize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOInternalize.cpp?rev=266170&r1=266169&r2=266170&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOInternalize.cpp (original)
+++ llvm/trunk/lib/LTO/LTOInternalize.cpp Wed Apr 13 00:36:06 2016
@@ -28,10 +28,8 @@ class ComputeAsmUsed {
 public:
   ComputeAsmUsed(const StringSet<> &AsmUndefinedRefs, const TargetMachine &TM,
                  const Module &TheModule,
-                 StringMap<GlobalValue::LinkageTypes> *ExternalSymbols,
                  SmallPtrSetImpl<const GlobalValue *> &AsmUsed)
-      : AsmUndefinedRefs(AsmUndefinedRefs), TM(TM),
-        ExternalSymbols(ExternalSymbols), AsmUsed(AsmUsed) {
+      : AsmUndefinedRefs(AsmUndefinedRefs), TM(TM), AsmUsed(AsmUsed) {
     accumulateAndSortLibcalls(TheModule);
     for (const Function &F : TheModule)
       findAsmUses(F);
@@ -51,7 +49,6 @@ private:
   std::vector<StringRef> Libcalls;
 
   // Output
-  StringMap<GlobalValue::LinkageTypes> *ExternalSymbols;
   SmallPtrSetImpl<const GlobalValue *> &AsmUsed;
 
   // Collect names of runtime library functions. User-defined functions with the
@@ -114,13 +111,6 @@ private:
     if (isa<Function>(GV) &&
         std::binary_search(Libcalls.begin(), Libcalls.end(), GV.getName()))
       AsmUsed.insert(&GV);
-
-    // Record the linkage type of non-local symbols so they can be restored
-    // prior
-    // to module splitting.
-    if (ExternalSymbols && !GV.hasAvailableExternallyLinkage() &&
-        !GV.hasLocalLinkage() && GV.hasName())
-      ExternalSymbols->insert(std::make_pair(GV.getName(), GV.getLinkage()));
   }
 };
 
@@ -142,10 +132,9 @@ static void findUsedValues(GlobalVariabl
 void llvm::LTOInternalize(
     Module &TheModule, const TargetMachine &TM,
     const std::function<bool(const GlobalValue &)> &MustPreserveSymbols,
-    const StringSet<> &AsmUndefinedRefs,
-    StringMap<GlobalValue::LinkageTypes> *ExternalSymbols) {
+    const StringSet<> &AsmUndefinedRefs) {
   SmallPtrSet<const GlobalValue *, 8> AsmUsed;
-  ComputeAsmUsed(AsmUndefinedRefs, TM, TheModule, ExternalSymbols, AsmUsed);
+  ComputeAsmUsed(AsmUndefinedRefs, TM, TheModule, AsmUsed);
 
   GlobalVariable *LLVMCompilerUsed =
       TheModule.getGlobalVariable("llvm.compiler.used");

Modified: llvm/trunk/lib/LTO/LTOInternalize.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOInternalize.h?rev=266170&r1=266169&r2=266170&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOInternalize.h (original)
+++ llvm/trunk/lib/LTO/LTOInternalize.h Wed Apr 13 00:36:06 2016
@@ -26,8 +26,7 @@ class TargetMachine;
 void LTOInternalize(
     Module &TheModule, const TargetMachine &TM,
     const std::function<bool(const GlobalValue &)> &MustPreserveSymbols,
-    const StringSet<> &AsmUndefinedRefs,
-    StringMap<GlobalValue::LinkageTypes> *ExternalSymbols);
+    const StringSet<> &AsmUndefinedRefs);
 }
 
 #endif // LLVM_LTO_LTOINTERNALIZE_H




More information about the llvm-commits mailing list