LLVM  8.0.1
IRCompileLayer.cpp
Go to the documentation of this file.
1 //===--------------- IRCompileLayer.cpp - IR Compiling Layer --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 
12 namespace llvm {
13 namespace orc {
14 
16  CompileFunction Compile)
17  : IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
18 
20  std::lock_guard<std::mutex> Lock(IRLayerMutex);
21  this->NotifyCompiled = std::move(NotifyCompiled);
22 }
23 
25  ThreadSafeModule TSM) {
26  assert(TSM.getModule() && "Module must not be null");
27 
28  if (auto Obj = Compile(*TSM.getModule())) {
29  {
30  std::lock_guard<std::mutex> Lock(IRLayerMutex);
31  if (NotifyCompiled)
32  NotifyCompiled(R.getVModuleKey(), std::move(TSM));
33  else
34  TSM = ThreadSafeModule();
35  }
36  BaseLayer.emit(std::move(R), std::move(*Obj));
37  } else {
39  getExecutionSession().reportError(Obj.takeError());
40  }
41 }
42 
43 } // End namespace orc.
44 } // End namespace llvm.
void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled)
IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, CompileFunction Compile)
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void emit(MaterializationResponsibility R, ThreadSafeModule TSM) override
Emit should materialize the given IR.
static sys::Mutex Lock
std::function< Expected< std::unique_ptr< MemoryBuffer > >(Module &)> CompileFunction
Definition: BitVector.h:938
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:155
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this layer.
Definition: Layer.h:32
Module * getModule()
Get the module wrapped by this ThreadSafeModule.
VModuleKey getVModuleKey() const
Returns the VModuleKey for this instance.
Definition: Core.h:172
An LLVM Module together with a shared ThreadSafeContext.
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:26
An ExecutionSession represents a running JIT program.
Definition: Core.h:697
void reportError(Error Err)
Report a error for this execution session.
Definition: Core.h:754
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:443
Interface for Layers that accept object files.
Definition: Layer.h:114
std::function< void(VModuleKey K, ThreadSafeModule TSM)> NotifyCompiledFunction