[llvm-commits] CVS: llvm/lib/ExecutionEngine/JIT/Emitter.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Nov 29 22:24:00 PST 2003


Changes in directory llvm/lib/ExecutionEngine/JIT:

Emitter.cpp updated: 1.34 -> 1.35

---
Log message:

Emit constants to one contiguous block, but this time, respect alignment constraints.

If this doesn't work Misha, feel free to revert it.


---
Diffs of the changes:  (+27 -5)

Index: llvm/lib/ExecutionEngine/JIT/Emitter.cpp
diff -u llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.34 llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.35
--- llvm/lib/ExecutionEngine/JIT/Emitter.cpp:1.34	Sat Nov 29 18:50:53 2003
+++ llvm/lib/ExecutionEngine/JIT/Emitter.cpp	Sat Nov 29 22:23:21 2003
@@ -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::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);
   }





More information about the llvm-commits mailing list