- // Link in the function bodies that are defined in the source module into
- // DstM.
- for (Function &SF : *SrcM) {
- // Skip if no body (function is external).
- if (SF.isDeclaration())
- continue;
-
- // Skip if not linking from source.
- if (DoNotLinkFromSource.count(&SF))
- continue;
-
- // When importing, only materialize the function requested for import.
- if (isPerformingImport() && &SF != ImportFunction)
- continue;
-
- if (linkGlobalValueBody(SF))
- return true;
- }
-
- // Resolve all uses of aliases with aliasees.
- for (GlobalAlias &Src : SrcM->aliases()) {
- if (DoNotLinkFromSource.count(&Src))
- continue;
- linkGlobalValueBody(Src);
- }
-
- // Update the initializers in the DstM module now that all globals that may
- // be referenced are in DstM.
- for (GlobalVariable &Src : SrcM->globals()) {
- // Only process initialized GV's or ones not already in dest.
- if (!Src.hasInitializer() || DoNotLinkFromSource.count(&Src))
- continue;
- linkGlobalValueBody(Src);
- }
-
- // Process vector of lazily linked in functions.
- while (!LazilyLinkGlobalValues.empty()) {
- GlobalValue *SGV = LazilyLinkGlobalValues.back();
- LazilyLinkGlobalValues.pop_back();
- if (isPerformingImport() && !doImportAsDefinition(SGV))
- continue;
-
- // Skip declarations that ValueMaterializer may have created in
- // case we link in only some of SrcM.
- if (shouldLinkOnlyNeeded() && SGV->isDeclaration())
- continue;
-
- assert(!SGV->isDeclaration() && "users should not pass down decls");
- if (linkGlobalValueBody(*SGV))
- return true;
- }