[llvm-commits] CVS: llvm/tools/lli/JIT/Emitter.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Jan 6 13:00:00 PST 2003


Changes in directory llvm/tools/lli/JIT:

Emitter.cpp updated: 1.1 -> 1.2

---
Log message:

* Add support for the constant pool
* Allocate larger blocks of memory to support big functions


---
Diffs of the changes:

Index: llvm/tools/lli/JIT/Emitter.cpp
diff -u llvm/tools/lli/JIT/Emitter.cpp:1.1 llvm/tools/lli/JIT/Emitter.cpp:1.2
--- llvm/tools/lli/JIT/Emitter.cpp:1.1	Mon Dec 23 18:01:04 2002
+++ llvm/tools/lli/JIT/Emitter.cpp	Mon Jan  6 12:59:22 2003
@@ -8,6 +8,8 @@
 #include "VM.h"
 #include "llvm/CodeGen/MachineCodeEmitter.h"
 #include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/Target/TargetData.h"
 #include "llvm/Function.h"
 #include "Support/Statistic.h"
 
@@ -22,15 +24,18 @@
     
     std::vector<std::pair<BasicBlock*, unsigned *> > BBRefs;
     std::map<BasicBlock*, unsigned> BBLocations;
+    std::vector<void*> ConstantPoolAddresses;
   public:
     Emitter(VM &vm) : TheVM(vm) {}
 
     virtual void startFunction(MachineFunction &F);
     virtual void finishFunction(MachineFunction &F);
+    virtual void emitConstantPool(MachineConstantPool *MCP);
     virtual void startBasicBlock(MachineBasicBlock &BB);
     virtual void emitByte(unsigned char B);
     virtual void emitPCRelativeDisp(Value *V);
     virtual void emitGlobalAddress(GlobalValue *V);
+    virtual void emitFunctionConstantValueAddress(unsigned ConstantNum);
   };
 }
 
@@ -44,7 +49,7 @@
 #include <sys/mman.h>
 
 static void *getMemory() {
-  return mmap(0, 4096*2, PROT_READ|PROT_WRITE|PROT_EXEC,
+  return mmap(0, 4096*8, PROT_READ|PROT_WRITE|PROT_EXEC,
               MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
 }
 
@@ -56,6 +61,7 @@
 }
 
 void Emitter::finishFunction(MachineFunction &F) {
+  ConstantPoolAddresses.clear();
   for (unsigned i = 0, e = BBRefs.size(); i != e; ++i) {
     unsigned Location = BBLocations[BBRefs[i].first];
     unsigned *Ref = BBRefs[i].second;
@@ -66,11 +72,24 @@
 
   NumBytes += CurByte-CurBlock;
 
-  DEBUG(std::cerr << "Finished CodeGen of [" << std::hex << (unsigned)CurBlock
+  DEBUG(std::cerr << "Finished CodeGen of [0x" << std::hex << (unsigned)CurBlock
                   << std::dec << "] Function: " << F.getFunction()->getName()
                   << ": " << CurByte-CurBlock << " bytes of text\n");
 }
 
+void Emitter::emitConstantPool(MachineConstantPool *MCP) {
+  const std::vector<Constant*> &Constants = MCP->getConstants();
+  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);
+  }
+}
+
+
 void Emitter::startBasicBlock(MachineBasicBlock &BB) {
   BBLocations[BB.getBasicBlock()] = (unsigned)CurByte;
 }
@@ -103,5 +122,12 @@
 
 void Emitter::emitGlobalAddress(GlobalValue *V) {
   *(void**)CurByte = TheVM.getPointerToGlobal(V);
+  CurByte += 4;
+}
+
+void Emitter::emitFunctionConstantValueAddress(unsigned ConstantNum) {
+  assert(ConstantNum < ConstantPoolAddresses.size() &&
+	 "Invalid ConstantPoolIndex!");
+  *(void**)CurByte = ConstantPoolAddresses[ConstantNum];
   CurByte += 4;
 }





More information about the llvm-commits mailing list