aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine/JIT
diff options
context:
space:
mode:
authorNicolas Geoffray <nicolas.geoffray@lip6.fr>2008-10-25 15:41:43 +0000
committerNicolas Geoffray <nicolas.geoffray@lip6.fr>2008-10-25 15:41:43 +0000
commit46fa139e26be6ebc00be2fb45820c2560dd22a32 (patch)
treef7c8ee9b2e72cf5f751e6bd23b2ce782a1b3e01a /lib/ExecutionEngine/JIT
parentb74f370e437de31b53496e86f024b533ee8ec91b (diff)
downloadexternal_llvm-46fa139e26be6ebc00be2fb45820c2560dd22a32.zip
external_llvm-46fa139e26be6ebc00be2fb45820c2560dd22a32.tar.gz
external_llvm-46fa139e26be6ebc00be2fb45820c2560dd22a32.tar.bz2
Support for allocation of TLS variables in the JIT. Allocation of a global
variable is moved to the execution engine. The JIT calls the TargetJITInfo to allocate thread local storage. Currently, only linux/x86 knows how to allocate thread local global variables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58142 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/JIT')
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp21
-rw-r--r--lib/ExecutionEngine/JIT/JIT.h6
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index f57de17..b768f4d 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -562,7 +562,12 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
const Type *GlobalType = GV->getType()->getElementType();
size_t S = getTargetData()->getABITypeSize(GlobalType);
size_t A = getTargetData()->getPreferredAlignment(GV);
- Ptr = MCE->allocateSpace(S, A);
+ if (GV->isThreadLocal()) {
+ MutexGuard locked(lock);
+ Ptr = TJI.allocateThreadLocalMemory(S);
+ } else {
+ Ptr = MCE->allocateSpace(S, A);
+ }
addGlobalMapping(GV, Ptr);
EmitGlobalVariable(GV);
}
@@ -594,3 +599,17 @@ void *JIT::recompileAndRelinkFunction(Function *F) {
return Addr;
}
+/// getMemoryForGV - This method abstracts memory allocation of global
+/// variable so that the JIT can allocate thread local variables depending
+/// on the target.
+///
+char* JIT::getMemoryForGV(const GlobalVariable* GV) {
+ const Type *ElTy = GV->getType()->getElementType();
+ size_t GVSize = (size_t)getTargetData()->getABITypeSize(ElTy);
+ if (GV->isThreadLocal()) {
+ MutexGuard locked(lock);
+ return TJI.allocateThreadLocalMemory(GVSize);
+ } else {
+ return new char[GVSize];
+ }
+}
diff --git a/lib/ExecutionEngine/JIT/JIT.h b/lib/ExecutionEngine/JIT/JIT.h
index 41fa9bd..2eee2e9 100644
--- a/lib/ExecutionEngine/JIT/JIT.h
+++ b/lib/ExecutionEngine/JIT/JIT.h
@@ -134,6 +134,12 @@ public:
private:
static MachineCodeEmitter *createEmitter(JIT &J, JITMemoryManager *JMM);
void runJITOnFunction (Function *F);
+
+protected:
+
+ /// getMemoryforGV - Allocate memory for a global variable.
+ virtual char* getMemoryForGV(const GlobalVariable* GV);
+
};
} // End llvm namespace