diff --git a/llvm/include/llvm/ADT/GenericCycleImpl.h b/llvm/include/llvm/ADT/GenericCycleImpl.h --- a/llvm/include/llvm/ADT/GenericCycleImpl.h +++ b/llvm/include/llvm/ADT/GenericCycleImpl.h @@ -177,8 +177,7 @@ CurrentContainer.pop_back(); Child->ParentCycle = NewParent; - NewParent->Blocks.insert(NewParent->Blocks.end(), Child->block_begin(), - Child->block_end()); + NewParent->Blocks.insert(Child->block_begin(), Child->block_end()); for (auto &It : BlockMapTopLevel) if (It.second == Child) @@ -266,7 +265,7 @@ } else { Info.BlockMap.try_emplace(Block, NewCycle.get()); assert(!is_contained(NewCycle->Blocks, Block)); - NewCycle->Blocks.push_back(Block); + NewCycle->Blocks.insert(Block); ProcessPredecessors(Block); Info.BlockMapTopLevel.try_emplace(Block, NewCycle.get()); } diff --git a/llvm/include/llvm/ADT/GenericCycleInfo.h b/llvm/include/llvm/ADT/GenericCycleInfo.h --- a/llvm/include/llvm/ADT/GenericCycleInfo.h +++ b/llvm/include/llvm/ADT/GenericCycleInfo.h @@ -32,6 +32,8 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/GenericSSAContext.h" #include "llvm/ADT/GraphTraits.h" +#include "llvm/ADT/SetVector.h" +#include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/iterator.h" #include "llvm/Support/Debug.h" @@ -67,7 +69,9 @@ /// Basic blocks that are contained in the cycle, including entry blocks, /// and including blocks that are part of a child cycle. - std::vector Blocks; + using BlockSetVectorT = SetVector, + SmallPtrSet>; + BlockSetVectorT Blocks; /// Depth of the cycle in the tree. The root "cycle" is at depth 0. /// @@ -85,7 +89,7 @@ } void appendEntry(BlockT *Block) { Entries.push_back(Block); } - void appendBlock(BlockT *Block) { Blocks.push_back(Block); } + void appendBlock(BlockT *Block) { Blocks.insert(Block); } GenericCycle(const GenericCycle &) = delete; GenericCycle &operator=(const GenericCycle &) = delete; @@ -110,9 +114,7 @@ } /// \brief Return whether \p Block is contained in the cycle. - bool contains(const BlockT *Block) const { - return is_contained(Blocks, Block); - } + bool contains(const BlockT *Block) const { return Blocks.contains(Block); } /// \brief Returns true iff this cycle contains \p C. /// @@ -171,7 +173,7 @@ /// Iteration over blocks in the cycle (including entry blocks). //@{ - using const_block_iterator = typename std::vector::const_iterator; + using const_block_iterator = typename BlockSetVectorT::const_iterator; const_block_iterator block_begin() const { return const_block_iterator{Blocks.begin()}; diff --git a/llvm/include/llvm/ADT/SetVector.h b/llvm/include/llvm/ADT/SetVector.h --- a/llvm/include/llvm/ADT/SetVector.h +++ b/llvm/include/llvm/ADT/SetVector.h @@ -39,10 +39,10 @@ typename Set = DenseSet> class SetVector { public: - using value_type = T; - using key_type = T; - using reference = T&; - using const_reference = const T&; + using value_type = typename Vector::value_type; + using key_type = typename Set::key_type; + using reference = value_type &; + using const_reference = const value_type &; using set_type = Set; using vector_type = Vector; using iterator = typename vector_type::const_iterator; @@ -60,7 +60,7 @@ insert(Start, End); } - ArrayRef getArrayRef() const { return vector_; } + ArrayRef getArrayRef() const { return vector_; } /// Clear the SetVector and return the underlying vector. Vector takeVector() { @@ -119,13 +119,13 @@ } /// Return the first element of the SetVector. - const T &front() const { + const value_type &front() const { assert(!empty() && "Cannot call front() on empty SetVector!"); return vector_.front(); } /// Return the last element of the SetVector. - const T &back() const { + const value_type &back() const { assert(!empty() && "Cannot call back() on empty SetVector!"); return vector_.back(); } @@ -222,8 +222,8 @@ vector_.pop_back(); } - [[nodiscard]] T pop_back_val() { - T Ret = back(); + [[nodiscard]] value_type pop_back_val() { + value_type Ret = back(); pop_back(); return Ret; } diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h --- a/llvm/include/llvm/ADT/SmallSet.h +++ b/llvm/include/llvm/ADT/SmallSet.h @@ -149,7 +149,9 @@ static_assert(N <= 32, "N should be small"); public: + using key_type = T; using size_type = size_t; + using value_type = T; using const_iterator = SmallSetIterator; SmallSet() = default;