Index: include/llvm/ExecutionEngine/Orc/LLJIT.h =================================================================== --- include/llvm/ExecutionEngine/Orc/LLJIT.h +++ include/llvm/ExecutionEngine/Orc/LLJIT.h @@ -29,10 +29,13 @@ /// A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT. class LLJIT { public: + using CompileFtor = IRCompileLayer2::CompileFunction; + using CompileFtorFactory = std::function; + /// Create an LLJIT instance. static Expected> Create(std::unique_ptr ES, - std::unique_ptr TM, DataLayout DL); + JITTargetMachineBuilder JTMB, DataLayout DL, bool Multithreaded); /// Returns a reference to the ExecutionSession for this JIT instance. ExecutionSession &getExecutionSession() { return *ES; } @@ -89,7 +92,7 @@ protected: LLJIT(std::unique_ptr ES, std::unique_ptr TM, - DataLayout DL); + DataLayout DL, CompileFtorFactory MakeCompileFtor); std::shared_ptr getMemoryManager(VModuleKey K); @@ -136,7 +139,8 @@ private: LLLazyJIT(std::unique_ptr ES, - std::unique_ptr TM, DataLayout DL, LLVMContext &Ctx, + std::unique_ptr TM, DataLayout DL, + CompileFtorFactory MakeCompileFtor, LLVMContext &Ctx, std::unique_ptr CCMgr, std::function()> ISMBuilder); Index: lib/ExecutionEngine/Orc/LLJIT.cpp =================================================================== --- lib/ExecutionEngine/Orc/LLJIT.cpp +++ lib/ExecutionEngine/Orc/LLJIT.cpp @@ -17,9 +17,25 @@ Expected> LLJIT::Create(std::unique_ptr ES, - std::unique_ptr TM, DataLayout DL) { + JITTargetMachineBuilder JTMB, DataLayout DL, bool Multithreaded) { + auto TM = JTMB.createTargetMachine(); + if (!TM) + return TM.takeError(); + + CompileFtorFactory MakeCompileFtor; + if (Multithreaded) { + MakeCompileFtor = [JTMB](TargetMachine &) -> CompileFtor { + return MultiThreadedSimpleCompiler(JTMB); + }; + } else { + MakeCompileFtor = [](TargetMachine &TM) -> CompileFtor { + return SimpleCompiler(TM); + }; + } + return std::unique_ptr( - new LLJIT(std::move(ES), std::move(TM), std::move(DL))); + new LLJIT(std::move(ES), std::move(*TM), std::move(DL), + std::move(MakeCompileFtor))); } Error LLJIT::defineAbsolute(StringRef Name, JITEvaluatedSymbol Sym) { @@ -51,12 +67,13 @@ } LLJIT::LLJIT(std::unique_ptr ES, - std::unique_ptr TM, DataLayout DL) + std::unique_ptr TM, DataLayout DL, + CompileFtorFactory MakeCompileFtor) : 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, SimpleCompiler(*this->TM)), + CompileLayer(*this->ES, ObjLinkingLayer, MakeCompileFtor(*this->TM)), CtorRunner(Main), DtorRunner(Main) {} std::shared_ptr @@ -108,8 +125,13 @@ std::string("No indirect stubs manager builder for ") + TT.str(), inconvertibleErrorCode()); + auto MakeCompileFtor = [](TargetMachine &TM) -> CompileFtor { + return SimpleCompiler(TM); + }; + return std::unique_ptr( - new LLLazyJIT(std::move(ES), std::move(TM), std::move(DL), Ctx, + new LLLazyJIT(std::move(ES), std::move(TM), std::move(DL), + std::move(MakeCompileFtor), Ctx, std::move(CCMgr), std::move(ISMBuilder))); } @@ -129,10 +151,11 @@ LLLazyJIT::LLLazyJIT( std::unique_ptr ES, std::unique_ptr TM, - DataLayout DL, LLVMContext &Ctx, + DataLayout DL, CompileFtorFactory MakeCompileFtor, LLVMContext &Ctx, std::unique_ptr CCMgr, std::function()> ISMBuilder) - : LLJIT(std::move(ES), std::move(TM), std::move(DL)), + : LLJIT(std::move(ES), std::move(TM), std::move(DL), + std::move(MakeCompileFtor)), CCMgr(std::move(CCMgr)), TransformLayer(*this->ES, CompileLayer), CODLayer(*this->ES, TransformLayer, *this->CCMgr, std::move(ISMBuilder), [&]() -> LLVMContext & { return Ctx; }) {}