diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-09-26 12:15:23 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-09-26 12:15:23 +0000 |
commit | 20b5abe23b33b924a9f1a7ad62f3a9d9e118ebf5 (patch) | |
tree | a30585e97ea494c1f71eed72f2669c38d07e9bf7 /llvm/lib/ExecutionEngine | |
parent | 7f8d310b7619ed0ff0af02a6ba397d7079ec1be2 (diff) | |
download | bcm5719-llvm-20b5abe23b33b924a9f1a7ad62f3a9d9e118ebf5.tar.gz bcm5719-llvm-20b5abe23b33b924a9f1a7ad62f3a9d9e118ebf5.zip |
Revert r343058 "[ORC] Add support for multithreaded compiles to LLJIT and LLLazyJIT."
This doesn't work well in builds configured with LLVM_ENABLE_THREADS=OFF,
causing the following assert when running
ExecutionEngine/OrcLazy/multiple-compile-threads-basic.ll:
lib/ExecutionEngine/Orc/Core.cpp:1748: Expected<llvm::JITEvaluatedSymbol>
llvm::orc::lookup(const llvm::orc::JITDylibList &, llvm::orc::SymbolStringPtr):
Assertion `ResultMap->size() == 1 && "Unexpected number of results"' failed.
> LLJIT and LLLazyJIT can now be constructed with an optional NumCompileThreads
> arguments. If this is non-zero then a thread-pool will be created with the
> given number of threads, and compile tasks will be dispatched to the thread
> pool.
>
> To enable testing of this feature, two new flags are added to lli:
>
> (1) -compile-threads=N (N = 0 by default) controls the number of compile threads
> to use.
>
> (2) -thread-entry can be used to execute code on additional threads. For each
> -thread-entry argument supplied (multiple are allowed) a new thread will be
> created and the given symbol called. These additional thread entry points are
> called after static constructors are run, but before main.
llvm-svn: 343099
Diffstat (limited to 'llvm/lib/ExecutionEngine')
-rw-r--r-- | llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 93 |
1 files changed, 9 insertions, 84 deletions
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index 0a0faaa681c..34402506a60 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -12,45 +12,13 @@ #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/IR/Mangler.h" -namespace { - - // A SimpleCompiler that owns its TargetMachine. - class TMOwningSimpleCompiler : public llvm::orc::SimpleCompiler { - public: - TMOwningSimpleCompiler(std::unique_ptr<llvm::TargetMachine> TM) - : llvm::orc::SimpleCompiler(*TM), TM(std::move(TM)) {} - private: - // FIXME: shared because std::functions (and thus - // IRCompileLayer2::CompileFunction) are not moveable. - std::shared_ptr<llvm::TargetMachine> TM; - }; - -} // end anonymous namespace - namespace llvm { namespace orc { -LLJIT::~LLJIT() { - if (CompileThreads) - CompileThreads->wait(); -} - Expected<std::unique_ptr<LLJIT>> -LLJIT::Create(JITTargetMachineBuilder JTMB, DataLayout DL, - unsigned NumCompileThreads) { - - if (NumCompileThreads == 0) { - // If NumCompileThreads == 0 then create a single-threaded LLJIT instance. - auto TM = JTMB.createTargetMachine(); - if (!TM) - return TM.takeError(); - return std::unique_ptr<LLJIT>(new LLJIT(llvm::make_unique<ExecutionSession>(), - std::move(*TM), std::move(DL))); - } - +LLJIT::Create(std::unique_ptr<TargetMachine> TM, DataLayout DL) { return std::unique_ptr<LLJIT>(new LLJIT(llvm::make_unique<ExecutionSession>(), - std::move(JTMB), std::move(DL), - NumCompileThreads)); + std::move(TM), std::move(DL))); } Error LLJIT::defineAbsolute(StringRef Name, JITEvaluatedSymbol Sym) { @@ -84,35 +52,12 @@ Expected<JITEvaluatedSymbol> LLJIT::lookupLinkerMangled(JITDylib &JD, LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES, std::unique_ptr<TargetMachine> TM, DataLayout DL) : ES(std::move(ES)), Main(this->ES->createJITDylib("main")), - DL(std::move(DL)), + TM(std::move(TM)), DL(std::move(DL)), ObjLinkingLayer(*this->ES, [this](VModuleKey K) { return getMemoryManager(K); }), - CompileLayer(*this->ES, ObjLinkingLayer, TMOwningSimpleCompiler(std::move(TM))), + CompileLayer(*this->ES, ObjLinkingLayer, SimpleCompiler(*this->TM)), CtorRunner(Main), DtorRunner(Main) {} -LLJIT::LLJIT(std::unique_ptr<ExecutionSession> ES, - JITTargetMachineBuilder JTMB, DataLayout DL, - unsigned NumCompileThreads) - : ES(std::move(ES)), Main(this->ES->createJITDylib("main")), - 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) { - assert(NumCompileThreads != 0 && - "Multithreaded LLJIT instance can not be created with 0 threads"); - - CompileThreads = llvm::make_unique<ThreadPool>(NumCompileThreads); - this->ES->setDispatchMaterialization([this](JITDylib &JD, std::unique_ptr<MaterializationUnit> MU) { - // FIXME: Switch to move capture once we have c++14. - auto SharedMU = std::shared_ptr<MaterializationUnit>(std::move(MU)); - auto Work = [SharedMU, &JD]() { - SharedMU->doMaterialize(JD); - }; - CompileThreads->async(std::move(Work)); - }); -} - std::unique_ptr<RuntimeDyld::MemoryManager> LLJIT::getMemoryManager(VModuleKey K) { return llvm::make_unique<SectionMemoryManager>(); @@ -145,11 +90,10 @@ void LLJIT::recordCtorDtors(Module &M) { } Expected<std::unique_ptr<LLLazyJIT>> - LLLazyJIT::Create(JITTargetMachineBuilder JTMB, DataLayout DL, - unsigned NumCompileThreads) { +LLLazyJIT::Create(std::unique_ptr<TargetMachine> TM, DataLayout DL) { auto ES = llvm::make_unique<ExecutionSession>(); - const Triple &TT = JTMB.getTargetTriple(); + const Triple &TT = TM->getTargetTriple(); auto LCTMgr = createLocalLazyCallThroughManager(TT, *ES, 0); if (!LCTMgr) @@ -161,18 +105,9 @@ Expected<std::unique_ptr<LLLazyJIT>> std::string("No indirect stubs manager builder for ") + TT.str(), inconvertibleErrorCode()); - if (NumCompileThreads == 0) { - auto TM = JTMB.createTargetMachine(); - if (!TM) - return TM.takeError(); - return std::unique_ptr<LLLazyJIT>( - new LLLazyJIT(std::move(ES), std::move(*TM), std::move(DL), - std::move(*LCTMgr), std::move(ISMBuilder))); - } - - return std::unique_ptr<LLLazyJIT>(new LLLazyJIT( - std::move(ES), std::move(JTMB), std::move(DL), NumCompileThreads, - std::move(*LCTMgr), std::move(ISMBuilder))); + return std::unique_ptr<LLLazyJIT>( + new LLLazyJIT(std::move(ES), std::move(TM), std::move(DL), + std::move(*LCTMgr), std::move(ISMBuilder))); } Error LLLazyJIT::addLazyIRModule(JITDylib &JD, ThreadSafeModule TSM) { @@ -198,15 +133,5 @@ LLLazyJIT::LLLazyJIT( CODLayer(*this->ES, TransformLayer, *this->LCTMgr, std::move(ISMBuilder)) {} -LLLazyJIT::LLLazyJIT( - std::unique_ptr<ExecutionSession> ES, JITTargetMachineBuilder JTMB, - DataLayout DL, unsigned NumCompileThreads, - std::unique_ptr<LazyCallThroughManager> LCTMgr, - std::function<std::unique_ptr<IndirectStubsManager>()> ISMBuilder) - : LLJIT(std::move(ES), std::move(JTMB), std::move(DL), NumCompileThreads), - LCTMgr(std::move(LCTMgr)), TransformLayer(*this->ES, CompileLayer), - CODLayer(*this->ES, TransformLayer, *this->LCTMgr, - std::move(ISMBuilder)) {} - } // End namespace orc. } // End namespace llvm. |