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