17330f729Sjoerg //===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg
97330f729Sjoerg #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
107330f729Sjoerg
117330f729Sjoerg namespace llvm {
127330f729Sjoerg namespace orc {
137330f729Sjoerg
~IRCompiler()14*82d56013Sjoerg IRCompileLayer::IRCompiler::~IRCompiler() {}
15*82d56013Sjoerg
IRCompileLayer(ExecutionSession & ES,ObjectLayer & BaseLayer,std::unique_ptr<IRCompiler> Compile)167330f729Sjoerg IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
17*82d56013Sjoerg std::unique_ptr<IRCompiler> Compile)
18*82d56013Sjoerg : IRLayer(ES, ManglingOpts), BaseLayer(BaseLayer),
19*82d56013Sjoerg Compile(std::move(Compile)) {
20*82d56013Sjoerg ManglingOpts = &this->Compile->getManglingOptions();
21*82d56013Sjoerg }
227330f729Sjoerg
setNotifyCompiled(NotifyCompiledFunction NotifyCompiled)237330f729Sjoerg void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
247330f729Sjoerg std::lock_guard<std::mutex> Lock(IRLayerMutex);
257330f729Sjoerg this->NotifyCompiled = std::move(NotifyCompiled);
267330f729Sjoerg }
277330f729Sjoerg
emit(std::unique_ptr<MaterializationResponsibility> R,ThreadSafeModule TSM)28*82d56013Sjoerg void IRCompileLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
297330f729Sjoerg ThreadSafeModule TSM) {
307330f729Sjoerg assert(TSM && "Module must not be null");
317330f729Sjoerg
32*82d56013Sjoerg if (auto Obj = TSM.withModuleDo(*Compile)) {
337330f729Sjoerg {
347330f729Sjoerg std::lock_guard<std::mutex> Lock(IRLayerMutex);
357330f729Sjoerg if (NotifyCompiled)
36*82d56013Sjoerg NotifyCompiled(*R, std::move(TSM));
377330f729Sjoerg else
387330f729Sjoerg TSM = ThreadSafeModule();
397330f729Sjoerg }
407330f729Sjoerg BaseLayer.emit(std::move(R), std::move(*Obj));
417330f729Sjoerg } else {
42*82d56013Sjoerg R->failMaterialization();
437330f729Sjoerg getExecutionSession().reportError(Obj.takeError());
447330f729Sjoerg }
457330f729Sjoerg }
467330f729Sjoerg
477330f729Sjoerg } // End namespace orc.
487330f729Sjoerg } // End namespace llvm.
49