Add a FunctionImporter helper to perform summary-based cross-module function importing
[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 /// The function importer is automatically importing function from other modules
22 /// based on the provided summary informations.
23 class FunctionImporter {
24
25   /// Cache of lazily loaded module for import.
26   StringMap<std::unique_ptr<Module>> ModuleMap;
27
28   /// The context that will be used for importing.
29   LLVMContext &Context;
30
31   /// The summaries index used to trigger importing.
32   const FunctionInfoIndex &Index;
33
34   /// Diagnostic will be sent to this handler.
35   DiagnosticHandlerFunction DiagnosticHandler;
36
37   /// Retrieve a Module from the cache or lazily load it on demand.
38   Module &getOrLoadModule(StringRef FileName);
39
40 public:
41   /// Create a Function Importer.
42   FunctionImporter(LLVMContext &Context, const FunctionInfoIndex &Index,
43                    DiagnosticHandlerFunction DiagnosticHandler)
44       : Context(Context), Index(Index), DiagnosticHandler(DiagnosticHandler) {}
45
46   /// Import functions in Module \p M based on the summary informations.
47   bool importFunctions(Module &M);
48 };
49 }
50
51 #endif // LLVM_FUNCTIONIMPORT_H