summaryrefslogtreecommitdiffstats
path: root/include/llvm/ADT
diff options
context:
space:
mode:
authorrdivacky <rdivacky@FreeBSD.org>2010-05-04 16:11:02 +0000
committerrdivacky <rdivacky@FreeBSD.org>2010-05-04 16:11:02 +0000
commit750ce4d809c7e2a298a389a512a17652ff5be3f2 (patch)
tree70fbd90da02177c8e6ef82adba9fa8ace285a5e3 /include/llvm/ADT
parent5f970ec96e421f64db6b1c6509a902ea73d98cc7 (diff)
downloadFreeBSD-src-750ce4d809c7e2a298a389a512a17652ff5be3f2.zip
FreeBSD-src-750ce4d809c7e2a298a389a512a17652ff5be3f2.tar.gz
Update LLVM to r103004.
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r--include/llvm/ADT/APInt.h64
-rw-r--r--include/llvm/ADT/BitVector.h5
-rw-r--r--include/llvm/ADT/DenseMapInfo.h10
-rw-r--r--include/llvm/ADT/ImmutableSet.h2
-rw-r--r--include/llvm/ADT/Optional.h66
-rw-r--r--include/llvm/ADT/SCCIterator.h68
-rw-r--r--include/llvm/ADT/SmallBitVector.h165
-rw-r--r--include/llvm/ADT/SmallVector.h2
-rw-r--r--include/llvm/ADT/StringExtras.h21
-rw-r--r--include/llvm/ADT/StringRef.h4
10 files changed, 302 insertions, 105 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index 3f67ffb..ec76fbd 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -870,12 +870,28 @@ public:
/// @brief Unsigned less than comparison
bool ult(const APInt& RHS) const;
+ /// Regards both *this as an unsigned quantity and compares it with RHS for
+ /// the validity of the less-than relationship.
+ /// @returns true if *this < RHS when considered unsigned.
+ /// @brief Unsigned less than comparison
+ bool ult(uint64_t RHS) const {
+ return ult(APInt(getBitWidth(), RHS));
+ }
+
/// Regards both *this and RHS as signed quantities and compares them for
/// validity of the less-than relationship.
/// @returns true if *this < RHS when both are considered signed.
/// @brief Signed less than comparison
bool slt(const APInt& RHS) const;
+ /// Regards both *this as a signed quantity and compares it with RHS for
+ /// the validity of the less-than relationship.
+ /// @returns true if *this < RHS when considered signed.
+ /// @brief Signed less than comparison
+ bool slt(uint64_t RHS) const {
+ return slt(APInt(getBitWidth(), RHS));
+ }
+
/// Regards both *this and RHS as unsigned quantities and compares them for
/// validity of the less-or-equal relationship.
/// @returns true if *this <= RHS when both are considered unsigned.
@@ -884,6 +900,14 @@ public:
return ult(RHS) || eq(RHS);
}
+ /// Regards both *this as an unsigned quantity and compares it with RHS for
+ /// the validity of the less-or-equal relationship.
+ /// @returns true if *this <= RHS when considered unsigned.
+ /// @brief Unsigned less or equal comparison
+ bool ule(uint64_t RHS) const {
+ return ule(APInt(getBitWidth(), RHS));
+ }
+
/// Regards both *this and RHS as signed quantities and compares them for
/// validity of the less-or-equal relationship.
/// @returns true if *this <= RHS when both are considered signed.
@@ -892,6 +916,14 @@ public:
return slt(RHS) || eq(RHS);
}
+ /// Regards both *this as a signed quantity and compares it with RHS for
+ /// the validity of the less-or-equal relationship.
+ /// @returns true if *this <= RHS when considered signed.
+ /// @brief Signed less or equal comparison
+ bool sle(uint64_t RHS) const {
+ return sle(APInt(getBitWidth(), RHS));
+ }
+
/// Regards both *this and RHS as unsigned quantities and compares them for
/// the validity of the greater-than relationship.
/// @returns true if *this > RHS when both are considered unsigned.
@@ -900,6 +932,14 @@ public:
return !ult(RHS) && !eq(RHS);
}
+ /// Regards both *this as an unsigned quantity and compares it with RHS for
+ /// the validity of the greater-than relationship.
+ /// @returns true if *this > RHS when considered unsigned.
+ /// @brief Unsigned greater than comparison
+ bool ugt(uint64_t RHS) const {
+ return ugt(APInt(getBitWidth(), RHS));
+ }
+
/// Regards both *this and RHS as signed quantities and compares them for
/// the validity of the greater-than relationship.
/// @returns true if *this > RHS when both are considered signed.
@@ -908,6 +948,14 @@ public:
return !slt(RHS) && !eq(RHS);
}
+ /// Regards both *this as a signed quantity and compares it with RHS for
+ /// the validity of the greater-than relationship.
+ /// @returns true if *this > RHS when considered signed.
+ /// @brief Signed greater than comparison
+ bool sgt(uint64_t RHS) const {
+ return sgt(APInt(getBitWidth(), RHS));
+ }
+
/// Regards both *this and RHS as unsigned quantities and compares them for
/// validity of the greater-or-equal relationship.
/// @returns true if *this >= RHS when both are considered unsigned.
@@ -916,6 +964,14 @@ public:
return !ult(RHS);
}
+ /// Regards both *this as an unsigned quantity and compares it with RHS for
+ /// the validity of the greater-or-equal relationship.
+ /// @returns true if *this >= RHS when considered unsigned.
+ /// @brief Unsigned greater or equal comparison
+ bool uge(uint64_t RHS) const {
+ return uge(APInt(getBitWidth(), RHS));
+ }
+
/// Regards both *this and RHS as signed quantities and compares them for
/// validity of the greater-or-equal relationship.
/// @returns true if *this >= RHS when both are considered signed.
@@ -924,6 +980,14 @@ public:
return !slt(RHS);
}
+ /// Regards both *this as a signed quantity and compares it with RHS for
+ /// the validity of the greater-or-equal relationship.
+ /// @returns true if *this >= RHS when considered signed.
+ /// @brief Signed greater or equal comparison
+ bool sge(uint64_t RHS) const {
+ return sge(APInt(getBitWidth(), RHS));
+ }
+
/// This operation tests if there are any pairs of corresponding bits
/// between this APInt and RHS that are both set.
bool intersects(const APInt &RHS) const {
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h
index 3a86b0d..9dcb9e1 100644
--- a/include/llvm/ADT/BitVector.h
+++ b/include/llvm/ADT/BitVector.h
@@ -49,6 +49,11 @@ public:
~reference() {}
+ reference &operator=(reference t) {
+ *this = bool(t);
+ return *this;
+ }
+
reference& operator=(bool t) {
if (t)
*WordRef |= 1L << BitPos;
diff --git a/include/llvm/ADT/DenseMapInfo.h b/include/llvm/ADT/DenseMapInfo.h
index 41197a1..5299386 100644
--- a/include/llvm/ADT/DenseMapInfo.h
+++ b/include/llvm/ADT/DenseMapInfo.h
@@ -92,6 +92,16 @@ template<> struct DenseMapInfo<unsigned long long> {
}
};
+// Provide DenseMapInfo for ints.
+template<> struct DenseMapInfo<int> {
+ static inline int getEmptyKey() { return 0x7fffffff; }
+ static inline int getTombstoneKey() { return -0x7fffffff - 1; }
+ static unsigned getHashValue(const int& Val) { return (unsigned)(Val * 37); }
+ static bool isEqual(const int& LHS, const int& RHS) {
+ return LHS == RHS;
+ }
+};
+
// Provide DenseMapInfo for long longs.
template<> struct DenseMapInfo<long long> {
static inline long long getEmptyKey() { return 0x7fffffffffffffffLL; }
diff --git a/include/llvm/ADT/ImmutableSet.h b/include/llvm/ADT/ImmutableSet.h
index 65e70e2..70c3caf 100644
--- a/include/llvm/ADT/ImmutableSet.h
+++ b/include/llvm/ADT/ImmutableSet.h
@@ -189,6 +189,8 @@ public:
unsigned verify() const {
unsigned HL = getLeft() ? getLeft()->verify() : 0;
unsigned HR = getRight() ? getRight()->verify() : 0;
+ (void) HL;
+ (void) HR;
assert(getHeight() == ( HL > HR ? HL : HR ) + 1
&& "Height calculation wrong");
diff --git a/include/llvm/ADT/Optional.h b/include/llvm/ADT/Optional.h
new file mode 100644
index 0000000..34e54a0
--- /dev/null
+++ b/include/llvm/ADT/Optional.h
@@ -0,0 +1,66 @@
+//===-- Optional.h - Simple variant for passing optional values ---*- C++ -*-=//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides Optional, a template class modeled in the spirit of
+// OCaml's 'opt' variant. The idea is to strongly type whether or not
+// a value can be optional.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ADT_OPTIONAL
+#define LLVM_ADT_OPTIONAL
+
+#include <cassert>
+
+namespace llvm {
+
+template<typename T>
+class Optional {
+ T x;
+ unsigned hasVal : 1;
+public:
+ explicit Optional() : x(), hasVal(false) {}
+ Optional(const T &y) : x(y), hasVal(true) {}
+
+ static inline Optional create(const T* y) {
+ return y ? Optional(*y) : Optional();
+ }
+
+ Optional &operator=(const T &y) {
+ x = y;
+ hasVal = true;
+ return *this;
+ }
+
+ const T* getPointer() const { assert(hasVal); return &x; }
+ const T& getValue() const { assert(hasVal); return x; }
+
+ operator bool() const { return hasVal; }
+ bool hasValue() const { return hasVal; }
+ const T* operator->() const { return getPointer(); }
+ const T& operator*() const { assert(hasVal); return x; }
+};
+
+template<typename T> struct simplify_type;
+
+template <typename T>
+struct simplify_type<const Optional<T> > {
+ typedef const T* SimpleType;
+ static SimpleType getSimplifiedValue(const Optional<T> &Val) {
+ return Val.getPointer();
+ }
+};
+
+template <typename T>
+struct simplify_type<Optional<T> >
+ : public simplify_type<const Optional<T> > {};
+
+} // end llvm namespace
+
+#endif
diff --git a/include/llvm/ADT/SCCIterator.h b/include/llvm/ADT/SCCIterator.h
index d38ce4c..c49d599 100644
--- a/include/llvm/ADT/SCCIterator.h
+++ b/include/llvm/ADT/SCCIterator.h
@@ -66,7 +66,7 @@ class scc_iterator
std::vector<unsigned> MinVisitNumStack;
// A single "visit" within the non-recursive DFS traversal.
- void DFSVisitOne(NodeType* N) {
+ void DFSVisitOne(NodeType *N) {
++visitNum; // Global counter for the visit order
nodeVisitNumbers[N] = visitNum;
SCCNodeStack.push_back(N);
@@ -83,13 +83,14 @@ class scc_iterator
// TOS has at least one more child so continue DFS
NodeType *childN = *VisitStack.back().second++;
if (!nodeVisitNumbers.count(childN)) {
- // this node has never been seen
+ // this node has never been seen.
DFSVisitOne(childN);
- } else {
- unsigned childNum = nodeVisitNumbers[childN];
- if (MinVisitNumStack.back() > childNum)
- MinVisitNumStack.back() = childNum;
+ continue;
}
+
+ unsigned childNum = nodeVisitNumbers[childN];
+ if (MinVisitNumStack.back() > childNum)
+ MinVisitNumStack.back() = childNum;
}
}
@@ -100,7 +101,7 @@ class scc_iterator
while (!VisitStack.empty()) {
DFSVisitChildren();
assert(VisitStack.back().second ==GT::child_end(VisitStack.back().first));
- NodeType* visitingN = VisitStack.back().first;
+ NodeType *visitingN = VisitStack.back().first;
unsigned minVisitNum = MinVisitNumStack.back();
VisitStack.pop_back();
MinVisitNumStack.pop_back();
@@ -111,18 +112,19 @@ class scc_iterator
// " : minVisitNum = " << minVisitNum << "; Node visit num = " <<
// nodeVisitNumbers[visitingN] << "\n";
- if (minVisitNum == nodeVisitNumbers[visitingN]) {
- // A full SCC is on the SCCNodeStack! It includes all nodes below
- // visitingN on the stack. Copy those nodes to CurrentSCC,
- // reset their minVisit values, and return (this suspends
- // the DFS traversal till the next ++).
- do {
- CurrentSCC.push_back(SCCNodeStack.back());
- SCCNodeStack.pop_back();
- nodeVisitNumbers[CurrentSCC.back()] = ~0U;
- } while (CurrentSCC.back() != visitingN);
- return;
- }
+ if (minVisitNum != nodeVisitNumbers[visitingN])
+ continue;
+
+ // A full SCC is on the SCCNodeStack! It includes all nodes below
+ // visitingN on the stack. Copy those nodes to CurrentSCC,
+ // reset their minVisit values, and return (this suspends
+ // the DFS traversal till the next ++).
+ do {
+ CurrentSCC.push_back(SCCNodeStack.back());
+ SCCNodeStack.pop_back();
+ nodeVisitNumbers[CurrentSCC.back()] = ~0U;
+ } while (CurrentSCC.back() != visitingN);
+ return;
}
}
@@ -136,11 +138,11 @@ public:
typedef scc_iterator<GraphT, GT> _Self;
// Provide static "constructors"...
- static inline _Self begin(const GraphT& G) { return _Self(GT::getEntryNode(G)); }
- static inline _Self end (const GraphT& G) { return _Self(); }
+ static inline _Self begin(const GraphT &G){return _Self(GT::getEntryNode(G));}
+ static inline _Self end (const GraphT &G) { return _Self(); }
- // Direct loop termination test (I.fini() is more efficient than I == end())
- inline bool fini() const {
+ // Direct loop termination test: I.isAtEnd() is more efficient than I == end()
+ inline bool isAtEnd() const {
assert(!CurrentSCC.empty() || VisitStack.empty());
return CurrentSCC.empty();
}
@@ -181,28 +183,36 @@ public:
return true;
return false;
}
+
+ /// ReplaceNode - This informs the scc_iterator that the specified Old node
+ /// has been deleted, and New is to be used in its place.
+ void ReplaceNode(NodeType *Old, NodeType *New) {
+ assert(nodeVisitNumbers.count(Old) && "Old not in scc_iterator?");
+ nodeVisitNumbers[New] = nodeVisitNumbers[Old];
+ nodeVisitNumbers.erase(Old);
+ }
};
// Global constructor for the SCC iterator.
template <class T>
-scc_iterator<T> scc_begin(const T& G) {
+scc_iterator<T> scc_begin(const T &G) {
return scc_iterator<T>::begin(G);
}
template <class T>
-scc_iterator<T> scc_end(const T& G) {
+scc_iterator<T> scc_end(const T &G) {
return scc_iterator<T>::end(G);
}
template <class T>
-scc_iterator<Inverse<T> > scc_begin(const Inverse<T>& G) {
- return scc_iterator<Inverse<T> >::begin(G);
+scc_iterator<Inverse<T> > scc_begin(const Inverse<T> &G) {
+ return scc_iterator<Inverse<T> >::begin(G);
}
template <class T>
-scc_iterator<Inverse<T> > scc_end(const Inverse<T>& G) {
- return scc_iterator<Inverse<T> >::end(G);
+scc_iterator<Inverse<T> > scc_end(const Inverse<T> &G) {
+ return scc_iterator<Inverse<T> >::end(G);
}
} // End llvm namespace
diff --git a/include/llvm/ADT/SmallBitVector.h b/include/llvm/ADT/SmallBitVector.h
index 5c774b9..3441d0a 100644
--- a/include/llvm/ADT/SmallBitVector.h
+++ b/include/llvm/ADT/SmallBitVector.h
@@ -15,7 +15,6 @@
#define LLVM_ADT_SMALLBITVECTOR_H
#include "llvm/ADT/BitVector.h"
-#include "llvm/ADT/PointerIntPair.h"
#include "llvm/Support/MathExtras.h"
#include <cassert>
@@ -32,48 +31,85 @@ class SmallBitVector {
// TODO: In "large" mode, a pointer to a BitVector is used, leading to an
// unnecessary level of indirection. It would be more efficient to use a
// pointer to memory containing size, allocation size, and the array of bits.
- PointerIntPair<BitVector *, 1, uintptr_t> X;
+ uintptr_t X;
- // The number of bits in this class.
- static const size_t NumBaseBits = sizeof(uintptr_t) * CHAR_BIT;
+ enum {
+ // The number of bits in this class.
+ NumBaseBits = sizeof(uintptr_t) * CHAR_BIT,
- // One bit is used to discriminate between small and large mode. The
- // remaining bits are used for the small-mode representation.
- static const size_t SmallNumRawBits = NumBaseBits - 1;
+ // One bit is used to discriminate between small and large mode. The
+ // remaining bits are used for the small-mode representation.
+ SmallNumRawBits = NumBaseBits - 1,
- // A few more bits are used to store the size of the bit set in small mode.
- // Theoretically this is a ceil-log2. These bits are encoded in the most
- // significant bits of the raw bits.
- static const size_t SmallNumSizeBits = (NumBaseBits == 32 ? 5 :
- NumBaseBits == 64 ? 6 :
- SmallNumRawBits);
+ // A few more bits are used to store the size of the bit set in small mode.
+ // Theoretically this is a ceil-log2. These bits are encoded in the most
+ // significant bits of the raw bits.
+ SmallNumSizeBits = (NumBaseBits == 32 ? 5 :
+ NumBaseBits == 64 ? 6 :
+ SmallNumRawBits),
- // The remaining bits are used to store the actual set in small mode.
- static const size_t SmallNumDataBits = SmallNumRawBits - SmallNumSizeBits;
+ // The remaining bits are used to store the actual set in small mode.
+ SmallNumDataBits = SmallNumRawBits - SmallNumSizeBits
+ };
+public:
+ // Encapsulation of a single bit.
+ class reference {
+ SmallBitVector &TheVector;
+ unsigned BitPos;
+
+ public:
+ reference(SmallBitVector &b, unsigned Idx) : TheVector(b), BitPos(Idx) {}
+
+ reference& operator=(reference t) {
+ *this = bool(t);
+ return *this;
+ }
+
+ reference& operator=(bool t) {
+ if (t)
+ TheVector.set(BitPos);
+ else
+ TheVector.reset(BitPos);
+ return *this;
+ }
+
+ operator bool() const {
+ return const_cast<const SmallBitVector &>(TheVector).operator[](BitPos);
+ }
+ };
+
+private:
bool isSmall() const {
- return X.getInt();
+ return X & uintptr_t(1);
+ }
+
+ BitVector *getPointer() const {
+ assert(!isSmall());
+ return reinterpret_cast<BitVector *>(X);
}
void switchToSmall(uintptr_t NewSmallBits, size_t NewSize) {
- X.setInt(true);
+ X = 1;
setSmallSize(NewSize);
setSmallBits(NewSmallBits);
}
void switchToLarge(BitVector *BV) {
- X.setInt(false);
- X.setPointer(BV);
+ X = reinterpret_cast<uintptr_t>(BV);
+ assert(!isSmall() && "Tried to use an unaligned pointer");
}
// Return all the bits used for the "small" representation; this includes
// bits for the size as well as the element bits.
uintptr_t getSmallRawBits() const {
- return reinterpret_cast<uintptr_t>(X.getPointer()) >> 1;
+ assert(isSmall());
+ return X >> 1;
}
void setSmallRawBits(uintptr_t NewRawBits) {
- return X.setPointer(reinterpret_cast<BitVector *>(NewRawBits << 1));
+ assert(isSmall());
+ X = (NewRawBits << 1) | uintptr_t(1);
}
// Return the size.
@@ -87,22 +123,22 @@ class SmallBitVector {
// Return the element bits.
uintptr_t getSmallBits() const {
- return getSmallRawBits() & ~(~uintptr_t(0) << SmallNumDataBits);
+ return getSmallRawBits() & ~(~uintptr_t(0) << getSmallSize());
}
void setSmallBits(uintptr_t NewBits) {
- setSmallRawBits((getSmallRawBits() & (~uintptr_t(0) << SmallNumDataBits)) |
- (NewBits & ~(~uintptr_t(0) << getSmallSize())));
+ setSmallRawBits((NewBits & ~(~uintptr_t(0) << getSmallSize())) |
+ (getSmallSize() << SmallNumDataBits));
}
public:
/// SmallBitVector default ctor - Creates an empty bitvector.
- SmallBitVector() : X(0, 1) {}
+ SmallBitVector() : X(1) {}
/// SmallBitVector ctor - Creates a bitvector of specified number of bits. All
/// bits are initialized to the specified value.
- explicit SmallBitVector(unsigned s, bool t = false) : X(0, 1) {
- if (s <= SmallNumRawBits)
+ explicit SmallBitVector(unsigned s, bool t = false) {
+ if (s <= SmallNumDataBits)
switchToSmall(t ? ~uintptr_t(0) : 0, s);
else
switchToLarge(new BitVector(s, t));
@@ -113,22 +149,22 @@ public:
if (RHS.isSmall())
X = RHS.X;
else
- switchToLarge(new BitVector(*RHS.X.getPointer()));
+ switchToLarge(new BitVector(*RHS.getPointer()));
}
~SmallBitVector() {
if (!isSmall())
- delete X.getPointer();
+ delete getPointer();
}
/// empty - Tests whether there are no bits in this bitvector.
bool empty() const {
- return isSmall() ? getSmallSize() == 0 : X.getPointer()->empty();
+ return isSmall() ? getSmallSize() == 0 : getPointer()->empty();
}
/// size - Returns the number of bits in this bitvector.
size_t size() const {
- return isSmall() ? getSmallSize() : X.getPointer()->size();
+ return isSmall() ? getSmallSize() : getPointer()->size();
}
/// count - Returns the number of bits which are set.
@@ -141,21 +177,21 @@ public:
return CountPopulation_64(Bits);
assert(0 && "Unsupported!");
}
- return X.getPointer()->count();
+ return getPointer()->count();
}
/// any - Returns true if any bit is set.
bool any() const {
if (isSmall())
return getSmallBits() != 0;
- return X.getPointer()->any();
+ return getPointer()->any();
}
/// none - Returns true if none of the bits are set.
bool none() const {
if (isSmall())
return getSmallBits() == 0;
- return X.getPointer()->none();
+ return getPointer()->none();
}
/// find_first - Returns the index of the first set bit, -1 if none
@@ -163,13 +199,15 @@ public:
int find_first() const {
if (isSmall()) {
uintptr_t Bits = getSmallBits();
+ if (Bits == 0)
+ return -1;
if (sizeof(uintptr_t) * CHAR_BIT == 32)
return CountTrailingZeros_32(Bits);
if (sizeof(uintptr_t) * CHAR_BIT == 64)
return CountTrailingZeros_64(Bits);
assert(0 && "Unsupported!");
}
- return X.getPointer()->find_first();
+ return getPointer()->find_first();
}
/// find_next - Returns the index of the next set bit following the
@@ -178,30 +216,33 @@ public:
if (isSmall()) {
uintptr_t Bits = getSmallBits();
// Mask off previous bits.
- Bits &= ~uintptr_t(0) << Prev;
+ Bits &= ~uintptr_t(0) << (Prev + 1);
+ if (Bits == 0 || Prev + 1 >= getSmallSize())
+ return -1;
if (sizeof(uintptr_t) * CHAR_BIT == 32)
return CountTrailingZeros_32(Bits);
if (sizeof(uintptr_t) * CHAR_BIT == 64)
return CountTrailingZeros_64(Bits);
assert(0 && "Unsupported!");
}
- return X.getPointer()->find_next(Prev);
+ return getPointer()->find_next(Prev);
}
/// clear - Clear all bits.
void clear() {
if (!isSmall())
- delete X.getPointer();
+ delete getPointer();
switchToSmall(0, 0);
}
/// resize - Grow or shrink the bitvector.
void resize(unsigned N, bool t = false) {
if (!isSmall()) {
- X.getPointer()->resize(N, t);
- } else if (getSmallSize() >= N) {
+ getPointer()->resize(N, t);
+ } else if (SmallNumDataBits >= N) {
+ uintptr_t NewBits = t ? ~uintptr_t(0) << getSmallSize() : 0;
setSmallSize(N);
- setSmallBits(getSmallBits());
+ setSmallBits(NewBits | getSmallBits());
} else {
BitVector *BV = new BitVector(N, t);
uintptr_t OldBits = getSmallBits();
@@ -224,7 +265,7 @@ public:
switchToLarge(BV);
}
} else {
- X.getPointer()->reserve(N);
+ getPointer()->reserve(N);
}
}
@@ -233,7 +274,7 @@ public:
if (isSmall())
setSmallBits(~uintptr_t(0));
else
- X.getPointer()->set();
+ getPointer()->set();
return *this;
}
@@ -241,7 +282,7 @@ public:
if (isSmall())
setSmallBits(getSmallBits() | (uintptr_t(1) << Idx));
else
- X.getPointer()->set(Idx);
+ getPointer()->set(Idx);
return *this;
}
@@ -249,7 +290,7 @@ public:
if (isSmall())
setSmallBits(0);
else
- X.getPointer()->reset();
+ getPointer()->reset();
return *this;
}
@@ -257,7 +298,7 @@ public:
if (isSmall())
setSmallBits(getSmallBits() & ~(uintptr_t(1) << Idx));
else
- X.getPointer()->reset(Idx);
+ getPointer()->reset(Idx);
return *this;
}
@@ -265,7 +306,7 @@ public:
if (isSmall())
setSmallBits(~getSmallBits());
else
- X.getPointer()->flip();
+ getPointer()->flip();
return *this;
}
@@ -273,7 +314,7 @@ public:
if (isSmall())
setSmallBits(getSmallBits() ^ (uintptr_t(1) << Idx));
else
- X.getPointer()->flip(Idx);
+ getPointer()->flip(Idx);
return *this;
}
@@ -283,12 +324,16 @@ public:
}
// Indexing.
- // TODO: Add an index operator which returns a "reference" (proxy class).
+ 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.");
if (isSmall())
return ((getSmallBits() >> Idx) & 1) != 0;
- return X.getPointer()->operator[](Idx);
+ return getPointer()->operator[](Idx);
}
bool test(unsigned Idx) const {
@@ -302,7 +347,7 @@ public:
if (isSmall())
return getSmallBits() == RHS.getSmallBits();
else
- return *X.getPointer() == *RHS.X.getPointer();
+ return *getPointer() == *RHS.getPointer();
}
bool operator!=(const SmallBitVector &RHS) const {
@@ -315,11 +360,11 @@ public:
if (isSmall())
setSmallBits(getSmallBits() & RHS.getSmallBits());
else if (!RHS.isSmall())
- X.getPointer()->operator&=(*RHS.X.getPointer());
+ getPointer()->operator&=(*RHS.getPointer());
else {
SmallBitVector Copy = RHS;
Copy.resize(size());
- X.getPointer()->operator&=(*Copy.X.getPointer());
+ getPointer()->operator&=(*Copy.getPointer());
}
return *this;
}
@@ -329,11 +374,11 @@ public:
if (isSmall())
setSmallBits(getSmallBits() | RHS.getSmallBits());
else if (!RHS.isSmall())
- X.getPointer()->operator|=(*RHS.X.getPointer());
+ getPointer()->operator|=(*RHS.getPointer());
else {
SmallBitVector Copy = RHS;
Copy.resize(size());
- X.getPointer()->operator|=(*Copy.X.getPointer());
+ getPointer()->operator|=(*Copy.getPointer());
}
return *this;
}
@@ -343,11 +388,11 @@ public:
if (isSmall())
setSmallBits(getSmallBits() ^ RHS.getSmallBits());
else if (!RHS.isSmall())
- X.getPointer()->operator^=(*RHS.X.getPointer());
+ getPointer()->operator^=(*RHS.getPointer());
else {
SmallBitVector Copy = RHS;
Copy.resize(size());
- X.getPointer()->operator^=(*Copy.X.getPointer());
+ getPointer()->operator^=(*Copy.getPointer());
}
return *this;
}
@@ -358,12 +403,12 @@ public:
if (RHS.isSmall())
X = RHS.X;
else
- switchToLarge(new BitVector(*RHS.X.getPointer()));
+ switchToLarge(new BitVector(*RHS.getPointer()));
} else {
if (!RHS.isSmall())
- *X.getPointer() = *RHS.X.getPointer();
+ *getPointer() = *RHS.getPointer();
else {
- delete X.getPointer();
+ delete getPointer();
X = RHS.X;
}
}
diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h
index 2d79a02..18c8619 100644
--- a/include/llvm/ADT/SmallVector.h
+++ b/include/llvm/ADT/SmallVector.h
@@ -59,7 +59,7 @@ protected:
// number of union instances for the space, which guarantee maximal alignment.
struct U {
#ifdef __GNUC__
- char X __attribute__((aligned));
+ char X __attribute__((aligned(8)));
#else
union {
double D;
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index 1ea546f..3c53ade 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -57,15 +57,14 @@ static inline char *utohex_buffer(IntTy X, char *BufferEnd) {
}
static inline std::string utohexstr(uint64_t X) {
- char Buffer[40];
- return utohex_buffer(X, Buffer+40);
+ char Buffer[17];
+ return utohex_buffer(X, Buffer+17);
}
static inline std::string utostr_32(uint32_t X, bool isNeg = false) {
- char Buffer[20];
- char *BufPtr = Buffer+19;
+ char Buffer[11];
+ char *BufPtr = Buffer+11;
- *BufPtr = 0; // Null terminate buffer...
if (X == 0) *--BufPtr = '0'; // Handle special case...
while (X) {
@@ -75,17 +74,13 @@ static inline std::string utostr_32(uint32_t X, bool isNeg = false) {
if (isNeg) *--BufPtr = '-'; // Add negative sign...
- return std::string(BufPtr);
+ return std::string(BufPtr, Buffer+11);
}
static inline std::string utostr(uint64_t X, bool isNeg = false) {
- if (X == uint32_t(X))
- return utostr_32(uint32_t(X), isNeg);
+ char Buffer[21];
+ char *BufPtr = Buffer+21;
- char Buffer[40];
- char *BufPtr = Buffer+39;
-
- *BufPtr = 0; // Null terminate buffer...
if (X == 0) *--BufPtr = '0'; // Handle special case...
while (X) {
@@ -94,7 +89,7 @@ static inline std::string utostr(uint64_t X, bool isNeg = false) {
}
if (isNeg) *--BufPtr = '-'; // Add negative sign...
- return std::string(BufPtr);
+ return std::string(BufPtr, Buffer+21);
}
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h
index 9257770..ab6358b 100644
--- a/include/llvm/ADT/StringRef.h
+++ b/include/llvm/ADT/StringRef.h
@@ -44,8 +44,8 @@ namespace llvm {
// Workaround PR5482: nearly all gcc 4.x miscompile StringRef and std::min()
// Changing the arg of min to be an integer, instead of a reference to an
// integer works around this bug.
- size_t min(size_t a, size_t b) const { return a < b ? a : b; }
- size_t max(size_t a, size_t b) const { return a > b ? a : b; }
+ static size_t min(size_t a, size_t b) { return a < b ? a : b; }
+ static size_t max(size_t a, size_t b) { return a > b ? a : b; }
public:
/// @name Constructors
OpenPOWER on IntegriCloud