summaryrefslogtreecommitdiff
path: root/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ExecutionEngine/Orc/IRCompileLayer.h')
-rw-r--r--include/llvm/ExecutionEngine/Orc/IRCompileLayer.h129
1 files changed, 43 insertions, 86 deletions
diff --git a/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h b/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
index f81d054440fc9..99ccd4d221a5e 100644
--- a/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
+++ b/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h
@@ -1,4 +1,4 @@
-//===------ IRCompileLayer.h -- Eagerly compile IR for JIT ------*- C++ -*-===//
+//===- IRCompileLayer.h -- Eagerly compile IR for JIT -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -14,79 +14,54 @@
#ifndef LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
#define LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
-#include "llvm/ExecutionEngine/ObjectCache.h"
-#include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/Error.h"
#include <memory>
+#include <string>
namespace llvm {
+
+class Module;
+
namespace orc {
/// @brief Eager IR compiling layer.
///
-/// This layer accepts sets of LLVM IR Modules (via addModuleSet). It
-/// immediately compiles each IR module to an object file (each IR Module is
-/// compiled separately). The resulting set of object files is then added to
-/// the layer below, which must implement the object layer concept.
-template <typename BaseLayerT> class IRCompileLayer {
+/// This layer immediately compiles each IR module added via addModule to an
+/// object file and adds this module file to the layer below, which must
+/// implement the object layer concept.
+template <typename BaseLayerT, typename CompileFtor>
+class IRCompileLayer {
public:
- typedef std::function<object::OwningBinary<object::ObjectFile>(Module &)>
- CompileFtor;
-
-private:
- typedef typename BaseLayerT::ObjSetHandleT ObjSetHandleT;
-public:
- /// @brief Handle to a set of compiled modules.
- typedef ObjSetHandleT ModuleSetHandleT;
+ /// @brief Handle to a compiled module.
+ using ModuleHandleT = typename BaseLayerT::ObjHandleT;
/// @brief Construct an IRCompileLayer with the given BaseLayer, which must
/// implement the ObjectLayer concept.
IRCompileLayer(BaseLayerT &BaseLayer, CompileFtor Compile)
- : BaseLayer(BaseLayer), Compile(std::move(Compile)), ObjCache(nullptr) {}
+ : BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
- /// @brief Set an ObjectCache to query before compiling.
- void setObjectCache(ObjectCache *NewCache) { ObjCache = NewCache; }
+ /// @brief Get a reference to the compiler functor.
+ CompileFtor& getCompiler() { return Compile; }
- /// @brief Compile each module in the given module set, then add the resulting
- /// set of objects to the base layer along with the memory manager and
- /// symbol resolver.
+ /// @brief Compile the module, and add the resulting object to the base layer
+ /// along with the given memory manager and symbol resolver.
///
- /// @return A handle for the added modules.
- template <typename ModuleSetT, typename MemoryManagerPtrT,
- typename SymbolResolverPtrT>
- ModuleSetHandleT addModuleSet(ModuleSetT Ms,
- MemoryManagerPtrT MemMgr,
- SymbolResolverPtrT Resolver) {
- std::vector<std::unique_ptr<object::OwningBinary<object::ObjectFile>>>
- Objects;
-
- for (const auto &M : Ms) {
- auto Object =
- llvm::make_unique<object::OwningBinary<object::ObjectFile>>();
-
- if (ObjCache)
- *Object = tryToLoadFromObjectCache(*M);
-
- if (!Object->getBinary()) {
- *Object = Compile(*M);
- if (ObjCache)
- ObjCache->notifyObjectCompiled(&*M,
- Object->getBinary()->getMemoryBufferRef());
- }
-
- Objects.push_back(std::move(Object));
- }
-
- ModuleSetHandleT H =
- BaseLayer.addObjectSet(std::move(Objects), std::move(MemMgr),
- std::move(Resolver));
-
- return H;
+ /// @return A handle for the added module.
+ template <typename MemoryManagerPtrT, typename SymbolResolverPtrT>
+ ModuleHandleT addModule(std::shared_ptr<Module> M,
+ MemoryManagerPtrT MemMgr,
+ SymbolResolverPtrT Resolver) {
+ using CompileResult = decltype(Compile(*M));
+ auto Obj = std::make_shared<CompileResult>(Compile(*M));
+ return BaseLayer.addObject(std::move(Obj), std::move(MemMgr),
+ std::move(Resolver));
}
- /// @brief Remove the module set associated with the handle H.
- void removeModuleSet(ModuleSetHandleT H) { BaseLayer.removeObjectSet(H); }
+ /// @brief Remove the module associated with the handle H.
+ void removeModule(ModuleHandleT H) { BaseLayer.removeObject(H); }
/// @brief Search for the given named symbol.
/// @param Name The name of the symbol to search for.
@@ -96,51 +71,33 @@ public:
return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
}
- /// @brief Get the address of the given symbol in the context of the set of
- /// compiled modules represented by the handle H. This call is
- /// forwarded to the base layer's implementation.
- /// @param H The handle for the module set to search in.
+ /// @brief Get the address of the given symbol in compiled module represented
+ /// by the handle H. This call is forwarded to the base layer's
+ /// implementation.
+ /// @param H The handle for the module to search in.
/// @param Name The name of the symbol to search for.
/// @param ExportedSymbolsOnly If true, search only for exported symbols.
/// @return A handle for the given named symbol, if it is found in the
- /// given module set.
- JITSymbol findSymbolIn(ModuleSetHandleT H, const std::string &Name,
+ /// given module.
+ JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
bool ExportedSymbolsOnly) {
return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
}
- /// @brief Immediately emit and finalize the moduleOB set represented by the
- /// given handle.
- /// @param H Handle for module set to emit/finalize.
- void emitAndFinalize(ModuleSetHandleT H) {
+ /// @brief Immediately emit and finalize the module represented by the given
+ /// handle.
+ /// @param H Handle for module to emit/finalize.
+ void emitAndFinalize(ModuleHandleT H) {
BaseLayer.emitAndFinalize(H);
}
private:
- object::OwningBinary<object::ObjectFile>
- tryToLoadFromObjectCache(const Module &M) {
- std::unique_ptr<MemoryBuffer> ObjBuffer = ObjCache->getObject(&M);
- if (!ObjBuffer)
- return object::OwningBinary<object::ObjectFile>();
-
- Expected<std::unique_ptr<object::ObjectFile>> Obj =
- object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef());
- if (!Obj) {
- // TODO: Actually report errors helpfully.
- consumeError(Obj.takeError());
- return object::OwningBinary<object::ObjectFile>();
- }
-
- return object::OwningBinary<object::ObjectFile>(std::move(*Obj),
- std::move(ObjBuffer));
- }
-
BaseLayerT &BaseLayer;
CompileFtor Compile;
- ObjectCache *ObjCache;
};
-} // End namespace orc.
-} // End namespace llvm.
+} // end namespace orc
+
+} // end namespace llvm
#endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILINGLAYER_H