summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/JIT/JIT.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2005-07-12 15:51:55 +0000
committerReid Spencer <rspencer@reidspencer.com>2005-07-12 15:51:55 +0000
commit79876f52aa4ebabfbffe63334faa2fd4905234d9 (patch)
tree2a1d7e19fc8c0414f2de5893cf4bdb26f3b80c5d /llvm/lib/ExecutionEngine/JIT/JIT.cpp
parentf404981bf2d324b2e04a0b6d4b81bd28a55c0ab6 (diff)
downloadbcm5719-llvm-79876f52aa4ebabfbffe63334faa2fd4905234d9.tar.gz
bcm5719-llvm-79876f52aa4ebabfbffe63334faa2fd4905234d9.zip
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. llvm-svn: 22404
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT/JIT.cpp')
-rw-r--r--llvm/lib/ExecutionEngine/JIT/JIT.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/JIT.cpp b/llvm/lib/ExecutionEngine/JIT/JIT.cpp
index cf4e14481b8..d97f1970d51 100644
--- a/llvm/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/llvm/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;
OpenPOWER on IntegriCloud