13#ifndef LLVM_EXECUTIONENGINE_ORC_THREADSAFEMODULE_H
14#define LLVM_EXECUTIONENGINE_ORC_THREADSAFEMODULE_H
32 State(std::unique_ptr<LLVMContext> Ctx) : Ctx(std::move(Ctx)) {}
34 std::unique_ptr<LLVMContext> Ctx;
35 std::recursive_mutex
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;
96 M = std::move(
Other.M);
97 TSCtx = std::move(
Other.TSCtx);
122 explicit operator bool()
const {
125 "Non-null module must have non-null context");
134 assert(M &&
"Can not call on null module");
142 assert(M &&
"Can not call on null module");
152 return F(std::move(M));
165 std::unique_ptr<Module> M;
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
Lock(std::shared_ptr< State > S)
An LLVMContext together with an associated mutex that can be used to lock the context to prevent conc...
ThreadSafeContext()=default
Construct a null context.
LLVMContext * getContext()
Returns a pointer to the LLVMContext that was used to construct this instance, or null if the instanc...
ThreadSafeContext(std::unique_ptr< LLVMContext > NewCtx)
Construct a ThreadSafeContext from the given LLVMContext.
const LLVMContext * getContext() const
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.
ThreadSafeContext getContext() const
Returns the context for this ThreadSafeModule.
decltype(auto) consumingModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function, passing the contained std::uniqu...
ThreadSafeModule & operator=(ThreadSafeModule &&Other)
ThreadSafeModule()=default
Default construct a ThreadSafeModule.
Module * getModuleUnlocked()
Get a raw pointer to the contained module without locking the context.
ThreadSafeModule(std::unique_ptr< Module > M, std::unique_ptr< LLVMContext > Ctx)
Construct a ThreadSafeModule from a unique_ptr<Module> and a unique_ptr<LLVMContext>.
decltype(auto) withModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function on the contained Module.
ThreadSafeModule(ThreadSafeModule &&Other)=default
decltype(auto) withModuleDo(Func &&F) const
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.
const Module * getModuleUnlocked() const
Get a raw pointer to the contained module without locking the context.
std::function< bool(const GlobalValue &)> GVPredicate
std::function< void(GlobalValue &)> GVModifier
ThreadSafeModule cloneToNewContext(const ThreadSafeModule &TSMW, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module on to a new context.
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.