1 //===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
14 IRCompileLayer::IRCompileLayer(ExecutionSession
&ES
, ObjectLayer
&BaseLayer
,
15 CompileFunction Compile
)
16 : IRLayer(ES
), BaseLayer(BaseLayer
), Compile(std::move(Compile
)) {}
18 void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled
) {
19 std::lock_guard
<std::mutex
> Lock(IRLayerMutex
);
20 this->NotifyCompiled
= std::move(NotifyCompiled
);
23 void IRCompileLayer::emit(MaterializationResponsibility R
,
24 ThreadSafeModule TSM
) {
25 assert(TSM
&& "Module must not be null");
27 if (auto Obj
= TSM
.withModuleDo(Compile
)) {
29 std::lock_guard
<std::mutex
> Lock(IRLayerMutex
);
31 NotifyCompiled(R
.getVModuleKey(), std::move(TSM
));
33 TSM
= ThreadSafeModule();
35 BaseLayer
.emit(std::move(R
), std::move(*Obj
));
37 R
.failMaterialization();
38 getExecutionSession().reportError(Obj
.takeError());
42 } // End namespace orc.
43 } // End namespace llvm.