1 //===- llvm/Transforms/IPO/FunctionImport.h - ThinLTO importing -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_FUNCTIONIMPORT_H
11 #define LLVM_FUNCTIONIMPORT_H
13 #include "llvm/IR/DiagnosticInfo.h"
14 #include "llvm/ADT/StringMap.h"
19 class FunctionInfoIndex;
21 /// Helper to load on demand a Module from file and cache it for subsequent
22 /// queries. It can be used with the FunctionImporter.
23 class ModuleLazyLoaderCache {
24 /// The context that will be used for importing.
27 /// Cache of lazily loaded module for import.
28 StringMap<std::unique_ptr<Module>> ModuleMap;
31 /// Create the loader, Module will be initialized in \p Context.
32 ModuleLazyLoaderCache(LLVMContext &Context) : Context(Context) {}
34 /// Retrieve a Module from the cache or lazily load it on demand.
35 Module &operator()(StringRef FileName);
38 /// The function importer is automatically importing function from other modules
39 /// based on the provided summary informations.
40 class FunctionImporter {
42 /// The summaries index used to trigger importing.
43 const FunctionInfoIndex &Index;
45 /// Diagnostic will be sent to this handler.
46 DiagnosticHandlerFunction DiagnosticHandler;
48 /// Retrieve a Module from the cache or lazily load it on demand.
49 std::function<Module &(StringRef FileName)> getLazyModule;
52 /// Create a Function Importer.
53 FunctionImporter(const FunctionInfoIndex &Index,
54 DiagnosticHandlerFunction DiagnosticHandler,
55 std::function<Module &(StringRef FileName)> ModuleLoader)
56 : Index(Index), DiagnosticHandler(DiagnosticHandler),
57 getLazyModule(ModuleLoader) {}
59 /// Import functions in Module \p M based on the summary informations.
60 bool importFunctions(Module &M);
64 #endif // LLVM_FUNCTIONIMPORT_H