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 /// getType - Return the LLVM type of this SCEV expression.
83 virtual const Type *getType() const = 0;
85 /// isZero - Return true if the expression is a constant zero.
89 /// isOne - Return true if the expression is a constant one.
93 /// isAllOnesValue - Return true if the expression is a constant
96 bool isAllOnesValue() const;
98 /// hasOperand - Test whether this SCEV has Op as a direct or
100 virtual bool hasOperand(const SCEV *Op) const = 0;
102 /// dominates - Return true if elements that makes up this SCEV dominates
103 /// the specified basic block.
104 virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const = 0;
106 /// properlyDominates - Return true if elements that makes up this SCEV
107 /// properly dominate the specified basic block.
108 virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const = 0;
110 /// print - Print out the internal representation of this scalar to the
111 /// specified stream. This should really only be used for debugging
113 virtual void print(raw_ostream &OS) const = 0;
115 /// dump - This method is used for debugging.
120 // Specialize FoldingSetTrait for SCEV to avoid needing to compute
121 // temporary FoldingSetNodeID values.
122 template<> struct FoldingSetTrait<SCEV> : DefaultFoldingSetTrait<SCEV> {
123 static void Profile(const SCEV &X, FoldingSetNodeID& ID) {
126 static bool Equals(const SCEV &X, const FoldingSetNodeID &ID,
127 FoldingSetNodeID &TempID) {
128 return ID == X.FastID;
130 static unsigned ComputeHash(const SCEV &X, FoldingSetNodeID &TempID) {
131 return X.FastID.ComputeHash();
135 inline raw_ostream &operator<<(raw_ostream &OS, const SCEV &S) {
140 /// SCEVCouldNotCompute - An object of this class is returned by queries that
141 /// could not be answered. For example, if you ask for the number of
142 /// iterations of a linked-list traversal loop, you will get one of these.
143 /// None of the standard SCEV operations are valid on this class, it is just a
145 struct SCEVCouldNotCompute : public SCEV {
146 SCEVCouldNotCompute();
148 // None of these methods are valid for this object.
149 virtual const Type *getType() const;
150 virtual void print(raw_ostream &OS) const;
151 virtual bool hasOperand(const SCEV *Op) const;
153 virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const {
157 virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const {
161 /// Methods for support type inquiry through isa, cast, and dyn_cast:
162 static inline bool classof(const SCEVCouldNotCompute *S) { return true; }
163 static bool classof(const SCEV *S);
166 /// ScalarEvolution - This class is the main scalar evolution driver. Because
167 /// client code (intentionally) can't do much with the SCEV objects directly,
168 /// they must ask this class for services.
170 class ScalarEvolution : public FunctionPass {
171 /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
172 /// notified whenever a Value is deleted.
173 class SCEVCallbackVH : public CallbackVH {
175 virtual void deleted();
176 virtual void allUsesReplacedWith(Value *New);
178 SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0);
181 friend class SCEVCallbackVH;
182 friend class SCEVExpander;
183 friend class SCEVUnknown;
185 /// F - The function we are analyzing.
189 /// LI - The loop information for the function we are currently analyzing.
193 /// TD - The target data information for the target we are targeting.
197 /// DT - The dominator tree.
201 /// CouldNotCompute - This SCEV is used to represent unknown trip
202 /// counts and things.
203 SCEVCouldNotCompute CouldNotCompute;
205 /// ValueExprMapType - The typedef for ValueExprMap.
207 typedef DenseMap<SCEVCallbackVH, const SCEV *, DenseMapInfo<Value *> >
210 /// ValueExprMap - This is a cache of the values we have analyzed so far.
212 ValueExprMapType ValueExprMap;
214 /// BackedgeTakenInfo - Information about the backedge-taken count
215 /// of a loop. This currently includes an exact count and a maximum count.
217 struct BackedgeTakenInfo {
218 /// Exact - An expression indicating the exact backedge-taken count of
219 /// the loop if it is known, or a SCEVCouldNotCompute otherwise.
222 /// Max - An expression indicating the least maximum backedge-taken
223 /// count of the loop that is known, or a SCEVCouldNotCompute.
226 /*implicit*/ BackedgeTakenInfo(const SCEV *exact) :
227 Exact(exact), Max(exact) {}
229 BackedgeTakenInfo(const SCEV *exact, const SCEV *max) :
230 Exact(exact), Max(max) {}
232 /// hasAnyInfo - Test whether this BackedgeTakenInfo contains any
233 /// computed information, or whether it's all SCEVCouldNotCompute
235 bool hasAnyInfo() const {
236 return !isa<SCEVCouldNotCompute>(Exact) ||
237 !isa<SCEVCouldNotCompute>(Max);
241 /// BackedgeTakenCounts - Cache the backedge-taken count of the loops for
242 /// this function as they are computed.
243 std::map<const Loop*, BackedgeTakenInfo> BackedgeTakenCounts;
245 /// ConstantEvolutionLoopExitValue - This map contains entries for all of
246 /// the PHI instructions that we attempt to compute constant evolutions for.
247 /// This allows us to avoid potentially expensive recomputation of these
248 /// properties. An instruction maps to null if we are unable to compute its
250 std::map<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
252 /// ValuesAtScopes - This map contains entries for all the expressions
253 /// that we attempt to compute getSCEVAtScope information for, which can
254 /// be expensive in extreme cases.
255 std::map<const SCEV *,
256 std::map<const Loop *, const SCEV *> > ValuesAtScopes;
258 /// UnsignedRanges - Memoized results from getUnsignedRange
259 DenseMap<const SCEV *, ConstantRange> UnsignedRanges;
261 /// SignedRanges - Memoized results from getSignedRange
262 DenseMap<const SCEV *, ConstantRange> SignedRanges;
264 /// setUnsignedRange - Set the memoized unsigned range for the given SCEV.
265 const ConstantRange &setUnsignedRange(const SCEV *S,
266 const ConstantRange &CR) {
267 std::pair<DenseMap<const SCEV *, ConstantRange>::iterator, bool> Pair =
268 UnsignedRanges.insert(std::make_pair(S, CR));
270 Pair.first->second = CR;
271 return Pair.first->second;
274 /// setUnsignedRange - Set the memoized signed range for the given SCEV.
275 const ConstantRange &setSignedRange(const SCEV *S,
276 const ConstantRange &CR) {
277 std::pair<DenseMap<const SCEV *, ConstantRange>::iterator, bool> Pair =
278 SignedRanges.insert(std::make_pair(S, CR));
280 Pair.first->second = CR;
281 return Pair.first->second;
284 /// createSCEV - We know that there is no SCEV for the specified value.
285 /// Analyze the expression.
286 const SCEV *createSCEV(Value *V);
288 /// createNodeForPHI - Provide the special handling we need to analyze PHI
290 const SCEV *createNodeForPHI(PHINode *PN);
292 /// createNodeForGEP - Provide the special handling we need to analyze GEP
294 const SCEV *createNodeForGEP(GEPOperator *GEP);
296 /// computeSCEVAtScope - Implementation code for getSCEVAtScope; called
297 /// at most once for each SCEV+Loop pair.
299 const SCEV *computeSCEVAtScope(const SCEV *S, const Loop *L);
301 /// ForgetSymbolicValue - This looks up computed SCEV values for all
302 /// instructions that depend on the given instruction and removes them from
303 /// the ValueExprMap map if they reference SymName. This is used during PHI
305 void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
307 /// getBECount - Subtract the end and start values and divide by the step,
308 /// rounding up, to get the number of times the backedge is executed. Return
309 /// CouldNotCompute if an intermediate computation overflows.
310 const SCEV *getBECount(const SCEV *Start,
315 /// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given
316 /// loop, lazily computing new values if the loop hasn't been analyzed
318 const BackedgeTakenInfo &getBackedgeTakenInfo(const Loop *L);
320 /// ComputeBackedgeTakenCount - Compute the number of times the specified
321 /// loop will iterate.
322 BackedgeTakenInfo ComputeBackedgeTakenCount(const Loop *L);
324 /// ComputeBackedgeTakenCountFromExit - Compute the number of times the
325 /// backedge of the specified loop will execute if it exits via the
327 BackedgeTakenInfo ComputeBackedgeTakenCountFromExit(const Loop *L,
328 BasicBlock *ExitingBlock);
330 /// ComputeBackedgeTakenCountFromExitCond - Compute the number of times the
331 /// backedge of the specified loop will execute if its exit condition
332 /// were a conditional branch of ExitCond, TBB, and FBB.
334 ComputeBackedgeTakenCountFromExitCond(const Loop *L,
339 /// ComputeBackedgeTakenCountFromExitCondICmp - Compute the number of
340 /// times the backedge of the specified loop will execute if its exit
341 /// condition were a conditional branch of the ICmpInst ExitCond, TBB,
344 ComputeBackedgeTakenCountFromExitCondICmp(const Loop *L,
349 /// ComputeLoadConstantCompareBackedgeTakenCount - Given an exit condition
350 /// of 'icmp op load X, cst', try to see if we can compute the
351 /// backedge-taken count.
353 ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI,
356 ICmpInst::Predicate p);
358 /// ComputeBackedgeTakenCountExhaustively - If the loop is known to execute
359 /// a constant number of times (the condition evolves only from constants),
360 /// try to evaluate a few iterations of the loop until we get the exit
361 /// condition gets a value of ExitWhen (true or false). If we cannot
362 /// evaluate the backedge-taken count of the loop, return CouldNotCompute.
363 const SCEV *ComputeBackedgeTakenCountExhaustively(const Loop *L,
367 /// HowFarToZero - Return the number of times a backedge comparing the
368 /// specified value to zero will execute. If not computable, return
370 BackedgeTakenInfo HowFarToZero(const SCEV *V, const Loop *L);
372 /// HowFarToNonZero - Return the number of times a backedge checking the
373 /// specified value for nonzero will execute. If not computable, return
375 BackedgeTakenInfo HowFarToNonZero(const SCEV *V, const Loop *L);
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);
383 /// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
384 /// (which may not be an immediate predecessor) which has exactly one
385 /// successor from which BB is reachable, or null if no such block is
387 std::pair<BasicBlock *, BasicBlock *>
388 getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB);
390 /// isImpliedCond - Test whether the condition described by Pred, LHS, and
391 /// RHS is true whenever the given FoundCondValue value evaluates to true.
392 bool isImpliedCond(ICmpInst::Predicate Pred,
393 const SCEV *LHS, const SCEV *RHS,
394 Value *FoundCondValue,
397 /// isImpliedCondOperands - Test whether the condition described by Pred,
398 /// LHS, and RHS is true whenever the condition described by Pred, FoundLHS,
399 /// and FoundRHS is true.
400 bool isImpliedCondOperands(ICmpInst::Predicate Pred,
401 const SCEV *LHS, const SCEV *RHS,
402 const SCEV *FoundLHS, const SCEV *FoundRHS);
404 /// isImpliedCondOperandsHelper - Test whether the condition described by
405 /// Pred, LHS, and RHS is true whenever the condition described by Pred,
406 /// FoundLHS, and FoundRHS is true.
407 bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred,
408 const SCEV *LHS, const SCEV *RHS,
409 const SCEV *FoundLHS, const SCEV *FoundRHS);
411 /// getConstantEvolutionLoopExitValue - If we know that the specified Phi is
412 /// in the header of its containing loop, we know the loop executes a
413 /// constant number of times, and the PHI node is just a recurrence
414 /// involving constants, fold it.
415 Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs,
418 /// isKnownPredicateWithRanges - Test if the given expression is known to
419 /// satisfy the condition described by Pred and the known constant ranges
422 bool isKnownPredicateWithRanges(ICmpInst::Predicate Pred,
423 const SCEV *LHS, const SCEV *RHS);
426 static char ID; // Pass identification, replacement for typeid
429 LLVMContext &getContext() const { return F->getContext(); }
431 /// isSCEVable - Test if values of the given type are analyzable within
432 /// the SCEV framework. This primarily includes integer types, and it
433 /// can optionally include pointer types if the ScalarEvolution class
434 /// has access to target-specific information.
435 bool isSCEVable(const Type *Ty) const;
437 /// getTypeSizeInBits - Return the size in bits of the specified type,
438 /// for which isSCEVable must return true.
439 uint64_t getTypeSizeInBits(const Type *Ty) const;
441 /// getEffectiveSCEVType - Return a type with the same bitwidth as
442 /// the given type and which represents how SCEV will treat the given
443 /// type, for which isSCEVable must return true. For pointer types,
444 /// this is the pointer-sized integer type.
445 const Type *getEffectiveSCEVType(const Type *Ty) const;
447 /// getSCEV - Return a SCEV expression for the full generality of the
448 /// specified expression.
449 const SCEV *getSCEV(Value *V);
451 const SCEV *getConstant(ConstantInt *V);
452 const SCEV *getConstant(const APInt& Val);
453 const SCEV *getConstant(const Type *Ty, uint64_t V, bool isSigned = false);
454 const SCEV *getTruncateExpr(const SCEV *Op, const Type *Ty);
455 const SCEV *getZeroExtendExpr(const SCEV *Op, const Type *Ty);
456 const SCEV *getSignExtendExpr(const SCEV *Op, const Type *Ty);
457 const SCEV *getAnyExtendExpr(const SCEV *Op, const Type *Ty);
458 const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
459 bool HasNUW = false, bool HasNSW = false);
460 const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS,
461 bool HasNUW = false, bool HasNSW = false) {
462 SmallVector<const SCEV *, 2> Ops;
465 return getAddExpr(Ops, HasNUW, HasNSW);
467 const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1,
469 bool HasNUW = false, bool HasNSW = false) {
470 SmallVector<const SCEV *, 3> Ops;
474 return getAddExpr(Ops, HasNUW, HasNSW);
476 const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
477 bool HasNUW = false, bool HasNSW = false);
478 const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS,
479 bool HasNUW = false, bool HasNSW = false) {
480 SmallVector<const SCEV *, 2> Ops;
483 return getMulExpr(Ops, HasNUW, HasNSW);
485 const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
486 const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
488 bool HasNUW = false, bool HasNSW = false);
489 const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
491 bool HasNUW = false, bool HasNSW = false);
492 const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
494 bool HasNUW = false, bool HasNSW = false) {
495 SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
496 return getAddRecExpr(NewOp, L, HasNUW, HasNSW);
498 const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
499 const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
500 const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS);
501 const SCEV *getUMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
502 const SCEV *getSMinExpr(const SCEV *LHS, const SCEV *RHS);
503 const SCEV *getUMinExpr(const SCEV *LHS, const SCEV *RHS);
504 const SCEV *getUnknown(Value *V);
505 const SCEV *getCouldNotCompute();
507 /// getSizeOfExpr - Return an expression for sizeof on the given type.
509 const SCEV *getSizeOfExpr(const Type *AllocTy);
511 /// getAlignOfExpr - Return an expression for alignof on the given type.
513 const SCEV *getAlignOfExpr(const Type *AllocTy);
515 /// getOffsetOfExpr - Return an expression for offsetof on the given field.
517 const SCEV *getOffsetOfExpr(const StructType *STy, unsigned FieldNo);
519 /// getOffsetOfExpr - Return an expression for offsetof on the given field.
521 const SCEV *getOffsetOfExpr(const Type *CTy, Constant *FieldNo);
523 /// getNegativeSCEV - Return the SCEV object corresponding to -V.
525 const SCEV *getNegativeSCEV(const SCEV *V);
527 /// getNotSCEV - Return the SCEV object corresponding to ~V.
529 const SCEV *getNotSCEV(const SCEV *V);
531 /// getMinusSCEV - Return LHS-RHS.
533 const SCEV *getMinusSCEV(const SCEV *LHS,
536 /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion
537 /// of the input value to the specified type. If the type must be
538 /// extended, it is zero extended.
539 const SCEV *getTruncateOrZeroExtend(const SCEV *V, const Type *Ty);
541 /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion
542 /// of the input value to the specified type. If the type must be
543 /// extended, it is sign extended.
544 const SCEV *getTruncateOrSignExtend(const SCEV *V, const Type *Ty);
546 /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of
547 /// the input value to the specified type. If the type must be extended,
548 /// it is zero extended. The conversion must not be narrowing.
549 const SCEV *getNoopOrZeroExtend(const SCEV *V, const Type *Ty);
551 /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of
552 /// the input value to the specified type. If the type must be extended,
553 /// it is sign extended. The conversion must not be narrowing.
554 const SCEV *getNoopOrSignExtend(const SCEV *V, const Type *Ty);
556 /// getNoopOrAnyExtend - Return a SCEV corresponding to a conversion of
557 /// the input value to the specified type. If the type must be extended,
558 /// it is extended with unspecified bits. The conversion must not be
560 const SCEV *getNoopOrAnyExtend(const SCEV *V, const Type *Ty);
562 /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the
563 /// input value to the specified type. The conversion must not be
565 const SCEV *getTruncateOrNoop(const SCEV *V, const Type *Ty);
567 /// getUMaxFromMismatchedTypes - Promote the operands to the wider of
568 /// the types using zero-extension, and then perform a umax operation
570 const SCEV *getUMaxFromMismatchedTypes(const SCEV *LHS,
573 /// getUMinFromMismatchedTypes - Promote the operands to the wider of
574 /// the types using zero-extension, and then perform a umin operation
576 const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS,
579 /// getSCEVAtScope - Return a SCEV expression for the specified value
580 /// at the specified scope in the program. The L value specifies a loop
581 /// nest to evaluate the expression at, where null is the top-level or a
582 /// specified loop is immediately inside of the loop.
584 /// This method can be used to compute the exit value for a variable defined
585 /// in a loop by querying what the value will hold in the parent loop.
587 /// In the case that a relevant loop exit value cannot be computed, the
588 /// original value V is returned.
589 const SCEV *getSCEVAtScope(const SCEV *S, const Loop *L);
591 /// getSCEVAtScope - This is a convenience function which does
592 /// getSCEVAtScope(getSCEV(V), L).
593 const SCEV *getSCEVAtScope(Value *V, const Loop *L);
595 /// isLoopEntryGuardedByCond - Test whether entry to the loop is protected
596 /// by a conditional between LHS and RHS. This is used to help avoid max
597 /// expressions in loop trip counts, and to eliminate casts.
598 bool isLoopEntryGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
599 const SCEV *LHS, const SCEV *RHS);
601 /// isLoopBackedgeGuardedByCond - Test whether the backedge of the loop is
602 /// protected by a conditional between LHS and RHS. This is used to
603 /// to eliminate casts.
604 bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
605 const SCEV *LHS, const SCEV *RHS);
607 /// getBackedgeTakenCount - If the specified loop has a predictable
608 /// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute
609 /// object. The backedge-taken count is the number of times the loop header
610 /// will be branched to from within the loop. This is one less than the
611 /// trip count of the loop, since it doesn't count the first iteration,
612 /// when the header is branched to from outside the loop.
614 /// Note that it is not valid to call this method on a loop without a
615 /// loop-invariant backedge-taken count (see
616 /// hasLoopInvariantBackedgeTakenCount).
618 const SCEV *getBackedgeTakenCount(const Loop *L);
620 /// getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except
621 /// return the least SCEV value that is known never to be less than the
622 /// actual backedge taken count.
623 const SCEV *getMaxBackedgeTakenCount(const Loop *L);
625 /// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop
626 /// has an analyzable loop-invariant backedge-taken count.
627 bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
629 /// forgetLoop - This method should be called by the client when it has
630 /// changed a loop in a way that may effect ScalarEvolution's ability to
631 /// compute a trip count, or if the loop is deleted.
632 void forgetLoop(const Loop *L);
634 /// forgetValue - This method should be called by the client when it has
635 /// changed a value in a way that may effect its value, or which may
636 /// disconnect it from a def-use chain linking it to a loop.
637 void forgetValue(Value *V);
639 /// GetMinTrailingZeros - Determine the minimum number of zero bits that S
640 /// is guaranteed to end in (at every loop iteration). It is, at the same
641 /// time, the minimum number of times S is divisible by 2. For example,
642 /// given {4,+,8} it returns 2. If S is guaranteed to be 0, it returns the
644 uint32_t GetMinTrailingZeros(const SCEV *S);
646 /// getUnsignedRange - Determine the unsigned range for a particular SCEV.
648 ConstantRange getUnsignedRange(const SCEV *S);
650 /// getSignedRange - Determine the signed range for a particular SCEV.
652 ConstantRange getSignedRange(const SCEV *S);
654 /// isKnownNegative - Test if the given expression is known to be negative.
656 bool isKnownNegative(const SCEV *S);
658 /// isKnownPositive - Test if the given expression is known to be positive.
660 bool isKnownPositive(const SCEV *S);
662 /// isKnownNonNegative - Test if the given expression is known to be
665 bool isKnownNonNegative(const SCEV *S);
667 /// isKnownNonPositive - Test if the given expression is known to be
670 bool isKnownNonPositive(const SCEV *S);
672 /// isKnownNonZero - Test if the given expression is known to be
675 bool isKnownNonZero(const SCEV *S);
677 /// isKnownPredicate - Test if the given expression is known to satisfy
678 /// the condition described by Pred, LHS, and RHS.
680 bool isKnownPredicate(ICmpInst::Predicate Pred,
681 const SCEV *LHS, const SCEV *RHS);
683 /// SimplifyICmpOperands - Simplify LHS and RHS in a comparison with
684 /// predicate Pred. Return true iff any changes were made. If the
685 /// operands are provably equal or inequal, LHS and RHS are set to
686 /// the same value and Pred is set to either ICMP_EQ or ICMP_NE.
688 bool SimplifyICmpOperands(ICmpInst::Predicate &Pred,
692 /// isLoopInvariant - Return true if the value of the given SCEV is
693 /// unchanging in the specified loop.
694 bool isLoopInvariant(const SCEV *S, const Loop *L);
696 /// hasComputableLoopEvolution - Return true if the given SCEV changes value
697 /// in a known way in the specified loop. This property being true implies
698 /// that the value is variant in the loop AND that we can emit an expression
699 /// to compute the value of the expression at any particular loop iteration.
700 bool hasComputableLoopEvolution(const SCEV *S, const Loop *L);
702 virtual bool runOnFunction(Function &F);
703 virtual void releaseMemory();
704 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
705 virtual void print(raw_ostream &OS, const Module* = 0) const;
708 FoldingSet<SCEV> UniqueSCEVs;
709 BumpPtrAllocator SCEVAllocator;
711 /// FirstUnknown - The head of a linked list of all SCEVUnknown
712 /// values that have been allocated. This is used by releaseMemory
713 /// to locate them all and call their destructors.
714 SCEVUnknown *FirstUnknown;