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.
|
||||
class ThreadSafeContext {
|
||||
private:
|
||||
|
||||
struct State {
|
||||
State(std::unique_ptr<LLVMContext> Ctx)
|
||||
: Ctx(std::move(Ctx)) {}
|
||||
State(std::unique_ptr<LLVMContext> Ctx) : Ctx(std::move(Ctx)) {}
|
||||
|
||||
std::unique_ptr<LLVMContext> Ctx;
|
||||
std::recursive_mutex Mutex;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
// RAII based lock for ThreadSafeContext.
|
||||
class LLVM_NODISCARD Lock {
|
||||
private:
|
||||
using UnderlyingLock = std::lock_guard<std::recursive_mutex>;
|
||||
public:
|
||||
|
||||
public:
|
||||
Lock(std::shared_ptr<State> S)
|
||||
: S(std::move(S)),
|
||||
L(llvm::make_unique<UnderlyingLock>(this->S->Mutex)) {}
|
||||
: S(std::move(S)),
|
||||
L(llvm::make_unique<UnderlyingLock>(this->S->Mutex)) {}
|
||||
|
||||
private:
|
||||
std::shared_ptr<State> S;
|
||||
std::unique_ptr<UnderlyingLock> L;
|
||||
@ -66,9 +64,7 @@ public:
|
||||
|
||||
/// Returns a pointer to the LLVMContext that was used to construct this
|
||||
/// instance, or null if the instance was default constructed.
|
||||
LLVMContext* getContext() {
|
||||
return S ? S->Ctx.get() : nullptr;
|
||||
}
|
||||
LLVMContext *getContext() { return S ? S->Ctx.get() : nullptr; }
|
||||
|
||||
Lock getLock() {
|
||||
assert(S && "Can not lock an empty ThreadSafeContext");
|
||||
@ -88,7 +84,7 @@ public:
|
||||
|
||||
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
|
||||
// reverse order (i.e. module first) to ensure the dependencies are
|
||||
// protected: The old module that is being overwritten must be destroyed
|
||||
@ -124,10 +120,10 @@ public:
|
||||
}
|
||||
|
||||
/// Get the module wrapped by this ThreadSafeModule.
|
||||
Module* getModule() { return M.get(); }
|
||||
Module *getModule() { return M.get(); }
|
||||
|
||||
/// 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.
|
||||
ThreadSafeContext::Lock getContextLock() { return TSCtx.getLock(); }
|
||||
@ -136,7 +132,8 @@ public:
|
||||
/// wraps a non-null module.
|
||||
explicit operator bool() {
|
||||
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 false;
|
||||
@ -147,8 +144,8 @@ private:
|
||||
ThreadSafeContext TSCtx;
|
||||
};
|
||||
|
||||
using GVPredicate = std::function<bool(const GlobalValue&)>;
|
||||
using GVModifier = std::function<void(GlobalValue&)>;
|
||||
using GVPredicate = std::function<bool(const GlobalValue &)>;
|
||||
using GVModifier = std::function<void(GlobalValue &)>;
|
||||
|
||||
/// Clones the given module on to a new context.
|
||||
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
|
||||
//
|
||||
@ -21,7 +22,7 @@ ThreadSafeModule cloneToNewContext(ThreadSafeModule &TSM,
|
||||
assert(TSM && "Can not clone null module");
|
||||
|
||||
if (!ShouldCloneDef)
|
||||
ShouldCloneDef = [](const GlobalValue&) { return true; };
|
||||
ShouldCloneDef = [](const GlobalValue &) { return true; };
|
||||
|
||||
auto Lock = TSM.getContextLock();
|
||||
|
||||
@ -30,8 +31,7 @@ ThreadSafeModule cloneToNewContext(ThreadSafeModule &TSM,
|
||||
{
|
||||
std::vector<GlobalValue *> ClonedDefsInSrc;
|
||||
ValueToValueMapTy VMap;
|
||||
auto Tmp = CloneModule(*TSM.getModule(), VMap,
|
||||
[&](const GlobalValue *GV) {
|
||||
auto Tmp = CloneModule(*TSM.getModule(), VMap, [&](const GlobalValue *GV) {
|
||||
if (ShouldCloneDef(*GV)) {
|
||||
ClonedDefsInSrc.push_back(const_cast<GlobalValue *>(GV));
|
||||
return true;
|
||||
|
@ -32,10 +32,10 @@ TEST(ThreadSafeModuleTest, ContextOwnershipSharedByTwoModules) {
|
||||
// ThreadSafeModule.
|
||||
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);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ TEST(ThreadSafeModuleTest, ThreadSafeModuleMoveAssignment) {
|
||||
TEST(ThreadSafeModuleTest, BasicContextLockAPI) {
|
||||
// Test that basic lock API calls work.
|
||||
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);
|
||||
|
||||
{ auto L = TSCtx.getLock(); }
|
||||
|
Loading…
Reference in New Issue
Block a user