0315c72811c168d5f91e0a51e258154d6563ef27
[oota-llvm.git] / include / llvm / Transforms / IPO / FunctionImport.h
1 //===- llvm/Transforms/IPO/FunctionImport.h - ThinLTO importing -*- C++ -*-===//
2 //
3 //                      The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_FUNCTIONIMPORT_H
11 #define LLVM_FUNCTIONIMPORT_H
12
13 #include "llvm/IR/DiagnosticInfo.h"
14 #include "llvm/ADT/StringMap.h"
15
16 namespace llvm {
17 class LLVMContext;
18 class Module;
19 class FunctionInfoIndex;
20
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.
25   LLVMContext &Context;
26
27   /// Cache of lazily loaded module for import.
28   StringMap<std::unique_ptr<Module>> ModuleMap;
29
30 public:
31   /// Create the loader, Module will be initialized in \p Context.
32   ModuleLazyLoaderCache(LLVMContext &Context) : Context(Context) {}
33
34   /// Retrieve a Module from the cache or lazily load it on demand.
35   Module &operator()(StringRef FileName);
36 };
37
38 /// The function importer is automatically importing function from other modules
39 /// based on the provided summary informations.
40 class FunctionImporter {
41
42   /// The summaries index used to trigger importing.
43   const FunctionInfoIndex &Index;
44
45   /// Diagnostic will be sent to this handler.
46   DiagnosticHandlerFunction DiagnosticHandler;
47
48   /// Retrieve a Module from the cache or lazily load it on demand.
49   std::function<Module &(StringRef FileName)> getLazyModule;
50
51 public:
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) {}
58
59   /// Import functions in Module \p M based on the summary informations.
60   bool importFunctions(Module &M);
61 };
62 }
63
64 #endif // LLVM_FUNCTIONIMPORT_H