blob: d311f34179c7c04cddfb2a24716438ae9b15c8d1 [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 Hames079df9a2018-10-15 22:56:10 +000014IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
Lang Hames4caa2f72018-05-23 21:27:01 +000015 CompileFunction Compile)
16 : IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
17
Lang Hames079df9a2018-10-15 22:56:10 +000018void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
Lang Hames4caa2f72018-05-23 21:27:01 +000019 std::lock_guard<std::mutex> Lock(IRLayerMutex);
20 this->NotifyCompiled = std::move(NotifyCompiled);
21}
22
Lang Hames8b942742018-10-16 20:13:06 +000023void IRCompileLayer::emit(MaterializationResponsibility R,
24 ThreadSafeModule TSM) {
Lang Hames809e9d12019-08-02 15:21:37 +000025 assert(TSM && "Module must not be null");
Lang Hames4caa2f72018-05-23 21:27:01 +000026
Lang Hames809e9d12019-08-02 15:21:37 +000027 if (auto Obj = TSM.withModuleDo(Compile)) {
Lang Hames4caa2f72018-05-23 21:27:01 +000028 {
29 std::lock_guard<std::mutex> Lock(IRLayerMutex);
30 if (NotifyCompiled)
Lang Hames8b942742018-10-16 20:13:06 +000031 NotifyCompiled(R.getVModuleKey(), std::move(TSM));
Lang Hames4caa2f72018-05-23 21:27:01 +000032 else
Lang Hames8d76c712018-09-26 01:24:12 +000033 TSM = ThreadSafeModule();
Lang Hames4caa2f72018-05-23 21:27:01 +000034 }
Lang Hames8b942742018-10-16 20:13:06 +000035 BaseLayer.emit(std::move(R), std::move(*Obj));
Lang Hames4caa2f72018-05-23 21:27:01 +000036 } else {
37 R.failMaterialization();
38 getExecutionSession().reportError(Obj.takeError());
39 }
40}
41
42} // End namespace orc.
43} // End namespace llvm.