Add caching of predecessor counts as well as predecessors themselves.
authorOwen Anderson <resistor@mac.com>
Wed, 22 Apr 2009 08:46:33 +0000 (08:46 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 22 Apr 2009 08:46:33 +0000 (08:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@69791 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/PredIteratorCache.h

index cef9de0b272ed818c314443a548842f4edbc42e1..bb66a8ed58b772d17836df55000e2ec0da3a637e 100644 (file)
@@ -27,6 +27,7 @@ namespace llvm {
   class PredIteratorCache {
     /// BlockToPredsMap - Pointer to null-terminated list.
     DenseMap<BasicBlock*, BasicBlock**> BlockToPredsMap;
+    DenseMap<BasicBlock*, unsigned> BlockToPredCountMap;
 
     /// Memory - This is the space that holds cached preds.
     BumpPtrAllocator Memory;
@@ -44,15 +45,23 @@ namespace llvm {
 
       SmallVector<BasicBlock*, 32> PredCache(pred_begin(BB), pred_end(BB));
       PredCache.push_back(0); // null terminator.
+      
+      BlockToPredCountMap[BB] = PredCache.size()-1;
 
       Entry = Memory.Allocate<BasicBlock*>(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();
     }
   };