diff options
| author | Mehdi Amini <mehdi.amini@apple.com> | 2015-12-02 02:00:29 +0000 |
|---|---|---|
| committer | Mehdi Amini <mehdi.amini@apple.com> | 2015-12-02 02:00:29 +0000 |
| commit | a11bdc8ef7034f3f5350d7942ff02c3c2702283f (patch) | |
| tree | 7d0a94b137b4089abbf6450b83445795a4b35422 /llvm | |
| parent | f1e91c8bf18e0d708b11d3154eb632e14403cadf (diff) | |
| download | bcm5719-llvm-a11bdc8ef7034f3f5350d7942ff02c3c2702283f.tar.gz bcm5719-llvm-a11bdc8ef7034f3f5350d7942ff02c3c2702283f.zip | |
Modify FunctionImport to take a callback to load modules
When linking static archive, there is no individual module files to
load. Instead they can be mmap'ed and could be initialized from a
buffer directly. The callback provide flexibility to override the
scheme for loading module from the summary.
Differential Revision: http://reviews.llvm.org/D15101
From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 254479
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/Transforms/IPO/FunctionImport.h | 31 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/FunctionImport.cpp | 11 |
2 files changed, 29 insertions, 13 deletions
diff --git a/llvm/include/llvm/Transforms/IPO/FunctionImport.h b/llvm/include/llvm/Transforms/IPO/FunctionImport.h index f06a1902175..0315c72811c 100644 --- a/llvm/include/llvm/Transforms/IPO/FunctionImport.h +++ b/llvm/include/llvm/Transforms/IPO/FunctionImport.h @@ -18,15 +18,26 @@ class LLVMContext; class Module; class FunctionInfoIndex; -/// The function importer is automatically importing function from other modules -/// based on the provided summary informations. -class FunctionImporter { +/// Helper to load on demand a Module from file and cache it for subsequent +/// queries. It can be used with the FunctionImporter. +class ModuleLazyLoaderCache { + /// The context that will be used for importing. + LLVMContext &Context; /// Cache of lazily loaded module for import. StringMap<std::unique_ptr<Module>> ModuleMap; - /// The context that will be used for importing. - LLVMContext &Context; +public: + /// Create the loader, Module will be initialized in \p Context. + ModuleLazyLoaderCache(LLVMContext &Context) : Context(Context) {} + + /// Retrieve a Module from the cache or lazily load it on demand. + Module &operator()(StringRef FileName); +}; + +/// The function importer is automatically importing function from other modules +/// based on the provided summary informations. +class FunctionImporter { /// The summaries index used to trigger importing. const FunctionInfoIndex &Index; @@ -35,13 +46,15 @@ class FunctionImporter { DiagnosticHandlerFunction DiagnosticHandler; /// Retrieve a Module from the cache or lazily load it on demand. - Module &getOrLoadModule(StringRef FileName); + std::function<Module &(StringRef FileName)> getLazyModule; public: /// Create a Function Importer. - FunctionImporter(LLVMContext &Context, const FunctionInfoIndex &Index, - DiagnosticHandlerFunction DiagnosticHandler) - : Context(Context), Index(Index), DiagnosticHandler(DiagnosticHandler) {} + FunctionImporter(const FunctionInfoIndex &Index, + DiagnosticHandlerFunction DiagnosticHandler, + std::function<Module &(StringRef FileName)> ModuleLoader) + : Index(Index), DiagnosticHandler(DiagnosticHandler), + getLazyModule(ModuleLoader) {} /// Import functions in Module \p M based on the summary informations. bool importFunctions(Module &M); diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index 444da3c55d2..92764c9e8c3 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -51,7 +51,7 @@ static std::unique_ptr<Module> loadFile(const std::string &FileName, } // 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); @@ -86,7 +86,6 @@ static void findExternalCalls(const Function &F, StringSet<> &CalledFunctions, // 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; @@ -142,7 +141,8 @@ bool FunctionImporter::importFunctions(Module &M) { << "\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); @@ -255,7 +255,10 @@ public: } // 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; |

