15 #ifndef LLVM_ADT_EQUIVALENCECLASSES_H
16 #define LLVM_ADT_EQUIVALENCECLASSES_H
58 template <
class ElemTy>
72 mutable const ECValue *Leader, *Next;
77 ECValue(
const ElemTy &Elt)
78 : Leader(
this), Next((ECValue*)(
intptr_t)1), Data(Elt) {}
80 const ECValue *getLeader()
const {
81 if (isLeader())
return this;
82 if (Leader->isLeader())
return Leader;
84 return Leader = Leader->getLeader();
87 const ECValue *getEndOfList()
const {
88 assert(isLeader() &&
"Cannot get the end of a list for a non-leader!");
92 void setNext(
const ECValue *NewNext)
const {
93 assert(getNext() ==
nullptr &&
"Already has a next pointer!");
98 ECValue(
const ECValue &RHS) : Leader(
this), Next((ECValue*)(
intptr_t)1),
101 assert(RHS.isLeader() && RHS.getNext() ==
nullptr &&
"Not a singleton!");
104 bool operator<(
const ECValue &UFN)
const {
return Data < UFN.Data; }
106 bool isLeader()
const {
return (
intptr_t)Next & 1; }
107 const ElemTy &getData()
const {
return Data; }
109 const ECValue *getNext()
const {
114 bool operator<(
const T &Val)
const {
return Data < Val; }
119 std::set<ECValue> TheMapping;
144 typedef typename std::set<ECValue>::const_iterator
iterator;
148 bool empty()
const {
return TheMapping.empty(); }
152 class member_iterator;
155 return member_iterator(I->isLeader() ? &*I :
nullptr);
158 return member_iterator(
nullptr);
164 return TheMapping.find(V);
190 if (
I->isLeader()) ++NC;
200 return TheMapping.insert(ECValue(Data)).first;
209 if (I == TheMapping.end())
return member_end();
210 return member_iterator(I->getLeader());
222 member_iterator
unionSets(member_iterator L1, member_iterator L2) {
224 if (L1 == L2)
return L1;
228 const ECValue &L1LV = *L1.Node, &L2LV = *L2.Node;
229 L1LV.getEndOfList()->setNext(&L2LV);
232 L1LV.Leader = L2LV.getEndOfList();
235 L2LV.Next = L2LV.getNext();
243 const ElemTy, ptrdiff_t> {
244 typedef std::iterator<std::forward_iterator_tag,
245 const ElemTy, ptrdiff_t> super;
258 assert(Node !=
nullptr &&
"Dereferencing end()!");
259 return Node->getData();
264 assert(Node !=
nullptr &&
"++'d off the end of the list!");
265 Node = Node->getNext();
276 return Node == RHS.Node;
279 return Node != RHS.Node;
286 #endif // LLVM_ADT_EQUIVALENCECLASSES_H
EquivalenceClasses()=default
member_iterator findLeader(const ElemTy &V) const
bool operator!=(const member_iterator &RHS) const
member_iterator unionSets(const ElemTy &V1, const ElemTy &V2)
union - Merge the two equivalence sets for the specified values, inserting them if they do not alread...
reference operator*() const
member_iterator member_begin(iterator I) const
super::reference reference
pointer operator->() const
bool operator==(const member_iterator &RHS) const
member_iterator member_end() const
member_iterator operator++(int)
EquivalenceClasses(const EquivalenceClasses &RHS)
iterator findValue(const ElemTy &V) const
findValue - Return an iterator to the specified value.
iterator insert(const ElemTy &Data)
insert - Insert a new value into the union/find set, ignoring the request if the value already exists...
std::set< ECValue >::const_iterator iterator
iterator* - Provides a way to iterate over all values in the set.
member_iterator()=default
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
unsigned getNumClasses() const
getNumClasses - Return the number of equivalence classes in this set.
EquivalenceClasses - This represents a collection of equivalence classes and supports three efficient...
const EquivalenceClasses & operator=(const EquivalenceClasses &RHS)
member_iterator(const ECValue *N)
const ElemTy & getOrInsertLeaderValue(const ElemTy &V)
getOrInsertLeaderValue - Return the leader for the specified value that is in the set...
member_iterator findLeader(iterator I) const
findLeader - Given a value in the set, return a member iterator for the equivalence class it is in...
member_iterator unionSets(member_iterator L1, member_iterator L2)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
const ElemTy & getLeaderValue(const ElemTy &V) const
getLeaderValue - Return the leader for the specified value that is in the set.
member_iterator & operator++()