summaryrefslogtreecommitdiff
path: root/include/llvm/ADT
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r--include/llvm/ADT/AllocatorList.h61
-rw-r--r--include/llvm/ADT/ArrayRef.h44
-rw-r--r--include/llvm/ADT/BreadthFirstIterator.h11
-rw-r--r--include/llvm/ADT/DAGDeltaAlgorithm.h10
-rw-r--r--include/llvm/ADT/DeltaAlgorithm.h10
-rw-r--r--include/llvm/ADT/DenseMap.h74
-rw-r--r--include/llvm/ADT/DenseMapInfo.h40
-rw-r--r--include/llvm/ADT/DenseSet.h46
-rw-r--r--include/llvm/ADT/DepthFirstIterator.h23
-rw-r--r--include/llvm/ADT/EquivalenceClasses.h22
-rw-r--r--include/llvm/ADT/FoldingSet.h233
-rw-r--r--include/llvm/ADT/GraphTraits.h15
-rw-r--r--include/llvm/ADT/ImmutableList.h8
-rw-r--r--include/llvm/ADT/ImmutableMap.h62
-rw-r--r--include/llvm/ADT/ImmutableSet.h121
-rw-r--r--include/llvm/ADT/IndexedMap.h18
-rw-r--r--include/llvm/ADT/IntervalMap.h49
-rw-r--r--include/llvm/ADT/IntrusiveRefCntPtr.h18
-rw-r--r--include/llvm/ADT/MapVector.h24
-rw-r--r--include/llvm/ADT/Optional.h33
-rw-r--r--include/llvm/ADT/PackedVector.h6
-rw-r--r--include/llvm/ADT/PointerEmbeddedInt.h30
-rw-r--r--include/llvm/ADT/PointerUnion.h2
-rw-r--r--include/llvm/ADT/ScopedHashTable.h12
-rw-r--r--include/llvm/ADT/SmallBitVector.h58
-rw-r--r--include/llvm/ADT/SmallSet.h7
-rw-r--r--include/llvm/ADT/StringExtras.h12
-rw-r--r--include/llvm/ADT/Triple.h4
-rw-r--r--include/llvm/ADT/ilist_base.h6
-rw-r--r--include/llvm/ADT/ilist_iterator.h59
-rw-r--r--include/llvm/ADT/ilist_node.h50
-rw-r--r--include/llvm/ADT/iterator.h8
-rw-r--r--include/llvm/ADT/simple_ilist.h33
33 files changed, 685 insertions, 524 deletions
diff --git a/include/llvm/ADT/AllocatorList.h b/include/llvm/ADT/AllocatorList.h
index 05a549f96ec70..178c6742a87b9 100644
--- a/include/llvm/ADT/AllocatorList.h
+++ b/include/llvm/ADT/AllocatorList.h
@@ -10,10 +10,16 @@
#ifndef LLVM_ADT_ALLOCATORLIST_H
#define LLVM_ADT_ALLOCATORLIST_H
+#include "llvm/ADT/ilist_node.h"
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/simple_ilist.h"
#include "llvm/Support/Allocator.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <iterator>
#include <type_traits>
+#include <utility>
namespace llvm {
@@ -39,7 +45,8 @@ template <class T, class AllocatorT> class AllocatorList : AllocatorT {
T V;
};
- typedef simple_ilist<Node> list_type;
+ using list_type = simple_ilist<Node>;
+
list_type List;
AllocatorT &getAlloc() { return *this; }
@@ -51,13 +58,17 @@ template <class T, class AllocatorT> class AllocatorList : AllocatorT {
struct Cloner {
AllocatorList &AL;
+
Cloner(AllocatorList &AL) : AL(AL) {}
+
Node *operator()(const Node &N) const { return AL.create(N.V); }
};
struct Disposer {
AllocatorList &AL;
+
Disposer(AllocatorList &AL) : AL(AL) {}
+
void operator()(Node *N) const {
N->~Node();
AL.getAlloc().Deallocate(N);
@@ -65,13 +76,13 @@ template <class T, class AllocatorT> class AllocatorList : AllocatorT {
};
public:
- typedef T value_type;
- typedef T *pointer;
- typedef T &reference;
- typedef const T *const_pointer;
- typedef const T &const_reference;
- typedef typename list_type::size_type size_type;
- typedef typename list_type::difference_type difference_type;
+ using value_type = T;
+ using pointer = T *;
+ using reference = T &;
+ using const_pointer = const T *;
+ using const_reference = const T &;
+ using size_type = typename list_type::size_type;
+ using difference_type = typename list_type::difference_type;
private:
template <class ValueT, class IteratorBase>
@@ -83,20 +94,18 @@ private:
friend class IteratorImpl;
friend AllocatorList;
- typedef iterator_adaptor_base<IteratorImpl<ValueT, IteratorBase>,
- IteratorBase, std::bidirectional_iterator_tag,
- ValueT>
- base_type;
+ using base_type =
+ iterator_adaptor_base<IteratorImpl<ValueT, IteratorBase>, IteratorBase,
+ std::bidirectional_iterator_tag, ValueT>;
public:
- typedef ValueT value_type;
- typedef ValueT *pointer;
- typedef ValueT &reference;
+ using value_type = ValueT;
+ using pointer = ValueT *;
+ using reference = ValueT &;
IteratorImpl() = default;
IteratorImpl(const IteratorImpl &) = default;
IteratorImpl &operator=(const IteratorImpl &) = default;
- ~IteratorImpl() = default;
explicit IteratorImpl(const IteratorBase &I) : base_type(I) {}
@@ -106,6 +115,8 @@ private:
OtherIteratorBase, IteratorBase>::value>::type * = nullptr)
: base_type(X.wrapped()) {}
+ ~IteratorImpl() = default;
+
reference operator*() const { return base_type::wrapped()->V; }
pointer operator->() const { return &operator*(); }
@@ -118,30 +129,34 @@ private:
};
public:
- typedef IteratorImpl<T, typename list_type::iterator> iterator;
- typedef IteratorImpl<T, typename list_type::reverse_iterator>
- reverse_iterator;
- typedef IteratorImpl<const T, typename list_type::const_iterator>
- const_iterator;
- typedef IteratorImpl<const T, typename list_type::const_reverse_iterator>
- const_reverse_iterator;
+ using iterator = IteratorImpl<T, typename list_type::iterator>;
+ using reverse_iterator =
+ IteratorImpl<T, typename list_type::reverse_iterator>;
+ using const_iterator =
+ IteratorImpl<const T, typename list_type::const_iterator>;
+ using const_reverse_iterator =
+ IteratorImpl<const T, typename list_type::const_reverse_iterator>;
AllocatorList() = default;
AllocatorList(AllocatorList &&X)
: AllocatorT(std::move(X.getAlloc())), List(std::move(X.List)) {}
+
AllocatorList(const AllocatorList &X) {
List.cloneFrom(X.List, Cloner(*this), Disposer(*this));
}
+
AllocatorList &operator=(AllocatorList &&X) {
clear(); // Dispose of current nodes explicitly.
List = std::move(X.List);
getAlloc() = std::move(X.getAlloc());
return *this;
}
+
AllocatorList &operator=(const AllocatorList &X) {
List.cloneFrom(X.List, Cloner(*this), Disposer(*this));
return *this;
}
+
~AllocatorList() { clear(); }
void swap(AllocatorList &RHS) {
diff --git a/include/llvm/ADT/ArrayRef.h b/include/llvm/ADT/ArrayRef.h
index 6b35d0aec8b2b..925ebafc3feda 100644
--- a/include/llvm/ADT/ArrayRef.h
+++ b/include/llvm/ADT/ArrayRef.h
@@ -1,4 +1,4 @@
-//===--- ArrayRef.h - Array Reference Wrapper -------------------*- C++ -*-===//
+//===- ArrayRef.h - Array Reference Wrapper ---------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -12,12 +12,21 @@
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/None.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Compiler.h"
+#include <algorithm>
#include <array>
+#include <cassert>
+#include <cstddef>
+#include <initializer_list>
+#include <iterator>
+#include <memory>
+#include <type_traits>
#include <vector>
namespace llvm {
+
/// ArrayRef - Represent a constant reference to an array (0 or more elements
/// consecutively in memory), i.e. a start pointer and a length. It allows
/// various APIs to take consecutive elements easily and conveniently.
@@ -32,28 +41,27 @@ namespace llvm {
template<typename T>
class LLVM_NODISCARD ArrayRef {
public:
- typedef const T *iterator;
- typedef const T *const_iterator;
- typedef size_t size_type;
-
- typedef std::reverse_iterator<iterator> reverse_iterator;
+ using iterator = const T *;
+ using const_iterator = const T *;
+ using size_type = size_t;
+ using reverse_iterator = std::reverse_iterator<iterator>;
private:
/// The start of the array, in an external buffer.
- const T *Data;
+ const T *Data = nullptr;
/// The number of elements.
- size_type Length;
+ size_type Length = 0;
public:
/// @name Constructors
/// @{
/// Construct an empty ArrayRef.
- /*implicit*/ ArrayRef() : Data(nullptr), Length(0) {}
+ /*implicit*/ ArrayRef() = default;
/// Construct an empty ArrayRef from None.
- /*implicit*/ ArrayRef(NoneType) : Data(nullptr), Length(0) {}
+ /*implicit*/ ArrayRef(NoneType) {}
/// Construct an ArrayRef from a single element.
/*implicit*/ ArrayRef(const T &OneElt)
@@ -282,9 +290,8 @@ namespace llvm {
template<typename T>
class LLVM_NODISCARD MutableArrayRef : public ArrayRef<T> {
public:
- typedef T *iterator;
-
- typedef std::reverse_iterator<iterator> reverse_iterator;
+ using iterator = T *;
+ using reverse_iterator = std::reverse_iterator<iterator>;
/// Construct an empty MutableArrayRef.
/*implicit*/ MutableArrayRef() : ArrayRef<T>() {}
@@ -416,19 +423,23 @@ namespace llvm {
/// This is a MutableArrayRef that owns its array.
template <typename T> class OwningArrayRef : public MutableArrayRef<T> {
public:
- OwningArrayRef() {}
+ OwningArrayRef() = default;
OwningArrayRef(size_t Size) : MutableArrayRef<T>(new T[Size], Size) {}
+
OwningArrayRef(ArrayRef<T> Data)
: MutableArrayRef<T>(new T[Data.size()], Data.size()) {
std::copy(Data.begin(), Data.end(), this->begin());
}
+
OwningArrayRef(OwningArrayRef &&Other) { *this = Other; }
+
OwningArrayRef &operator=(OwningArrayRef &&Other) {
delete[] this->data();
this->MutableArrayRef<T>::operator=(Other);
Other.MutableArrayRef<T>::operator=(MutableArrayRef<T>());
return *this;
}
+
~OwningArrayRef() { delete[] this->data(); }
};
@@ -517,13 +528,14 @@ namespace llvm {
// ArrayRefs can be treated like a POD type.
template <typename T> struct isPodLike;
- template <typename T> struct isPodLike<ArrayRef<T> > {
+ template <typename T> struct isPodLike<ArrayRef<T>> {
static const bool value = true;
};
template <typename T> hash_code hash_value(ArrayRef<T> S) {
return hash_combine_range(S.begin(), S.end());
}
+
} // end namespace llvm
#endif // LLVM_ADT_ARRAYREF_H
diff --git a/include/llvm/ADT/BreadthFirstIterator.h b/include/llvm/ADT/BreadthFirstIterator.h
index eaeecb6e057ff..6bc63c283b097 100644
--- a/include/llvm/ADT/BreadthFirstIterator.h
+++ b/include/llvm/ADT/BreadthFirstIterator.h
@@ -25,7 +25,6 @@
#include "llvm/ADT/iterator_range.h"
#include <iterator>
#include <queue>
-#include <set>
#include <utility>
namespace llvm {
@@ -49,13 +48,13 @@ template <class GraphT,
class bf_iterator
: public std::iterator<std::forward_iterator_tag, typename GT::NodeRef>,
public bf_iterator_storage<SetType> {
- typedef std::iterator<std::forward_iterator_tag, typename GT::NodeRef> super;
+ using super = std::iterator<std::forward_iterator_tag, typename GT::NodeRef>;
- typedef typename GT::NodeRef NodeRef;
- typedef typename GT::ChildIteratorType ChildItTy;
+ using NodeRef = typename GT::NodeRef;
+ using ChildItTy = typename GT::ChildIteratorType;
// First element is the node reference, second is the next child to visit.
- typedef std::pair<NodeRef, Optional<ChildItTy>> QueueElement;
+ using QueueElement = std::pair<NodeRef, Optional<ChildItTy>>;
// Visit queue - used to maintain BFS ordering.
// Optional<> because we need markers for levels.
@@ -109,7 +108,7 @@ private:
}
public:
- typedef typename super::pointer pointer;
+ using pointer = typename super::pointer;
// Provide static begin and end methods as our public "constructors"
static bf_iterator begin(const GraphT &G) {
diff --git a/include/llvm/ADT/DAGDeltaAlgorithm.h b/include/llvm/ADT/DAGDeltaAlgorithm.h
index 5ea0fe8728682..41fdd43efb8a3 100644
--- a/include/llvm/ADT/DAGDeltaAlgorithm.h
+++ b/include/llvm/ADT/DAGDeltaAlgorithm.h
@@ -1,4 +1,4 @@
-//===--- DAGDeltaAlgorithm.h - A DAG Minimization Algorithm ----*- C++ -*--===//
+//===- DAGDeltaAlgorithm.h - A DAG Minimization Algorithm ------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
@@ -40,12 +40,12 @@ class DAGDeltaAlgorithm {
virtual void anchor();
public:
- typedef unsigned change_ty;
- typedef std::pair<change_ty, change_ty> edge_ty;
+ using change_ty = unsigned;
+ using edge_ty = std::pair<change_ty, change_ty>;
// FIXME: Use a decent data structure.
- typedef std::set<change_ty> changeset_ty;
- typedef std::vector<changeset_ty> changesetlist_ty;
+ using changeset_ty = std::set<change_ty>;
+ using changesetlist_ty = std::vector<changeset_ty>;
public:
virtual ~DAGDeltaAlgorithm() = default;
diff --git a/include/llvm/ADT/DeltaAlgorithm.h b/include/llvm/ADT/DeltaAlgorithm.h
index a26f37dfdc7dc..6becb2a601044 100644
--- a/include/llvm/ADT/DeltaAlgorithm.h
+++ b/include/llvm/ADT/DeltaAlgorithm.h
@@ -1,4 +1,4 @@
-//===--- DeltaAlgorithm.h - A Set Minimization Algorithm -------*- C++ -*--===//
+//===- DeltaAlgorithm.h - A Set Minimization Algorithm ---------*- C++ -*--===//
//
// The LLVM Compiler Infrastructure
//
@@ -35,10 +35,10 @@ namespace llvm {
/// predicate.
class DeltaAlgorithm {
public:
- typedef unsigned change_ty;
+ using change_ty = unsigned;
// FIXME: Use a decent data structure.
- typedef std::set<change_ty> changeset_ty;
- typedef std::vector<changeset_ty> changesetlist_ty;
+ using changeset_ty = std::set<change_ty>;
+ using changesetlist_ty = std::vector<changeset_ty>;
private:
/// Cache of failed test results. Successful test results are never cached
@@ -90,4 +90,4 @@ public:
} // end namespace llvm
-#endif
+#endif // LLVM_ADT_DELTAALGORITHM_H
diff --git a/include/llvm/ADT/DenseMap.h b/include/llvm/ADT/DenseMap.h
index fd8d3bf368a88..b311e69ec9d37 100644
--- a/include/llvm/ADT/DenseMap.h
+++ b/include/llvm/ADT/DenseMap.h
@@ -25,8 +25,8 @@
#include <cstddef>
#include <cstring>
#include <iterator>
-#include <limits>
#include <new>
+#include <type_traits>
#include <utility>
namespace llvm {
@@ -57,14 +57,15 @@ class DenseMapBase : public DebugEpochBase {
using const_arg_type_t = typename const_pointer_or_const_ref<T>::type;
public:
- typedef unsigned size_type;
- typedef KeyT key_type;
- typedef ValueT mapped_type;
- typedef BucketT value_type;
-
- typedef DenseMapIterator<KeyT, ValueT, KeyInfoT, BucketT> iterator;
- typedef DenseMapIterator<KeyT, ValueT, KeyInfoT, BucketT, true>
- const_iterator;
+ using size_type = unsigned;
+ using key_type = KeyT;
+ using mapped_type = ValueT;
+ using value_type = BucketT;
+
+ using iterator = DenseMapIterator<KeyT, ValueT, KeyInfoT, BucketT>;
+ using const_iterator =
+ DenseMapIterator<KeyT, ValueT, KeyInfoT, BucketT, true>;
+
inline iterator begin() {
// When the map is empty, avoid the overhead of AdvancePastEmptyBuckets().
return empty() ? end() : iterator(getBuckets(), getBucketsEnd(), *this);
@@ -387,15 +388,18 @@ protected:
static unsigned getHashValue(const KeyT &Val) {
return KeyInfoT::getHashValue(Val);
}
+
template<typename LookupKeyT>
static unsigned getHashValue(const LookupKeyT &Val) {
return KeyInfoT::getHashValue(Val);
}
+
static const KeyT getEmptyKey() {
static_assert(std::is_base_of<DenseMapBase, DerivedT>::value,
"Must pass the derived type to this template!");
return KeyInfoT::getEmptyKey();
}
+
static const KeyT getTombstoneKey() {
return KeyInfoT::getTombstoneKey();
}
@@ -404,39 +408,51 @@ private:
unsigned getNumEntries() const {
return static_cast<const DerivedT *>(this)->getNumEntries();
}
+
void setNumEntries(unsigned Num) {
static_cast<DerivedT *>(this)->setNumEntries(Num);
}
+
void incrementNumEntries() {
setNumEntries(getNumEntries() + 1);
}
+
void decrementNumEntries() {
setNumEntries(getNumEntries() - 1);
}
+
unsigned getNumTombstones() const {
return static_cast<const DerivedT *>(this)->getNumTombstones();
}
+
void setNumTombstones(unsigned Num) {
static_cast<DerivedT *>(this)->setNumTombstones(Num);
}
+
void incrementNumTombstones() {
setNumTombstones(getNumTombstones() + 1);
}
+
void decrementNumTombstones() {
setNumTombstones(getNumTombstones() - 1);
}
+
const BucketT *getBuckets() const {
return static_cast<const DerivedT *>(this)->getBuckets();
}
+
BucketT *getBuckets() {
return static_cast<DerivedT *>(this)->getBuckets();
}
+
unsigned getNumBuckets() const {
return static_cast<const DerivedT *>(this)->getNumBuckets();
}
+
BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets();
}
+
const BucketT *getBucketsEnd() const {
return getBuckets() + getNumBuckets();
}
@@ -587,10 +603,11 @@ template <typename KeyT, typename ValueT,
typename BucketT = detail::DenseMapPair<KeyT, ValueT>>
class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
KeyT, ValueT, KeyInfoT, BucketT> {
+ friend class DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
+
// Lift some types from the dependent base class into this class for
// simplicity of referring to them.
- typedef DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT, BucketT> BaseT;
- friend class DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
+ using BaseT = DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
BucketT *Buckets;
unsigned NumEntries;
@@ -705,6 +722,7 @@ private:
unsigned getNumEntries() const {
return NumEntries;
}
+
void setNumEntries(unsigned Num) {
NumEntries = Num;
}
@@ -712,6 +730,7 @@ private:
unsigned getNumTombstones() const {
return NumTombstones;
}
+
void setNumTombstones(unsigned Num) {
NumTombstones = Num;
}
@@ -743,10 +762,12 @@ class SmallDenseMap
: public DenseMapBase<
SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
ValueT, KeyInfoT, BucketT> {
+ friend class DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
+
// Lift some types from the dependent base class into this class for
// simplicity of referring to them.
- typedef DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT, BucketT> BaseT;
- friend class DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
+ using BaseT = DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
+
static_assert(isPowerOf2_64(InlineBuckets),
"InlineBuckets must be a power of 2.");
@@ -972,6 +993,7 @@ private:
unsigned getNumEntries() const {
return NumEntries;
}
+
void setNumEntries(unsigned Num) {
// NumEntries is hardcoded to be 31 bits wide.
assert(Num < (1U << 31) && "Cannot support more than 1<<31 entries");
@@ -981,6 +1003,7 @@ private:
unsigned getNumTombstones() const {
return NumTombstones;
}
+
void setNumTombstones(unsigned Num) {
NumTombstones = Num;
}
@@ -992,15 +1015,18 @@ private:
// 'storage.buffer' static type is 'char *'.
return reinterpret_cast<const BucketT *>(storage.buffer);
}
+
BucketT *getInlineBuckets() {
return const_cast<BucketT *>(
const_cast<const SmallDenseMap *>(this)->getInlineBuckets());
}
+
const LargeRep *getLargeRep() const {
assert(!Small);
// Note, same rule about aliasing as with getInlineBuckets.
return reinterpret_cast<const LargeRep *>(storage.buffer);
}
+
LargeRep *getLargeRep() {
return const_cast<LargeRep *>(
const_cast<const SmallDenseMap *>(this)->getLargeRep());
@@ -1009,10 +1035,12 @@ private:
const BucketT *getBuckets() const {
return Small ? getInlineBuckets() : getLargeRep()->Buckets;
}
+
BucketT *getBuckets() {
return const_cast<BucketT *>(
const_cast<const SmallDenseMap *>(this)->getBuckets());
}
+
unsigned getNumBuckets() const {
return Small ? InlineBuckets : getLargeRep()->NumBuckets;
}
@@ -1037,23 +1065,25 @@ private:
template <typename KeyT, typename ValueT, typename KeyInfoT, typename Bucket,
bool IsConst>
class DenseMapIterator : DebugEpochBase::HandleBase {
- typedef DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true> ConstIterator;
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, false>;
+ using ConstIterator = DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, true>;
+
public:
- typedef ptrdiff_t difference_type;
- typedef typename std::conditional<IsConst, const Bucket, Bucket>::type
- value_type;
- typedef value_type *pointer;
- typedef value_type &reference;
- typedef std::forward_iterator_tag iterator_category;
+ using difference_type = ptrdiff_t;
+ using value_type =
+ typename std::conditional<IsConst, const Bucket, Bucket>::type;
+ using pointer = value_type *;
+ using reference = value_type &;
+ using iterator_category = std::forward_iterator_tag;
private:
- pointer Ptr, End;
+ pointer Ptr = nullptr;
+ pointer End = nullptr;
public:
- DenseMapIterator() : Ptr(nullptr), End(nullptr) {}
+ DenseMapIterator() = default;
DenseMapIterator(pointer Pos, pointer E, const DebugEpochBase &Epoch,
bool NoAdvance = false)
diff --git a/include/llvm/ADT/DenseMapInfo.h b/include/llvm/ADT/DenseMapInfo.h
index bb973ac650634..a96904c7dbbf6 100644
--- a/include/llvm/ADT/DenseMapInfo.h
+++ b/include/llvm/ADT/DenseMapInfo.h
@@ -18,7 +18,10 @@
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/PointerLikeTypeTraits.h"
-#include "llvm/Support/type_traits.h"
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <utility>
namespace llvm {
@@ -38,15 +41,18 @@ struct DenseMapInfo<T*> {
Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
return reinterpret_cast<T*>(Val);
}
+
static inline T* getTombstoneKey() {
uintptr_t Val = static_cast<uintptr_t>(-2);
Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
return reinterpret_cast<T*>(Val);
}
+
static unsigned getHashValue(const T *PtrVal) {
return (unsigned((uintptr_t)PtrVal) >> 4) ^
(unsigned((uintptr_t)PtrVal) >> 9);
}
+
static bool isEqual(const T *LHS, const T *RHS) { return LHS == RHS; }
};
@@ -55,6 +61,7 @@ template<> struct DenseMapInfo<char> {
static inline char getEmptyKey() { return ~0; }
static inline char getTombstoneKey() { return ~0 - 1; }
static unsigned getHashValue(const char& Val) { return Val * 37U; }
+
static bool isEqual(const char &LHS, const char &RHS) {
return LHS == RHS;
}
@@ -65,6 +72,7 @@ template <> struct DenseMapInfo<unsigned short> {
static inline unsigned short getEmptyKey() { return 0xFFFF; }
static inline unsigned short getTombstoneKey() { return 0xFFFF - 1; }
static unsigned getHashValue(const unsigned short &Val) { return Val * 37U; }
+
static bool isEqual(const unsigned short &LHS, const unsigned short &RHS) {
return LHS == RHS;
}
@@ -75,6 +83,7 @@ template<> struct DenseMapInfo<unsigned> {
static inline unsigned getEmptyKey() { return ~0U; }
static inline unsigned getTombstoneKey() { return ~0U - 1; }
static unsigned getHashValue(const unsigned& Val) { return Val * 37U; }
+
static bool isEqual(const unsigned& LHS, const unsigned& RHS) {
return LHS == RHS;
}
@@ -84,9 +93,11 @@ template<> struct DenseMapInfo<unsigned> {
template<> struct DenseMapInfo<unsigned long> {
static inline unsigned long getEmptyKey() { return ~0UL; }
static inline unsigned long getTombstoneKey() { return ~0UL - 1L; }
+
static unsigned getHashValue(const unsigned long& Val) {
return (unsigned)(Val * 37UL);
}
+
static bool isEqual(const unsigned long& LHS, const unsigned long& RHS) {
return LHS == RHS;
}
@@ -96,9 +107,11 @@ template<> struct DenseMapInfo<unsigned long> {
template<> struct DenseMapInfo<unsigned long long> {
static inline unsigned long long getEmptyKey() { return ~0ULL; }
static inline unsigned long long getTombstoneKey() { return ~0ULL - 1ULL; }
+
static unsigned getHashValue(const unsigned long long& Val) {
return (unsigned)(Val * 37ULL);
}
+
static bool isEqual(const unsigned long long& LHS,
const unsigned long long& RHS) {
return LHS == RHS;
@@ -118,6 +131,7 @@ 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 * 37U); }
+
static bool isEqual(const int& LHS, const int& RHS) {
return LHS == RHS;
}
@@ -128,10 +142,13 @@ template<> struct DenseMapInfo<long> {
static inline long getEmptyKey() {
return (1UL << (sizeof(long) * 8 - 1)) - 1UL;
}
+
static inline long getTombstoneKey() { return getEmptyKey() - 1L; }
+
static unsigned getHashValue(const long& Val) {
return (unsigned)(Val * 37UL);
}
+
static bool isEqual(const long& LHS, const long& RHS) {
return LHS == RHS;
}
@@ -141,9 +158,11 @@ template<> struct DenseMapInfo<long> {
template<> struct DenseMapInfo<long long> {
static inline long long getEmptyKey() { return 0x7fffffffffffffffLL; }
static inline long long getTombstoneKey() { return -0x7fffffffffffffffLL-1; }
+
static unsigned getHashValue(const long long& Val) {
return (unsigned)(Val * 37ULL);
}
+
static bool isEqual(const long long& LHS,
const long long& RHS) {
return LHS == RHS;
@@ -152,19 +171,21 @@ template<> struct DenseMapInfo<long long> {
// Provide DenseMapInfo for all pairs whose members have info.
template<typename T, typename U>
-struct DenseMapInfo<std::pair<T, U> > {
- typedef std::pair<T, U> Pair;
- typedef DenseMapInfo<T> FirstInfo;
- typedef DenseMapInfo<U> SecondInfo;
+struct DenseMapInfo<std::pair<T, U>> {
+ using Pair = std::pair<T, U>;
+ using FirstInfo = DenseMapInfo<T>;
+ using SecondInfo = DenseMapInfo<U>;
static inline Pair getEmptyKey() {
return std::make_pair(FirstInfo::getEmptyKey(),
SecondInfo::getEmptyKey());
}
+
static inline Pair getTombstoneKey() {
return std::make_pair(FirstInfo::getTombstoneKey(),
SecondInfo::getTombstoneKey());
}
+
static unsigned getHashValue(const Pair& PairVal) {
uint64_t key = (uint64_t)FirstInfo::getHashValue(PairVal.first) << 32
| (uint64_t)SecondInfo::getHashValue(PairVal.second);
@@ -178,6 +199,7 @@ struct DenseMapInfo<std::pair<T, U> > {
key ^= (key >> 31);
return (unsigned)key;
}
+
static bool isEqual(const Pair &LHS, const Pair &RHS) {
return FirstInfo::isEqual(LHS.first, RHS.first) &&
SecondInfo::isEqual(LHS.second, RHS.second);
@@ -190,16 +212,19 @@ template <> struct DenseMapInfo<StringRef> {
return StringRef(reinterpret_cast<const char *>(~static_cast<uintptr_t>(0)),
0);
}
+
static inline StringRef getTombstoneKey() {
return StringRef(reinterpret_cast<const char *>(~static_cast<uintptr_t>(1)),
0);
}
+
static unsigned getHashValue(StringRef Val) {
assert(Val.data() != getEmptyKey().data() && "Cannot hash the empty key!");
assert(Val.data() != getTombstoneKey().data() &&
"Cannot hash the tombstone key!");
return (unsigned)(hash_value(Val));
}
+
static bool isEqual(StringRef LHS, StringRef RHS) {
if (RHS.data() == getEmptyKey().data())
return LHS.data() == getEmptyKey().data();
@@ -215,16 +240,19 @@ template <typename T> struct DenseMapInfo<ArrayRef<T>> {
return ArrayRef<T>(reinterpret_cast<const T *>(~static_cast<uintptr_t>(0)),
size_t(0));
}
+
static inline ArrayRef<T> getTombstoneKey() {
return ArrayRef<T>(reinterpret_cast<const T *>(~static_cast<uintptr_t>(1)),
size_t(0));
}
+
static unsigned getHashValue(ArrayRef<T> Val) {
assert(Val.data() != getEmptyKey().data() && "Cannot hash the empty key!");
assert(Val.data() != getTombstoneKey().data() &&
"Cannot hash the tombstone key!");
return (unsigned)(hash_value(Val));
}
+
static bool isEqual(ArrayRef<T> LHS, ArrayRef<T> RHS) {
if (RHS.data() == getEmptyKey().data())
return LHS.data() == getEmptyKey().data();
@@ -236,4 +264,4 @@ template <typename T> struct DenseMapInfo<ArrayRef<T>> {
} // end namespace llvm
-#endif
+#endif // LLVM_ADT_DENSEMAPINFO_H
diff --git a/include/llvm/ADT/DenseSet.h b/include/llvm/ADT/DenseSet.h
index fcf304c3ecc41..7e5171c3f3a44 100644
--- a/include/llvm/ADT/DenseSet.h
+++ b/include/llvm/ADT/DenseSet.h
@@ -15,11 +15,18 @@
#define LLVM_ADT_DENSESET_H
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/Support/type_traits.h"
+#include <algorithm>
+#include <cstddef>
#include <initializer_list>
+#include <iterator>
+#include <utility>
namespace llvm {
namespace detail {
+
struct DenseSetEmpty {};
// Use the empty base class trick so we can create a DenseMap where the buckets
@@ -48,13 +55,14 @@ class DenseSetImpl {
static_assert(sizeof(typename MapTy::value_type) == sizeof(ValueT),
"DenseMap buckets unexpectedly large!");
MapTy TheMap;
+
template <typename T>
using const_arg_type_t = typename const_pointer_or_const_ref<T>::type;
public:
- typedef ValueT key_type;
- typedef ValueT value_type;
- typedef unsigned size_type;
+ using key_type = ValueT;
+ using value_type = ValueT;
+ using size_type = unsigned;
explicit DenseSetImpl(unsigned InitialReserve = 0) : TheMap(InitialReserve) {}
@@ -100,11 +108,11 @@ public:
friend class ConstIterator;
public:
- typedef typename MapTy::iterator::difference_type difference_type;
- typedef ValueT value_type;
- typedef value_type *pointer;
- typedef value_type &reference;
- typedef std::forward_iterator_tag iterator_category;
+ using difference_type = typename MapTy::iterator::difference_type;
+ using value_type = ValueT;
+ using pointer = value_type *;
+ using reference = value_type &;
+ using iterator_category = std::forward_iterator_tag;
Iterator() = default;
Iterator(const typename MapTy::iterator &i) : I(i) {}
@@ -126,16 +134,14 @@ public:
friend class Iterator;
public:
- typedef typename MapTy::const_iterator::difference_type difference_type;
- typedef ValueT value_type;
- typedef value_type *pointer;
- typedef value_type &reference;
- typedef std::forward_iterator_tag iterator_category;
-
- ConstIterator(const Iterator &B) : I(B.I) {}
+ using difference_type = typename MapTy::const_iterator::difference_type;
+ using value_type = ValueT;
+ using pointer = value_type *;
+ using reference = value_type &;
+ using iterator_category = std::forward_iterator_tag;
ConstIterator() = default;
-
+ ConstIterator(const Iterator &B) : I(B.I) {}
ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
const ValueT &operator*() const { return I->getFirst(); }
@@ -147,8 +153,8 @@ public:
bool operator!=(const ConstIterator& X) const { return I != X.I; }
};
- typedef Iterator iterator;
- typedef ConstIterator const_iterator;
+ using iterator = Iterator;
+ using const_iterator = ConstIterator;
iterator begin() { return Iterator(TheMap.begin()); }
iterator end() { return Iterator(TheMap.end()); }
@@ -208,7 +214,7 @@ public:
}
};
-} // namespace detail
+} // end namespace detail
/// Implements a dense probed hash-table based set.
template <typename ValueT, typename ValueInfoT = DenseMapInfo<ValueT>>
@@ -246,4 +252,4 @@ public:
} // end namespace llvm
-#endif
+#endif // LLVM_ADT_DENSESET_H
diff --git a/include/llvm/ADT/DepthFirstIterator.h b/include/llvm/ADT/DepthFirstIterator.h
index b020d48cb3f08..e964d7fa23911 100644
--- a/include/llvm/ADT/DepthFirstIterator.h
+++ b/include/llvm/ADT/DepthFirstIterator.h
@@ -68,13 +68,14 @@ public:
// cross edges in the spanning tree but is not used in the common case.
template <typename NodeRef, unsigned SmallSize=8>
struct df_iterator_default_set : public SmallPtrSet<NodeRef, SmallSize> {
- typedef SmallPtrSet<NodeRef, SmallSize> BaseSet;
- typedef typename BaseSet::iterator iterator;
- std::pair<iterator,bool> insert(NodeRef N) { return BaseSet::insert(N) ; }
+ using BaseSet = SmallPtrSet<NodeRef, SmallSize>;
+ using iterator = typename BaseSet::iterator;
+
+ std::pair<iterator,bool> insert(NodeRef N) { return BaseSet::insert(N); }
template <typename IterT>
void insert(IterT Begin, IterT End) { BaseSet::insert(Begin,End); }
- void completed(NodeRef) { }
+ void completed(NodeRef) {}
};
// Generic Depth First Iterator
@@ -85,15 +86,14 @@ template <class GraphT,
class df_iterator
: public std::iterator<std::forward_iterator_tag, typename GT::NodeRef>,
public df_iterator_storage<SetType, ExtStorage> {
- typedef std::iterator<std::forward_iterator_tag, typename GT::NodeRef> super;
-
- typedef typename GT::NodeRef NodeRef;
- typedef typename GT::ChildIteratorType ChildItTy;
+ using super = std::iterator<std::forward_iterator_tag, typename GT::NodeRef>;
+ using NodeRef = typename GT::NodeRef;
+ using ChildItTy = typename GT::ChildIteratorType;
// First element is node reference, second is the 'next child' to visit.
// The second child is initialized lazily to pick up graph changes during the
// DFS.
- typedef std::pair<NodeRef, Optional<ChildItTy>> StackElement;
+ using StackElement = std::pair<NodeRef, Optional<ChildItTy>>;
// VisitStack - Used to maintain the ordering. Top = current block
std::vector<StackElement> VisitStack;
@@ -103,12 +103,15 @@ private:
this->Visited.insert(Node);
VisitStack.push_back(StackElement(Node, None));
}
+
inline df_iterator() = default; // End is when stack is empty
+
inline df_iterator(NodeRef Node, SetType &S)
: df_iterator_storage<SetType, ExtStorage>(S) {
if (this->Visited.insert(Node).second)
VisitStack.push_back(StackElement(Node, None));
}
+
inline df_iterator(SetType &S)
: df_iterator_storage<SetType, ExtStorage>(S) {
// End is when stack is empty
@@ -142,7 +145,7 @@ private:
}
public:
- typedef typename super::pointer pointer;
+ using pointer = typename super::pointer;
// Provide static begin and end methods as our public "constructors"
static df_iterator begin(const GraphT &G) {
diff --git a/include/llvm/ADT/EquivalenceClasses.h b/include/llvm/ADT/EquivalenceClasses.h
index 8fcac178ffc97..af293d4c1422a 100644
--- a/include/llvm/ADT/EquivalenceClasses.h
+++ b/include/llvm/ADT/EquivalenceClasses.h
@@ -1,4 +1,4 @@
-//===-- llvm/ADT/EquivalenceClasses.h - Generic Equiv. Classes --*- C++ -*-===//
+//===- llvm/ADT/EquivalenceClasses.h - Generic Equiv. Classes ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -69,6 +69,7 @@ class EquivalenceClasses {
/// leader is determined by a bit stolen from one of the pointers.
class ECValue {
friend class EquivalenceClasses;
+
mutable const ECValue *Leader, *Next;
ElemTy Data;
@@ -141,14 +142,14 @@ public:
//
/// iterator* - Provides a way to iterate over all values in the set.
- typedef typename std::set<ECValue>::const_iterator iterator;
+ using iterator = typename std::set<ECValue>::const_iterator;
+
iterator begin() const { return TheMapping.begin(); }
iterator end() const { return TheMapping.end(); }
bool empty() const { return TheMapping.empty(); }
/// member_* Iterate over the members of an equivalence class.
- ///
class member_iterator;
member_iterator member_begin(iterator I) const {
// Only leaders provide anything to iterate over.
@@ -204,7 +205,6 @@ public:
/// equivalence class it is in. This does the path-compression part that
/// makes union-find "union findy". This returns an end iterator if the value
/// is not in the equivalence class.
- ///
member_iterator findLeader(iterator I) const {
if (I == TheMapping.end()) return member_end();
return member_iterator(I->getLeader());
@@ -241,15 +241,17 @@ public:
class member_iterator : public std::iterator<std::forward_iterator_tag,
const ElemTy, ptrdiff_t> {
- typedef std::iterator<std::forward_iterator_tag,
- const ElemTy, ptrdiff_t> super;
- const ECValue *Node;
friend class EquivalenceClasses;
+ using super = std::iterator<std::forward_iterator_tag,
+ const ElemTy, ptrdiff_t>;
+
+ const ECValue *Node;
+
public:
- typedef size_t size_type;
- typedef typename super::pointer pointer;
- typedef typename super::reference reference;
+ using size_type = size_t;
+ using pointer = typename super::pointer;
+ using reference = typename super::reference;
explicit member_iterator() = default;
explicit member_iterator(const ECValue *N) : Node(N) {}
diff --git a/include/llvm/ADT/FoldingSet.h b/include/llvm/ADT/FoldingSet.h
index dab18297dd3b4..c5987a947e182 100644
--- a/include/llvm/ADT/FoldingSet.h
+++ b/include/llvm/ADT/FoldingSet.h
@@ -40,7 +40,7 @@ namespace llvm {
/// FoldingSetNode. The node class must also define a Profile method used to
/// establish the unique bits of data for the node. The Profile method is
/// passed a FoldingSetNodeID object which is used to gather the bits. Just
-/// call one of the Add* functions defined in the FoldingSetImpl::NodeID class.
+/// call one of the Add* functions defined in the FoldingSetBase::NodeID class.
/// NOTE: That the folding set does not own the nodes and it is the
/// responsibility of the user to dispose of the nodes.
///
@@ -104,13 +104,13 @@ class FoldingSetNodeID;
class StringRef;
//===----------------------------------------------------------------------===//
-/// FoldingSetImpl - Implements the folding set functionality. The main
+/// FoldingSetBase - Implements the folding set functionality. The main
/// structure is an array of buckets. Each bucket is indexed by the hash of
/// the nodes it contains. The bucket itself points to the nodes contained
/// in the bucket via a singly linked list. The last node in the list points
/// back to the bucket to facilitate node removal.
///
-class FoldingSetImpl {
+class FoldingSetBase {
virtual void anchor(); // Out of line virtual method.
protected:
@@ -126,10 +126,10 @@ protected:
/// is greater than twice the number of buckets.
unsigned NumNodes;
- explicit FoldingSetImpl(unsigned Log2InitSize = 6);
- FoldingSetImpl(FoldingSetImpl &&Arg);
- FoldingSetImpl &operator=(FoldingSetImpl &&RHS);
- ~FoldingSetImpl();
+ explicit FoldingSetBase(unsigned Log2InitSize = 6);
+ FoldingSetBase(FoldingSetBase &&Arg);
+ FoldingSetBase &operator=(FoldingSetBase &&RHS);
+ ~FoldingSetBase();
public:
//===--------------------------------------------------------------------===//
@@ -152,33 +152,6 @@ public:
/// clear - Remove all nodes from the folding set.
void clear();
- /// RemoveNode - Remove a node from the folding set, returning true if one
- /// was removed or false if the node was not in the folding set.
- bool RemoveNode(Node *N);
-
- /// GetOrInsertNode - If there is an existing simple Node exactly
- /// equal to the specified node, return it. Otherwise, insert 'N' and return
- /// it instead.
- Node *GetOrInsertNode(Node *N);
-
- /// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
- /// return it. If not, return the insertion token that will make insertion
- /// faster.
- Node *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
-
- /// InsertNode - Insert the specified node into the folding set, knowing that
- /// it is not already in the folding set. InsertPos must be obtained from
- /// FindNodeOrInsertPos.
- void InsertNode(Node *N, void *InsertPos);
-
- /// InsertNode - Insert the specified node into the folding set, knowing that
- /// it is not already in the folding set.
- void InsertNode(Node *N) {
- Node *Inserted = GetOrInsertNode(N);
- (void)Inserted;
- assert(Inserted == N && "Node already inserted!");
- }
-
/// size - Returns the number of nodes in the folding set.
unsigned size() const { return NumNodes; }
@@ -220,6 +193,28 @@ protected:
/// ComputeNodeHash - Instantiations of the FoldingSet template implement
/// this function to compute a hash value for the given node.
virtual unsigned ComputeNodeHash(Node *N, FoldingSetNodeID &TempID) const = 0;
+
+ // The below methods are protected to encourage subclasses to provide a more
+ // type-safe API.
+
+ /// RemoveNode - Remove a node from the folding set, returning true if one
+ /// was removed or false if the node was not in the folding set.
+ bool RemoveNode(Node *N);
+
+ /// GetOrInsertNode - If there is an existing simple Node exactly
+ /// equal to the specified node, return it. Otherwise, insert 'N' and return
+ /// it instead.
+ Node *GetOrInsertNode(Node *N);
+
+ /// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
+ /// return it. If not, return the insertion token that will make insertion
+ /// faster.
+ Node *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos);
+
+ /// InsertNode - Insert the specified node into the folding set, knowing that
+ /// it is not already in the folding set. InsertPos must be obtained from
+ /// FindNodeOrInsertPos.
+ void InsertNode(Node *N, void *InsertPos);
};
//===----------------------------------------------------------------------===//
@@ -293,7 +288,7 @@ public:
FoldingSetNodeIDRef(const unsigned *D, size_t S) : Data(D), Size(S) {}
/// ComputeHash - Compute a strong hash value for this FoldingSetNodeIDRef,
- /// used to lookup the node in the FoldingSetImpl.
+ /// used to lookup the node in the FoldingSetBase.
unsigned ComputeHash() const;
bool operator==(FoldingSetNodeIDRef) const;
@@ -345,7 +340,7 @@ public:
inline void clear() { Bits.clear(); }
/// ComputeHash - Compute a strong hash value for this FoldingSetNodeID, used
- /// to lookup the node in the FoldingSetImpl.
+ /// to lookup the node in the FoldingSetBase.
unsigned ComputeHash() const;
/// operator== - Used to compare two nodes to each other.
@@ -368,7 +363,7 @@ public:
};
// Convenience type to hide the implementation of the folding set.
-typedef FoldingSetImpl::Node FoldingSetNode;
+typedef FoldingSetBase::Node FoldingSetNode;
template<class T> class FoldingSetIterator;
template<class T> class FoldingSetBucketIterator;
@@ -408,6 +403,71 @@ DefaultContextualFoldingSetTrait<T, Ctx>::ComputeHash(T &X,
}
//===----------------------------------------------------------------------===//
+/// FoldingSetImpl - An implementation detail that lets us share code between
+/// FoldingSet and ContextualFoldingSet.
+template <class T> class FoldingSetImpl : public FoldingSetBase {
+protected:
+ explicit FoldingSetImpl(unsigned Log2InitSize)
+ : FoldingSetBase(Log2InitSize) {}
+
+ FoldingSetImpl(FoldingSetImpl &&Arg) = default;
+ FoldingSetImpl &operator=(FoldingSetImpl &&RHS) = default;
+ ~FoldingSetImpl() = default;
+
+public:
+ typedef FoldingSetIterator<T> iterator;
+ iterator begin() { return iterator(Buckets); }
+ iterator end() { return iterator(Buckets+NumBuckets); }
+
+ typedef FoldingSetIterator<const T> const_iterator;
+ const_iterator begin() const { return const_iterator(Buckets); }
+ const_iterator end() const { return const_iterator(Buckets+NumBuckets); }
+
+ typedef FoldingSetBucketIterator<T> bucket_iterator;
+
+ bucket_iterator bucket_begin(unsigned hash) {
+ return bucket_iterator(Buckets + (hash & (NumBuckets-1)));
+ }
+
+ bucket_iterator bucket_end(unsigned hash) {
+ return bucket_iterator(Buckets + (hash & (NumBuckets-1)), true);
+ }
+
+ /// RemoveNode - Remove a node from the folding set, returning true if one
+ /// was removed or false if the node was not in the folding set.
+ bool RemoveNode(T *N) { return FoldingSetBase::RemoveNode(N); }
+
+ /// GetOrInsertNode - If there is an existing simple Node exactly
+ /// equal to the specified node, return it. Otherwise, insert 'N' and
+ /// return it instead.
+ T *GetOrInsertNode(T *N) {
+ return static_cast<T *>(FoldingSetBase::GetOrInsertNode(N));
+ }
+
+ /// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
+ /// return it. If not, return the insertion token that will make insertion
+ /// faster.
+ T *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos) {
+ return static_cast<T *>(FoldingSetBase::FindNodeOrInsertPos(ID, InsertPos));
+ }
+
+ /// InsertNode - Insert the specified node into the folding set, knowing that
+ /// it is not already in the folding set. InsertPos must be obtained from
+ /// FindNodeOrInsertPos.
+ void InsertNode(T *N, void *InsertPos) {
+ FoldingSetBase::InsertNode(N, InsertPos);
+ }
+
+ /// InsertNode - Insert the specified node into the folding set, knowing that
+ /// it is not already in the folding set.
+ void InsertNode(T *N) {
+ T *Inserted = GetOrInsertNode(N);
+ (void)Inserted;
+ assert(Inserted == N && "Node already inserted!");
+ }
+};
+
+//===----------------------------------------------------------------------===//
/// FoldingSet - This template class is used to instantiate a specialized
/// implementation of the folding set to the node class T. T must be a
/// subclass of FoldingSetNode and implement a Profile function.
@@ -416,8 +476,10 @@ DefaultContextualFoldingSetTrait<T, Ctx>::ComputeHash(T &X,
/// moved-from state is not a valid state for anything other than
/// move-assigning and destroying. This is primarily to enable movable APIs
/// that incorporate these objects.
-template <class T> class FoldingSet final : public FoldingSetImpl {
-private:
+template <class T> class FoldingSet final : public FoldingSetImpl<T> {
+ using Super = FoldingSetImpl<T>;
+ using Node = typename Super::Node;
+
/// GetNodeProfile - Each instantiatation of the FoldingSet needs to provide a
/// way to convert nodes into a unique specifier.
void GetNodeProfile(Node *N, FoldingSetNodeID &ID) const override {
@@ -442,45 +504,10 @@ private:
public:
explicit FoldingSet(unsigned Log2InitSize = 6)
- : FoldingSetImpl(Log2InitSize) {}
-
- FoldingSet(FoldingSet &&Arg) : FoldingSetImpl(std::move(Arg)) {}
- FoldingSet &operator=(FoldingSet &&RHS) {
- (void)FoldingSetImpl::operator=(std::move(RHS));
- return *this;
- }
-
- typedef FoldingSetIterator<T> iterator;
- iterator begin() { return iterator(Buckets); }
- iterator end() { return iterator(Buckets+NumBuckets); }
-
- typedef FoldingSetIterator<const T> const_iterator;
- const_iterator begin() const { return const_iterator(Buckets); }
- const_iterator end() const { return const_iterator(Buckets+NumBuckets); }
-
- typedef FoldingSetBucketIterator<T> bucket_iterator;
-
- bucket_iterator bucket_begin(unsigned hash) {
- return bucket_iterator(Buckets + (hash & (NumBuckets-1)));
- }
-
- bucket_iterator bucket_end(unsigned hash) {
- return bucket_iterator(Buckets + (hash & (NumBuckets-1)), true);
- }
+ : Super(Log2InitSize) {}
- /// GetOrInsertNode - If there is an existing simple Node exactly
- /// equal to the specified node, return it. Otherwise, insert 'N' and
- /// return it instead.
- T *GetOrInsertNode(Node *N) {
- return static_cast<T *>(FoldingSetImpl::GetOrInsertNode(N));
- }
-
- /// FindNodeOrInsertPos - Look up the node specified by ID. If it exists,
- /// return it. If not, return the insertion token that will make insertion
- /// faster.
- T *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos) {
- return static_cast<T *>(FoldingSetImpl::FindNodeOrInsertPos(ID, InsertPos));
- }
+ FoldingSet(FoldingSet &&Arg) = default;
+ FoldingSet &operator=(FoldingSet &&RHS) = default;
};
//===----------------------------------------------------------------------===//
@@ -493,74 +520,42 @@ public:
/// function with signature
/// void Profile(FoldingSetNodeID &, Ctx);
template <class T, class Ctx>
-class ContextualFoldingSet final : public FoldingSetImpl {
+class ContextualFoldingSet final : public FoldingSetImpl<T> {
// Unfortunately, this can't derive from FoldingSet<T> because the
- // construction vtable for FoldingSet<T> requires
+ // construction of the vtable for FoldingSet<T> requires
// FoldingSet<T>::GetNodeProfile to be instantiated, which in turn
// requires a single-argument T::Profile().
-private:
+ using Super = FoldingSetImpl<T>;
+ using Node = typename Super::Node;
+
Ctx Context;
/// GetNodeProfile - Each instantiatation of the FoldingSet needs to provide a
/// way to convert nodes into a unique specifier.
- void GetNodeProfile(FoldingSetImpl::Node *N,
- FoldingSetNodeID &ID) const override {
+ void GetNodeProfile(Node *N, FoldingSetNodeID &ID) const override {
T *TN = static_cast<T *>(N);
ContextualFoldingSetTrait<T, Ctx>::Profile(*TN, ID, Context);
}
- bool NodeEquals(FoldingSetImpl::Node *N, const FoldingSetNodeID &ID,
- unsigned IDHash, FoldingSetNodeID &TempID) const override {
+ bool NodeEquals(Node *N, const FoldingSetNodeID &ID, unsigned IDHash,
+ FoldingSetNodeID &TempID) const override {
T *TN = static_cast<T *>(N);
return ContextualFoldingSetTrait<T, Ctx>::Equals(*TN, ID, IDHash, TempID,
Context);
}
- unsigned ComputeNodeHash(FoldingSetImpl::Node *N,
- FoldingSetNodeID &TempID) const override {
+ unsigned ComputeNodeHash(Node *N, FoldingSetNodeID &TempID) const override {
T *TN = static_cast<T *>(N);
return ContextualFoldingSetTrait<T, Ctx>::ComputeHash(*TN, TempID, Context);
}
public:
explicit ContextualFoldingSet(Ctx Context, unsigned Log2InitSize = 6)
- : FoldingSetImpl(Log2InitSize), Context(Context)
+ : Super(Log2InitSize), Context(Context)
{}
Ctx getContext() const { return Context; }
-
- typedef FoldingSetIterator<T> iterator;
- iterator begin() { return iterator(Buckets); }
- iterator end() { return iterator(Buckets+NumBuckets); }
-
- typedef FoldingSetIterator<const T> const_iterator;
- const_iterator begin() const { return const_iterator(Buckets); }
- const_iterator end() const { return const_iterator(Buckets+NumBuckets); }
-
- typedef FoldingSetBucketIterator<T> bucket_iterator;
-
- bucket_iterator bucket_begin(unsigned hash) {
- return bucket_iterator(Buckets + (hash & (NumBuckets-1)));
- }
-
- bucket_iterator bucket_end(unsigned hash) {
- return bucket_iterator(Buckets + (hash & (NumBuckets-1)), true);
- }
-
- /// GetOrInsertNode - If there is an existing simple Node exactly
- /// equal to the specified node, return it. Otherwise, insert 'N'
- /// and return it instead.
- T *GetOrInsertNode(Node *N) {
- return static_cast<T *>(FoldingSetImpl::GetOrInsertNode(N));
- }
-
- /// FindNodeOrInsertPos - Look up the node specified by ID. If it
- /// exists, return it. If not, return the insertion token that will
- /// make insertion faster.
- T *FindNodeOrInsertPos(const FoldingSetNodeID &ID, void *&InsertPos) {
- return static_cast<T *>(FoldingSetImpl::FindNodeOrInsertPos(ID, InsertPos));
- }
};
//===----------------------------------------------------------------------===//
diff --git a/include/llvm/ADT/GraphTraits.h b/include/llvm/ADT/GraphTraits.h
index 68149d9e3bf56..225d9eb847f00 100644
--- a/include/llvm/ADT/GraphTraits.h
+++ b/include/llvm/ADT/GraphTraits.h
@@ -1,4 +1,4 @@
-//===-- llvm/ADT/GraphTraits.h - Graph traits template ----------*- C++ -*-===//
+//===- llvm/ADT/GraphTraits.h - Graph traits template -----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -41,7 +41,6 @@ struct GraphTraits {
// static ChildIteratorType child_end (NodeRef)
// Return iterators that point to the beginning and ending of the child
// node list for the specified node.
- //
// typedef ...iterator nodes_iterator; - dereference to a NodeRef
// static nodes_iterator nodes_begin(GraphType *G)
@@ -50,7 +49,6 @@ struct GraphTraits {
// static unsigned size (GraphType *G)
// Return total number of nodes in the graph
- //
// If anyone tries to use this class without having an appropriate
// specialization, make an error. If you get this error, it's because you
@@ -58,11 +56,9 @@ struct GraphTraits {
// graph, or you need to define it for a new graph type. Either that or
// your argument to XXX_begin(...) is unknown or needs to have the proper .h
// file #include'd.
- //
- typedef typename GraphType::UnknownGraphTypeError NodeRef;
+ using NodeRef = typename GraphType::UnknownGraphTypeError;
};
-
// Inverse - This class is used as a little marker class to tell the graph
// iterator to iterate over the graph in a graph defined "Inverse" ordering.
// Not all graphs define an inverse ordering, and if they do, it depends on
@@ -73,7 +69,7 @@ struct GraphTraits {
// for (; I != E; ++I) { ... }
//
// Which is equivalent to:
-// df_iterator<Inverse<Method*> > I = idf_begin(M), E = idf_end(M);
+// df_iterator<Inverse<Method*>> I = idf_begin(M), E = idf_end(M);
// for (; I != E; ++I) { ... }
//
template <class GraphType>
@@ -114,6 +110,7 @@ inverse_children(const typename GraphTraits<GraphType>::NodeRef &G) {
return make_range(GraphTraits<Inverse<GraphType>>::child_begin(G),
GraphTraits<Inverse<GraphType>>::child_end(G));
}
-} // End llvm namespace
-#endif
+} // end namespace llvm
+
+#endif // LLVM_ADT_GRAPHTRAITS_H
diff --git a/include/llvm/ADT/ImmutableList.h b/include/llvm/ADT/ImmutableList.h
index e5f51bafe995d..60d63e09d4268 100644
--- a/include/llvm/ADT/ImmutableList.h
+++ b/include/llvm/ADT/ImmutableList.h
@@ -63,8 +63,8 @@ public:
template <typename T>
class ImmutableList {
public:
- typedef T value_type;
- typedef ImmutableListFactory<T> Factory;
+ using value_type = T;
+ using Factory = ImmutableListFactory<T>;
private:
const ImmutableListImpl<T>* X;
@@ -141,8 +141,8 @@ public:
template <typename T>
class ImmutableListFactory {
- typedef ImmutableListImpl<T> ListTy;
- typedef FoldingSet<ListTy> CacheTy;
+ using ListTy = ImmutableListImpl<T>;
+ using CacheTy = FoldingSet<ListTy>;
CacheTy Cache;
uintptr_t Allocator;
diff --git a/include/llvm/ADT/ImmutableMap.h b/include/llvm/ADT/ImmutableMap.h
index f197d407ba3bc..10d1e1f0139ba 100644
--- a/include/llvm/ADT/ImmutableMap.h
+++ b/include/llvm/ADT/ImmutableMap.h
@@ -26,12 +26,12 @@ namespace llvm {
/// only the first element (the key) is used by isEqual and isLess.
template <typename T, typename S>
struct ImutKeyValueInfo {
- typedef const std::pair<T,S> value_type;
- typedef const value_type& value_type_ref;
- typedef const T key_type;
- typedef const T& key_type_ref;
- typedef const S data_type;
- typedef const S& data_type_ref;
+ using value_type = const std::pair<T,S>;
+ using value_type_ref = const value_type&;
+ using key_type = const T;
+ using key_type_ref = const T&;
+ using data_type = const S;
+ using data_type_ref = const S&;
static inline key_type_ref KeyOfValue(value_type_ref V) {
return V.first;
@@ -62,13 +62,13 @@ template <typename KeyT, typename ValT,
typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
class ImmutableMap {
public:
- typedef typename ValInfo::value_type value_type;
- typedef typename ValInfo::value_type_ref value_type_ref;
- typedef typename ValInfo::key_type key_type;
- typedef typename ValInfo::key_type_ref key_type_ref;
- typedef typename ValInfo::data_type data_type;
- typedef typename ValInfo::data_type_ref data_type_ref;
- typedef ImutAVLTree<ValInfo> TreeTy;
+ using value_type = typename ValInfo::value_type;
+ using value_type_ref = typename ValInfo::value_type_ref;
+ using key_type = typename ValInfo::key_type;
+ using key_type_ref = typename ValInfo::key_type_ref;
+ using data_type = typename ValInfo::data_type;
+ using data_type_ref = typename ValInfo::data_type_ref;
+ using TreeTy = ImutAVLTree<ValInfo>;
protected:
TreeTy* Root;
@@ -86,6 +86,10 @@ public:
if (Root) { Root->retain(); }
}
+ ~ImmutableMap() {
+ if (Root) { Root->release(); }
+ }
+
ImmutableMap &operator=(const ImmutableMap &X) {
if (Root != X.Root) {
if (X.Root) { X.Root->retain(); }
@@ -95,10 +99,6 @@ public:
return *this;
}
- ~ImmutableMap() {
- if (Root) { Root->release(); }
- }
-
class Factory {
typename TreeTy::Factory F;
const bool Canonicalize;
@@ -166,12 +166,14 @@ private:
template <typename Callback>
struct CBWrapper {
Callback C;
+
void operator()(value_type_ref V) { C(V.first,V.second); }
};
template <typename Callback>
struct CBWrapperRef {
Callback &C;
+
CBWrapperRef(Callback& c) : C(c) {}
void operator()(value_type_ref V) { C(V.first,V.second); }
@@ -254,14 +256,14 @@ template <typename KeyT, typename ValT,
typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
class ImmutableMapRef {
public:
- typedef typename ValInfo::value_type value_type;
- typedef typename ValInfo::value_type_ref value_type_ref;
- typedef typename ValInfo::key_type key_type;
- typedef typename ValInfo::key_type_ref key_type_ref;
- typedef typename ValInfo::data_type data_type;
- typedef typename ValInfo::data_type_ref data_type_ref;
- typedef ImutAVLTree<ValInfo> TreeTy;
- typedef typename TreeTy::Factory FactoryTy;
+ using value_type = typename ValInfo::value_type;
+ using value_type_ref = typename ValInfo::value_type_ref;
+ using key_type = typename ValInfo::key_type;
+ using key_type_ref = typename ValInfo::key_type_ref;
+ using data_type = typename ValInfo::data_type;
+ using data_type_ref = typename ValInfo::data_type_ref;
+ using TreeTy = ImutAVLTree<ValInfo>;
+ using FactoryTy = typename TreeTy::Factory;
protected:
TreeTy *Root;
@@ -292,6 +294,11 @@ public:
}
}
+ ~ImmutableMapRef() {
+ if (Root)
+ Root->release();
+ }
+
ImmutableMapRef &operator=(const ImmutableMapRef &X) {
if (Root != X.Root) {
if (X.Root)
@@ -306,11 +313,6 @@ public:
return *this;
}
- ~ImmutableMapRef() {
- if (Root)
- Root->release();
- }
-
static inline ImmutableMapRef getEmptyMap(FactoryTy *F) {
return ImmutableMapRef(0, F);
}
diff --git a/include/llvm/ADT/ImmutableSet.h b/include/llvm/ADT/ImmutableSet.h
index 9c9bcb81f76b0..9d580c5a3d416 100644
--- a/include/llvm/ADT/ImmutableSet.h
+++ b/include/llvm/ADT/ImmutableSet.h
@@ -41,18 +41,16 @@ template <typename ImutInfo> class ImutAVLTreeGenericIterator;
template <typename ImutInfo >
class ImutAVLTree {
public:
- typedef typename ImutInfo::key_type_ref key_type_ref;
- typedef typename ImutInfo::value_type value_type;
- typedef typename ImutInfo::value_type_ref value_type_ref;
+ using key_type_ref = typename ImutInfo::key_type_ref;
+ using value_type = typename ImutInfo::value_type;
+ using value_type_ref = typename ImutInfo::value_type_ref;
+ using Factory = ImutAVLFactory<ImutInfo>;
+ using iterator = ImutAVLTreeInOrderIterator<ImutInfo>;
- typedef ImutAVLFactory<ImutInfo> Factory;
friend class ImutAVLFactory<ImutInfo>;
friend class ImutIntervalAVLFactory<ImutInfo>;
-
friend class ImutAVLTreeGenericIterator<ImutInfo>;
- typedef ImutAVLTreeInOrderIterator<ImutInfo> iterator;
-
//===----------------------------------------------------===//
// Public Interface.
//===----------------------------------------------------===//
@@ -225,17 +223,17 @@ private:
Factory *factory;
ImutAVLTree *left;
ImutAVLTree *right;
- ImutAVLTree *prev;
- ImutAVLTree *next;
+ ImutAVLTree *prev = nullptr;
+ ImutAVLTree *next = nullptr;
- unsigned height : 28;
- unsigned IsMutable : 1;
- unsigned IsDigestCached : 1;
- unsigned IsCanonicalized : 1;
+ unsigned height : 28;
+ bool IsMutable : 1;
+ bool IsDigestCached : 1;
+ bool IsCanonicalized : 1;
value_type value;
- uint32_t digest;
- uint32_t refCount;
+ uint32_t digest = 0;
+ uint32_t refCount = 0;
//===----------------------------------------------------===//
// Internal methods (node manipulation; used by Factory).
@@ -246,9 +244,8 @@ private:
/// ImutAVLFactory.
ImutAVLTree(Factory *f, ImutAVLTree* l, ImutAVLTree* r, value_type_ref v,
unsigned height)
- : factory(f), left(l), right(r), prev(nullptr), next(nullptr),
- height(height), IsMutable(true), IsDigestCached(false),
- IsCanonicalized(0), value(v), digest(0), refCount(0)
+ : factory(f), left(l), right(r), height(height), IsMutable(true),
+ IsDigestCached(false), IsCanonicalized(false), value(v)
{
if (left) left->retain();
if (right) right->retain();
@@ -369,11 +366,11 @@ public:
template <typename ImutInfo >
class ImutAVLFactory {
friend class ImutAVLTree<ImutInfo>;
- typedef ImutAVLTree<ImutInfo> TreeTy;
- typedef typename TreeTy::value_type_ref value_type_ref;
- typedef typename TreeTy::key_type_ref key_type_ref;
- typedef DenseMap<unsigned, TreeTy*> CacheTy;
+ using TreeTy = ImutAVLTree<ImutInfo>;
+ using value_type_ref = typename TreeTy::value_type_ref;
+ using key_type_ref = typename TreeTy::key_type_ref;
+ using CacheTy = DenseMap<unsigned, TreeTy*>;
CacheTy Cache;
uintptr_t Allocator;
@@ -659,7 +656,7 @@ public:
enum VisitFlag { VisitedNone=0x0, VisitedLeft=0x1, VisitedRight=0x3,
Flags=0x3 };
- typedef ImutAVLTree<ImutInfo> TreeTy;
+ using TreeTy = ImutAVLTree<ImutInfo>;
ImutAVLTreeGenericIterator() = default;
ImutAVLTreeGenericIterator(const TreeTy *Root) {
@@ -764,11 +761,12 @@ template <typename ImutInfo>
class ImutAVLTreeInOrderIterator
: public std::iterator<std::bidirectional_iterator_tag,
ImutAVLTree<ImutInfo>> {
- typedef ImutAVLTreeGenericIterator<ImutInfo> InternalIteratorTy;
+ using InternalIteratorTy = ImutAVLTreeGenericIterator<ImutInfo>;
+
InternalIteratorTy InternalItr;
public:
- typedef ImutAVLTree<ImutInfo> TreeTy;
+ using TreeTy = ImutAVLTree<ImutInfo>;
ImutAVLTreeInOrderIterator(const TreeTy* Root) : InternalItr(Root) {
if (Root)
@@ -840,8 +838,8 @@ struct ImutAVLValueIterator
/// and generic handling of pointers is done below.
template <typename T>
struct ImutProfileInfo {
- typedef const T value_type;
- typedef const T& value_type_ref;
+ using value_type = const T;
+ using value_type_ref = const T&;
static void Profile(FoldingSetNodeID &ID, value_type_ref X) {
FoldingSetTrait<T>::Profile(X,ID);
@@ -851,8 +849,8 @@ struct ImutProfileInfo {
/// Profile traits for integers.
template <typename T>
struct ImutProfileInteger {
- typedef const T value_type;
- typedef const T& value_type_ref;
+ using value_type = const T;
+ using value_type_ref = const T&;
static void Profile(FoldingSetNodeID &ID, value_type_ref X) {
ID.AddInteger(X);
@@ -878,8 +876,8 @@ PROFILE_INTEGER_INFO(unsigned long long)
/// Profile traits for booleans.
template <>
struct ImutProfileInfo<bool> {
- typedef const bool value_type;
- typedef const bool& value_type_ref;
+ using value_type = const bool;
+ using value_type_ref = const bool&;
static void Profile(FoldingSetNodeID &ID, value_type_ref X) {
ID.AddBoolean(X);
@@ -890,8 +888,8 @@ struct ImutProfileInfo<bool> {
/// references to unique objects.
template <typename T>
struct ImutProfileInfo<T*> {
- typedef const T* value_type;
- typedef value_type value_type_ref;
+ using value_type = const T*;
+ using value_type_ref = value_type;
static void Profile(FoldingSetNodeID &ID, value_type_ref X) {
ID.AddPointer(X);
@@ -910,12 +908,12 @@ struct ImutProfileInfo<T*> {
/// std::equal_to<> and std::less<> to perform comparison of elements.
template <typename T>
struct ImutContainerInfo : public ImutProfileInfo<T> {
- typedef typename ImutProfileInfo<T>::value_type value_type;
- typedef typename ImutProfileInfo<T>::value_type_ref value_type_ref;
- typedef value_type key_type;
- typedef value_type_ref key_type_ref;
- typedef bool data_type;
- typedef bool data_type_ref;
+ using value_type = typename ImutProfileInfo<T>::value_type;
+ using value_type_ref = typename ImutProfileInfo<T>::value_type_ref;
+ using key_type = value_type;
+ using key_type_ref = value_type_ref;
+ using data_type = bool;
+ using data_type_ref = bool;
static key_type_ref KeyOfValue(value_type_ref D) { return D; }
static data_type_ref DataOfValue(value_type_ref) { return true; }
@@ -936,12 +934,12 @@ struct ImutContainerInfo : public ImutProfileInfo<T> {
/// their addresses.
template <typename T>
struct ImutContainerInfo<T*> : public ImutProfileInfo<T*> {
- typedef typename ImutProfileInfo<T*>::value_type value_type;
- typedef typename ImutProfileInfo<T*>::value_type_ref value_type_ref;
- typedef value_type key_type;
- typedef value_type_ref key_type_ref;
- typedef bool data_type;
- typedef bool data_type_ref;
+ using value_type = typename ImutProfileInfo<T*>::value_type;
+ using value_type_ref = typename ImutProfileInfo<T*>::value_type_ref;
+ using key_type = value_type;
+ using key_type_ref = value_type_ref;
+ using data_type = bool;
+ using data_type_ref = bool;
static key_type_ref KeyOfValue(value_type_ref D) { return D; }
static data_type_ref DataOfValue(value_type_ref) { return true; }
@@ -960,9 +958,9 @@ struct ImutContainerInfo<T*> : public ImutProfileInfo<T*> {
template <typename ValT, typename ValInfo = ImutContainerInfo<ValT>>
class ImmutableSet {
public:
- typedef typename ValInfo::value_type value_type;
- typedef typename ValInfo::value_type_ref value_type_ref;
- typedef ImutAVLTree<ValInfo> TreeTy;
+ using value_type = typename ValInfo::value_type;
+ using value_type_ref = typename ValInfo::value_type_ref;
+ using TreeTy = ImutAVLTree<ValInfo>;
private:
TreeTy *Root;
@@ -980,6 +978,10 @@ public:
if (Root) { Root->retain(); }
}
+ ~ImmutableSet() {
+ if (Root) { Root->release(); }
+ }
+
ImmutableSet &operator=(const ImmutableSet &X) {
if (Root != X.Root) {
if (X.Root) { X.Root->retain(); }
@@ -989,10 +991,6 @@ public:
return *this;
}
- ~ImmutableSet() {
- if (Root) { Root->release(); }
- }
-
class Factory {
typename TreeTy::Factory F;
const bool Canonicalize;
@@ -1084,7 +1082,7 @@ public:
// Iterators.
//===--------------------------------------------------===//
- typedef ImutAVLValueIterator<ImmutableSet> iterator;
+ using iterator = ImutAVLValueIterator<ImmutableSet>;
iterator begin() const { return iterator(Root); }
iterator end() const { return iterator(); }
@@ -1112,10 +1110,10 @@ public:
template <typename ValT, typename ValInfo = ImutContainerInfo<ValT>>
class ImmutableSetRef {
public:
- typedef typename ValInfo::value_type value_type;
- typedef typename ValInfo::value_type_ref value_type_ref;
- typedef ImutAVLTree<ValInfo> TreeTy;
- typedef typename TreeTy::Factory FactoryTy;
+ using value_type = typename ValInfo::value_type;
+ using value_type_ref = typename ValInfo::value_type_ref;
+ using TreeTy = ImutAVLTree<ValInfo>;
+ using FactoryTy = typename TreeTy::Factory;
private:
TreeTy *Root;
@@ -1138,6 +1136,10 @@ public:
if (Root) { Root->retain(); }
}
+ ~ImmutableSetRef() {
+ if (Root) { Root->release(); }
+ }
+
ImmutableSetRef &operator=(const ImmutableSetRef &X) {
if (Root != X.Root) {
if (X.Root) { X.Root->retain(); }
@@ -1147,9 +1149,6 @@ public:
}
return *this;
}
- ~ImmutableSetRef() {
- if (Root) { Root->release(); }
- }
static ImmutableSetRef getEmptySet(FactoryTy *F) {
return ImmutableSetRef(0, F);
@@ -1196,7 +1195,7 @@ public:
// Iterators.
//===--------------------------------------------------===//
- typedef ImutAVLValueIterator<ImmutableSetRef> iterator;
+ using iterator = ImutAVLValueIterator<ImmutableSetRef>;
iterator begin() const { return iterator(Root); }
iterator end() const { return iterator(); }
diff --git a/include/llvm/ADT/IndexedMap.h b/include/llvm/ADT/IndexedMap.h
index 5ba85c0279209..2ee80d2cde63a 100644
--- a/include/llvm/ADT/IndexedMap.h
+++ b/include/llvm/ADT/IndexedMap.h
@@ -20,28 +20,28 @@
#ifndef LLVM_ADT_INDEXEDMAP_H
#define LLVM_ADT_INDEXEDMAP_H
-#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/STLExtras.h"
#include <cassert>
-#include <functional>
namespace llvm {
-template <typename T, typename ToIndexT = llvm::identity<unsigned> >
+template <typename T, typename ToIndexT = identity<unsigned>>
class IndexedMap {
- typedef typename ToIndexT::argument_type IndexT;
+ using IndexT = typename ToIndexT::argument_type;
// Prefer SmallVector with zero inline storage over std::vector. IndexedMaps
// can grow very large and SmallVector grows more efficiently as long as T
// is trivially copyable.
- typedef SmallVector<T, 0> StorageT;
+ using StorageT = SmallVector<T, 0>;
+
StorageT storage_;
T nullVal_;
ToIndexT toIndex_;
public:
- IndexedMap() : nullVal_(T()) { }
+ IndexedMap() : nullVal_(T()) {}
- explicit IndexedMap(const T& val) : nullVal_(val) { }
+ explicit IndexedMap(const T& val) : nullVal_(val) {}
typename StorageT::reference operator[](IndexT n) {
assert(toIndex_(n) < storage_.size() && "index out of bounds!");
@@ -80,6 +80,6 @@ template <typename T, typename ToIndexT = llvm::identity<unsigned> >
}
};
-} // End llvm namespace
+} // end namespace llvm
-#endif
+#endif // LLVM_ADT_INDEXEDMAP_H
diff --git a/include/llvm/ADT/IntervalMap.h b/include/llvm/ADT/IntervalMap.h
index 430b9671bd1d7..f71366811218b 100644
--- a/include/llvm/ADT/IntervalMap.h
+++ b/include/llvm/ADT/IntervalMap.h
@@ -106,6 +106,7 @@
#include "llvm/Support/RecyclingAllocator.h"
#include <algorithm>
#include <cassert>
+#include <cstdint>
#include <iterator>
#include <new>
#include <utility>
@@ -186,7 +187,7 @@ struct IntervalMapHalfOpenInfo {
/// It should be considered private to the implementation.
namespace IntervalMapImpl {
-typedef std::pair<unsigned,unsigned> IdxPair;
+using IdxPair = std::pair<unsigned,unsigned>;
//===----------------------------------------------------------------------===//
//--- IntervalMapImpl::NodeBase ---//
@@ -445,7 +446,7 @@ struct NodeSizer {
LeafSize = DesiredLeafSize > MinLeafSize ? DesiredLeafSize : MinLeafSize
};
- typedef NodeBase<std::pair<KeyT, KeyT>, ValT, LeafSize> LeafBase;
+ using LeafBase = NodeBase<std::pair<KeyT, KeyT>, ValT, LeafSize>;
enum {
// Now that we have the leaf branching factor, compute the actual allocation
@@ -461,8 +462,8 @@ struct NodeSizer {
/// This typedef is very likely to be identical for all IntervalMaps with
/// reasonably sized entries, so the same allocator can be shared among
/// different kinds of maps.
- typedef RecyclingAllocator<BumpPtrAllocator, char,
- AllocBytes, CacheLineBytes> Allocator;
+ using Allocator =
+ RecyclingAllocator<BumpPtrAllocator, char, AllocBytes, CacheLineBytes>;
};
//===----------------------------------------------------------------------===//
@@ -930,12 +931,12 @@ template <typename KeyT, typename ValT,
unsigned N = IntervalMapImpl::NodeSizer<KeyT, ValT>::LeafSize,
typename Traits = IntervalMapInfo<KeyT>>
class IntervalMap {
- typedef IntervalMapImpl::NodeSizer<KeyT, ValT> Sizer;
- typedef IntervalMapImpl::LeafNode<KeyT, ValT, Sizer::LeafSize, Traits> Leaf;
- typedef IntervalMapImpl::BranchNode<KeyT, ValT, Sizer::BranchSize, Traits>
- Branch;
- typedef IntervalMapImpl::LeafNode<KeyT, ValT, N, Traits> RootLeaf;
- typedef IntervalMapImpl::IdxPair IdxPair;
+ using Sizer = IntervalMapImpl::NodeSizer<KeyT, ValT>;
+ using Leaf = IntervalMapImpl::LeafNode<KeyT, ValT, Sizer::LeafSize, Traits>;
+ using Branch =
+ IntervalMapImpl::BranchNode<KeyT, ValT, Sizer::BranchSize, Traits>;
+ using RootLeaf = IntervalMapImpl::LeafNode<KeyT, ValT, N, Traits>;
+ using IdxPair = IntervalMapImpl::IdxPair;
// The RootLeaf capacity is given as a template parameter. We must compute the
// corresponding RootBranch capacity.
@@ -945,8 +946,8 @@ class IntervalMap {
RootBranchCap = DesiredRootBranchCap ? DesiredRootBranchCap : 1
};
- typedef IntervalMapImpl::BranchNode<KeyT, ValT, RootBranchCap, Traits>
- RootBranch;
+ using RootBranch =
+ IntervalMapImpl::BranchNode<KeyT, ValT, RootBranchCap, Traits>;
// When branched, we store a global start key as well as the branch node.
struct RootBranchData {
@@ -955,10 +956,10 @@ class IntervalMap {
};
public:
- typedef typename Sizer::Allocator Allocator;
- typedef KeyT KeyType;
- typedef ValT ValueType;
- typedef Traits KeyTraits;
+ using Allocator = typename Sizer::Allocator;
+ using KeyType = KeyT;
+ using ValueType = ValT;
+ using KeyTraits = Traits;
private:
// The root data is either a RootLeaf or a RootBranchData instance.
@@ -1290,7 +1291,7 @@ protected:
friend class IntervalMap;
// The map referred to.
- IntervalMap *map;
+ IntervalMap *map = nullptr;
// We store a full path from the root to the current position.
// The path may be partially filled, but never between iterator calls.
@@ -1338,7 +1339,7 @@ protected:
public:
/// const_iterator - Create an iterator that isn't pointing anywhere.
- const_iterator() : map(nullptr) {}
+ const_iterator() = default;
/// setMap - Change the map iterated over. This call must be followed by a
/// call to goToBegin(), goToEnd(), or find()
@@ -1509,7 +1510,8 @@ const_iterator::treeAdvanceTo(KeyT x) {
template <typename KeyT, typename ValT, unsigned N, typename Traits>
class IntervalMap<KeyT, ValT, N, Traits>::iterator : public const_iterator {
friend class IntervalMap;
- typedef IntervalMapImpl::IdxPair IdxPair;
+
+ using IdxPair = IntervalMapImpl::IdxPair;
explicit iterator(IntervalMap &map) : const_iterator(map) {}
@@ -2003,7 +2005,7 @@ iterator::overflow(unsigned Level) {
// Elements have been rearranged, now update node sizes and stops.
bool SplitRoot = false;
unsigned Pos = 0;
- for (;;) {
+ while (true) {
KeyT Stop = Node[Pos]->stop(NewSize[Pos]-1);
if (NewNode && Pos == NewNode) {
SplitRoot = insertNode(Level, NodeRef(Node[Pos], NewSize[Pos]), Stop);
@@ -2045,8 +2047,9 @@ iterator::overflow(unsigned Level) {
///
template <typename MapA, typename MapB>
class IntervalMapOverlaps {
- typedef typename MapA::KeyType KeyType;
- typedef typename MapA::KeyTraits Traits;
+ using KeyType = typename MapA::KeyType;
+ using Traits = typename MapA::KeyTraits;
+
typename MapA::const_iterator posA;
typename MapB::const_iterator posB;
@@ -2071,7 +2074,7 @@ class IntervalMapOverlaps {
// Already overlapping.
return;
- for (;;) {
+ while (true) {
// Make a.end > b.start.
posA.advanceTo(posB.start());
if (!posA.valid() || !Traits::stopLess(posB.stop(), posA.start()))
diff --git a/include/llvm/ADT/IntrusiveRefCntPtr.h b/include/llvm/ADT/IntrusiveRefCntPtr.h
index a77cf04ea4d1d..430ef86afbd95 100644
--- a/include/llvm/ADT/IntrusiveRefCntPtr.h
+++ b/include/llvm/ADT/IntrusiveRefCntPtr.h
@@ -1,4 +1,4 @@
-//== llvm/ADT/IntrusiveRefCntPtr.h - Smart Refcounting Pointer ---*- C++ -*-==//
+//==- llvm/ADT/IntrusiveRefCntPtr.h - Smart Refcounting Pointer --*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
@@ -73,9 +73,10 @@ template <class Derived> class RefCountedBase {
public:
RefCountedBase() = default;
- RefCountedBase(const RefCountedBase &) : RefCount(0) {}
+ RefCountedBase(const RefCountedBase &) {}
void Retain() const { ++RefCount; }
+
void Release() const {
assert(RefCount > 0 && "Reference count is already zero.");
if (--RefCount == 0)
@@ -136,7 +137,7 @@ template <typename T> class IntrusiveRefCntPtr {
T *Obj = nullptr;
public:
- typedef T element_type;
+ using element_type = T;
explicit IntrusiveRefCntPtr() = default;
IntrusiveRefCntPtr(T *obj) : Obj(obj) { retain(); }
@@ -153,13 +154,13 @@ public:
retain();
}
+ ~IntrusiveRefCntPtr() { release(); }
+
IntrusiveRefCntPtr &operator=(IntrusiveRefCntPtr S) {
swap(S);
return *this;
}
- ~IntrusiveRefCntPtr() { release(); }
-
T &operator*() const { return *Obj; }
T *operator->() const { return Obj; }
T *get() const { return Obj; }
@@ -183,6 +184,7 @@ private:
if (Obj)
IntrusiveRefCntPtrInfo<T>::retain(Obj);
}
+
void release() {
if (Obj)
IntrusiveRefCntPtrInfo<T>::release(Obj);
@@ -248,14 +250,16 @@ bool operator!=(const IntrusiveRefCntPtr<T> &A, std::nullptr_t B) {
template <typename From> struct simplify_type;
template <class T> struct simplify_type<IntrusiveRefCntPtr<T>> {
- typedef T *SimpleType;
+ using SimpleType = T *;
+
static SimpleType getSimplifiedValue(IntrusiveRefCntPtr<T> &Val) {
return Val.get();
}
};
template <class T> struct simplify_type<const IntrusiveRefCntPtr<T>> {
- typedef /*const*/ T *SimpleType;
+ using SimpleType = /*const*/ T *;
+
static SimpleType getSimplifiedValue(const IntrusiveRefCntPtr<T> &Val) {
return Val.get();
}
diff --git a/include/llvm/ADT/MapVector.h b/include/llvm/ADT/MapVector.h
index ac1885758cb9c..26a555ee1d3bd 100644
--- a/include/llvm/ADT/MapVector.h
+++ b/include/llvm/ADT/MapVector.h
@@ -19,6 +19,12 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
+#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <iterator>
+#include <type_traits>
+#include <utility>
#include <vector>
namespace llvm {
@@ -27,20 +33,20 @@ namespace llvm {
/// in a deterministic order. The values are kept in a std::vector and the
/// mapping is done with DenseMap from Keys to indexes in that vector.
template<typename KeyT, typename ValueT,
- typename MapType = llvm::DenseMap<KeyT, unsigned>,
- typename VectorType = std::vector<std::pair<KeyT, ValueT> > >
+ typename MapType = DenseMap<KeyT, unsigned>,
+ typename VectorType = std::vector<std::pair<KeyT, ValueT>>>
class MapVector {
- typedef typename VectorType::value_type value_type;
- typedef typename VectorType::size_type size_type;
+ using value_type = typename VectorType::value_type;
+ using size_type = typename VectorType::size_type;
MapType Map;
VectorType Vector;
public:
- typedef typename VectorType::iterator iterator;
- typedef typename VectorType::const_iterator const_iterator;
- typedef typename VectorType::reverse_iterator reverse_iterator;
- typedef typename VectorType::const_reverse_iterator const_reverse_iterator;
+ using iterator = typename VectorType::iterator;
+ using const_iterator = typename VectorType::const_iterator;
+ using reverse_iterator = typename VectorType::reverse_iterator;
+ using const_reverse_iterator = typename VectorType::const_reverse_iterator;
/// Clear the MapVector and return the underlying vector.
VectorType takeVector() {
@@ -220,4 +226,4 @@ struct SmallMapVector
} // end namespace llvm
-#endif
+#endif // LLVM_ADT_MAPVECTOR_H
diff --git a/include/llvm/ADT/Optional.h b/include/llvm/ADT/Optional.h
index 701872c9f63fc..b782d9da17ac4 100644
--- a/include/llvm/ADT/Optional.h
+++ b/include/llvm/ADT/Optional.h
@@ -1,4 +1,4 @@
-//===-- Optional.h - Simple variant for passing optional values ---*- C++ -*-=//
+//===- Optional.h - Simple variant for passing optional values --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -19,6 +19,8 @@
#include "llvm/ADT/None.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/type_traits.h"
+#include <algorithm>
#include <cassert>
#include <new>
#include <utility>
@@ -28,15 +30,18 @@ namespace llvm {
template<typename T>
class Optional {
AlignedCharArrayUnion<T> storage;
- bool hasVal;
+ bool hasVal = false;
+
public:
- typedef T value_type;
+ using value_type = T;
+
+ Optional(NoneType) {}
+ explicit Optional() {}
- Optional(NoneType) : hasVal(false) {}
- explicit Optional() : hasVal(false) {}
Optional(const T &y) : hasVal(true) {
new (storage.buffer) T(y);
}
+
Optional(const Optional &O) : hasVal(O.hasVal) {
if (hasVal)
new (storage.buffer) T(*O);
@@ -45,12 +50,18 @@ public:
Optional(T &&y) : hasVal(true) {
new (storage.buffer) T(std::forward<T>(y));
}
+
Optional(Optional<T> &&O) : hasVal(O) {
if (O) {
new (storage.buffer) T(std::move(*O));
O.reset();
}
}
+
+ ~Optional() {
+ reset();
+ }
+
Optional &operator=(T &&y) {
if (hasVal)
**this = std::move(y);
@@ -60,6 +71,7 @@ public:
}
return *this;
}
+
Optional &operator=(Optional &&O) {
if (!O)
reset();
@@ -112,10 +124,6 @@ public:
}
}
- ~Optional() {
- reset();
- }
-
const T* getPointer() const { assert(hasVal); return reinterpret_cast<const T*>(storage.buffer); }
T* getPointer() { assert(hasVal); return reinterpret_cast<T*>(storage.buffer); }
const T& getValue() const LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); }
@@ -144,8 +152,7 @@ public:
#endif
};
-template <typename T> struct isPodLike;
-template <typename T> struct isPodLike<Optional<T> > {
+template <typename T> struct isPodLike<Optional<T>> {
// An Optional<T> is pod-like if T is.
static const bool value = isPodLike<T>::value;
};
@@ -284,6 +291,6 @@ template <typename T> bool operator>=(const T &X, const Optional<T> &Y) {
return !(X < Y);
}
-} // end llvm namespace
+} // end namespace llvm
-#endif
+#endif // LLVM_ADT_OPTIONAL_H
diff --git a/include/llvm/ADT/PackedVector.h b/include/llvm/ADT/PackedVector.h
index 8f925f1ff5cbc..95adc2926813b 100644
--- a/include/llvm/ADT/PackedVector.h
+++ b/include/llvm/ADT/PackedVector.h
@@ -76,8 +76,8 @@ template <typename T, unsigned BitNum, typename BitVectorTy = BitVector>
class PackedVector : public PackedVectorBase<T, BitNum, BitVectorTy,
std::numeric_limits<T>::is_signed> {
BitVectorTy Bits;
- typedef PackedVectorBase<T, BitNum, BitVectorTy,
- std::numeric_limits<T>::is_signed> base;
+ using base = PackedVectorBase<T, BitNum, BitVectorTy,
+ std::numeric_limits<T>::is_signed>;
public:
class reference {
@@ -99,7 +99,7 @@ public:
};
PackedVector() = default;
- explicit PackedVector(unsigned size) : Bits(size << (BitNum-1)) { }
+ explicit PackedVector(unsigned size) : Bits(size << (BitNum-1)) {}
bool empty() const { return Bits.empty(); }
diff --git a/include/llvm/ADT/PointerEmbeddedInt.h b/include/llvm/ADT/PointerEmbeddedInt.h
index 2279d43405fa7..34323b5b8af49 100644
--- a/include/llvm/ADT/PointerEmbeddedInt.h
+++ b/include/llvm/ADT/PointerEmbeddedInt.h
@@ -13,7 +13,10 @@
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/PointerLikeTypeTraits.h"
+#include <cassert>
#include <climits>
+#include <cstdint>
+#include <type_traits>
namespace llvm {
@@ -29,7 +32,7 @@ namespace llvm {
/// Also, the default constructed value zero initializes the integer.
template <typename IntT, int Bits = sizeof(IntT) * CHAR_BIT>
class PointerEmbeddedInt {
- uintptr_t Value;
+ uintptr_t Value = 0;
// Note: This '<' is correct; using '<=' would result in some shifts
// overflowing their storage types.
@@ -54,15 +57,12 @@ class PointerEmbeddedInt {
explicit PointerEmbeddedInt(uintptr_t Value, RawValueTag) : Value(Value) {}
public:
- PointerEmbeddedInt() : Value(0) {}
+ PointerEmbeddedInt() = default;
- PointerEmbeddedInt(IntT I) {
- *this = I;
- }
+ PointerEmbeddedInt(IntT I) { *this = I; }
PointerEmbeddedInt &operator=(IntT I) {
- assert((std::is_signed<IntT>::value ? llvm::isInt<Bits>(I)
- : llvm::isUInt<Bits>(I)) &&
+ assert((std::is_signed<IntT>::value ? isInt<Bits>(I) : isUInt<Bits>(I)) &&
"Integer has bits outside those preserved!");
Value = static_cast<uintptr_t>(I) << Shift;
return *this;
@@ -81,15 +81,17 @@ public:
// types.
template <typename IntT, int Bits>
class PointerLikeTypeTraits<PointerEmbeddedInt<IntT, Bits>> {
- typedef PointerEmbeddedInt<IntT, Bits> T;
+ using T = PointerEmbeddedInt<IntT, Bits>;
public:
static inline void *getAsVoidPointer(const T &P) {
return reinterpret_cast<void *>(P.Value);
}
+
static inline T getFromVoidPointer(void *P) {
return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag());
}
+
static inline T getFromVoidPointer(const void *P) {
return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag());
}
@@ -101,17 +103,19 @@ public:
// itself can be a key.
template <typename IntT, int Bits>
struct DenseMapInfo<PointerEmbeddedInt<IntT, Bits>> {
- typedef PointerEmbeddedInt<IntT, Bits> T;
-
- typedef DenseMapInfo<IntT> IntInfo;
+ using T = PointerEmbeddedInt<IntT, Bits>;
+ using IntInfo = DenseMapInfo<IntT>;
static inline T getEmptyKey() { return IntInfo::getEmptyKey(); }
static inline T getTombstoneKey() { return IntInfo::getTombstoneKey(); }
+
static unsigned getHashValue(const T &Arg) {
return IntInfo::getHashValue(Arg);
}
+
static bool isEqual(const T &LHS, const T &RHS) { return LHS == RHS; }
};
-}
-#endif
+} // end namespace llvm
+
+#endif // LLVM_ADT_POINTEREMBEDDEDINT_H
diff --git a/include/llvm/ADT/PointerUnion.h b/include/llvm/ADT/PointerUnion.h
index 7ce70ebc8ce01..aeab641f5715a 100644
--- a/include/llvm/ADT/PointerUnion.h
+++ b/include/llvm/ADT/PointerUnion.h
@@ -158,7 +158,7 @@ public:
assert(
get<PT1>() == Val.getPointer() &&
"Can't get the address because PointerLikeTypeTraits changes the ptr");
- return (PT1 *)Val.getAddrOfPointer();
+ return const_cast<PT1 *>(reinterpret_cast<const PT1 *>(Val.getAddrOfPointer()));
}
/// Assignment from nullptr which just clears the union.
diff --git a/include/llvm/ADT/ScopedHashTable.h b/include/llvm/ADT/ScopedHashTable.h
index d52128e294a32..22b0c1bdaf4d0 100644
--- a/include/llvm/ADT/ScopedHashTable.h
+++ b/include/llvm/ADT/ScopedHashTable.h
@@ -109,6 +109,7 @@ private:
ScopedHashTableVal<K, V> *getLastValInScope() {
return LastValInScope;
}
+
void setLastValInScope(ScopedHashTableVal<K, V> *Val) {
LastValInScope = Val;
}
@@ -151,13 +152,14 @@ class ScopedHashTable {
public:
/// ScopeTy - This is a helpful typedef that allows clients to get easy access
/// to the name of the scope for this hash table.
- typedef ScopedHashTableScope<K, V, KInfo, AllocatorTy> ScopeTy;
- typedef unsigned size_type;
+ using ScopeTy = ScopedHashTableScope<K, V, KInfo, AllocatorTy>;
+ using size_type = unsigned;
private:
friend class ScopedHashTableScope<K, V, KInfo, AllocatorTy>;
- typedef ScopedHashTableVal<K, V> ValTy;
+ using ValTy = ScopedHashTableVal<K, V>;
+
DenseMap<K, ValTy*, KInfo> TopLevelMap;
ScopeTy *CurScope = nullptr;
@@ -165,7 +167,7 @@ private:
public:
ScopedHashTable() = default;
- ScopedHashTable(AllocatorTy A) : CurScope(0), Allocator(A) {}
+ ScopedHashTable(AllocatorTy A) : Allocator(A) {}
ScopedHashTable(const ScopedHashTable &) = delete;
ScopedHashTable &operator=(const ScopedHashTable &) = delete;
@@ -194,7 +196,7 @@ public:
insertIntoScope(CurScope, Key, Val);
}
- typedef ScopedHashTableIterator<K, V, KInfo> iterator;
+ using iterator = ScopedHashTableIterator<K, V, KInfo>;
iterator end() { return iterator(0); }
diff --git a/include/llvm/ADT/SmallBitVector.h b/include/llvm/ADT/SmallBitVector.h
index 0ff4270669591..b6391746639b0 100644
--- a/include/llvm/ADT/SmallBitVector.h
+++ b/include/llvm/ADT/SmallBitVector.h
@@ -15,8 +15,15 @@
#define LLVM_ADT_SMALLBITVECTOR_H
#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/MathExtras.h"
+#include <algorithm>
#include <cassert>
+#include <climits>
+#include <cstddef>
+#include <cstdint>
+#include <limits>
+#include <utility>
namespace llvm {
@@ -29,7 +36,7 @@ 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.
- uintptr_t X;
+ uintptr_t X = 1;
enum {
// The number of bits in this class.
@@ -54,7 +61,8 @@ class SmallBitVector {
"Unsupported word size");
public:
- typedef unsigned size_type;
+ using size_type = unsigned;
+
// Encapsulation of a single bit.
class reference {
SmallBitVector &TheVector;
@@ -134,21 +142,8 @@ private:
}
public:
- typedef const_set_bits_iterator_impl<SmallBitVector> const_set_bits_iterator;
- typedef const_set_bits_iterator set_iterator;
-
- const_set_bits_iterator set_bits_begin() const {
- return const_set_bits_iterator(*this);
- }
- const_set_bits_iterator set_bits_end() const {
- return const_set_bits_iterator(*this, -1);
- }
- iterator_range<const_set_bits_iterator> set_bits() const {
- return make_range(set_bits_begin(), set_bits_end());
- }
-
/// Creates an empty bitvector.
- SmallBitVector() : X(1) {}
+ SmallBitVector() = default;
/// Creates a bitvector of specified number of bits. All bits are initialized
/// to the specified value.
@@ -176,6 +171,21 @@ public:
delete getPointer();
}
+ using const_set_bits_iterator = const_set_bits_iterator_impl<SmallBitVector>;
+ using set_iterator = const_set_bits_iterator;
+
+ const_set_bits_iterator set_bits_begin() const {
+ return const_set_bits_iterator(*this);
+ }
+
+ const_set_bits_iterator set_bits_end() const {
+ return const_set_bits_iterator(*this, -1);
+ }
+
+ iterator_range<const_set_bits_iterator> set_bits() const {
+ return make_range(set_bits_begin(), set_bits_end());
+ }
+
/// Tests whether there are no bits in this bitvector.
bool empty() const {
return isSmall() ? getSmallSize() == 0 : getPointer()->empty();
@@ -677,14 +687,16 @@ operator^(const SmallBitVector &LHS, const SmallBitVector &RHS) {
return Result;
}
-} // End llvm namespace
+} // end namespace llvm
namespace std {
- /// Implement std::swap in terms of BitVector swap.
- inline void
- swap(llvm::SmallBitVector &LHS, llvm::SmallBitVector &RHS) {
- LHS.swap(RHS);
- }
+
+/// Implement std::swap in terms of BitVector swap.
+inline void
+swap(llvm::SmallBitVector &LHS, llvm::SmallBitVector &RHS) {
+ LHS.swap(RHS);
}
-#endif
+} // end namespace std
+
+#endif // LLVM_ADT_SMALLBITVECTOR_H
diff --git a/include/llvm/ADT/SmallSet.h b/include/llvm/ADT/SmallSet.h
index 6dac1677b7a26..d52d0f07f9a63 100644
--- a/include/llvm/ADT/SmallSet.h
+++ b/include/llvm/ADT/SmallSet.h
@@ -39,8 +39,9 @@ class SmallSet {
/// we will never use.
SmallVector<T, N> Vector;
std::set<T, C> Set;
- typedef typename SmallVector<T, N>::const_iterator VIterator;
- typedef typename SmallVector<T, N>::iterator mutable_iterator;
+
+ using VIterator = typename SmallVector<T, N>::const_iterator;
+ using mutable_iterator = typename SmallVector<T, N>::iterator;
// In small mode SmallPtrSet uses linear search for the elements, so it is
// not a good idea to choose this value too high. You may consider using a
@@ -48,7 +49,7 @@ class SmallSet {
static_assert(N <= 32, "N should be small");
public:
- typedef size_t size_type;
+ using size_type = size_t;
SmallSet() = default;
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index bbea8619a6736..ffcf998a3d323 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -14,6 +14,7 @@
#ifndef LLVM_ADT_STRINGEXTRAS_H
#define LLVM_ADT_STRINGEXTRAS_H
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include <cassert>
#include <cstddef>
@@ -40,6 +41,11 @@ static inline StringRef toStringRef(bool B) {
return StringRef(B ? "true" : "false");
}
+/// Construct a string ref from an array ref of unsigned chars.
+static inline StringRef toStringRef(ArrayRef<uint8_t> Input) {
+ return StringRef(reinterpret_cast<const char *>(Input.begin()), Input.size());
+}
+
/// Interpret the given character \p C as a hexadecimal digit and return its
/// value.
///
@@ -68,7 +74,7 @@ static inline std::string utohexstr(uint64_t X, bool LowerCase = false) {
/// Convert buffer \p Input to its hexadecimal representation.
/// The returned string is double the size of \p Input.
-static inline std::string toHex(StringRef Input) {
+inline std::string toHex(StringRef Input) {
static const char *const LUT = "0123456789ABCDEF";
size_t Length = Input.size();
@@ -82,6 +88,10 @@ static inline std::string toHex(StringRef Input) {
return Output;
}
+inline std::string toHex(ArrayRef<uint8_t> Input) {
+ return toHex(toStringRef(Input));
+}
+
static inline uint8_t hexFromNibbles(char MSB, char LSB) {
unsigned U1 = hexDigitValue(MSB);
unsigned U2 = hexDigitValue(LSB);
diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h
index 07626982d2890..26a991812a3a5 100644
--- a/include/llvm/ADT/Triple.h
+++ b/include/llvm/ADT/Triple.h
@@ -239,7 +239,9 @@ public:
/// Default constructor is the same as an empty string and leaves all
/// triple fields unknown.
- Triple() : Data(), Arch(), Vendor(), OS(), Environment(), ObjectFormat() {}
+ Triple()
+ : Data(), Arch(), SubArch(), Vendor(), OS(), Environment(),
+ ObjectFormat() {}
explicit Triple(const Twine &Str);
Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr);
diff --git a/include/llvm/ADT/ilist_base.h b/include/llvm/ADT/ilist_base.h
index 1ffc864bea2f3..3d818a48d41d4 100644
--- a/include/llvm/ADT/ilist_base.h
+++ b/include/llvm/ADT/ilist_base.h
@@ -1,4 +1,4 @@
-//===- llvm/ADT/ilist_base.h - Intrusive List Base ---------------*- C++ -*-==//
+//===- llvm/ADT/ilist_base.h - Intrusive List Base --------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -12,15 +12,13 @@
#include "llvm/ADT/ilist_node_base.h"
#include <cassert>
-#include <cstddef>
-#include <type_traits>
namespace llvm {
/// Implementations of list algorithms using ilist_node_base.
template <bool EnableSentinelTracking> class ilist_base {
public:
- typedef ilist_node_base<EnableSentinelTracking> node_base_type;
+ using node_base_type = ilist_node_base<EnableSentinelTracking>;
static void insertBeforeImpl(node_base_type &Next, node_base_type &N) {
node_base_type &Prev = *Next.getPrev();
diff --git a/include/llvm/ADT/ilist_iterator.h b/include/llvm/ADT/ilist_iterator.h
index c848d1a134f19..671e644e01542 100644
--- a/include/llvm/ADT/ilist_iterator.h
+++ b/include/llvm/ADT/ilist_iterator.h
@@ -1,4 +1,4 @@
-//===- llvm/ADT/ilist_iterator.h - Intrusive List Iterator -------*- C++ -*-==//
+//===- llvm/ADT/ilist_iterator.h - Intrusive List Iterator ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -23,28 +23,30 @@ namespace ilist_detail {
/// Find const-correct node types.
template <class OptionsT, bool IsConst> struct IteratorTraits;
template <class OptionsT> struct IteratorTraits<OptionsT, false> {
- typedef typename OptionsT::value_type value_type;
- typedef typename OptionsT::pointer pointer;
- typedef typename OptionsT::reference reference;
- typedef ilist_node_impl<OptionsT> *node_pointer;
- typedef ilist_node_impl<OptionsT> &node_reference;
+ using value_type = typename OptionsT::value_type;
+ using pointer = typename OptionsT::pointer;
+ using reference = typename OptionsT::reference;
+ using node_pointer = ilist_node_impl<OptionsT> *;
+ using node_reference = ilist_node_impl<OptionsT> &;
};
template <class OptionsT> struct IteratorTraits<OptionsT, true> {
- typedef const typename OptionsT::value_type value_type;
- typedef typename OptionsT::const_pointer pointer;
- typedef typename OptionsT::const_reference reference;
- typedef const ilist_node_impl<OptionsT> *node_pointer;
- typedef const ilist_node_impl<OptionsT> &node_reference;
+ using value_type = const typename OptionsT::value_type;
+ using pointer = typename OptionsT::const_pointer;
+ using reference = typename OptionsT::const_reference;
+ using node_pointer = const ilist_node_impl<OptionsT> *;
+ using node_reference = const ilist_node_impl<OptionsT> &;
};
template <bool IsReverse> struct IteratorHelper;
template <> struct IteratorHelper<false> : ilist_detail::NodeAccess {
- typedef ilist_detail::NodeAccess Access;
+ using Access = ilist_detail::NodeAccess;
+
template <class T> static void increment(T *&I) { I = Access::getNext(*I); }
template <class T> static void decrement(T *&I) { I = Access::getPrev(*I); }
};
template <> struct IteratorHelper<true> : ilist_detail::NodeAccess {
- typedef ilist_detail::NodeAccess Access;
+ using Access = ilist_detail::NodeAccess;
+
template <class T> static void increment(T *&I) { I = Access::getPrev(*I); }
template <class T> static void decrement(T *&I) { I = Access::getNext(*I); }
};
@@ -58,24 +60,23 @@ class ilist_iterator : ilist_detail::SpecificNodeAccess<OptionsT> {
friend ilist_iterator<OptionsT, !IsReverse, IsConst>;
friend ilist_iterator<OptionsT, !IsReverse, !IsConst>;
- typedef ilist_detail::IteratorTraits<OptionsT, IsConst> Traits;
- typedef ilist_detail::SpecificNodeAccess<OptionsT> Access;
+ using Traits = ilist_detail::IteratorTraits<OptionsT, IsConst>;
+ using Access = ilist_detail::SpecificNodeAccess<OptionsT>;
public:
- typedef typename Traits::value_type value_type;
- typedef typename Traits::pointer pointer;
- typedef typename Traits::reference reference;
- typedef ptrdiff_t difference_type;
- typedef std::bidirectional_iterator_tag iterator_category;
-
- typedef typename OptionsT::const_pointer const_pointer;
- typedef typename OptionsT::const_reference const_reference;
+ using value_type = typename Traits::value_type;
+ using pointer = typename Traits::pointer;
+ using reference = typename Traits::reference;
+ using difference_type = ptrdiff_t;
+ using iterator_category = std::bidirectional_iterator_tag;
+ using const_pointer = typename OptionsT::const_pointer;
+ using const_reference = typename OptionsT::const_reference;
private:
- typedef typename Traits::node_pointer node_pointer;
- typedef typename Traits::node_reference node_reference;
+ using node_pointer = typename Traits::node_pointer;
+ using node_reference = typename Traits::node_reference;
- node_pointer NodePtr;
+ node_pointer NodePtr = nullptr;
public:
/// Create from an ilist_node.
@@ -83,7 +84,7 @@ public:
explicit ilist_iterator(pointer NP) : NodePtr(Access::getNodePtr(NP)) {}
explicit ilist_iterator(reference NR) : NodePtr(Access::getNodePtr(&NR)) {}
- ilist_iterator() : NodePtr(nullptr) {}
+ ilist_iterator() = default;
// This is templated so that we can allow constructing a const iterator from
// a nonconst iterator...
@@ -184,8 +185,8 @@ template <typename From> struct simplify_type;
/// FIXME: remove this, since there is no implicit conversion to NodeTy.
template <class OptionsT, bool IsConst>
struct simplify_type<ilist_iterator<OptionsT, false, IsConst>> {
- typedef ilist_iterator<OptionsT, false, IsConst> iterator;
- typedef typename iterator::pointer SimpleType;
+ using iterator = ilist_iterator<OptionsT, false, IsConst>;
+ using SimpleType = typename iterator::pointer;
static SimpleType getSimplifiedValue(const iterator &Node) { return &*Node; }
};
diff --git a/include/llvm/ADT/ilist_node.h b/include/llvm/ADT/ilist_node.h
index 7244d0f405860..3362611697cb0 100644
--- a/include/llvm/ADT/ilist_node.h
+++ b/include/llvm/ADT/ilist_node.h
@@ -1,4 +1,4 @@
-//==-- llvm/ADT/ilist_node.h - Intrusive Linked List Helper ------*- C++ -*-==//
+//===- llvm/ADT/ilist_node.h - Intrusive Linked List Helper -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -21,11 +21,10 @@
namespace llvm {
namespace ilist_detail {
+
struct NodeAccess;
-} // end namespace ilist_detail
-template<typename NodeTy>
-struct ilist_traits;
+} // end namespace ilist_detail
template <class OptionsT, bool IsReverse, bool IsConst> class ilist_iterator;
template <class OptionsT> class ilist_sentinel;
@@ -39,9 +38,9 @@ template <class OptionsT> class ilist_sentinel;
/// provide type safety: you can't insert nodes of \a ilist_node_impl into the
/// wrong \a simple_ilist or \a iplist.
template <class OptionsT> class ilist_node_impl : OptionsT::node_base_type {
- typedef typename OptionsT::value_type value_type;
- typedef typename OptionsT::node_base_type node_base_type;
- typedef typename OptionsT::list_base_type list_base_type;
+ using value_type = typename OptionsT::value_type;
+ using node_base_type = typename OptionsT::node_base_type;
+ using list_base_type = typename OptionsT::list_base_type;
friend typename OptionsT::list_base_type;
friend struct ilist_detail::NodeAccess;
@@ -52,17 +51,18 @@ template <class OptionsT> class ilist_node_impl : OptionsT::node_base_type {
friend class ilist_iterator<OptionsT, true, true>;
protected:
- ilist_node_impl() = default;
+ using self_iterator = ilist_iterator<OptionsT, false, false>;
+ using const_self_iterator = ilist_iterator<OptionsT, false, true>;
+ using reverse_self_iterator = ilist_iterator<OptionsT, true, false>;
+ using const_reverse_self_iterator = ilist_iterator<OptionsT, true, true>;
- typedef ilist_iterator<OptionsT, false, false> self_iterator;
- typedef ilist_iterator<OptionsT, false, true> const_self_iterator;
- typedef ilist_iterator<OptionsT, true, false> reverse_self_iterator;
- typedef ilist_iterator<OptionsT, true, true> const_reverse_self_iterator;
+ ilist_node_impl() = default;
private:
ilist_node_impl *getPrev() {
return static_cast<ilist_node_impl *>(node_base_type::getPrev());
}
+
ilist_node_impl *getNext() {
return static_cast<ilist_node_impl *>(node_base_type::getNext());
}
@@ -70,6 +70,7 @@ private:
const ilist_node_impl *getPrev() const {
return static_cast<ilist_node_impl *>(node_base_type::getPrev());
}
+
const ilist_node_impl *getNext() const {
return static_cast<ilist_node_impl *>(node_base_type::getNext());
}
@@ -80,9 +81,11 @@ private:
public:
self_iterator getIterator() { return self_iterator(*this); }
const_self_iterator getIterator() const { return const_self_iterator(*this); }
+
reverse_self_iterator getReverseIterator() {
return reverse_self_iterator(*this);
}
+
const_reverse_self_iterator getReverseIterator() const {
return const_reverse_self_iterator(*this);
}
@@ -151,6 +154,7 @@ class ilist_node
};
namespace ilist_detail {
+
/// An access class for ilist_node private API.
///
/// This gives access to the private parts of ilist nodes. Nodes for an ilist
@@ -163,15 +167,18 @@ protected:
static ilist_node_impl<OptionsT> *getNodePtr(typename OptionsT::pointer N) {
return N;
}
+
template <class OptionsT>
static const ilist_node_impl<OptionsT> *
getNodePtr(typename OptionsT::const_pointer N) {
return N;
}
+
template <class OptionsT>
static typename OptionsT::pointer getValuePtr(ilist_node_impl<OptionsT> *N) {
return static_cast<typename OptionsT::pointer>(N);
}
+
template <class OptionsT>
static typename OptionsT::const_pointer
getValuePtr(const ilist_node_impl<OptionsT> *N) {
@@ -182,15 +189,18 @@ protected:
static ilist_node_impl<OptionsT> *getPrev(ilist_node_impl<OptionsT> &N) {
return N.getPrev();
}
+
template <class OptionsT>
static ilist_node_impl<OptionsT> *getNext(ilist_node_impl<OptionsT> &N) {
return N.getNext();
}
+
template <class OptionsT>
static const ilist_node_impl<OptionsT> *
getPrev(const ilist_node_impl<OptionsT> &N) {
return N.getPrev();
}
+
template <class OptionsT>
static const ilist_node_impl<OptionsT> *
getNext(const ilist_node_impl<OptionsT> &N) {
@@ -200,23 +210,27 @@ protected:
template <class OptionsT> struct SpecificNodeAccess : NodeAccess {
protected:
- typedef typename OptionsT::pointer pointer;
- typedef typename OptionsT::const_pointer const_pointer;
- typedef ilist_node_impl<OptionsT> node_type;
+ using pointer = typename OptionsT::pointer;
+ using const_pointer = typename OptionsT::const_pointer;
+ using node_type = ilist_node_impl<OptionsT>;
static node_type *getNodePtr(pointer N) {
return NodeAccess::getNodePtr<OptionsT>(N);
}
+
static const node_type *getNodePtr(const_pointer N) {
return NodeAccess::getNodePtr<OptionsT>(N);
}
+
static pointer getValuePtr(node_type *N) {
return NodeAccess::getValuePtr<OptionsT>(N);
}
+
static const_pointer getValuePtr(const node_type *N) {
return NodeAccess::getValuePtr<OptionsT>(N);
}
};
+
} // end namespace ilist_detail
template <class OptionsT>
@@ -265,6 +279,7 @@ public:
getNodeParent()->*(ParentTy::getSublistAccess((NodeTy *)nullptr));
return List.getPrevNode(*static_cast<NodeTy *>(this));
}
+
/// \brief Get the previous node, or \c nullptr for the list head.
const NodeTy *getPrevNode() const {
return const_cast<ilist_node_with_parent *>(this)->getPrevNode();
@@ -278,6 +293,7 @@ public:
getNodeParent()->*(ParentTy::getSublistAccess((NodeTy *)nullptr));
return List.getNextNode(*static_cast<NodeTy *>(this));
}
+
/// \brief Get the next node, or \c nullptr for the list tail.
const NodeTy *getNextNode() const {
return const_cast<ilist_node_with_parent *>(this)->getNextNode();
@@ -285,6 +301,6 @@ public:
/// @}
};
-} // End llvm namespace
+} // end namespace llvm
-#endif
+#endif // LLVM_ADT_ILIST_NODE_H
diff --git a/include/llvm/ADT/iterator.h b/include/llvm/ADT/iterator.h
index 28dcdf9613ef2..15720a67c047b 100644
--- a/include/llvm/ADT/iterator.h
+++ b/include/llvm/ADT/iterator.h
@@ -11,9 +11,11 @@
#define LLVM_ADT_ITERATOR_H
#include "llvm/ADT/iterator_range.h"
+#include <algorithm>
#include <cstddef>
#include <iterator>
#include <type_traits>
+#include <utility>
namespace llvm {
@@ -206,7 +208,7 @@ template <
class iterator_adaptor_base
: public iterator_facade_base<DerivedT, IteratorCategoryT, T,
DifferenceTypeT, PointerT, ReferenceT> {
- typedef typename iterator_adaptor_base::iterator_facade_base BaseT;
+ using BaseT = typename iterator_adaptor_base::iterator_facade_base;
protected:
WrappedIteratorT I;
@@ -221,7 +223,7 @@ protected:
const WrappedIteratorT &wrapped() const { return I; }
public:
- typedef DifferenceTypeT difference_type;
+ using difference_type = DifferenceTypeT;
DerivedT &operator+=(difference_type n) {
static_assert(
@@ -279,7 +281,7 @@ public:
/// which is implemented with some iterator over T*s:
///
/// \code
-/// typedef pointee_iterator<SmallVectorImpl<T *>::iterator> iterator;
+/// using iterator = pointee_iterator<SmallVectorImpl<T *>::iterator>;
/// \endcode
template <typename WrappedIteratorT,
typename T = typename std::remove_reference<
diff --git a/include/llvm/ADT/simple_ilist.h b/include/llvm/ADT/simple_ilist.h
index a1ab59170840f..4c7598a1acb4e 100644
--- a/include/llvm/ADT/simple_ilist.h
+++ b/include/llvm/ADT/simple_ilist.h
@@ -13,9 +13,14 @@
#include "llvm/ADT/ilist_base.h"
#include "llvm/ADT/ilist_iterator.h"
#include "llvm/ADT/ilist_node.h"
+#include "llvm/ADT/ilist_node_options.h"
+#include "llvm/Support/Compiler.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
+#include <functional>
+#include <iterator>
+#include <utility>
namespace llvm {
@@ -77,23 +82,23 @@ class simple_ilist
typename ilist_detail::compute_node_options<T, Options...>::type> {
static_assert(ilist_detail::check_options<Options...>::value,
"Unrecognized node option!");
- typedef
- typename ilist_detail::compute_node_options<T, Options...>::type OptionsT;
- typedef typename OptionsT::list_base_type list_base_type;
+ using OptionsT =
+ typename ilist_detail::compute_node_options<T, Options...>::type;
+ using list_base_type = typename OptionsT::list_base_type;
ilist_sentinel<OptionsT> Sentinel;
public:
- typedef typename OptionsT::value_type value_type;
- typedef typename OptionsT::pointer pointer;
- typedef typename OptionsT::reference reference;
- typedef typename OptionsT::const_pointer const_pointer;
- typedef typename OptionsT::const_reference const_reference;
- typedef ilist_iterator<OptionsT, false, false> iterator;
- typedef ilist_iterator<OptionsT, false, true> const_iterator;
- typedef ilist_iterator<OptionsT, true, false> reverse_iterator;
- typedef ilist_iterator<OptionsT, true, true> const_reverse_iterator;
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
+ using value_type = typename OptionsT::value_type;
+ using pointer = typename OptionsT::pointer;
+ using reference = typename OptionsT::reference;
+ using const_pointer = typename OptionsT::const_pointer;
+ using const_reference = typename OptionsT::const_reference;
+ using iterator = ilist_iterator<OptionsT, false, false>;
+ using const_iterator = ilist_iterator<OptionsT, false, true>;
+ using reverse_iterator = ilist_iterator<OptionsT, true, false>;
+ using const_reverse_iterator = ilist_iterator<OptionsT, true, true>;
+ using size_type = size_t;
+ using difference_type = ptrdiff_t;
simple_ilist() = default;
~simple_ilist() = default;