xref: /llvm-project/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp (revision 3a3cb929ab6fd69ea7d5db42db613a4701fa4669)
14caa2f70SLang Hames //===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
24caa2f70SLang Hames //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
64caa2f70SLang Hames //
74caa2f70SLang Hames //===----------------------------------------------------------------------===//
84caa2f70SLang Hames 
94caa2f70SLang Hames #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
104caa2f70SLang Hames 
114caa2f70SLang Hames namespace llvm {
124caa2f70SLang Hames namespace orc {
134caa2f70SLang Hames 
14*3a3cb929SKazu Hirata IRCompileLayer::IRCompiler::~IRCompiler() = default;
15ce2207abSLang Hames 
IRCompileLayer(ExecutionSession & ES,ObjectLayer & BaseLayer,std::unique_ptr<IRCompiler> Compile)16079df9abSLang Hames IRCompileLayer::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
17ce2207abSLang Hames                                std::unique_ptr<IRCompiler> Compile)
18ce2207abSLang Hames     : IRLayer(ES, ManglingOpts), BaseLayer(BaseLayer),
19ce2207abSLang Hames       Compile(std::move(Compile)) {
20ce2207abSLang Hames   ManglingOpts = &this->Compile->getManglingOptions();
21ce2207abSLang Hames }
224caa2f70SLang Hames 
setNotifyCompiled(NotifyCompiledFunction NotifyCompiled)23079df9abSLang Hames void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
244caa2f70SLang Hames   std::lock_guard<std::mutex> Lock(IRLayerMutex);
254caa2f70SLang Hames   this->NotifyCompiled = std::move(NotifyCompiled);
264caa2f70SLang Hames }
274caa2f70SLang Hames 
emit(std::unique_ptr<MaterializationResponsibility> R,ThreadSafeModule TSM)287dcd0042SLang Hames void IRCompileLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
298d76c711SLang Hames                           ThreadSafeModule TSM) {
30809e9d1eSLang Hames   assert(TSM && "Module must not be null");
314caa2f70SLang Hames 
32ce2207abSLang Hames   if (auto Obj = TSM.withModuleDo(*Compile)) {
334caa2f70SLang Hames     {
344caa2f70SLang Hames       std::lock_guard<std::mutex> Lock(IRLayerMutex);
354caa2f70SLang Hames       if (NotifyCompiled)
360aec49c8SLang Hames         NotifyCompiled(*R, std::move(TSM));
374caa2f70SLang Hames       else
388d76c711SLang Hames         TSM = ThreadSafeModule();
394caa2f70SLang Hames     }
408b94274fSLang Hames     BaseLayer.emit(std::move(R), std::move(*Obj));
414caa2f70SLang Hames   } else {
427dcd0042SLang Hames     R->failMaterialization();
434caa2f70SLang Hames     getExecutionSession().reportError(Obj.takeError());
444caa2f70SLang Hames   }
454caa2f70SLang Hames }
464caa2f70SLang Hames 
474caa2f70SLang Hames } // End namespace orc.
484caa2f70SLang Hames } // End namespace llvm.
49