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