[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
|
|
|
//===-- IndirectionUtils.h - Utilities for adding indirections --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Contains utilities for adding indirections and breaking up modules.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
|
|
|
|
#define LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
|
|
|
|
|
2015-02-09 01:20:51 +00:00
|
|
|
#include "JITSymbol.h"
|
2015-02-17 01:18:38 +00:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/IR/IRBuilder.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/IR/Mangler.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
namespace llvm {
|
2015-02-21 20:44:36 +00:00
|
|
|
namespace orc {
|
[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-02-17 01:18:38 +00:00
|
|
|
/// @brief Base class for JITLayer independent aspects of
|
|
|
|
/// JITCompileCallbackManager.
|
|
|
|
class JITCompileCallbackManagerBase {
|
[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
|
|
|
public:
|
|
|
|
|
2015-03-25 02:45:50 +00:00
|
|
|
typedef std::function<TargetAddress()> CompileFtor;
|
|
|
|
typedef std::function<void(TargetAddress)> UpdateFtor;
|
|
|
|
|
|
|
|
/// @brief Handle to a newly created compile callback. Can be used to get an
|
|
|
|
/// IR constant representing the address of the trampoline, and to set
|
|
|
|
/// the compile and update actions for the callback.
|
|
|
|
class CompileCallbackInfo {
|
|
|
|
public:
|
|
|
|
CompileCallbackInfo(Constant *Addr, CompileFtor &Compile,
|
|
|
|
UpdateFtor &Update)
|
|
|
|
: Addr(Addr), Compile(Compile), Update(Update) {}
|
|
|
|
|
|
|
|
Constant* getAddress() const { return Addr; }
|
|
|
|
void setCompileAction(CompileFtor Compile) {
|
|
|
|
this->Compile = std::move(Compile);
|
|
|
|
}
|
|
|
|
void setUpdateAction(UpdateFtor Update) {
|
|
|
|
this->Update = std::move(Update);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
Constant *Addr;
|
|
|
|
CompileFtor &Compile;
|
|
|
|
UpdateFtor &Update;
|
|
|
|
};
|
|
|
|
|
2015-02-17 01:18:38 +00:00
|
|
|
/// @brief Construct a JITCompileCallbackManagerBase.
|
|
|
|
/// @param ErrorHandlerAddress The address of an error handler in the target
|
|
|
|
/// process to be used if a compile callback fails.
|
|
|
|
/// @param NumTrampolinesPerBlock Number of trampolines to emit if there is no
|
|
|
|
/// available trampoline when getCompileCallback is
|
|
|
|
/// called.
|
|
|
|
JITCompileCallbackManagerBase(TargetAddress ErrorHandlerAddress,
|
|
|
|
unsigned NumTrampolinesPerBlock)
|
|
|
|
: ErrorHandlerAddress(ErrorHandlerAddress),
|
|
|
|
NumTrampolinesPerBlock(NumTrampolinesPerBlock) {}
|
|
|
|
|
2015-03-25 02:45:50 +00:00
|
|
|
virtual ~JITCompileCallbackManagerBase() {}
|
|
|
|
|
2015-02-17 01:18:38 +00:00
|
|
|
/// @brief Execute the callback for the given trampoline id. Called by the JIT
|
|
|
|
/// to compile functions on demand.
|
|
|
|
TargetAddress executeCompileCallback(TargetAddress TrampolineID) {
|
2015-03-25 04:00:34 +00:00
|
|
|
TrampolineMapT::iterator I = ActiveTrampolines.find(TrampolineID);
|
2015-02-17 01:18:38 +00:00
|
|
|
// FIXME: Also raise an error in the Orc error-handler when we finally have
|
|
|
|
// one.
|
|
|
|
if (I == ActiveTrampolines.end())
|
|
|
|
return ErrorHandlerAddress;
|
|
|
|
|
|
|
|
// Found a callback handler. Yank this trampoline out of the active list and
|
|
|
|
// put it back in the available trampolines list, then try to run the
|
|
|
|
// handler's compile and update actions.
|
|
|
|
// Moving the trampoline ID back to the available list first means there's at
|
|
|
|
// least one available trampoline if the compile action triggers a request for
|
|
|
|
// a new one.
|
2015-03-24 04:27:02 +00:00
|
|
|
AvailableTrampolines.push_back(I->first);
|
2015-02-17 01:18:38 +00:00
|
|
|
auto CallbackHandler = std::move(I->second);
|
|
|
|
ActiveTrampolines.erase(I);
|
|
|
|
|
|
|
|
if (auto Addr = CallbackHandler.Compile()) {
|
|
|
|
CallbackHandler.Update(Addr);
|
|
|
|
return Addr;
|
[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-02-17 01:18:38 +00:00
|
|
|
return ErrorHandlerAddress;
|
[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-03-25 02:45:50 +00:00
|
|
|
/// @brief Get/create a compile callback with the given signature.
|
|
|
|
virtual CompileCallbackInfo getCompileCallback(FunctionType &FT) = 0;
|
[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-03-25 02:45:50 +00:00
|
|
|
protected:
|
[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-02-17 01:18:38 +00:00
|
|
|
struct CallbackHandler {
|
2015-03-25 02:45:50 +00:00
|
|
|
CompileFtor Compile;
|
|
|
|
UpdateFtor Update;
|
2015-02-17 01:18:38 +00:00
|
|
|
};
|
[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-02-17 01:18:38 +00:00
|
|
|
TargetAddress ErrorHandlerAddress;
|
|
|
|
unsigned NumTrampolinesPerBlock;
|
[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-02-17 01:18:38 +00:00
|
|
|
typedef std::map<TargetAddress, CallbackHandler> TrampolineMapT;
|
|
|
|
TrampolineMapT ActiveTrampolines;
|
|
|
|
std::vector<TargetAddress> AvailableTrampolines;
|
[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-02-17 01:18:38 +00:00
|
|
|
/// @brief Manage compile callbacks.
|
|
|
|
template <typename JITLayerT, typename TargetT>
|
2015-03-25 02:45:50 +00:00
|
|
|
class JITCompileCallbackManager : public JITCompileCallbackManagerBase {
|
[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
|
|
|
public:
|
2015-02-17 01:18:38 +00:00
|
|
|
|
|
|
|
/// @brief Construct a JITCompileCallbackManager.
|
|
|
|
/// @param JIT JIT layer to emit callback trampolines, etc. into.
|
|
|
|
/// @param Context LLVMContext to use for trampoline & resolve block modules.
|
|
|
|
/// @param ErrorHandlerAddress The address of an error handler in the target
|
|
|
|
/// process to be used if a compile callback fails.
|
|
|
|
/// @param NumTrampolinesPerBlock Number of trampolines to allocate whenever
|
|
|
|
/// there is no existing callback trampoline.
|
|
|
|
/// (Trampolines are allocated in blocks for
|
|
|
|
/// efficiency.)
|
|
|
|
JITCompileCallbackManager(JITLayerT &JIT, LLVMContext &Context,
|
|
|
|
TargetAddress ErrorHandlerAddress,
|
|
|
|
unsigned NumTrampolinesPerBlock)
|
2015-03-25 02:45:50 +00:00
|
|
|
: JITCompileCallbackManagerBase(ErrorHandlerAddress,
|
|
|
|
NumTrampolinesPerBlock),
|
2015-02-17 01:18:38 +00:00
|
|
|
JIT(JIT) {
|
|
|
|
emitResolverBlock(Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Get/create a compile callback with the given signature.
|
2015-03-25 02:45:50 +00:00
|
|
|
CompileCallbackInfo getCompileCallback(FunctionType &FT) final {
|
2015-02-17 01:18:38 +00:00
|
|
|
TargetAddress TrampolineAddr = getAvailableTrampolineAddr(FT.getContext());
|
|
|
|
auto &CallbackHandler =
|
2015-03-24 04:27:02 +00:00
|
|
|
this->ActiveTrampolines[TrampolineAddr];
|
2015-02-17 01:18:38 +00:00
|
|
|
Constant *AddrIntVal =
|
|
|
|
ConstantInt::get(Type::getInt64Ty(FT.getContext()), TrampolineAddr);
|
|
|
|
Constant *AddrPtrVal =
|
|
|
|
ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
|
|
|
|
PointerType::get(&FT, 0));
|
|
|
|
|
|
|
|
return CompileCallbackInfo(AddrPtrVal, CallbackHandler.Compile,
|
|
|
|
CallbackHandler.Update);
|
|
|
|
}
|
|
|
|
|
[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:
|
|
|
|
|
2015-02-17 01:18:38 +00:00
|
|
|
std::vector<std::unique_ptr<Module>>
|
|
|
|
SingletonSet(std::unique_ptr<Module> M) {
|
|
|
|
std::vector<std::unique_ptr<Module>> Ms;
|
|
|
|
Ms.push_back(std::move(M));
|
|
|
|
return Ms;
|
|
|
|
}
|
[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-02-17 01:18:38 +00:00
|
|
|
void emitResolverBlock(LLVMContext &Context) {
|
|
|
|
std::unique_ptr<Module> M(new Module("resolver_block_module",
|
|
|
|
Context));
|
|
|
|
TargetT::insertResolverBlock(*M, *this);
|
|
|
|
auto H = JIT.addModuleSet(SingletonSet(std::move(M)), nullptr);
|
|
|
|
JIT.emitAndFinalize(H);
|
|
|
|
auto ResolverBlockSymbol =
|
|
|
|
JIT.findSymbolIn(H, TargetT::ResolverBlockName, false);
|
|
|
|
assert(ResolverBlockSymbol && "Failed to insert resolver block");
|
|
|
|
ResolverBlockAddr = ResolverBlockSymbol.getAddress();
|
|
|
|
}
|
[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-02-17 01:18:38 +00:00
|
|
|
TargetAddress getAvailableTrampolineAddr(LLVMContext &Context) {
|
|
|
|
if (this->AvailableTrampolines.empty())
|
|
|
|
grow(Context);
|
|
|
|
assert(!this->AvailableTrampolines.empty() &&
|
|
|
|
"Failed to grow available trampolines.");
|
|
|
|
TargetAddress TrampolineAddr = this->AvailableTrampolines.back();
|
|
|
|
this->AvailableTrampolines.pop_back();
|
|
|
|
return TrampolineAddr;
|
|
|
|
}
|
[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-02-17 01:18:38 +00:00
|
|
|
void grow(LLVMContext &Context) {
|
|
|
|
assert(this->AvailableTrampolines.empty() && "Growing prematurely?");
|
|
|
|
std::unique_ptr<Module> M(new Module("trampoline_block", Context));
|
|
|
|
auto GetLabelName =
|
|
|
|
TargetT::insertCompileCallbackTrampolines(*M, ResolverBlockAddr,
|
|
|
|
this->NumTrampolinesPerBlock,
|
|
|
|
this->ActiveTrampolines.size());
|
|
|
|
auto H = JIT.addModuleSet(SingletonSet(std::move(M)), nullptr);
|
|
|
|
JIT.emitAndFinalize(H);
|
|
|
|
for (unsigned I = 0; I < this->NumTrampolinesPerBlock; ++I) {
|
|
|
|
std::string Name = GetLabelName(I);
|
|
|
|
auto TrampolineSymbol = JIT.findSymbolIn(H, Name, false);
|
|
|
|
assert(TrampolineSymbol && "Failed to emit trampoline.");
|
|
|
|
this->AvailableTrampolines.push_back(TrampolineSymbol.getAddress());
|
|
|
|
}
|
[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-02-17 01:18:38 +00:00
|
|
|
JITLayerT &JIT;
|
|
|
|
TargetAddress ResolverBlockAddr;
|
|
|
|
};
|
|
|
|
|
2015-03-25 02:45:50 +00:00
|
|
|
/// @brief Get an update functor for updating the value of a named function
|
|
|
|
/// pointer.
|
|
|
|
template <typename JITLayerT>
|
|
|
|
JITCompileCallbackManagerBase::UpdateFtor
|
|
|
|
getLocalFPUpdater(JITLayerT &JIT, typename JITLayerT::ModuleSetHandleT H,
|
|
|
|
std::string Name) {
|
|
|
|
// FIXME: Move-capture Name once we can use C++14.
|
|
|
|
return [=,&JIT](TargetAddress Addr) {
|
|
|
|
auto FPSym = JIT.findSymbolIn(H, Name, true);
|
|
|
|
assert(FPSym && "Cannot find function pointer to update.");
|
|
|
|
void *FPAddr = reinterpret_cast<void*>(
|
|
|
|
static_cast<uintptr_t>(FPSym.getAddress()));
|
|
|
|
memcpy(FPAddr, &Addr, sizeof(uintptr_t));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-02-17 01:18:38 +00:00
|
|
|
GlobalVariable* createImplPointer(Function &F, const Twine &Name,
|
|
|
|
Constant *Initializer);
|
|
|
|
|
|
|
|
void makeStub(Function &F, GlobalVariable &ImplPointer);
|
|
|
|
|
|
|
|
typedef std::map<Module*, DenseSet<const GlobalValue*>> ModulePartitionMap;
|
|
|
|
|
|
|
|
void partition(Module &M, const ModulePartitionMap &PMap);
|
|
|
|
|
|
|
|
/// @brief Struct for trivial "complete" partitioning of a module.
|
2015-02-17 12:52:58 +00:00
|
|
|
class FullyPartitionedModule {
|
|
|
|
public:
|
2015-02-17 01:18:38 +00:00
|
|
|
std::unique_ptr<Module> GlobalVars;
|
|
|
|
std::unique_ptr<Module> Commons;
|
|
|
|
std::vector<std::unique_ptr<Module>> Functions;
|
2015-02-17 12:52:58 +00:00
|
|
|
|
|
|
|
FullyPartitionedModule() = default;
|
|
|
|
FullyPartitionedModule(FullyPartitionedModule &&S)
|
|
|
|
: GlobalVars(std::move(S.GlobalVars)), Commons(std::move(S.Commons)),
|
|
|
|
Functions(std::move(S.Functions)) {}
|
2015-02-17 01:18:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
FullyPartitionedModule fullyPartition(Module &M);
|
|
|
|
|
2015-02-21 20:44:36 +00:00
|
|
|
} // End namespace orc.
|
|
|
|
} // End namespace llvm.
|
[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
|
|
|
|
|
|
|
#endif // LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
|