[llvm-commits] [llvm] r58338 - in /llvm/trunk: include/llvm/Target/TargetJITInfo.h lib/ExecutionEngine/JIT/JITEmitter.cpp lib/Target/ARM/ARMCodeEmitter.cpp lib/Target/ARM/ARMJITInfo.h

Jim Grosbach grosbach at apple.com
Tue Oct 28 11:25:50 PDT 2008


Author: grosbach
Date: Tue Oct 28 13:25:49 2008
New Revision: 58338

URL: http://llvm.org/viewvc/llvm-project?rev=58338&view=rev
Log:
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.

Modified:
    llvm/trunk/include/llvm/Target/TargetJITInfo.h
    llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
    llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp
    llvm/trunk/lib/Target/ARM/ARMJITInfo.h

Modified: llvm/trunk/include/llvm/Target/TargetJITInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetJITInfo.h?rev=58338&r1=58337&r2=58338&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetJITInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetJITInfo.h Tue Oct 28 13:25:49 2008
@@ -107,6 +107,15 @@
     // JIT to manage a GOT for it.
     bool needsGOT() const { return useGOT; }
 
+    /// hasCustomConstantPool - Allows a target to specify that constant
+    /// pool address resolution is handled by the target.
+    virtual bool hasCustomConstantPool() const { return false; }
+
+    /// getCustomConstantPoolEntryAddress - When using a custom constant
+    /// pool, resolve a constant pool index to the address of where the
+    /// entry is stored.
+    virtual intptr_t getCustomConstantPoolEntryAddress(unsigned CPI) const 
+      {return 0;}
   protected:
     bool useGOT;
   };

Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=58338&r1=58337&r2=58338&view=diff

==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Tue Oct 28 13:25:49 2008
@@ -1011,6 +1011,11 @@
 }
 
 void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
+  if (TheJIT->getJITInfo().hasCustomConstantPool()) {
+    DOUT << "JIT: Target has custom constant pool handling. Omitting standard "
+            "constant pool\n";
+    return;
+  }
   const std::vector<MachineConstantPoolEntry> &Constants = MCP->getConstants();
   if (Constants.empty()) return;
 
@@ -1124,6 +1129,10 @@
 // method.
 //
 intptr_t JITEmitter::getConstantPoolEntryAddress(unsigned ConstantNum) const {
+  if (TheJIT->getJITInfo().hasCustomConstantPool()) {
+    return TheJIT->getJITInfo().getCustomConstantPoolEntryAddress(ConstantNum);
+  }
+
   assert(ConstantNum < ConstantPool->getConstants().size() &&
          "Invalid ConstantPoolIndex!");
   return (intptr_t)ConstantPoolBase +

Modified: llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp?rev=58338&r1=58337&r2=58338&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMCodeEmitter.cpp Tue Oct 28 13:25:49 2008
@@ -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) {

Modified: llvm/trunk/lib/Target/ARM/ARMJITInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMJITInfo.h?rev=58338&r1=58337&r2=58338&view=diff

==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMJITInfo.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMJITInfo.h Tue Oct 28 13:25:49 2008
@@ -15,14 +15,16 @@
 #define ARMJITINFO_H
 
 #include "llvm/Target/TargetJITInfo.h"
+#include <map>
 
 namespace llvm {
   class ARMTargetMachine;
 
   class ARMJITInfo : public TargetJITInfo {
     ARMTargetMachine &TM;
+    std::map<unsigned, intptr_t> CPIDtoAddressMap;
   public:
-    explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) {useGOT = 0;}
+    explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
 
     /// replaceMachineCodeForFunction - Make it so that calling the function
     /// whose machine code is at OLD turns into a call to NEW, perhaps by
@@ -45,6 +47,27 @@
     /// referenced global symbols.
     virtual void relocate(void *Function, MachineRelocation *MR,
                           unsigned NumRelocs, unsigned char* GOTBase);
+  
+    /// hasCustomConstantPool - Allows a target to specify that constant
+    /// pool address resolution is handled by the target.
+    virtual bool hasCustomConstantPool() const { return true; }
+
+    /// getCustomConstantPoolEntryAddress - The ARM target puts all constant
+    /// pool entries into constant islands. Resolve the constant pool index
+    /// into the address where the constant is stored.
+    virtual intptr_t getCustomConstantPoolEntryAddress(unsigned CPID) const
+      {
+        std::map<unsigned, intptr_t>::const_iterator elem;
+        elem = CPIDtoAddressMap.find(CPID);
+        assert (elem != CPIDtoAddressMap.end());
+        return elem->second;
+      }
+
+    /// mapCPIDtoAddress - Map a Constant Pool Index (CPID) to the address
+    /// where its associated value is stored. When relocations are processed,
+    /// this value will be used to resolve references to the constant.
+    void mapCPIDtoAddress(unsigned CPID, intptr_t address)
+      { CPIDtoAddressMap[CPID] = address; }
   };
 }
 





More information about the llvm-commits mailing list