[llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
Chris Lattner
lattner at cs.uiuc.edu
Mon Jan 10 10:23:38 PST 2005
Changes in directory llvm/lib/ExecutionEngine/JIT:
JITEmitter.cpp updated: 1.61 -> 1.62
---
Log message:
Rework constant pool handling so that function constant pools are no longer
leaked to the system. Now they are destroyed with the JITMemoryManager is
destroyed.
---
Diffs of the changes: (+24 -21)
Index: llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
diff -u llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.61 llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.62
--- llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp:1.61 Sat Jan 8 14:07:03 2005
+++ llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp Mon Jan 10 12:23:22 2005
@@ -48,14 +48,17 @@
sys::MemoryBlock MemBlock; // Virtual memory block allocated RWX
unsigned char *MemBase; // Base of block of memory, start of stub mem
unsigned char *FunctionBase; // Start of the function body area
- unsigned char *CurStubPtr, *CurFunctionPtr;
+ unsigned char *ConstantPool; // Memory allocated for constant pools
+ unsigned char *CurStubPtr, *CurFunctionPtr, *CurConstantPtr;
public:
JITMemoryManager();
~JITMemoryManager();
inline unsigned char *allocateStub(unsigned StubSize);
+ inline unsigned char *allocateConstant(unsigned ConstantSize,
+ unsigned Alignment);
inline unsigned char *startFunctionBody();
- inline void endFunctionBody(unsigned char *FunctionEnd);
+ inline void endFunctionBody(unsigned char *FunctionEnd);
};
}
@@ -68,10 +71,14 @@
// Allocate stubs backwards from the function base, allocate functions forward
// from the function base.
CurStubPtr = CurFunctionPtr = FunctionBase;
+
+ ConstantPool = new unsigned char [512*1024]; // Use 512k for constant pools
+ CurConstantPtr = ConstantPool + 512*1024;
}
JITMemoryManager::~JITMemoryManager() {
sys::Memory::ReleaseRWX(MemBlock);
+ delete[] ConstantPool;
}
unsigned char *JITMemoryManager::allocateStub(unsigned StubSize) {
@@ -83,6 +90,20 @@
return CurStubPtr;
}
+unsigned char *JITMemoryManager::allocateConstant(unsigned ConstantSize,
+ unsigned Alignment) {
+ // Reserve space and align pointer.
+ CurConstantPtr -= ConstantSize;
+ CurConstantPtr =
+ (unsigned char *)((intptr_t)CurConstantPtr & ~((intptr_t)Alignment - 1));
+
+ if (CurConstantPtr < ConstantPool) {
+ std::cerr << "JIT ran out of memory for constant pools!\n";
+ abort();
+ }
+ return CurConstantPtr;
+}
+
unsigned char *JITMemoryManager::startFunctionBody() {
// Round up to an even multiple of 8 bytes, this should eventually be target
// specific.
@@ -352,30 +373,12 @@
const std::vector<Constant*> &Constants = MCP->getConstants();
if (Constants.empty()) return;
- std::vector<unsigned> ConstantOffset;
- ConstantOffset.reserve(Constants.size());
-
- // Calculate how much space we will need for all the constants, and the offset
- // each one will live in.
- unsigned TotalSize = 0;
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
const Type *Ty = Constants[i]->getType();
unsigned Size = (unsigned)TheJIT->getTargetData().getTypeSize(Ty);
unsigned Alignment = TheJIT->getTargetData().getTypeAlignment(Ty);
- // Make sure to take into account the alignment requirements of the type.
- TotalSize = (TotalSize + Alignment-1) & ~(Alignment-1);
-
- // Remember the offset this element lives at.
- ConstantOffset.push_back(TotalSize);
- TotalSize += Size; // Reserve space for the constant.
- }
- // Now that we know how much memory to allocate, do so.
- char *Pool = new char[TotalSize];
-
- // Actually output all of the constants, and remember their addresses.
- for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
- void *Addr = Pool + ConstantOffset[i];
+ void *Addr = MemMgr.allocateConstant(Size, Alignment);
TheJIT->InitializeMemory(Constants[i], Addr);
ConstantPoolAddresses.push_back(Addr);
}
More information about the llvm-commits
mailing list