}
// Get a Module for \p FileName from the cache, or load it lazily.
-Module &FunctionImporter::getOrLoadModule(StringRef FileName) {
+Module &ModuleLazyLoaderCache::operator()(StringRef FileName) {
auto &Module = ModuleMap[FileName];
if (!Module)
Module = loadFile(FileName, Context);
// The current implementation imports every called functions that exists in the
// summaries index.
bool FunctionImporter::importFunctions(Module &M) {
- assert(&Context == &M.getContext());
bool Changed = false;
<< "\n");
// Get the module for the import (potentially from the cache).
- auto &Module = getOrLoadModule(FileName);
+ auto &Module = getLazyModule(FileName);
+ assert(&Module.getContext() == &M.getContext());
// The function that we will import!
GlobalValue *SGV = Module.getNamedValue(CalledFunctionName);
}
// Perform the import now.
- FunctionImporter Importer(M.getContext(), *Index, diagnosticHandler);
+ ModuleLazyLoaderCache Loader(M.getContext());
+ FunctionImporter Importer(*Index, diagnosticHandler,
+ [&](StringRef Name)
+ -> Module &{ return Loader(Name); });
return Importer.importFunctions(M);
return false;