diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-11 01:50:01 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-11 01:50:01 +0000 |
commit | 77cf856e56dc568ebe760e7de820323fdcf825a4 (patch) | |
tree | 377495323604a06e95c3199fe563498fc6139a70 /include | |
parent | ae64ab542a8452e93c4d4c89295e086bb0cc49a2 (diff) | |
download | llvm-77cf856e56dc568ebe760e7de820323fdcf825a4.tar.gz llvm-77cf856e56dc568ebe760e7de820323fdcf825a4.tar.bz2 llvm-77cf856e56dc568ebe760e7de820323fdcf825a4.tar.xz |
Implement depth_first and inverse_depth_first range factory functions.
Also updated as many loops as I could find using df_begin/idf_begin -
strangely I found no uses of idf_begin. Is that just used out of tree?
Also a few places couldn't use df_begin because either they used the
member functions of the depth first iterators or had specific ordering
constraints (I added a comment in the latter case).
Based on a patch by Jim Grosbach. (Jim - you just had iterator_range<T>
where you needed iterator_range<idf_iterator<T>>)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206016 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/ADT/DepthFirstIterator.h | 13 | ||||
-rw-r--r-- | include/llvm/Analysis/LoopInfoImpl.h | 9 |
2 files changed, 17 insertions, 5 deletions
diff --git a/include/llvm/ADT/DepthFirstIterator.h b/include/llvm/ADT/DepthFirstIterator.h index 644544253a..dfba43f3ac 100644 --- a/include/llvm/ADT/DepthFirstIterator.h +++ b/include/llvm/ADT/DepthFirstIterator.h @@ -33,6 +33,7 @@ #ifndef LLVM_ADT_DEPTHFIRSTITERATOR_H #define LLVM_ADT_DEPTHFIRSTITERATOR_H +#include "llvm/ADT/iterator_range.h" #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallPtrSet.h" @@ -207,6 +208,12 @@ df_iterator<T> df_end(const T& G) { return df_iterator<T>::end(G); } +// Provide an accessor method to use them in range-based patterns. +template <class T> +iterator_range<df_iterator<T>> depth_first(const T& G) { + return iterator_range<df_iterator<T>>(df_begin(G), df_end(G)); +} + // Provide global definitions of external depth first iterators... template <class T, class SetTy = std::set<typename GraphTraits<T>::NodeType*> > struct df_ext_iterator : public df_iterator<T, SetTy, true> { @@ -244,6 +251,12 @@ idf_iterator<T> idf_end(const T& G){ return idf_iterator<T>::end(Inverse<T>(G)); } +// Provide an accessor method to use them in range-based patterns. +template <class T> +iterator_range<idf_iterator<T>> inverse_depth_first(const T& G) { + return iterator_range<idf_iterator<T>>(idf_begin(G), idf_end(G)); +} + // Provide global definitions of external inverse depth first iterators... template <class T, class SetTy = std::set<typename GraphTraits<T>::NodeType*> > struct idf_ext_iterator : public idf_iterator<T, SetTy, true> { diff --git a/include/llvm/Analysis/LoopInfoImpl.h b/include/llvm/Analysis/LoopInfoImpl.h index dd2dc28bb0..0c0d5c44fb 100644 --- a/include/llvm/Analysis/LoopInfoImpl.h +++ b/include/llvm/Analysis/LoopInfoImpl.h @@ -270,11 +270,10 @@ void LoopBase<BlockT, LoopT>::verifyLoop() const { // though it is permitted if the predecessor is not itself actually // reachable. BlockT *EntryBB = BB->getParent()->begin(); - for (df_iterator<BlockT *> NI = df_begin(EntryBB), - NE = df_end(EntryBB); NI != NE; ++NI) - for (unsigned i = 0, e = OutsideLoopPreds.size(); i != e; ++i) - assert(*NI != OutsideLoopPreds[i] && - "Loop has multiple entry points!"); + for (BlockT *CB : depth_first(EntryBB)) + for (unsigned i = 0, e = OutsideLoopPreds.size(); i != e; ++i) + assert(CB != OutsideLoopPreds[i] && + "Loop has multiple entry points!"); } assert(HasInsideLoopPreds && "Loop block has no in-loop predecessors!"); assert(HasInsideLoopSuccs && "Loop block has no in-loop successors!"); |