Factor out the predicate code for loopsimplify form exit blocks into
authorDan Gohman <gohman@apple.com>
Thu, 5 Nov 2009 19:21:41 +0000 (19:21 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 5 Nov 2009 19:21:41 +0000 (19:21 +0000)
a separate helper function.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86159 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopInfo.h
lib/Analysis/LoopInfo.cpp

index bc87adbfc79e12c8cf3bcf0564c70ea78fefa682..ac565c703f4b5d2e4b08cce51de6c73f84f651d4 100644 (file)
@@ -572,6 +572,10 @@ public:
   /// normal form.
   bool isLoopSimplifyForm() const;
 
+  /// hasDedicatedExits - Return true if no exit block for the loop
+  /// has a predecessor that is outside the loop.
+  bool hasDedicatedExits() const;
+
   /// getUniqueExitBlocks - Return all unique successor blocks of this loop. 
   /// These are the blocks _outside of the current loop_ which are branched to.
   /// This assumes that loop is in canonical form.
index e9256b74140f0f46315560c5a64374691448f4c4..b5f407dfdc0a1fb983e7d18d0fb76e94501e0ac7 100644 (file)
@@ -286,12 +286,14 @@ bool Loop::isLCSSAForm() const {
 /// the LoopSimplify form transforms loops to, which is sometimes called
 /// normal form.
 bool Loop::isLoopSimplifyForm() const {
-  // Normal-form loops have a preheader.
-  if (!getLoopPreheader())
-    return false;
-  // Normal-form loops have a single backedge.
-  if (!getLoopLatch())
-    return false;
+  // Normal-form loops have a preheader, a single backedge, and all of their
+  // exits have all their predecessors inside the loop.
+  return getLoopPreheader() && getLoopLatch() && hasDedicatedExits();
+}
+
+/// hasDedicatedExits - Return true if no exit block for the loop
+/// has a predecessor that is outside the loop.
+bool Loop::hasDedicatedExits() const {
   // Sort the blocks vector so that we can use binary search to do quick
   // lookups.
   SmallPtrSet<BasicBlock *, 16> LoopBBs(block_begin(), block_end());