Index: include/llvm/Linker/Linker.h =================================================================== --- include/llvm/Linker/Linker.h +++ include/llvm/Linker/Linker.h @@ -83,7 +83,7 @@ /// Returns true on error. bool linkInModule(Module *Src, unsigned Flags = Flags::None, const FunctionInfoIndex *Index = nullptr, - Function *FuncToImport = nullptr); + DenseSet *FuncToImport = nullptr); /// \brief Set the composite to the passed-in module. void setModule(Module *Dst); Index: lib/Linker/LinkModules.cpp =================================================================== --- lib/Linker/LinkModules.cpp +++ lib/Linker/LinkModules.cpp @@ -423,7 +423,7 @@ /// Function to import from source module, all other functions are /// imported as declarations instead of definitions. - Function *ImportFunction; + DenseSet *ImportFunction; /// Set to true if the given FunctionInfoIndex contains any functions /// from this source module, in which case we must conservatively assume @@ -442,7 +442,7 @@ ModuleLinker(Module *dstM, Linker::IdentifiedStructTypeSet &Set, Module *srcM, DiagnosticHandlerFunction DiagnosticHandler, unsigned Flags, const FunctionInfoIndex *Index = nullptr, - Function *FuncToImport = nullptr) + DenseSet *FuncToImport = nullptr) : DstM(dstM), SrcM(srcM), TypeMap(Set), ValMaterializer(this), DiagnosticHandler(DiagnosticHandler), Flags(Flags), ImportIndex(Index), ImportFunction(FuncToImport), HasExportedFunctions(false), @@ -655,7 +655,7 @@ return true; // Only import the function requested for importing. auto *SF = dyn_cast(SGV); - if (SF && SF == ImportFunction) + if (SF && ImportFunction->count(SF)) return true; // Otherwise no. return false; @@ -1081,7 +1081,7 @@ if (isa(&Src)) { // For functions, LinkFromSrc iff this is the function requested // for importing. For variables, decide below normally. - LinkFromSrc = (&Src == ImportFunction); + LinkFromSrc = ImportFunction->count(&Src); return false; } @@ -2102,7 +2102,7 @@ bool Linker::linkInModule(Module *Src, unsigned Flags, const FunctionInfoIndex *Index, - Function *FuncToImport) { + DenseSet *FuncToImport) { ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src, DiagnosticHandler, Flags, Index, FuncToImport); bool RetCode = TheLinker.run(); Index: lib/Transforms/IPO/FunctionImport.cpp =================================================================== --- lib/Transforms/IPO/FunctionImport.cpp +++ lib/Transforms/IPO/FunctionImport.cpp @@ -185,8 +185,10 @@ continue; } - // Link in the specified function. - if (L.linkInModule(&Module, Linker::Flags::None, &Index, F)) + DenseSet FunctionsToImport; + FunctionsToImport.insert(F); + if (L.linkInModule(&Module, Linker::Flags::None, &Index, + &FunctionsToImport)) report_fatal_error("Function Import: link error"); // Process the newly imported function and add callees to the worklist. @@ -198,6 +200,7 @@ Changed = true; } + return Changed; } Index: tools/llvm-link/llvm-link.cpp =================================================================== --- tools/llvm-link/llvm-link.cpp +++ tools/llvm-link/llvm-link.cpp @@ -198,7 +198,10 @@ } // Link in the specified function. - if (L.linkInModule(M.get(), Linker::Flags::None, Index.get(), F)) + DenseSet FunctionToImport; + FunctionToImport.insert(F); + if (L.linkInModule(M.get(), Linker::Flags::None, Index.get(), + &FunctionToImport)) return false; } return true;