xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1 //===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
10 
11 namespace llvm {
12 namespace orc {
13 
14 IRCompileLayer::IRCompiler::~IRCompiler() = default;
15 
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();
21 }
22 
23 void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
24   std::lock_guard<std::mutex> Lock(IRLayerMutex);
25   this->NotifyCompiled = std::move(NotifyCompiled);
26 }
27 
28 void IRCompileLayer::emit(std::unique_ptr<MaterializationResponsibility> R,
29                           ThreadSafeModule TSM) {
30   assert(TSM && "Module must not be null");
31 
32   if (auto Obj = TSM.withModuleDo(*Compile)) {
33     {
34       std::lock_guard<std::mutex> Lock(IRLayerMutex);
35       if (NotifyCompiled)
36         NotifyCompiled(*R, std::move(TSM));
37       else
38         TSM = ThreadSafeModule();
39     }
40     BaseLayer.emit(std::move(R), std::move(*Obj));
41   } else {
42     R->failMaterialization();
43     getExecutionSession().reportError(Obj.takeError());
44   }
45 }
46 
47 } // End namespace orc.
48 } // End namespace llvm.
49