Revert "[ADT] Fix some Clang-tidy modernize-use-using warnings; other minor fixes (NFC)."

This reverts commit r303383.

This breaks the modules-enabled macOS build with:

lib/Support/LockFileManager.cpp:86:7: error: declaration of 'gethostuuid' must be imported from module 'Darwin.POSIX.unistd' before it is required

llvm-svn: 303402
This commit is contained in:
Adam Nemet 2017-05-19 02:56:37 +00:00
parent 74639b1900
commit 8967672015
14 changed files with 250 additions and 302 deletions

View File

@ -63,8 +63,8 @@ public:
template <typename T> template <typename T>
class ImmutableList { class ImmutableList {
public: public:
using value_type = T; typedef T value_type;
using Factory = ImmutableListFactory<T>; typedef ImmutableListFactory<T> Factory;
private: private:
const ImmutableListImpl<T>* X; const ImmutableListImpl<T>* X;
@ -141,8 +141,8 @@ public:
template <typename T> template <typename T>
class ImmutableListFactory { class ImmutableListFactory {
using ListTy = ImmutableListImpl<T>; typedef ImmutableListImpl<T> ListTy;
using CacheTy = FoldingSet<ListTy>; typedef FoldingSet<ListTy> CacheTy;
CacheTy Cache; CacheTy Cache;
uintptr_t Allocator; uintptr_t Allocator;

View File

@ -26,12 +26,12 @@ namespace llvm {
/// only the first element (the key) is used by isEqual and isLess. /// only the first element (the key) is used by isEqual and isLess.
template <typename T, typename S> template <typename T, typename S>
struct ImutKeyValueInfo { struct ImutKeyValueInfo {
using value_type = const std::pair<T,S>; typedef const std::pair<T,S> value_type;
using value_type_ref = const value_type&; typedef const value_type& value_type_ref;
using key_type = const T; typedef const T key_type;
using key_type_ref = const T&; typedef const T& key_type_ref;
using data_type = const S; typedef const S data_type;
using data_type_ref = const S&; typedef const S& data_type_ref;
static inline key_type_ref KeyOfValue(value_type_ref V) { static inline key_type_ref KeyOfValue(value_type_ref V) {
return V.first; return V.first;
@ -62,13 +62,13 @@ template <typename KeyT, typename ValT,
typename ValInfo = ImutKeyValueInfo<KeyT,ValT>> typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
class ImmutableMap { class ImmutableMap {
public: public:
using value_type = typename ValInfo::value_type; typedef typename ValInfo::value_type value_type;
using value_type_ref = typename ValInfo::value_type_ref; typedef typename ValInfo::value_type_ref value_type_ref;
using key_type = typename ValInfo::key_type; typedef typename ValInfo::key_type key_type;
using key_type_ref = typename ValInfo::key_type_ref; typedef typename ValInfo::key_type_ref key_type_ref;
using data_type = typename ValInfo::data_type; typedef typename ValInfo::data_type data_type;
using data_type_ref = typename ValInfo::data_type_ref; typedef typename ValInfo::data_type_ref data_type_ref;
using TreeTy = ImutAVLTree<ValInfo>; typedef ImutAVLTree<ValInfo> TreeTy;
protected: protected:
TreeTy* Root; TreeTy* Root;
@ -86,10 +86,6 @@ public:
if (Root) { Root->retain(); } if (Root) { Root->retain(); }
} }
~ImmutableMap() {
if (Root) { Root->release(); }
}
ImmutableMap &operator=(const ImmutableMap &X) { ImmutableMap &operator=(const ImmutableMap &X) {
if (Root != X.Root) { if (Root != X.Root) {
if (X.Root) { X.Root->retain(); } if (X.Root) { X.Root->retain(); }
@ -99,6 +95,10 @@ public:
return *this; return *this;
} }
~ImmutableMap() {
if (Root) { Root->release(); }
}
class Factory { class Factory {
typename TreeTy::Factory F; typename TreeTy::Factory F;
const bool Canonicalize; const bool Canonicalize;
@ -166,14 +166,12 @@ private:
template <typename Callback> template <typename Callback>
struct CBWrapper { struct CBWrapper {
Callback C; Callback C;
void operator()(value_type_ref V) { C(V.first,V.second); } void operator()(value_type_ref V) { C(V.first,V.second); }
}; };
template <typename Callback> template <typename Callback>
struct CBWrapperRef { struct CBWrapperRef {
Callback &C; Callback &C;
CBWrapperRef(Callback& c) : C(c) {} CBWrapperRef(Callback& c) : C(c) {}
void operator()(value_type_ref V) { C(V.first,V.second); } void operator()(value_type_ref V) { C(V.first,V.second); }
@ -256,14 +254,14 @@ template <typename KeyT, typename ValT,
typename ValInfo = ImutKeyValueInfo<KeyT,ValT>> typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
class ImmutableMapRef { class ImmutableMapRef {
public: public:
using value_type = typename ValInfo::value_type; typedef typename ValInfo::value_type value_type;
using value_type_ref = typename ValInfo::value_type_ref; typedef typename ValInfo::value_type_ref value_type_ref;
using key_type = typename ValInfo::key_type; typedef typename ValInfo::key_type key_type;
using key_type_ref = typename ValInfo::key_type_ref; typedef typename ValInfo::key_type_ref key_type_ref;
using data_type = typename ValInfo::data_type; typedef typename ValInfo::data_type data_type;
using data_type_ref = typename ValInfo::data_type_ref; typedef typename ValInfo::data_type_ref data_type_ref;
using TreeTy = ImutAVLTree<ValInfo>; typedef ImutAVLTree<ValInfo> TreeTy;
using FactoryTy = typename TreeTy::Factory; typedef typename TreeTy::Factory FactoryTy;
protected: protected:
TreeTy *Root; TreeTy *Root;
@ -294,11 +292,6 @@ public:
} }
} }
~ImmutableMapRef() {
if (Root)
Root->release();
}
ImmutableMapRef &operator=(const ImmutableMapRef &X) { ImmutableMapRef &operator=(const ImmutableMapRef &X) {
if (Root != X.Root) { if (Root != X.Root) {
if (X.Root) if (X.Root)
@ -313,6 +306,11 @@ public:
return *this; return *this;
} }
~ImmutableMapRef() {
if (Root)
Root->release();
}
static inline ImmutableMapRef getEmptyMap(FactoryTy *F) { static inline ImmutableMapRef getEmptyMap(FactoryTy *F) {
return ImmutableMapRef(0, F); return ImmutableMapRef(0, F);
} }

View File

@ -41,16 +41,18 @@ template <typename ImutInfo> class ImutAVLTreeGenericIterator;
template <typename ImutInfo > template <typename ImutInfo >
class ImutAVLTree { class ImutAVLTree {
public: public:
using key_type_ref = typename ImutInfo::key_type_ref; typedef typename ImutInfo::key_type_ref key_type_ref;
using value_type = typename ImutInfo::value_type; typedef typename ImutInfo::value_type value_type;
using value_type_ref = typename ImutInfo::value_type_ref; typedef typename ImutInfo::value_type_ref value_type_ref;
using Factory = ImutAVLFactory<ImutInfo>;
using iterator = ImutAVLTreeInOrderIterator<ImutInfo>;
typedef ImutAVLFactory<ImutInfo> Factory;
friend class ImutAVLFactory<ImutInfo>; friend class ImutAVLFactory<ImutInfo>;
friend class ImutIntervalAVLFactory<ImutInfo>; friend class ImutIntervalAVLFactory<ImutInfo>;
friend class ImutAVLTreeGenericIterator<ImutInfo>; friend class ImutAVLTreeGenericIterator<ImutInfo>;
typedef ImutAVLTreeInOrderIterator<ImutInfo> iterator;
//===----------------------------------------------------===// //===----------------------------------------------------===//
// Public Interface. // Public Interface.
//===----------------------------------------------------===// //===----------------------------------------------------===//
@ -223,17 +225,17 @@ private:
Factory *factory; Factory *factory;
ImutAVLTree *left; ImutAVLTree *left;
ImutAVLTree *right; ImutAVLTree *right;
ImutAVLTree *prev = nullptr; ImutAVLTree *prev;
ImutAVLTree *next = nullptr; ImutAVLTree *next;
unsigned height : 28; unsigned height : 28;
bool IsMutable : 1; unsigned IsMutable : 1;
bool IsDigestCached : 1; unsigned IsDigestCached : 1;
bool IsCanonicalized : 1; unsigned IsCanonicalized : 1;
value_type value; value_type value;
uint32_t digest = 0; uint32_t digest;
uint32_t refCount = 0; uint32_t refCount;
//===----------------------------------------------------===// //===----------------------------------------------------===//
// Internal methods (node manipulation; used by Factory). // Internal methods (node manipulation; used by Factory).
@ -244,8 +246,9 @@ private:
/// ImutAVLFactory. /// ImutAVLFactory.
ImutAVLTree(Factory *f, ImutAVLTree* l, ImutAVLTree* r, value_type_ref v, ImutAVLTree(Factory *f, ImutAVLTree* l, ImutAVLTree* r, value_type_ref v,
unsigned height) unsigned height)
: factory(f), left(l), right(r), height(height), IsMutable(true), : factory(f), left(l), right(r), prev(nullptr), next(nullptr),
IsDigestCached(false), IsCanonicalized(false), value(v) height(height), IsMutable(true), IsDigestCached(false),
IsCanonicalized(0), value(v), digest(0), refCount(0)
{ {
if (left) left->retain(); if (left) left->retain();
if (right) right->retain(); if (right) right->retain();
@ -366,11 +369,11 @@ public:
template <typename ImutInfo > template <typename ImutInfo >
class ImutAVLFactory { class ImutAVLFactory {
friend class ImutAVLTree<ImutInfo>; 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;
using TreeTy = ImutAVLTree<ImutInfo>; typedef DenseMap<unsigned, TreeTy*> CacheTy;
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; CacheTy Cache;
uintptr_t Allocator; uintptr_t Allocator;
@ -656,7 +659,7 @@ public:
enum VisitFlag { VisitedNone=0x0, VisitedLeft=0x1, VisitedRight=0x3, enum VisitFlag { VisitedNone=0x0, VisitedLeft=0x1, VisitedRight=0x3,
Flags=0x3 }; Flags=0x3 };
using TreeTy = ImutAVLTree<ImutInfo>; typedef ImutAVLTree<ImutInfo> TreeTy;
ImutAVLTreeGenericIterator() = default; ImutAVLTreeGenericIterator() = default;
ImutAVLTreeGenericIterator(const TreeTy *Root) { ImutAVLTreeGenericIterator(const TreeTy *Root) {
@ -761,12 +764,11 @@ template <typename ImutInfo>
class ImutAVLTreeInOrderIterator class ImutAVLTreeInOrderIterator
: public std::iterator<std::bidirectional_iterator_tag, : public std::iterator<std::bidirectional_iterator_tag,
ImutAVLTree<ImutInfo>> { ImutAVLTree<ImutInfo>> {
using InternalIteratorTy = ImutAVLTreeGenericIterator<ImutInfo>; typedef ImutAVLTreeGenericIterator<ImutInfo> InternalIteratorTy;
InternalIteratorTy InternalItr; InternalIteratorTy InternalItr;
public: public:
using TreeTy = ImutAVLTree<ImutInfo>; typedef ImutAVLTree<ImutInfo> TreeTy;
ImutAVLTreeInOrderIterator(const TreeTy* Root) : InternalItr(Root) { ImutAVLTreeInOrderIterator(const TreeTy* Root) : InternalItr(Root) {
if (Root) if (Root)
@ -838,8 +840,8 @@ struct ImutAVLValueIterator
/// and generic handling of pointers is done below. /// and generic handling of pointers is done below.
template <typename T> template <typename T>
struct ImutProfileInfo { struct ImutProfileInfo {
using value_type = const T; typedef const T value_type;
using value_type_ref = const T&; typedef const T& value_type_ref;
static void Profile(FoldingSetNodeID &ID, value_type_ref X) { static void Profile(FoldingSetNodeID &ID, value_type_ref X) {
FoldingSetTrait<T>::Profile(X,ID); FoldingSetTrait<T>::Profile(X,ID);
@ -849,8 +851,8 @@ struct ImutProfileInfo {
/// Profile traits for integers. /// Profile traits for integers.
template <typename T> template <typename T>
struct ImutProfileInteger { struct ImutProfileInteger {
using value_type = const T; typedef const T value_type;
using value_type_ref = const T&; typedef const T& value_type_ref;
static void Profile(FoldingSetNodeID &ID, value_type_ref X) { static void Profile(FoldingSetNodeID &ID, value_type_ref X) {
ID.AddInteger(X); ID.AddInteger(X);
@ -876,8 +878,8 @@ PROFILE_INTEGER_INFO(unsigned long long)
/// Profile traits for booleans. /// Profile traits for booleans.
template <> template <>
struct ImutProfileInfo<bool> { struct ImutProfileInfo<bool> {
using value_type = const bool; typedef const bool value_type;
using value_type_ref = const bool&; typedef const bool& value_type_ref;
static void Profile(FoldingSetNodeID &ID, value_type_ref X) { static void Profile(FoldingSetNodeID &ID, value_type_ref X) {
ID.AddBoolean(X); ID.AddBoolean(X);
@ -888,8 +890,8 @@ struct ImutProfileInfo<bool> {
/// references to unique objects. /// references to unique objects.
template <typename T> template <typename T>
struct ImutProfileInfo<T*> { struct ImutProfileInfo<T*> {
using value_type = const T*; typedef const T* value_type;
using value_type_ref = value_type; typedef value_type value_type_ref;
static void Profile(FoldingSetNodeID &ID, value_type_ref X) { static void Profile(FoldingSetNodeID &ID, value_type_ref X) {
ID.AddPointer(X); ID.AddPointer(X);
@ -908,12 +910,12 @@ struct ImutProfileInfo<T*> {
/// std::equal_to<> and std::less<> to perform comparison of elements. /// std::equal_to<> and std::less<> to perform comparison of elements.
template <typename T> template <typename T>
struct ImutContainerInfo : public ImutProfileInfo<T> { struct ImutContainerInfo : public ImutProfileInfo<T> {
using value_type = typename ImutProfileInfo<T>::value_type; typedef typename ImutProfileInfo<T>::value_type value_type;
using value_type_ref = typename ImutProfileInfo<T>::value_type_ref; typedef typename ImutProfileInfo<T>::value_type_ref value_type_ref;
using key_type = value_type; typedef value_type key_type;
using key_type_ref = value_type_ref; typedef value_type_ref key_type_ref;
using data_type = bool; typedef bool data_type;
using data_type_ref = bool; typedef bool data_type_ref;
static key_type_ref KeyOfValue(value_type_ref D) { return D; } static key_type_ref KeyOfValue(value_type_ref D) { return D; }
static data_type_ref DataOfValue(value_type_ref) { return true; } static data_type_ref DataOfValue(value_type_ref) { return true; }
@ -934,12 +936,12 @@ struct ImutContainerInfo : public ImutProfileInfo<T> {
/// their addresses. /// their addresses.
template <typename T> template <typename T>
struct ImutContainerInfo<T*> : public ImutProfileInfo<T*> { struct ImutContainerInfo<T*> : public ImutProfileInfo<T*> {
using value_type = typename ImutProfileInfo<T*>::value_type; typedef typename ImutProfileInfo<T*>::value_type value_type;
using value_type_ref = typename ImutProfileInfo<T*>::value_type_ref; typedef typename ImutProfileInfo<T*>::value_type_ref value_type_ref;
using key_type = value_type; typedef value_type key_type;
using key_type_ref = value_type_ref; typedef value_type_ref key_type_ref;
using data_type = bool; typedef bool data_type;
using data_type_ref = bool; typedef bool data_type_ref;
static key_type_ref KeyOfValue(value_type_ref D) { return D; } static key_type_ref KeyOfValue(value_type_ref D) { return D; }
static data_type_ref DataOfValue(value_type_ref) { return true; } static data_type_ref DataOfValue(value_type_ref) { return true; }
@ -958,9 +960,9 @@ struct ImutContainerInfo<T*> : public ImutProfileInfo<T*> {
template <typename ValT, typename ValInfo = ImutContainerInfo<ValT>> template <typename ValT, typename ValInfo = ImutContainerInfo<ValT>>
class ImmutableSet { class ImmutableSet {
public: public:
using value_type = typename ValInfo::value_type; typedef typename ValInfo::value_type value_type;
using value_type_ref = typename ValInfo::value_type_ref; typedef typename ValInfo::value_type_ref value_type_ref;
using TreeTy = ImutAVLTree<ValInfo>; typedef ImutAVLTree<ValInfo> TreeTy;
private: private:
TreeTy *Root; TreeTy *Root;
@ -978,10 +980,6 @@ public:
if (Root) { Root->retain(); } if (Root) { Root->retain(); }
} }
~ImmutableSet() {
if (Root) { Root->release(); }
}
ImmutableSet &operator=(const ImmutableSet &X) { ImmutableSet &operator=(const ImmutableSet &X) {
if (Root != X.Root) { if (Root != X.Root) {
if (X.Root) { X.Root->retain(); } if (X.Root) { X.Root->retain(); }
@ -991,6 +989,10 @@ public:
return *this; return *this;
} }
~ImmutableSet() {
if (Root) { Root->release(); }
}
class Factory { class Factory {
typename TreeTy::Factory F; typename TreeTy::Factory F;
const bool Canonicalize; const bool Canonicalize;
@ -1082,7 +1084,7 @@ public:
// Iterators. // Iterators.
//===--------------------------------------------------===// //===--------------------------------------------------===//
using iterator = ImutAVLValueIterator<ImmutableSet>; typedef ImutAVLValueIterator<ImmutableSet> iterator;
iterator begin() const { return iterator(Root); } iterator begin() const { return iterator(Root); }
iterator end() const { return iterator(); } iterator end() const { return iterator(); }
@ -1110,10 +1112,10 @@ public:
template <typename ValT, typename ValInfo = ImutContainerInfo<ValT>> template <typename ValT, typename ValInfo = ImutContainerInfo<ValT>>
class ImmutableSetRef { class ImmutableSetRef {
public: public:
using value_type = typename ValInfo::value_type; typedef typename ValInfo::value_type value_type;
using value_type_ref = typename ValInfo::value_type_ref; typedef typename ValInfo::value_type_ref value_type_ref;
using TreeTy = ImutAVLTree<ValInfo>; typedef ImutAVLTree<ValInfo> TreeTy;
using FactoryTy = typename TreeTy::Factory; typedef typename TreeTy::Factory FactoryTy;
private: private:
TreeTy *Root; TreeTy *Root;
@ -1136,10 +1138,6 @@ public:
if (Root) { Root->retain(); } if (Root) { Root->retain(); }
} }
~ImmutableSetRef() {
if (Root) { Root->release(); }
}
ImmutableSetRef &operator=(const ImmutableSetRef &X) { ImmutableSetRef &operator=(const ImmutableSetRef &X) {
if (Root != X.Root) { if (Root != X.Root) {
if (X.Root) { X.Root->retain(); } if (X.Root) { X.Root->retain(); }
@ -1149,6 +1147,9 @@ public:
} }
return *this; return *this;
} }
~ImmutableSetRef() {
if (Root) { Root->release(); }
}
static ImmutableSetRef getEmptySet(FactoryTy *F) { static ImmutableSetRef getEmptySet(FactoryTy *F) {
return ImmutableSetRef(0, F); return ImmutableSetRef(0, F);
@ -1195,7 +1196,7 @@ public:
// Iterators. // Iterators.
//===--------------------------------------------------===// //===--------------------------------------------------===//
using iterator = ImutAVLValueIterator<ImmutableSetRef>; typedef ImutAVLValueIterator<ImmutableSetRef> iterator;
iterator begin() const { return iterator(Root); } iterator begin() const { return iterator(Root); }
iterator end() const { return iterator(); } iterator end() const { return iterator(); }

View File

@ -23,25 +23,25 @@
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include <cassert> #include <cassert>
#include <functional>
namespace llvm { namespace llvm {
template <typename T, typename ToIndexT = identity<unsigned>> template <typename T, typename ToIndexT = llvm::identity<unsigned> >
class IndexedMap { class IndexedMap {
using IndexT = typename ToIndexT::argument_type; typedef typename ToIndexT::argument_type IndexT;
// Prefer SmallVector with zero inline storage over std::vector. IndexedMaps // Prefer SmallVector with zero inline storage over std::vector. IndexedMaps
// can grow very large and SmallVector grows more efficiently as long as T // can grow very large and SmallVector grows more efficiently as long as T
// is trivially copyable. // is trivially copyable.
using StorageT = SmallVector<T, 0>; typedef SmallVector<T, 0> StorageT;
StorageT storage_; StorageT storage_;
T nullVal_; T nullVal_;
ToIndexT toIndex_; ToIndexT toIndex_;
public: 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) { typename StorageT::reference operator[](IndexT n) {
assert(toIndex_(n) < storage_.size() && "index out of bounds!"); assert(toIndex_(n) < storage_.size() && "index out of bounds!");
@ -80,6 +80,6 @@ template <typename T, typename ToIndexT = identity<unsigned>>
} }
}; };
} // end namespace llvm } // End llvm namespace
#endif // LLVM_ADT_INDEXEDMAP_H #endif

View File

@ -106,7 +106,6 @@
#include "llvm/Support/RecyclingAllocator.h" #include "llvm/Support/RecyclingAllocator.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cstdint>
#include <iterator> #include <iterator>
#include <new> #include <new>
#include <utility> #include <utility>
@ -187,7 +186,7 @@ struct IntervalMapHalfOpenInfo {
/// It should be considered private to the implementation. /// It should be considered private to the implementation.
namespace IntervalMapImpl { namespace IntervalMapImpl {
using IdxPair = std::pair<unsigned,unsigned>; typedef std::pair<unsigned,unsigned> IdxPair;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
//--- IntervalMapImpl::NodeBase ---// //--- IntervalMapImpl::NodeBase ---//
@ -446,7 +445,7 @@ struct NodeSizer {
LeafSize = DesiredLeafSize > MinLeafSize ? DesiredLeafSize : MinLeafSize LeafSize = DesiredLeafSize > MinLeafSize ? DesiredLeafSize : MinLeafSize
}; };
using LeafBase = NodeBase<std::pair<KeyT, KeyT>, ValT, LeafSize>; typedef NodeBase<std::pair<KeyT, KeyT>, ValT, LeafSize> LeafBase;
enum { enum {
// Now that we have the leaf branching factor, compute the actual allocation // Now that we have the leaf branching factor, compute the actual allocation
@ -462,8 +461,8 @@ struct NodeSizer {
/// This typedef is very likely to be identical for all IntervalMaps with /// This typedef is very likely to be identical for all IntervalMaps with
/// reasonably sized entries, so the same allocator can be shared among /// reasonably sized entries, so the same allocator can be shared among
/// different kinds of maps. /// different kinds of maps.
using Allocator = typedef RecyclingAllocator<BumpPtrAllocator, char,
RecyclingAllocator<BumpPtrAllocator, char, AllocBytes, CacheLineBytes>; AllocBytes, CacheLineBytes> Allocator;
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -931,12 +930,12 @@ template <typename KeyT, typename ValT,
unsigned N = IntervalMapImpl::NodeSizer<KeyT, ValT>::LeafSize, unsigned N = IntervalMapImpl::NodeSizer<KeyT, ValT>::LeafSize,
typename Traits = IntervalMapInfo<KeyT>> typename Traits = IntervalMapInfo<KeyT>>
class IntervalMap { class IntervalMap {
using Sizer = IntervalMapImpl::NodeSizer<KeyT, ValT>; typedef IntervalMapImpl::NodeSizer<KeyT, ValT> Sizer;
using Leaf = IntervalMapImpl::LeafNode<KeyT, ValT, Sizer::LeafSize, Traits>; typedef IntervalMapImpl::LeafNode<KeyT, ValT, Sizer::LeafSize, Traits> Leaf;
using Branch = typedef IntervalMapImpl::BranchNode<KeyT, ValT, Sizer::BranchSize, Traits>
IntervalMapImpl::BranchNode<KeyT, ValT, Sizer::BranchSize, Traits>; Branch;
using RootLeaf = IntervalMapImpl::LeafNode<KeyT, ValT, N, Traits>; typedef IntervalMapImpl::LeafNode<KeyT, ValT, N, Traits> RootLeaf;
using IdxPair = IntervalMapImpl::IdxPair; typedef IntervalMapImpl::IdxPair IdxPair;
// The RootLeaf capacity is given as a template parameter. We must compute the // The RootLeaf capacity is given as a template parameter. We must compute the
// corresponding RootBranch capacity. // corresponding RootBranch capacity.
@ -946,8 +945,8 @@ class IntervalMap {
RootBranchCap = DesiredRootBranchCap ? DesiredRootBranchCap : 1 RootBranchCap = DesiredRootBranchCap ? DesiredRootBranchCap : 1
}; };
using RootBranch = typedef IntervalMapImpl::BranchNode<KeyT, ValT, RootBranchCap, Traits>
IntervalMapImpl::BranchNode<KeyT, ValT, RootBranchCap, Traits>; RootBranch;
// When branched, we store a global start key as well as the branch node. // When branched, we store a global start key as well as the branch node.
struct RootBranchData { struct RootBranchData {
@ -956,10 +955,10 @@ class IntervalMap {
}; };
public: public:
using Allocator = typename Sizer::Allocator; typedef typename Sizer::Allocator Allocator;
using KeyType = KeyT; typedef KeyT KeyType;
using ValueType = ValT; typedef ValT ValueType;
using KeyTraits = Traits; typedef Traits KeyTraits;
private: private:
// The root data is either a RootLeaf or a RootBranchData instance. // The root data is either a RootLeaf or a RootBranchData instance.
@ -1291,7 +1290,7 @@ protected:
friend class IntervalMap; friend class IntervalMap;
// The map referred to. // The map referred to.
IntervalMap *map = nullptr; IntervalMap *map;
// We store a full path from the root to the current position. // We store a full path from the root to the current position.
// The path may be partially filled, but never between iterator calls. // The path may be partially filled, but never between iterator calls.
@ -1339,7 +1338,7 @@ protected:
public: public:
/// const_iterator - Create an iterator that isn't pointing anywhere. /// const_iterator - Create an iterator that isn't pointing anywhere.
const_iterator() = default; const_iterator() : map(nullptr) {}
/// setMap - Change the map iterated over. This call must be followed by a /// setMap - Change the map iterated over. This call must be followed by a
/// call to goToBegin(), goToEnd(), or find() /// call to goToBegin(), goToEnd(), or find()
@ -1510,8 +1509,7 @@ const_iterator::treeAdvanceTo(KeyT x) {
template <typename KeyT, typename ValT, unsigned N, typename Traits> template <typename KeyT, typename ValT, unsigned N, typename Traits>
class IntervalMap<KeyT, ValT, N, Traits>::iterator : public const_iterator { class IntervalMap<KeyT, ValT, N, Traits>::iterator : public const_iterator {
friend class IntervalMap; friend class IntervalMap;
typedef IntervalMapImpl::IdxPair IdxPair;
using IdxPair = IntervalMapImpl::IdxPair;
explicit iterator(IntervalMap &map) : const_iterator(map) {} explicit iterator(IntervalMap &map) : const_iterator(map) {}
@ -2005,7 +2003,7 @@ iterator::overflow(unsigned Level) {
// Elements have been rearranged, now update node sizes and stops. // Elements have been rearranged, now update node sizes and stops.
bool SplitRoot = false; bool SplitRoot = false;
unsigned Pos = 0; unsigned Pos = 0;
while (true) { for (;;) {
KeyT Stop = Node[Pos]->stop(NewSize[Pos]-1); KeyT Stop = Node[Pos]->stop(NewSize[Pos]-1);
if (NewNode && Pos == NewNode) { if (NewNode && Pos == NewNode) {
SplitRoot = insertNode(Level, NodeRef(Node[Pos], NewSize[Pos]), Stop); SplitRoot = insertNode(Level, NodeRef(Node[Pos], NewSize[Pos]), Stop);
@ -2047,9 +2045,8 @@ iterator::overflow(unsigned Level) {
/// ///
template <typename MapA, typename MapB> template <typename MapA, typename MapB>
class IntervalMapOverlaps { class IntervalMapOverlaps {
using KeyType = typename MapA::KeyType; typedef typename MapA::KeyType KeyType;
using Traits = typename MapA::KeyTraits; typedef typename MapA::KeyTraits Traits;
typename MapA::const_iterator posA; typename MapA::const_iterator posA;
typename MapB::const_iterator posB; typename MapB::const_iterator posB;
@ -2074,7 +2071,7 @@ class IntervalMapOverlaps {
// Already overlapping. // Already overlapping.
return; return;
while (true) { for (;;) {
// Make a.end > b.start. // Make a.end > b.start.
posA.advanceTo(posB.start()); posA.advanceTo(posB.start());
if (!posA.valid() || !Traits::stopLess(posB.stop(), posA.start())) if (!posA.valid() || !Traits::stopLess(posB.stop(), posA.start()))

View File

@ -1,4 +1,4 @@
//==- llvm/ADT/IntrusiveRefCntPtr.h - Smart Refcounting Pointer --*- C++ -*-==// //== llvm/ADT/IntrusiveRefCntPtr.h - Smart Refcounting Pointer ---*- C++ -*-==//
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
// //
@ -73,10 +73,9 @@ template <class Derived> class RefCountedBase {
public: public:
RefCountedBase() = default; RefCountedBase() = default;
RefCountedBase(const RefCountedBase &) {} RefCountedBase(const RefCountedBase &) : RefCount(0) {}
void Retain() const { ++RefCount; } void Retain() const { ++RefCount; }
void Release() const { void Release() const {
assert(RefCount > 0 && "Reference count is already zero."); assert(RefCount > 0 && "Reference count is already zero.");
if (--RefCount == 0) if (--RefCount == 0)
@ -137,7 +136,7 @@ template <typename T> class IntrusiveRefCntPtr {
T *Obj = nullptr; T *Obj = nullptr;
public: public:
using element_type = T; typedef T element_type;
explicit IntrusiveRefCntPtr() = default; explicit IntrusiveRefCntPtr() = default;
IntrusiveRefCntPtr(T *obj) : Obj(obj) { retain(); } IntrusiveRefCntPtr(T *obj) : Obj(obj) { retain(); }
@ -154,13 +153,13 @@ public:
retain(); retain();
} }
~IntrusiveRefCntPtr() { release(); }
IntrusiveRefCntPtr &operator=(IntrusiveRefCntPtr S) { IntrusiveRefCntPtr &operator=(IntrusiveRefCntPtr S) {
swap(S); swap(S);
return *this; return *this;
} }
~IntrusiveRefCntPtr() { release(); }
T &operator*() const { return *Obj; } T &operator*() const { return *Obj; }
T *operator->() const { return Obj; } T *operator->() const { return Obj; }
T *get() const { return Obj; } T *get() const { return Obj; }
@ -184,7 +183,6 @@ private:
if (Obj) if (Obj)
IntrusiveRefCntPtrInfo<T>::retain(Obj); IntrusiveRefCntPtrInfo<T>::retain(Obj);
} }
void release() { void release() {
if (Obj) if (Obj)
IntrusiveRefCntPtrInfo<T>::release(Obj); IntrusiveRefCntPtrInfo<T>::release(Obj);
@ -250,16 +248,14 @@ bool operator!=(const IntrusiveRefCntPtr<T> &A, std::nullptr_t B) {
template <typename From> struct simplify_type; template <typename From> struct simplify_type;
template <class T> struct simplify_type<IntrusiveRefCntPtr<T>> { template <class T> struct simplify_type<IntrusiveRefCntPtr<T>> {
using SimpleType = T *; typedef T *SimpleType;
static SimpleType getSimplifiedValue(IntrusiveRefCntPtr<T> &Val) { static SimpleType getSimplifiedValue(IntrusiveRefCntPtr<T> &Val) {
return Val.get(); return Val.get();
} }
}; };
template <class T> struct simplify_type<const IntrusiveRefCntPtr<T>> { template <class T> struct simplify_type<const IntrusiveRefCntPtr<T>> {
using SimpleType = /*const*/ T *; typedef /*const*/ T *SimpleType;
static SimpleType getSimplifiedValue(const IntrusiveRefCntPtr<T> &Val) { static SimpleType getSimplifiedValue(const IntrusiveRefCntPtr<T> &Val) {
return Val.get(); return Val.get();
} }

View File

@ -19,12 +19,6 @@
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <iterator>
#include <type_traits>
#include <utility>
#include <vector> #include <vector>
namespace llvm { namespace llvm {
@ -33,20 +27,20 @@ namespace llvm {
/// in a deterministic order. The values are kept in a std::vector and the /// 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. /// mapping is done with DenseMap from Keys to indexes in that vector.
template<typename KeyT, typename ValueT, template<typename KeyT, typename ValueT,
typename MapType = DenseMap<KeyT, unsigned>, typename MapType = llvm::DenseMap<KeyT, unsigned>,
typename VectorType = std::vector<std::pair<KeyT, ValueT>>> typename VectorType = std::vector<std::pair<KeyT, ValueT> > >
class MapVector { class MapVector {
using value_type = typename VectorType::value_type; typedef typename VectorType::value_type value_type;
using size_type = typename VectorType::size_type; typedef typename VectorType::size_type size_type;
MapType Map; MapType Map;
VectorType Vector; VectorType Vector;
public: public:
using iterator = typename VectorType::iterator; typedef typename VectorType::iterator iterator;
using const_iterator = typename VectorType::const_iterator; typedef typename VectorType::const_iterator const_iterator;
using reverse_iterator = typename VectorType::reverse_iterator; typedef typename VectorType::reverse_iterator reverse_iterator;
using const_reverse_iterator = typename VectorType::const_reverse_iterator; typedef typename VectorType::const_reverse_iterator const_reverse_iterator;
/// Clear the MapVector and return the underlying vector. /// Clear the MapVector and return the underlying vector.
VectorType takeVector() { VectorType takeVector() {
@ -226,4 +220,4 @@ struct SmallMapVector
} // end namespace llvm } // end namespace llvm
#endif // LLVM_ADT_MAPVECTOR_H #endif

View File

@ -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 // The LLVM Compiler Infrastructure
// //
@ -19,8 +19,6 @@
#include "llvm/ADT/None.h" #include "llvm/ADT/None.h"
#include "llvm/Support/AlignOf.h" #include "llvm/Support/AlignOf.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/type_traits.h"
#include <algorithm>
#include <cassert> #include <cassert>
#include <new> #include <new>
#include <utility> #include <utility>
@ -30,18 +28,15 @@ namespace llvm {
template<typename T> template<typename T>
class Optional { class Optional {
AlignedCharArrayUnion<T> storage; AlignedCharArrayUnion<T> storage;
bool hasVal = false; bool hasVal;
public: public:
using value_type = T; typedef T value_type;
Optional(NoneType) {}
explicit Optional() {}
Optional(NoneType) : hasVal(false) {}
explicit Optional() : hasVal(false) {}
Optional(const T &y) : hasVal(true) { Optional(const T &y) : hasVal(true) {
new (storage.buffer) T(y); new (storage.buffer) T(y);
} }
Optional(const Optional &O) : hasVal(O.hasVal) { Optional(const Optional &O) : hasVal(O.hasVal) {
if (hasVal) if (hasVal)
new (storage.buffer) T(*O); new (storage.buffer) T(*O);
@ -50,18 +45,12 @@ public:
Optional(T &&y) : hasVal(true) { Optional(T &&y) : hasVal(true) {
new (storage.buffer) T(std::forward<T>(y)); new (storage.buffer) T(std::forward<T>(y));
} }
Optional(Optional<T> &&O) : hasVal(O) { Optional(Optional<T> &&O) : hasVal(O) {
if (O) { if (O) {
new (storage.buffer) T(std::move(*O)); new (storage.buffer) T(std::move(*O));
O.reset(); O.reset();
} }
} }
~Optional() {
reset();
}
Optional &operator=(T &&y) { Optional &operator=(T &&y) {
if (hasVal) if (hasVal)
**this = std::move(y); **this = std::move(y);
@ -71,7 +60,6 @@ public:
} }
return *this; return *this;
} }
Optional &operator=(Optional &&O) { Optional &operator=(Optional &&O) {
if (!O) if (!O)
reset(); reset();
@ -124,6 +112,10 @@ public:
} }
} }
~Optional() {
reset();
}
const T* getPointer() const { assert(hasVal); return reinterpret_cast<const T*>(storage.buffer); } const T* getPointer() const { assert(hasVal); return reinterpret_cast<const T*>(storage.buffer); }
T* getPointer() { assert(hasVal); return reinterpret_cast<T*>(storage.buffer); } T* getPointer() { assert(hasVal); return reinterpret_cast<T*>(storage.buffer); }
const T& getValue() const LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); } const T& getValue() const LLVM_LVALUE_FUNCTION { assert(hasVal); return *getPointer(); }
@ -152,7 +144,8 @@ public:
#endif #endif
}; };
template <typename T> struct isPodLike<Optional<T>> { template <typename T> struct isPodLike;
template <typename T> struct isPodLike<Optional<T> > {
// An Optional<T> is pod-like if T is. // An Optional<T> is pod-like if T is.
static const bool value = isPodLike<T>::value; static const bool value = isPodLike<T>::value;
}; };
@ -291,6 +284,6 @@ template <typename T> bool operator>=(const T &X, const Optional<T> &Y) {
return !(X < Y); return !(X < Y);
} }
} // end namespace llvm } // end llvm namespace
#endif // LLVM_ADT_OPTIONAL_H #endif

View File

@ -76,8 +76,8 @@ template <typename T, unsigned BitNum, typename BitVectorTy = BitVector>
class PackedVector : public PackedVectorBase<T, BitNum, BitVectorTy, class PackedVector : public PackedVectorBase<T, BitNum, BitVectorTy,
std::numeric_limits<T>::is_signed> { std::numeric_limits<T>::is_signed> {
BitVectorTy Bits; BitVectorTy Bits;
using base = PackedVectorBase<T, BitNum, BitVectorTy, typedef PackedVectorBase<T, BitNum, BitVectorTy,
std::numeric_limits<T>::is_signed>; std::numeric_limits<T>::is_signed> base;
public: public:
class reference { class reference {
@ -99,7 +99,7 @@ public:
}; };
PackedVector() = default; PackedVector() = default;
explicit PackedVector(unsigned size) : Bits(size << (BitNum-1)) {} explicit PackedVector(unsigned size) : Bits(size << (BitNum-1)) { }
bool empty() const { return Bits.empty(); } bool empty() const { return Bits.empty(); }

View File

@ -13,10 +13,7 @@
#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/MathExtras.h" #include "llvm/Support/MathExtras.h"
#include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/PointerLikeTypeTraits.h"
#include <cassert>
#include <climits> #include <climits>
#include <cstdint>
#include <type_traits>
namespace llvm { namespace llvm {
@ -32,7 +29,7 @@ namespace llvm {
/// Also, the default constructed value zero initializes the integer. /// Also, the default constructed value zero initializes the integer.
template <typename IntT, int Bits = sizeof(IntT) * CHAR_BIT> template <typename IntT, int Bits = sizeof(IntT) * CHAR_BIT>
class PointerEmbeddedInt { class PointerEmbeddedInt {
uintptr_t Value = 0; uintptr_t Value;
// Note: This '<' is correct; using '<=' would result in some shifts // Note: This '<' is correct; using '<=' would result in some shifts
// overflowing their storage types. // overflowing their storage types.
@ -57,12 +54,15 @@ class PointerEmbeddedInt {
explicit PointerEmbeddedInt(uintptr_t Value, RawValueTag) : Value(Value) {} explicit PointerEmbeddedInt(uintptr_t Value, RawValueTag) : Value(Value) {}
public: public:
PointerEmbeddedInt() = default; PointerEmbeddedInt() : Value(0) {}
PointerEmbeddedInt(IntT I) { *this = I; } PointerEmbeddedInt(IntT I) {
*this = I;
}
PointerEmbeddedInt &operator=(IntT I) { PointerEmbeddedInt &operator=(IntT I) {
assert((std::is_signed<IntT>::value ? isInt<Bits>(I) : isUInt<Bits>(I)) && assert((std::is_signed<IntT>::value ? llvm::isInt<Bits>(I)
: llvm::isUInt<Bits>(I)) &&
"Integer has bits outside those preserved!"); "Integer has bits outside those preserved!");
Value = static_cast<uintptr_t>(I) << Shift; Value = static_cast<uintptr_t>(I) << Shift;
return *this; return *this;
@ -81,17 +81,15 @@ public:
// types. // types.
template <typename IntT, int Bits> template <typename IntT, int Bits>
class PointerLikeTypeTraits<PointerEmbeddedInt<IntT, Bits>> { class PointerLikeTypeTraits<PointerEmbeddedInt<IntT, Bits>> {
using T = PointerEmbeddedInt<IntT, Bits>; typedef PointerEmbeddedInt<IntT, Bits> T;
public: public:
static inline void *getAsVoidPointer(const T &P) { static inline void *getAsVoidPointer(const T &P) {
return reinterpret_cast<void *>(P.Value); return reinterpret_cast<void *>(P.Value);
} }
static inline T getFromVoidPointer(void *P) { static inline T getFromVoidPointer(void *P) {
return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag()); return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag());
} }
static inline T getFromVoidPointer(const void *P) { static inline T getFromVoidPointer(const void *P) {
return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag()); return T(reinterpret_cast<uintptr_t>(P), typename T::RawValueTag());
} }
@ -103,19 +101,17 @@ public:
// itself can be a key. // itself can be a key.
template <typename IntT, int Bits> template <typename IntT, int Bits>
struct DenseMapInfo<PointerEmbeddedInt<IntT, Bits>> { struct DenseMapInfo<PointerEmbeddedInt<IntT, Bits>> {
using T = PointerEmbeddedInt<IntT, Bits>; typedef PointerEmbeddedInt<IntT, Bits> T;
using IntInfo = DenseMapInfo<IntT>;
typedef DenseMapInfo<IntT> IntInfo;
static inline T getEmptyKey() { return IntInfo::getEmptyKey(); } static inline T getEmptyKey() { return IntInfo::getEmptyKey(); }
static inline T getTombstoneKey() { return IntInfo::getTombstoneKey(); } static inline T getTombstoneKey() { return IntInfo::getTombstoneKey(); }
static unsigned getHashValue(const T &Arg) { static unsigned getHashValue(const T &Arg) {
return IntInfo::getHashValue(Arg); return IntInfo::getHashValue(Arg);
} }
static bool isEqual(const T &LHS, const T &RHS) { return LHS == RHS; } static bool isEqual(const T &LHS, const T &RHS) { return LHS == RHS; }
}; };
}
} // end namespace llvm #endif
#endif // LLVM_ADT_POINTEREMBEDDEDINT_H

View File

@ -14,9 +14,9 @@
#ifndef LLVM_ADT_POINTERINTPAIR_H #ifndef LLVM_ADT_POINTERINTPAIR_H
#define LLVM_ADT_POINTERINTPAIR_H #define LLVM_ADT_POINTERINTPAIR_H
#include "llvm/Support/Compiler.h"
#include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/PointerLikeTypeTraits.h"
#include <cassert> #include <cassert>
#include <cstdint>
#include <limits> #include <limits>
namespace llvm { namespace llvm {
@ -44,20 +44,20 @@ template <typename PointerTy, unsigned IntBits, typename IntType = unsigned,
typename PtrTraits = PointerLikeTypeTraits<PointerTy>, typename PtrTraits = PointerLikeTypeTraits<PointerTy>,
typename Info = PointerIntPairInfo<PointerTy, IntBits, PtrTraits>> typename Info = PointerIntPairInfo<PointerTy, IntBits, PtrTraits>>
class PointerIntPair { class PointerIntPair {
intptr_t Value = 0; intptr_t Value;
public: public:
PointerIntPair() = default; PointerIntPair() : Value(0) {}
PointerIntPair(PointerTy PtrVal, IntType IntVal) { PointerIntPair(PointerTy PtrVal, IntType IntVal) {
setPointerAndInt(PtrVal, IntVal); setPointerAndInt(PtrVal, IntVal);
} }
explicit PointerIntPair(PointerTy PtrVal) { initWithPointer(PtrVal); } explicit PointerIntPair(PointerTy PtrVal) { initWithPointer(PtrVal); }
PointerTy getPointer() const { return Info::getPointer(Value); } PointerTy getPointer() const { return Info::getPointer(Value); }
IntType getInt() const { return (IntType)Info::getInt(Value); } IntType getInt() const {
return (IntType)Info::getInt(Value);
}
void setPointer(PointerTy PtrVal) { void setPointer(PointerTy PtrVal) {
Value = Info::updatePointer(Value, PtrVal); Value = Info::updatePointer(Value, PtrVal);
@ -88,7 +88,6 @@ public:
} }
void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); } void *getOpaqueValue() const { return reinterpret_cast<void *>(Value); }
void setFromOpaqueValue(void *Val) { void setFromOpaqueValue(void *Val) {
Value = reinterpret_cast<intptr_t>(Val); Value = reinterpret_cast<intptr_t>(Val);
} }
@ -109,18 +108,14 @@ public:
bool operator==(const PointerIntPair &RHS) const { bool operator==(const PointerIntPair &RHS) const {
return Value == RHS.Value; return Value == RHS.Value;
} }
bool operator!=(const PointerIntPair &RHS) const { bool operator!=(const PointerIntPair &RHS) const {
return Value != RHS.Value; return Value != RHS.Value;
} }
bool operator<(const PointerIntPair &RHS) const { return Value < RHS.Value; } bool operator<(const PointerIntPair &RHS) const { return Value < RHS.Value; }
bool operator>(const PointerIntPair &RHS) const { return Value > RHS.Value; } bool operator>(const PointerIntPair &RHS) const { return Value > RHS.Value; }
bool operator<=(const PointerIntPair &RHS) const { bool operator<=(const PointerIntPair &RHS) const {
return Value <= RHS.Value; return Value <= RHS.Value;
} }
bool operator>=(const PointerIntPair &RHS) const { bool operator>=(const PointerIntPair &RHS) const {
return Value >= RHS.Value; return Value >= RHS.Value;
} }
@ -185,25 +180,21 @@ struct isPodLike<PointerIntPair<PointerTy, IntBits, IntType>> {
// Provide specialization of DenseMapInfo for PointerIntPair. // Provide specialization of DenseMapInfo for PointerIntPair.
template <typename PointerTy, unsigned IntBits, typename IntType> template <typename PointerTy, unsigned IntBits, typename IntType>
struct DenseMapInfo<PointerIntPair<PointerTy, IntBits, IntType>> { struct DenseMapInfo<PointerIntPair<PointerTy, IntBits, IntType>> {
using Ty = PointerIntPair<PointerTy, IntBits, IntType>; typedef PointerIntPair<PointerTy, IntBits, IntType> Ty;
static Ty getEmptyKey() { static Ty getEmptyKey() {
uintptr_t Val = static_cast<uintptr_t>(-1); uintptr_t Val = static_cast<uintptr_t>(-1);
Val <<= PointerLikeTypeTraits<Ty>::NumLowBitsAvailable; Val <<= PointerLikeTypeTraits<Ty>::NumLowBitsAvailable;
return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val)); return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val));
} }
static Ty getTombstoneKey() { static Ty getTombstoneKey() {
uintptr_t Val = static_cast<uintptr_t>(-2); uintptr_t Val = static_cast<uintptr_t>(-2);
Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable; Val <<= PointerLikeTypeTraits<PointerTy>::NumLowBitsAvailable;
return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val)); return Ty::getFromOpaqueValue(reinterpret_cast<void *>(Val));
} }
static unsigned getHashValue(Ty V) { static unsigned getHashValue(Ty V) {
uintptr_t IV = reinterpret_cast<uintptr_t>(V.getOpaqueValue()); uintptr_t IV = reinterpret_cast<uintptr_t>(V.getOpaqueValue());
return unsigned(IV) ^ unsigned(IV >> 9); return unsigned(IV) ^ unsigned(IV >> 9);
} }
static bool isEqual(const Ty &LHS, const Ty &RHS) { return LHS == RHS; } static bool isEqual(const Ty &LHS, const Ty &RHS) { return LHS == RHS; }
}; };
@ -217,20 +208,16 @@ public:
getAsVoidPointer(const PointerIntPair<PointerTy, IntBits, IntType> &P) { getAsVoidPointer(const PointerIntPair<PointerTy, IntBits, IntType> &P) {
return P.getOpaqueValue(); return P.getOpaqueValue();
} }
static inline PointerIntPair<PointerTy, IntBits, IntType> static inline PointerIntPair<PointerTy, IntBits, IntType>
getFromVoidPointer(void *P) { getFromVoidPointer(void *P) {
return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P); return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P);
} }
static inline PointerIntPair<PointerTy, IntBits, IntType> static inline PointerIntPair<PointerTy, IntBits, IntType>
getFromVoidPointer(const void *P) { getFromVoidPointer(const void *P) {
return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P); return PointerIntPair<PointerTy, IntBits, IntType>::getFromOpaqueValue(P);
} }
enum { NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits }; enum { NumLowBitsAvailable = PtrTraits::NumLowBitsAvailable - IntBits };
}; };
} // end namespace llvm } // end namespace llvm
#endif
#endif // LLVM_ADT_POINTERINTPAIR_H

View File

@ -11,10 +11,8 @@
#define LLVM_ADT_POINTERSUMTYPE_H #define LLVM_ADT_POINTERSUMTYPE_H
#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/PointerLikeTypeTraits.h"
#include <cassert>
#include <cstdint>
#include <type_traits>
namespace llvm { namespace llvm {
@ -26,15 +24,16 @@ template <uintptr_t N, typename PointerArgT,
typename TraitsArgT = PointerLikeTypeTraits<PointerArgT>> typename TraitsArgT = PointerLikeTypeTraits<PointerArgT>>
struct PointerSumTypeMember { struct PointerSumTypeMember {
enum { Tag = N }; enum { Tag = N };
using PointerT = PointerArgT; typedef PointerArgT PointerT;
using TraitsT = TraitsArgT; typedef TraitsArgT TraitsT;
}; };
namespace detail { namespace detail {
template <typename TagT, typename... MemberTs> struct PointerSumTypeHelper; template <typename TagT, typename... MemberTs>
struct PointerSumTypeHelper;
} // end namespace detail }
/// A sum type over pointer-like types. /// A sum type over pointer-like types.
/// ///
@ -61,12 +60,12 @@ template <typename TagT, typename... MemberTs> struct PointerSumTypeHelper;
/// There is no support for constructing or accessing with a dynamic tag as /// There is no support for constructing or accessing with a dynamic tag as
/// that would fundamentally violate the type safety provided by the sum type. /// that would fundamentally violate the type safety provided by the sum type.
template <typename TagT, typename... MemberTs> class PointerSumType { template <typename TagT, typename... MemberTs> class PointerSumType {
uintptr_t Value = 0; uintptr_t Value;
using HelperT = detail::PointerSumTypeHelper<TagT, MemberTs...>; typedef detail::PointerSumTypeHelper<TagT, MemberTs...> HelperT;
public: public:
PointerSumType() = default; PointerSumType() : Value(0) {}
/// A typed constructor for a specific tagged member of the sum type. /// A typed constructor for a specific tagged member of the sum type.
template <TagT N> template <TagT N>
@ -129,14 +128,14 @@ struct PointerSumTypeHelper : MemberTs... {
template <TagT N> static void LookupOverload(...); template <TagT N> static void LookupOverload(...);
template <TagT N> struct Lookup { template <TagT N> struct Lookup {
// Compute a particular member type by resolving the lookup helper ovorload. // Compute a particular member type by resolving the lookup helper ovorload.
using MemberT = decltype( typedef decltype(LookupOverload<N>(
LookupOverload<N>(static_cast<PointerSumTypeHelper *>(nullptr))); static_cast<PointerSumTypeHelper *>(nullptr))) MemberT;
/// The Nth member's pointer type. /// The Nth member's pointer type.
using PointerT = typename MemberT::PointerT; typedef typename MemberT::PointerT PointerT;
/// The Nth member's traits type. /// The Nth member's traits type.
using TraitsT = typename MemberT::TraitsT; typedef typename MemberT::TraitsT TraitsT;
}; };
// Next we need to compute the number of bits available for the discriminant // Next we need to compute the number of bits available for the discriminant
@ -172,37 +171,35 @@ struct PointerSumTypeHelper : MemberTs... {
"Each member must pass the checker."); "Each member must pass the checker.");
}; };
} // end namespace detail }
// Teach DenseMap how to use PointerSumTypes as keys. // Teach DenseMap how to use PointerSumTypes as keys.
template <typename TagT, typename... MemberTs> template <typename TagT, typename... MemberTs>
struct DenseMapInfo<PointerSumType<TagT, MemberTs...>> { struct DenseMapInfo<PointerSumType<TagT, MemberTs...>> {
using SumType = PointerSumType<TagT, MemberTs...>; typedef PointerSumType<TagT, MemberTs...> SumType;
using HelperT = detail::PointerSumTypeHelper<TagT, MemberTs...>; typedef detail::PointerSumTypeHelper<TagT, MemberTs...> HelperT;
enum { SomeTag = HelperT::MinTag }; enum { SomeTag = HelperT::MinTag };
using SomePointerT = typedef typename HelperT::template Lookup<HelperT::MinTag>::PointerT
typename HelperT::template Lookup<HelperT::MinTag>::PointerT; SomePointerT;
using SomePointerInfo = DenseMapInfo<SomePointerT>; typedef DenseMapInfo<SomePointerT> SomePointerInfo;
static inline SumType getEmptyKey() { static inline SumType getEmptyKey() {
return SumType::create<SomeTag>(SomePointerInfo::getEmptyKey()); return SumType::create<SomeTag>(SomePointerInfo::getEmptyKey());
} }
static inline SumType getTombstoneKey() { static inline SumType getTombstoneKey() {
return SumType::create<SomeTag>(SomePointerInfo::getTombstoneKey()); return SumType::create<SomeTag>(
SomePointerInfo::getTombstoneKey());
} }
static unsigned getHashValue(const SumType &Arg) { static unsigned getHashValue(const SumType &Arg) {
uintptr_t OpaqueValue = Arg.getOpaqueValue(); uintptr_t OpaqueValue = Arg.getOpaqueValue();
return DenseMapInfo<uintptr_t>::getHashValue(OpaqueValue); return DenseMapInfo<uintptr_t>::getHashValue(OpaqueValue);
} }
static bool isEqual(const SumType &LHS, const SumType &RHS) { static bool isEqual(const SumType &LHS, const SumType &RHS) {
return LHS == RHS; return LHS == RHS;
} }
}; };
} // end namespace llvm }
#endif // LLVM_ADT_POINTERSUMTYPE_H #endif

View File

@ -19,13 +19,13 @@
#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerIntPair.h"
#include "llvm/Support/PointerLikeTypeTraits.h" #include "llvm/Support/PointerLikeTypeTraits.h"
#include <cassert> #include <cassert>
#include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstddef>
namespace llvm { namespace llvm {
template <typename T> struct PointerUnionTypeSelectorReturn { template <typename T> struct PointerUnionTypeSelectorReturn {
using Return = T; typedef T Return;
}; };
/// Get a type based on whether two types are the same or not. /// Get a type based on whether two types are the same or not.
@ -39,19 +39,19 @@ template <typename T> struct PointerUnionTypeSelectorReturn {
/// Ret will be EQ type if T1 is same as T2 or NE type otherwise. /// Ret will be EQ type if T1 is same as T2 or NE type otherwise.
template <typename T1, typename T2, typename RET_EQ, typename RET_NE> template <typename T1, typename T2, typename RET_EQ, typename RET_NE>
struct PointerUnionTypeSelector { struct PointerUnionTypeSelector {
using Return = typename PointerUnionTypeSelectorReturn<RET_NE>::Return; typedef typename PointerUnionTypeSelectorReturn<RET_NE>::Return Return;
}; };
template <typename T, typename RET_EQ, typename RET_NE> template <typename T, typename RET_EQ, typename RET_NE>
struct PointerUnionTypeSelector<T, T, RET_EQ, RET_NE> { struct PointerUnionTypeSelector<T, T, RET_EQ, RET_NE> {
using Return = typename PointerUnionTypeSelectorReturn<RET_EQ>::Return; typedef typename PointerUnionTypeSelectorReturn<RET_EQ>::Return Return;
}; };
template <typename T1, typename T2, typename RET_EQ, typename RET_NE> template <typename T1, typename T2, typename RET_EQ, typename RET_NE>
struct PointerUnionTypeSelectorReturn< struct PointerUnionTypeSelectorReturn<
PointerUnionTypeSelector<T1, T2, RET_EQ, RET_NE>> { PointerUnionTypeSelector<T1, T2, RET_EQ, RET_NE>> {
using Return = typedef
typename PointerUnionTypeSelector<T1, T2, RET_EQ, RET_NE>::Return; typename PointerUnionTypeSelector<T1, T2, RET_EQ, RET_NE>::Return Return;
}; };
/// Provide PointerLikeTypeTraits for void* that is used by PointerUnion /// Provide PointerLikeTypeTraits for void* that is used by PointerUnion
@ -86,8 +86,8 @@ public:
/// X = P.get<int*>(); // runtime assertion failure. /// X = P.get<int*>(); // runtime assertion failure.
template <typename PT1, typename PT2> class PointerUnion { template <typename PT1, typename PT2> class PointerUnion {
public: public:
using ValTy = typedef PointerIntPair<void *, 1, bool, PointerUnionUIntTraits<PT1, PT2>>
PointerIntPair<void *, 1, bool, PointerUnionUIntTraits<PT1, PT2>>; ValTy;
private: private:
ValTy Val; ValTy Val;
@ -121,10 +121,10 @@ public:
/// Test if the Union currently holds the type matching T. /// Test if the Union currently holds the type matching T.
template <typename T> int is() const { template <typename T> int is() const {
using Ty = typename ::llvm::PointerUnionTypeSelector< typedef typename ::llvm::PointerUnionTypeSelector<
PT1, T, IsPT1, PT1, T, IsPT1, ::llvm::PointerUnionTypeSelector<
::llvm::PointerUnionTypeSelector<PT2, T, IsPT2, PT2, T, IsPT2, UNION_DOESNT_CONTAIN_TYPE<T>>>::Return
UNION_DOESNT_CONTAIN_TYPE<T>>>::Return; Ty;
int TyNo = Ty::Num; int TyNo = Ty::Num;
return static_cast<int>(Val.getInt()) == TyNo; return static_cast<int>(Val.getInt()) == TyNo;
} }
@ -228,22 +228,19 @@ public:
/// for usage. /// for usage.
template <typename PT1, typename PT2, typename PT3> class PointerUnion3 { template <typename PT1, typename PT2, typename PT3> class PointerUnion3 {
public: public:
using InnerUnion = PointerUnion<PT1, PT2>; typedef PointerUnion<PT1, PT2> InnerUnion;
using ValTy = PointerUnion<InnerUnion, PT3>; typedef PointerUnion<InnerUnion, PT3> ValTy;
private: private:
ValTy Val; ValTy Val;
struct IsInnerUnion { struct IsInnerUnion {
ValTy Val; ValTy Val;
IsInnerUnion(ValTy val) : Val(val) {} IsInnerUnion(ValTy val) : Val(val) {}
template <typename T> int is() const { template <typename T> int is() const {
return Val.template is<InnerUnion>() && return Val.template is<InnerUnion>() &&
Val.template get<InnerUnion>().template is<T>(); Val.template get<InnerUnion>().template is<T>();
} }
template <typename T> T get() const { template <typename T> T get() const {
return Val.template get<InnerUnion>().template get<T>(); return Val.template get<InnerUnion>().template get<T>();
} }
@ -251,15 +248,14 @@ private:
struct IsPT3 { struct IsPT3 {
ValTy Val; ValTy Val;
IsPT3(ValTy val) : Val(val) {} IsPT3(ValTy val) : Val(val) {}
template <typename T> int is() const { return Val.template is<T>(); } template <typename T> int is() const { return Val.template is<T>(); }
template <typename T> T get() const { return Val.template get<T>(); } template <typename T> T get() const { return Val.template get<T>(); }
}; };
public: public:
PointerUnion3() = default; PointerUnion3() = default;
PointerUnion3(PT1 V) { Val = InnerUnion(V); } PointerUnion3(PT1 V) { Val = InnerUnion(V); }
PointerUnion3(PT2 V) { Val = InnerUnion(V); } PointerUnion3(PT2 V) { Val = InnerUnion(V); }
PointerUnion3(PT3 V) { Val = V; } PointerUnion3(PT3 V) { Val = V; }
@ -272,9 +268,10 @@ public:
/// Test if the Union currently holds the type matching T. /// Test if the Union currently holds the type matching T.
template <typename T> int is() const { template <typename T> int is() const {
// If T is PT1/PT2 choose IsInnerUnion otherwise choose IsPT3. // If T is PT1/PT2 choose IsInnerUnion otherwise choose IsPT3.
using Ty = typename ::llvm::PointerUnionTypeSelector< typedef typename ::llvm::PointerUnionTypeSelector<
PT1, T, IsInnerUnion, PT1, T, IsInnerUnion,
::llvm::PointerUnionTypeSelector<PT2, T, IsInnerUnion, IsPT3>>::Return; ::llvm::PointerUnionTypeSelector<PT2, T, IsInnerUnion, IsPT3>>::Return
Ty;
return Ty(Val).template is<T>(); return Ty(Val).template is<T>();
} }
@ -284,9 +281,10 @@ public:
template <typename T> T get() const { template <typename T> T get() const {
assert(is<T>() && "Invalid accessor called"); assert(is<T>() && "Invalid accessor called");
// If T is PT1/PT2 choose IsInnerUnion otherwise choose IsPT3. // If T is PT1/PT2 choose IsInnerUnion otherwise choose IsPT3.
using Ty = typename ::llvm::PointerUnionTypeSelector< typedef typename ::llvm::PointerUnionTypeSelector<
PT1, T, IsInnerUnion, PT1, T, IsInnerUnion,
::llvm::PointerUnionTypeSelector<PT2, T, IsInnerUnion, IsPT3>>::Return; ::llvm::PointerUnionTypeSelector<PT2, T, IsInnerUnion, IsPT3>>::Return
Ty;
return Ty(Val).template get<T>(); return Ty(Val).template get<T>();
} }
@ -352,15 +350,16 @@ public:
template <typename PT1, typename PT2, typename PT3, typename PT4> template <typename PT1, typename PT2, typename PT3, typename PT4>
class PointerUnion4 { class PointerUnion4 {
public: public:
using InnerUnion1 = PointerUnion<PT1, PT2>; typedef PointerUnion<PT1, PT2> InnerUnion1;
using InnerUnion2 = PointerUnion<PT3, PT4>; typedef PointerUnion<PT3, PT4> InnerUnion2;
using ValTy = PointerUnion<InnerUnion1, InnerUnion2>; typedef PointerUnion<InnerUnion1, InnerUnion2> ValTy;
private: private:
ValTy Val; ValTy Val;
public: public:
PointerUnion4() = default; PointerUnion4() = default;
PointerUnion4(PT1 V) { Val = InnerUnion1(V); } PointerUnion4(PT1 V) { Val = InnerUnion1(V); }
PointerUnion4(PT2 V) { Val = InnerUnion1(V); } PointerUnion4(PT2 V) { Val = InnerUnion1(V); }
PointerUnion4(PT3 V) { Val = InnerUnion2(V); } PointerUnion4(PT3 V) { Val = InnerUnion2(V); }
@ -374,10 +373,9 @@ public:
/// Test if the Union currently holds the type matching T. /// Test if the Union currently holds the type matching T.
template <typename T> int is() const { template <typename T> int is() const {
// If T is PT1/PT2 choose InnerUnion1 otherwise choose InnerUnion2. // If T is PT1/PT2 choose InnerUnion1 otherwise choose InnerUnion2.
using Ty = typename ::llvm::PointerUnionTypeSelector< typedef typename ::llvm::PointerUnionTypeSelector<
PT1, T, InnerUnion1, PT1, T, InnerUnion1, ::llvm::PointerUnionTypeSelector<
::llvm::PointerUnionTypeSelector<PT2, T, InnerUnion1, PT2, T, InnerUnion1, InnerUnion2>>::Return Ty;
InnerUnion2>>::Return;
return Val.template is<Ty>() && Val.template get<Ty>().template is<T>(); return Val.template is<Ty>() && Val.template get<Ty>().template is<T>();
} }
@ -387,10 +385,9 @@ public:
template <typename T> T get() const { template <typename T> T get() const {
assert(is<T>() && "Invalid accessor called"); assert(is<T>() && "Invalid accessor called");
// If T is PT1/PT2 choose InnerUnion1 otherwise choose InnerUnion2. // If T is PT1/PT2 choose InnerUnion1 otherwise choose InnerUnion2.
using Ty = typename ::llvm::PointerUnionTypeSelector< typedef typename ::llvm::PointerUnionTypeSelector<
PT1, T, InnerUnion1, PT1, T, InnerUnion1, ::llvm::PointerUnionTypeSelector<
::llvm::PointerUnionTypeSelector<PT2, T, InnerUnion1, PT2, T, InnerUnion1, InnerUnion2>>::Return Ty;
InnerUnion2>>::Return;
return Val.template get<Ty>().template get<T>(); return Val.template get<Ty>().template get<T>();
} }
@ -458,21 +455,18 @@ public:
// Teach DenseMap how to use PointerUnions as keys. // Teach DenseMap how to use PointerUnions as keys.
template <typename T, typename U> struct DenseMapInfo<PointerUnion<T, U>> { template <typename T, typename U> struct DenseMapInfo<PointerUnion<T, U>> {
using Pair = PointerUnion<T, U>; typedef PointerUnion<T, U> Pair;
using FirstInfo = DenseMapInfo<T>; typedef DenseMapInfo<T> FirstInfo;
using SecondInfo = DenseMapInfo<U>; typedef DenseMapInfo<U> SecondInfo;
static inline Pair getEmptyKey() { return Pair(FirstInfo::getEmptyKey()); } static inline Pair getEmptyKey() { return Pair(FirstInfo::getEmptyKey()); }
static inline Pair getTombstoneKey() { static inline Pair getTombstoneKey() {
return Pair(FirstInfo::getTombstoneKey()); return Pair(FirstInfo::getTombstoneKey());
} }
static unsigned getHashValue(const Pair &PairVal) { static unsigned getHashValue(const Pair &PairVal) {
intptr_t key = (intptr_t)PairVal.getOpaqueValue(); intptr_t key = (intptr_t)PairVal.getOpaqueValue();
return DenseMapInfo<intptr_t>::getHashValue(key); return DenseMapInfo<intptr_t>::getHashValue(key);
} }
static bool isEqual(const Pair &LHS, const Pair &RHS) { static bool isEqual(const Pair &LHS, const Pair &RHS) {
return LHS.template is<T>() == RHS.template is<T>() && return LHS.template is<T>() == RHS.template is<T>() &&
(LHS.template is<T>() ? FirstInfo::isEqual(LHS.template get<T>(), (LHS.template is<T>() ? FirstInfo::isEqual(LHS.template get<T>(),

View File

@ -13,14 +13,9 @@
#include "llvm/ADT/ilist_base.h" #include "llvm/ADT/ilist_base.h"
#include "llvm/ADT/ilist_iterator.h" #include "llvm/ADT/ilist_iterator.h"
#include "llvm/ADT/ilist_node.h" #include "llvm/ADT/ilist_node.h"
#include "llvm/ADT/ilist_node_options.h"
#include "llvm/Support/Compiler.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>
#include <functional>
#include <iterator>
#include <utility>
namespace llvm { namespace llvm {
@ -82,23 +77,23 @@ class simple_ilist
typename ilist_detail::compute_node_options<T, Options...>::type> { typename ilist_detail::compute_node_options<T, Options...>::type> {
static_assert(ilist_detail::check_options<Options...>::value, static_assert(ilist_detail::check_options<Options...>::value,
"Unrecognized node option!"); "Unrecognized node option!");
using OptionsT = typedef
typename ilist_detail::compute_node_options<T, Options...>::type; typename ilist_detail::compute_node_options<T, Options...>::type OptionsT;
using list_base_type = typename OptionsT::list_base_type; typedef typename OptionsT::list_base_type list_base_type;
ilist_sentinel<OptionsT> Sentinel; ilist_sentinel<OptionsT> Sentinel;
public: public:
using value_type = typename OptionsT::value_type; typedef typename OptionsT::value_type value_type;
using pointer = typename OptionsT::pointer; typedef typename OptionsT::pointer pointer;
using reference = typename OptionsT::reference; typedef typename OptionsT::reference reference;
using const_pointer = typename OptionsT::const_pointer; typedef typename OptionsT::const_pointer const_pointer;
using const_reference = typename OptionsT::const_reference; typedef typename OptionsT::const_reference const_reference;
using iterator = ilist_iterator<OptionsT, false, false>; typedef ilist_iterator<OptionsT, false, false> iterator;
using const_iterator = ilist_iterator<OptionsT, false, true>; typedef ilist_iterator<OptionsT, false, true> const_iterator;
using reverse_iterator = ilist_iterator<OptionsT, true, false>; typedef ilist_iterator<OptionsT, true, false> reverse_iterator;
using const_reverse_iterator = ilist_iterator<OptionsT, true, true>; typedef ilist_iterator<OptionsT, true, true> const_reverse_iterator;
using size_type = size_t; typedef size_t size_type;
using difference_type = ptrdiff_t; typedef ptrdiff_t difference_type;
simple_ilist() = default; simple_ilist() = default;
~simple_ilist() = default; ~simple_ilist() = default;