LLVM  11.0.0git
IRCompileLayer.cpp
Go to the documentation of this file.
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 
10 
11 namespace llvm {
12 namespace orc {
13 
15 
17  std::unique_ptr<IRCompiler> Compile)
18  : IRLayer(ES, ManglingOpts), BaseLayer(BaseLayer),
19  Compile(std::move(Compile)) {
20  ManglingOpts = &this->Compile->getManglingOptions();
21 }
22 
24  std::lock_guard<std::mutex> Lock(IRLayerMutex);
25  this->NotifyCompiled = std::move(NotifyCompiled);
26 }
27 
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.getVModuleKey(), std::move(TSM));
37  else
38  TSM = ThreadSafeModule();
39  }
40  BaseLayer.emit(std::move(R), std::move(*Obj));
41  } else {
43  getExecutionSession().reportError(Obj.takeError());
44  }
45 }
46 
47 } // End namespace orc.
48 } // End namespace llvm.
void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void emit(MaterializationResponsibility R, ThreadSafeModule TSM) override
Emit should materialize the given IR.
static sys::Mutex Lock
Definition: BitVector.h:959
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:410
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this layer.
Definition: Layer.h:74
VModuleKey getVModuleKey() const
Returns the VModuleKey for this instance.
Definition: Core.h:427
An LLVM Module together with a shared ThreadSafeContext.
decltype(auto) withModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function on the contained Module...
IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, std::unique_ptr< IRCompiler > Compile)
virtual void emit(MaterializationResponsibility R, std::unique_ptr< MemoryBuffer > O)=0
Emit should materialize the given IR.
Interface for layers that accept LLVM IR.
Definition: Layer.h:66
An ExecutionSession represents a running JIT program.
Definition: Core.h:1088
void reportError(Error Err)
Report a error for this execution session.
Definition: Core.h:1170
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void failMaterialization()
Notify all not-yet-emitted covered by this MaterializationResponsibility instance that an error has o...
Definition: Core.cpp:242
Interface for Layers that accept object files.
Definition: Layer.h:128
std::function< void(VModuleKey K, ThreadSafeModule TSM)> NotifyCompiledFunction