[llvm-commits] [llvm] r84673 - /llvm/trunk/lib/Analysis/LoopInfo.cpp

Dan Gohman gohman at apple.com
Tue Oct 20 13:41:13 PDT 2009


Author: djg
Date: Tue Oct 20 15:41:13 2009
New Revision: 84673

URL: http://llvm.org/viewvc/llvm-project?rev=84673&view=rev
Log:
Fix another place that calls Loop::contains a lot to construct a sorted
container of the blocks and do efficient lookups. This makes
isLoopSimplifyForm much faster on large loops, fixing a significant
compile-time issue in builds with assertions enabled.

Modified:
    llvm/trunk/lib/Analysis/LoopInfo.cpp

Modified: llvm/trunk/lib/Analysis/LoopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopInfo.cpp?rev=84673&r1=84672&r2=84673&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/LoopInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopInfo.cpp Tue Oct 20 15:41:13 2009
@@ -292,6 +292,9 @@
   // Normal-form loops have a single backedge.
   if (!getLoopLatch())
     return false;
+  // Sort the blocks vector so that we can use binary search to do quick
+  // lookups.
+  SmallPtrSet<BasicBlock *, 16> LoopBBs(block_begin(), block_end());
   // Each predecessor of each exit block of a normal loop is contained
   // within the loop.
   SmallVector<BasicBlock *, 4> ExitBlocks;
@@ -299,7 +302,7 @@
   for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
     for (pred_iterator PI = pred_begin(ExitBlocks[i]),
          PE = pred_end(ExitBlocks[i]); PI != PE; ++PI)
-      if (!contains(*PI))
+      if (!LoopBBs.count(*PI))
         return false;
   // All the requirements are met.
   return true;





More information about the llvm-commits mailing list