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 | f7d58f12fa2377090dd844e52662e5a942606d0f (patch) | |
tree | 92a9c64b7289d4ba1c2e911b7b9c664777ea525c /include | |
parent | 327823045115e7df540f8ed7f1871c432305066f (diff) |
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>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254479 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Transforms/IPO/FunctionImport.h | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/include/llvm/Transforms/IPO/FunctionImport.h b/include/llvm/Transforms/IPO/FunctionImport.h index f06a1902175..0315c72811c 100644 --- a/include/llvm/Transforms/IPO/FunctionImport.h +++ b/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); |