[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
//===------ IRCompileLayer.h -- Eagerly compile IR for JIT ------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Contains the definition for a basic, eagerly compiling layer of the JIT.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
|
|
|
|
#define LLVM_EXECUTIONENGINE_ORC_IRCOMPILELAYER_H
|
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
#include "JITSymbol.h"
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
#include "llvm/ExecutionEngine/ObjectCache.h"
|
2015-02-06 22:48:43 +00:00
|
|
|
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
|
2015-02-06 19:34:40 +00:00
|
|
|
#include "llvm/Object/ObjectFile.h"
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// @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 {
|
|
|
|
public:
|
|
|
|
typedef std::function<object::OwningBinary<object::ObjectFile>(Module &)>
|
|
|
|
CompileFtor;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef typename BaseLayerT::ObjSetHandleT ObjSetHandleT;
|
|
|
|
|
|
|
|
typedef std::vector<std::unique_ptr<object::ObjectFile>> OwningObjectVec;
|
|
|
|
typedef std::vector<std::unique_ptr<MemoryBuffer>> OwningBufferVec;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// @brief Handle to a set of compiled modules.
|
|
|
|
typedef ObjSetHandleT ModuleSetHandleT;
|
|
|
|
|
|
|
|
/// @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) {}
|
|
|
|
|
|
|
|
/// @brief Set an ObjectCache to query before compiling.
|
|
|
|
void setObjectCache(ObjectCache *NewCache) { ObjCache = NewCache; }
|
|
|
|
|
|
|
|
/// @brief Compile each module in the given module set, then then add the
|
|
|
|
/// resulting set of objects to the base layer, along with the memory
|
|
|
|
// manager MM.
|
|
|
|
///
|
|
|
|
/// @return A handle for the added modules.
|
|
|
|
template <typename ModuleSetT>
|
|
|
|
ModuleSetHandleT addModuleSet(ModuleSetT Ms,
|
|
|
|
std::unique_ptr<RTDyldMemoryManager> MM) {
|
|
|
|
OwningObjectVec Objects;
|
|
|
|
OwningBufferVec Buffers;
|
|
|
|
|
|
|
|
for (const auto &M : Ms) {
|
|
|
|
std::unique_ptr<object::ObjectFile> Object;
|
|
|
|
std::unique_ptr<MemoryBuffer> Buffer;
|
|
|
|
|
|
|
|
if (ObjCache)
|
|
|
|
std::tie(Object, Buffer) = tryToLoadFromObjectCache(*M).takeBinary();
|
|
|
|
|
|
|
|
if (!Object) {
|
|
|
|
std::tie(Object, Buffer) = Compile(*M).takeBinary();
|
|
|
|
if (ObjCache)
|
|
|
|
ObjCache->notifyObjectCompiled(&*M, Buffer->getMemBufferRef());
|
|
|
|
}
|
|
|
|
|
|
|
|
Objects.push_back(std::move(Object));
|
|
|
|
Buffers.push_back(std::move(Buffer));
|
|
|
|
}
|
|
|
|
|
2015-02-02 04:32:17 +00:00
|
|
|
ModuleSetHandleT H =
|
|
|
|
BaseLayer.addObjectSet(Objects, std::move(MM));
|
|
|
|
|
|
|
|
BaseLayer.takeOwnershipOfBuffers(H, std::move(Buffers));
|
|
|
|
|
|
|
|
return H;
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Remove the module set associated with the handle H.
|
|
|
|
void removeModuleSet(ModuleSetHandleT H) { BaseLayer.removeObjectSet(H); }
|
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
/// @brief Search for the given named symbol.
|
|
|
|
/// @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 exists.
|
|
|
|
JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
|
|
|
|
return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// @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.
|
2015-02-09 01:20:51 +00:00
|
|
|
/// @param H The handle for the module set 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,
|
|
|
|
bool ExportedSymbolsOnly) {
|
|
|
|
return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
object::OwningBinary<object::ObjectFile>
|
|
|
|
tryToLoadFromObjectCache(const Module &M) {
|
|
|
|
std::unique_ptr<MemoryBuffer> ObjBuffer = ObjCache->getObject(&M);
|
|
|
|
if (!ObjBuffer)
|
2015-01-25 11:41:49 +00:00
|
|
|
return object::OwningBinary<object::ObjectFile>();
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
|
|
|
|
ErrorOr<std::unique_ptr<object::ObjectFile>> Obj =
|
|
|
|
object::ObjectFile::createObjectFile(ObjBuffer->getMemBufferRef());
|
|
|
|
if (!Obj)
|
2015-01-25 11:41:49 +00:00
|
|
|
return object::OwningBinary<object::ObjectFile>();
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
|
2015-01-25 11:41:56 +00:00
|
|
|
return object::OwningBinary<object::ObjectFile>(std::move(*Obj),
|
|
|
|
std::move(ObjBuffer));
|
[Orc] New JIT APIs.
This patch adds a new set of JIT APIs to LLVM. The aim of these new APIs is to
cleanly support a wider range of JIT use cases in LLVM, and encourage the
development and contribution of re-usable infrastructure for LLVM JIT use-cases.
These APIs are intended to live alongside the MCJIT APIs, and should not affect
existing clients.
Included in this patch:
1) New headers in include/llvm/ExecutionEngine/Orc that provide a set of
components for building JIT infrastructure.
Implementation code for these headers lives in lib/ExecutionEngine/Orc.
2) A prototype re-implementation of MCJIT (OrcMCJITReplacement) built out of the
new components.
3) Minor changes to RTDyldMemoryManager needed to support the new components.
These changes should not impact existing clients.
4) A new flag for lli, -use-orcmcjit, which will cause lli to use the
OrcMCJITReplacement class as its underlying execution engine, rather than
MCJIT itself.
Tests to follow shortly.
Special thanks to Michael Ilseman, Pete Cooper, David Blaikie, Eric Christopher,
Justin Bogner, and Jim Grosbach for extensive feedback and discussion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226940 91177308-0d34-0410-b5e6-96231b3b80d8
2015-01-23 21:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BaseLayerT &BaseLayer;
|
|
|
|
CompileFtor Compile;
|
|
|
|
ObjectCache *ObjCache;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // LLVM_EXECUTIONENGINE_ORC_IRCOMPILINGLAYER_H
|