For some targets, it's not possible to place GVs in the same memory buffer as the MachineCodeEmitter allocated memory. Code and data has different read / write / execution privilege requirements.

This is a short term workaround. The current solution is for the JIT memory manager to manage code and data memory separately.

llvm-svn: 58688
This commit is contained in:
Evan Cheng 2008-11-04 09:30:48 +00:00
parent a6dee4e28f
commit 9340be4641
3 changed files with 26 additions and 0 deletions

View File

@ -110,6 +110,11 @@ namespace llvm {
/// hasCustomConstantPool - Allows a target to specify that constant /// hasCustomConstantPool - Allows a target to specify that constant
/// pool address resolution is handled by the target. /// pool address resolution is handled by the target.
virtual bool hasCustomConstantPool() const { return false; } 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: protected:
bool useGOT; bool useGOT;
}; };

View File

@ -565,6 +565,16 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
if (GV->isThreadLocal()) { if (GV->isThreadLocal()) {
MutexGuard locked(lock); MutexGuard locked(lock);
Ptr = TJI.allocateThreadLocalMemory(S); 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 { } else {
Ptr = MCE->allocateSpace(S, A); Ptr = MCE->allocateSpace(S, A);
} }

View File

@ -65,6 +65,17 @@ namespace llvm {
/// pool address resolution is handled by the target. /// pool address resolution is handled by the target.
virtual bool hasCustomConstantPool() const { return true; } 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 /// Initialize - Initialize internal stage. Get the list of constant pool
/// Resize constant pool ids to CONSTPOOL_ENTRY addresses map. /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map.
void Initialize(const std::vector<MachineConstantPoolEntry> *mcpes) { void Initialize(const std::vector<MachineConstantPoolEntry> *mcpes) {