Index: include/llvm/ExecutionEngine/Orc/LLJIT.h =================================================================== --- include/llvm/ExecutionEngine/Orc/LLJIT.h +++ include/llvm/ExecutionEngine/Orc/LLJIT.h @@ -34,6 +34,11 @@ Create(std::unique_ptr ES, std::unique_ptr TM, DataLayout DL); + /// Create an LLJIT instance suitable for multithreaded compilation. + static Expected> + CreateMultiThreaded(std::unique_ptr ES, + JITTargetMachineBuilder JTMB); + /// Returns a reference to the ExecutionSession for this JIT instance. ExecutionSession &getExecutionSession() { return *ES; } @@ -83,6 +88,9 @@ LLJIT(std::unique_ptr ES, std::unique_ptr TM, DataLayout DL); + LLJIT(std::unique_ptr ES, std::unique_ptr TM, + JITTargetMachineBuilder JTMB, DataLayout DL); + std::shared_ptr getMemoryManager(VModuleKey K); std::string mangle(StringRef UnmangledName); Index: lib/ExecutionEngine/Orc/LLJIT.cpp =================================================================== --- lib/ExecutionEngine/Orc/LLJIT.cpp +++ lib/ExecutionEngine/Orc/LLJIT.cpp @@ -22,6 +22,18 @@ new LLJIT(std::move(ES), std::move(TM), std::move(DL))); } +Expected> +LLJIT::CreateMultiThreaded(std::unique_ptr ES, + JITTargetMachineBuilder JTMB) { + if (auto TM = JTMB.createTargetMachine()) { + auto DL = (**TM).createDataLayout(); + return std::unique_ptr(new LLJIT(std::move(ES), std::move(*TM), + std::move(JTMB), std::move(DL))); + } else { + return TM.takeError(); + } +} + Error LLJIT::defineAbsolute(StringRef Name, JITEvaluatedSymbol Sym) { auto InternedName = ES->getSymbolStringPool().intern(Name); SymbolMap Symbols({{InternedName, Sym}}); @@ -52,6 +64,17 @@ CompileLayer(*this->ES, ObjLinkingLayer, SimpleCompiler(*this->TM)), CtorRunner(Main), DtorRunner(Main) {} +LLJIT::LLJIT(std::unique_ptr ES, + std::unique_ptr TM, JITTargetMachineBuilder JTMB, + DataLayout DL) + : ES(std::move(ES)), Main(this->ES->createJITDylib("main")), + TM(std::move(TM)), DL(std::move(DL)), + ObjLinkingLayer(*this->ES, + [this](VModuleKey K) { return getMemoryManager(K); }), + CompileLayer(*this->ES, ObjLinkingLayer, + MultiThreadedSimpleCompiler(std::move(JTMB))), + CtorRunner(Main), DtorRunner(Main) {} + std::shared_ptr LLJIT::getMemoryManager(VModuleKey K) { return llvm::make_unique();