aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-08-22 05:08:25 +0000
committerChris Lattner <sabre@nondot.org>2008-08-22 05:08:25 +0000
commit2dba6a1bdb7d78b4d1e5e69b81989816193e6b70 (patch)
treeec5e62c07a7f8e8d7b108d6e1e2ebb2f77c53197
parent5f0cfa299d16e6d43577317176cab1a463c912da (diff)
consolidate DenseMapInfo implementations, and add one for std::pair.
Patch contributed by m-s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55167 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/DenseMap.h42
-rw-r--r--include/llvm/CodeGen/LiveIntervalAnalysis.h14
-rw-r--r--lib/CodeGen/RegAllocLocal.cpp12
-rw-r--r--lib/Transforms/Scalar/GVN.cpp12
4 files changed, 42 insertions, 38 deletions
diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h
index e584973e4f..df8f464ada 100644
--- a/include/llvm/ADT/DenseMap.h
+++ b/include/llvm/ADT/DenseMap.h
@@ -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> >
diff --git a/include/llvm/CodeGen/LiveIntervalAnalysis.h b/include/llvm/CodeGen/LiveIntervalAnalysis.h
index d588190cc4..a43c2d4b98 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<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_;
diff --git a/lib/CodeGen/RegAllocLocal.cpp b/lib/CodeGen/RegAllocLocal.cpp
index a660e00aa8..5946e74902 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<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) {
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index a8b4905a4c..272ad1b99b 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<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;