1 //===- llvm/Analysis/ScalarEvolution.h - Scalar Evolution -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // The ScalarEvolution class is an LLVM pass which can be used to analyze and
11 // categorize 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.
16 // This analysis is primarily useful for induction variable substitution and
17 // strength reduction.
19 //===----------------------------------------------------------------------===//
21 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H
22 #define LLVM_ANALYSIS_SCALAREVOLUTION_H
24 #include "llvm/Pass.h"
25 #include "llvm/Instructions.h"
26 #include "llvm/Function.h"
27 #include "llvm/System/DataTypes.h"
28 #include "llvm/Support/ValueHandle.h"
29 #include "llvm/Support/Allocator.h"
30 #include "llvm/Support/ConstantRange.h"
31 #include "llvm/ADT/FoldingSet.h"
32 #include "llvm/ADT/DenseMap.h"
41 class ScalarEvolution;
49 template<> struct FoldingSetTrait<SCEV>;
51 /// SCEV - This class represents an analyzed expression in the program. These
52 /// are opaque objects that the client is not allowed to do much with
55 class SCEV : public FoldingSetNode {
56 friend struct FoldingSetTrait<SCEV>;
58 /// FastID - A reference to an Interned FoldingSetNodeID for this node.
59 /// The ScalarEvolution's BumpPtrAllocator holds the data.
60 FoldingSetNodeIDRef FastID;
62 // The SCEV baseclass this node corresponds to
63 const unsigned short SCEVType;
66 /// SubclassData - This field is initialized to zero and may be used in
67 /// subclasses to store miscellaneous information.
68 unsigned short SubclassData;
71 SCEV(const SCEV &); // DO NOT IMPLEMENT
72 void operator=(const SCEV &); // DO NOT IMPLEMENT
76 explicit SCEV(const FoldingSetNodeIDRef ID, unsigned SCEVTy) :
77 FastID(ID), SCEVType(SCEVTy), SubclassData(0) {}
79 unsigned getSCEVType() const { return SCEVType; }
81 /// isLoopInvariant - Return true if the value of this SCEV is unchanging in
82 /// the specified loop.
83 virtual bool isLoopInvariant(const Loop *L) const = 0;
85 /// hasComputableLoopEvolution - Return true if this SCEV changes value in a
86 /// known way in the specified loop. This property being true implies that
87 /// the value is variant in the loop AND that we can emit an expression to
88 /// compute the value of the expression at any particular loop iteration.
89 virtual bool hasComputableLoopEvolution(const Loop *L) const = 0;
91 /// getType - Return the LLVM type of this SCEV expression.
93 virtual const Type *getType() const = 0;
95 /// isZero - Return true if the expression is a constant zero.
99 /// isOne - Return true if the expression is a constant one.
103 /// isAllOnesValue - Return true if the expression is a constant
106 bool isAllOnesValue() const;
108 /// hasOperand - Test whether this SCEV has Op as a direct or
109 /// indirect operand.
110 virtual bool hasOperand(const SCEV *Op) const = 0;
112 /// dominates - Return true if elements that makes up this SCEV dominates
113 /// the specified basic block.
114 virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const = 0;
116 /// properlyDominates - Return true if elements that makes up this SCEV
117 /// properly dominate the specified basic block.
118 virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const = 0;
120 /// print - Print out the internal representation of this scalar to the
121 /// specified stream. This should really only be used for debugging
123 virtual void print(raw_ostream &OS) const = 0;
125 /// dump - This method is used for debugging.
130 // Specialize FoldingSetTrait for SCEV to avoid needing to compute
131 // temporary FoldingSetNodeID values.
132 template<> struct FoldingSetTrait<SCEV> : DefaultFoldingSetTrait<SCEV> {
133 static void Profile(const SCEV &X, FoldingSetNodeID& ID) {
136 static bool Equals(const SCEV &X, const FoldingSetNodeID &ID,
137 FoldingSetNodeID &TempID) {
138 return ID == X.FastID;
140 static unsigned ComputeHash(const SCEV &X, FoldingSetNodeID &TempID) {
141 return X.FastID.ComputeHash();
145 inline raw_ostream &operator<<(raw_ostream &OS, const SCEV &S) {
150 /// SCEVCouldNotCompute - An object of this class is returned by queries that
151 /// could not be answered. For example, if you ask for the number of
152 /// iterations of a linked-list traversal loop, you will get one of these.
153 /// None of the standard SCEV operations are valid on this class, it is just a
155 struct SCEVCouldNotCompute : public SCEV {
156 SCEVCouldNotCompute();
158 // None of these methods are valid for this object.
159 virtual bool isLoopInvariant(const Loop *L) const;
160 virtual const Type *getType() const;
161 virtual bool hasComputableLoopEvolution(const Loop *L) const;
162 virtual void print(raw_ostream &OS) const;
163 virtual bool hasOperand(const SCEV *Op) const;
165 virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const {
169 virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const {
173 /// Methods for support type inquiry through isa, cast, and dyn_cast:
174 static inline bool classof(const SCEVCouldNotCompute *S) { return true; }
175 static bool classof(const SCEV *S);
178 /// ScalarEvolution - This class is the main scalar evolution driver. Because
179 /// client code (intentionally) can't do much with the SCEV objects directly,
180 /// they must ask this class for services.
182 class ScalarEvolution : public FunctionPass {
183 /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
184 /// notified whenever a Value is deleted.
185 class SCEVCallbackVH : public CallbackVH {
187 virtual void deleted();
188 virtual void allUsesReplacedWith(Value *New);
190 SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0);
193 friend class SCEVCallbackVH;
194 friend class SCEVExpander;
195 friend class SCEVUnknown;
197 /// F - The function we are analyzing.
201 /// LI - The loop information for the function we are currently analyzing.
205 /// TD - The target data information for the target we are targeting.
209 /// DT - The dominator tree.
213 /// CouldNotCompute - This SCEV is used to represent unknown trip
214 /// counts and things.
215 SCEVCouldNotCompute CouldNotCompute;
217 /// Scalars - This is a cache of the scalars we have analyzed so far.
219 std::map<SCEVCallbackVH, const SCEV *> Scalars;
221 /// BackedgeTakenInfo - Information about the backedge-taken count
222 /// of a loop. This currently includes an exact count and a maximum count.
224 struct BackedgeTakenInfo {
225 /// Exact - An expression indicating the exact backedge-taken count of
226 /// the loop if it is known, or a SCEVCouldNotCompute otherwise.
229 /// Max - An expression indicating the least maximum backedge-taken
230 /// count of the loop that is known, or a SCEVCouldNotCompute.
233 /*implicit*/ BackedgeTakenInfo(const SCEV *exact) :
234 Exact(exact), Max(exact) {}
236 BackedgeTakenInfo(const SCEV *exact, const SCEV *max) :
237 Exact(exact), Max(max) {}
239 /// hasAnyInfo - Test whether this BackedgeTakenInfo contains any
240 /// computed information, or whether it's all SCEVCouldNotCompute
242 bool hasAnyInfo() const {
243 return !isa<SCEVCouldNotCompute>(Exact) ||
244 !isa<SCEVCouldNotCompute>(Max);
248 /// BackedgeTakenCounts - Cache the backedge-taken count of the loops for
249 /// this function as they are computed.
250 std::map<const Loop*, BackedgeTakenInfo> BackedgeTakenCounts;
252 /// ConstantEvolutionLoopExitValue - This map contains entries for all of
253 /// the PHI instructions that we attempt to compute constant evolutions for.
254 /// This allows us to avoid potentially expensive recomputation of these
255 /// properties. An instruction maps to null if we are unable to compute its
257 std::map<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
259 /// ValuesAtScopes - This map contains entries for all the expressions
260 /// that we attempt to compute getSCEVAtScope information for, which can
261 /// be expensive in extreme cases.
262 std::map<const SCEV *,
263 std::map<const Loop *, const SCEV *> > ValuesAtScopes;
265 /// createSCEV - We know that there is no SCEV for the specified value.
266 /// Analyze the expression.
267 const SCEV *createSCEV(Value *V);
269 /// createNodeForPHI - Provide the special handling we need to analyze PHI
271 const SCEV *createNodeForPHI(PHINode *PN);
273 /// createNodeForGEP - Provide the special handling we need to analyze GEP
275 const SCEV *createNodeForGEP(GEPOperator *GEP);
277 /// computeSCEVAtScope - Implementation code for getSCEVAtScope; called
278 /// at most once for each SCEV+Loop pair.
280 const SCEV *computeSCEVAtScope(const SCEV *S, const Loop *L);
282 /// ForgetSymbolicValue - This looks up computed SCEV values for all
283 /// instructions that depend on the given instruction and removes them from
284 /// the Scalars map if they reference SymName. This is used during PHI
286 void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
288 /// getBECount - Subtract the end and start values and divide by the step,
289 /// rounding up, to get the number of times the backedge is executed. Return
290 /// CouldNotCompute if an intermediate computation overflows.
291 const SCEV *getBECount(const SCEV *Start,
296 /// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given
297 /// loop, lazily computing new values if the loop hasn't been analyzed
299 const BackedgeTakenInfo &getBackedgeTakenInfo(const Loop *L);
301 /// ComputeBackedgeTakenCount - Compute the number of times the specified
302 /// loop will iterate.
303 BackedgeTakenInfo ComputeBackedgeTakenCount(const Loop *L);
305 /// ComputeBackedgeTakenCountFromExit - Compute the number of times the
306 /// backedge of the specified loop will execute if it exits via the
308 BackedgeTakenInfo ComputeBackedgeTakenCountFromExit(const Loop *L,
309 BasicBlock *ExitingBlock);
311 /// ComputeBackedgeTakenCountFromExitCond - Compute the number of times the
312 /// backedge of the specified loop will execute if its exit condition
313 /// were a conditional branch of ExitCond, TBB, and FBB.
315 ComputeBackedgeTakenCountFromExitCond(const Loop *L,
320 /// ComputeBackedgeTakenCountFromExitCondICmp - Compute the number of
321 /// times the backedge of the specified loop will execute if its exit
322 /// condition were a conditional branch of the ICmpInst ExitCond, TBB,
325 ComputeBackedgeTakenCountFromExitCondICmp(const Loop *L,
330 /// ComputeLoadConstantCompareBackedgeTakenCount - Given an exit condition
331 /// of 'icmp op load X, cst', try to see if we can compute the
332 /// backedge-taken count.
334 ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI,
337 ICmpInst::Predicate p);
339 /// ComputeBackedgeTakenCountExhaustively - If the loop is known to execute
340 /// a constant number of times (the condition evolves only from constants),
341 /// try to evaluate a few iterations of the loop until we get the exit
342 /// condition gets a value of ExitWhen (true or false). If we cannot
343 /// evaluate the backedge-taken count of the loop, return CouldNotCompute.
344 const SCEV *ComputeBackedgeTakenCountExhaustively(const Loop *L,
348 /// HowFarToZero - Return the number of times a backedge comparing the
349 /// specified value to zero will execute. If not computable, return
351 BackedgeTakenInfo HowFarToZero(const SCEV *V, const Loop *L);
353 /// HowFarToNonZero - Return the number of times a backedge checking the
354 /// specified value for nonzero will execute. If not computable, return
356 BackedgeTakenInfo HowFarToNonZero(const SCEV *V, const Loop *L);
358 /// HowManyLessThans - Return the number of times a backedge containing the
359 /// specified less-than comparison will execute. If not computable, return
360 /// CouldNotCompute. isSigned specifies whether the less-than is signed.
361 BackedgeTakenInfo HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
362 const Loop *L, bool isSigned);
364 /// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
365 /// (which may not be an immediate predecessor) which has exactly one
366 /// successor from which BB is reachable, or null if no such block is
368 std::pair<BasicBlock *, BasicBlock *>
369 getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB);
371 /// isImpliedCond - Test whether the condition described by Pred, LHS, and
372 /// RHS is true whenever the given FoundCondValue value evaluates to true.
373 bool isImpliedCond(ICmpInst::Predicate Pred,
374 const SCEV *LHS, const SCEV *RHS,
375 Value *FoundCondValue,
378 /// isImpliedCondOperands - Test whether the condition described by Pred,
379 /// LHS, and RHS is true whenever the condition described by Pred, FoundLHS,
380 /// and FoundRHS is true.
381 bool isImpliedCondOperands(ICmpInst::Predicate Pred,
382 const SCEV *LHS, const SCEV *RHS,
383 const SCEV *FoundLHS, const SCEV *FoundRHS);
385 /// isImpliedCondOperandsHelper - Test whether the condition described by
386 /// Pred, LHS, and RHS is true whenever the condition described by Pred,
387 /// FoundLHS, and FoundRHS is true.
388 bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred,
389 const SCEV *LHS, const SCEV *RHS,
390 const SCEV *FoundLHS, const SCEV *FoundRHS);
392 /// getConstantEvolutionLoopExitValue - If we know that the specified Phi is
393 /// in the header of its containing loop, we know the loop executes a
394 /// constant number of times, and the PHI node is just a recurrence
395 /// involving constants, fold it.
396 Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs,
399 /// isKnownPredicateWithRanges - Test if the given expression is known to
400 /// satisfy the condition described by Pred and the known constant ranges
403 bool isKnownPredicateWithRanges(ICmpInst::Predicate Pred,
404 const SCEV *LHS, const SCEV *RHS);
407 static char ID; // Pass identification, replacement for typeid
410 LLVMContext &getContext() const { return F->getContext(); }
412 /// isSCEVable - Test if values of the given type are analyzable within
413 /// the SCEV framework. This primarily includes integer types, and it
414 /// can optionally include pointer types if the ScalarEvolution class
415 /// has access to target-specific information.
416 bool isSCEVable(const Type *Ty) const;
418 /// getTypeSizeInBits - Return the size in bits of the specified type,
419 /// for which isSCEVable must return true.
420 uint64_t getTypeSizeInBits(const Type *Ty) const;
422 /// getEffectiveSCEVType - Return a type with the same bitwidth as
423 /// the given type and which represents how SCEV will treat the given
424 /// type, for which isSCEVable must return true. For pointer types,
425 /// this is the pointer-sized integer type.
426 const Type *getEffectiveSCEVType(const Type *Ty) const;
428 /// getSCEV - Return a SCEV expression for the full generality of the
429 /// specified expression.
430 const SCEV *getSCEV(Value *V);
432 const SCEV *getConstant(ConstantInt *V);
433 const SCEV *getConstant(const APInt& Val);
434 const SCEV *getConstant(const Type *Ty, uint64_t V, bool isSigned = false);
435 const SCEV *getTruncateExpr(const SCEV *Op, const Type *Ty);
436 const SCEV *getZeroExtendExpr(const SCEV *Op, const Type *Ty);
437 const SCEV *getSignExtendExpr(const SCEV *Op, const Type *Ty);
438 const SCEV *getAnyExtendExpr(const SCEV *Op, const Type *Ty);
439 const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
440 bool HasNUW = false, bool HasNSW = false);
441 const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS,
442 bool HasNUW = false, bool HasNSW = false) {
443 SmallVector<const SCEV *, 2> Ops;
446 return getAddExpr(Ops, HasNUW, HasNSW);
448 const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1,
450 bool HasNUW = false, bool HasNSW = false) {
451 SmallVector<const SCEV *, 3> Ops;
455 return getAddExpr(Ops, HasNUW, HasNSW);
457 const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
458 bool HasNUW = false, bool HasNSW = false);
459 const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS,
460 bool HasNUW = false, bool HasNSW = false) {
461 SmallVector<const SCEV *, 2> Ops;
464 return getMulExpr(Ops, HasNUW, HasNSW);
466 const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
467 const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
469 bool HasNUW = false, bool HasNSW = false);
470 const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
472 bool HasNUW = false, bool HasNSW = false);
473 const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
475 bool HasNUW = false, bool HasNSW = false) {
476 SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
477 return getAddRecExpr(NewOp, L, HasNUW, HasNSW);
479 const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
480 const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
481 const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS);
482 const SCEV *getUMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
483 const SCEV *getSMinExpr(const SCEV *LHS, const SCEV *RHS);
484 const SCEV *getUMinExpr(const SCEV *LHS, const SCEV *RHS);
485 const SCEV *getUnknown(Value *V);
486 const SCEV *getCouldNotCompute();
488 /// getSizeOfExpr - Return an expression for sizeof on the given type.
490 const SCEV *getSizeOfExpr(const Type *AllocTy);
492 /// getAlignOfExpr - Return an expression for alignof on the given type.
494 const SCEV *getAlignOfExpr(const Type *AllocTy);
496 /// getOffsetOfExpr - Return an expression for offsetof on the given field.
498 const SCEV *getOffsetOfExpr(const StructType *STy, unsigned FieldNo);
500 /// getOffsetOfExpr - Return an expression for offsetof on the given field.
502 const SCEV *getOffsetOfExpr(const Type *CTy, Constant *FieldNo);
504 /// getNegativeSCEV - Return the SCEV object corresponding to -V.
506 const SCEV *getNegativeSCEV(const SCEV *V);
508 /// getNotSCEV - Return the SCEV object corresponding to ~V.
510 const SCEV *getNotSCEV(const SCEV *V);
512 /// getMinusSCEV - Return LHS-RHS.
514 const SCEV *getMinusSCEV(const SCEV *LHS,
517 /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion
518 /// of the input value to the specified type. If the type must be
519 /// extended, it is zero extended.
520 const SCEV *getTruncateOrZeroExtend(const SCEV *V, const Type *Ty);
522 /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion
523 /// of the input value to the specified type. If the type must be
524 /// extended, it is sign extended.
525 const SCEV *getTruncateOrSignExtend(const SCEV *V, const Type *Ty);
527 /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of
528 /// the input value to the specified type. If the type must be extended,
529 /// it is zero extended. The conversion must not be narrowing.
530 const SCEV *getNoopOrZeroExtend(const SCEV *V, const Type *Ty);
532 /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of
533 /// the input value to the specified type. If the type must be extended,
534 /// it is sign extended. The conversion must not be narrowing.
535 const SCEV *getNoopOrSignExtend(const SCEV *V, const Type *Ty);
537 /// getNoopOrAnyExtend - Return a SCEV corresponding to a conversion of
538 /// the input value to the specified type. If the type must be extended,
539 /// it is extended with unspecified bits. The conversion must not be
541 const SCEV *getNoopOrAnyExtend(const SCEV *V, const Type *Ty);
543 /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the
544 /// input value to the specified type. The conversion must not be
546 const SCEV *getTruncateOrNoop(const SCEV *V, const Type *Ty);
548 /// getUMaxFromMismatchedTypes - Promote the operands to the wider of
549 /// the types using zero-extension, and then perform a umax operation
551 const SCEV *getUMaxFromMismatchedTypes(const SCEV *LHS,
554 /// getUMinFromMismatchedTypes - Promote the operands to the wider of
555 /// the types using zero-extension, and then perform a umin operation
557 const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS,
560 /// getSCEVAtScope - Return a SCEV expression for the specified value
561 /// at the specified scope in the program. The L value specifies a loop
562 /// nest to evaluate the expression at, where null is the top-level or a
563 /// specified loop is immediately inside of the loop.
565 /// This method can be used to compute the exit value for a variable defined
566 /// in a loop by querying what the value will hold in the parent loop.
568 /// In the case that a relevant loop exit value cannot be computed, the
569 /// original value V is returned.
570 const SCEV *getSCEVAtScope(const SCEV *S, const Loop *L);
572 /// getSCEVAtScope - This is a convenience function which does
573 /// getSCEVAtScope(getSCEV(V), L).
574 const SCEV *getSCEVAtScope(Value *V, const Loop *L);
576 /// isLoopEntryGuardedByCond - Test whether entry to the loop is protected
577 /// by a conditional between LHS and RHS. This is used to help avoid max
578 /// expressions in loop trip counts, and to eliminate casts.
579 bool isLoopEntryGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
580 const SCEV *LHS, const SCEV *RHS);
582 /// isLoopBackedgeGuardedByCond - Test whether the backedge of the loop is
583 /// protected by a conditional between LHS and RHS. This is used to
584 /// to eliminate casts.
585 bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
586 const SCEV *LHS, const SCEV *RHS);
588 /// getBackedgeTakenCount - If the specified loop has a predictable
589 /// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute
590 /// object. The backedge-taken count is the number of times the loop header
591 /// will be branched to from within the loop. This is one less than the
592 /// trip count of the loop, since it doesn't count the first iteration,
593 /// when the header is branched to from outside the loop.
595 /// Note that it is not valid to call this method on a loop without a
596 /// loop-invariant backedge-taken count (see
597 /// hasLoopInvariantBackedgeTakenCount).
599 const SCEV *getBackedgeTakenCount(const Loop *L);
601 /// getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except
602 /// return the least SCEV value that is known never to be less than the
603 /// actual backedge taken count.
604 const SCEV *getMaxBackedgeTakenCount(const Loop *L);
606 /// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop
607 /// has an analyzable loop-invariant backedge-taken count.
608 bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
610 /// forgetLoop - This method should be called by the client when it has
611 /// changed a loop in a way that may effect ScalarEvolution's ability to
612 /// compute a trip count, or if the loop is deleted.
613 void forgetLoop(const Loop *L);
615 /// forgetValue - This method should be called by the client when it has
616 /// changed a value in a way that may effect its value, or which may
617 /// disconnect it from a def-use chain linking it to a loop.
618 void forgetValue(Value *V);
620 /// GetMinTrailingZeros - Determine the minimum number of zero bits that S
621 /// is guaranteed to end in (at every loop iteration). It is, at the same
622 /// time, the minimum number of times S is divisible by 2. For example,
623 /// given {4,+,8} it returns 2. If S is guaranteed to be 0, it returns the
625 uint32_t GetMinTrailingZeros(const SCEV *S);
627 /// getUnsignedRange - Determine the unsigned range for a particular SCEV.
629 ConstantRange getUnsignedRange(const SCEV *S);
631 /// getSignedRange - Determine the signed range for a particular SCEV.
633 ConstantRange getSignedRange(const SCEV *S);
635 /// isKnownNegative - Test if the given expression is known to be negative.
637 bool isKnownNegative(const SCEV *S);
639 /// isKnownPositive - Test if the given expression is known to be positive.
641 bool isKnownPositive(const SCEV *S);
643 /// isKnownNonNegative - Test if the given expression is known to be
646 bool isKnownNonNegative(const SCEV *S);
648 /// isKnownNonPositive - Test if the given expression is known to be
651 bool isKnownNonPositive(const SCEV *S);
653 /// isKnownNonZero - Test if the given expression is known to be
656 bool isKnownNonZero(const SCEV *S);
658 /// isKnownPredicate - Test if the given expression is known to satisfy
659 /// the condition described by Pred, LHS, and RHS.
661 bool isKnownPredicate(ICmpInst::Predicate Pred,
662 const SCEV *LHS, const SCEV *RHS);
664 /// SimplifyICmpOperands - Simplify LHS and RHS in a comparison with
665 /// predicate Pred. Return true iff any changes were made. If the
666 /// operands are provably equal or inequal, LHS and RHS are set to
667 /// the same value and Pred is set to either ICMP_EQ or ICMP_NE.
669 bool SimplifyICmpOperands(ICmpInst::Predicate &Pred,
673 virtual bool runOnFunction(Function &F);
674 virtual void releaseMemory();
675 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
676 virtual void print(raw_ostream &OS, const Module* = 0) const;
679 FoldingSet<SCEV> UniqueSCEVs;
680 BumpPtrAllocator SCEVAllocator;
682 /// FirstUnknown - The head of a linked list of all SCEVUnknown
683 /// values that have been allocated. This is used by releaseMemory
684 /// to locate them all and call their destructors.
685 SCEVUnknown *FirstUnknown;