Skip to content

Commit 67a1b7f

Browse files
committed
[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.
1 parent 073df42 commit 67a1b7f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
10+
#include "llvm/ExecutionEngine/JITLink/JITLinkMemoryManager.h"
11+
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
1012
#include "llvm/ExecutionEngine/Orc/OrcError.h"
1113
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
1214
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
@@ -22,6 +24,22 @@ Error LLJITBuilderState::prepareForConstruction() {
2224
JTMB = std::move(*JTMBOrErr);
2325
else
2426
return JTMBOrErr.takeError();
27+
28+
// If no ObjectLinkingLayer creator was set and the target supports JITLink
29+
// then configure for JITLink.
30+
auto &TT = JTMB->getTargetTriple();
31+
if (!CreateObjectLinkingLayer && TT.isOSBinFormatMachO() &&
32+
(TT.getArch() == Triple::aarch64 || TT.getArch() == Triple::x86_64)) {
33+
34+
JTMB->setRelocationModel(Reloc::PIC_);
35+
JTMB->setCodeModel(CodeModel::Small);
36+
CreateObjectLinkingLayer =
37+
[](ExecutionSession &ES,
38+
const Triple &) -> std::unique_ptr<ObjectLayer> {
39+
return std::make_unique<ObjectLinkingLayer>(
40+
ES, std::make_unique<jitlink::InProcessMemoryManager>());
41+
};
42+
}
2543
}
2644

2745
return Error::success();

0 commit comments

Comments
 (0)