blob: aadc437c80c499030786416d5a15269240cd06c0 [file] [log] [blame]
Lang Hames4caa2f72018-05-23 21:27:01 +00001//===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Lang Hames4caa2f72018-05-23 21:27:01 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
10
11namespace llvm {
12namespace orc {
13
Lang Hamesce2207a2020-01-21 16:28:30 -080014IRCompileLayer::IRCompiler::~IRCompiler() {}
15
Lang Hames079df9a2018-10-15 22:56:10 +000016IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
Lang Hamesce2207a2020-01-21 16:28:30 -080017 std::unique_ptr<IRCompiler> Compile)
18 : IRLayer(ES, ManglingOpts), BaseLayer(BaseLayer),
19 Compile(std::move(Compile)) {
20 ManglingOpts = &this->Compile->getManglingOptions();
21}
Lang Hames4caa2f72018-05-23 21:27:01 +000022
Lang Hames079df9a2018-10-15 22:56:10 +000023void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
Lang Hames4caa2f72018-05-23 21:27:01 +000024 std::lock_guard<std::mutex> Lock(IRLayerMutex);
25 this->NotifyCompiled = std::move(NotifyCompiled);
26}
27
Lang Hames7dcd0042020-09-11 09:23:14 -070028void IRCompileLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
Lang Hames8b942742018-10-16 20:13:06 +000029 ThreadSafeModule TSM) {
Lang Hames809e9d12019-08-02 15:21:37 +000030 assert(TSM && "Module must not be null");
Lang Hames4caa2f72018-05-23 21:27:01 +000031
Lang Hamesce2207a2020-01-21 16:28:30 -080032 if (auto Obj = TSM.withModuleDo(*Compile)) {
Lang Hames4caa2f72018-05-23 21:27:01 +000033 {
34 std::lock_guard<std::mutex> Lock(IRLayerMutex);
35 if (NotifyCompiled)
Lang Hames0aec49c2020-09-11 09:50:41 -070036 NotifyCompiled(*R, std::move(TSM));
Lang Hames4caa2f72018-05-23 21:27:01 +000037 else
Lang Hames8d76c712018-09-26 01:24:12 +000038 TSM = ThreadSafeModule();
Lang Hames4caa2f72018-05-23 21:27:01 +000039 }
Lang Hames8b942742018-10-16 20:13:06 +000040 BaseLayer.emit(std::move(R), std::move(*Obj));
Lang Hames4caa2f72018-05-23 21:27:01 +000041 } else {
Lang Hames7dcd0042020-09-11 09:23:14 -070042 R->failMaterialization();
Lang Hames4caa2f72018-05-23 21:27:01 +000043 getExecutionSession().reportError(Obj.takeError());
44 }
45}
46
47} // End namespace orc.
48} // End namespace llvm.