diff options
author | Chris Lattner <sabre@nondot.org> | 2003-11-30 04:23:21 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-11-30 04:23:21 +0000 |
commit | 2c0a6a19ef42f2ad547dbc0693e55e082a21ac8b (patch) | |
tree | 2f7518920a8e5976e5cb93d8c76bdf84241c1296 /lib/ExecutionEngine | |
parent | 91de352796a52e5d18b19f0be322677b1cf6b176 (diff) | |
download | external_llvm-2c0a6a19ef42f2ad547dbc0693e55e082a21ac8b.zip external_llvm-2c0a6a19ef42f2ad547dbc0693e55e082a21ac8b.tar.gz external_llvm-2c0a6a19ef42f2ad547dbc0693e55e082a21ac8b.tar.bz2 |
Emit constants to one contiguous block, but this time, respect alignment constraints.
If this doesn't work Misha, feel free to revert it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10267 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/JIT/JITEmitter.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index 32d0651..1d04f99 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -17,11 +17,12 @@ #define _POSIX_MAPPED_FILES #endif #include "VM.h" +#include "llvm/Constant.h" +#include "llvm/Module.h" #include "llvm/CodeGen/MachineCodeEmitter.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/Target/TargetData.h" -#include "llvm/Module.h" #include "Support/Debug.h" #include "Support/Statistic.h" #include "Config/unistd.h" @@ -187,11 +188,32 @@ void Emitter::finishFunction(MachineFunction &F) { void Emitter::emitConstantPool(MachineConstantPool *MCP) { 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 = TheVM->getTargetData().getTypeSize(Ty); + unsigned Alignment = TheVM->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) { - // 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)); + void *Addr = Pool + ConstantOffset[i]; TheVM->InitializeMemory(Constants[i], Addr); ConstantPoolAddresses.push_back(Addr); } |