15 #ifndef LLVM_ADT_EQUIVALENCECLASSES_H
16 #define LLVM_ADT_EQUIVALENCECLASSES_H
18 #include "llvm/Support/DataTypes.h"
57 template <
class ElemTy>
71 mutable const ECValue *Leader, *Next;
75 ECValue(
const ElemTy &Elt)
76 : Leader(
this), Next((ECValue*)(
intptr_t)1),
Data(Elt) {}
78 const ECValue *getLeader()
const {
79 if (isLeader())
return this;
80 if (Leader->isLeader())
return Leader;
82 return Leader = Leader->getLeader();
84 const ECValue *getEndOfList()
const {
85 assert(isLeader() &&
"Cannot get the end of a list for a non-leader!");
89 void setNext(
const ECValue *NewNext)
const {
90 assert(getNext() ==
nullptr &&
"Already has a next pointer!");
94 ECValue(
const ECValue &RHS) : Leader(
this), Next((ECValue*)(
intptr_t)1),
97 assert(RHS.isLeader() && RHS.getNext() ==
nullptr &&
"Not a singleton!");
100 bool operator<(
const ECValue &UFN)
const {
return Data < UFN.Data; }
102 bool isLeader()
const {
return (
intptr_t)Next & 1; }
103 const ElemTy &getData()
const {
return Data; }
105 const ECValue *getNext()
const {
115 std::set<ECValue> TheMapping;
140 typedef typename std::set<ECValue>::const_iterator
iterator;
144 bool empty()
const {
return TheMapping.empty(); }
148 class member_iterator;
160 return TheMapping.find(V);
168 assert(MI !=
member_end() &&
"Value is not in the set!");
177 assert(MI !=
member_end() &&
"Value is not in the set!");
186 if (
I->isLeader()) ++NC;
197 return TheMapping.insert(ECValue(Data)).first;
206 if (I == TheMapping.end())
return member_end();
222 if (L1 == L2)
return L1;
226 const ECValue &L1LV = *L1.Node, &L2LV = *L2.Node;
227 L1LV.getEndOfList()->setNext(&L2LV);
230 L1LV.Leader = L2LV.getEndOfList();
233 L2LV.Next = L2LV.getNext();
241 const ElemTy, ptrdiff_t> {
242 typedef std::iterator<std::forward_iterator_tag,
243 const ElemTy, ptrdiff_t> super;
255 assert(Node !=
nullptr &&
"Dereferencing end()!");
256 return Node->getData();
261 assert(Node !=
nullptr &&
"++'d off the end of the list!");
262 Node = Node->getNext();
273 return Node == RHS.Node;
276 return Node != RHS.Node;
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.
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)
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++()