LLVM  6.0.0svn
FunctionImport.h
Go to the documentation of this file.
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_TRANSFORMS_IPO_FUNCTIONIMPORT_H
11 #define LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
12 
13 #include "llvm/ADT/DenseSet.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/IR/GlobalValue.h"
18 #include "llvm/IR/PassManager.h"
19 #include "llvm/Support/Error.h"
20 #include <functional>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <system_error>
25 #include <unordered_set>
26 #include <utility>
27 
28 namespace llvm {
29 
30 class Module;
31 
32 /// The function importer is automatically importing function from other modules
33 /// based on the provided summary informations.
35 public:
36  /// Set of functions to import from a source module. Each entry is a map
37  /// containing all the functions to import for a source module.
38  /// The keys is the GUID identifying a function to import, and the value
39  /// is the threshold applied when deciding to import it.
40  using FunctionsToImportTy = std::map<GlobalValue::GUID, unsigned>;
41 
42  /// The map contains an entry for every module to import from, the key being
43  /// the module identifier to pass to the ModuleLoader. The value is the set of
44  /// functions to import.
46 
47  /// The set contains an entry for every global value the module exports.
48  using ExportSetTy = std::unordered_set<GlobalValue::GUID>;
49 
50  /// A function of this type is used to load modules referenced by the index.
51  using ModuleLoaderTy =
52  std::function<Expected<std::unique_ptr<Module>>(StringRef Identifier)>;
53 
54  /// Create a Function Importer.
56  : Index(Index), ModuleLoader(std::move(ModuleLoader)) {}
57 
58  /// Import functions in Module \p M based on the supplied import list.
59  Expected<bool> importFunctions(Module &M, const ImportMapTy &ImportList);
60 
61 private:
62  /// The summaries index used to trigger importing.
63  const ModuleSummaryIndex &Index;
64 
65  /// Factory function to load a Module for a given identifier
66  ModuleLoaderTy ModuleLoader;
67 };
68 
69 /// The function importing pass
70 class FunctionImportPass : public PassInfoMixin<FunctionImportPass> {
71 public:
73 };
74 
75 /// Compute all the imports and exports for every module in the Index.
76 ///
77 /// \p ModuleToDefinedGVSummaries contains for each Module a map
78 /// (GUID -> Summary) for every global defined in the module.
79 ///
80 /// \p ImportLists will be populated with an entry for every Module we are
81 /// importing into. This entry is itself a map that can be passed to
82 /// FunctionImporter::importFunctions() above (see description there).
83 ///
84 /// \p ExportLists contains for each Module the set of globals (GUID) that will
85 /// be imported by another module, or referenced by such a function. I.e. this
86 /// is the set of globals that need to be promoted/renamed appropriately.
88  const ModuleSummaryIndex &Index,
89  const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
92 
93 /// Compute all the imports for the given module using the Index.
94 ///
95 /// \p ImportList will be populated with a map that can be passed to
96 /// FunctionImporter::importFunctions() above (see description there).
98  StringRef ModulePath, const ModuleSummaryIndex &Index,
99  FunctionImporter::ImportMapTy &ImportList);
100 
101 /// Compute all the symbols that are "dead": i.e these that can't be reached
102 /// in the graph from any of the given symbols listed in
103 /// \p GUIDPreservedSymbols.
104 void computeDeadSymbols(
105  ModuleSummaryIndex &Index,
106  const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols);
107 
108 /// Compute the set of summaries needed for a ThinLTO backend compilation of
109 /// \p ModulePath.
110 //
111 /// This includes summaries from that module (in case any global summary based
112 /// optimizations were recorded) and from any definitions in other modules that
113 /// should be imported.
114 //
115 /// \p ModuleToSummariesForIndex will be populated with the needed summaries
116 /// from each required module path. Use a std::map instead of StringMap to get
117 /// stable order for bitcode emission.
119  StringRef ModulePath,
120  const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
121  const FunctionImporter::ImportMapTy &ImportList,
122  std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);
123 
124 /// Emit into \p OutputFilename the files module \p ModulePath will import from.
125 std::error_code
127  const FunctionImporter::ImportMapTy &ModuleImports);
128 
129 /// Resolve WeakForLinker values in \p TheModule based on the information
130 /// recorded in the summaries during global summary-based analysis.
132  const GVSummaryMapTy &DefinedGlobals);
133 
134 /// Internalize \p TheModule based on the information recorded in the summaries
135 /// during global summary-based analysis.
136 void thinLTOInternalizeModule(Module &TheModule,
137  const GVSummaryMapTy &DefinedGlobals);
138 
139 } // end namespace llvm
140 
141 #endif // LLVM_TRANSFORMS_IPO_FUNCTIONIMPORT_H
void computeDeadSymbols(ModuleSummaryIndex &Index, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols)
Compute all the symbols that are "dead": i.e these that can&#39;t be reached in the graph from any of the...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
Implements a dense probed hash-table based set.
Definition: DenseSet.h:221
Definition: BitVector.h:920
FunctionImporter(const ModuleSummaryIndex &Index, ModuleLoaderTy ModuleLoader)
Create a Function Importer.
std::unordered_set< GlobalValue::GUID > ExportSetTy
The set contains an entry for every global value the module exports.
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
static cl::opt< std::string > OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"), cl::init("-"))
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:365
Class to hold module path string table and global value map, and encapsulate methods for operating on...
The function importing pass.
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:153
void gatherImportedSummariesForModule(StringRef ModulePath, const StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, const FunctionImporter::ImportMapTy &ImportList, std::map< std::string, GVSummaryMapTy > &ModuleToSummariesForIndex)
Compute the set of summaries needed for a ThinLTO backend compilation of ModulePath.
std::function< Expected< std::unique_ptr< Module > >(StringRef Identifier)> ModuleLoaderTy
A function of this type is used to load modules referenced by the index.
std::error_code EmitImportsFiles(StringRef ModulePath, StringRef OutputFilename, const FunctionImporter::ImportMapTy &ModuleImports)
Emit into OutputFilename the files module ModulePath will import from.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:224
Expected< bool > importFunctions(Module &M, const ImportMapTy &ImportList)
Import functions in Module M based on the supplied import list.
void ComputeCrossModuleImport(const ModuleSummaryIndex &Index, const StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries, StringMap< FunctionImporter::ImportMapTy > &ImportLists, StringMap< FunctionImporter::ExportSetTy > &ExportLists)
Compute all the imports and exports for every module in the Index.
void thinLTOInternalizeModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Internalize TheModule based on the information recorded in the summaries during global summary-based ...
void thinLTOResolveWeakForLinkerModule(Module &TheModule, const GVSummaryMapTy &DefinedGlobals)
Resolve WeakForLinker values in TheModule based on the information recorded in the summaries during g...
void ComputeCrossModuleImportForModule(StringRef ModulePath, const ModuleSummaryIndex &Index, FunctionImporter::ImportMapTy &ImportList)
Compute all the imports for the given module using the Index.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
The function importer is automatically importing function from other modules based on the provided su...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
std::map< GlobalValue::GUID, unsigned > FunctionsToImportTy
Set of functions to import from a source module.
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.