diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h index e584973e4f1..df8f464adaf 100644 --- a/include/llvm/ADT/DenseMap.h +++ b/include/llvm/ADT/DenseMap.h @@ -43,6 +43,48 @@ struct DenseMapInfo { static bool isPod() { return true; } }; +// Provide DenseMapInfo for unsigned ints. +template<> struct DenseMapInfo { + 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 +struct DenseMapInfo > { + typedef std::pair Pair; + typedef DenseMapInfo FirstInfo; + typedef DenseMapInfo 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 ValueInfoT = DenseMapInfo > diff --git a/include/llvm/CodeGen/LiveIntervalAnalysis.h b/include/llvm/CodeGen/LiveIntervalAnalysis.h index d588190cc43..a43c2d4b982 100644 --- a/include/llvm/CodeGen/LiveIntervalAnalysis.h +++ b/include/llvm/CodeGen/LiveIntervalAnalysis.h @@ -55,20 +55,6 @@ namespace llvm { } }; - // Provide DenseMapInfo for unsigned. - template<> - struct DenseMapInfo { - 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_; diff --git a/lib/CodeGen/RegAllocLocal.cpp b/lib/CodeGen/RegAllocLocal.cpp index a660e00aa8b..5946e749022 100644 --- a/lib/CodeGen/RegAllocLocal.cpp +++ b/lib/CodeGen/RegAllocLocal.cpp @@ -561,18 +561,6 @@ static bool precedes(MachineBasicBlock::iterator A, return false; } -namespace llvm { - template<> struct DenseMapInfo { - 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) { diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index a8b4905a4cf..272ad1b99b9 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -682,18 +682,6 @@ void ValueTable::erase(Value* V) { // GVN Pass //===----------------------------------------------------------------------===// -namespace llvm { - template<> struct DenseMapInfo { - 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;