Rename MDValue* to Metadata* (NFC)
[oota-llvm.git] / lib / Linker / LinkModules.cpp
index e866461cf9aac985e8f0095eae85ca2a1ba69d20..9de3be412d757443c654c6f8a3fe4f69fbb4cfb8 100644 (file)
@@ -38,9 +38,9 @@ class ModuleLinker {
   /// importing/exporting handling.
   const FunctionInfoIndex *ImportIndex;
 
-  /// Function to import from source module, all other functions are
+  /// Functions to import from source module, all other functions are
   /// imported as declarations instead of definitions.
-  DenseSet<const GlobalValue *> *ImportFunction;
+  DenseSet<const GlobalValue *> *FunctionsToImport;
 
   /// Set to true if the given FunctionInfoIndex contains any functions
   /// from this source module, in which case we must conservatively assume
@@ -118,7 +118,7 @@ class ModuleLinker {
 
   /// Helper methods to check if we are importing from or potentially
   /// exporting from the current source module.
-  bool isPerformingImport() const { return ImportFunction != nullptr; }
+  bool isPerformingImport() const { return FunctionsToImport != nullptr; }
   bool isModuleExporting() const { return HasExportedFunctions; }
 
   /// If we are importing from the source module, checks if we should
@@ -142,32 +142,23 @@ class ModuleLinker {
   /// to be adjusted.
   GlobalValue::LinkageTypes getLinkage(const GlobalValue *SGV);
 
-  /// Copies the necessary global value attributes and name from the source
-  /// to the newly cloned global value.
-  void copyGVAttributes(GlobalValue *NewGV, const GlobalValue *SrcGV);
-
-  /// Updates the visibility for the new global cloned from the source
-  /// and, if applicable, linked with an existing destination global.
-  /// Handles visibility change required for promoted locals.
-  void setVisibility(GlobalValue *NewGV, const GlobalValue *SGV,
-                     const GlobalValue *DGV = nullptr);
-
 public:
   ModuleLinker(IRMover &Mover, Module &SrcM, unsigned Flags,
                const FunctionInfoIndex *Index = nullptr,
                DenseSet<const GlobalValue *> *FunctionsToImport = nullptr,
                DenseMap<unsigned, MDNode *> *ValIDToTempMDMap = nullptr)
       : Mover(Mover), SrcM(SrcM), Flags(Flags), ImportIndex(Index),
-        ImportFunction(FunctionsToImport), ValIDToTempMDMap(ValIDToTempMDMap) {
-    assert((ImportIndex || !ImportFunction) &&
+        FunctionsToImport(FunctionsToImport),
+        ValIDToTempMDMap(ValIDToTempMDMap) {
+    assert((ImportIndex || !FunctionsToImport) &&
            "Expect a FunctionInfoIndex when importing");
     // If we have a FunctionInfoIndex but no function to import,
     // then this is the primary module being compiled in a ThinLTO
     // backend compilation, and we need to see if it has functions that
     // may be exported to another backend compilation.
-    if (ImportIndex && !ImportFunction)
+    if (ImportIndex && !FunctionsToImport)
       HasExportedFunctions = ImportIndex->hasExportedFunctions(SrcM);
-    assert((ValIDToTempMDMap || !ImportFunction) &&
+    assert((ValIDToTempMDMap || !FunctionsToImport) &&
            "Function importing must provide a ValIDToTempMDMap");
   }
 
@@ -175,38 +166,6 @@ public:
 };
 }
 
-/// The LLVM SymbolTable class autorenames globals that conflict in the symbol
-/// table. This is good for all clients except for us. Go through the trouble
-/// to force this back.
-static void forceRenaming(GlobalValue *GV, StringRef Name) {
-  // If the global doesn't force its name or if it already has the right name,
-  // there is nothing for us to do.
-  // Note that any required local to global promotion should already be done,
-  // so promoted locals will not skip this handling as their linkage is no
-  // longer local.
-  if (GV->hasLocalLinkage() || GV->getName() == Name)
-    return;
-
-  Module *M = GV->getParent();
-
-  // If there is a conflict, rename the conflict.
-  if (GlobalValue *ConflictGV = M->getNamedValue(Name)) {
-    GV->takeName(ConflictGV);
-    ConflictGV->setName(Name); // This will cause ConflictGV to get renamed
-    assert(ConflictGV->getName() != Name && "forceRenaming didn't work");
-  } else {
-    GV->setName(Name); // Force the name back
-  }
-}
-
-/// copy additional attributes (those not needed to construct a GlobalValue)
-/// from the SrcGV to the DestGV.
-void ModuleLinker::copyGVAttributes(GlobalValue *NewGV,
-                                    const GlobalValue *SrcGV) {
-  NewGV->copyAttributesFrom(SrcGV);
-  forceRenaming(NewGV, getName(SrcGV));
-}
-
 bool ModuleLinker::doImportAsDefinition(const GlobalValue *SGV) {
   if (!isPerformingImport())
     return false;
@@ -231,7 +190,7 @@ bool ModuleLinker::doImportAsDefinition(const GlobalValue *SGV) {
     return true;
   // Only import the function requested for importing.
   auto *SF = dyn_cast<Function>(SGV);
-  if (SF && ImportFunction->count(SF))
+  if (SF && FunctionsToImport->count(SF))
     return true;
   // Otherwise no.
   return false;
@@ -383,18 +342,6 @@ getMinVisibility(GlobalValue::VisibilityTypes A,
   return GlobalValue::DefaultVisibility;
 }
 
-void ModuleLinker::setVisibility(GlobalValue *NewGV, const GlobalValue *SGV,
-                                 const GlobalValue *DGV) {
-  GlobalValue::VisibilityTypes Visibility = SGV->getVisibility();
-  if (DGV)
-    Visibility = getMinVisibility(DGV->getVisibility(), Visibility);
-  // For promoted locals, mark them hidden so that they can later be
-  // stripped from the symbol table to reduce bloat.
-  if (SGV->hasLocalLinkage() && doPromoteLocalToGlobal(SGV))
-    Visibility = GlobalValue::HiddenVisibility;
-  NewGV->setVisibility(Visibility);
-}
-
 bool ModuleLinker::getComdatLeader(Module &M, StringRef ComdatName,
                                    const GlobalVariable *&GVar) {
   const GlobalValue *GVal = M.getNamedValue(ComdatName);
@@ -530,9 +477,9 @@ bool ModuleLinker::shouldLinkFromSource(bool &LinkFromSrc,
 
   if (isPerformingImport()) {
     if (isa<Function>(&Src)) {
-      // For functions, LinkFromSrc iff this is the function requested
+      // For functions, LinkFromSrc iff this is a function requested
       // for importing. For variables, decide below normally.
-      LinkFromSrc = ImportFunction->count(&Src);
+      LinkFromSrc = FunctionsToImport->count(&Src);
       return false;
     }