mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
[ORC] clang-format the ThreadSafeModule code.
Evidently I forgot to do this before committing r343055. llvm-svn: 343288
This commit is contained in:
parent
3c8d6a2f70
commit
9e09d1c199
@ -29,26 +29,24 @@ namespace orc {
|
|||||||
/// the context to prevent concurrent access by other threads.
|
/// the context to prevent concurrent access by other threads.
|
||||||
class ThreadSafeContext {
|
class ThreadSafeContext {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
State(std::unique_ptr<LLVMContext> Ctx)
|
State(std::unique_ptr<LLVMContext> Ctx) : Ctx(std::move(Ctx)) {}
|
||||||
: Ctx(std::move(Ctx)) {}
|
|
||||||
|
|
||||||
std::unique_ptr<LLVMContext> Ctx;
|
std::unique_ptr<LLVMContext> Ctx;
|
||||||
std::recursive_mutex Mutex;
|
std::recursive_mutex Mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// RAII based lock for ThreadSafeContext.
|
// RAII based lock for ThreadSafeContext.
|
||||||
class LLVM_NODISCARD Lock {
|
class LLVM_NODISCARD Lock {
|
||||||
private:
|
private:
|
||||||
using UnderlyingLock = std::lock_guard<std::recursive_mutex>;
|
using UnderlyingLock = std::lock_guard<std::recursive_mutex>;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
Lock(std::shared_ptr<State> S)
|
Lock(std::shared_ptr<State> S)
|
||||||
: S(std::move(S)),
|
: S(std::move(S)),
|
||||||
L(llvm::make_unique<UnderlyingLock>(this->S->Mutex)) {}
|
L(llvm::make_unique<UnderlyingLock>(this->S->Mutex)) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<State> S;
|
std::shared_ptr<State> S;
|
||||||
std::unique_ptr<UnderlyingLock> L;
|
std::unique_ptr<UnderlyingLock> L;
|
||||||
@ -66,9 +64,7 @@ public:
|
|||||||
|
|
||||||
/// Returns a pointer to the LLVMContext that was used to construct this
|
/// Returns a pointer to the LLVMContext that was used to construct this
|
||||||
/// instance, or null if the instance was default constructed.
|
/// instance, or null if the instance was default constructed.
|
||||||
LLVMContext* getContext() {
|
LLVMContext *getContext() { return S ? S->Ctx.get() : nullptr; }
|
||||||
return S ? S->Ctx.get() : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Lock getLock() {
|
Lock getLock() {
|
||||||
assert(S && "Can not lock an empty ThreadSafeContext");
|
assert(S && "Can not lock an empty ThreadSafeContext");
|
||||||
@ -88,7 +84,7 @@ public:
|
|||||||
|
|
||||||
ThreadSafeModule(ThreadSafeModule &&Other) = default;
|
ThreadSafeModule(ThreadSafeModule &&Other) = default;
|
||||||
|
|
||||||
ThreadSafeModule& operator=(ThreadSafeModule &&Other) {
|
ThreadSafeModule &operator=(ThreadSafeModule &&Other) {
|
||||||
// We have to explicitly define this move operator to copy the fields in
|
// We have to explicitly define this move operator to copy the fields in
|
||||||
// reverse order (i.e. module first) to ensure the dependencies are
|
// reverse order (i.e. module first) to ensure the dependencies are
|
||||||
// protected: The old module that is being overwritten must be destroyed
|
// protected: The old module that is being overwritten must be destroyed
|
||||||
@ -124,10 +120,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the module wrapped by this ThreadSafeModule.
|
/// Get the module wrapped by this ThreadSafeModule.
|
||||||
Module* getModule() { return M.get(); }
|
Module *getModule() { return M.get(); }
|
||||||
|
|
||||||
/// Get the module wrapped by this ThreadSafeModule.
|
/// Get the module wrapped by this ThreadSafeModule.
|
||||||
const Module* getModule() const { return M.get(); }
|
const Module *getModule() const { return M.get(); }
|
||||||
|
|
||||||
/// Take out a lock on the ThreadSafeContext for this module.
|
/// Take out a lock on the ThreadSafeContext for this module.
|
||||||
ThreadSafeContext::Lock getContextLock() { return TSCtx.getLock(); }
|
ThreadSafeContext::Lock getContextLock() { return TSCtx.getLock(); }
|
||||||
@ -136,7 +132,8 @@ public:
|
|||||||
/// wraps a non-null module.
|
/// wraps a non-null module.
|
||||||
explicit operator bool() {
|
explicit operator bool() {
|
||||||
if (M) {
|
if (M) {
|
||||||
assert(TSCtx.getContext() && "Non-null module must have non-null context");
|
assert(TSCtx.getContext() &&
|
||||||
|
"Non-null module must have non-null context");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -147,8 +144,8 @@ private:
|
|||||||
ThreadSafeContext TSCtx;
|
ThreadSafeContext TSCtx;
|
||||||
};
|
};
|
||||||
|
|
||||||
using GVPredicate = std::function<bool(const GlobalValue&)>;
|
using GVPredicate = std::function<bool(const GlobalValue &)>;
|
||||||
using GVModifier = std::function<void(GlobalValue&)>;
|
using GVModifier = std::function<void(GlobalValue &)>;
|
||||||
|
|
||||||
/// Clones the given module on to a new context.
|
/// Clones the given module on to a new context.
|
||||||
ThreadSafeModule
|
ThreadSafeModule
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
//===-- ThreadSafeModule.cpp - Thread safe Module, Context, and Utilities h-===//
|
//===-- ThreadSafeModule.cpp - Thread safe Module, Context, and Utilities
|
||||||
|
//h-===//
|
||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
@ -21,7 +22,7 @@ ThreadSafeModule cloneToNewContext(ThreadSafeModule &TSM,
|
|||||||
assert(TSM && "Can not clone null module");
|
assert(TSM && "Can not clone null module");
|
||||||
|
|
||||||
if (!ShouldCloneDef)
|
if (!ShouldCloneDef)
|
||||||
ShouldCloneDef = [](const GlobalValue&) { return true; };
|
ShouldCloneDef = [](const GlobalValue &) { return true; };
|
||||||
|
|
||||||
auto Lock = TSM.getContextLock();
|
auto Lock = TSM.getContextLock();
|
||||||
|
|
||||||
@ -30,8 +31,7 @@ ThreadSafeModule cloneToNewContext(ThreadSafeModule &TSM,
|
|||||||
{
|
{
|
||||||
std::vector<GlobalValue *> ClonedDefsInSrc;
|
std::vector<GlobalValue *> ClonedDefsInSrc;
|
||||||
ValueToValueMapTy VMap;
|
ValueToValueMapTy VMap;
|
||||||
auto Tmp = CloneModule(*TSM.getModule(), VMap,
|
auto Tmp = CloneModule(*TSM.getModule(), VMap, [&](const GlobalValue *GV) {
|
||||||
[&](const GlobalValue *GV) {
|
|
||||||
if (ShouldCloneDef(*GV)) {
|
if (ShouldCloneDef(*GV)) {
|
||||||
ClonedDefsInSrc.push_back(const_cast<GlobalValue *>(GV));
|
ClonedDefsInSrc.push_back(const_cast<GlobalValue *>(GV));
|
||||||
return true;
|
return true;
|
||||||
|
@ -32,10 +32,10 @@ TEST(ThreadSafeModuleTest, ContextOwnershipSharedByTwoModules) {
|
|||||||
// ThreadSafeModule.
|
// ThreadSafeModule.
|
||||||
ThreadSafeContext TSCtx(llvm::make_unique<LLVMContext>());
|
ThreadSafeContext TSCtx(llvm::make_unique<LLVMContext>());
|
||||||
|
|
||||||
auto M1 =llvm::make_unique<Module>("M1", *TSCtx.getContext());
|
auto M1 = llvm::make_unique<Module>("M1", *TSCtx.getContext());
|
||||||
ThreadSafeModule TSM1(std::move(M1), TSCtx);
|
ThreadSafeModule TSM1(std::move(M1), TSCtx);
|
||||||
|
|
||||||
auto M2 =llvm::make_unique<Module>("M2", *TSCtx.getContext());
|
auto M2 = llvm::make_unique<Module>("M2", *TSCtx.getContext());
|
||||||
ThreadSafeModule TSM2(std::move(M2), std::move(TSCtx));
|
ThreadSafeModule TSM2(std::move(M2), std::move(TSCtx));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ TEST(ThreadSafeModuleTest, ThreadSafeModuleMoveAssignment) {
|
|||||||
TEST(ThreadSafeModuleTest, BasicContextLockAPI) {
|
TEST(ThreadSafeModuleTest, BasicContextLockAPI) {
|
||||||
// Test that basic lock API calls work.
|
// Test that basic lock API calls work.
|
||||||
ThreadSafeContext TSCtx(llvm::make_unique<LLVMContext>());
|
ThreadSafeContext TSCtx(llvm::make_unique<LLVMContext>());
|
||||||
auto M =llvm::make_unique<Module>("M", *TSCtx.getContext());
|
auto M = llvm::make_unique<Module>("M", *TSCtx.getContext());
|
||||||
ThreadSafeModule TSM(std::move(M), TSCtx);
|
ThreadSafeModule TSM(std::move(M), TSCtx);
|
||||||
|
|
||||||
{ auto L = TSCtx.getLock(); }
|
{ auto L = TSCtx.getLock(); }
|
||||||
|
Loading…
Reference in New Issue
Block a user