Make Loop able to verify that it is in LCSSA-form, and have the LCSSA pass assert
authorOwen Anderson <resistor@mac.com>
Fri, 9 Jun 2006 18:33:30 +0000 (18:33 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 9 Jun 2006 18:33:30 +0000 (18:33 +0000)
on this.

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

include/llvm/Analysis/LoopInfo.h
lib/Analysis/LoopInfo.cpp
lib/Transforms/Utils/LCSSA.cpp

index 06b007cf3fcce6fd54e3762f04004a58aee9b579..d6d6edf5c08040cd22193f5645577a6a44c5c29e 100644 (file)
@@ -98,7 +98,7 @@ public:
   /// isLoopInvariant - Return true if the specified value is loop invariant
   ///
   bool isLoopInvariant(Value *V) const;
-
+  
   //===--------------------------------------------------------------------===//
   // APIs for simple analysis of the loop.
   //
@@ -147,6 +147,9 @@ public:
   ///
   Value *getTripCount() const;
 
+  /// isLCSSAForm - Return true if the Loop is in LCSSA form
+  bool isLCSSAForm() const;
+
   //===--------------------------------------------------------------------===//
   // APIs for updating loop information after changing the CFG
   //
index c7ce58ef915a9634c13110b0f7ef15d4b1de7998..eed2cd6c4ef2930865429c8d6dc8315f63229f46 100644 (file)
@@ -479,6 +479,22 @@ Value *Loop::getTripCount() const {
   return 0;
 }
 
+/// isLCSSAForm - Return true if the Loop is in LCSSA form
+bool Loop::isLCSSAForm() const {  
+  for (Loop::block_iterator BB = block_begin(), E = block_end();
+       BB != E; ++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;
+           ++UI) {
+        BasicBlock *UserBB = cast<Instruction>(*UI)->getParent();
+        if (!isa<PHINode>(*UI) && !contains(UserBB)) {
+          return false;
+        }
+      }
+  }
+  
+  return true;
+}
 
 //===-------------------------------------------------------------------===//
 // APIs for updating loop information after changing the CFG
index e1af50e7454cf7ebf7e63696a00aa6ac9c6caf7b..ecbf1804383e8e7305c7546ca7dd0714c3d76d65 100644 (file)
@@ -98,7 +98,7 @@ bool LCSSA::runOnFunction(Function &F) {
   for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) {
     changed |= visitSubloop(*I);
   }
-      
+  
   return changed;
 }
 
@@ -132,6 +132,8 @@ bool LCSSA::visitSubloop(Loop* L) {
     processInstruction(*I, exitBlocks);
   }
   
+  assert(L->isLCSSAForm());
+  
   return true;
 }