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