[llvm-commits] [llvm] r68004 - in /llvm/trunk: include/llvm/Constant.h lib/VMCore/Constants.cpp

Anton Korobeynikov asl at math.spbu.ru
Sun Mar 29 10:13:21 PDT 2009


Author: asl
Date: Sun Mar 29 12:13:18 2009
New Revision: 68004

URL: http://llvm.org/viewvc/llvm-project?rev=68004&view=rev
Log:
Extend the relocation tracker handler, so we can filter on different 'kinds' of relocations required.

Modified:
    llvm/trunk/include/llvm/Constant.h
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/include/llvm/Constant.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constant.h?rev=68004&r1=68003&r2=68004&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Constant.h (original)
+++ llvm/trunk/include/llvm/Constant.h Sun Mar 29 12:13:18 2009
@@ -19,6 +19,12 @@
 namespace llvm {
   template<typename T> class SmallVectorImpl;
 
+  namespace Reloc {
+    const unsigned Local  = 1 << 0; ///< Local relocations are required
+    const unsigned Global = 1 << 1; ///< Global relocations are required
+    const unsigned LocalOrGlobal = Local | Global;
+  }
+
 /// This is an important base class in LLVM. It provides the common facilities
 /// of all constant values in an LLVM program. A constant is a value that is
 /// immutable at runtime. Functions are constants because their address is
@@ -62,9 +68,9 @@
   /// true for things like constant expressions that could divide by zero.
   bool canTrap() const;
 
-  /// ContaintsRelocations - Return true if the constant value contains
+  /// ContainsRelocations - Return true if the constant value contains
   /// relocations which cannot be resolved at compile time.
-  bool ContainsRelocations() const;
+  bool ContainsRelocations(unsigned Kind = Reloc::LocalOrGlobal) const;
 
   // Specialize get/setOperand for Constants as their operands are always
   // constants as well.

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=68004&r1=68003&r2=68004&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Sun Mar 29 12:13:18 2009
@@ -90,14 +90,29 @@
   }
 }
 
-/// ContaintsRelocations - Return true if the constant value contains
-/// relocations which cannot be resolved at compile time.
-bool Constant::ContainsRelocations() const {
-  if (isa<GlobalValue>(this))
-    return true;
+/// ContainsRelocations - Return true if the constant value contains relocations
+/// which cannot be resolved at compile time. Kind argument is used to filter
+/// only 'interesting' sorts of relocations.
+bool Constant::ContainsRelocations(unsigned Kind) const {
+  if (const GlobalValue* GV = dyn_cast<GlobalValue>(this)) {
+    bool isLocal = GV->hasLocalLinkage();
+    if ((Kind & Reloc::Local) && isLocal) {
+      // Global has local linkage and 'local' kind of relocations are
+      // requested
+      return true;
+    }
+
+    if ((Kind & Reloc::Global) && !isLocal) {
+      // Global has non-local linkage and 'global' kind of relocations are
+      // requested
+      return true;
+    }
+  }
+
   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
     if (getOperand(i)->ContainsRelocations())
       return true;
+
   return false;
 }
 





More information about the llvm-commits mailing list