diff options
author | Misha Brukman <brukman+llvm@gmail.com> | 2003-11-17 20:40:07 +0000 |
---|---|---|
committer | Misha Brukman <brukman+llvm@gmail.com> | 2003-11-17 20:40:07 +0000 |
commit | ef7e57018d63dd7df4c74b91d5b7f717930999ad (patch) | |
tree | 19ffc1f64c0f84f058a325cfd4cf375255d9f7c9 /lib/ExecutionEngine | |
parent | 0ca042db71a5cfa7e95e48996b7fdaecc6e313f5 (diff) | |
download | external_llvm-ef7e57018d63dd7df4c74b91d5b7f717930999ad.zip external_llvm-ef7e57018d63dd7df4c74b91d5b7f717930999ad.tar.gz external_llvm-ef7e57018d63dd7df4c74b91d5b7f717930999ad.tar.bz2 |
Emit the MachineConstantPool constants in one contiguous memory `pool'.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/JIT/JITEmitter.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index 32d0651..be60b23 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -187,13 +187,28 @@ void Emitter::finishFunction(MachineFunction &F) { void Emitter::emitConstantPool(MachineConstantPool *MCP) { const std::vector<Constant*> &Constants = MCP->getConstants(); + if (Constants.size() == 0) return; + + std::vector<unsigned> ConstantSizes; + unsigned TotalSize = 0; + // Calculate how much space we will need for all the constants for (unsigned i = 0, e = Constants.size(); i != e; ++i) { - // For now we just allocate some memory on the heap, this can be - // dramatically improved. const Type *Ty = ((Value*)Constants[i])->getType(); - void *Addr = malloc(TheVM->getTargetData().getTypeSize(Ty)); - TheVM->InitializeMemory(Constants[i], Addr); - ConstantPoolAddresses.push_back(Addr); + unsigned TySize = TheVM->getTargetData().getTypeSize(Ty); + ConstantSizes.push_back(TySize); + TotalSize += TySize; + } + // Allocate a 'pool' of memory just once + void *ConstPool = malloc(TotalSize); + if (!ConstPool) { + perror("malloc"); + abort(); + } + // Initialize each slot in the 'pool' appropriately + for (unsigned i = 0, e = Constants.size(); i != e; ++i) { + TheVM->InitializeMemory(Constants[i], ConstPool); + ConstantPoolAddresses.push_back(ConstPool); + ConstPool = (void*) ((intptr_t)ConstPool + ConstantSizes[i]); } } |