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
diff --git a/lib/Target/X86/X86JITInfo.cpp b/lib/Target/X86/X86JITInfo.cpp
index 7b3a070..f8761dc 100644
--- a/lib/Target/X86/X86JITInfo.cpp
+++ b/lib/Target/X86/X86JITInfo.cpp
@@ -518,3 +518,13 @@
}
}
}
+
+char* X86JITInfo::allocateThreadLocalMemory(size_t size) {
+#if defined(X86_32_JIT) && !defined(__APPLE__) && !defined(_MSC_VER)
+ TLSOffset -= size;
+ return TLSOffset;
+#else
+ assert(0 && "Cannot allocate thread local storage on this arch!\n");
+ return 0;
+#endif
+}
diff --git a/lib/Target/X86/X86JITInfo.h b/lib/Target/X86/X86JITInfo.h
index f9fcefe..6b8d197 100644
--- a/lib/Target/X86/X86JITInfo.h
+++ b/lib/Target/X86/X86JITInfo.h
@@ -23,8 +23,12 @@
class X86JITInfo : public TargetJITInfo {
X86TargetMachine &TM;
intptr_t PICBase;
+ char* TLSOffset;
public:
- explicit X86JITInfo(X86TargetMachine &tm) : TM(tm) {useGOT = 0;}
+ explicit X86JITInfo(X86TargetMachine &tm) : TM(tm) {
+ useGOT = 0;
+ TLSOffset = 0;
+ }
/// replaceMachineCodeForFunction - Make it so that calling the function
/// whose machine code is at OLD turns into a call to NEW, perhaps by
@@ -56,6 +60,11 @@
/// referenced global symbols.
virtual void relocate(void *Function, MachineRelocation *MR,
unsigned NumRelocs, unsigned char* GOTBase);
+
+ /// allocateThreadLocalMemory - Each target has its own way of
+ /// handling thread local variables. This method returns a value only
+ /// meaningful to the target.
+ virtual char* allocateThreadLocalMemory(size_t size);
/// setPICBase / getPICBase - Getter / setter of PICBase, used to compute
/// PIC jumptable entry.