[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"
|
2015-02-17 09:18:38 +08:00
|
|
|
#include "llvm/ExecutionEngine/Orc/OrcTargetSupport.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 <array>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
std::array<const char *, 12> X86GPRsToSave = {{
|
|
|
|
"rbp", "rbx", "r12", "r13", "r14", "r15", // Callee saved.
|
|
|
|
"rdi", "rsi", "rdx", "rcx", "r8", "r9", // Int args.
|
|
|
|
}};
|
|
|
|
|
|
|
|
std::array<const char *, 8> X86XMMsToSave = {{
|
|
|
|
"xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" // FP args
|
|
|
|
}};
|
|
|
|
|
|
|
|
template <typename OStream> unsigned saveX86Regs(OStream &OS) {
|
|
|
|
for (const auto &GPR : X86GPRsToSave)
|
|
|
|
OS << " pushq %" << GPR << "\n";
|
|
|
|
|
|
|
|
OS << " subq $" << (16 * X86XMMsToSave.size()) << ", %rsp\n";
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < X86XMMsToSave.size(); ++i)
|
|
|
|
OS << " movdqu %" << X86XMMsToSave[i] << ", "
|
|
|
|
<< (16 * (X86XMMsToSave.size() - i - 1)) << "(%rsp)\n";
|
|
|
|
|
|
|
|
return (8 * X86GPRsToSave.size()) + (16 * X86XMMsToSave.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename OStream> void restoreX86Regs(OStream &OS) {
|
|
|
|
for (unsigned i = 0; i < X86XMMsToSave.size(); ++i)
|
|
|
|
OS << " movdqu " << (16 * i) << "(%rsp), %"
|
|
|
|
<< X86XMMsToSave[(X86XMMsToSave.size() - i - 1)] << "\n";
|
|
|
|
OS << " addq $" << (16 * X86XMMsToSave.size()) << ", %rsp\n";
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < X86GPRsToSave.size(); ++i)
|
|
|
|
OS << " popq %" << X86GPRsToSave[X86GPRsToSave.size() - i - 1] << "\n";
|
|
|
|
}
|
|
|
|
|
2015-02-17 09:18:38 +08:00
|
|
|
template <typename TargetT>
|
|
|
|
uint64_t executeCompileCallback(JITCompileCallbackManagerBase<TargetT> *JCBM,
|
|
|
|
TargetAddress CallbackID) {
|
|
|
|
return JCBM->executeCompileCallback(CallbackID);
|
[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
|
|
|
|
[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-17 09:18:38 +08:00
|
|
|
const char* OrcX86_64::ResolverBlockName = "orc_resolver_block";
|
[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
|
|
|
void OrcX86_64::insertResolverBlock(
|
2015-02-17 20:53:05 +08:00
|
|
|
Module &M, JITCompileCallbackManagerBase<OrcX86_64> &JCBM) {
|
|
|
|
uint64_t CallbackAddr = static_cast<uint64_t>(
|
|
|
|
reinterpret_cast<uintptr_t>(executeCompileCallback<OrcX86_64>));
|
[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
|
|
|
std::ostringstream AsmStream;
|
[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
|
|
|
Triple TT(M.getTargetTriple());
|
|
|
|
|
|
|
|
if (TT.getOS() == Triple::Darwin)
|
2015-02-17 09:18:38 +08:00
|
|
|
AsmStream << ".section __TEXT,__text,regular,pure_instructions\n"
|
|
|
|
<< ".align 4, 0x90\n";
|
[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
|
|
|
else
|
2015-02-17 09:18:38 +08:00
|
|
|
AsmStream << ".text\n"
|
|
|
|
<< ".align 16, 0x90\n";
|
[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
|
|
|
AsmStream << "jit_callback_manager_addr:\n"
|
|
|
|
<< " .quad " << &JCBM << "\n"
|
|
|
|
<< ResolverBlockName << ":\n";
|
[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
|
|
|
uint64_t ReturnAddrOffset = saveX86Regs(AsmStream);
|
[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
|
|
|
|
|
|
|
// Compute index, load object address, and call JIT.
|
2015-02-17 09:18:38 +08:00
|
|
|
AsmStream << " leaq jit_callback_manager_addr(%rip), %rdi\n"
|
|
|
|
<< " movq (%rdi), %rdi\n"
|
|
|
|
<< " movq " << ReturnAddrOffset << "(%rsp), %rsi\n"
|
|
|
|
<< " movabsq $" << CallbackAddr << ", %rax\n"
|
|
|
|
<< " callq *%rax\n"
|
|
|
|
<< " movq %rax, " << ReturnAddrOffset << "(%rsp)\n";
|
|
|
|
|
|
|
|
restoreX86Regs(AsmStream);
|
|
|
|
|
|
|
|
AsmStream << " retq\n";
|
|
|
|
|
|
|
|
M.appendModuleInlineAsm(AsmStream.str());
|
[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
|
|
|
|
|
|
|
OrcX86_64::LabelNameFtor
|
|
|
|
OrcX86_64::insertCompileCallbackTrampolines(Module &M,
|
|
|
|
TargetAddress ResolverBlockAddr,
|
|
|
|
unsigned NumCalls,
|
|
|
|
unsigned StartIndex) {
|
|
|
|
const char *ResolverBlockPtrName = "Lorc_resolve_block_addr";
|
|
|
|
|
|
|
|
std::ostringstream AsmStream;
|
|
|
|
Triple TT(M.getTargetTriple());
|
|
|
|
|
|
|
|
if (TT.getOS() == Triple::Darwin)
|
|
|
|
AsmStream << ".section __TEXT,__text,regular,pure_instructions\n"
|
|
|
|
<< ".align 4, 0x90\n";
|
|
|
|
else
|
|
|
|
AsmStream << ".text\n"
|
|
|
|
<< ".align 16, 0x90\n";
|
|
|
|
|
|
|
|
AsmStream << ResolverBlockPtrName << ":\n"
|
|
|
|
<< " .quad " << ResolverBlockAddr << "\n";
|
|
|
|
|
|
|
|
auto GetLabelName =
|
|
|
|
[=](unsigned I) {
|
|
|
|
std::ostringstream LabelStream;
|
|
|
|
LabelStream << "orc_jcc_" << (StartIndex + I);
|
|
|
|
return LabelStream.str();
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned I = 0; I < NumCalls; ++I)
|
|
|
|
AsmStream << GetLabelName(I) << ":\n"
|
|
|
|
<< " callq *" << ResolverBlockPtrName << "(%rip)\n";
|
|
|
|
|
|
|
|
M.appendModuleInlineAsm(AsmStream.str());
|
|
|
|
|
|
|
|
return GetLabelName;
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
}
|