15 #ifndef LLVM_ADT_EQUIVALENCECLASSES_H
16 #define LLVM_ADT_EQUIVALENCECLASSES_H
18 #include "llvm/Support/DataTypes.h"
56 template <
class ElemTy>
70 mutable const ECValue *Leader, *Next;
74 ECValue(
const ElemTy &Elt)
75 : Leader(
this), Next((ECValue*)(
intptr_t)1), Data(Elt) {}
77 const ECValue *getLeader()
const {
78 if (isLeader())
return this;
79 if (Leader->isLeader())
return Leader;
81 return Leader = Leader->getLeader();
83 const ECValue *getEndOfList()
const {
84 assert(isLeader() &&
"Cannot get the end of a list for a non-leader!");
88 void setNext(
const ECValue *NewNext)
const {
89 assert(getNext() == 0 &&
"Already has a next pointer!");
93 ECValue(
const ECValue &RHS) : Leader(
this), Next((ECValue*)(
intptr_t)1),
96 assert(RHS.isLeader() && RHS.getNext() == 0 &&
"Not a singleton!");
99 bool operator<(
const ECValue &UFN)
const {
return Data < UFN.Data; }
101 bool isLeader()
const {
return (
intptr_t)Next & 1; }
102 const ElemTy &getData()
const {
return Data; }
104 const ECValue *getNext()
const {
109 bool operator<(
const T &Val)
const {
return Data < Val; }
114 std::set<ECValue> TheMapping;
139 typedef typename std::set<ECValue>::const_iterator
iterator;
143 bool empty()
const {
return TheMapping.empty(); }
147 class member_iterator;
159 return TheMapping.find(V);
167 assert(MI !=
member_end() &&
"Value is not in the set!");
176 assert(MI !=
member_end() &&
"Value is not in the set!");
185 if (
I->isLeader()) ++NC;
196 return TheMapping.insert(ECValue(Data)).first;
205 if (I == TheMapping.end())
return member_end();
221 if (L1 == L2)
return L1;
225 const ECValue &L1LV = *L1.Node, &L2LV = *L2.Node;
226 L1LV.getEndOfList()->setNext(&L2LV);
229 L1LV.Leader = L2LV.getEndOfList();
232 L2LV.Next = L2LV.getNext();
240 const ElemTy, ptrdiff_t> {
241 typedef std::iterator<std::forward_iterator_tag,
242 const ElemTy, ptrdiff_t> super;
255 assert(Node != 0 &&
"Dereferencing end()!");
256 return Node->getData();
261 assert(Node != 0 &&
"++'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
void operator<(const Optional< T > &X, const Optional< U > &Y)
Poison comparison between two Optional objects. Clients needs to explicitly compare the underlying va...
bool operator!=(const member_iterator &RHS) const
member_iterator unionSets(const ElemTy &V1, const ElemTy &V2)
reference operator*() const
member_iterator member_begin(iterator I) const
reference operator->() const
super::reference reference
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
iterator insert(const ElemTy &Data)
std::set< ECValue >::const_iterator iterator
iterator* - Provides a way to iterate over all values in the set.
unsigned getNumClasses() const
const EquivalenceClasses & operator=(const EquivalenceClasses &RHS)
member_iterator(const ECValue *N)
const ElemTy & getOrInsertLeaderValue(const ElemTy &V)
member_iterator(const member_iterator &I)
member_iterator findLeader(iterator I) const
member_iterator unionSets(member_iterator L1, member_iterator L2)
const ElemTy & getLeaderValue(const ElemTy &V) const
member_iterator & operator++()