llvm.org GIT mirror llvm / 680a7c2
Get rid of WORDSIZE macro which can pollute untold numbers of translation units git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6843 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 17 years ago
2 changed file(s) with 24 addition(s) and 36 deletion(s). Raw diff Collapse all Expand all
88 // We therefore use a vector of bitsets. The maxmimum size of our sets
99 // (i.e., the size of the universal set) can be chosen at creation time.
1010 //
11 // The size of each Bitset is defined by the macro WORDSIZE.
12 //
13 // NOTE: The WORDSIZE macro should be made machine-dependent, in order to use
14 // 64-bit words or whatever gives most efficient Bitsets on each platform.
15 //
16 //
1711 // External functions:
1812 //
1913 // bool Disjoint(const BitSetVector& set1, const BitSetVector& set2):
2923 #include
3024 #include
3125 #include
32
3326 #include
3427
35 #define WORDSIZE (32U)
36
37
3828 class BitSetVector {
29 enum { BITSET_WORDSIZE = sizeof(long)*8 };
30
3931 // Types used internal to the representation
40 typedef std::bitset<WORDSIZE> bitword;
32 typedef std::bitset<BITSET_WORDSIZE> bitword;
4133 typedef bitword::reference reference;
4234 class iterator;
4335
4739
4840 private:
4941 // Utility functions for the representation
50 static unsigned NumWords(unsigned Size) { return (Size+WORDSIZE-1)/WORDSIZE;}
51 static unsigned LastWordSize(unsigned Size) { return Size % WORDSIZE; }
42 static unsigned NumWords(unsigned Size) {
43 return (Size+BITSET_WORDSIZE-1)/BITSET_WORDSIZE;
44 }
45 static unsigned LastWordSize(unsigned Size) { return Size % BITSET_WORDSIZE; }
5246
5347 // Clear the unused bits in the last word.
54 // The unused bits are the high (WORDSIZE - LastWordSize()) bits
48 // The unused bits are the high (BITSET_WORDSIZE - LastWordSize()) bits
5549 void ClearUnusedBits() {
5650 unsigned long usedBits = (1U << LastWordSize(size())) - 1;
5751 bitsetVec.back() &= bitword(usedBits);
9084 }
9185 reference operator[](unsigned n) {
9286 assert(n < size() && "BitSetVector: Bit number out of range");
93 unsigned ndiv = n / WORDSIZE, nmod = n % WORDSIZE;
87 unsigned ndiv = n / BITSET_WORDSIZE, nmod = n % BITSET_WORDSIZE;
9488 return bitsetVec[ndiv][nmod];
9589 }
9690 iterator begin() { return iterator::begin(*this); }
115109 ///
116110 bool test(unsigned n) const {
117111 assert(n < size() && "BitSetVector: Bit number out of range");
118 unsigned ndiv = n / WORDSIZE, nmod = n % WORDSIZE;
112 unsigned ndiv = n / BITSET_WORDSIZE, nmod = n % BITSET_WORDSIZE;
119113 return bitsetVec[ndiv].test(nmod);
120114 }
121115 bool any() const {
202196
203197 // Increment and decrement operators (pre and post)
204198 iterator& operator++() {
205 if (++currentBit == WORDSIZE)
199 if (++currentBit == BITSET_WORDSIZE)
206200 { currentBit = 0; if (currentWord < bitvec->size()) ++currentWord; }
207201 return *this;
208202 }
209203 iterator& operator--() {
210204 if (currentBit == 0) {
211 currentBit = WORDSIZE-1;
205 currentBit = BITSET_WORDSIZE-1;
212206 currentWord = (currentWord == 0)? bitvec->size() : --currentWord;
213207 }
214208 else
88 // We therefore use a vector of bitsets. The maxmimum size of our sets
99 // (i.e., the size of the universal set) can be chosen at creation time.
1010 //
11 // The size of each Bitset is defined by the macro WORDSIZE.
12 //
13 // NOTE: The WORDSIZE macro should be made machine-dependent, in order to use
14 // 64-bit words or whatever gives most efficient Bitsets on each platform.
15 //
16 //
1711 // External functions:
1812 //
1913 // bool Disjoint(const BitSetVector& set1, const BitSetVector& set2):
2923 #include
3024 #include
3125 #include
32
3326 #include
3427
35 #define WORDSIZE (32U)
36
37
3828 class BitSetVector {
29 enum { BITSET_WORDSIZE = sizeof(long)*8 };
30
3931 // Types used internal to the representation
40 typedef std::bitset<WORDSIZE> bitword;
32 typedef std::bitset<BITSET_WORDSIZE> bitword;
4133 typedef bitword::reference reference;
4234 class iterator;
4335
4739
4840 private:
4941 // Utility functions for the representation
50 static unsigned NumWords(unsigned Size) { return (Size+WORDSIZE-1)/WORDSIZE;}
51 static unsigned LastWordSize(unsigned Size) { return Size % WORDSIZE; }
42 static unsigned NumWords(unsigned Size) {
43 return (Size+BITSET_WORDSIZE-1)/BITSET_WORDSIZE;
44 }
45 static unsigned LastWordSize(unsigned Size) { return Size % BITSET_WORDSIZE; }
5246
5347 // Clear the unused bits in the last word.
54 // The unused bits are the high (WORDSIZE - LastWordSize()) bits
48 // The unused bits are the high (BITSET_WORDSIZE - LastWordSize()) bits
5549 void ClearUnusedBits() {
5650 unsigned long usedBits = (1U << LastWordSize(size())) - 1;
5751 bitsetVec.back() &= bitword(usedBits);
9084 }
9185 reference operator[](unsigned n) {
9286 assert(n < size() && "BitSetVector: Bit number out of range");
93 unsigned ndiv = n / WORDSIZE, nmod = n % WORDSIZE;
87 unsigned ndiv = n / BITSET_WORDSIZE, nmod = n % BITSET_WORDSIZE;
9488 return bitsetVec[ndiv][nmod];
9589 }
9690 iterator begin() { return iterator::begin(*this); }
115109 ///
116110 bool test(unsigned n) const {
117111 assert(n < size() && "BitSetVector: Bit number out of range");
118 unsigned ndiv = n / WORDSIZE, nmod = n % WORDSIZE;
112 unsigned ndiv = n / BITSET_WORDSIZE, nmod = n % BITSET_WORDSIZE;
119113 return bitsetVec[ndiv].test(nmod);
120114 }
121115 bool any() const {
202196
203197 // Increment and decrement operators (pre and post)
204198 iterator& operator++() {
205 if (++currentBit == WORDSIZE)
199 if (++currentBit == BITSET_WORDSIZE)
206200 { currentBit = 0; if (currentWord < bitvec->size()) ++currentWord; }
207201 return *this;
208202 }
209203 iterator& operator--() {
210204 if (currentBit == 0) {
211 currentBit = WORDSIZE-1;
205 currentBit = BITSET_WORDSIZE-1;
212206 currentWord = (currentWord == 0)? bitvec->size() : --currentWord;
213207 }
214208 else