Added ImmutableMap constructor that accepts a const TreeTy*.
[oota-llvm.git] / include / llvm / ADT / BitVector.h
index 927cfa9f7869ab83645e78d1ed85cc8c4a1eb95b..a2f273df4a23ba1ae28c514acbe35d99aa44d835 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by Evan Cheng and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 
 #include "llvm/Support/MathExtras.h"
 #include <algorithm>
-#include <cstdlib>
 #include <cassert>
+#include <cstring>
 
 namespace llvm {
 
 class BitVector {
   typedef unsigned long BitWord;
 
-  enum { BITWORD_SIZE = sizeof(BitWord) * 8 };
+  enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * 8 };
 
   BitWord  *Bits;        // Actual bits. 
   unsigned Size;         // Size of bitvector in bits.
@@ -64,7 +64,7 @@ public:
 
   /// BitVector default ctor - Creates an empty bitvector.
   BitVector() : Size(0), Capacity(0) {
-    Bits = NULL;
+    Bits = 0;
   }
 
   /// BitVector ctor - Creates a bitvector of specified number of bits. All
@@ -80,7 +80,7 @@ public:
   /// BitVector copy ctor.
   BitVector(const BitVector &RHS) : Size(RHS.size()) {
     if (Size == 0) {
-      Bits = NULL;
+      Bits = 0;
       Capacity = 0;
       return;
     }
@@ -102,7 +102,7 @@ public:
     unsigned NumBits = 0;
     for (unsigned i = 0; i < NumBitWords(size()); ++i)
       if (sizeof(BitWord) == 4)
-        NumBits += CountPopulation_32(Bits[i]);
+        NumBits += CountPopulation_32((uint32_t)Bits[i]);
       else if (sizeof(BitWord) == 8)
         NumBits += CountPopulation_64(Bits[i]);
       else
@@ -129,7 +129,7 @@ public:
     for (unsigned i = 0; i < NumBitWords(size()); ++i)
       if (Bits[i] != 0) {
         if (sizeof(BitWord) == 4)
-          return i * BITWORD_SIZE + CountTrailingZeros_32(Bits[i]);
+          return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
         else if (sizeof(BitWord) == 8)
           return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
         else
@@ -153,7 +153,7 @@ public:
 
     if (Copy != 0) {
       if (sizeof(BitWord) == 4)
-        return WordPos * BITWORD_SIZE + CountTrailingZeros_32(Copy);
+        return WordPos * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Copy);
       else if (sizeof(BitWord) == 8)
         return WordPos * BITWORD_SIZE + CountTrailingZeros_64(Copy);
       else
@@ -164,7 +164,7 @@ public:
     for (unsigned i = WordPos+1; i < NumBitWords(size()); ++i)
       if (Bits[i] != 0) {
         if (sizeof(BitWord) == 4)
-          return i * BITWORD_SIZE + CountTrailingZeros_32(Bits[i]);
+          return i * BITWORD_SIZE + CountTrailingZeros_32((uint32_t)Bits[i]);
         else if (sizeof(BitWord) == 8)
           return i * BITWORD_SIZE + CountTrailingZeros_64(Bits[i]);
         else
@@ -245,10 +245,12 @@ public:
 
   // Indexing.
   reference operator[](unsigned Idx) {
+    assert (Idx < Size && "Out-of-bounds Bit access.");
     return reference(*this, Idx);
   }
 
   bool operator[](unsigned Idx) const {
+    assert (Idx < Size && "Out-of-bounds Bit access.");   
     BitWord Mask = 1L << (Idx % BITWORD_SIZE);
     return (Bits[Idx / BITWORD_SIZE] & Mask) != 0;
   }
@@ -375,6 +377,8 @@ private:
     // Destroy the old bits.
     delete[] Bits;
     Bits = NewBits;
+    
+    clear_unused_bits();
   }
 
   void init_words(BitWord *B, unsigned NumWords, bool t) {