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