13 #ifndef LLVM_EXECUTIONENGINE_ORC_THREADSAFEMODULEWRAPPER_H 14 #define LLVM_EXECUTIONENGINE_ORC_THREADSAFEMODULEWRAPPER_H 32 State(std::unique_ptr<LLVMContext> Ctx) : Ctx(std::move(Ctx)) {}
34 std::unique_ptr<LLVMContext> Ctx;
35 std::recursive_mutex
Mutex;
42 Lock(std::shared_ptr<State> S) : S(
std::move(S)), L(this->S->
Mutex) {}
45 std::shared_ptr<State> S;
46 std::unique_lock<std::recursive_mutex> L;
54 : S(
std::make_shared<State>(
std::move(NewCtx))) {
55 assert(S->Ctx !=
nullptr &&
56 "Can not construct a ThreadSafeContext from a nullptr");
68 assert(S &&
"Can not lock an empty ThreadSafeContext");
73 std::shared_ptr<State> S;
93 auto L = TSCtx.getLock();
96 M = std::move(
Other.M);
97 TSCtx = std::move(
Other.TSCtx);
105 : M(
std::move(M)), TSCtx(
std::move(Ctx)) {}
110 : M(
std::move(M)), TSCtx(
std::move(TSCtx)) {}
115 auto L = TSCtx.getLock();
122 explicit operator bool()
const {
124 assert(TSCtx.getContext() &&
125 "Non-null module must have non-null context");
133 template <
typename Func>
135 assert(M &&
"Can not call on null module");
136 auto Lock = TSCtx.getLock();
142 template <
typename Func>
144 -> decltype(
F(std::declval<const Module &>())) {
145 auto Lock = TSCtx.getLock();
159 std::unique_ptr<Module> M;
175 #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...
auto withModuleDo(Func &&F) -> decltype(F(std::declval< Module &>()))
Locks the associated ThreadSafeContext and calls the given function on the contained Module...
Optional< std::vector< StOtherPiece > > Other
ThreadSafeContext(std::unique_ptr< LLVMContext > NewCtx)
Construct a ThreadSafeContext from the given LLVMContext.
std::function< bool(const GlobalValue &)> GVPredicate
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...
auto withModuleDo(Func &&F) const -> decltype(F(std::declval< const Module &>()))
Locks the associated ThreadSafeContext and calls the given function on the contained Module...
ThreadSafeModule(std::unique_ptr< Module > M, ThreadSafeContext TSCtx)
Construct a ThreadSafeModule from a unique_ptr<Module> and an existing ThreadSafeContext.
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...
ThreadSafeContext getContext() const
Returns the context for this ThreadSafeModule.
An LLVM Module together with a shared ThreadSafeContext.
const Module * getModuleUnlocked() const
Get a raw pointer to the contained module without locking the context.
Module.h This file contains the declarations for the Module class.
ThreadSafeModule(std::unique_ptr< Module > M, std::unique_ptr< LLVMContext > Ctx)
Construct a ThreadSafeModule from a unique_ptr<Module> and a unique_ptr<LLVMContext>.
Module * getModuleUnlocked()
Get a raw pointer to the contained module without locking the context.
ThreadSafeModule cloneToNewContext(ThreadSafeModule &TSMW, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module on to a new context.
ThreadSafeModule & operator=(ThreadSafeModule &&Other)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(GlobalValue &)> GVModifier
Lock(std::shared_ptr< State > S)
ThreadSafeContext()=default
Construct a null context.