Remove unused arguments. NFC.
[oota-llvm.git] / lib / Linker / LinkModules.cpp
index 5b2d425c805dd2a21b253fa43968a7c35a271e04..1d4dae4c479dda79fa909edd675b2e6446cc90f5 100644 (file)
@@ -484,12 +484,9 @@ private:
                              const GlobalVariable *SrcGV);
 
   bool linkGlobalValueProto(GlobalValue *GV);
-  GlobalValue *linkGlobalVariableProto(const GlobalVariable *SGVar,
-                                       GlobalValue *DGV, bool LinkFromSrc);
-  GlobalValue *linkFunctionProto(const Function *SF, GlobalValue *DGV,
-                                 bool LinkFromSrc);
-  GlobalValue *linkGlobalAliasProto(const GlobalAlias *SGA, GlobalValue *DGV,
-                                    bool LinkFromSrc);
+  GlobalValue *linkGlobalVariableProto(const GlobalVariable *SGVar);
+  GlobalValue *linkFunctionProto(const Function *SF, GlobalValue *DGV);
+  GlobalValue *linkGlobalAliasProto(const GlobalAlias *SGA);
 
   bool linkModuleFlagsMetadata();
 
@@ -1021,63 +1018,58 @@ bool ModuleLinker::linkGlobalValueProto(GlobalValue *SGV) {
     return false;
 
   GlobalValue *NewGV;
-  if (auto *SGVar = dyn_cast<GlobalVariable>(SGV))
-    NewGV = linkGlobalVariableProto(SGVar, DGV, LinkFromSrc);
-  else if (auto *SF = dyn_cast<Function>(SGV))
-    NewGV = linkFunctionProto(SF, DGV, LinkFromSrc);
-  else
-    NewGV = linkGlobalAliasProto(cast<GlobalAlias>(SGV), DGV, LinkFromSrc);
-
-  if (NewGV) {
-    if (NewGV != DGV)
-      copyGVAttributes(NewGV, SGV);
-
-    NewGV->setUnnamedAddr(HasUnnamedAddr);
-    NewGV->setVisibility(Visibility);
-
-    if (auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
-      if (C)
-        NewGO->setComdat(C);
-
-      if (DGV && DGV->hasCommonLinkage() && SGV->hasCommonLinkage())
-        NewGO->setAlignment(std::max(DGV->getAlignment(), SGV->getAlignment()));
-    }
-
-    // Make sure to remember this mapping.
-    if (NewGV != DGV) {
-      if (DGV) {
-        DGV->replaceAllUsesWith(
-            ConstantExpr::getBitCast(NewGV, DGV->getType()));
-        DGV->eraseFromParent();
-      }
-      ValueMap[SGV] = NewGV;
-    }
+  if (!LinkFromSrc) {
+    NewGV = DGV;
+  } else {
+    if (auto *SGVar = dyn_cast<GlobalVariable>(SGV))
+      NewGV = linkGlobalVariableProto(SGVar);
+    else if (auto *SF = dyn_cast<Function>(SGV))
+      NewGV = linkFunctionProto(SF, DGV);
+    else
+      NewGV = linkGlobalAliasProto(cast<GlobalAlias>(SGV));
   }
 
-  return false;
-}
+  if (!NewGV)
+    return false;
 
-/// Loop through the global variables in the src module and merge them into the
-/// dest module.
-GlobalValue *ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar,
-                                                   GlobalValue *DGV,
-                                                   bool LinkFromSrc) {
-  bool ClearConstant = false;
+  if (NewGV != DGV)
+    copyGVAttributes(NewGV, SGV);
 
-  if (DGV) {
-    auto *DGVar = dyn_cast<GlobalVariable>(DGV);
-    if (!SGVar->isConstant() || (DGVar && !DGVar->isConstant()))
-      ClearConstant = true;
+  NewGV->setUnnamedAddr(HasUnnamedAddr);
+  NewGV->setVisibility(Visibility);
+
+  if (auto *NewGO = dyn_cast<GlobalObject>(NewGV)) {
+    if (C)
+      NewGO->setComdat(C);
+
+    if (DGV && DGV->hasCommonLinkage() && SGV->hasCommonLinkage())
+      NewGO->setAlignment(std::max(DGV->getAlignment(), SGV->getAlignment()));
   }
 
-  if (!LinkFromSrc) {
-    if (auto *NewGVar = dyn_cast<GlobalVariable>(DGV)) {
-      if (NewGVar->isDeclaration() && ClearConstant)
-        NewGVar->setConstant(false);
+  if (auto *NewGVar = dyn_cast<GlobalVariable>(NewGV)) {
+    auto *DGVar = dyn_cast_or_null<GlobalVariable>(DGV);
+    auto *SGVar = dyn_cast<GlobalVariable>(SGV);
+    if (DGVar && SGVar && DGVar->isDeclaration() && SGVar->isDeclaration() &&
+        (!DGVar->isConstant() || !SGVar->isConstant()))
+      NewGVar->setConstant(false);
+  }
+
+  // Make sure to remember this mapping.
+  if (NewGV != DGV) {
+    if (DGV) {
+      DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewGV, DGV->getType()));
+      DGV->eraseFromParent();
     }
-    return DGV;
+    ValueMap[SGV] = NewGV;
   }
 
+  return false;
+}
+
+/// Loop through the global variables in the src module and merge them into the
+/// dest module.
+GlobalValue *
+ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar) {
   // No linking to be performed or linking from the source: simply create an
   // identical version of the symbol over in the dest module... the
   // initializer will be filled in later by LinkGlobalInits.
@@ -1093,11 +1085,7 @@ GlobalValue *ModuleLinker::linkGlobalVariableProto(const GlobalVariable *SGVar,
 /// Link the function in the source module into the destination module if
 /// needed, setting up mapping information.
 GlobalValue *ModuleLinker::linkFunctionProto(const Function *SF,
-                                             GlobalValue *DGV,
-                                             bool LinkFromSrc) {
-  if (!LinkFromSrc)
-    return DGV;
-
+                                             GlobalValue *DGV) {
   // If the function is to be lazily linked, don't create it just yet.
   // The ValueMaterializerTy will deal with creating it if it's used.
   if (!DGV && (SF->hasLocalLinkage() || SF->hasLinkOnceLinkage() ||
@@ -1113,12 +1101,7 @@ GlobalValue *ModuleLinker::linkFunctionProto(const Function *SF,
 }
 
 /// Set up prototypes for any aliases that come over from the source module.
-GlobalValue *ModuleLinker::linkGlobalAliasProto(const GlobalAlias *SGA,
-                                                GlobalValue *DGV,
-                                                bool LinkFromSrc) {
-  if (!LinkFromSrc)
-    return DGV;
-
+GlobalValue *ModuleLinker::linkGlobalAliasProto(const GlobalAlias *SGA) {
   // If there is no linkage to be performed or we're linking from the source,
   // bring over SGA.
   auto *PTy = cast<PointerType>(TypeMap.get(SGA->getType()));