Add an isLoopSimplifyForm() predicate, following the example of
authorDan Gohman <gohman@apple.com>
Thu, 16 Jul 2009 16:16:23 +0000 (16:16 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 16 Jul 2009 16:16:23 +0000 (16:16 +0000)
isLCSSAForm(), to test whether a loop is in the form guaranteed
by the LoopSimplify pass.

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

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

index 60c9564222aa110486ab5de78c659d2065c54baf..7ce6a4eddab571ca3c9a65c6bad6b733d0bfb566 100644 (file)
@@ -551,6 +551,11 @@ public:
   /// isLCSSAForm - Return true if the Loop is in LCSSA form
   bool isLCSSAForm() const;
 
+  /// isLoopSimplifyForm - Return true if the Loop is in the form that
+  /// the LoopSimplify form transforms loops to, which is sometimes called
+  /// normal form.
+  bool isLoopSimplifyForm() const;
+
 private:
   friend class LoopInfoBase<BasicBlock, Loop>;
   explicit Loop(BasicBlock *BB) : LoopBase<BasicBlock, Loop>(BB) {}
index 63de1aa7aee9e117ca6328e49d90b567b8a8b0b1..d350fa6f9eb174bed27fdd99a7528f9fe3891fb1 100644 (file)
@@ -276,6 +276,30 @@ bool Loop::isLCSSAForm() const {
 
   return true;
 }
+
+/// isLoopSimplifyForm - Return true if the Loop is in the form that
+/// 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;
+  // Each predecessor of each exit block of a normal loop is contained
+  // within the loop.
+  SmallVector<BasicBlock *, 4> ExitBlocks;
+  getExitBlocks(ExitBlocks);
+  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))
+        return false;
+  // All the requirements are met.
+  return true;
+}
+
 //===----------------------------------------------------------------------===//
 // LoopInfo implementation
 //