[PATCH] Add iterator and iterator range to PredIteratorCache
Daniel Berlin
dberlin at dberlin.org
Tue Apr 21 13:00:24 PDT 2015
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();
+ }
/// 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));
+ }
+
} // end namespace llvm
#endif
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9169.24163.patch
Type: text/x-patch
Size: 1219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150421/bae40e99/attachment.bin>
More information about the llvm-commits
mailing list