X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FADT%2FSparseBitVector.h;h=6230135131a7ccb9a0eabc07475aa64109b46e25;hb=aafa94260d5b1b6422258ed3db7244fe4449f217;hp=efd0accaad289f1aadecc17f9dcd66dfb29470c3;hpb=fed90b6d097d50881afb45e4d79f430db66dd741;p=oota-llvm.git diff --git a/include/llvm/ADT/SparseBitVector.h b/include/llvm/ADT/SparseBitVector.h index efd0accaad2..6230135131a 100644 --- a/include/llvm/ADT/SparseBitVector.h +++ b/include/llvm/ADT/SparseBitVector.h @@ -16,12 +16,13 @@ #define LLVM_ADT_SPARSEBITVECTOR_H #include +#include #include -#include #include "llvm/Support/DataTypes.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/MathExtras.h" #include "llvm/ADT/ilist.h" + namespace llvm { /// SparseBitVector is an implementation of a bitvector that is sparse by only @@ -44,7 +45,7 @@ struct SparseBitVectorElement public: typedef unsigned long BitWord; enum { - BITWORD_SIZE = sizeof(BitWord) * 8, + BITWORD_SIZE = sizeof(BitWord) * CHAR_BIT, BITWORDS_PER_ELEMENT = (ElementSize + BITWORD_SIZE - 1) / BITWORD_SIZE, BITS_PER_ELEMENT = ElementSize }; @@ -54,7 +55,7 @@ private: unsigned ElementIndex; BitWord Bits[BITWORDS_PER_ELEMENT]; // Needed for sentinels - friend class ilist_sentinel_traits; + friend struct ilist_sentinel_traits; SparseBitVectorElement() { ElementIndex = ~0U; memset(&Bits[0], 0, sizeof (BitWord) * BITWORDS_PER_ELEMENT); @@ -459,11 +460,16 @@ public: CurrElementIter = Elements.begin (); } - + + // Clear. + void clear() { + Elements.clear(); + } + // Assignment SparseBitVector& operator=(const SparseBitVector& RHS) { Elements.clear(); - + ElementListConstIter ElementIter = RHS.Elements.begin(); while (ElementIter != RHS.Elements.end()) { Elements.push_back(SparseBitVectorElement(*ElementIter)); @@ -471,7 +477,7 @@ public: } CurrElementIter = Elements.begin (); - + return *this; } @@ -635,8 +641,8 @@ public: return changed; } - // Intersect our bitmap with the complement of the RHS and return true if ours - // changed. + // Intersect our bitmap with the complement of the RHS and return true + // if ours changed. bool intersectWithComplement(const SparseBitVector &RHS) { bool changed = false; ElementListIter Iter1 = Elements.begin(); @@ -679,8 +685,8 @@ public: } - // Three argument version of intersectWithComplement. Result of RHS1 & ~RHS2 - // is stored into this bitmap. + // Three argument version of intersectWithComplement. + // Result of RHS1 & ~RHS2 is stored into this bitmap. void intersectWithComplement(const SparseBitVector &RHS1, const SparseBitVector &RHS2) { @@ -769,6 +775,14 @@ public: return false; } + // Return true iff all bits set in this SparseBitVector are + // also set in RHS. + bool contains(const SparseBitVector &RHS) const { + SparseBitVector Result(*this); + Result &= RHS; + return (Result == RHS); + } + // Return the first set bit in the bitmap. Return -1 if no bits are set. int find_first() const { if (Elements.empty()) @@ -836,10 +850,41 @@ inline bool operator &=(SparseBitVector *LHS, template inline bool operator &=(SparseBitVector &LHS, const SparseBitVector *RHS) { - return LHS &= (*RHS); + return LHS &= *RHS; +} + +// Convenience functions for infix union, intersection, difference operators. + +template +inline SparseBitVector +operator|(const SparseBitVector &LHS, + const SparseBitVector &RHS) { + SparseBitVector Result(LHS); + Result |= RHS; + return Result; +} + +template +inline SparseBitVector +operator&(const SparseBitVector &LHS, + const SparseBitVector &RHS) { + SparseBitVector Result(LHS); + Result &= RHS; + return Result; +} + +template +inline SparseBitVector +operator-(const SparseBitVector &LHS, + const SparseBitVector &RHS) { + SparseBitVector Result; + Result.intersectWithComplement(LHS, RHS); + return Result; } + + // Dump a SparseBitVector to a stream template void dump(const SparseBitVector &LHS, llvm::OStream &out) { @@ -849,10 +894,8 @@ void dump(const SparseBitVector &LHS, llvm::OStream &out) { for (bi = LHS.begin(); bi != LHS.end(); ++bi) { out << *bi << " "; } - out << " ]\n"; + out << " ]\n"; } -} - - +} // end namespace llvm #endif