diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2005-07-12 15:51:55 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2005-07-12 15:51:55 +0000 |
commit | ee448630bdf7eb6037fe2c50518d32010c433ca3 (patch) | |
tree | f8ecc527ec9e16ba1b610b08cbb35e2e05e5ebef /lib/ExecutionEngine/JIT/JIT.cpp | |
parent | b2164e5cb5086f0595e96fdbb5ffc614dea9c441 (diff) |
For PR540:
This patch completes the changes for making lli thread-safe. Here's the list
of changes:
* The Support/ThreadSupport* files were removed and replaced with the
MutexGuard.h file since all ThreadSupport* declared was a Mutex Guard.
The implementation of MutexGuard.h is now based on sys::Mutex which hides
its implementation and makes it unnecessary to have the -NoSupport.h and
-PThreads.h versions of ThreadSupport.
* All places in ExecutionEngine that previously referred to "Mutex" now
refer to sys::Mutex
* All places in ExecutionEngine that previously referred to "MutexLocker"
now refer to MutexGuard (this is frivolous but I believe the technically
correct name for such a class is "Guard" not a "Locker").
These changes passed all of llvm-test. All we need now are some test cases
that actually use multiple threads.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22404 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/JIT/JIT.cpp')
-rw-r--r-- | lib/ExecutionEngine/JIT/JIT.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp index cf4e14481b..d97f1970d5 100644 --- a/lib/ExecutionEngine/JIT/JIT.cpp +++ b/lib/ExecutionEngine/JIT/JIT.cpp @@ -30,13 +30,15 @@ using namespace llvm; JIT::JIT(ModuleProvider *MP, TargetMachine &tm, TargetJITInfo &tji) - : ExecutionEngine(MP), TM(tm), TJI(tji), PM(MP) { + : ExecutionEngine(MP), TM(tm), TJI(tji), state(MP) { setTargetData(TM.getTargetData()); // Initialize MCE MCE = createEmitter(*this); // Add target data + MutexGuard locked(lock); + FunctionPassManager& PM = state.getPM(locked); PM.add(new TargetData(TM.getTargetData())); // Compile LLVM Code down to machine code in the intermediate representation @@ -216,18 +218,20 @@ GenericValue JIT::runFunction(Function *F, void JIT::runJITOnFunction(Function *F) { static bool isAlreadyCodeGenerating = false; assert(!isAlreadyCodeGenerating && "Error: Recursive compilation detected!"); + + MutexGuard locked(lock); // JIT the function isAlreadyCodeGenerating = true; - PM.run(*F); + state.getPM(locked).run(*F); isAlreadyCodeGenerating = false; // If the function referred to a global variable that had not yet been // emitted, it allocates memory for the global, but doesn't emit it yet. Emit // all of these globals now. - while (!PendingGlobals.empty()) { - const GlobalVariable *GV = PendingGlobals.back(); - PendingGlobals.pop_back(); + while (!state.getPendingGlobals(locked).empty()) { + const GlobalVariable *GV = state.getPendingGlobals(locked).back(); + state.getPendingGlobals(locked).pop_back(); EmitGlobalVariable(GV); } } @@ -236,6 +240,8 @@ void JIT::runJITOnFunction(Function *F) { /// specified function, compiling it if neccesary. /// void *JIT::getPointerToFunction(Function *F) { + MutexGuard locked(lock); + if (void *Addr = getPointerToGlobalIfAvailable(F)) return Addr; // Check if function already code gen'd @@ -270,6 +276,8 @@ void *JIT::getPointerToFunction(Function *F) { /// variable, possibly emitting it to memory if needed. This is used by the /// Emitter. void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) { + MutexGuard locked(lock); + void *Ptr = getPointerToGlobalIfAvailable(GV); if (Ptr) return Ptr; @@ -287,7 +295,7 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) { // compilation. uint64_t S = getTargetData().getTypeSize(GV->getType()->getElementType()); Ptr = new char[(size_t)S]; - PendingGlobals.push_back(GV); + state.getPendingGlobals(locked).push_back(GV); } addGlobalMapping(GV, Ptr); return Ptr; |