X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FPredIteratorCache.h;h=bb66a8ed58b772d17836df55000e2ec0da3a637e;hb=48b6a79b2d367ea2e8cf014d8af9d573889d2f7f;hp=2de2a02461dedfb3f5649801277a292adcfca395;hpb=723a59c17eecad082f0c734d29553a5d392c24b2;p=oota-llvm.git diff --git a/include/llvm/Support/PredIteratorCache.h b/include/llvm/Support/PredIteratorCache.h index 2de2a02461d..bb66a8ed58b 100644 --- a/include/llvm/Support/PredIteratorCache.h +++ b/include/llvm/Support/PredIteratorCache.h @@ -27,11 +27,12 @@ namespace llvm { class PredIteratorCache { /// BlockToPredsMap - Pointer to null-terminated list. DenseMap BlockToPredsMap; + DenseMap BlockToPredCountMap; /// Memory - This is the space that holds cached preds. BumpPtrAllocator Memory; public: - + /// GetPreds - Get a cached list for the null-terminated predecessor list of /// the specified block. This can be used in a loop like this: /// for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) @@ -41,22 +42,29 @@ namespace llvm { BasicBlock **GetPreds(BasicBlock *BB) { BasicBlock **&Entry = BlockToPredsMap[BB]; if (Entry) return Entry; - + SmallVector PredCache(pred_begin(BB), pred_end(BB)); PredCache.push_back(0); // null terminator. + BlockToPredCountMap[BB] = PredCache.size()-1; + Entry = Memory.Allocate(PredCache.size()); std::copy(PredCache.begin(), PredCache.end(), Entry); return Entry; } + unsigned GetNumPreds(BasicBlock *BB) { + GetPreds(BB); + return BlockToPredCountMap[BB]; + } + /// clear - Remove all information. void clear() { BlockToPredsMap.clear(); + BlockToPredCountMap.clear(); Memory.Reset(); } }; } // end namespace llvm #endif -