Skip to content

Commit 5fc8ab6

Browse files
committed
consolidate DenseMapInfo implementations, and add one for std::pair.
Patch contributed by m-s. llvm-svn: 55167
1 parent 41e0881 commit 5fc8ab6

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

llvm/include/llvm/ADT/DenseMap.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,48 @@ struct DenseMapInfo<T*> {
4343
static bool isPod() { return true; }
4444
};
4545

46+
// Provide DenseMapInfo for unsigned ints.
47+
template<> struct DenseMapInfo<uint32_t> {
48+
static inline uint32_t getEmptyKey() { return ~0; }
49+
static inline uint32_t getTombstoneKey() { return ~0 - 1; }
50+
static unsigned getHashValue(const uint32_t& Val) { return Val * 37; }
51+
static bool isPod() { return true; }
52+
static bool isEqual(const uint32_t& LHS, const uint32_t& RHS) {
53+
return LHS == RHS;
54+
}
55+
};
56+
57+
// Provide DenseMapInfo for all pairs whose members have info.
58+
template<typename T, typename U>
59+
struct DenseMapInfo<std::pair<T, U> > {
60+
typedef std::pair<T, U> Pair;
61+
typedef DenseMapInfo<T> FirstInfo;
62+
typedef DenseMapInfo<U> SecondInfo;
63+
64+
static inline Pair getEmptyKey() {
65+
return std::make_pair(FirstInfo::getEmptyKey(),
66+
SecondInfo::getEmptyKey());
67+
}
68+
static inline Pair getTombstoneKey() {
69+
return std::make_pair(FirstInfo::getTombstoneKey(),
70+
SecondInfo::getEmptyKey()); }
71+
static unsigned getHashValue(const Pair& PairVal) {
72+
uint64_t key = (uint64_t)FirstInfo::getHashValue(PairVal.first) << 32
73+
| (uint64_t)SecondInfo::getHashValue(PairVal.second);
74+
key += ~(key << 32);
75+
key ^= (key >> 22);
76+
key += ~(key << 13);
77+
key ^= (key >> 8);
78+
key += (key << 3);
79+
key ^= (key >> 15);
80+
key += ~(key << 27);
81+
key ^= (key >> 31);
82+
return (unsigned)key;
83+
}
84+
static bool isEqual(const Pair& LHS, const Pair& RHS) { return LHS == RHS; }
85+
static bool isPod() { return false; }
86+
};
87+
4688
template<typename KeyT, typename ValueT,
4789
typename KeyInfoT = DenseMapInfo<KeyT>,
4890
typename ValueInfoT = DenseMapInfo<ValueT> >

llvm/include/llvm/CodeGen/LiveIntervalAnalysis.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,6 @@ namespace llvm {
5555
}
5656
};
5757

58-
// Provide DenseMapInfo for unsigned.
59-
template<>
60-
struct DenseMapInfo<unsigned> {
61-
static inline unsigned getEmptyKey() { return (unsigned)-1; }
62-
static inline unsigned getTombstoneKey() { return (unsigned)-2; }
63-
static unsigned getHashValue(const unsigned Val) {
64-
return Val * 37;
65-
}
66-
static bool isEqual(const unsigned LHS, const unsigned RHS) {
67-
return LHS == RHS;
68-
}
69-
static bool isPod() { return true; }
70-
};
71-
7258
class LiveIntervals : public MachineFunctionPass {
7359
MachineFunction* mf_;
7460
MachineRegisterInfo* mri_;

llvm/lib/CodeGen/RegAllocLocal.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -561,18 +561,6 @@ static bool precedes(MachineBasicBlock::iterator A,
561561
return false;
562562
}
563563

564-
namespace llvm {
565-
template<> struct DenseMapInfo<uint32_t> {
566-
static inline uint32_t getEmptyKey() { return ~0; }
567-
static inline uint32_t getTombstoneKey() { return ~0 - 1; }
568-
static unsigned getHashValue(const uint32_t& Val) { return Val * 37; }
569-
static bool isPod() { return true; }
570-
static bool isEqual(const uint32_t& LHS, const uint32_t& RHS) {
571-
return LHS == RHS;
572-
}
573-
};
574-
}
575-
576564
/// ComputeLocalLiveness - Computes liveness of registers within a basic
577565
/// block, setting the killed/dead flags as appropriate.
578566
void RALocal::ComputeLocalLiveness(MachineBasicBlock& MBB) {

llvm/lib/Transforms/Scalar/GVN.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -682,18 +682,6 @@ void ValueTable::erase(Value* V) {
682682
// GVN Pass
683683
//===----------------------------------------------------------------------===//
684684

685-
namespace llvm {
686-
template<> struct DenseMapInfo<uint32_t> {
687-
static inline uint32_t getEmptyKey() { return ~0; }
688-
static inline uint32_t getTombstoneKey() { return ~0 - 1; }
689-
static unsigned getHashValue(const uint32_t& Val) { return Val * 37; }
690-
static bool isPod() { return true; }
691-
static bool isEqual(const uint32_t& LHS, const uint32_t& RHS) {
692-
return LHS == RHS;
693-
}
694-
};
695-
}
696-
697685
namespace {
698686
struct VISIBILITY_HIDDEN ValueNumberScope {
699687
ValueNumberScope* parent;

0 commit comments

Comments
 (0)