Change ConstantFoldConstantExpression to accept a null
[oota-llvm.git] / include / llvm / Analysis / ScalarEvolution.h
index c9a80b74a2d182056e3a366bc1c635f9db0526f5..88002cb77530e8c0e05d042aab31506e277e3da6 100644 (file)
@@ -35,8 +35,8 @@ namespace llvm {
   class ScalarEvolution;
   class TargetData;
 
-  /// SCEV - This class represent an analyzed expression in the program.  These
-  /// are reference counted opaque objects that the client is not allowed to
+  /// SCEV - This class represents an analyzed expression in the program.  These
+  /// are reference-counted opaque objects that the client is not allowed to
   /// do much with directly.
   ///
   class SCEV {
@@ -77,6 +77,10 @@ namespace llvm {
     ///
     bool isZero() const;
 
+    /// isOne - Return true if the expression is a constant one.
+    ///
+    bool isOne() const;
+
     /// replaceSymbolicValuesWithConcrete - If this SCEV internally references
     /// the symbolic value "Sym", construct and return a new SCEV that produces
     /// the same value, but which uses the concrete value Conc instead of the
@@ -141,16 +145,6 @@ namespace llvm {
     static bool classof(const SCEV *S);
   };
 
-  /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
-  /// notified whenever a Value is deleted.
-  class SCEVCallbackVH : public CallbackVH {
-    ScalarEvolution *SE;
-    virtual void deleted();
-    virtual void allUsesReplacedWith(Value *New);
-  public:
-    SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0);
-  };
-
   /// SCEVHandle - This class is used to maintain the SCEV object's refcounts,
   /// freeing the objects when the last reference is dropped.
   class SCEVHandle {
@@ -208,7 +202,18 @@ namespace llvm {
   /// they must ask this class for services.
   ///
   class ScalarEvolution : public FunctionPass {
+    /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
+    /// notified whenever a Value is deleted.
+    class SCEVCallbackVH : public CallbackVH {
+      ScalarEvolution *SE;
+      virtual void deleted();
+      virtual void allUsesReplacedWith(Value *New);
+    public:
+      SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0);
+    };
+
     friend class SCEVCallbackVH;
+    friend class SCEVExpander;
 
     /// F - The function we are analyzing.
     ///
@@ -286,7 +291,7 @@ namespace llvm {
 
     /// createNodeForGEP - Provide the special handling we need to analyze GEP
     /// SCEVs.
-    SCEVHandle createNodeForGEP(GetElementPtrInst *GEP);
+    SCEVHandle createNodeForGEP(User *GEP);
 
     /// ReplaceSymbolicValueWithConcrete - This looks up the computed SCEV value
     /// for the specified instruction and replaces any references to the
@@ -337,6 +342,10 @@ namespace llvm {
     BackedgeTakenInfo HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
                                        const Loop *L, bool isSigned);
 
+    /// getLoopPredecessor - If the given loop's header has exactly one unique
+    /// predecessor outside the loop, return it. Otherwise return null.
+    BasicBlock *getLoopPredecessor(const Loop *L);
+
     /// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
     /// (which may not be an immediate predecessor) which has exactly one
     /// successor from which BB is reachable, or null if no such block is
@@ -446,6 +455,21 @@ namespace llvm {
     /// extended, it is sign extended.
     SCEVHandle getTruncateOrSignExtend(const SCEVHandle &V, const Type *Ty);
 
+    /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of
+    /// the input value to the specified type.  If the type must be extended,
+    /// it is zero extended.  The conversion must not be narrowing.
+    SCEVHandle getNoopOrZeroExtend(const SCEVHandle &V, const Type *Ty);
+
+    /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of
+    /// the input value to the specified type.  If the type must be extended,
+    /// it is sign extended.  The conversion must not be narrowing.
+    SCEVHandle getNoopOrSignExtend(const SCEVHandle &V, const Type *Ty);
+
+    /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the
+    /// input value to the specified type.  The conversion must not be
+    /// widening.
+    SCEVHandle getTruncateOrNoop(const SCEVHandle &V, const Type *Ty);
+
     /// getIntegerSCEV - Given an integer or FP type, create a constant for the
     /// specified signed integer value and return a SCEV for the constant.
     SCEVHandle getIntegerSCEV(int Val, const Type *Ty);
@@ -466,8 +490,8 @@ namespace llvm {
     /// This method can be used to compute the exit value for a variable defined
     /// in a loop by querying what the value will hold in the parent loop.
     ///
-    /// If this value is not computable at this scope, a SCEVCouldNotCompute
-    /// object is returned.
+    /// In the case that a relevant loop exit value cannot be computed, the
+    /// original value V is returned.
     SCEVHandle getSCEVAtScope(const SCEV *S, const Loop *L);
 
     /// getSCEVAtScope - This is a convenience function which does