15#ifndef LLVM_ADT_EQUIVALENCECLASSES_H
16#define LLVM_ADT_EQUIVALENCECLASSES_H
77 mutable const ECValue *Leader, *Next;
82 ECValue(
const ElemTy &Elt)
84 Next(reinterpret_cast<ECValue *>(static_cast<intptr_t>(1))),
87 const ECValue *getLeader()
const {
93 return Leader = Leader->getLeader();
96 const ECValue *getEndOfList()
const {
97 assert(
isLeader() &&
"Cannot get the end of a list for a non-leader!");
101 void setNext(
const ECValue *NewNext)
const {
102 assert(
getNext() ==
nullptr &&
"Already has a next pointer!");
103 Next =
reinterpret_cast<const ECValue *
>(
104 reinterpret_cast<intptr_t
>(NewNext) |
111 Next(reinterpret_cast<ECValue *>(static_cast<intptr_t>(1))),
114 assert(
RHS.isLeader() &&
RHS.getNext() ==
nullptr &&
"Not a singleton!");
117 bool isLeader()
const {
return (intptr_t)Next & 1; }
118 const ElemTy &
getData()
const {
return Data; }
121 return reinterpret_cast<ECValue *
>(
reinterpret_cast<intptr_t
>(Next) &
122 ~static_cast<intptr_t>(1));
143 for (
const auto &
E :
RHS)
145 member_iterator
MI =
RHS.member_begin(*
E);
163 bool empty()
const {
return TheMapping.empty(); }
166 class member_iterator;
169 return member_iterator(ECV.isLeader() ? &ECV :
nullptr);
172 member_iterator
member_end()
const {
return member_iterator(
nullptr); }
184 return TheMapping.find(V) != TheMapping.end();
209 for (
const auto &
E : *
this)
221 auto [
I, Inserted] = TheMapping.try_emplace(
Data);
225 auto *ECV =
new (ECValueAllocator) ECValue(
Data);
227 Members.push_back(ECV);
234 if (!TheMapping.contains(V))
236 const ECValue *Cur = TheMapping[V];
237 const ECValue *
Next = Cur->getNext();
242 if (Cur->isLeader() &&
Next) {
243 Next->Leader = Cur->Leader;
244 Next->Next =
reinterpret_cast<const ECValue *
>(
245 reinterpret_cast<intptr_t
>(
Next->Next) |
static_cast<intptr_t
>(1));
247 const ECValue *NewLeader =
Next;
249 Next->Leader = NewLeader;
251 }
else if (!Cur->isLeader()) {
253 const ECValue *Pre = Leader;
254 while (Pre->getNext() != Cur) {
255 Pre = Pre->getNext();
262 Leader->Leader = Pre;
266 Pre->Next =
reinterpret_cast<const ECValue *
>(
267 reinterpret_cast<intptr_t
>(
Next) |
268 static_cast<intptr_t
>(Pre->isLeader()));
274 assert(TheMapping.contains(V) &&
"Can't find input in TheMapping!");
276 auto I =
find(Members, Cur);
277 assert(
I != Members.end() &&
"Can't find input in members!");
287 auto I = TheMapping.find(V);
288 if (
I == TheMapping.end())
289 return member_iterator(
nullptr);
293 return member_iterator(ECV.getLeader());
298 member_iterator
unionSets(
const ElemTy &V1,
const ElemTy &V2) {
302 member_iterator
unionSets(member_iterator L1, member_iterator L2) {
309 const ECValue &L1LV = *L1.Node, &L2LV = *L2.Node;
310 L1LV.getEndOfList()->setNext(&L2LV);
313 L1LV.Leader = L2LV.getEndOfList();
350 assert(Node !=
nullptr &&
"Dereferencing end()!");
351 return Node->getData();
356 assert(Node !=
nullptr &&
"++'d off the end of the list!");
357 Node = Node->getNext();
368 return Node ==
RHS.Node;
371 return Node !=
RHS.Node;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
This file defines the SmallVector class.
ECValue - The EquivalenceClasses data structure is just a set of these.
const ECValue * getNext() const
friend class EquivalenceClasses
ECValue(const ECValue &RHS)
const ElemTy & getData() const
std::forward_iterator_tag iterator_category
member_iterator(const ECValue *N)
member_iterator & operator++()
friend class EquivalenceClasses
member_iterator()=default
std::ptrdiff_t difference_type
pointer operator->() const
member_iterator operator++(int)
reference operator*() const
bool operator!=(const member_iterator &RHS) const
bool operator==(const member_iterator &RHS) const
EquivalenceClasses()=default
member_iterator member_begin(const ECValue &ECV) const
iterator_range< member_iterator > members(const ECValue &ECV) const
bool contains(const ElemTy &V) const
Returns true if V is contained an equivalence class.
member_iterator findLeader(const ECValue &ECV) const
const ElemTy & getOrInsertLeaderValue(const ElemTy &V)
getOrInsertLeaderValue - Return the leader for the specified value that is in the set.
const ECValue & insert(const ElemTy &Data)
insert - Insert a new value into the union/find set, ignoring the request if the value already exists...
bool isEquivalent(const ElemTy &V1, const ElemTy &V2) const
member_iterator member_end() const
const ElemTy & getLeaderValue(const ElemTy &V) const
getLeaderValue - Return the leader for the specified value that is in the set.
iterator_range< member_iterator > members(const ElemTy &V) const
EquivalenceClasses & operator=(const EquivalenceClasses &RHS)
typename SmallVector< const ECValue * >::const_iterator iterator
iterator* - Provides a way to iterate over all values in the set.
member_iterator findLeader(const ElemTy &V) const
findLeader - Given a value in the set, return a member iterator for the equivalence class it is in.
unsigned getNumClasses() const
getNumClasses - Return the number of equivalence classes in this set.
member_iterator unionSets(member_iterator L1, member_iterator L2)
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...
bool erase(const ElemTy &V)
erase - Erase a value from the union/find set, return "true" if erase succeeded, or "false" when the ...
EquivalenceClasses(const EquivalenceClasses &RHS)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
FunctionAddr VTableAddr Next