Skip to content

Commit

Permalink
[ADT, Support, TableGen] Fix some Clang-tidy modernize-use-default an…
Browse files Browse the repository at this point in the history
…d Include What You Use warnings; other minor fixes (NFC).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288424 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
EugeneZelenko committed Dec 1, 2016
1 parent 2af4e8b commit 9ed0c7a
Show file tree
Hide file tree
Showing 12 changed files with 318 additions and 161 deletions.
50 changes: 27 additions & 23 deletions include/llvm/ADT/SparseBitVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#ifndef LLVM_ADT_SPARSEBITVECTOR_H
#define LLVM_ADT_SPARSEBITVECTOR_H

#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <climits>
#include <cstring>
#include <iterator>
#include <list>

namespace llvm {
Expand Down Expand Up @@ -52,6 +53,7 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
// Index of Element in terms of where first bit starts.
unsigned ElementIndex;
BitWord Bits[BITWORDS_PER_ELEMENT];

SparseBitVectorElement() {
ElementIndex = ~0U;
memset(&Bits[0], 0, sizeof (BitWord) * BITWORDS_PER_ELEMENT);
Expand Down Expand Up @@ -79,7 +81,7 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {

// Return the bits that make up word Idx in our element.
BitWord word(unsigned Idx) const {
assert (Idx < BITWORDS_PER_ELEMENT);
assert(Idx < BITWORDS_PER_ELEMENT);
return Bits[Idx];
}

Expand Down Expand Up @@ -139,8 +141,8 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
unsigned WordPos = Curr / BITWORD_SIZE;
unsigned BitPos = Curr % BITWORD_SIZE;
BitWord Copy = Bits[WordPos];
assert (WordPos <= BITWORDS_PER_ELEMENT
&& "Word Position outside of element");
assert(WordPos <= BITWORDS_PER_ELEMENT
&& "Word Position outside of element");

// Mask off previous bits.
Copy &= ~0UL << BitPos;
Expand Down Expand Up @@ -289,7 +291,7 @@ class SparseBitVector {
private:
bool AtEnd;

const SparseBitVector<ElementSize> *BitVector;
const SparseBitVector<ElementSize> *BitVector = nullptr;

// Current element inside of bitmap.
ElementListConstIter Iter;
Expand Down Expand Up @@ -359,7 +361,20 @@ class SparseBitVector {
}
}
}

public:
SparseBitVectorIterator() = default;

SparseBitVectorIterator(const SparseBitVector<ElementSize> *RHS,
bool end = false):BitVector(RHS) {
Iter = BitVector->Elements.begin();
BitNumber = 0;
Bits = 0;
WordNumber = ~0;
AtEnd = end;
AdvanceToFirstNonZero();
}

// Preincrement.
inline SparseBitVectorIterator& operator++() {
++BitNumber;
Expand Down Expand Up @@ -392,29 +407,16 @@ class SparseBitVector {
bool operator!=(const SparseBitVectorIterator &RHS) const {
return !(*this == RHS);
}

SparseBitVectorIterator(): BitVector(nullptr) {
}

SparseBitVectorIterator(const SparseBitVector<ElementSize> *RHS,
bool end = false):BitVector(RHS) {
Iter = BitVector->Elements.begin();
BitNumber = 0;
Bits = 0;
WordNumber = ~0;
AtEnd = end;
AdvanceToFirstNonZero();
}
};

public:
typedef SparseBitVectorIterator iterator;

SparseBitVector () {
CurrElementIter = Elements.begin ();
SparseBitVector() {
CurrElementIter = Elements.begin();
}

~SparseBitVector() {
}
~SparseBitVector() = default;

// SparseBitVector copy ctor.
SparseBitVector(const SparseBitVector &RHS) {
Expand Down Expand Up @@ -511,7 +513,7 @@ class SparseBitVector {
ElementIter->set(Idx % ElementSize);
}

bool test_and_set (unsigned Idx) {
bool test_and_set(unsigned Idx) {
bool old = test(Idx);
if (!old) {
set(Idx);
Expand Down Expand Up @@ -780,6 +782,7 @@ class SparseBitVector {

return BitCount;
}

iterator begin() const {
return iterator(this);
}
Expand Down Expand Up @@ -860,6 +863,7 @@ void dump(const SparseBitVector<ElementSize> &LHS, raw_ostream &out) {
}
out << "]\n";
}

} // end namespace llvm

#endif // LLVM_ADT_SPARSEBITVECTOR_H
20 changes: 16 additions & 4 deletions include/llvm/ADT/TinyPtrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
#define LLVM_ADT_TINYPTRVECTOR_H

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/SmallVector.h"
#include <cassert>
#include <cstddef>
#include <iterator>
#include <type_traits>

namespace llvm {

Expand All @@ -25,15 +30,16 @@ namespace llvm {
template <typename EltTy>
class TinyPtrVector {
public:
typedef llvm::SmallVector<EltTy, 4> VecTy;
typedef SmallVector<EltTy, 4> VecTy;
typedef typename VecTy::value_type value_type;
typedef llvm::PointerUnion<EltTy, VecTy *> PtrUnion;
typedef PointerUnion<EltTy, VecTy *> PtrUnion;

private:
PtrUnion Val;

public:
TinyPtrVector() {}
TinyPtrVector() = default;

~TinyPtrVector() {
if (VecTy *V = Val.template dyn_cast<VecTy*>())
delete V;
Expand All @@ -43,6 +49,7 @@ class TinyPtrVector {
if (VecTy *V = Val.template dyn_cast<VecTy*>())
Val = new VecTy(*V);
}

TinyPtrVector &operator=(const TinyPtrVector &RHS) {
if (this == &RHS)
return *this;
Expand Down Expand Up @@ -74,6 +81,7 @@ class TinyPtrVector {
TinyPtrVector(TinyPtrVector &&RHS) : Val(RHS.Val) {
RHS.Val = (EltTy)nullptr;
}

TinyPtrVector &operator=(TinyPtrVector &&RHS) {
if (this == &RHS)
return *this;
Expand Down Expand Up @@ -170,6 +178,7 @@ class TinyPtrVector {

return Val.template get<VecTy *>()->begin();
}

iterator end() {
if (Val.template is<EltTy>())
return begin() + (Val.isNull() ? 0 : 1);
Expand All @@ -187,9 +196,11 @@ class TinyPtrVector {

reverse_iterator rbegin() { return reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }

const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}

const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
Expand Down Expand Up @@ -329,6 +340,7 @@ class TinyPtrVector {
return Val.template get<VecTy*>()->insert(begin() + Offset, From, To);
}
};

} // end namespace llvm

#endif
#endif // LLVM_ADT_TINYPTRVECTOR_H
Loading

0 comments on commit 9ed0c7a

Please sign in to comment.