[llvm-commits] [llvm] r76678 - in /llvm/trunk: include/llvm/CodeGen/MachineConstantPool.h lib/CodeGen/MachineFunction.cpp lib/Target/ARM/ARMConstantPoolValue.h

Chris Lattner sabre at nondot.org
Tue Jul 21 16:34:23 PDT 2009


Author: lattner
Date: Tue Jul 21 18:34:23 2009
New Revision: 76678

URL: http://llvm.org/viewvc/llvm-project?rev=76678&view=rev
Log:
add an API so target-independent codegen can determine if a constant
pool entry will require relocations against it.  I implemented this
conservatively for ARM, someone who is knowledgable about it should
see if this can be improved.

Modified:
    llvm/trunk/include/llvm/CodeGen/MachineConstantPool.h
    llvm/trunk/lib/CodeGen/MachineFunction.cpp
    llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.h

Modified: llvm/trunk/include/llvm/CodeGen/MachineConstantPool.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineConstantPool.h?rev=76678&r1=76677&r2=76678&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineConstantPool.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineConstantPool.h Tue Jul 21 18:34:23 2009
@@ -41,8 +41,22 @@
 
   /// getType - get type of this MachineConstantPoolValue.
   ///
-  inline const Type *getType() const { return Ty; }
+  const Type *getType() const { return Ty; }
 
+  
+  /// getRelocatationInfo - This method classifies the entry according to
+  /// whether or not it may generate a relocation entry.  This must be
+  /// conservative, so if it might codegen to a relocatable entry, it should say
+  /// so.  The return values are:
+  /// 
+  ///  0: This constant pool entry is guaranteed to never have a relocation
+  ///     applied to it (because it holds a simple constant like '4').
+  ///  1: This entry has relocations, but the entries are guaranteed to be
+  ///     resolvable by the static linker, so the dynamic linker will never see
+  ///     them.
+  ///  2: This entry may have arbitrary relocations. 
+  virtual unsigned getRelocatationInfo() const = 0;
+  
   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
                                         unsigned Alignment) = 0;
 
@@ -94,6 +108,19 @@
   }
 
   const Type *getType() const;
+  
+  /// getRelocatationInfo - This method classifies the entry according to
+  /// whether or not it may generate a relocation entry.  This must be
+  /// conservative, so if it might codegen to a relocatable entry, it should say
+  /// so.  The return values are:
+  /// 
+  ///  0: This constant pool entry is guaranteed to never have a relocation
+  ///     applied to it (because it holds a simple constant like '4').
+  ///  1: This entry has relocations, but the entries are guaranteed to be
+  ///     resolvable by the static linker, so the dynamic linker will never see
+  ///     them.
+  ///  2: This entry may have arbitrary relocations. 
+  unsigned getRelocatationInfo() const;
 };
   
 /// The MachineConstantPool class keeps track of constants referenced by a

Modified: llvm/trunk/lib/CodeGen/MachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineFunction.cpp?rev=76678&r1=76677&r2=76678&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/MachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineFunction.cpp Tue Jul 21 18:34:23 2009
@@ -539,10 +539,29 @@
 
 const Type *MachineConstantPoolEntry::getType() const {
   if (isMachineConstantPoolEntry())
-      return Val.MachineCPVal->getType();
+    return Val.MachineCPVal->getType();
   return Val.ConstVal->getType();
 }
 
+
+unsigned MachineConstantPoolEntry::getRelocatationInfo() const {
+  if (isMachineConstantPoolEntry())
+    return Val.MachineCPVal->getRelocatationInfo();
+  
+  // FIXME: This API sucks.
+  
+  // If no relocations, return 0.
+  if (!Val.ConstVal->ContainsRelocations())
+    return 0;
+
+  // If it contains no global relocations, return 1.
+  if (!Val.ConstVal->ContainsRelocations(Reloc::Global))
+    return 1;
+
+  // Otherwise, it has general relocations.
+  return 2;
+}
+
 MachineConstantPool::~MachineConstantPool() {
   for (unsigned i = 0, e = Constants.size(); i != e; ++i)
     if (Constants[i].isMachineConstantPoolEntry())

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

==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.h (original)
+++ llvm/trunk/lib/Target/ARM/ARMConstantPoolValue.h Tue Jul 21 18:34:23 2009
@@ -65,6 +65,13 @@
   bool isStub() const { return Kind == ARMCP::CPStub; }
   unsigned char getPCAdjustment() const { return PCAdjust; }
 
+  virtual unsigned getRelocatationInfo() const {
+    // FIXME: This is conservatively claiming that these entries require a
+    // relocation, we may be able to do better than this.
+    return 2;
+  }
+
+  
   virtual int getExistingMachineCPValue(MachineConstantPool *CP,
                                         unsigned Alignment);
 





More information about the llvm-commits mailing list