Changed llvm_ostream et all to OStream. llvm_cerr, llvm_cout, llvm_null, are
[oota-llvm.git] / include / llvm / Analysis / ScalarEvolutionExpressions.h
index 8f113a4004081235365ce76f54b244bad6b28341..ba1b6d4fecb06218eb07bcbd4b39bb0801c3dcb0 100644 (file)
@@ -1,14 +1,14 @@
 //===- llvm/Analysis/ScalarEvolutionExpressions.h - SCEV Exprs --*- C++ -*-===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
 // This file was developed by the LLVM research group and is distributed under
 // the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+//
 //===----------------------------------------------------------------------===//
 //
 // This file defines the classes used to represent and build scalar expressions.
-// 
+//
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_EXPRESSIONS_H
@@ -23,7 +23,7 @@ namespace llvm {
   enum SCEVTypes {
     // These should be ordered in terms of increasing complexity to make the
     // folders simpler.
-    scConstant, scTruncate, scZeroExtend, scAddExpr, scMulExpr, scUDivExpr,
+    scConstant, scTruncate, scZeroExtend, scAddExpr, scMulExpr, scSDivExpr,
     scAddRecExpr, scUnknown, scCouldNotCompute
   };
 
@@ -33,7 +33,7 @@ namespace llvm {
   class SCEVConstant : public SCEV {
     ConstantInt *V;
     SCEVConstant(ConstantInt *v) : SCEV(scConstant), V(v) {}
-    
+
     virtual ~SCEVConstant();
   public:
     /// get method - This just gets and returns a new SCEVConstant object.
@@ -86,7 +86,7 @@ namespace llvm {
 
     const SCEVHandle &getOperand() const { return Op; }
     virtual const Type *getType() const { return Ty; }
-    
+
     virtual bool isLoopInvariant(const Loop *L) const {
       return Op->isLoopInvariant(L);
     }
@@ -132,7 +132,7 @@ namespace llvm {
 
     const SCEVHandle &getOperand() const { return Op; }
     virtual const Type *getType() const { return Ty; }
-    
+
     virtual bool isLoopInvariant(const Loop *L) const {
       return Op->isLoopInvariant(L);
     }
@@ -197,10 +197,18 @@ namespace llvm {
       return true;
     }
 
+    // hasComputableLoopEvolution - Commutative expressions have computable loop
+    // evolutions iff they have at least one operand that varies with the loop,
+    // but that all varying operands are computable.
     virtual bool hasComputableLoopEvolution(const Loop *L) const {
+      bool HasVarying = false;
       for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
-        if (getOperand(i)->hasComputableLoopEvolution(L)) return true;
-      return false;
+        if (!getOperand(i)->isLoopInvariant(L))
+          if (getOperand(i)->hasComputableLoopEvolution(L))
+            HasVarying = true;
+          else
+            return false;
+      return HasVarying;
     }
 
     SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
@@ -285,16 +293,16 @@ namespace llvm {
 
 
   //===--------------------------------------------------------------------===//
-  /// SCEVUDivExpr - This class represents a binary unsigned division operation.
+  /// SCEVSDivExpr - This class represents a binary signed division operation.
   ///
-  class SCEVUDivExpr : public SCEV {
+  class SCEVSDivExpr : public SCEV {
     SCEVHandle LHS, RHS;
-    SCEVUDivExpr(const SCEVHandle &lhs, const SCEVHandle &rhs)
-      : SCEV(scUDivExpr), LHS(lhs), RHS(rhs) {}
+    SCEVSDivExpr(const SCEVHandle &lhs, const SCEVHandle &rhs)
+      : SCEV(scSDivExpr), LHS(lhs), RHS(rhs) {}
 
-    virtual ~SCEVUDivExpr();
+    virtual ~SCEVSDivExpr();
   public:
-    /// get method - This just gets and returns a new SCEVUDiv object.
+    /// get method - This just gets and returns a new SCEVSDiv object.
     ///
     static SCEVHandle get(const SCEVHandle &LHS, const SCEVHandle &RHS);
 
@@ -326,9 +334,9 @@ namespace llvm {
     void print(std::ostream &OS) const;
 
     /// Methods for support type inquiry through isa, cast, and dyn_cast:
-    static inline bool classof(const SCEVUDivExpr *S) { return true; }
+    static inline bool classof(const SCEVSDivExpr *S) { return true; }
     static inline bool classof(const SCEV *S) {
-      return S->getSCEVType() == scUDivExpr;
+      return S->getSCEVType() == scSDivExpr;
     }
   };
 
@@ -382,8 +390,6 @@ namespace llvm {
 
     virtual bool hasComputableLoopEvolution(const Loop *QL) const {
       if (L == QL) return true;
-      /// FIXME: What if the start or step value a recurrence for the specified
-      /// loop?
       return false;
     }
 
@@ -490,8 +496,8 @@ namespace llvm {
         return ((SC*)this)->visitAddExpr((SCEVAddExpr*)S);
       case scMulExpr:
         return ((SC*)this)->visitMulExpr((SCEVMulExpr*)S);
-      case scUDivExpr:
-        return ((SC*)this)->visitUDivExpr((SCEVUDivExpr*)S);
+      case scSDivExpr:
+        return ((SC*)this)->visitSDivExpr((SCEVSDivExpr*)S);
       case scAddRecExpr:
         return ((SC*)this)->visitAddRecExpr((SCEVAddRecExpr*)S);
       case scUnknown: