15 #ifndef LLVM_ADT_EQUIVALENCECLASSES_H 16 #define LLVM_ADT_EQUIVALENCECLASSES_H 58 template <
class ElemTy>
73 mutable const ECValue *Leader, *Next;
78 ECValue(
const ElemTy &Elt)
79 : Leader(
this), Next((ECValue*)(
intptr_t)1),
Data(Elt) {}
81 const ECValue *getLeader()
const {
82 if (isLeader())
return this;
83 if (Leader->isLeader())
return Leader;
85 return Leader = Leader->getLeader();
88 const ECValue *getEndOfList()
const {
89 assert(isLeader() &&
"Cannot get the end of a list for a non-leader!");
93 void setNext(
const ECValue *NewNext)
const {
94 assert(getNext() ==
nullptr &&
"Already has a next pointer!");
99 ECValue(
const ECValue &RHS) : Leader(
this), Next((ECValue*)(
intptr_t)1),
102 assert(RHS.isLeader() && RHS.getNext() ==
nullptr &&
"Not a singleton!");
105 bool operator<(
const ECValue &UFN)
const {
return Data < UFN.Data; }
107 bool isLeader()
const {
return (
intptr_t)Next & 1; }
108 const ElemTy &getData()
const {
return Data; }
110 const ECValue *getNext()
const {
115 bool operator<(
const T &Val)
const {
return Data < Val; }
120 std::set<ECValue> TheMapping;
145 using iterator =
typename std::set<ECValue>::const_iterator;
150 bool empty()
const {
return TheMapping.empty(); }
153 class member_iterator;
156 return member_iterator(I->isLeader() ? &*
I :
nullptr);
159 return member_iterator(
nullptr);
165 return TheMapping.find(V);
191 if (
I->isLeader()) ++NC;
201 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();
253 const ElemTy, ptrdiff_t> {
256 using super = std::iterator<std::forward_iterator_tag,
270 assert(Node !=
nullptr &&
"Dereferencing end()!");
271 return Node->getData();
276 assert(Node !=
nullptr &&
"++'d off the end of the list!");
277 Node = Node->getNext();
288 return Node == RHS.Node;
291 return Node != RHS.Node;
298 #endif // LLVM_ADT_EQUIVALENCECLASSES_H EquivalenceClasses()=default
This class represents lattice values for constants.
const ElemTy & getLeaderValue(const ElemTy &V) const
getLeaderValue - Return the leader for the specified value that is in the set.
pointer operator->() 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...
typename super::pointer pointer
APInt operator*(APInt a, uint64_t RHS)
member_iterator operator++(int)
EquivalenceClasses(const EquivalenceClasses &RHS)
member_iterator member_begin(iterator I) const
iterator insert(const ElemTy &Data)
insert - Insert a new value into the union/find set, ignoring the request if the value already exists...
iterator findValue(const ElemTy &V) const
findValue - Return an iterator to the specified value.
reference operator*() const
member_iterator findLeader(iterator I) const
findLeader - Given a value in the set, return a member iterator for the equivalence class it is in...
typename super::reference reference
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
EquivalenceClasses - This represents a collection of equivalence classes and supports three efficient...
member_iterator member_end() const
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...
bool operator!=(const member_iterator &RHS) const
bool operator==(const member_iterator &RHS) const
member_iterator unionSets(member_iterator L1, member_iterator L2)
typename std::set< ECValue >::const_iterator iterator
iterator* - Provides a way to iterate over all values in the set.
unsigned getNumClasses() const
getNumClasses - Return the number of equivalence classes in this set.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool operator<(int64_t V1, const APSInt &V2)
member_iterator & operator++()
bool isEquivalent(const ElemTy &V1, const ElemTy &V2) const
member_iterator findLeader(const ElemTy &V) const