#include "llvm/Support/MutexGuard.h"
#include "llvm/Target/TargetJITInfo.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
using namespace llvm;
sys::DynamicLibrary::LoadLibraryPermanently(nullptr, nullptr);
// If the target supports JIT code generation, create the JIT.
- if (TargetJITInfo *TJ = TM->getJITInfo()) {
+ if (TargetJITInfo *TJ = TM->getSubtargetImpl()->getJITInfo()) {
return new JIT(M, *TM, *TJ, JMM, GVsWithCode);
} else {
if (ErrorStr)
/// 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(),
: ExecutionEngine(M), TM(tm), TJI(tji),
JMM(jmm ? jmm : JITMemoryManager::CreateDefaultMemManager()),
AllocateGVsWithCode(GVsWithCode), isAlreadyCodeGenerating(false) {
- setDataLayout(TM.getDataLayout());
+ setDataLayout(TM.getSubtargetImpl()->getDataLayout());
jitstate = new JITState(M);
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());
+ M->setDataLayout(TM.getSubtargetImpl()->getDataLayout());
PM.add(new DataLayoutPass(M));
// Turn the machine code intermediate representation into bytes in memory that
/// 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!");
jitstate = new JITState(M);
FunctionPassManager &PM = jitstate->getPM();
- M->setDataLayout(TM.getDataLayout());
+ M->setDataLayout(TM.getSubtargetImpl()->getDataLayout());
PM.add(new DataLayoutPass(M));
// Turn the machine code intermediate representation into bytes in memory
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;
jitstate = new JITState(Modules[0]);
FunctionPassManager &PM = jitstate->getPM();
- M->setDataLayout(TM.getDataLayout());
+ M->setDataLayout(TM.getSubtargetImpl()->getDataLayout());
PM.add(new DataLayoutPass(M));
// Turn the machine code intermediate representation into bytes in memory
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()) {
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);
}
/// 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;
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.
}
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);
}
void JIT::clearPointerToBasicBlock(const BasicBlock *BB) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
getBasicBlockAddressMap().erase(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);
/// 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;
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) {
}
void JIT::addPendingFunction(Function *F) {
- std::lock_guard<std::recursive_mutex> locked(lock);
+ MutexGuard locked(lock);
jitstate->getPendingFunctions().push_back(F);
}