summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Linker/LinkModules.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-12-05 17:53:15 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-12-05 17:53:15 +0000
commit26c2951117afe06a05969beecbdb0d4f7f54116e (patch)
treeee9e5a901a98c434b0cb5b4d7d6cc37314ba0b7d /llvm/lib/Linker/LinkModules.cpp
parent7f0a430c7d327ba5e1f06f309fa814a31691d8c3 (diff)
downloadbcm5719-llvm-26c2951117afe06a05969beecbdb0d4f7f54116e.tar.gz
bcm5719-llvm-26c2951117afe06a05969beecbdb0d4f7f54116e.zip
Refactor duplicated code. NFC.
llvm-svn: 223486
Diffstat (limited to 'llvm/lib/Linker/LinkModules.cpp')
-rw-r--r--llvm/lib/Linker/LinkModules.cpp42
1 files changed, 16 insertions, 26 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 4aa0b88df5b..18fab19833d 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -485,11 +485,9 @@ private:
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 *DGV);
+ GlobalValue *linkFunctionProto(const Function *SF, GlobalValue *DGV);
+ GlobalValue *linkGlobalAliasProto(const GlobalAlias *SGA, GlobalValue *DGV);
bool linkModuleFlagsMetadata();
@@ -1021,12 +1019,16 @@ 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 (!LinkFromSrc) {
+ NewGV = DGV;
+ } else {
+ if (auto *SGVar = dyn_cast<GlobalVariable>(SGV))
+ NewGV = linkGlobalVariableProto(SGVar, DGV);
+ else if (auto *SF = dyn_cast<Function>(SGV))
+ NewGV = linkFunctionProto(SF, DGV);
+ else
+ NewGV = linkGlobalAliasProto(cast<GlobalAlias>(SGV), DGV);
+ }
if (!NewGV)
return false;
@@ -1068,11 +1070,7 @@ bool ModuleLinker::linkGlobalValueProto(GlobalValue *SGV) {
/// 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) {
- if (!LinkFromSrc)
- return DGV;
-
+ GlobalValue *DGV) {
// 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.
@@ -1088,11 +1086,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() ||
@@ -1109,11 +1103,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 *DGV) {
// 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()));
OpenPOWER on IntegriCloud