2015-02-22 09:45:31 +08:00
|
|
|
//===---- IndirectionUtils.cpp - Utilities for call indirection in Orc ----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
|
2015-03-02 05:28:53 +08:00
|
|
|
#include "llvm/ADT/STLExtras.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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2016-05-27 01:20:35 +08:00
|
|
|
#include "llvm/ExecutionEngine/Orc/OrcABISupport.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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
#include "llvm/IR/CallSite.h"
|
|
|
|
#include "llvm/IR/IRBuilder.h"
|
2018-05-30 09:57:45 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2015-05-06 01:37:18 +08:00
|
|
|
#include "llvm/Transforms/Utils/Cloning.h"
|
2015-04-13 04:05:51 +08:00
|
|
|
#include <sstream>
|
[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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
|
2018-05-30 09:57:45 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::orc;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class CompileCallbackMaterializationUnit : public orc::MaterializationUnit {
|
|
|
|
public:
|
|
|
|
using CompileFunction = JITCompileCallbackManager::CompileFunction;
|
|
|
|
|
|
|
|
CompileCallbackMaterializationUnit(SymbolStringPtr Name,
|
|
|
|
CompileFunction Compile)
|
|
|
|
: MaterializationUnit(SymbolFlagsMap({{Name, JITSymbolFlags::Exported}})),
|
|
|
|
Name(std::move(Name)), Compile(std::move(Compile)) {}
|
|
|
|
|
2018-09-28 23:03:11 +08:00
|
|
|
StringRef getName() const override { return "<Compile Callbacks>"; }
|
|
|
|
|
2018-05-30 09:57:45 +08:00
|
|
|
private:
|
2018-09-28 23:03:11 +08:00
|
|
|
void materialize(MaterializationResponsibility R) override {
|
2018-05-30 09:57:45 +08:00
|
|
|
SymbolMap Result;
|
|
|
|
Result[Name] = JITEvaluatedSymbol(Compile(), JITSymbolFlags::Exported);
|
|
|
|
R.resolve(Result);
|
2018-08-18 10:06:18 +08:00
|
|
|
R.emit();
|
2018-05-30 09:57:45 +08:00
|
|
|
}
|
|
|
|
|
2018-09-28 23:03:11 +08:00
|
|
|
void discard(const JITDylib &JD, SymbolStringPtr Name) override {
|
2018-05-30 09:57:45 +08:00
|
|
|
llvm_unreachable("Discard should never occur on a LMU?");
|
|
|
|
}
|
|
|
|
|
|
|
|
SymbolStringPtr Name;
|
|
|
|
CompileFunction Compile;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
[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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
namespace llvm {
|
2015-02-22 04:44:36 +08: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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
|
2015-12-07 03:44:45 +08:00
|
|
|
void IndirectStubsManager::anchor() {}
|
2018-09-26 11:32:12 +08:00
|
|
|
void TrampolinePool::anchor() {}
|
2015-10-20 01:43:51 +08:00
|
|
|
|
2018-05-30 09:57:45 +08:00
|
|
|
Expected<JITTargetAddress>
|
|
|
|
JITCompileCallbackManager::getCompileCallback(CompileFunction Compile) {
|
2018-09-26 11:32:12 +08:00
|
|
|
if (auto TrampolineAddr = TP->getTrampoline()) {
|
2018-05-30 09:57:45 +08:00
|
|
|
auto CallbackName = ES.getSymbolStringPool().intern(
|
|
|
|
std::string("cc") + std::to_string(++NextCallbackId));
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> Lock(CCMgrMutex);
|
|
|
|
AddrToSymbol[*TrampolineAddr] = CallbackName;
|
2018-08-18 05:18:18 +08:00
|
|
|
cantFail(CallbacksJD.define(
|
2018-05-30 10:40:40 +08:00
|
|
|
llvm::make_unique<CompileCallbackMaterializationUnit>(
|
2018-05-30 09:57:45 +08:00
|
|
|
std::move(CallbackName), std::move(Compile))));
|
|
|
|
return *TrampolineAddr;
|
|
|
|
} else
|
|
|
|
return TrampolineAddr.takeError();
|
|
|
|
}
|
|
|
|
|
|
|
|
JITTargetAddress JITCompileCallbackManager::executeCompileCallback(
|
|
|
|
JITTargetAddress TrampolineAddr) {
|
|
|
|
SymbolStringPtr Name;
|
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> Lock(CCMgrMutex);
|
|
|
|
auto I = AddrToSymbol.find(TrampolineAddr);
|
|
|
|
|
|
|
|
// If this address is not associated with a compile callback then report an
|
|
|
|
// error to the execution session and return ErrorHandlerAddress to the
|
|
|
|
// callee.
|
|
|
|
if (I == AddrToSymbol.end()) {
|
|
|
|
Lock.unlock();
|
|
|
|
std::string ErrMsg;
|
|
|
|
{
|
|
|
|
raw_string_ostream ErrMsgStream(ErrMsg);
|
|
|
|
ErrMsgStream << "No compile callback for trampoline at "
|
|
|
|
<< format("0x%016x", TrampolineAddr);
|
|
|
|
}
|
|
|
|
ES.reportError(
|
|
|
|
make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode()));
|
|
|
|
return ErrorHandlerAddress;
|
|
|
|
} else
|
|
|
|
Name = I->second;
|
|
|
|
}
|
|
|
|
|
2018-08-18 05:18:18 +08:00
|
|
|
if (auto Sym = lookup({&CallbacksJD}, Name))
|
2018-05-30 09:57:45 +08:00
|
|
|
return Sym->getAddress();
|
|
|
|
else {
|
|
|
|
// If anything goes wrong materializing Sym then report it to the session
|
|
|
|
// and return the ErrorHandlerAddress;
|
|
|
|
ES.reportError(Sym.takeError());
|
|
|
|
return ErrorHandlerAddress;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 11:32:12 +08:00
|
|
|
Expected<std::unique_ptr<JITCompileCallbackManager>>
|
2018-05-30 09:57:45 +08:00
|
|
|
createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES,
|
2016-08-02 04:49:11 +08:00
|
|
|
JITTargetAddress ErrorHandlerAddress) {
|
2016-05-27 01:20:35 +08:00
|
|
|
switch (T.getArch()) {
|
2018-09-26 11:32:12 +08:00
|
|
|
default:
|
|
|
|
return make_error<StringError>(
|
|
|
|
std::string("No callback manager available for ") + T.str(),
|
|
|
|
inconvertibleErrorCode());
|
|
|
|
case Triple::aarch64: {
|
|
|
|
typedef orc::LocalJITCompileCallbackManager<orc::OrcAArch64> CCMgrT;
|
|
|
|
return CCMgrT::Create(ES, ErrorHandlerAddress);
|
2017-08-16 02:10:19 +08:00
|
|
|
}
|
|
|
|
|
2016-05-27 01:20:35 +08:00
|
|
|
case Triple::x86: {
|
|
|
|
typedef orc::LocalJITCompileCallbackManager<orc::OrcI386> CCMgrT;
|
2018-09-26 11:32:12 +08:00
|
|
|
return CCMgrT::Create(ES, ErrorHandlerAddress);
|
2016-05-27 01:20:35 +08:00
|
|
|
}
|
|
|
|
|
2018-09-11 21:10:04 +08:00
|
|
|
case Triple::mips: {
|
|
|
|
typedef orc::LocalJITCompileCallbackManager<orc::OrcMips32Be> CCMgrT;
|
2018-09-26 11:32:12 +08:00
|
|
|
return CCMgrT::Create(ES, ErrorHandlerAddress);
|
2018-09-11 21:10:04 +08:00
|
|
|
}
|
|
|
|
case Triple::mipsel: {
|
|
|
|
typedef orc::LocalJITCompileCallbackManager<orc::OrcMips32Le> CCMgrT;
|
2018-09-26 11:32:12 +08:00
|
|
|
return CCMgrT::Create(ES, ErrorHandlerAddress);
|
2018-09-11 21:10:04 +08:00
|
|
|
}
|
2018-09-26 11:32:12 +08:00
|
|
|
|
2018-09-11 21:10:04 +08:00
|
|
|
case Triple::mips64:
|
|
|
|
case Triple::mips64el: {
|
|
|
|
typedef orc::LocalJITCompileCallbackManager<orc::OrcMips64> CCMgrT;
|
2018-09-26 11:32:12 +08:00
|
|
|
return CCMgrT::Create(ES, ErrorHandlerAddress);
|
2018-09-11 21:10:04 +08:00
|
|
|
}
|
2018-09-26 11:32:12 +08:00
|
|
|
|
2016-05-27 01:20:35 +08:00
|
|
|
case Triple::x86_64: {
|
|
|
|
if ( T.getOS() == Triple::OSType::Win32 ) {
|
|
|
|
typedef orc::LocalJITCompileCallbackManager<orc::OrcX86_64_Win32> CCMgrT;
|
2018-09-26 11:32:12 +08:00
|
|
|
return CCMgrT::Create(ES, ErrorHandlerAddress);
|
2016-05-27 01:20:35 +08:00
|
|
|
} else {
|
|
|
|
typedef orc::LocalJITCompileCallbackManager<orc::OrcX86_64_SysV> CCMgrT;
|
2018-09-26 11:32:12 +08:00
|
|
|
return CCMgrT::Create(ES, ErrorHandlerAddress);
|
2016-05-27 01:20:35 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-16 02:10:19 +08:00
|
|
|
|
2016-05-27 01:20:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::function<std::unique_ptr<IndirectStubsManager>()>
|
2016-06-09 03:09:22 +08:00
|
|
|
createLocalIndirectStubsManagerBuilder(const Triple &T) {
|
2016-05-27 01:20:35 +08:00
|
|
|
switch (T.getArch()) {
|
2018-03-28 11:41:45 +08:00
|
|
|
default:
|
|
|
|
return [](){
|
|
|
|
return llvm::make_unique<
|
|
|
|
orc::LocalIndirectStubsManager<orc::OrcGenericABI>>();
|
|
|
|
};
|
2016-05-27 01:20:35 +08:00
|
|
|
|
2017-08-16 02:10:19 +08:00
|
|
|
case Triple::aarch64:
|
|
|
|
return [](){
|
|
|
|
return llvm::make_unique<
|
|
|
|
orc::LocalIndirectStubsManager<orc::OrcAArch64>>();
|
|
|
|
};
|
|
|
|
|
2016-05-27 01:20:35 +08:00
|
|
|
case Triple::x86:
|
|
|
|
return [](){
|
|
|
|
return llvm::make_unique<
|
|
|
|
orc::LocalIndirectStubsManager<orc::OrcI386>>();
|
|
|
|
};
|
|
|
|
|
2018-09-11 21:10:04 +08:00
|
|
|
case Triple::mips:
|
|
|
|
return [](){
|
|
|
|
return llvm::make_unique<
|
|
|
|
orc::LocalIndirectStubsManager<orc::OrcMips32Be>>();
|
|
|
|
};
|
|
|
|
|
|
|
|
case Triple::mipsel:
|
|
|
|
return [](){
|
|
|
|
return llvm::make_unique<
|
|
|
|
orc::LocalIndirectStubsManager<orc::OrcMips32Le>>();
|
|
|
|
};
|
|
|
|
|
|
|
|
case Triple::mips64:
|
|
|
|
case Triple::mips64el:
|
|
|
|
return [](){
|
|
|
|
return llvm::make_unique<
|
|
|
|
orc::LocalIndirectStubsManager<orc::OrcMips64>>();
|
|
|
|
};
|
|
|
|
|
2016-05-27 01:20:35 +08:00
|
|
|
case Triple::x86_64:
|
|
|
|
if (T.getOS() == Triple::OSType::Win32) {
|
|
|
|
return [](){
|
|
|
|
return llvm::make_unique<
|
|
|
|
orc::LocalIndirectStubsManager<orc::OrcX86_64_Win32>>();
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return [](){
|
|
|
|
return llvm::make_unique<
|
|
|
|
orc::LocalIndirectStubsManager<orc::OrcX86_64_SysV>>();
|
|
|
|
};
|
|
|
|
}
|
2017-08-16 02:10:19 +08:00
|
|
|
|
2016-05-27 01:20:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 04:49:11 +08:00
|
|
|
Constant* createIRTypedAddress(FunctionType &FT, JITTargetAddress Addr) {
|
2015-04-11 08:23:49 +08:00
|
|
|
Constant *AddrIntVal =
|
|
|
|
ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr);
|
|
|
|
Constant *AddrPtrVal =
|
|
|
|
ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
|
|
|
|
PointerType::get(&FT, 0));
|
|
|
|
return AddrPtrVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalVariable* createImplPointer(PointerType &PT, Module &M,
|
|
|
|
const Twine &Name, Constant *Initializer) {
|
2015-05-06 01:37:18 +08:00
|
|
|
auto IP = new GlobalVariable(M, &PT, false, GlobalValue::ExternalLinkage,
|
|
|
|
Initializer, Name, nullptr,
|
|
|
|
GlobalValue::NotThreadLocal, 0, true);
|
|
|
|
IP->setVisibility(GlobalValue::HiddenVisibility);
|
|
|
|
return IP;
|
[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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
}
|
|
|
|
|
2015-10-20 01:43:51 +08:00
|
|
|
void makeStub(Function &F, Value &ImplPointer) {
|
2015-02-17 09:18:38 +08:00
|
|
|
assert(F.isDeclaration() && "Can't turn a definition into a stub.");
|
|
|
|
assert(F.getParent() && "Function isn't in a module.");
|
|
|
|
Module &M = *F.getParent();
|
|
|
|
BasicBlock *EntryBlock = BasicBlock::Create(M.getContext(), "entry", &F);
|
|
|
|
IRBuilder<> Builder(EntryBlock);
|
|
|
|
LoadInst *ImplAddr = Builder.CreateLoad(&ImplPointer);
|
|
|
|
std::vector<Value*> CallArgs;
|
|
|
|
for (auto &A : F.args())
|
|
|
|
CallArgs.push_back(&A);
|
|
|
|
CallInst *Call = Builder.CreateCall(ImplAddr, CallArgs);
|
|
|
|
Call->setTailCall();
|
2015-04-21 04:41:45 +08:00
|
|
|
Call->setAttributes(F.getAttributes());
|
2015-05-06 01:37:18 +08:00
|
|
|
if (F.getReturnType()->isVoidTy())
|
|
|
|
Builder.CreateRetVoid();
|
|
|
|
else
|
|
|
|
Builder.CreateRet(Call);
|
2015-02-17 09:18:38 +08: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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
|
2018-09-28 03:27:20 +08:00
|
|
|
void SymbolLinkagePromoter::operator()(Module &M) {
|
|
|
|
for (auto &GV : M.global_values()) {
|
|
|
|
|
|
|
|
// Rename if necessary.
|
|
|
|
if (!GV.hasName())
|
|
|
|
GV.setName("__orc_anon." + Twine(NextId++));
|
|
|
|
else if (GV.getName().startswith("\01L"))
|
|
|
|
GV.setName("__" + GV.getName().substr(1) + "." + Twine(NextId++));
|
|
|
|
else if (GV.hasLocalLinkage())
|
|
|
|
GV.setName("__orc_lcl." + GV.getName() + "." + Twine(NextId++));
|
|
|
|
|
|
|
|
if (GV.hasLocalLinkage()) {
|
|
|
|
GV.setLinkage(GlobalValue::ExternalLinkage);
|
|
|
|
GV.setVisibility(GlobalValue::HiddenVisibility);
|
2015-04-13 04:05:51 +08:00
|
|
|
}
|
2018-09-28 03:27:20 +08:00
|
|
|
GV.setUnnamedAddr(GlobalValue::UnnamedAddr::None);
|
[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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
}
|
2015-05-06 01:37:18 +08:00
|
|
|
}
|
2015-05-05 07:30:01 +08:00
|
|
|
|
2015-05-06 01:37:18 +08:00
|
|
|
Function* cloneFunctionDecl(Module &Dst, const Function &F,
|
|
|
|
ValueToValueMapTy *VMap) {
|
|
|
|
Function *NewF =
|
2016-01-17 04:30:46 +08:00
|
|
|
Function::Create(cast<FunctionType>(F.getValueType()),
|
2015-05-06 01:37:18 +08:00
|
|
|
F.getLinkage(), F.getName(), &Dst);
|
|
|
|
NewF->copyAttributesFrom(&F);
|
|
|
|
|
|
|
|
if (VMap) {
|
|
|
|
(*VMap)[&F] = NewF;
|
|
|
|
auto NewArgI = NewF->arg_begin();
|
|
|
|
for (auto ArgI = F.arg_begin(), ArgE = F.arg_end(); ArgI != ArgE;
|
|
|
|
++ArgI, ++NewArgI)
|
2015-10-14 02:10:59 +08:00
|
|
|
(*VMap)[&*ArgI] = &*NewArgI;
|
[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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
}
|
|
|
|
|
2015-05-06 01:37:18 +08:00
|
|
|
return NewF;
|
|
|
|
}
|
[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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
|
2015-05-06 01:37:18 +08:00
|
|
|
void moveFunctionBody(Function &OrigF, ValueToValueMapTy &VMap,
|
|
|
|
ValueMaterializer *Materializer,
|
|
|
|
Function *NewF) {
|
|
|
|
assert(!OrigF.isDeclaration() && "Nothing to move");
|
|
|
|
if (!NewF)
|
|
|
|
NewF = cast<Function>(VMap[&OrigF]);
|
|
|
|
else
|
|
|
|
assert(VMap[&OrigF] == NewF && "Incorrect function mapping in VMap.");
|
|
|
|
assert(NewF && "Function mapping missing from VMap.");
|
|
|
|
assert(NewF->getParent() != OrigF.getParent() &&
|
|
|
|
"moveFunctionBody should only be used to move bodies between "
|
|
|
|
"modules.");
|
|
|
|
|
|
|
|
SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned.
|
|
|
|
CloneFunctionInto(NewF, &OrigF, VMap, /*ModuleLevelChanges=*/true, Returns,
|
|
|
|
"", nullptr, nullptr, Materializer);
|
|
|
|
OrigF.deleteBody();
|
|
|
|
}
|
2015-05-05 07:30:01 +08:00
|
|
|
|
2015-05-06 01:37:18 +08:00
|
|
|
GlobalVariable* cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV,
|
|
|
|
ValueToValueMapTy *VMap) {
|
|
|
|
GlobalVariable *NewGV = new GlobalVariable(
|
2016-01-17 04:30:46 +08:00
|
|
|
Dst, GV.getValueType(), GV.isConstant(),
|
2015-05-06 01:37:18 +08:00
|
|
|
GV.getLinkage(), nullptr, GV.getName(), nullptr,
|
|
|
|
GV.getThreadLocalMode(), GV.getType()->getAddressSpace());
|
|
|
|
NewGV->copyAttributesFrom(&GV);
|
|
|
|
if (VMap)
|
|
|
|
(*VMap)[&GV] = NewGV;
|
|
|
|
return NewGV;
|
|
|
|
}
|
2015-02-17 09:18:38 +08:00
|
|
|
|
2015-05-06 01:37:18 +08:00
|
|
|
void moveGlobalVariableInitializer(GlobalVariable &OrigGV,
|
|
|
|
ValueToValueMapTy &VMap,
|
|
|
|
ValueMaterializer *Materializer,
|
|
|
|
GlobalVariable *NewGV) {
|
|
|
|
assert(OrigGV.hasInitializer() && "Nothing to move");
|
|
|
|
if (!NewGV)
|
|
|
|
NewGV = cast<GlobalVariable>(VMap[&OrigGV]);
|
|
|
|
else
|
|
|
|
assert(VMap[&OrigGV] == NewGV &&
|
|
|
|
"Incorrect global variable mapping in VMap.");
|
|
|
|
assert(NewGV->getParent() != OrigGV.getParent() &&
|
2018-07-12 14:41:41 +08:00
|
|
|
"moveGlobalVariableInitializer should only be used to move "
|
|
|
|
"initializers between modules");
|
2015-05-06 01:37:18 +08:00
|
|
|
|
|
|
|
NewGV->setInitializer(MapValue(OrigGV.getInitializer(), VMap, RF_None,
|
|
|
|
nullptr, Materializer));
|
[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.
llvm-svn: 226940
2015-01-24 05:25:00 +08:00
|
|
|
}
|
2015-02-17 09:18:38 +08:00
|
|
|
|
2015-10-20 01:43:51 +08:00
|
|
|
GlobalAlias* cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA,
|
|
|
|
ValueToValueMapTy &VMap) {
|
2015-10-07 06:55:05 +08:00
|
|
|
assert(OrigA.getAliasee() && "Original alias doesn't have an aliasee?");
|
|
|
|
auto *NewA = GlobalAlias::create(OrigA.getValueType(),
|
|
|
|
OrigA.getType()->getPointerAddressSpace(),
|
|
|
|
OrigA.getLinkage(), OrigA.getName(), &Dst);
|
|
|
|
NewA->copyAttributesFrom(&OrigA);
|
|
|
|
VMap[&OrigA] = NewA;
|
|
|
|
return NewA;
|
|
|
|
}
|
|
|
|
|
2016-09-05 01:53:30 +08:00
|
|
|
void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
|
|
|
|
ValueToValueMapTy &VMap) {
|
|
|
|
auto *MFs = Src.getModuleFlagsMetadata();
|
|
|
|
if (!MFs)
|
|
|
|
return;
|
|
|
|
for (auto *MF : MFs->operands())
|
|
|
|
Dst.addModuleFlag(MapMetadata(MF, VMap));
|
|
|
|
}
|
|
|
|
|
2015-02-22 04:44:36 +08:00
|
|
|
} // End namespace orc.
|
|
|
|
} // End namespace llvm.
|