Fix a few bugs related to zero'ing of elements

llvm-svn: 42017
This commit is contained in:
Daniel Berlin 2007-09-16 22:31:47 +00:00
parent ffce584d1c
commit c637abee96
1 changed files with 14 additions and 45 deletions

View File

@ -212,7 +212,7 @@ public:
BitWord old = changed ? 0 : Bits[i]; BitWord old = changed ? 0 : Bits[i];
Bits[i] |= RHS.Bits[i]; Bits[i] |= RHS.Bits[i];
if (old != Bits[i]) if (!changed && old != Bits[i])
changed = true; changed = true;
} }
return changed; return changed;
@ -242,17 +242,17 @@ public:
if (Bits[i] != 0) if (Bits[i] != 0)
allzero = false; allzero = false;
if (old != Bits[i]) if (!changed && old != Bits[i])
changed = true; changed = true;
} }
BecameZero = !allzero; BecameZero = allzero;
return changed; return changed;
} }
// Intersect this Element with the complement of RHS and return true if this // Intersect this Element with the complement of RHS and return true if this
// one changed. BecameZero is set to true if this element became all-zero // one changed. BecameZero is set to true if this element became all-zero
// bits. // bits.
bool intersectWithComplement(const SparseBitVectorElement &RHS, bool intersectWithComplement(const SparseBitVectorElement &RHS,
bool &BecameZero) { bool &BecameZero) {
bool changed = false; bool changed = false;
bool allzero = true; bool allzero = true;
@ -264,10 +264,10 @@ public:
if (Bits[i] != 0) if (Bits[i] != 0)
allzero = false; allzero = false;
if (old != Bits[i]) if (!changed && old != Bits[i])
changed = true; changed = true;
} }
BecameZero = !allzero; BecameZero = allzero;
return changed; return changed;
} }
// Three argument version of intersectWithComplement that intersects // Three argument version of intersectWithComplement that intersects
@ -283,7 +283,7 @@ public:
if (Bits[i] != 0) if (Bits[i] != 0)
allzero = false; allzero = false;
} }
BecameZero = !allzero; BecameZero = allzero;
} }
}; };
@ -548,12 +548,6 @@ public:
if (Elements.empty() && RHS.Elements.empty()) if (Elements.empty() && RHS.Elements.empty())
return false; return false;
// See if the first bitmap element is the same in both. This is only
// possible if they are the same bitmap.
if (Iter1 != Elements.end() && Iter2 != RHS.Elements.end())
if (*Iter1 == *Iter2)
return false;
while (Iter2 != RHS.Elements.end()) { while (Iter2 != RHS.Elements.end()) {
if (Iter1 == Elements.end() || Iter1->index() > Iter2->index()) { if (Iter1 == Elements.end() || Iter1->index() > Iter2->index()) {
Elements.insert(Iter1, Elements.insert(Iter1,
@ -582,12 +576,6 @@ public:
if (Elements.empty() && RHS.Elements.empty()) if (Elements.empty() && RHS.Elements.empty())
return false; return false;
// See if the first bitmap element is the same in both. This is only
// possible if they are the same bitmap.
if (Iter1 != Elements.end() && Iter2 != RHS.Elements.end())
if (*Iter1 == *Iter2)
return false;
// Loop through, intersecting as we go, erasing elements when necessary. // Loop through, intersecting as we go, erasing elements when necessary.
while (Iter2 != RHS.Elements.end()) { while (Iter2 != RHS.Elements.end()) {
if (Iter1 == Elements.end()) if (Iter1 == Elements.end())
@ -600,9 +588,11 @@ public:
changed |= Iter1->intersectWith(*Iter2, BecameZero); changed |= Iter1->intersectWith(*Iter2, BecameZero);
if (BecameZero) { if (BecameZero) {
ElementListIter IterTmp = Iter1; ElementListIter IterTmp = Iter1;
++Iter1;
Elements.erase(IterTmp); Elements.erase(IterTmp);
} else {
++Iter1;
} }
++Iter1;
++Iter2; ++Iter2;
} else { } else {
ElementListIter IterTmp = Iter1; ElementListIter IterTmp = Iter1;
@ -626,14 +616,6 @@ public:
if (Elements.empty() && RHS.Elements.empty()) if (Elements.empty() && RHS.Elements.empty())
return false; return false;
// See if the first bitmap element is the same in both. This is only
// possible if they are the same bitmap.
if (Iter1 != Elements.end() && Iter2 != RHS.Elements.end())
if (*Iter1 == *Iter2) {
Elements.clear();
return true;
}
// Loop through, intersecting as we go, erasing elements when necessary. // Loop through, intersecting as we go, erasing elements when necessary.
while (Iter2 != RHS.Elements.end()) { while (Iter2 != RHS.Elements.end()) {
if (Iter1 == Elements.end()) if (Iter1 == Elements.end())
@ -646,9 +628,11 @@ public:
changed |= Iter1->intersectWithComplement(*Iter2, BecameZero); changed |= Iter1->intersectWithComplement(*Iter2, BecameZero);
if (BecameZero) { if (BecameZero) {
ElementListIter IterTmp = Iter1; ElementListIter IterTmp = Iter1;
++Iter1;
Elements.erase(IterTmp); Elements.erase(IterTmp);
} else {
++Iter1;
} }
++Iter1;
++Iter2; ++Iter2;
} else { } else {
ElementListIter IterTmp = Iter1; ElementListIter IterTmp = Iter1;
@ -678,13 +662,6 @@ public:
if (RHS1.empty() && RHS2.empty()) if (RHS1.empty() && RHS2.empty())
return; return;
// See if the first bitmap element is the same in both. This is only
// possible if they are the same bitmap.
if (Iter1 != RHS1.Elements.end() && Iter2 != RHS2.Elements.end())
if (*Iter1 == *Iter2) {
return;
}
// Loop through, intersecting as we go, erasing elements when necessary. // Loop through, intersecting as we go, erasing elements when necessary.
while (Iter2 != RHS2.Elements.end()) { while (Iter2 != RHS2.Elements.end()) {
if (Iter1 == RHS1.Elements.end()) if (Iter1 == RHS1.Elements.end())
@ -702,7 +679,6 @@ public:
} }
else else
delete NewElement; delete NewElement;
++Iter1; ++Iter1;
++Iter2; ++Iter2;
} else { } else {
@ -740,13 +716,6 @@ public:
if (Elements.empty() && RHS.Elements.empty()) if (Elements.empty() && RHS.Elements.empty())
return false; return false;
// See if the first bitmap element is the same in both. This is only
// possible if they are the same bitmap.
if (Iter1 != Elements.end() && Iter2 != RHS.Elements.end())
if (*Iter1 == *Iter2) {
return true;
}
// Loop through, intersecting stopping when we hit bits in common. // Loop through, intersecting stopping when we hit bits in common.
while (Iter2 != RHS.Elements.end()) { while (Iter2 != RHS.Elements.end()) {
if (Iter1 == Elements.end()) if (Iter1 == Elements.end())
@ -824,7 +793,7 @@ inline bool operator &=(SparseBitVector<ElementSize> &LHS,
const SparseBitVector<ElementSize> *RHS) { const SparseBitVector<ElementSize> *RHS) {
return LHS &= (*RHS); return LHS &= (*RHS);
} }
// Dump a SparseBitVector to a stream // Dump a SparseBitVector to a stream
template <unsigned ElementSize> template <unsigned ElementSize>