diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-05-04 20:55:23 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-05-04 20:55:23 +0000 |
commit | 7c52c97a2232756bbcc2fb4e664892bdb8b2d90c (patch) | |
tree | c461b6340583748ebfb69be0be481a94bc9c5211 /include/llvm/Analysis | |
parent | 49683f3c961379fbc088871a5d6304950f1f1cbc (diff) | |
download | external_llvm-7c52c97a2232756bbcc2fb4e664892bdb8b2d90c.zip external_llvm-7c52c97a2232756bbcc2fb4e664892bdb8b2d90c.tar.gz external_llvm-7c52c97a2232756bbcc2fb4e664892bdb8b2d90c.tar.bz2 |
Rename the Region::block_iterator to Region::block_node_iterator, and
add a new Region::block_iterator which actually iterates over the basic
blocks of the region.
The old iterator, now call 'block_node_iterator' iterates over
RegionNodes which contain a single basic block. This works well with the
GraphTraits-based iterator design, however most users actually want an
iterator over the BasicBlocks inside these RegionNodes. Now the
'block_iterator' is a wrapper which exposes exactly this interface.
Internally it uses the block_node_iterator to walk all nodes which are
single basic blocks, but transparently unwraps the basic block to make
user code simpler.
While this patch is a bit of a wash, most of the updates are to internal
users, not external users of the RegionInfo. I have an accompanying
patch to Polly that is a strict simplification of every user of this
interface, and I'm working on a pass that also wants the same simplified
interface.
This patch alone should have no functional impact.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156202 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Analysis')
-rw-r--r-- | include/llvm/Analysis/RegionInfo.h | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/include/llvm/Analysis/RegionInfo.h b/include/llvm/Analysis/RegionInfo.h index b098eea..eae94e7 100644 --- a/include/llvm/Analysis/RegionInfo.h +++ b/include/llvm/Analysis/RegionInfo.h @@ -473,19 +473,71 @@ public: const_iterator end() const { return children.end(); } //@} - /// @name BasicBlock Iterators + /// @name BasicBlock Node Iterators /// /// These iterators iterate over all BasicBlock RegionNodes that are - /// contained in this Region. The iterator also iterates over BasicBlocks - /// that are elements of a subregion of this Region. It is therefore called a - /// flat iterator. + /// contained in this Region. The iterator also iterates over BasicBlock + /// RegionNodes that are elements of a subregion of this Region. It is + /// therefore called a flat iterator. //@{ typedef df_iterator<RegionNode*, SmallPtrSet<RegionNode*, 8>, false, - GraphTraits<FlatIt<RegionNode*> > > block_iterator; + GraphTraits<FlatIt<RegionNode*> > > block_node_iterator; typedef df_iterator<const RegionNode*, SmallPtrSet<const RegionNode*, 8>, false, GraphTraits<FlatIt<const RegionNode*> > > - const_block_iterator; + const_block_node_iterator; + + block_node_iterator block_node_begin(); + block_node_iterator block_node_end(); + + const_block_node_iterator block_node_begin() const; + const_block_node_iterator block_node_end() const; + //@} + + /// @name BasicBlock Iterators + /// + /// These iterators iterate over all BasicBlocks that are contained in this + /// Region. The iterator also iterates over BasicBlocks that are elements of + /// a subregion of this Region. It is therefore called a flat iterator. + //@{ + template <typename RegionNodeItT> + class block_iterator_wrapper + : public std::iterator<std::forward_iterator_tag, BasicBlock, ptrdiff_t> { + typedef std::iterator<std::forward_iterator_tag, BasicBlock, ptrdiff_t> + super; + + RegionNodeItT Iter; + + public: + typedef block_iterator_wrapper<RegionNodeItT> 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<BasicBlock>(); + } + + Self& operator++() { + ++Iter; + return *this; + } + Self operator++(int) { + Self tmp = *this; + ++*this; + return tmp; + } + + const Self &operator=(const Self &I) { + Iter = I.Iter; + return *this; + } + }; + typedef block_iterator_wrapper<block_node_iterator> block_iterator; + typedef block_iterator_wrapper<const_block_node_iterator> + const_block_iterator; block_iterator block_begin(); block_iterator block_end(); |