[PATCH] Add iterator and iterator range to PredIteratorCache
David Blaikie
dblaikie at gmail.com
Tue Apr 21 13:14:31 PDT 2015
On Tue, Apr 21, 2015 at 1:00 PM, Daniel Berlin <dberlin at dberlin.org> wrote:
> Hi chandlerc,
>
> This lets us use range based for loops, and generally makes the interface
> much closer to
> normal pred iterators.
>
> http://reviews.llvm.org/D9169
>
> Files:
> include/llvm/IR/PredIteratorCache.h
>
> Index: include/llvm/IR/PredIteratorCache.h
> ===================================================================
> --- include/llvm/IR/PredIteratorCache.h
> +++ include/llvm/IR/PredIteratorCache.h
> @@ -14,6 +14,7 @@
> #ifndef LLVM_IR_PREDITERATORCACHE_H
> #define LLVM_IR_PREDITERATORCACHE_H
>
> +#include "llvm/ADT/ArrayRef.h"
> #include "llvm/ADT/DenseMap.h"
> #include "llvm/ADT/SmallVector.h"
> #include "llvm/IR/CFG.h"
> @@ -32,6 +33,13 @@
> /// Memory - This is the space that holds cached preds.
> BumpPtrAllocator Memory;
> public:
> + ArrayRef<BasicBlock *>::iterator begin(BasicBlock *BB) {
+ return makeArrayRef(GetPreds(BB), GetNumPreds(BB)).begin();
> + }
> +
> + ArrayRef<BasicBlock *>::iterator end(BasicBlock *BB) {
> + return makeArrayRef(GetPreds(BB), GetNumPreds(BB)).end();
> + }
>
Looks like these could just be:
BasicBlock **begin(BasicBlock *BB) {
return GetPreds(BB) + GetNumPreds(BB);
}
>
> /// GetPreds - Get a cached list for the null-terminated predecessor
> list of
> /// the specified block. This can be used in a loop like this:
> @@ -65,6 +73,12 @@
> Memory.Reset();
> }
> };
> +
> + iterator_range<ArrayRef<BasicBlock *>::iterator>
> + cached_predecessors(PredIteratorCache &PC, BasicBlock *BB) {
> + return make_range(PC.begin(BB), PC.end(BB));
> + }
>
And /this/ would be:
ArrayRef<BasicBlock*> cached_predecessors(...) {
return makeArrayRef(GetPreds(BB), GetNumPreds(BB));
}
(though I guess GetPreds/GetNumPreds are private to the PredIteratorCache?
So maybe just exposing the ArrayRef directly from PredIteratorCache and
avoid ever exposing begin/end?)
> +
> } // end namespace llvm
>
> #endif
>
> EMAIL PREFERENCES
> http://reviews.llvm.org/settings/panel/emailpreferences/
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150421/81cd8a41/attachment.html>
More information about the llvm-commits
mailing list