1 //===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
15 IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
16 CompileFunction Compile)
17 : IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
19 void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
20 std::lock_guard<std::mutex> Lock(IRLayerMutex);
21 this->NotifyCompiled = std::move(NotifyCompiled);
24 void IRCompileLayer::emit(MaterializationResponsibility R,
25 ThreadSafeModule TSM) {
26 assert(TSM.getModule() && "Module must not be null");
28 if (auto Obj = Compile(*TSM.getModule())) {
30 std::lock_guard<std::mutex> Lock(IRLayerMutex);
32 NotifyCompiled(R.getVModuleKey(), std::move(TSM));
34 TSM = ThreadSafeModule();
36 BaseLayer.emit(std::move(R), std::move(*Obj));
38 R.failMaterialization();
39 getExecutionSession().reportError(Obj.takeError());
43 } // End namespace orc.
44 } // End namespace llvm.