summaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2014-06-20 21:07:14 +0000
committerZachary Turner <zturner@google.com>2014-06-20 21:07:14 +0000
commit91e18f7639c61ca40efe39efbfcba825570a824e (patch)
treedd4ecf9c26f55bb430daef6c1efb180b3a48cca4 /lib/ExecutionEngine
parent5b8e73ef81bdbc3ce4d020f66d875e22827b7626 (diff)
downloadllvm-91e18f7639c61ca40efe39efbfcba825570a824e.tar.gz
llvm-91e18f7639c61ca40efe39efbfcba825570a824e.tar.bz2
llvm-91e18f7639c61ca40efe39efbfcba825570a824e.tar.xz
Revert "Replace Execution Engine's mutex with std::recursive_mutex."
This reverts commit 1f502bd9d7d2c1f98ad93a09ffe435e11a95aedd, due to GCC / MinGW's lack of support for C++11 threading. It's possible this will go back in after we come up with a reasonable solution. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211401 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/ExecutionEngine.cpp16
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp38
-rw-r--r--lib/ExecutionEngine/JIT/JITEmitter.cpp22
-rw-r--r--lib/ExecutionEngine/MCJIT/MCJIT.cpp37
4 files changed, 57 insertions, 56 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp
index 553ceb4575..9154fe2f5f 100644
--- a/lib/ExecutionEngine/ExecutionEngine.cpp
+++ b/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -166,7 +166,7 @@ void *ExecutionEngineState::RemoveMapping(const GlobalValue *ToUnmap) {
}
void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
DEBUG(dbgs() << "JIT: Map \'" << GV->getName()
<< "\' to [" << Addr << "]\n";);
@@ -184,14 +184,14 @@ void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
}
void ExecutionEngine::clearAllGlobalMappings() {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
EEState.getGlobalAddressMap().clear();
EEState.getGlobalAddressReverseMap().clear();
}
void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
EEState.RemoveMapping(FI);
@@ -201,7 +201,7 @@ void ExecutionEngine::clearGlobalMappingsFromModule(Module *M) {
}
void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
ExecutionEngineState::GlobalAddressMapTy &Map =
EEState.getGlobalAddressMap();
@@ -228,7 +228,7 @@ void *ExecutionEngine::updateGlobalMapping(const GlobalValue *GV, void *Addr) {
}
void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
ExecutionEngineState::GlobalAddressMapTy::iterator I =
EEState.getGlobalAddressMap().find(GV);
@@ -236,7 +236,7 @@ void *ExecutionEngine::getPointerToGlobalIfAvailable(const GlobalValue *GV) {
}
const GlobalValue *ExecutionEngine::getGlobalValueAtAddress(void *Addr) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// If we haven't computed the reverse mapping yet, do so first.
if (EEState.getGlobalAddressReverseMap().empty()) {
@@ -555,7 +555,7 @@ void *ExecutionEngine::getPointerToGlobal(const GlobalValue *GV) {
if (Function *F = const_cast<Function*>(dyn_cast<Function>(GV)))
return getPointerToFunction(F);
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
if (void *P = EEState.getGlobalAddressMap()[GV])
return P;
@@ -1346,7 +1346,7 @@ ExecutionEngineState::ExecutionEngineState(ExecutionEngine &EE)
: EE(EE), GlobalAddressMap(this) {
}
-std::recursive_mutex *
+sys::Mutex *
ExecutionEngineState::AddressMapConfig::getMutex(ExecutionEngineState *EES) {
return &EES->EE.lock;
}
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index 463fa299b3..83ec9784b9 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -96,18 +96,18 @@ namespace {
/// bugpoint or gdb users to search for a function by name without any context.
class JitPool {
SmallPtrSet<JIT*, 1> JITs; // Optimize for process containing just 1 JIT.
- mutable std::recursive_mutex Lock;
+ mutable sys::Mutex Lock;
public:
void Add(JIT *jit) {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
JITs.insert(jit);
}
void Remove(JIT *jit) {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
JITs.erase(jit);
}
void *getPointerToNamedFunction(const char *Name) const {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
assert(JITs.size() != 0 && "No Jit registered");
//search function in every instance of JIT
for (SmallPtrSet<JIT*, 1>::const_iterator Jit = JITs.begin(),
@@ -150,7 +150,7 @@ JIT::JIT(Module *M, TargetMachine &tm, TargetJITInfo &tji,
AllJits->Add(this);
// Add target data
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
FunctionPassManager &PM = jitstate->getPM();
M->setDataLayout(TM.getDataLayout());
PM.add(new DataLayoutPass(M));
@@ -177,7 +177,7 @@ JIT::~JIT() {
/// addModule - Add a new Module to the JIT. If we previously removed the last
/// Module, we need re-initialize jitstate with a valid Module.
void JIT::addModule(Module *M) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
if (Modules.empty()) {
assert(!jitstate && "jitstate should be NULL if Modules vector is empty!");
@@ -206,7 +206,7 @@ void JIT::addModule(Module *M) {
bool JIT::removeModule(Module *M) {
bool result = ExecutionEngine::removeModule(M);
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
if (jitstate && jitstate->getModule() == M) {
delete jitstate;
@@ -408,13 +408,13 @@ GenericValue JIT::runFunction(Function *F,
void JIT::RegisterJITEventListener(JITEventListener *L) {
if (!L)
return;
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
EventListeners.push_back(L);
}
void JIT::UnregisterJITEventListener(JITEventListener *L) {
if (!L)
return;
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
std::vector<JITEventListener*>::reverse_iterator I=
std::find(EventListeners.rbegin(), EventListeners.rend(), L);
if (I != EventListeners.rend()) {
@@ -426,14 +426,14 @@ void JIT::NotifyFunctionEmitted(
const Function &F,
void *Code, size_t Size,
const JITEvent_EmittedFunctionDetails &Details) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFunctionEmitted(F, Code, Size, Details);
}
}
void JIT::NotifyFreeingMachineCode(void *OldPtr) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFreeingMachineCode(OldPtr);
}
@@ -444,7 +444,7 @@ void JIT::NotifyFreeingMachineCode(void *OldPtr) {
/// GlobalAddress[F] with the address of F's machine code.
///
void JIT::runJITOnFunction(Function *F, MachineCodeInfo *MCI) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
class MCIListener : public JITEventListener {
MachineCodeInfo *const MCI;
@@ -505,7 +505,7 @@ void *JIT::getPointerToFunction(Function *F) {
if (void *Addr = getPointerToGlobalIfAvailable(F))
return Addr; // Check if function already code gen'd
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// Now that this thread owns the lock, make sure we read in the function if it
// exists in this Module.
@@ -534,7 +534,7 @@ void *JIT::getPointerToFunction(Function *F) {
}
void JIT::addPointerToBasicBlock(const BasicBlock *BB, void *Addr) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
BasicBlockAddressMapTy::iterator I =
getBasicBlockAddressMap().find(BB);
@@ -546,7 +546,7 @@ void JIT::addPointerToBasicBlock(const BasicBlock *BB, void *Addr) {
}
void JIT::clearPointerToBasicBlock(const BasicBlock *BB) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
getBasicBlockAddressMap().erase(BB);
}
@@ -555,7 +555,7 @@ void *JIT::getPointerToBasicBlock(BasicBlock *BB) {
(void)getPointerToFunction(BB->getParent());
// resolve basic block address
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
BasicBlockAddressMapTy::iterator I =
getBasicBlockAddressMap().find(BB);
@@ -592,7 +592,7 @@ void *JIT::getPointerToNamedFunction(const std::string &Name,
/// variable, possibly emitting it to memory if needed. This is used by the
/// Emitter.
void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
void *Ptr = getPointerToGlobalIfAvailable(GV);
if (Ptr) return Ptr;
@@ -666,7 +666,7 @@ char* JIT::getMemoryForGV(const GlobalVariable* GV) {
size_t S = getDataLayout()->getTypeAllocSize(GlobalType);
size_t A = getDataLayout()->getPreferredAlignment(GV);
if (GV->isThreadLocal()) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
Ptr = TJI.allocateThreadLocalMemory(S);
} else if (TJI.allocateSeparateGVMemory()) {
if (A <= 8) {
@@ -687,7 +687,7 @@ char* JIT::getMemoryForGV(const GlobalVariable* GV) {
}
void JIT::addPendingFunction(Function *F) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
jitstate->getPendingFunctions().push_back(F);
}
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index 1e1f5d5580..50b8c10b63 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -40,6 +40,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Memory.h"
+#include "llvm/Support/MutexGuard.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetJITInfo.h"
@@ -49,7 +50,6 @@
#ifndef NDEBUG
#include <iomanip>
#endif
-#include <mutex>
using namespace llvm;
#define DEBUG_TYPE "jit"
@@ -230,22 +230,22 @@ namespace {
std::map<void*, JITResolver*> Map;
/// Guards Map from concurrent accesses.
- mutable std::recursive_mutex Lock;
+ mutable sys::Mutex Lock;
public:
/// Registers a Stub to be resolved by Resolver.
void RegisterStubResolver(void *Stub, JITResolver *Resolver) {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
Map.insert(std::make_pair(Stub, Resolver));
}
/// Unregisters the Stub when it's invalidated.
void UnregisterStubResolver(void *Stub) {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
Map.erase(Stub);
}
/// Returns the JITResolver instance that owns the Stub.
JITResolver *getResolverFromStub(void *Stub) const {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
// The address given to us for the stub may not be exactly right, it might
// be a little bit after the stub. As such, use upper_bound to find it.
// This is the same trick as in LookupFunctionFromCallSite from
@@ -258,7 +258,7 @@ namespace {
/// True if any stubs refer to the given resolver. Only used in an assert().
/// O(N)
bool ResolverHasStubs(JITResolver* Resolver) const {
- std::lock_guard<std::recursive_mutex> guard(Lock);
+ MutexGuard guard(Lock);
for (std::map<void*, JITResolver*>::const_iterator I = Map.begin(),
E = Map.end(); I != E; ++I) {
if (I->second == Resolver)
@@ -494,7 +494,7 @@ JITResolver::~JITResolver() {
/// getLazyFunctionStubIfAvailable - This returns a pointer to a function stub
/// if it has already been created.
void *JITResolver::getLazyFunctionStubIfAvailable(Function *F) {
- std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+ MutexGuard locked(TheJIT->lock);
// If we already have a stub for this function, recycle it.
return state.getFunctionToLazyStubMap().lookup(F);
@@ -503,7 +503,7 @@ void *JITResolver::getLazyFunctionStubIfAvailable(Function *F) {
/// getFunctionStub - This returns a pointer to a function stub, creating
/// one on demand as needed.
void *JITResolver::getLazyFunctionStub(Function *F) {
- std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+ MutexGuard locked(TheJIT->lock);
// If we already have a lazy stub for this function, recycle it.
void *&Stub = state.getFunctionToLazyStubMap()[F];
@@ -564,7 +564,7 @@ void *JITResolver::getLazyFunctionStub(Function *F) {
/// getGlobalValueIndirectSym - Return a lazy pointer containing the specified
/// GV address.
void *JITResolver::getGlobalValueIndirectSym(GlobalValue *GV, void *GVAddress) {
- std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+ MutexGuard locked(TheJIT->lock);
// If we already have a stub for this global variable, recycle it.
void *&IndirectSym = state.getGlobalToIndirectSymMap()[GV];
@@ -622,7 +622,7 @@ void *JITResolver::JITCompilerFn(void *Stub) {
// Only lock for getting the Function. The call getPointerToFunction made
// in this function might trigger function materializing, which requires
// JIT lock to be unlocked.
- std::lock_guard<std::recursive_mutex> guard(JR->TheJIT->lock);
+ MutexGuard locked(JR->TheJIT->lock);
// The address given to us for the stub may not be exactly right, it might
// be a little bit after the stub. As such, use upper_bound to find it.
@@ -654,7 +654,7 @@ void *JITResolver::JITCompilerFn(void *Stub) {
}
// Reacquire the lock to update the GOT map.
- std::lock_guard<std::recursive_mutex> locked(JR->TheJIT->lock);
+ MutexGuard locked(JR->TheJIT->lock);
// We might like to remove the call site from the CallSiteToFunction map, but
// we can't do that! Multiple threads could be stuck, waiting to acquire the
diff --git a/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index f149edcb7b..e9ba96a649 100644
--- a/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/lib/ExecutionEngine/MCJIT/MCJIT.cpp
@@ -26,6 +26,7 @@
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/MutexGuard.h"
#include "llvm/Target/TargetLowering.h"
using namespace llvm;
@@ -65,7 +66,7 @@ MCJIT::MCJIT(Module *m, TargetMachine *tm, RTDyldMemoryManager *MM,
}
MCJIT::~MCJIT() {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// FIXME: We are managing our modules, so we do not want the base class
// ExecutionEngine to manage them as well. To avoid double destruction
// of the first (and only) module added in ExecutionEngine constructor
@@ -101,12 +102,12 @@ MCJIT::~MCJIT() {
}
void MCJIT::addModule(Module *M) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
OwnedModules.addModule(M);
}
bool MCJIT::removeModule(Module *M) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
return OwnedModules.removeModule(M);
}
@@ -128,12 +129,12 @@ void MCJIT::addArchive(object::Archive *A) {
void MCJIT::setObjectCache(ObjectCache* NewCache) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
ObjCache = NewCache;
}
ObjectBufferStream* MCJIT::emitObject(Module *M) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// This must be a module which has already been added but not loaded to this
// MCJIT instance, since these conditions are tested by our caller,
@@ -173,7 +174,7 @@ ObjectBufferStream* MCJIT::emitObject(Module *M) {
void MCJIT::generateCodeForModule(Module *M) {
// Get a thread lock to make sure we aren't trying to load multiple times
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// This must be a module which has already been added to this MCJIT instance.
assert(OwnedModules.ownsModule(M) &&
@@ -213,7 +214,7 @@ void MCJIT::generateCodeForModule(Module *M) {
}
void MCJIT::finalizeLoadedModules() {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// Resolve any outstanding relocations.
Dyld.resolveRelocations();
@@ -229,7 +230,7 @@ void MCJIT::finalizeLoadedModules() {
// FIXME: Rename this.
void MCJIT::finalizeObject() {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
E = OwnedModules.end_added();
@@ -242,7 +243,7 @@ void MCJIT::finalizeObject() {
}
void MCJIT::finalizeModule(Module *M) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// This must be a module which has already been added to this MCJIT instance.
assert(OwnedModules.ownsModule(M) && "MCJIT::finalizeModule: Unknown module.");
@@ -267,7 +268,7 @@ uint64_t MCJIT::getExistingSymbolAddress(const std::string &Name) {
Module *MCJIT::findModuleForSymbol(const std::string &Name,
bool CheckFunctionsOnly) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// If it hasn't already been generated, see if it's in one of our modules.
for (ModulePtrSet::iterator I = OwnedModules.begin_added(),
@@ -291,7 +292,7 @@ Module *MCJIT::findModuleForSymbol(const std::string &Name,
uint64_t MCJIT::getSymbolAddress(const std::string &Name,
bool CheckFunctionsOnly)
{
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
// First, check to see if we already have this symbol.
uint64_t Addr = getExistingSymbolAddress(Name);
@@ -335,7 +336,7 @@ uint64_t MCJIT::getSymbolAddress(const std::string &Name,
}
uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
uint64_t Result = getSymbolAddress(Name, false);
if (Result != 0)
finalizeLoadedModules();
@@ -343,7 +344,7 @@ uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
}
uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
uint64_t Result = getSymbolAddress(Name, true);
if (Result != 0)
finalizeLoadedModules();
@@ -352,7 +353,7 @@ uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
// Deprecated. Use getFunctionAddress instead.
void *MCJIT::getPointerToFunction(Function *F) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
bool AbortOnFailure = !F->hasExternalWeakLinkage();
@@ -551,13 +552,13 @@ void *MCJIT::getPointerToNamedFunction(const std::string &Name,
void MCJIT::RegisterJITEventListener(JITEventListener *L) {
if (!L)
return;
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
EventListeners.push_back(L);
}
void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
if (!L)
return;
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
SmallVector<JITEventListener*, 2>::reverse_iterator I=
std::find(EventListeners.rbegin(), EventListeners.rend(), L);
if (I != EventListeners.rend()) {
@@ -566,14 +567,14 @@ void MCJIT::UnregisterJITEventListener(JITEventListener *L) {
}
}
void MCJIT::NotifyObjectEmitted(const ObjectImage& Obj) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
MemMgr.notifyObjectLoaded(this, &Obj);
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyObjectEmitted(Obj);
}
}
void MCJIT::NotifyFreeingObject(const ObjectImage& Obj) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
for (unsigned I = 0, S = EventListeners.size(); I < S; ++I) {
EventListeners[I]->NotifyFreeingObject(Obj);
}