diff options
author | Nicolas Geoffray <nicolas.geoffray@lip6.fr> | 2008-10-25 15:41:43 +0000 |
---|---|---|
committer | Nicolas Geoffray <nicolas.geoffray@lip6.fr> | 2008-10-25 15:41:43 +0000 |
commit | 46fa139e26be6ebc00be2fb45820c2560dd22a32 (patch) | |
tree | f7c8ee9b2e72cf5f751e6bd23b2ce782a1b3e01a /lib/ExecutionEngine/ExecutionEngine.cpp | |
parent | b74f370e437de31b53496e86f024b533ee8ec91b (diff) |
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/ExecutionEngine.cpp')
-rw-r--r-- | lib/ExecutionEngine/ExecutionEngine.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/ExecutionEngine/ExecutionEngine.cpp b/lib/ExecutionEngine/ExecutionEngine.cpp index 55151cb1d5..a13fdc2bb5 100644 --- a/lib/ExecutionEngine/ExecutionEngine.cpp +++ b/lib/ExecutionEngine/ExecutionEngine.cpp @@ -52,6 +52,12 @@ ExecutionEngine::~ExecutionEngine() { delete Modules[i]; } +char* ExecutionEngine::getMemoryForGV(const GlobalVariable* GV) { + const Type *ElTy = GV->getType()->getElementType(); + size_t GVSize = (size_t)getTargetData()->getABITypeSize(ElTy); + return new char[GVSize]; +} + /// removeModuleProvider - Remove a ModuleProvider from the list of modules. /// Release module from ModuleProvider. Module* ExecutionEngine::removeModuleProvider(ModuleProvider *P, @@ -873,7 +879,6 @@ void ExecutionEngine::InitializeMemory(const Constant *Init, void *Addr) { /// their initializers into the memory. /// void ExecutionEngine::emitGlobals() { - const TargetData *TD = getTargetData(); // Loop over all of the global variables in the program, allocating the memory // to hold them. If there is more than one module, do a prepass over globals @@ -934,12 +939,7 @@ void ExecutionEngine::emitGlobals() { } if (!I->isDeclaration()) { - // Get the type of the global. - const Type *Ty = I->getType()->getElementType(); - - // Allocate some memory for it! - unsigned Size = TD->getABITypeSize(Ty); - addGlobalMapping(I, new char[Size]); + addGlobalMapping(I, getMemoryForGV(I)); } else { // External variable reference. Try to use the dynamic loader to // get a pointer to it. @@ -991,15 +991,18 @@ void ExecutionEngine::EmitGlobalVariable(const GlobalVariable *GV) { void *GA = getPointerToGlobalIfAvailable(GV); DOUT << "Global '" << GV->getName() << "' -> " << GA << "\n"; - const Type *ElTy = GV->getType()->getElementType(); - size_t GVSize = (size_t)getTargetData()->getABITypeSize(ElTy); if (GA == 0) { // If it's not already specified, allocate memory for the global. - GA = new char[GVSize]; + GA = getMemoryForGV(GV); addGlobalMapping(GV, GA); } - - InitializeMemory(GV->getInitializer(), GA); + + // Don't initialize if it's thread local, let the client do it. + if (!GV->isThreadLocal()) + InitializeMemory(GV->getInitializer(), GA); + + const Type *ElTy = GV->getType()->getElementType(); + size_t GVSize = (size_t)getTargetData()->getABITypeSize(ElTy); NumInitBytes += (unsigned)GVSize; ++NumGlobals; } |