Support for constant islands in the ARM JIT.

Since the ARM constant pool handling supercedes the standard LLVM constant
pool entirely, the JIT emitter does not allocate space for the constants,
nor initialize the memory. The constant pool is considered part of the 
instruction stream.

Likewise, when resolving relocations into the constant pool, a hook into
the target back end is used to resolve from the constant ID# to the
address where the constant is stored.

For now, the support in the ARM emitter is limited to 32-bit integer. Future
patches will expand this to the full range of constants necessary.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58338 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/ARM/ARMCodeEmitter.cpp b/lib/Target/ARM/ARMCodeEmitter.cpp
index 574c14e..641e1a1 100644
--- a/lib/Target/ARM/ARMCodeEmitter.cpp
+++ b/lib/Target/ARM/ARMCodeEmitter.cpp
@@ -19,6 +19,8 @@
 #include "ARMRelocations.h"
 #include "ARMSubtarget.h"
 #include "ARMTargetMachine.h"
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 #include "llvm/PassManager.h"
 #include "llvm/CodeGen/MachineCodeEmitter.h"
@@ -358,7 +360,29 @@
 }
 
 void ARMCodeEmitter::emitConstPoolInstruction(const MachineInstr &MI) {
-  // FIXME
+  unsigned CPID = MI.getOperand(0).getImm();
+  unsigned CPIndex = MI.getOperand(1).getIndex();
+  const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIndex];
+  
+  //FIXME: Can we get these here?
+  assert (!MCPE.isMachineConstantPoolEntry());
+
+  const Constant *CV = MCPE.Val.ConstVal;  
+  // FIXME: We can get other types here. Need to handle them.
+  // According to the constant island pass, everything is multiples,
+  // of 4-bytes in size, though, so that helps.
+  assert (CV->getType()->isInteger());
+  assert (cast<IntegerType>(CV->getType())->getBitWidth() == 32);
+
+  const ConstantInt *CI = dyn_cast<ConstantInt>(CV);
+  uint32_t Val = *(uint32_t*)CI->getValue().getRawData();
+
+  DOUT << "Constant pool #" << CPID << ", value '" << Val << "' @ " << 
+    (void*)MCE.getCurrentPCValue() << "\n";
+
+  if (JTI)
+    JTI->mapCPIDtoAddress(CPID, MCE.getCurrentPCValue());
+  MCE.emitWordLE(Val);
 }
 
 void ARMCodeEmitter::emitPseudoInstruction(const MachineInstr &MI) {