LLVM  10.0.0svn
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  CompileFunction Compile)
16  : IRLayer(ES), BaseLayer(BaseLayer), Compile(std::move(Compile)) {}
17 
19  std::lock_guard<std::mutex> Lock(IRLayerMutex);
20  this->NotifyCompiled = std::move(NotifyCompiled);
21 }
22 
24  ThreadSafeModule TSM) {
25  assert(TSM && "Module must not be null");
26 
27  if (auto Obj = TSM.withModuleDo(Compile)) {
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 {
38  getExecutionSession().reportError(Obj.takeError());
39  }
40 }
41 
42 } // End namespace orc.
43 } // End namespace llvm.
void setNotifyCompiled(NotifyCompiledFunction NotifyCompiled)
IRCompileLayer(ExecutionSession &ES, ObjectLayer &BaseLayer, CompileFunction Compile)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
auto withModuleDo(Func &&F) -> decltype(F(std::declval< Module &>()))
Locks the associated ThreadSafeContext and calls the given function on the contained Module...
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:937
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:171
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this layer.
Definition: Layer.h:31
VModuleKey getVModuleKey() const
Returns the VModuleKey for this instance.
Definition: Core.h:188
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:25
An ExecutionSession represents a running JIT program.
Definition: Core.h:761
void reportError(Error Err)
Report a error for this execution session.
Definition: Core.h:826
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:418
Interface for Layers that accept object files.
Definition: Layer.h:113
std::function< void(VModuleKey K, ThreadSafeModule TSM)> NotifyCompiledFunction