From: Rafael Espindola Date: Fri, 5 Dec 2014 17:53:15 +0000 (+0000) Subject: Refactor duplicated code. NFC. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26c2951117afe06a05969beecbdb0d4f7f54116e;p=platform%2Fupstream%2Fllvm.git Refactor duplicated code. NFC. llvm-svn: 223486 --- diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp index 4aa0b88..18fab19 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(SGV)) - NewGV = linkGlobalVariableProto(SGVar, DGV, LinkFromSrc); - else if (auto *SF = dyn_cast(SGV)) - NewGV = linkFunctionProto(SF, DGV, LinkFromSrc); - else - NewGV = linkGlobalAliasProto(cast(SGV), DGV, LinkFromSrc); + if (!LinkFromSrc) { + NewGV = DGV; + } else { + if (auto *SGVar = dyn_cast(SGV)) + NewGV = linkGlobalVariableProto(SGVar, DGV); + else if (auto *SF = dyn_cast(SGV)) + NewGV = linkFunctionProto(SF, DGV); + else + NewGV = linkGlobalAliasProto(cast(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(TypeMap.get(SGA->getType()));