• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-LTO.h - LLVM Link Time Optimizer ------------------------------------===//
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 // This file declares functions and classes used to support LTO. It is intended
11 // to be used both by LTO classes as well as by clients (gold-plugin) that
12 // don't utilize the LTO code generator interfaces.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LTO_LTO_H
17 #define LLVM_LTO_LTO_H
18 
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/IR/ModuleSummaryIndex.h"
21 
22 namespace llvm {
23 
24 class LLVMContext;
25 class MemoryBufferRef;
26 class Module;
27 
28 /// Helper to load a module from bitcode.
29 std::unique_ptr<Module> loadModuleFromBuffer(const MemoryBufferRef &Buffer,
30                                              LLVMContext &Context, bool Lazy);
31 
32 /// Provide a "loader" for the FunctionImporter to access function from other
33 /// modules.
34 class ModuleLoader {
35   /// The context that will be used for importing.
36   LLVMContext &Context;
37 
38   /// Map from Module identifier to MemoryBuffer. Used by clients like the
39   /// FunctionImported to request loading a Module.
40   StringMap<MemoryBufferRef> &ModuleMap;
41 
42 public:
ModuleLoader(LLVMContext & Context,StringMap<MemoryBufferRef> & ModuleMap)43   ModuleLoader(LLVMContext &Context, StringMap<MemoryBufferRef> &ModuleMap)
44       : Context(Context), ModuleMap(ModuleMap) {}
45 
46   /// Load a module on demand.
operator()47   std::unique_ptr<Module> operator()(StringRef Identifier) {
48     return loadModuleFromBuffer(ModuleMap[Identifier], Context, /*Lazy*/ true);
49   }
50 };
51 
52 
53 /// Resolve Weak and LinkOnce values in the \p Index. Linkage changes recorded
54 /// in the index and the ThinLTO backends must apply the changes to the Module
55 /// via thinLTOResolveWeakForLinkerModule.
56 ///
57 /// This is done for correctness (if value exported, ensure we always
58 /// emit a copy), and compile-time optimization (allow drop of duplicates).
59 void thinLTOResolveWeakForLinkerInIndex(
60     ModuleSummaryIndex &Index,
61     function_ref<bool(GlobalValue::GUID, const GlobalValueSummary *)>
62         isPrevailing,
63     function_ref<void(StringRef, GlobalValue::GUID, GlobalValue::LinkageTypes)>
64         recordNewLinkage);
65 
66 /// Update the linkages in the given \p Index to mark exported values
67 /// as external and non-exported values as internal. The ThinLTO backends
68 /// must apply the changes to the Module via thinLTOInternalizeModule.
69 void thinLTOInternalizeAndPromoteInIndex(
70     ModuleSummaryIndex &Index,
71     function_ref<bool(StringRef, GlobalValue::GUID)> isExported);
72 }
73 
74 #endif
75