Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions llvm/include/llvm/ADT/EquivalenceClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ template <class ElemTy> class EquivalenceClasses {
// ECValue ctor - Start out with EndOfList pointing to this node, Next is
// Null, isLeader = true.
ECValue(const ElemTy &Elt)
: Leader(this), Next((ECValue*)(intptr_t)1), Data(Elt) {}
: Leader(this),
Next(reinterpret_cast<ECValue *>(static_cast<intptr_t>(1))),
Data(Elt) {}

const ECValue *getLeader() const {
if (isLeader()) return this;
if (Leader->isLeader()) return Leader;
if (isLeader())
return this;
if (Leader->isLeader())
return Leader;
// Path compression.
return Leader = Leader->getLeader();
}
Expand All @@ -95,12 +99,16 @@ template <class ElemTy> class EquivalenceClasses {

void setNext(const ECValue *NewNext) const {
assert(getNext() == nullptr && "Already has a next pointer!");
Next = (const ECValue*)((intptr_t)NewNext | (intptr_t)isLeader());
Next = reinterpret_cast<const ECValue *>(
reinterpret_cast<intptr_t>(NewNext) |
static_cast<intptr_t>(isLeader()));
}

public:
ECValue(const ECValue &RHS) : Leader(this), Next((ECValue*)(intptr_t)1),
Data(RHS.Data) {
ECValue(const ECValue &RHS)
: Leader(this),
Next(reinterpret_cast<ECValue *>(static_cast<intptr_t>(1))),
Data(RHS.Data) {
// Only support copying of singleton nodes.
assert(RHS.isLeader() && RHS.getNext() == nullptr && "Not a singleton!");
}
Expand All @@ -109,7 +117,8 @@ template <class ElemTy> class EquivalenceClasses {
const ElemTy &getData() const { return Data; }

const ECValue *getNext() const {
return (ECValue*)((intptr_t)Next & ~(intptr_t)1);
return reinterpret_cast<ECValue *>(reinterpret_cast<intptr_t>(Next) &
~static_cast<intptr_t>(1));
}
};

Expand All @@ -124,9 +133,7 @@ template <class ElemTy> class EquivalenceClasses {

public:
EquivalenceClasses() = default;
EquivalenceClasses(const EquivalenceClasses &RHS) {
operator=(RHS);
}
EquivalenceClasses(const EquivalenceClasses &RHS) { operator=(RHS); }

EquivalenceClasses &operator=(const EquivalenceClasses &RHS) {
TheMapping.clear();
Expand Down Expand Up @@ -160,9 +167,7 @@ template <class ElemTy> class EquivalenceClasses {
return member_iterator(ECV.isLeader() ? &ECV : nullptr);
}

member_iterator member_end() const {
return member_iterator(nullptr);
}
member_iterator member_end() const { return member_iterator(nullptr); }

iterator_range<member_iterator> members(const ECValue &ECV) const {
return make_range(member_begin(ECV), member_end());
Expand Down Expand Up @@ -294,7 +299,8 @@ template <class ElemTy> class EquivalenceClasses {
}
member_iterator unionSets(member_iterator L1, member_iterator L2) {
assert(L1 != member_end() && L2 != member_end() && "Illegal inputs!");
if (L1 == L2) return L1; // Unifying the same two sets, noop.
if (L1 == L2)
return L1; // Unifying the same two sets, noop.

// Otherwise, this is a real union operation. Set the end of the L1 list to
// point to the L2 leader node.
Expand Down Expand Up @@ -350,7 +356,7 @@ template <class ElemTy> class EquivalenceClasses {
return *this;
}

member_iterator operator++(int) { // postincrement operators.
member_iterator operator++(int) { // postincrement operators.
member_iterator tmp = *this;
++*this;
return tmp;
Expand Down