IRCompileLayer.cpp revision 360784
1//===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8 9#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" 10 11namespace llvm { 12namespace orc { 13 14IRCompileLayer::IRCompiler::~IRCompiler() {} 15 16IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, 17 std::unique_ptr<IRCompiler> Compile) 18 : IRLayer(ES, ManglingOpts), BaseLayer(BaseLayer), 19 Compile(std::move(Compile)) { 20 ManglingOpts = &this->Compile->getManglingOptions(); 21} 22 23void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) { 24 std::lock_guard<std::mutex> Lock(IRLayerMutex); 25 this->NotifyCompiled = std::move(NotifyCompiled); 26} 27 28void IRCompileLayer::emit(MaterializationResponsibility R, 29 ThreadSafeModule TSM) { 30 assert(TSM && "Module must not be null"); 31 32 if (auto Obj = TSM.withModuleDo(*Compile)) { 33 { 34 std::lock_guard<std::mutex> Lock(IRLayerMutex); 35 if (NotifyCompiled) 36 NotifyCompiled(R.getVModuleKey(), std::move(TSM)); 37 else 38 TSM = ThreadSafeModule(); 39 } 40 BaseLayer.emit(std::move(R), std::move(*Obj)); 41 } else { 42 R.failMaterialization(); 43 getExecutionSession().reportError(Obj.takeError()); 44 } 45} 46 47} // End namespace orc. 48} // End namespace llvm. 49