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
This commit is contained in:
Chandler Carruth
2012-05-04 20:55:23 +00:00
parent 49683f3c96
commit 7c52c97a22
4 changed files with 87 additions and 18 deletions
+58 -6
View File
@@ -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();