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 | be755279f37c02c50355780ea71b0b23d566a985 (patch) | |
tree | 14ca46f1d2a8356b3a134e69555b52bdc800804b /llvm/lib/ExecutionEngine | |
parent | fc16bb1af5b9d72526f958f27ea0227180d4c4a7 (diff) | |
download | bcm5719-llvm-be755279f37c02c50355780ea71b0b23d566a985.tar.gz bcm5719-llvm-be755279f37c02c50355780ea71b0b23d566a985.zip |
Emit the MachineConstantPool constants in one contiguous memory `pool'.
llvm-svn: 10060
Diffstat (limited to 'llvm/lib/ExecutionEngine')
-rw-r--r-- | llvm/lib/ExecutionEngine/JIT/Emitter.cpp | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/Emitter.cpp b/llvm/lib/ExecutionEngine/JIT/Emitter.cpp index 32d0651f226..be60b239a3e 100644 --- a/llvm/lib/ExecutionEngine/JIT/Emitter.cpp +++ b/llvm/lib/ExecutionEngine/JIT/Emitter.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]); } } |