For some targets, it's not possible to place GVs in the same memory buffer as the...
authorEvan Cheng <evan.cheng@apple.com>
Tue, 4 Nov 2008 09:30:48 +0000 (09:30 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Tue, 4 Nov 2008 09:30:48 +0000 (09:30 +0000)
This is a short term workaround. The current solution is for the JIT memory manager to manage code and data memory separately.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58688 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetJITInfo.h
lib/ExecutionEngine/JIT/JIT.cpp
lib/Target/ARM/ARMJITInfo.h

index 09ef15eb49f1f6aea16b2142675aa1b0df2175eb..fb89292c537c647c13fc4921446f699548de8d1a 100644 (file)
@@ -110,6 +110,11 @@ namespace llvm {
     /// hasCustomConstantPool - Allows a target to specify that constant
     /// pool address resolution is handled by the target.
     virtual bool hasCustomConstantPool() const { return false; }
+
+    /// allocateSeparateGVMemory - If true, globals should be placed in
+    /// separately allocated heap memory rather than in the same
+    /// code memory allocated by MachineCodeEmitter.
+    virtual bool allocateSeparateGVMemory() const { return false; }
   protected:
     bool useGOT;
   };
index b768f4d31c2dc265f58dae9f27e14423796981c9..83923a2b8e35a82103b94cd2fed45dc3c1656e6b 100644 (file)
@@ -565,6 +565,16 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
     if (GV->isThreadLocal()) {
       MutexGuard locked(lock);
       Ptr = TJI.allocateThreadLocalMemory(S);
+    } else if (TJI.allocateSeparateGVMemory()) {
+      if (A <= 8) {
+        Ptr = malloc(S);
+      } else {
+        // Allocate S+A bytes of memory, then use an aligned pointer within that
+        // space.
+        Ptr = malloc(S+A);
+        unsigned MisAligned = ((intptr_t)Ptr & (A-1));
+        Ptr = (char*)Ptr + (MisAligned ? (A-MisAligned) : 0);
+      }
     } else {
       Ptr = MCE->allocateSpace(S, A);
     }
index ba8768aec4baa5eaae6d4fdefcc4677b60ac72a4..2a3a7f8f37c5145e6e60915748f90bd57377147b 100644 (file)
@@ -65,6 +65,17 @@ namespace llvm {
     /// pool address resolution is handled by the target.
     virtual bool hasCustomConstantPool() const { return true; }
 
+    /// allocateSeparateGVMemory - If true, globals should be placed in
+    /// separately allocated heap memory rather than in the same
+    /// code memory allocated by MachineCodeEmitter.
+    virtual bool allocateSeparateGVMemory() const {
+#ifdef __APPLE__
+      return true;
+#else
+      return false;
+#endif
+    }
+
     /// Initialize - Initialize internal stage. Get the list of constant pool
     /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map.
     void Initialize(const std::vector<MachineConstantPoolEntry> *mcpes) {