[llvm-commits] CVS: llvm/lib/Analysis/LoopInfo.cpp

Chris Lattner sabre at nondot.org
Sat Mar 3 20:06:56 PST 2007



Changes in directory llvm/lib/Analysis:

LoopInfo.cpp updated: 1.82 -> 1.83
---
Log message:

Speed up Loop::isLCSSAForm by using a hash table instead of a sorted vector.


---
Diffs of the changes:  (+7 -9)

 LoopInfo.cpp |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)


Index: llvm/lib/Analysis/LoopInfo.cpp
diff -u llvm/lib/Analysis/LoopInfo.cpp:1.82 llvm/lib/Analysis/LoopInfo.cpp:1.83
--- llvm/lib/Analysis/LoopInfo.cpp:1.82	Sat Dec 23 00:05:40 2006
+++ llvm/lib/Analysis/LoopInfo.cpp	Sat Mar  3 22:06:39 2007
@@ -22,6 +22,7 @@
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/Streams.h"
 #include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include <algorithm>
 #include <ostream>
 using namespace llvm;
@@ -565,25 +566,22 @@
 bool Loop::isLCSSAForm() const { 
   // Sort the blocks vector so that we can use binary search to do quick
   // lookups.
-  std::vector<BasicBlock*> LoopBBs(block_begin(), block_end());
-  std::sort(LoopBBs.begin(), LoopBBs.end());
+  SmallPtrSet<BasicBlock*, 16> LoopBBs(block_begin(), block_end());
   
-  for (unsigned i = 0, e = LoopBBs.size(); i != e; ++i) {
-    BasicBlock *BB = LoopBBs[i];
+  for (block_iterator BI = block_begin(), E = block_end(); BI != E; ++BI) {
+    BasicBlock *BB = *BI;
     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;
            ++UI) {
         BasicBlock *UserBB = cast<Instruction>(*UI)->getParent();
-        if (PHINode* p = dyn_cast<PHINode>(*UI)) {
+        if (PHINode *P = dyn_cast<PHINode>(*UI)) {
           unsigned OperandNo = UI.getOperandNo();
-          UserBB = p->getIncomingBlock(OperandNo/2);
+          UserBB = P->getIncomingBlock(OperandNo/2);
         }
         
         // Check the current block, as a fast-path.  Most values are used in the
         // same block they are defined in.
-        if (UserBB != BB &&
-            // Otherwise, binary search LoopBBs for this block.
-            !std::binary_search(LoopBBs.begin(), LoopBBs.end(), UserBB))
+        if (UserBB != BB && !LoopBBs.count(UserBB))
           return false;
       }
   }






More information about the llvm-commits mailing list