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;
44 : S(
std::make_shared<State>(
std::
move(NewCtx))) {
45 assert(S->Ctx !=
nullptr &&
46 "Can not construct a ThreadSafeContext from a nullptr");
51 std::lock_guard<std::recursive_mutex> Lock(TmpS->Mutex);
52 return F(TmpS->Ctx.get());
59 std::lock_guard<std::recursive_mutex> Lock(TmpS->Mutex);
60 return F(
const_cast<const LLVMContext *
>(TmpS->Ctx.get()));
66 std::shared_ptr<State> S;
86 M = std::move(
Other.M);
87 TSCtx = std::move(
Other.TSCtx);
109 explicit operator bool()
const {
return !!M; }
115 assert(M &&
"Can not call on null module");
124 assert(M &&
"Can not call on null module");
134 assert(M &&
"Can not call on null module");
135 return F(std::move(M));
149 std::unique_ptr<Module> M;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Module.h This file contains the declarations for the Module class.
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.
An LLVMContext together with an associated mutex that can be used to lock the context to prevent conc...
ThreadSafeContext()=default
Construct a null context.
ThreadSafeContext(std::unique_ptr< LLVMContext > NewCtx)
Construct a ThreadSafeContext from the given LLVMContext.
decltype(auto) withContextDo(Func &&F)
decltype(auto) withContextDo(Func &&F) const
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
LLVM_ABI ThreadSafeModule cloneToContext(const ThreadSafeModule &TSMW, ThreadSafeContext TSCtx, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clones the given module onto the given context.
LLVM_ABI ThreadSafeModule cloneExternalModuleToContext(const Module &M, ThreadSafeContext TSCtx, GVPredicate ShouldCloneDef=GVPredicate(), GVModifier UpdateClonedDefSource=GVModifier())
Clone the given module onto the given context.
LLVM_ABI 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.