Teach ScalarEvolution how to reason about no-wrap flags on loops
[oota-llvm.git] / include / llvm / Analysis / ScalarEvolution.h
1 //===- llvm/Analysis/ScalarEvolution.h - Scalar Evolution -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // The ScalarEvolution class is an LLVM pass which can be used to analyze and
11 // catagorize scalar expressions in loops.  It specializes in recognizing
12 // general induction variables, representing them with the abstract and opaque
13 // SCEV class.  Given this analysis, trip counts of loops and other important
14 // properties can be obtained.
15 //
16 // This analysis is primarily useful for induction variable substitution and
17 // strength reduction.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H
22 #define LLVM_ANALYSIS_SCALAREVOLUTION_H
23
24 #include "llvm/Pass.h"
25 #include "llvm/Instructions.h"
26 #include "llvm/Function.h"
27 #include "llvm/Support/DataTypes.h"
28 #include "llvm/Support/ValueHandle.h"
29 #include "llvm/Support/Allocator.h"
30 #include "llvm/Support/ConstantRange.h"
31 #include "llvm/ADT/FoldingSet.h"
32 #include "llvm/ADT/DenseMap.h"
33 #include <map>
34
35 namespace llvm {
36   class APInt;
37   class Constant;
38   class ConstantInt;
39   class DominatorTree;
40   class Type;
41   class ScalarEvolution;
42   class TargetData;
43   class LLVMContext;
44   class Loop;
45   class LoopInfo;
46   class Operator;
47
48   /// SCEV - This class represents an analyzed expression in the program.  These
49   /// are opaque objects that the client is not allowed to do much with
50   /// directly.
51   ///
52   class SCEV : public FastFoldingSetNode {
53     // The SCEV baseclass this node corresponds to
54     const unsigned short SCEVType;
55
56   protected:
57     /// SubclassData - This field is initialized to zero and may be used in
58     /// subclasses to store miscelaneous information.
59     unsigned short SubclassData;
60
61   private:
62     SCEV(const SCEV &);            // DO NOT IMPLEMENT
63     void operator=(const SCEV &);  // DO NOT IMPLEMENT
64   protected:
65     virtual ~SCEV();
66   public:
67     explicit SCEV(const FoldingSetNodeID &ID, unsigned SCEVTy) :
68       FastFoldingSetNode(ID), SCEVType(SCEVTy), SubclassData(0) {}
69
70     unsigned getSCEVType() const { return SCEVType; }
71
72     /// isLoopInvariant - Return true if the value of this SCEV is unchanging in
73     /// the specified loop.
74     virtual bool isLoopInvariant(const Loop *L) const = 0;
75
76     /// hasComputableLoopEvolution - Return true if this SCEV changes value in a
77     /// known way in the specified loop.  This property being true implies that
78     /// the value is variant in the loop AND that we can emit an expression to
79     /// compute the value of the expression at any particular loop iteration.
80     virtual bool hasComputableLoopEvolution(const Loop *L) const = 0;
81
82     /// getType - Return the LLVM type of this SCEV expression.
83     ///
84     virtual const Type *getType() const = 0;
85
86     /// isZero - Return true if the expression is a constant zero.
87     ///
88     bool isZero() const;
89
90     /// isOne - Return true if the expression is a constant one.
91     ///
92     bool isOne() const;
93
94     /// isAllOnesValue - Return true if the expression is a constant
95     /// all-ones value.
96     ///
97     bool isAllOnesValue() const;
98
99     /// hasOperand - Test whether this SCEV has Op as a direct or
100     /// indirect operand.
101     virtual bool hasOperand(const SCEV *Op) const = 0;
102
103     /// dominates - Return true if elements that makes up this SCEV dominates
104     /// the specified basic block.
105     virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const = 0;
106
107     /// print - Print out the internal representation of this scalar to the
108     /// specified stream.  This should really only be used for debugging
109     /// purposes.
110     virtual void print(raw_ostream &OS) const = 0;
111
112     /// dump - This method is used for debugging.
113     ///
114     void dump() const;
115   };
116
117   inline raw_ostream &operator<<(raw_ostream &OS, const SCEV &S) {
118     S.print(OS);
119     return OS;
120   }
121
122   /// SCEVCouldNotCompute - An object of this class is returned by queries that
123   /// could not be answered.  For example, if you ask for the number of
124   /// iterations of a linked-list traversal loop, you will get one of these.
125   /// None of the standard SCEV operations are valid on this class, it is just a
126   /// marker.
127   struct SCEVCouldNotCompute : public SCEV {
128     SCEVCouldNotCompute();
129
130     // None of these methods are valid for this object.
131     virtual bool isLoopInvariant(const Loop *L) const;
132     virtual const Type *getType() const;
133     virtual bool hasComputableLoopEvolution(const Loop *L) const;
134     virtual void print(raw_ostream &OS) const;
135     virtual bool hasOperand(const SCEV *Op) const;
136
137     virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const {
138       return true;
139     }
140
141     /// Methods for support type inquiry through isa, cast, and dyn_cast:
142     static inline bool classof(const SCEVCouldNotCompute *S) { return true; }
143     static bool classof(const SCEV *S);
144   };
145
146   /// ScalarEvolution - This class is the main scalar evolution driver.  Because
147   /// client code (intentionally) can't do much with the SCEV objects directly,
148   /// they must ask this class for services.
149   ///
150   class ScalarEvolution : public FunctionPass {
151     /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
152     /// notified whenever a Value is deleted.
153     class SCEVCallbackVH : public CallbackVH {
154       ScalarEvolution *SE;
155       virtual void deleted();
156       virtual void allUsesReplacedWith(Value *New);
157     public:
158       SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0);
159     };
160
161     friend class SCEVCallbackVH;
162     friend struct SCEVExpander;
163
164     /// F - The function we are analyzing.
165     ///
166     Function *F;
167
168     /// LI - The loop information for the function we are currently analyzing.
169     ///
170     LoopInfo *LI;
171
172     /// TD - The target data information for the target we are targetting.
173     ///
174     TargetData *TD;
175
176     /// CouldNotCompute - This SCEV is used to represent unknown trip
177     /// counts and things.
178     SCEVCouldNotCompute CouldNotCompute;
179
180     /// Scalars - This is a cache of the scalars we have analyzed so far.
181     ///
182     std::map<SCEVCallbackVH, const SCEV *> Scalars;
183
184     /// BackedgeTakenInfo - Information about the backedge-taken count
185     /// of a loop. This currently inclues an exact count and a maximum count.
186     ///
187     struct BackedgeTakenInfo {
188       /// Exact - An expression indicating the exact backedge-taken count of
189       /// the loop if it is known, or a SCEVCouldNotCompute otherwise.
190       const SCEV *Exact;
191
192       /// Max - An expression indicating the least maximum backedge-taken
193       /// count of the loop that is known, or a SCEVCouldNotCompute.
194       const SCEV *Max;
195
196       /*implicit*/ BackedgeTakenInfo(const SCEV *exact) :
197         Exact(exact), Max(exact) {}
198
199       BackedgeTakenInfo(const SCEV *exact, const SCEV *max) :
200         Exact(exact), Max(max) {}
201
202       /// hasAnyInfo - Test whether this BackedgeTakenInfo contains any
203       /// computed information, or whether it's all SCEVCouldNotCompute
204       /// values.
205       bool hasAnyInfo() const {
206         return !isa<SCEVCouldNotCompute>(Exact) ||
207                !isa<SCEVCouldNotCompute>(Max);
208       }
209     };
210
211     /// BackedgeTakenCounts - Cache the backedge-taken count of the loops for
212     /// this function as they are computed.
213     std::map<const Loop*, BackedgeTakenInfo> BackedgeTakenCounts;
214
215     /// ConstantEvolutionLoopExitValue - This map contains entries for all of
216     /// the PHI instructions that we attempt to compute constant evolutions for.
217     /// This allows us to avoid potentially expensive recomputation of these
218     /// properties.  An instruction maps to null if we are unable to compute its
219     /// exit value.
220     std::map<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
221
222     /// ValuesAtScopes - This map contains entries for all the expressions
223     /// that we attempt to compute getSCEVAtScope information for, which can
224     /// be expensive in extreme cases.
225     std::map<const SCEV *,
226              std::map<const Loop *, const SCEV *> > ValuesAtScopes;
227
228     /// createSCEV - We know that there is no SCEV for the specified value.
229     /// Analyze the expression.
230     const SCEV *createSCEV(Value *V);
231
232     /// createNodeForPHI - Provide the special handling we need to analyze PHI
233     /// SCEVs.
234     const SCEV *createNodeForPHI(PHINode *PN);
235
236     /// createNodeForGEP - Provide the special handling we need to analyze GEP
237     /// SCEVs.
238     const SCEV *createNodeForGEP(Operator *GEP);
239
240     /// computeSCEVAtScope - Implementation code for getSCEVAtScope; called
241     /// at most once for each SCEV+Loop pair.
242     ///
243     const SCEV *computeSCEVAtScope(const SCEV *S, const Loop *L);
244
245     /// ForgetSymbolicValue - This looks up computed SCEV values for all
246     /// instructions that depend on the given instruction and removes them from
247     /// the Scalars map if they reference SymName. This is used during PHI
248     /// resolution.
249     void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
250
251     /// getBECount - Subtract the end and start values and divide by the step,
252     /// rounding up, to get the number of times the backedge is executed. Return
253     /// CouldNotCompute if an intermediate computation overflows.
254     const SCEV *getBECount(const SCEV *Start,
255                            const SCEV *End,
256                            const SCEV *Step,
257                            bool NoWrap);
258
259     /// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given
260     /// loop, lazily computing new values if the loop hasn't been analyzed
261     /// yet.
262     const BackedgeTakenInfo &getBackedgeTakenInfo(const Loop *L);
263
264     /// ComputeBackedgeTakenCount - Compute the number of times the specified
265     /// loop will iterate.
266     BackedgeTakenInfo ComputeBackedgeTakenCount(const Loop *L);
267
268     /// ComputeBackedgeTakenCountFromExit - Compute the number of times the
269     /// backedge of the specified loop will execute if it exits via the
270     /// specified block.
271     BackedgeTakenInfo ComputeBackedgeTakenCountFromExit(const Loop *L,
272                                                       BasicBlock *ExitingBlock);
273
274     /// ComputeBackedgeTakenCountFromExitCond - Compute the number of times the
275     /// backedge of the specified loop will execute if its exit condition
276     /// were a conditional branch of ExitCond, TBB, and FBB.
277     BackedgeTakenInfo
278       ComputeBackedgeTakenCountFromExitCond(const Loop *L,
279                                             Value *ExitCond,
280                                             BasicBlock *TBB,
281                                             BasicBlock *FBB);
282
283     /// ComputeBackedgeTakenCountFromExitCondICmp - Compute the number of
284     /// times the backedge of the specified loop will execute if its exit
285     /// condition were a conditional branch of the ICmpInst ExitCond, TBB,
286     /// and FBB.
287     BackedgeTakenInfo
288       ComputeBackedgeTakenCountFromExitCondICmp(const Loop *L,
289                                                 ICmpInst *ExitCond,
290                                                 BasicBlock *TBB,
291                                                 BasicBlock *FBB);
292
293     /// ComputeLoadConstantCompareBackedgeTakenCount - Given an exit condition
294     /// of 'icmp op load X, cst', try to see if we can compute the
295     /// backedge-taken count.
296     const SCEV *
297       ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI,
298                                                    Constant *RHS,
299                                                    const Loop *L,
300                                                    ICmpInst::Predicate p);
301
302     /// ComputeBackedgeTakenCountExhaustively - If the loop is known to execute
303     /// a constant number of times (the condition evolves only from constants),
304     /// try to evaluate a few iterations of the loop until we get the exit
305     /// condition gets a value of ExitWhen (true or false).  If we cannot
306     /// evaluate the backedge-taken count of the loop, return CouldNotCompute.
307     const SCEV *ComputeBackedgeTakenCountExhaustively(const Loop *L,
308                                                       Value *Cond,
309                                                       bool ExitWhen);
310
311     /// HowFarToZero - Return the number of times a backedge comparing the
312     /// specified value to zero will execute.  If not computable, return
313     /// CouldNotCompute.
314     const SCEV *HowFarToZero(const SCEV *V, const Loop *L);
315
316     /// HowFarToNonZero - Return the number of times a backedge checking the
317     /// specified value for nonzero will execute.  If not computable, return
318     /// CouldNotCompute.
319     const SCEV *HowFarToNonZero(const SCEV *V, const Loop *L);
320
321     /// HowManyLessThans - Return the number of times a backedge containing the
322     /// specified less-than comparison will execute.  If not computable, return
323     /// CouldNotCompute. isSigned specifies whether the less-than is signed.
324     BackedgeTakenInfo HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
325                                        const Loop *L, bool isSigned);
326
327     /// getLoopPredecessor - If the given loop's header has exactly one unique
328     /// predecessor outside the loop, return it. Otherwise return null.
329     BasicBlock *getLoopPredecessor(const Loop *L);
330
331     /// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
332     /// (which may not be an immediate predecessor) which has exactly one
333     /// successor from which BB is reachable, or null if no such block is
334     /// found.
335     BasicBlock* getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB);
336
337     /// isImpliedCond - Test whether the condition described by Pred, LHS,
338     /// and RHS is true whenever the given Cond value evaluates to true.
339     bool isImpliedCond(Value *Cond, ICmpInst::Predicate Pred,
340                        const SCEV *LHS, const SCEV *RHS,
341                        bool Inverse);
342
343     /// isImpliedCondOperands - Test whether the condition described by Pred,
344     /// LHS, and RHS is true whenever the condition desribed by Pred, FoundLHS,
345     /// and FoundRHS is true.
346     bool isImpliedCondOperands(ICmpInst::Predicate Pred,
347                                const SCEV *LHS, const SCEV *RHS,
348                                const SCEV *FoundLHS, const SCEV *FoundRHS);
349
350     /// isImpliedCondOperandsHelper - Test whether the condition described by
351     /// Pred, LHS, and RHS is true whenever the condition desribed by Pred,
352     /// FoundLHS, and FoundRHS is true.
353     bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred,
354                                      const SCEV *LHS, const SCEV *RHS,
355                                      const SCEV *FoundLHS, const SCEV *FoundRHS);
356
357     /// getConstantEvolutionLoopExitValue - If we know that the specified Phi is
358     /// in the header of its containing loop, we know the loop executes a
359     /// constant number of times, and the PHI node is just a recurrence
360     /// involving constants, fold it.
361     Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs,
362                                                 const Loop *L);
363
364   public:
365     static char ID; // Pass identification, replacement for typeid
366     ScalarEvolution();
367
368     LLVMContext &getContext() const { return F->getContext(); }
369
370     /// isSCEVable - Test if values of the given type are analyzable within
371     /// the SCEV framework. This primarily includes integer types, and it
372     /// can optionally include pointer types if the ScalarEvolution class
373     /// has access to target-specific information.
374     bool isSCEVable(const Type *Ty) const;
375
376     /// getTypeSizeInBits - Return the size in bits of the specified type,
377     /// for which isSCEVable must return true.
378     uint64_t getTypeSizeInBits(const Type *Ty) const;
379
380     /// getEffectiveSCEVType - Return a type with the same bitwidth as
381     /// the given type and which represents how SCEV will treat the given
382     /// type, for which isSCEVable must return true. For pointer types,
383     /// this is the pointer-sized integer type.
384     const Type *getEffectiveSCEVType(const Type *Ty) const;
385
386     /// getSCEV - Return a SCEV expression for the full generality of the
387     /// specified expression.
388     const SCEV *getSCEV(Value *V);
389
390     const SCEV *getConstant(ConstantInt *V);
391     const SCEV *getConstant(const APInt& Val);
392     const SCEV *getConstant(const Type *Ty, uint64_t V, bool isSigned = false);
393     const SCEV *getTruncateExpr(const SCEV *Op, const Type *Ty);
394     const SCEV *getZeroExtendExpr(const SCEV *Op, const Type *Ty);
395     const SCEV *getSignExtendExpr(const SCEV *Op, const Type *Ty);
396     const SCEV *getAnyExtendExpr(const SCEV *Op, const Type *Ty);
397     const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops);
398     const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS) {
399       SmallVector<const SCEV *, 2> Ops;
400       Ops.push_back(LHS);
401       Ops.push_back(RHS);
402       return getAddExpr(Ops);
403     }
404     const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1,
405                            const SCEV *Op2) {
406       SmallVector<const SCEV *, 3> Ops;
407       Ops.push_back(Op0);
408       Ops.push_back(Op1);
409       Ops.push_back(Op2);
410       return getAddExpr(Ops);
411     }
412     const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops);
413     const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS) {
414       SmallVector<const SCEV *, 2> Ops;
415       Ops.push_back(LHS);
416       Ops.push_back(RHS);
417       return getMulExpr(Ops);
418     }
419     const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
420     const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
421                               const Loop *L);
422     const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
423                               const Loop *L);
424     const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
425                               const Loop *L) {
426       SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
427       return getAddRecExpr(NewOp, L);
428     }
429     const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
430     const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
431     const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS);
432     const SCEV *getUMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
433     const SCEV *getSMinExpr(const SCEV *LHS, const SCEV *RHS);
434     const SCEV *getUMinExpr(const SCEV *LHS, const SCEV *RHS);
435     const SCEV *getFieldOffsetExpr(const StructType *STy, unsigned FieldNo);
436     const SCEV *getAllocSizeExpr(const Type *AllocTy);
437     const SCEV *getUnknown(Value *V);
438     const SCEV *getCouldNotCompute();
439
440     /// getNegativeSCEV - Return the SCEV object corresponding to -V.
441     ///
442     const SCEV *getNegativeSCEV(const SCEV *V);
443
444     /// getNotSCEV - Return the SCEV object corresponding to ~V.
445     ///
446     const SCEV *getNotSCEV(const SCEV *V);
447
448     /// getMinusSCEV - Return LHS-RHS.
449     ///
450     const SCEV *getMinusSCEV(const SCEV *LHS,
451                              const SCEV *RHS);
452
453     /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion
454     /// of the input value to the specified type.  If the type must be
455     /// extended, it is zero extended.
456     const SCEV *getTruncateOrZeroExtend(const SCEV *V, const Type *Ty);
457
458     /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion
459     /// of the input value to the specified type.  If the type must be
460     /// extended, it is sign extended.
461     const SCEV *getTruncateOrSignExtend(const SCEV *V, const Type *Ty);
462
463     /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of
464     /// the input value to the specified type.  If the type must be extended,
465     /// it is zero extended.  The conversion must not be narrowing.
466     const SCEV *getNoopOrZeroExtend(const SCEV *V, const Type *Ty);
467
468     /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of
469     /// the input value to the specified type.  If the type must be extended,
470     /// it is sign extended.  The conversion must not be narrowing.
471     const SCEV *getNoopOrSignExtend(const SCEV *V, const Type *Ty);
472
473     /// getNoopOrAnyExtend - Return a SCEV corresponding to a conversion of
474     /// the input value to the specified type. If the type must be extended,
475     /// it is extended with unspecified bits. The conversion must not be
476     /// narrowing.
477     const SCEV *getNoopOrAnyExtend(const SCEV *V, const Type *Ty);
478
479     /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the
480     /// input value to the specified type.  The conversion must not be
481     /// widening.
482     const SCEV *getTruncateOrNoop(const SCEV *V, const Type *Ty);
483
484     /// getIntegerSCEV - Given a SCEVable type, create a constant for the
485     /// specified signed integer value and return a SCEV for the constant.
486     const SCEV *getIntegerSCEV(int Val, const Type *Ty);
487
488     /// getUMaxFromMismatchedTypes - Promote the operands to the wider of
489     /// the types using zero-extension, and then perform a umax operation
490     /// with them.
491     const SCEV *getUMaxFromMismatchedTypes(const SCEV *LHS,
492                                            const SCEV *RHS);
493
494     /// getUMinFromMismatchedTypes - Promote the operands to the wider of
495     /// the types using zero-extension, and then perform a umin operation
496     /// with them.
497     const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS,
498                                            const SCEV *RHS);
499
500     /// getSCEVAtScope - Return a SCEV expression for the specified value
501     /// at the specified scope in the program.  The L value specifies a loop
502     /// nest to evaluate the expression at, where null is the top-level or a
503     /// specified loop is immediately inside of the loop.
504     ///
505     /// This method can be used to compute the exit value for a variable defined
506     /// in a loop by querying what the value will hold in the parent loop.
507     ///
508     /// In the case that a relevant loop exit value cannot be computed, the
509     /// original value V is returned.
510     const SCEV *getSCEVAtScope(const SCEV *S, const Loop *L);
511
512     /// getSCEVAtScope - This is a convenience function which does
513     /// getSCEVAtScope(getSCEV(V), L).
514     const SCEV *getSCEVAtScope(Value *V, const Loop *L);
515
516     /// isLoopGuardedByCond - Test whether entry to the loop is protected by
517     /// a conditional between LHS and RHS.  This is used to help avoid max
518     /// expressions in loop trip counts, and to eliminate casts.
519     bool isLoopGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
520                              const SCEV *LHS, const SCEV *RHS);
521
522     /// isLoopBackedgeGuardedByCond - Test whether the backedge of the loop is
523     /// protected by a conditional between LHS and RHS.  This is used to
524     /// to eliminate casts.
525     bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
526                                      const SCEV *LHS, const SCEV *RHS);
527
528     /// getBackedgeTakenCount - If the specified loop has a predictable
529     /// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute
530     /// object. The backedge-taken count is the number of times the loop header
531     /// will be branched to from within the loop. This is one less than the
532     /// trip count of the loop, since it doesn't count the first iteration,
533     /// when the header is branched to from outside the loop.
534     ///
535     /// Note that it is not valid to call this method on a loop without a
536     /// loop-invariant backedge-taken count (see
537     /// hasLoopInvariantBackedgeTakenCount).
538     ///
539     const SCEV *getBackedgeTakenCount(const Loop *L);
540
541     /// getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except
542     /// return the least SCEV value that is known never to be less than the
543     /// actual backedge taken count.
544     const SCEV *getMaxBackedgeTakenCount(const Loop *L);
545
546     /// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop
547     /// has an analyzable loop-invariant backedge-taken count.
548     bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
549
550     /// forgetLoopBackedgeTakenCount - This method should be called by the
551     /// client when it has changed a loop in a way that may effect
552     /// ScalarEvolution's ability to compute a trip count, or if the loop
553     /// is deleted.
554     void forgetLoopBackedgeTakenCount(const Loop *L);
555
556     /// GetMinTrailingZeros - Determine the minimum number of zero bits that S
557     /// is guaranteed to end in (at every loop iteration).  It is, at the same
558     /// time, the minimum number of times S is divisible by 2.  For example,
559     /// given {4,+,8} it returns 2.  If S is guaranteed to be 0, it returns the
560     /// bitwidth of S.
561     uint32_t GetMinTrailingZeros(const SCEV *S);
562
563     /// getUnsignedRange - Determine the unsigned range for a particular SCEV.
564     ///
565     ConstantRange getUnsignedRange(const SCEV *S);
566
567     /// getSignedRange - Determine the signed range for a particular SCEV.
568     ///
569     ConstantRange getSignedRange(const SCEV *S);
570
571     /// isKnownNegative - Test if the given expression is known to be negative.
572     ///
573     bool isKnownNegative(const SCEV *S);
574
575     /// isKnownPositive - Test if the given expression is known to be positive.
576     ///
577     bool isKnownPositive(const SCEV *S);
578
579     /// isKnownNonNegative - Test if the given expression is known to be
580     /// non-negative.
581     ///
582     bool isKnownNonNegative(const SCEV *S);
583
584     /// isKnownNonPositive - Test if the given expression is known to be
585     /// non-positive.
586     ///
587     bool isKnownNonPositive(const SCEV *S);
588
589     /// isKnownNonZero - Test if the given expression is known to be
590     /// non-zero.
591     ///
592     bool isKnownNonZero(const SCEV *S);
593
594     /// isKnownNonZero - Test if the given expression is known to satisfy
595     /// the condition described by Pred, LHS, and RHS.
596     ///
597     bool isKnownPredicate(ICmpInst::Predicate Pred,
598                           const SCEV *LHS, const SCEV *RHS);
599
600     virtual bool runOnFunction(Function &F);
601     virtual void releaseMemory();
602     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
603     virtual void print(raw_ostream &OS, const Module* = 0) const;
604
605   private:
606     FoldingSet<SCEV> UniqueSCEVs;
607     BumpPtrAllocator SCEVAllocator;
608   };
609 }
610
611 #endif