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::IRCompiler::~IRCompiler() = default;
16 IRCompileLayer::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();
23 void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled
) {
24 std::lock_guard
<std::mutex
> Lock(IRLayerMutex
);
25 this->NotifyCompiled
= std::move(NotifyCompiled
);
28 void IRCompileLayer::emit(std::unique_ptr
<MaterializationResponsibility
> R
,
29 ThreadSafeModule TSM
) {
30 assert(TSM
&& "Module must not be null");
32 if (auto Obj
= TSM
.withModuleDo(*Compile
)) {
34 std::lock_guard
<std::mutex
> Lock(IRLayerMutex
);
36 NotifyCompiled(*R
, std::move(TSM
));
38 TSM
= ThreadSafeModule();
40 BaseLayer
.emit(std::move(R
), std::move(*Obj
));
42 R
->failMaterialization();
43 getExecutionSession().reportError(Obj
.takeError());
47 } // End namespace orc.
48 } // End namespace llvm.