14 #ifndef LLVM_EXECUTIONENGINE_ORC_THREADSAFEMODULEWRAPPER_H 15 #define LLVM_EXECUTIONENGINE_ORC_THREADSAFEMODULEWRAPPER_H 33 State(std::unique_ptr<LLVMContext> Ctx) : Ctx(std::move(Ctx)) {}
35 std::unique_ptr<LLVMContext> Ctx;
36 std::recursive_mutex
Mutex;
43 using UnderlyingLock = std::lock_guard<std::recursive_mutex>;
46 Lock(std::shared_ptr<State> S)
51 std::shared_ptr<State> S;
52 std::unique_ptr<UnderlyingLock> L;
60 : S(
std::make_shared<State>(
std::move(NewCtx))) {
61 assert(S->Ctx !=
nullptr &&
62 "Can not construct a ThreadSafeContext from a nullptr");
74 assert(S &&
"Can not lock an empty ThreadSafeContext");
79 std::shared_ptr<State> S;
99 auto L = getContextLock();
102 M = std::move(
Other.M);
103 TSCtx = std::move(
Other.TSCtx);
111 : M(
std::move(M)), TSCtx(
std::move(Ctx)) {}
116 : M(
std::move(M)), TSCtx(
std::move(TSCtx)) {}
121 auto L = getContextLock();
139 assert(TSCtx.getContext() &&
140 "Non-null module must have non-null context");
147 std::unique_ptr<Module> M;
163 #endif // LLVM_EXECUTIONENGINE_ORC_THREADSAFEMODULEWRAPPER_H This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
An LLVMContext together with an associated mutex that can be used to lock the context to prevent conc...
ThreadSafeContext(std::unique_ptr< LLVMContext > NewCtx)
Construct a ThreadSafeContext from the given LLVMContext.
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
std::function< bool(const GlobalValue &)> GVPredicate
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
SmartMutex< false > Mutex
Mutex - A standard, always enforced mutex.
const LLVMContext * getContext() const
Returns a pointer to the LLVMContext that was used to construct this instance, or null if the instanc...
Module * getModule()
Get the module wrapped by this ThreadSafeModule.
ThreadSafeModule(std::unique_ptr< Module > M, ThreadSafeContext TSCtx)
Construct a ThreadSafeModule from a unique_ptr<Module> and an existing ThreadSafeContext.
const Module * getModule() const
Get the module wrapped by this ThreadSafeModule.
This is an important class for using LLVM in a threaded context.
LLVMContext * getContext()
Returns a pointer to the LLVMContext that was used to construct this instance, or null if the instanc...
An LLVM Module together with a shared ThreadSafeContext.
Module.h This file contains the declarations for the Module class.
ThreadSafeContext::Lock getContextLock()
Take out a lock on the ThreadSafeContext for this module.
ThreadSafeModule(std::unique_ptr< Module > M, std::unique_ptr< LLVMContext > Ctx)
Construct a ThreadSafeModule from a unique_ptr<Module> and a unique_ptr<LLVMContext>.
ThreadSafeModule cloneToNewContext(ThreadSafeModule &TSMW, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module on to a new context.
ThreadSafeModule & operator=(ThreadSafeModule &&Other)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(GlobalValue &)> GVModifier
Lock(std::shared_ptr< State > S)
ThreadSafeContext()=default
Construct a null context.