|
@@ -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);
|
|
|
}
|