[Orc][LLJIT] Automatically use JITLink for LLJIT on supported platforms.
authorLang Hames <lhames@gmail.com>
Mon, 16 Dec 2019 03:51:35 +0000 (19:51 -0800)
committerLang Hames <lhames@gmail.com>
Mon, 16 Dec 2019 05:57:10 +0000 (21:57 -0800)
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.

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

index 89dad6d..5c39373 100644 (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();