Index: lib/ExecutionEngine/Orc/IRCompileLayer.cpp =================================================================== --- lib/ExecutionEngine/Orc/IRCompileLayer.cpp +++ lib/ExecutionEngine/Orc/IRCompileLayer.cpp @@ -21,23 +21,34 @@ this->NotifyCompiled = std::move(NotifyCompiled); } +// FIXME: Quick hack to avoid calling into PassManager::run() in parallel. +static std::mutex PassManagerRunMutex; + void IRCompileLayer2::emit(MaterializationResponsibility R, VModuleKey K, std::unique_ptr M) { assert(M && "Module must not be null"); - if (auto Obj = Compile(*M)) { - { - std::lock_guard Lock(IRLayerMutex); - if (NotifyCompiled) - NotifyCompiled(K, std::move(M)); - else - M = nullptr; + std::unique_ptr Obj; + { + std::lock_guard Lock(PassManagerRunMutex); + if (auto CompileRes = Compile(*M)) { + Obj = std::move(*CompileRes); + assert(Obj && "In success case Obj cannot be null"); + } else { + R.failMaterialization(); + getExecutionSession().reportError(CompileRes.takeError()); + return; } - BaseLayer.emit(std::move(R), std::move(K), std::move(*Obj)); - } else { - R.failMaterialization(); - getExecutionSession().reportError(Obj.takeError()); } + + { + std::lock_guard Lock(IRLayerMutex); + if (NotifyCompiled) + NotifyCompiled(K, std::move(M)); + else + M = nullptr; + } + BaseLayer.emit(std::move(R), std::move(K), std::move(Obj)); } } // End namespace orc.