llvm.org GIT mirror llvm / be20773
Add a new DenseSet abstraction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@42474 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
2 changed file(s) with 65 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
0 //===- llvm/ADT/DenseSet.h - Dense probed hash table ------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by Chris Lattner and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the DenseSet class.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_ADT_DENSESET_H
14 #define LLVM_ADT_DENSESET_H
15
16 #include "llvm/ADT/DenseMap.h"
17
18 namespace llvm {
19
20 /// DenseSet - This implements a dense probed hash-table based set.
21 ///
22 /// FIXME: This is currently implemented directly in terms of DenseMap, this
23 /// should be optimized later if there is a need.
24 template >
25 class DenseSet {
26 DenseMap TheMap;
27 public:
28 DenseSet(const DenseSet &Other) : TheMap(Other.TheMap) {}
29 explicit DenseSet(unsigned NumInitBuckets = 64) : TheMap(NumInitBuckets) {}
30
31 bool empty() const { return TheMap.empty(); }
32 unsigned size() const { return TheMap.size(); }
33
34 // TODO add iterators.
35
36 void clear() {
37 TheMap.clear();
38 }
39
40 bool count(const ValueT &V) {
41 return TheMap.count(V);
42 }
43
44 void insert(const ValueT &V) {
45 TheMap[V] = 0;
46 }
47
48 void erase(const ValueT &V) {
49 TheMap.erase(V);
50 }
51
52 DenseSet &operator=(const DenseSet &RHS) {
53 TheMap = RHS.TheMap;
54 return *this;
55 }
56 };
57
58 } // end namespace llvm
59
60 #endif
6464 #include "llvm/Support/Debug.h"
6565 #include "llvm/ADT/Statistic.h"
6666 #include "llvm/ADT/SparseBitVector.h"
67 #include "llvm/ADT/DenseMap.h"
67 #include "llvm/ADT/DenseSet.h"
6868 #include
6969 #include
7070 #include
17721772 /// replaced by their the pointer equivalence class representative.
17731773 void Andersens::RewriteConstraints() {
17741774 std::vector NewConstraints;
1775 DenseMap, ConstraintKeyInfo> Seen;
1775 DenseSet, ConstraintKeyInfo> Seen;
17761776
17771777 PEClass2Node.clear();
17781778 PENLEClass2Node.clear();
18101810 C.Src = FindEquivalentNode(RHSNode, RHSLabel);
18111811 C.Dest = FindEquivalentNode(FindNode(LHSNode), LHSLabel);
18121812 if (C.Src == C.Dest && C.Type == Constraint::Copy
1813 || Seen[C] == true)
1813 || Seen.count(C))
18141814 continue;
18151815
1816 Seen[C] = true;
1816 Seen.insert(C);
18171817 NewConstraints.push_back(C);
18181818 }
18191819 Constraints.swap(NewConstraints);