[llvm-branch-commits] [llvm-branch] r69826 - in /llvm/branches/Apple/Dib: include/llvm/Support/PredIteratorCache.h lib/Transforms/Utils/LCSSA.cpp

Bill Wendling isanbard at gmail.com
Wed Apr 22 13:56:33 PDT 2009


Author: void
Date: Wed Apr 22 15:56:33 2009
New Revision: 69826

URL: http://llvm.org/viewvc/llvm-project?rev=69826&view=rev
Log:
--- Merging (from foreign repository) r69788 into '.':
U    lib/Transforms/Utils/LCSSA.cpp
--- Merging (from foreign repository) r69791 into '.':
U    include/llvm/Support/PredIteratorCache.h
--- Merging (from foreign repository) r69792 into '.':
G    lib/Transforms/Utils/LCSSA.cpp

Some commits to make things go faster.

Modified:
    llvm/branches/Apple/Dib/include/llvm/Support/PredIteratorCache.h
    llvm/branches/Apple/Dib/lib/Transforms/Utils/LCSSA.cpp

Modified: llvm/branches/Apple/Dib/include/llvm/Support/PredIteratorCache.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Support/PredIteratorCache.h?rev=69826&r1=69825&r2=69826&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/include/llvm/Support/PredIteratorCache.h (original)
+++ llvm/branches/Apple/Dib/include/llvm/Support/PredIteratorCache.h Wed Apr 22 15:56:33 2009
@@ -27,6 +27,7 @@
   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 @@
 
       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();
     }
   };

Modified: llvm/branches/Apple/Dib/lib/Transforms/Utils/LCSSA.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Utils/LCSSA.cpp?rev=69826&r1=69825&r2=69826&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/Utils/LCSSA.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/Utils/LCSSA.cpp Wed Apr 22 15:56:33 2009
@@ -40,6 +40,7 @@
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/PredIteratorCache.h"
 #include <algorithm>
 #include <map>
 using namespace llvm;
@@ -55,6 +56,7 @@
     LoopInfo *LI;
     DominatorTree *DT;
     std::vector<BasicBlock*> LoopBlocks;
+    PredIteratorCache PredCache;
     
     virtual bool runOnLoop(Loop *L, LPPassManager &LPM);
 
@@ -84,7 +86,8 @@
     }
   private:
     void getLoopValuesUsedOutsideLoop(Loop *L,
-                                      SetVector<Instruction*> &AffectedValues);
+                                      SetVector<Instruction*> &AffectedValues,
+                                 const SmallVector<BasicBlock*, 8>& exitBlocks);
 
     Value *GetValueForBlock(DomTreeNode *BB, Instruction *OrigInst,
                             DenseMap<DomTreeNode*, Value*> &Phis);
@@ -104,6 +107,7 @@
 
 /// runOnFunction - Process all loops in the function, inner-most out.
 bool LCSSA::runOnLoop(Loop *L, LPPassManager &LPM) {
+  PredCache.clear();
   
   LI = &LPM.getAnalysis<LoopInfo>();
   DT = &getAnalysis<DominatorTree>();
@@ -113,17 +117,17 @@
   LoopBlocks.insert(LoopBlocks.end(), L->block_begin(), L->block_end());
   std::sort(LoopBlocks.begin(), LoopBlocks.end());
   
+  SmallVector<BasicBlock*, 8> exitBlocks;
+  L->getExitBlocks(exitBlocks);
+  
   SetVector<Instruction*> AffectedValues;
-  getLoopValuesUsedOutsideLoop(L, AffectedValues);
+  getLoopValuesUsedOutsideLoop(L, AffectedValues, exitBlocks);
   
   // If no values are affected, we can save a lot of work, since we know that
   // nothing will be changed.
   if (AffectedValues.empty())
     return false;
   
-  SmallVector<BasicBlock*, 8> exitBlocks;
-  L->getExitBlocks(exitBlocks);  
-  
   // Iterate over all affected values for this loop and insert Phi nodes
   // for them in the appropriate exit blocks
   
@@ -157,13 +161,13 @@
     if (!Phi && DT->dominates(InstrNode, ExitBBNode)) {
       PHINode *PN = PHINode::Create(Instr->getType(), Instr->getName()+".lcssa",
                                     BB->begin());
-      PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
+      PN->reserveOperandSpace(PredCache.GetNumPreds(BB));
 
       // Remember that this phi makes the value alive in this block.
       Phi = PN;
 
       // Add inputs from inside the loop for this PHI.
-      for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
+      for (BasicBlock** PI = PredCache.GetPreds(BB); *PI; ++PI)
         PN->addIncoming(Instr, *PI);
     }
   }
@@ -199,15 +203,16 @@
 /// getLoopValuesUsedOutsideLoop - Return any values defined in the loop that
 /// are used by instructions outside of it.
 void LCSSA::getLoopValuesUsedOutsideLoop(Loop *L,
-                                      SetVector<Instruction*> &AffectedValues) {
+                                      SetVector<Instruction*> &AffectedValues,
+                                const SmallVector<BasicBlock*, 8>& exitBlocks) {
   // FIXME: For large loops, we may be able to avoid a lot of use-scanning
   // by using dominance information.  In particular, if a block does not
   // dominate any of the loop exits, then none of the values defined in the
   // block could be used outside the loop.
-  for (Loop::block_iterator BB = L->block_begin(), E = L->block_end();
-       BB != E; ++BB) {
+  for (Loop::block_iterator BB = L->block_begin(), BE = L->block_end();
+       BB != BE; ++BB) {
     for (BasicBlock::iterator I = (*BB)->begin(), E = (*BB)->end(); I != E; ++I)
-      for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); UI != E;
+      for (Value::use_iterator UI = I->use_begin(), UE = I->use_end(); UI != UE;
            ++UI) {
         BasicBlock *UserBB = cast<Instruction>(*UI)->getParent();
         if (PHINode* p = dyn_cast<PHINode>(*UI)) {
@@ -260,11 +265,11 @@
   // now, then get values to fill in the incoming values for the PHI.
   PHINode *PN = PHINode::Create(OrigInst->getType(),
                                 OrigInst->getName() + ".lcssa", BBN->begin());
-  PN->reserveOperandSpace(std::distance(pred_begin(BBN), pred_end(BBN)));
+  PN->reserveOperandSpace(PredCache.GetNumPreds(BBN));
   Phis.insert(std::make_pair(BB, PN));
                                  
   // Fill in the incoming values for the block.
-  for (pred_iterator PI = pred_begin(BBN), E = pred_end(BBN); PI != E; ++PI)
+  for (BasicBlock** PI = PredCache.GetPreds(BBN); *PI; ++PI)
     PN->addIncoming(GetValueForBlock(DT->getNode(*PI), OrigInst, Phis), *PI);
   return PN;
 }





More information about the llvm-branch-commits mailing list