summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTeresa Johnson <tejohnson@google.com>2016-05-23 22:54:06 +0000
committerTeresa Johnson <tejohnson@google.com>2016-05-23 22:54:06 +0000
commitad092ca1c9664766f457624b639667938d06353d (patch)
tree1002ddf78d2cdf52a04f723ee4cbf669c5abd04a /include
parent7e9fa84c679d1730d985a15d5157ab558da15587 (diff)
[ThinLTO] Refactor module loader handling into new LTO file (NFC)
Moved the ModuleLoader and supporting helper loadModuleFromBuffer out of ThinLTOCodeGenerator and into new LTO.h/LTO.cpp files. This is in preparation for a patch that will utilize these in the gold-plugin. Note that there are some other pending patches (D20268 and D20290) that also plan to refactor common interfaces and functionality into this same pair of new files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270509 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/LTO/LTO.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/include/llvm/LTO/LTO.h b/include/llvm/LTO/LTO.h
new file mode 100644
index 00000000000..34c20f2074d
--- /dev/null
+++ b/include/llvm/LTO/LTO.h
@@ -0,0 +1,52 @@
+//===-LTO.h - LLVM Link Time Optimizer ------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares functions and classes used to support LTO. It is intended
+// to be used both by LTO classes as well as by clients (gold-plugin) that
+// don't utilize the LTO code generator interfaces.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LTO_LTO_H
+#define LLVM_LTO_LTO_H
+
+#include "llvm/ADT/StringMap.h"
+
+namespace llvm {
+
+class LLVMContext;
+class MemoryBufferRef;
+class Module;
+
+/// Helper to load a module from bitcode.
+std::unique_ptr<Module> loadModuleFromBuffer(const MemoryBufferRef &Buffer,
+ LLVMContext &Context, bool Lazy);
+
+/// Provide a "loader" for the FunctionImporter to access function from other
+/// modules.
+class ModuleLoader {
+ /// The context that will be used for importing.
+ LLVMContext &Context;
+
+ /// Map from Module identifier to MemoryBuffer. Used by clients like the
+ /// FunctionImported to request loading a Module.
+ StringMap<MemoryBufferRef> &ModuleMap;
+
+public:
+ ModuleLoader(LLVMContext &Context, StringMap<MemoryBufferRef> &ModuleMap)
+ : Context(Context), ModuleMap(ModuleMap) {}
+
+ /// Load a module on demand.
+ std::unique_ptr<Module> operator()(StringRef Identifier) {
+ return loadModuleFromBuffer(ModuleMap[Identifier], Context, /*Lazy*/ true);
+ }
+};
+}
+
+#endif