consolidate DenseMapInfo implementations, and add one for std::pair.
authorChris Lattner <sabre@nondot.org>
Fri, 22 Aug 2008 05:08:25 +0000 (05:08 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 22 Aug 2008 05:08:25 +0000 (05:08 +0000)
Patch contributed by m-s.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55167 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/DenseMap.h
include/llvm/CodeGen/LiveIntervalAnalysis.h
lib/CodeGen/RegAllocLocal.cpp
lib/Transforms/Scalar/GVN.cpp

index e584973e4f177dc8294a5ef5e0f49c161d450b6b..df8f464adafd5b968bc1e9aec5142256402c4256 100644 (file)
@@ -43,6 +43,48 @@ struct DenseMapInfo<T*> {
   static bool isPod() { return true; }
 };
 
+// Provide DenseMapInfo for unsigned ints.
+template<> struct DenseMapInfo<uint32_t> {
+  static inline uint32_t getEmptyKey() { return ~0; }
+  static inline uint32_t getTombstoneKey() { return ~0 - 1; }
+  static unsigned getHashValue(const uint32_t& Val) { return Val * 37; }
+  static bool isPod() { return true; }
+  static bool isEqual(const uint32_t& LHS, const uint32_t& RHS) {
+  return LHS == RHS;
+  }
+};
+
+// Provide DenseMapInfo for all pairs whose members have info.
+template<typename T, typename U>
+struct DenseMapInfo<std::pair<T, U> > {
+  typedef std::pair<T, U> Pair;
+  typedef DenseMapInfo<T> FirstInfo;
+  typedef DenseMapInfo<U> SecondInfo;
+
+  static inline Pair getEmptyKey() { 
+    return std::make_pair(FirstInfo::getEmptyKey(), 
+                          SecondInfo::getEmptyKey()); 
+  }
+  static inline Pair getTombstoneKey() { 
+    return std::make_pair(FirstInfo::getTombstoneKey(), 
+                            SecondInfo::getEmptyKey()); }
+    static unsigned getHashValue(const Pair& PairVal) {
+      uint64_t key = (uint64_t)FirstInfo::getHashValue(PairVal.first) << 32
+            | (uint64_t)SecondInfo::getHashValue(PairVal.second);
+      key += ~(key << 32);
+      key ^= (key >> 22);
+      key += ~(key << 13);
+      key ^= (key >> 8);
+      key += (key << 3);
+      key ^= (key >> 15);
+      key += ~(key << 27);
+      key ^= (key >> 31);
+      return (unsigned)key;
+    }
+    static bool isEqual(const Pair& LHS, const Pair& RHS) { return LHS == RHS; }
+    static bool isPod() { return false; }
+};
+
 template<typename KeyT, typename ValueT, 
          typename KeyInfoT = DenseMapInfo<KeyT>,
          typename ValueInfoT = DenseMapInfo<ValueT> >
index d588190cc4365e5f4f422465bbb2bbd3016f7bac..a43c2d4b982fcc98e3b30387f1861d55126959d4 100644 (file)
@@ -55,20 +55,6 @@ namespace llvm {
     }
   };
   
-  // Provide DenseMapInfo for unsigned.
-  template<>
-  struct DenseMapInfo<unsigned> {
-    static inline unsigned getEmptyKey() { return (unsigned)-1; }
-    static inline unsigned getTombstoneKey() { return (unsigned)-2; }
-    static unsigned getHashValue(const unsigned Val) {
-      return Val * 37;
-    }
-    static bool isEqual(const unsigned LHS, const unsigned RHS) {
-      return LHS == RHS;
-    }
-    static bool isPod() { return true; }
-  };
-
   class LiveIntervals : public MachineFunctionPass {
     MachineFunction* mf_;
     MachineRegisterInfo* mri_;
index a660e00aa8b587595ae0d340e14e4c1e2662e977..5946e74902205486f2f84af8b33efeb8a5a4f3d4 100644 (file)
@@ -561,18 +561,6 @@ static bool precedes(MachineBasicBlock::iterator A,
   return false;
 }
 
-namespace llvm {
-  template<> struct DenseMapInfo<uint32_t> {
-    static inline uint32_t getEmptyKey() { return ~0; }
-    static inline uint32_t getTombstoneKey() { return ~0 - 1; }
-    static unsigned getHashValue(const uint32_t& Val) { return Val * 37; }
-    static bool isPod() { return true; }
-    static bool isEqual(const uint32_t& LHS, const uint32_t& RHS) {
-      return LHS == RHS;
-    }
-  };
-}
-
 /// ComputeLocalLiveness - Computes liveness of registers within a basic
 /// block, setting the killed/dead flags as appropriate.
 void RALocal::ComputeLocalLiveness(MachineBasicBlock& MBB) {
index a8b4905a4cfc269245a408ec5939e4ac67f68e47..272ad1b99b9b0951f698e6409b04644a878bee43 100644 (file)
@@ -682,18 +682,6 @@ void ValueTable::erase(Value* V) {
 //                         GVN Pass
 //===----------------------------------------------------------------------===//
 
-namespace llvm {
-  template<> struct DenseMapInfo<uint32_t> {
-    static inline uint32_t getEmptyKey() { return ~0; }
-    static inline uint32_t getTombstoneKey() { return ~0 - 1; }
-    static unsigned getHashValue(const uint32_t& Val) { return Val * 37; }
-    static bool isPod() { return true; }
-    static bool isEqual(const uint32_t& LHS, const uint32_t& RHS) {
-      return LHS == RHS;
-    }
-  };
-}
-
 namespace {
   struct VISIBILITY_HIDDEN ValueNumberScope {
     ValueNumberScope* parent;