From f117c8ae032d3b2c8026c52bacf8deb88fe6946a Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 5 Dec 2014 21:04:36 +0000 Subject: [PATCH] Simplify the loop linking function bodies. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223512 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 62 ++++++++++++++------------------------ 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 1d4dae4c479..c7cf9f69003 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -1514,48 +1514,32 @@ bool ModuleLinker::run() { linkGlobalInits(); // Process vector of lazily linked in functions. - bool LinkedInAnyFunctions; - do { - LinkedInAnyFunctions = false; + while (!LazilyLinkFunctions.empty()) { + Function *SF = LazilyLinkFunctions.back(); + LazilyLinkFunctions.pop_back(); - for(std::vector::iterator I = LazilyLinkFunctions.begin(), - E = LazilyLinkFunctions.end(); I != E; ++I) { - Function *SF = *I; - if (!SF) - continue; + if (!SF) + continue; - Function *DF = cast(ValueMap[SF]); - if (SF->hasPrefixData()) { - // Link in the prefix data. - DF->setPrefixData(MapValue(SF->getPrefixData(), - ValueMap, - RF_None, - &TypeMap, - &ValMaterializer)); - } - - // Materialize if needed. - if (std::error_code EC = SF->materialize()) - return emitError(EC.message()); - - // Skip if no body (function is external). - if (SF->isDeclaration()) - continue; - - // Erase from vector *before* the function body is linked - linkFunctionBody could - // invalidate I. - LazilyLinkFunctions.erase(I); - - // Link in function body. - linkFunctionBody(DF, SF); - SF->Dematerialize(); - - // Set flag to indicate we may have more functions to lazily link in - // since we linked in a function. - LinkedInAnyFunctions = true; - break; + Function *DF = cast(ValueMap[SF]); + if (SF->hasPrefixData()) { + // Link in the prefix data. + DF->setPrefixData(MapValue(SF->getPrefixData(), ValueMap, RF_None, + &TypeMap, &ValMaterializer)); } - } while (LinkedInAnyFunctions); + + // Materialize if needed. + if (std::error_code EC = SF->materialize()) + return emitError(EC.message()); + + // Skip if no body (function is external). + if (SF->isDeclaration()) + continue; + + // Link in function body. + linkFunctionBody(DF, SF); + SF->Dematerialize(); + } return false; }