From: Hongbin Zheng Date: Thu, 2 Aug 2012 14:20:02 +0000 (+0000) Subject: Implement the block_iterator of Region based on df_iterator. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=f63f8834250e5bd50b1cc5b2649acdf42988abad Implement the block_iterator of Region based on df_iterator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161177 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/RegionInfo.h b/include/llvm/Analysis/RegionInfo.h index eae94e757b0..c76a8a7d2ae 100644 --- a/include/llvm/Analysis/RegionInfo.h +++ b/include/llvm/Analysis/RegionInfo.h @@ -500,50 +500,58 @@ public: /// Region. The iterator also iterates over BasicBlocks that are elements of /// a subregion of this Region. It is therefore called a flat iterator. //@{ - template + template class block_iterator_wrapper - : public std::iterator { - typedef std::iterator + : public df_iterator::type*> { + typedef df_iterator::type*> super; - - RegionNodeItT Iter; - public: - typedef block_iterator_wrapper Self; + typedef block_iterator_wrapper Self; typedef typename super::pointer pointer; - block_iterator_wrapper(RegionNodeItT Iter) : Iter(Iter) {} - - bool operator==(const Self &RHS) const { return Iter == RHS.Iter; } - bool operator!=(const Self &RHS) const { return Iter != RHS.Iter; } - pointer operator*() const { - return (*Iter)->template getNodeAs(); + // Construct the begin iterator. + block_iterator_wrapper(pointer Entry, pointer Exit) : super(df_begin(Entry)) + { + // Mark the exit of the region as visited, so that the children of the + // exit and the exit itself, i.e. the block outside the region will never + // be visited. + super::Visited.insert(Exit); } - Self& operator++() { - ++Iter; - return *this; - } - Self operator++(int) { - Self tmp = *this; - ++*this; - return tmp; - } + // Construct the end iterator. + block_iterator_wrapper() : super(df_end(0)) {} + + /*implicit*/ block_iterator_wrapper(super I) : super(I) {} - const Self &operator=(const Self &I) { - Iter = I.Iter; - return *this; + // FIXME: Even a const_iterator returns a non-const BasicBlock pointer. + // This was introduced for backwards compatibility, but should + // be removed as soon as all users are fixed. + BasicBlock *operator*() const { + return const_cast(super::operator*()); } }; - typedef block_iterator_wrapper block_iterator; - typedef block_iterator_wrapper - const_block_iterator; - block_iterator block_begin(); - block_iterator block_end(); + typedef block_iterator_wrapper block_iterator; + typedef block_iterator_wrapper const_block_iterator; - const_block_iterator block_begin() const; - const_block_iterator block_end() const; + block_iterator block_begin() { + return block_iterator(getEntry(), getExit()); + } + + block_iterator block_end() { + return block_iterator(); + } + + const_block_iterator block_begin() const { + return const_block_iterator(getEntry(), getExit()); + } + const_block_iterator block_end() const { + return const_block_iterator(); + } //@} /// @name Element Iterators diff --git a/lib/Analysis/RegionInfo.cpp b/lib/Analysis/RegionInfo.cpp index 5f4458b4020..868f4834b7d 100644 --- a/lib/Analysis/RegionInfo.cpp +++ b/lib/Analysis/RegionInfo.cpp @@ -262,22 +262,6 @@ Region::const_block_node_iterator Region::block_node_end() const { return GraphTraits >::nodes_end(this); } -Region::block_iterator Region::block_begin() { - return block_node_begin(); -} - -Region::block_iterator Region::block_end() { - return block_node_end(); -} - -Region::const_block_iterator Region::block_begin() const { - return block_node_begin(); -} - -Region::const_block_iterator Region::block_end() const { - return block_node_end(); -} - Region::element_iterator Region::element_begin() { return GraphTraits::nodes_begin(this); }