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