xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/Orc/IRCompileLayer.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
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::IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer,
15                                  CompileFunction Compile)
16     : IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
17 
18 void IRCompileLayer::setNotifyCompiled(NotifyCompiledFunction NotifyCompiled) {
19   std::lock_guard<std::mutex> Lock(IRLayerMutex);
20   this->NotifyCompiled = std::move(NotifyCompiled);
21 }
22 
23 void IRCompileLayer::emit(MaterializationResponsibility R,
24                           ThreadSafeModule TSM) {
25   assert(TSM.getModule() && "Module must not be null");
26 
27   if (auto Obj = Compile(*TSM.getModule())) {
28     {
29       std::lock_guard<std::mutex> Lock(IRLayerMutex);
30       if (NotifyCompiled)
31         NotifyCompiled(R.getVModuleKey(), std::move(TSM));
32       else
33         TSM = ThreadSafeModule();
34     }
35     BaseLayer.emit(std::move(R), std::move(*Obj));
36   } else {
37     R.failMaterialization();
38     getExecutionSession().reportError(Obj.takeError());
39   }
40 }
41 
42 } // End namespace orc.
43 } // End namespace llvm.
44