mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Do not make the JIT memory manager manage the memory for globals. Instead
just have the JIT malloc them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28062 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -166,9 +166,6 @@ public:
|
|||||||
/// 'Index' in the function that last called initJumpTableInfo.
|
/// 'Index' in the function that last called initJumpTableInfo.
|
||||||
///
|
///
|
||||||
virtual uint64_t getJumpTableEntryAddress(unsigned Index) = 0;
|
virtual uint64_t getJumpTableEntryAddress(unsigned Index) = 0;
|
||||||
|
|
||||||
// allocateGlobal - Allocate some space for a global variable.
|
|
||||||
virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
@@ -73,10 +73,6 @@ namespace llvm {
|
|||||||
assert(0 && "JT not implementated yet!");
|
assert(0 && "JT not implementated yet!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment) {
|
|
||||||
assert(0 && "Globals not implemented yet!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE!
|
/// JIT SPECIFIC FUNCTIONS - DO NOT IMPLEMENT THESE HERE!
|
||||||
void startFunctionStub(unsigned StubSize) {
|
void startFunctionStub(unsigned StubSize) {
|
||||||
|
@@ -301,10 +301,22 @@ void *JIT::getOrEmitGlobalVariable(const GlobalVariable *GV) {
|
|||||||
// If the global hasn't been emitted to memory yet, allocate space. We will
|
// If the global hasn't been emitted to memory yet, allocate space. We will
|
||||||
// actually initialize the global after current function has finished
|
// actually initialize the global after current function has finished
|
||||||
// compilation.
|
// compilation.
|
||||||
uint64_t S = getTargetData().getTypeSize(GV->getType()->getElementType());
|
const Type *GlobalType = GV->getType()->getElementType();
|
||||||
unsigned char A =
|
size_t S = getTargetData().getTypeSize(GlobalType);
|
||||||
getTargetData().getTypeAlignment(GV->getType()->getElementType());
|
size_t A = getTargetData().getTypeAlignment(GlobalType);
|
||||||
Ptr = MCE->allocateGlobal(S, A);
|
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));
|
||||||
|
unsigned Offset = MisAligned ? (A-MisAligned) : 0;
|
||||||
|
|
||||||
|
// Trim the tail off the memory block.
|
||||||
|
realloc(Ptr, S+Offset);
|
||||||
|
Ptr = (char*)Ptr + Offset;
|
||||||
|
}
|
||||||
state.getPendingGlobals(locked).push_back(GV);
|
state.getPendingGlobals(locked).push_back(GV);
|
||||||
}
|
}
|
||||||
addGlobalMapping(GV, Ptr);
|
addGlobalMapping(GV, Ptr);
|
||||||
|
@@ -54,9 +54,8 @@ namespace {
|
|||||||
class JITMemoryManager {
|
class JITMemoryManager {
|
||||||
std::list<sys::MemoryBlock> Blocks; // List of blocks allocated by the JIT
|
std::list<sys::MemoryBlock> Blocks; // List of blocks allocated by the JIT
|
||||||
unsigned char *FunctionBase; // Start of the function body area
|
unsigned char *FunctionBase; // Start of the function body area
|
||||||
unsigned char *GlobalBase; // Start of the Global area
|
|
||||||
unsigned char *ConstantBase; // Memory allocated for constant pools
|
unsigned char *ConstantBase; // Memory allocated for constant pools
|
||||||
unsigned char *CurStubPtr, *CurFunctionPtr, *CurConstantPtr, *CurGlobalPtr;
|
unsigned char *CurStubPtr, *CurFunctionPtr, *CurConstantPtr;
|
||||||
unsigned char *GOTBase; // Target Specific reserved memory
|
unsigned char *GOTBase; // Target Specific reserved memory
|
||||||
|
|
||||||
// centralize memory block allocation
|
// centralize memory block allocation
|
||||||
@@ -68,8 +67,6 @@ namespace {
|
|||||||
inline unsigned char *allocateStub(unsigned StubSize);
|
inline unsigned char *allocateStub(unsigned StubSize);
|
||||||
inline unsigned char *allocateConstant(unsigned ConstantSize,
|
inline unsigned char *allocateConstant(unsigned ConstantSize,
|
||||||
unsigned Alignment);
|
unsigned Alignment);
|
||||||
inline unsigned char* allocateGlobal(unsigned Size,
|
|
||||||
unsigned Alignment);
|
|
||||||
inline unsigned char *startFunctionBody();
|
inline unsigned char *startFunctionBody();
|
||||||
inline void endFunctionBody(unsigned char *FunctionEnd);
|
inline void endFunctionBody(unsigned char *FunctionEnd);
|
||||||
|
|
||||||
@@ -87,28 +84,22 @@ JITMemoryManager::JITMemoryManager(bool useGOT) {
|
|||||||
sys::MemoryBlock FunBlock = getNewMemoryBlock(16 << 20);
|
sys::MemoryBlock FunBlock = getNewMemoryBlock(16 << 20);
|
||||||
// Allocate a 1M block of memory for Constants
|
// Allocate a 1M block of memory for Constants
|
||||||
sys::MemoryBlock ConstBlock = getNewMemoryBlock(1 << 20);
|
sys::MemoryBlock ConstBlock = getNewMemoryBlock(1 << 20);
|
||||||
// Allocate a 1M Block of memory for Globals
|
|
||||||
sys::MemoryBlock GVBlock = getNewMemoryBlock(1 << 20);
|
|
||||||
|
|
||||||
Blocks.push_front(FunBlock);
|
Blocks.push_front(FunBlock);
|
||||||
Blocks.push_front(ConstBlock);
|
Blocks.push_front(ConstBlock);
|
||||||
Blocks.push_front(GVBlock);
|
|
||||||
|
|
||||||
FunctionBase = reinterpret_cast<unsigned char*>(FunBlock.base());
|
FunctionBase = reinterpret_cast<unsigned char*>(FunBlock.base());
|
||||||
ConstantBase = reinterpret_cast<unsigned char*>(ConstBlock.base());
|
ConstantBase = reinterpret_cast<unsigned char*>(ConstBlock.base());
|
||||||
GlobalBase = reinterpret_cast<unsigned char*>(GVBlock.base());
|
|
||||||
|
|
||||||
// Allocate stubs backwards from the base, allocate functions forward
|
// Allocate stubs backwards from the base, allocate functions forward
|
||||||
// from the base.
|
// from the base.
|
||||||
CurStubPtr = CurFunctionPtr = FunctionBase + 512*1024;// Use 512k for stubs
|
CurStubPtr = CurFunctionPtr = FunctionBase + 512*1024;// Use 512k for stubs
|
||||||
|
|
||||||
CurConstantPtr = ConstantBase + ConstBlock.size();
|
CurConstantPtr = ConstantBase + ConstBlock.size();
|
||||||
CurGlobalPtr = GlobalBase + GVBlock.size();
|
|
||||||
|
|
||||||
//Allocate the GOT just like a global array
|
// Allocate the GOT.
|
||||||
GOTBase = NULL;
|
GOTBase = NULL;
|
||||||
if (useGOT)
|
if (useGOT) GOTBase = (unsigned char*)malloc(sizeof(void*) * 8192);
|
||||||
GOTBase = allocateGlobal(sizeof(void*) * 8192, 8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JITMemoryManager::~JITMemoryManager() {
|
JITMemoryManager::~JITMemoryManager() {
|
||||||
@@ -145,23 +136,6 @@ unsigned char *JITMemoryManager::allocateConstant(unsigned ConstantSize,
|
|||||||
return CurConstantPtr;
|
return CurConstantPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *JITMemoryManager::allocateGlobal(unsigned Size,
|
|
||||||
unsigned Alignment) {
|
|
||||||
// Reserve space and align pointer.
|
|
||||||
CurGlobalPtr -= Size;
|
|
||||||
CurGlobalPtr =
|
|
||||||
(unsigned char *)((intptr_t)CurGlobalPtr & ~((intptr_t)Alignment - 1));
|
|
||||||
|
|
||||||
if (CurGlobalPtr < GlobalBase) {
|
|
||||||
//Either allocate another MB or 2xSize
|
|
||||||
sys::MemoryBlock GVBlock = getNewMemoryBlock(2 * Size);
|
|
||||||
GlobalBase = reinterpret_cast<unsigned char*>(GVBlock.base());
|
|
||||||
CurGlobalPtr = GlobalBase + GVBlock.size();
|
|
||||||
return allocateGlobal(Size, Alignment);
|
|
||||||
}
|
|
||||||
return CurGlobalPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char *JITMemoryManager::startFunctionBody() {
|
unsigned char *JITMemoryManager::startFunctionBody() {
|
||||||
// Round up to an even multiple of 8 bytes, this should eventually be target
|
// Round up to an even multiple of 8 bytes, this should eventually be target
|
||||||
// specific.
|
// specific.
|
||||||
@@ -453,7 +427,6 @@ public:
|
|||||||
|
|
||||||
virtual uint64_t getConstantPoolEntryAddress(unsigned Entry);
|
virtual uint64_t getConstantPoolEntryAddress(unsigned Entry);
|
||||||
virtual uint64_t getJumpTableEntryAddress(unsigned Entry);
|
virtual uint64_t getJumpTableEntryAddress(unsigned Entry);
|
||||||
virtual unsigned char* allocateGlobal(unsigned size, unsigned alignment);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *getPointerToGlobal(GlobalValue *GV, void *Reference, bool NoNeedStub);
|
void *getPointerToGlobal(GlobalValue *GV, void *Reference, bool NoNeedStub);
|
||||||
@@ -681,11 +654,6 @@ uint64_t JITEmitter::getJumpTableEntryAddress(unsigned Index) {
|
|||||||
return (intptr_t)((char *)JumpTableBase + Offset);
|
return (intptr_t)((char *)JumpTableBase + Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char* JITEmitter::allocateGlobal(unsigned size, unsigned alignment)
|
|
||||||
{
|
|
||||||
return MemMgr.allocateGlobal(size, alignment);
|
|
||||||
}
|
|
||||||
|
|
||||||
// getPointerToNamedFunction - This function is used as a global wrapper to
|
// getPointerToNamedFunction - This function is used as a global wrapper to
|
||||||
// JIT::getPointerToNamedFunction for the purpose of resolving symbols when
|
// JIT::getPointerToNamedFunction for the purpose of resolving symbols when
|
||||||
// bugpoint is debugging the JIT. In that scenario, we are loading an .so and
|
// bugpoint is debugging the JIT. In that scenario, we are loading an .so and
|
||||||
|
Reference in New Issue
Block a user