[llvm] r223512 - Simplify the loop linking function bodies. NFC.

Rafael Espindola rafael.espindola at gmail.com
Fri Dec 5 13:04:37 PST 2014


Author: rafael
Date: Fri Dec  5 15:04:36 2014
New Revision: 223512

URL: http://llvm.org/viewvc/llvm-project?rev=223512&view=rev
Log:
Simplify the loop linking function bodies. NFC.

Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=223512&r1=223511&r2=223512&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri Dec  5 15:04:36 2014
@@ -1514,48 +1514,32 @@ bool ModuleLinker::run() {
   linkGlobalInits();
 
   // Process vector of lazily linked in functions.
-  bool LinkedInAnyFunctions;
-  do {
-    LinkedInAnyFunctions = false;
-
-    for(std::vector<Function*>::iterator I = LazilyLinkFunctions.begin(),
-        E = LazilyLinkFunctions.end(); I != E; ++I) {
-      Function *SF = *I;
-      if (!SF)
-        continue;
-
-      Function *DF = cast<Function>(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;
+  while (!LazilyLinkFunctions.empty()) {
+    Function *SF = LazilyLinkFunctions.back();
+    LazilyLinkFunctions.pop_back();
+
+    if (!SF)
+      continue;
+
+    Function *DF = cast<Function>(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;
 }





More information about the llvm-commits mailing list