Instead of eagerly creating new SCEVs to replace all SCEVs that are
[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/Support/DataTypes.h"
27 #include "llvm/Support/ValueHandle.h"
28 #include "llvm/Support/Allocator.h"
29 #include "llvm/Support/ConstantRange.h"
30 #include "llvm/ADT/FoldingSet.h"
31 #include "llvm/ADT/DenseMap.h"
32 #include <iosfwd>
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     void print(std::ostream &OS) const;
112     void print(std::ostream *OS) const { if (OS) print(*OS); }
113
114     /// dump - This method is used for debugging.
115     ///
116     void dump() const;
117   };
118
119   inline raw_ostream &operator<<(raw_ostream &OS, const SCEV &S) {
120     S.print(OS);
121     return OS;
122   }
123
124   inline std::ostream &operator<<(std::ostream &OS, const SCEV &S) {
125     S.print(OS);
126     return OS;
127   }
128
129   /// SCEVCouldNotCompute - An object of this class is returned by queries that
130   /// could not be answered.  For example, if you ask for the number of
131   /// iterations of a linked-list traversal loop, you will get one of these.
132   /// None of the standard SCEV operations are valid on this class, it is just a
133   /// marker.
134   struct SCEVCouldNotCompute : public SCEV {
135     SCEVCouldNotCompute();
136
137     // None of these methods are valid for this object.
138     virtual bool isLoopInvariant(const Loop *L) const;
139     virtual const Type *getType() const;
140     virtual bool hasComputableLoopEvolution(const Loop *L) const;
141     virtual void print(raw_ostream &OS) const;
142     virtual bool hasOperand(const SCEV *Op) const;
143
144     virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const {
145       return true;
146     }
147
148     /// Methods for support type inquiry through isa, cast, and dyn_cast:
149     static inline bool classof(const SCEVCouldNotCompute *S) { return true; }
150     static bool classof(const SCEV *S);
151   };
152
153   /// ScalarEvolution - This class is the main scalar evolution driver.  Because
154   /// client code (intentionally) can't do much with the SCEV objects directly,
155   /// they must ask this class for services.
156   ///
157   class ScalarEvolution : public FunctionPass {
158     /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
159     /// notified whenever a Value is deleted.
160     class SCEVCallbackVH : public CallbackVH {
161       ScalarEvolution *SE;
162       virtual void deleted();
163       virtual void allUsesReplacedWith(Value *New);
164     public:
165       SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0);
166     };
167
168     friend class SCEVCallbackVH;
169     friend struct SCEVExpander;
170
171     /// F - The function we are analyzing.
172     ///
173     Function *F;
174
175     /// LI - The loop information for the function we are currently analyzing.
176     ///
177     LoopInfo *LI;
178
179     /// TD - The target data information for the target we are targetting.
180     ///
181     TargetData *TD;
182
183     /// CouldNotCompute - This SCEV is used to represent unknown trip
184     /// counts and things.
185     SCEVCouldNotCompute CouldNotCompute;
186
187     /// Scalars - This is a cache of the scalars we have analyzed so far.
188     ///
189     std::map<SCEVCallbackVH, const SCEV *> Scalars;
190
191     /// BackedgeTakenInfo - Information about the backedge-taken count
192     /// of a loop. This currently inclues an exact count and a maximum count.
193     ///
194     struct BackedgeTakenInfo {
195       /// Exact - An expression indicating the exact backedge-taken count of
196       /// the loop if it is known, or a SCEVCouldNotCompute otherwise.
197       const SCEV *Exact;
198
199       /// Max - An expression indicating the least maximum backedge-taken
200       /// count of the loop that is known, or a SCEVCouldNotCompute.
201       const SCEV *Max;
202
203       /*implicit*/ BackedgeTakenInfo(const SCEV *exact) :
204         Exact(exact), Max(exact) {}
205
206       BackedgeTakenInfo(const SCEV *exact, const SCEV *max) :
207         Exact(exact), Max(max) {}
208
209       /// hasAnyInfo - Test whether this BackedgeTakenInfo contains any
210       /// computed information, or whether it's all SCEVCouldNotCompute
211       /// values.
212       bool hasAnyInfo() const {
213         return !isa<SCEVCouldNotCompute>(Exact) ||
214                !isa<SCEVCouldNotCompute>(Max);
215       }
216     };
217
218     /// BackedgeTakenCounts - Cache the backedge-taken count of the loops for
219     /// this function as they are computed.
220     std::map<const Loop*, BackedgeTakenInfo> BackedgeTakenCounts;
221
222     /// ConstantEvolutionLoopExitValue - This map contains entries for all of
223     /// the PHI instructions that we attempt to compute constant evolutions for.
224     /// This allows us to avoid potentially expensive recomputation of these
225     /// properties.  An instruction maps to null if we are unable to compute its
226     /// exit value.
227     std::map<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
228
229     /// ValuesAtScopes - This map contains entries for all the instructions
230     /// that we attempt to compute getSCEVAtScope information for without
231     /// using SCEV techniques, which can be expensive.
232     std::map<Instruction *, std::map<const Loop *, Constant *> > ValuesAtScopes;
233
234     /// createSCEV - We know that there is no SCEV for the specified value.
235     /// Analyze the expression.
236     const SCEV *createSCEV(Value *V);
237
238     /// createNodeForPHI - Provide the special handling we need to analyze PHI
239     /// SCEVs.
240     const SCEV *createNodeForPHI(PHINode *PN);
241
242     /// createNodeForGEP - Provide the special handling we need to analyze GEP
243     /// SCEVs.
244     const SCEV *createNodeForGEP(Operator *GEP);
245
246     /// ForgetSymbolicValue - This looks up computed SCEV values for all
247     /// instructions that depend on the given instruction and removes them from
248     /// the Scalars map if they reference SymName. This is used during PHI
249     /// resolution.
250     void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
251
252     /// getBECount - Subtract the end and start values and divide by the step,
253     /// rounding up, to get the number of times the backedge is executed. Return
254     /// CouldNotCompute if an intermediate computation overflows.
255     const SCEV *getBECount(const SCEV *Start,
256                            const SCEV *End,
257                            const SCEV *Step);
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 trip count.
295     const SCEV *
296       ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI,
297                                                    Constant *RHS,
298                                                    const Loop *L,
299                                                    ICmpInst::Predicate p);
300
301     /// ComputeBackedgeTakenCountExhaustively - If the trip is known to execute
302     /// a constant number of times (the condition evolves only from constants),
303     /// try to evaluate a few iterations of the loop until we get the exit
304     /// condition gets a value of ExitWhen (true or false).  If we cannot
305     /// evaluate the trip count of the loop, return CouldNotCompute.
306     const SCEV *ComputeBackedgeTakenCountExhaustively(const Loop *L,
307                                                       Value *Cond,
308                                                       bool ExitWhen);
309
310     /// HowFarToZero - Return the number of times a backedge comparing the
311     /// specified value to zero will execute.  If not computable, return
312     /// CouldNotCompute.
313     const SCEV *HowFarToZero(const SCEV *V, const Loop *L);
314
315     /// HowFarToNonZero - Return the number of times a backedge checking the
316     /// specified value for nonzero will execute.  If not computable, return
317     /// CouldNotCompute.
318     const SCEV *HowFarToNonZero(const SCEV *V, const Loop *L);
319
320     /// HowManyLessThans - Return the number of times a backedge containing the
321     /// specified less-than comparison will execute.  If not computable, return
322     /// CouldNotCompute. isSigned specifies whether the less-than is signed.
323     BackedgeTakenInfo HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
324                                        const Loop *L, bool isSigned);
325
326     /// getLoopPredecessor - If the given loop's header has exactly one unique
327     /// predecessor outside the loop, return it. Otherwise return null.
328     BasicBlock *getLoopPredecessor(const Loop *L);
329
330     /// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
331     /// (which may not be an immediate predecessor) which has exactly one
332     /// successor from which BB is reachable, or null if no such block is
333     /// found.
334     BasicBlock* getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB);
335
336     /// isImpliedCond - Test whether the condition described by Pred, LHS,
337     /// and RHS is true whenever the given Cond value evaluates to true.
338     bool isImpliedCond(Value *Cond, ICmpInst::Predicate Pred,
339                        const SCEV *LHS, const SCEV *RHS,
340                        bool Inverse);
341
342     /// isImpliedCondOperands - Test whether the condition described by Pred,
343     /// LHS, and RHS is true whenever the condition desribed by Pred, FoundLHS,
344     /// and FoundRHS is true.
345     bool isImpliedCondOperands(ICmpInst::Predicate Pred,
346                                const SCEV *LHS, const SCEV *RHS,
347                                const SCEV *FoundLHS, const SCEV *FoundRHS);
348
349     /// isImpliedCondOperandsHelper - Test whether the condition described by
350     /// Pred, LHS, and RHS is true whenever the condition desribed by Pred,
351     /// FoundLHS, and FoundRHS is true.
352     bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred,
353                                      const SCEV *LHS, const SCEV *RHS,
354                                      const SCEV *FoundLHS, const SCEV *FoundRHS);
355
356     /// getConstantEvolutionLoopExitValue - If we know that the specified Phi is
357     /// in the header of its containing loop, we know the loop executes a
358     /// constant number of times, and the PHI node is just a recurrence
359     /// involving constants, fold it.
360     Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs,
361                                                 const Loop *L);
362
363   public:
364     static char ID; // Pass identification, replacement for typeid
365     ScalarEvolution();
366
367     LLVMContext &getContext() const { return F->getContext(); }
368
369     /// isSCEVable - Test if values of the given type are analyzable within
370     /// the SCEV framework. This primarily includes integer types, and it
371     /// can optionally include pointer types if the ScalarEvolution class
372     /// has access to target-specific information.
373     bool isSCEVable(const Type *Ty) const;
374
375     /// getTypeSizeInBits - Return the size in bits of the specified type,
376     /// for which isSCEVable must return true.
377     uint64_t getTypeSizeInBits(const Type *Ty) const;
378
379     /// getEffectiveSCEVType - Return a type with the same bitwidth as
380     /// the given type and which represents how SCEV will treat the given
381     /// type, for which isSCEVable must return true. For pointer types,
382     /// this is the pointer-sized integer type.
383     const Type *getEffectiveSCEVType(const Type *Ty) const;
384
385     /// getSCEV - Return a SCEV expression handle for the full generality of the
386     /// specified expression.
387     const SCEV *getSCEV(Value *V);
388
389     const SCEV *getConstant(ConstantInt *V);
390     const SCEV *getConstant(const APInt& Val);
391     const SCEV *getConstant(const Type *Ty, uint64_t V, bool isSigned = false);
392     const SCEV *getTruncateExpr(const SCEV *Op, const Type *Ty);
393     const SCEV *getZeroExtendExpr(const SCEV *Op, const Type *Ty);
394     const SCEV *getSignExtendExpr(const SCEV *Op, const Type *Ty);
395     const SCEV *getAnyExtendExpr(const SCEV *Op, const Type *Ty);
396     const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops);
397     const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS) {
398       SmallVector<const SCEV *, 2> Ops;
399       Ops.push_back(LHS);
400       Ops.push_back(RHS);
401       return getAddExpr(Ops);
402     }
403     const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1,
404                            const SCEV *Op2) {
405       SmallVector<const SCEV *, 3> Ops;
406       Ops.push_back(Op0);
407       Ops.push_back(Op1);
408       Ops.push_back(Op2);
409       return getAddExpr(Ops);
410     }
411     const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops);
412     const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS) {
413       SmallVector<const SCEV *, 2> Ops;
414       Ops.push_back(LHS);
415       Ops.push_back(RHS);
416       return getMulExpr(Ops);
417     }
418     const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
419     const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
420                               const Loop *L);
421     const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
422                               const Loop *L);
423     const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
424                               const Loop *L) {
425       SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
426       return getAddRecExpr(NewOp, L);
427     }
428     const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
429     const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
430     const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS);
431     const SCEV *getUMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
432     const SCEV *getSMinExpr(const SCEV *LHS, const SCEV *RHS);
433     const SCEV *getUMinExpr(const SCEV *LHS, const SCEV *RHS);
434     const SCEV *getUnknown(Value *V);
435     const SCEV *getCouldNotCompute();
436
437     /// getNegativeSCEV - Return the SCEV object corresponding to -V.
438     ///
439     const SCEV *getNegativeSCEV(const SCEV *V);
440
441     /// getNotSCEV - Return the SCEV object corresponding to ~V.
442     ///
443     const SCEV *getNotSCEV(const SCEV *V);
444
445     /// getMinusSCEV - Return LHS-RHS.
446     ///
447     const SCEV *getMinusSCEV(const SCEV *LHS,
448                              const SCEV *RHS);
449
450     /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion
451     /// of the input value to the specified type.  If the type must be
452     /// extended, it is zero extended.
453     const SCEV *getTruncateOrZeroExtend(const SCEV *V, const Type *Ty);
454
455     /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion
456     /// of the input value to the specified type.  If the type must be
457     /// extended, it is sign extended.
458     const SCEV *getTruncateOrSignExtend(const SCEV *V, const Type *Ty);
459
460     /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of
461     /// the input value to the specified type.  If the type must be extended,
462     /// it is zero extended.  The conversion must not be narrowing.
463     const SCEV *getNoopOrZeroExtend(const SCEV *V, const Type *Ty);
464
465     /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of
466     /// the input value to the specified type.  If the type must be extended,
467     /// it is sign extended.  The conversion must not be narrowing.
468     const SCEV *getNoopOrSignExtend(const SCEV *V, const Type *Ty);
469
470     /// getNoopOrAnyExtend - Return a SCEV corresponding to a conversion of
471     /// the input value to the specified type. If the type must be extended,
472     /// it is extended with unspecified bits. The conversion must not be
473     /// narrowing.
474     const SCEV *getNoopOrAnyExtend(const SCEV *V, const Type *Ty);
475
476     /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the
477     /// input value to the specified type.  The conversion must not be
478     /// widening.
479     const SCEV *getTruncateOrNoop(const SCEV *V, const Type *Ty);
480
481     /// getIntegerSCEV - Given a SCEVable type, create a constant for the
482     /// specified signed integer value and return a SCEV for the constant.
483     const SCEV *getIntegerSCEV(int Val, const Type *Ty);
484
485     /// getUMaxFromMismatchedTypes - Promote the operands to the wider of
486     /// the types using zero-extension, and then perform a umax operation
487     /// with them.
488     const SCEV *getUMaxFromMismatchedTypes(const SCEV *LHS,
489                                            const SCEV *RHS);
490
491     /// getUMinFromMismatchedTypes - Promote the operands to the wider of
492     /// the types using zero-extension, and then perform a umin operation
493     /// with them.
494     const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS,
495                                            const SCEV *RHS);
496
497     /// getSCEVAtScope - Return a SCEV expression handle for the specified value
498     /// at the specified scope in the program.  The L value specifies a loop
499     /// nest to evaluate the expression at, where null is the top-level or a
500     /// specified loop is immediately inside of the loop.
501     ///
502     /// This method can be used to compute the exit value for a variable defined
503     /// in a loop by querying what the value will hold in the parent loop.
504     ///
505     /// In the case that a relevant loop exit value cannot be computed, the
506     /// original value V is returned.
507     const SCEV *getSCEVAtScope(const SCEV *S, const Loop *L);
508
509     /// getSCEVAtScope - This is a convenience function which does
510     /// getSCEVAtScope(getSCEV(V), L).
511     const SCEV *getSCEVAtScope(Value *V, const Loop *L);
512
513     /// isLoopGuardedByCond - Test whether entry to the loop is protected by
514     /// a conditional between LHS and RHS.  This is used to help avoid max
515     /// expressions in loop trip counts, and to eliminate casts.
516     bool isLoopGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
517                              const SCEV *LHS, const SCEV *RHS);
518
519     /// isLoopBackedgeGuardedByCond - Test whether the backedge of the loop is
520     /// protected by a conditional between LHS and RHS.  This is used to
521     /// to eliminate casts.
522     bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
523                                      const SCEV *LHS, const SCEV *RHS);
524
525     /// getBackedgeTakenCount - If the specified loop has a predictable
526     /// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute
527     /// object. The backedge-taken count is the number of times the loop header
528     /// will be branched to from within the loop. This is one less than the
529     /// trip count of the loop, since it doesn't count the first iteration,
530     /// when the header is branched to from outside the loop.
531     ///
532     /// Note that it is not valid to call this method on a loop without a
533     /// loop-invariant backedge-taken count (see
534     /// hasLoopInvariantBackedgeTakenCount).
535     ///
536     const SCEV *getBackedgeTakenCount(const Loop *L);
537
538     /// getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except
539     /// return the least SCEV value that is known never to be less than the
540     /// actual backedge taken count.
541     const SCEV *getMaxBackedgeTakenCount(const Loop *L);
542
543     /// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop
544     /// has an analyzable loop-invariant backedge-taken count.
545     bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
546
547     /// forgetLoopBackedgeTakenCount - This method should be called by the
548     /// client when it has changed a loop in a way that may effect
549     /// ScalarEvolution's ability to compute a trip count, or if the loop
550     /// is deleted.
551     void forgetLoopBackedgeTakenCount(const Loop *L);
552
553     /// GetMinTrailingZeros - Determine the minimum number of zero bits that S
554     /// is guaranteed to end in (at every loop iteration).  It is, at the same
555     /// time, the minimum number of times S is divisible by 2.  For example,
556     /// given {4,+,8} it returns 2.  If S is guaranteed to be 0, it returns the
557     /// bitwidth of S.
558     uint32_t GetMinTrailingZeros(const SCEV *S);
559
560     /// getUnsignedRange - Determine the unsigned range for a particular SCEV.
561     ///
562     ConstantRange getUnsignedRange(const SCEV *S);
563
564     /// getSignedRange - Determine the signed range for a particular SCEV.
565     ///
566     ConstantRange getSignedRange(const SCEV *S);
567
568     /// isKnownNegative - Test if the given expression is known to be negative.
569     ///
570     bool isKnownNegative(const SCEV *S);
571
572     /// isKnownPositive - Test if the given expression is known to be positive.
573     ///
574     bool isKnownPositive(const SCEV *S);
575
576     /// isKnownNonNegative - Test if the given expression is known to be
577     /// non-negative.
578     ///
579     bool isKnownNonNegative(const SCEV *S);
580
581     /// isKnownNonPositive - Test if the given expression is known to be
582     /// non-positive.
583     ///
584     bool isKnownNonPositive(const SCEV *S);
585
586     /// isKnownNonZero - Test if the given expression is known to be
587     /// non-zero.
588     ///
589     bool isKnownNonZero(const SCEV *S);
590
591     /// isKnownNonZero - Test if the given expression is known to satisfy
592     /// the condition described by Pred, LHS, and RHS.
593     ///
594     bool isKnownPredicate(ICmpInst::Predicate Pred,
595                           const SCEV *LHS, const SCEV *RHS);
596
597     virtual bool runOnFunction(Function &F);
598     virtual void releaseMemory();
599     virtual void getAnalysisUsage(AnalysisUsage &AU) const;
600     void print(raw_ostream &OS, const Module* = 0) const;
601     virtual void print(std::ostream &OS, const Module* = 0) const;
602     void print(std::ostream *OS, const Module* M = 0) const {
603       if (OS) print(*OS, M);
604     }
605
606   private:
607     FoldingSet<SCEV> UniqueSCEVs;
608     BumpPtrAllocator SCEVAllocator;
609   };
610 }
611
612 #endif