[Orc][LLJIT] Automatically use JITLink for LLJIT on supported platforms.

JITLink (which underlies ObjectLinkingLayer) is a replacement for RuntimeDyld.
It supports the native code model, and linker plugins that enable a wider range
of features than RuntimeDyld.

Currently only enabled for MachO/x86-64 and MachO/arm64. New architectures will
be added as JITLink support for them is developed.
This commit is contained in:
Lang Hames 2019-12-15 19:51:35 -08:00
parent 073df421e0
commit 67a1b7f053
1 changed files with 18 additions and 0 deletions

View File

@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/OrcError.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
@ -22,6 +24,22 @@ Error LLJITBuilderState::prepareForConstruction() {
JTMB = std::move(*JTMBOrErr);
else
return JTMBOrErr.takeError();
// If no ObjectLinkingLayer creator was set and the target supports JITLink
// then configure for JITLink.
auto &TT = JTMB->getTargetTriple();
if (!CreateObjectLinkingLayer && TT.isOSBinFormatMachO() &&
(TT.getArch() == Triple::aarch64 || TT.getArch() == Triple::x86_64)) {
JTMB->setRelocationModel(Reloc::PIC_);
JTMB->setCodeModel(CodeModel::Small);
CreateObjectLinkingLayer =
[](ExecutionSession &ES,
const Triple &) -> std::unique_ptr<ObjectLayer> {
return std::make_unique<ObjectLinkingLayer>(
ES, std::make_unique<jitlink::InProcessMemoryManager>());
};
}
}
return Error::success();