15#ifndef LLVM_ADT_EQUIVALENCECLASSES_H
16#define LLVM_ADT_EQUIVALENCECLASSES_H
59template <
class ElemTy,
class Compare = std::less<ElemTy>>
74 mutable const ECValue *Leader, *Next;
79 ECValue(
const ElemTy &Elt)
80 : Leader(
this), Next((ECValue*)(intptr_t)1), Data(Elt) {}
82 const ECValue *getLeader()
const {
83 if (isLeader())
return this;
84 if (Leader->isLeader())
return Leader;
86 return Leader = Leader->getLeader();
89 const ECValue *getEndOfList()
const {
90 assert(isLeader() &&
"Cannot get the end of a list for a non-leader!");
94 void setNext(
const ECValue *NewNext)
const {
95 assert(getNext() ==
nullptr &&
"Already has a next pointer!");
96 Next = (
const ECValue*)((intptr_t)NewNext | (intptr_t)isLeader());
100 ECValue(
const ECValue &
RHS) : Leader(
this), Next((ECValue*)(intptr_t)1),
103 assert(
RHS.isLeader() &&
RHS.getNext() ==
nullptr &&
"Not a singleton!");
106 bool isLeader()
const {
return (intptr_t)Next & 1; }
107 const ElemTy &getData()
const {
return Data; }
109 const ECValue *getNext()
const {
110 return (ECValue*)((intptr_t)Next & ~(intptr_t)1);
115 struct ECValueComparator {
116 using is_transparent = void;
118 ECValueComparator() : compare(Compare()) {}
120 bool operator()(
const ECValue &lhs,
const ECValue &rhs)
const {
121 return compare(lhs.Data, rhs.Data);
124 template <
typename T>
125 bool operator()(
const T &lhs,
const ECValue &rhs)
const {
126 return compare(lhs, rhs.Data);
129 template <
typename T>
130 bool operator()(
const ECValue &lhs,
const T &rhs)
const {
131 return compare(lhs.Data, rhs);
134 const Compare compare;
139 std::set<ECValue, ECValueComparator> TheMapping;
165 typename std::set<ECValue, ECValueComparator>::const_iterator;
170 bool empty()
const {
return TheMapping.empty(); }
173 class member_iterator;
185 return TheMapping.find(V);
211 if (
I->isLeader()) ++
NC;
221 return TheMapping.insert(ECValue(
Data)).first;
244 if (L1 == L2)
return L1;
248 const ECValue &L1LV = *L1.Node, &L2LV = *L2.Node;
249 L1LV.getEndOfList()->setNext(&L2LV);
252 L1LV.Leader = L2LV.getEndOfList();
255 L2LV.Next = L2LV.getNext();
289 assert(
Node !=
nullptr &&
"Dereferencing end()!");
290 return Node->getData();
295 assert(
Node !=
nullptr &&
"++'d off the end of the list!");
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator!=(const member_iterator &RHS) const
bool operator==(const member_iterator &RHS) const
member_iterator(const ECValue *N)
member_iterator & operator++()
pointer operator->() const
member_iterator operator++(int)
reference operator*() const
std::forward_iterator_tag iterator_category
member_iterator()=default
std::ptrdiff_t difference_type
EquivalenceClasses - This represents a collection of equivalence classes and supports three efficient...
iterator findValue(const ElemTy &V) const
findValue - Return an iterator to the specified value.
member_iterator findLeader(iterator I) const
findLeader - Given a value in the set, return a member iterator for the equivalence class it is in.
const ElemTy & getOrInsertLeaderValue(const ElemTy &V)
getOrInsertLeaderValue - Return the leader for the specified value that is in the set.
iterator insert(const ElemTy &Data)
insert - Insert a new value into the union/find set, ignoring the request if the value already exists...
member_iterator member_end() const
unsigned getNumClasses() const
getNumClasses - Return the number of equivalence classes in this set.
typename std::set< ECValue, ECValueComparator >::const_iterator iterator
iterator* - Provides a way to iterate over all values in the set.
member_iterator findLeader(const ElemTy &V) const
member_iterator member_begin(iterator I) const
EquivalenceClasses()=default
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...
const EquivalenceClasses & operator=(const EquivalenceClasses &RHS)
EquivalenceClasses(const EquivalenceClasses &RHS)
member_iterator unionSets(member_iterator L1, member_iterator L2)
const ElemTy & getLeaderValue(const ElemTy &V) const
getLeaderValue - Return the leader for the specified value that is in the set.
bool isEquivalent(const ElemTy &V1, const ElemTy &V2) const
This is an optimization pass for GlobalISel generic memory operations.