ScalarEvolution.h revision 6cf07a80ff5ee8ef7dc336f954aae17c7e8d83d4
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===- llvm/Analysis/ScalarEvolution.h - Scalar Evolution -------*- C++ -*-===// 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The LLVM Compiler Infrastructure 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 5116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// This file is distributed under the University of Illinois Open Source 6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// License. See LICENSE.TXT for details. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 8116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch//===----------------------------------------------------------------------===// 9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 10116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// The ScalarEvolution class is an LLVM pass which can be used to analyze and 11116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// categorize scalar expressions in loops. It specializes in recognizing 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// general induction variables, representing them with the abstract and opaque 13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// SCEV class. Given this analysis, trip counts of loops and other important 1403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// properties can be obtained. 15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// This analysis is primarily useful for induction variable substitution and 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// strength reduction. 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch//===----------------------------------------------------------------------===// 20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 21116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#define LLVM_ANALYSIS_SCALAREVOLUTION_H 23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/Pass.h" 25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/Instructions.h" 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/Function.h" 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/Operator.h" 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/Support/DataTypes.h" 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/Support/ValueHandle.h" 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/Support/Allocator.h" 31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/Support/ConstantRange.h" 32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/ADT/FoldingSet.h" 33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "llvm/ADT/DenseSet.h" 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include <map> 35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 36116680a4aac90f2aa7413d9095a592090648e557Ben Murdochnamespace llvm { 37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class APInt; 38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class Constant; 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class ConstantInt; 40116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class DominatorTree; 411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci class Type; 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class ScalarEvolution; 43116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class TargetData; 44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class TargetLibraryInfo; 45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class LLVMContext; 46116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class Loop; 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class LoopInfo; 48116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class Operator; 49116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class SCEVUnknown; 50116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class SCEV; 51116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch template<> struct FoldingSetTrait<SCEV>; 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// SCEV - This class represents an analyzed expression in the program. These 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// are opaque objects that the client is not allowed to do much with 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// directly. 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 57116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch class SCEV : public FoldingSetNode { 58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch friend struct FoldingSetTrait<SCEV>; 59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// FastID - A reference to an Interned FoldingSetNodeID for this node. 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// The ScalarEvolution's BumpPtrAllocator holds the data. 62116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch FoldingSetNodeIDRef FastID; 63116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 64116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // The SCEV baseclass this node corresponds to 65116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const unsigned short SCEVType; 66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch protected: 68116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// SubclassData - This field is initialized to zero and may be used in 69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// subclasses to store miscellaneous information. 70116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch unsigned short SubclassData; 71116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 72116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private: 73116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch SCEV(const SCEV &); // DO NOT IMPLEMENT 74116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void operator=(const SCEV &); // DO NOT IMPLEMENT 7503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 76116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public: 77116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// NoWrapFlags are bitfield indices into SubclassData. 781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// 79116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// Add and Mul expressions may have no-unsigned-wrap <NUW> or 80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// no-signed-wrap <NSW> properties, which are derived from the IR 81116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// operator. NSW is a misnomer that we use to mean no signed overflow or 82116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// underflow. 83116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// AddRec expression may have a no-self-wraparound <NW> property if the 85116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// result can never reach the start value. This property is independent of 86116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// the actual start value and step direction. Self-wraparound is defined 87116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// purely in terms of the recurrence's loop, step size, and 88116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// bitwidth. Formally, a recurrence with no self-wraparound satisfies: 89116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// abs(step) * max-iteration(loop) <= unsigned-max(bitwidth). 901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// 91116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// Note that NUW and NSW are also valid properties of a recurrence, and 92116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// either implies NW. For convenience, NW will be set for a recurrence 93116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// whenever either NUW or NSW are set. 94116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch enum NoWrapFlags { FlagAnyWrap = 0, // No guarantee. 95116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch FlagNW = (1 << 0), // No self-wrap. 96116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch FlagNUW = (1 << 1), // No unsigned wrap. 97116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch FlagNSW = (1 << 2), // No signed wrap. 98116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NoWrapMask = (1 << 3) -1 }; 99116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 100116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch explicit SCEV(const FoldingSetNodeIDRef ID, unsigned SCEVTy) : 1011320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci FastID(ID), SCEVType(SCEVTy), SubclassData(0) {} 1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch unsigned getSCEVType() const { return SCEVType; } 104116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 105116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// getType - Return the LLVM type of this SCEV expression. 106116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 107116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Type *getType() const; 108116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 109116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// isZero - Return true if the expression is a constant zero. 110116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 111116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool isZero() const; 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 113f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) /// isOne - Return true if the expression is a constant one. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) /// 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool isOne() const; 116116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 117116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// isAllOnesValue - Return true if the expression is a constant 118116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// all-ones value. 119116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 120116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool isAllOnesValue() const; 121116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 122116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// isNonConstantNegative - Return true if the specified scev is negated, 123116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// but not a constant. 124116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool isNonConstantNegative() const; 125116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 126116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// print - Print out the internal representation of this scalar to the 127116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// specified stream. This should really only be used for debugging 128116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// purposes. 129116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void print(raw_ostream &OS) const; 130116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 131116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// dump - This method is used for debugging. 132116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// 133116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void dump() const; 134116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch }; 135116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 136116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Specialize FoldingSetTrait for SCEV to avoid needing to compute 137116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // temporary FoldingSetNodeID values. 138116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch template<> struct FoldingSetTrait<SCEV> : DefaultFoldingSetTrait<SCEV> { 139116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static void Profile(const SCEV &X, FoldingSetNodeID& ID) { 140116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ID = X.FastID; 141116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 142116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static bool Equals(const SCEV &X, const FoldingSetNodeID &ID, 143116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch unsigned IDHash, FoldingSetNodeID &TempID) { 144116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return ID == X.FastID; 145116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 146116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch static unsigned ComputeHash(const SCEV &X, FoldingSetNodeID &TempID) { 147 return X.FastID.ComputeHash(); 148 } 149 }; 150 151 inline raw_ostream &operator<<(raw_ostream &OS, const SCEV &S) { 152 S.print(OS); 153 return OS; 154 } 155 156 /// SCEVCouldNotCompute - An object of this class is returned by queries that 157 /// could not be answered. For example, if you ask for the number of 158 /// iterations of a linked-list traversal loop, you will get one of these. 159 /// None of the standard SCEV operations are valid on this class, it is just a 160 /// marker. 161 struct SCEVCouldNotCompute : public SCEV { 162 SCEVCouldNotCompute(); 163 164 /// Methods for support type inquiry through isa, cast, and dyn_cast: 165 static inline bool classof(const SCEVCouldNotCompute *S) { return true; } 166 static bool classof(const SCEV *S); 167 }; 168 169 /// ScalarEvolution - This class is the main scalar evolution driver. Because 170 /// client code (intentionally) can't do much with the SCEV objects directly, 171 /// they must ask this class for services. 172 /// 173 class ScalarEvolution : public FunctionPass { 174 public: 175 /// LoopDisposition - An enum describing the relationship between a 176 /// SCEV and a loop. 177 enum LoopDisposition { 178 LoopVariant, ///< The SCEV is loop-variant (unknown). 179 LoopInvariant, ///< The SCEV is loop-invariant. 180 LoopComputable ///< The SCEV varies predictably with the loop. 181 }; 182 183 /// BlockDisposition - An enum describing the relationship between a 184 /// SCEV and a basic block. 185 enum BlockDisposition { 186 DoesNotDominateBlock, ///< The SCEV does not dominate the block. 187 DominatesBlock, ///< The SCEV dominates the block. 188 ProperlyDominatesBlock ///< The SCEV properly dominates the block. 189 }; 190 191 /// Convenient NoWrapFlags manipulation that hides enum casts and is 192 /// visible in the ScalarEvolution name space. 193 static SCEV::NoWrapFlags maskFlags(SCEV::NoWrapFlags Flags, int Mask) { 194 return (SCEV::NoWrapFlags)(Flags & Mask); 195 } 196 static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags, 197 SCEV::NoWrapFlags OnFlags) { 198 return (SCEV::NoWrapFlags)(Flags | OnFlags); 199 } 200 static SCEV::NoWrapFlags clearFlags(SCEV::NoWrapFlags Flags, 201 SCEV::NoWrapFlags OffFlags) { 202 return (SCEV::NoWrapFlags)(Flags & ~OffFlags); 203 } 204 205 private: 206 /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be 207 /// notified whenever a Value is deleted. 208 class SCEVCallbackVH : public CallbackVH { 209 ScalarEvolution *SE; 210 virtual void deleted(); 211 virtual void allUsesReplacedWith(Value *New); 212 public: 213 SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0); 214 }; 215 216 friend class SCEVCallbackVH; 217 friend class SCEVExpander; 218 friend class SCEVUnknown; 219 220 /// F - The function we are analyzing. 221 /// 222 Function *F; 223 224 /// LI - The loop information for the function we are currently analyzing. 225 /// 226 LoopInfo *LI; 227 228 /// TD - The target data information for the target we are targeting. 229 /// 230 TargetData *TD; 231 232 /// TLI - The target library information for the target we are targeting. 233 /// 234 TargetLibraryInfo *TLI; 235 236 /// DT - The dominator tree. 237 /// 238 DominatorTree *DT; 239 240 /// CouldNotCompute - This SCEV is used to represent unknown trip 241 /// counts and things. 242 SCEVCouldNotCompute CouldNotCompute; 243 244 /// ValueExprMapType - The typedef for ValueExprMap. 245 /// 246 typedef DenseMap<SCEVCallbackVH, const SCEV *, DenseMapInfo<Value *> > 247 ValueExprMapType; 248 249 /// ValueExprMap - This is a cache of the values we have analyzed so far. 250 /// 251 ValueExprMapType ValueExprMap; 252 253 /// Mark predicate values currently being processed by isImpliedCond. 254 DenseSet<Value*> PendingLoopPredicates; 255 256 /// ExitLimit - Information about the number of loop iterations for 257 /// which a loop exit's branch condition evaluates to the not-taken path. 258 /// This is a temporary pair of exact and max expressions that are 259 /// eventually summarized in ExitNotTakenInfo and BackedgeTakenInfo. 260 struct ExitLimit { 261 const SCEV *Exact; 262 const SCEV *Max; 263 264 /*implicit*/ ExitLimit(const SCEV *E) : Exact(E), Max(E) {} 265 266 ExitLimit(const SCEV *E, const SCEV *M) : Exact(E), Max(M) {} 267 268 /// hasAnyInfo - Test whether this ExitLimit contains any computed 269 /// information, or whether it's all SCEVCouldNotCompute values. 270 bool hasAnyInfo() const { 271 return !isa<SCEVCouldNotCompute>(Exact) || 272 !isa<SCEVCouldNotCompute>(Max); 273 } 274 }; 275 276 /// ExitNotTakenInfo - Information about the number of times a particular 277 /// loop exit may be reached before exiting the loop. 278 struct ExitNotTakenInfo { 279 AssertingVH<BasicBlock> ExitingBlock; 280 const SCEV *ExactNotTaken; 281 PointerIntPair<ExitNotTakenInfo*, 1> NextExit; 282 283 ExitNotTakenInfo() : ExitingBlock(0), ExactNotTaken(0) {} 284 285 /// isCompleteList - Return true if all loop exits are computable. 286 bool isCompleteList() const { 287 return NextExit.getInt() == 0; 288 } 289 290 void setIncomplete() { NextExit.setInt(1); } 291 292 /// getNextExit - Return a pointer to the next exit's not-taken info. 293 ExitNotTakenInfo *getNextExit() const { 294 return NextExit.getPointer(); 295 } 296 297 void setNextExit(ExitNotTakenInfo *ENT) { NextExit.setPointer(ENT); } 298 }; 299 300 /// BackedgeTakenInfo - Information about the backedge-taken count 301 /// of a loop. This currently includes an exact count and a maximum count. 302 /// 303 class BackedgeTakenInfo { 304 /// ExitNotTaken - A list of computable exits and their not-taken counts. 305 /// Loops almost never have more than one computable exit. 306 ExitNotTakenInfo ExitNotTaken; 307 308 /// Max - An expression indicating the least maximum backedge-taken 309 /// count of the loop that is known, or a SCEVCouldNotCompute. 310 const SCEV *Max; 311 312 public: 313 BackedgeTakenInfo() : Max(0) {} 314 315 /// Initialize BackedgeTakenInfo from a list of exact exit counts. 316 BackedgeTakenInfo( 317 SmallVectorImpl< std::pair<BasicBlock *, const SCEV *> > &ExitCounts, 318 bool Complete, const SCEV *MaxCount); 319 320 /// hasAnyInfo - Test whether this BackedgeTakenInfo contains any 321 /// computed information, or whether it's all SCEVCouldNotCompute 322 /// values. 323 bool hasAnyInfo() const { 324 return ExitNotTaken.ExitingBlock || !isa<SCEVCouldNotCompute>(Max); 325 } 326 327 /// getExact - Return an expression indicating the exact backedge-taken 328 /// count of the loop if it is known, or SCEVCouldNotCompute 329 /// otherwise. This is the number of times the loop header can be 330 /// guaranteed to execute, minus one. 331 const SCEV *getExact(ScalarEvolution *SE) const; 332 333 /// getExact - Return the number of times this loop exit may fall through 334 /// to the back edge, or SCEVCouldNotCompute. The loop is guaranteed not 335 /// to exit via this block before this number of iterations, but may exit 336 /// via another block. 337 const SCEV *getExact(BasicBlock *ExitingBlock, ScalarEvolution *SE) const; 338 339 /// getMax - Get the max backedge taken count for the loop. 340 const SCEV *getMax(ScalarEvolution *SE) const; 341 342 /// clear - Invalidate this result and free associated memory. 343 void clear(); 344 }; 345 346 /// BackedgeTakenCounts - Cache the backedge-taken count of the loops for 347 /// this function as they are computed. 348 DenseMap<const Loop*, BackedgeTakenInfo> BackedgeTakenCounts; 349 350 /// ConstantEvolutionLoopExitValue - This map contains entries for all of 351 /// the PHI instructions that we attempt to compute constant evolutions for. 352 /// This allows us to avoid potentially expensive recomputation of these 353 /// properties. An instruction maps to null if we are unable to compute its 354 /// exit value. 355 DenseMap<PHINode*, Constant*> ConstantEvolutionLoopExitValue; 356 357 /// ValuesAtScopes - This map contains entries for all the expressions 358 /// that we attempt to compute getSCEVAtScope information for, which can 359 /// be expensive in extreme cases. 360 DenseMap<const SCEV *, 361 std::map<const Loop *, const SCEV *> > ValuesAtScopes; 362 363 /// LoopDispositions - Memoized computeLoopDisposition results. 364 DenseMap<const SCEV *, 365 std::map<const Loop *, LoopDisposition> > LoopDispositions; 366 367 /// computeLoopDisposition - Compute a LoopDisposition value. 368 LoopDisposition computeLoopDisposition(const SCEV *S, const Loop *L); 369 370 /// BlockDispositions - Memoized computeBlockDisposition results. 371 DenseMap<const SCEV *, 372 std::map<const BasicBlock *, BlockDisposition> > BlockDispositions; 373 374 /// computeBlockDisposition - Compute a BlockDisposition value. 375 BlockDisposition computeBlockDisposition(const SCEV *S, const BasicBlock *BB); 376 377 /// UnsignedRanges - Memoized results from getUnsignedRange 378 DenseMap<const SCEV *, ConstantRange> UnsignedRanges; 379 380 /// SignedRanges - Memoized results from getSignedRange 381 DenseMap<const SCEV *, ConstantRange> SignedRanges; 382 383 /// setUnsignedRange - Set the memoized unsigned range for the given SCEV. 384 const ConstantRange &setUnsignedRange(const SCEV *S, 385 const ConstantRange &CR) { 386 std::pair<DenseMap<const SCEV *, ConstantRange>::iterator, bool> Pair = 387 UnsignedRanges.insert(std::make_pair(S, CR)); 388 if (!Pair.second) 389 Pair.first->second = CR; 390 return Pair.first->second; 391 } 392 393 /// setUnsignedRange - Set the memoized signed range for the given SCEV. 394 const ConstantRange &setSignedRange(const SCEV *S, 395 const ConstantRange &CR) { 396 std::pair<DenseMap<const SCEV *, ConstantRange>::iterator, bool> Pair = 397 SignedRanges.insert(std::make_pair(S, CR)); 398 if (!Pair.second) 399 Pair.first->second = CR; 400 return Pair.first->second; 401 } 402 403 /// createSCEV - We know that there is no SCEV for the specified value. 404 /// Analyze the expression. 405 const SCEV *createSCEV(Value *V); 406 407 /// createNodeForPHI - Provide the special handling we need to analyze PHI 408 /// SCEVs. 409 const SCEV *createNodeForPHI(PHINode *PN); 410 411 /// createNodeForGEP - Provide the special handling we need to analyze GEP 412 /// SCEVs. 413 const SCEV *createNodeForGEP(GEPOperator *GEP); 414 415 /// computeSCEVAtScope - Implementation code for getSCEVAtScope; called 416 /// at most once for each SCEV+Loop pair. 417 /// 418 const SCEV *computeSCEVAtScope(const SCEV *S, const Loop *L); 419 420 /// ForgetSymbolicValue - This looks up computed SCEV values for all 421 /// instructions that depend on the given instruction and removes them from 422 /// the ValueExprMap map if they reference SymName. This is used during PHI 423 /// resolution. 424 void ForgetSymbolicName(Instruction *I, const SCEV *SymName); 425 426 /// getBECount - Subtract the end and start values and divide by the step, 427 /// rounding up, to get the number of times the backedge is executed. Return 428 /// CouldNotCompute if an intermediate computation overflows. 429 const SCEV *getBECount(const SCEV *Start, 430 const SCEV *End, 431 const SCEV *Step, 432 bool NoWrap); 433 434 /// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given 435 /// loop, lazily computing new values if the loop hasn't been analyzed 436 /// yet. 437 const BackedgeTakenInfo &getBackedgeTakenInfo(const Loop *L); 438 439 /// ComputeBackedgeTakenCount - Compute the number of times the specified 440 /// loop will iterate. 441 BackedgeTakenInfo ComputeBackedgeTakenCount(const Loop *L); 442 443 /// ComputeExitLimit - Compute the number of times the backedge of the 444 /// specified loop will execute if it exits via the specified block. 445 ExitLimit ComputeExitLimit(const Loop *L, BasicBlock *ExitingBlock); 446 447 /// ComputeExitLimitFromCond - Compute the number of times the backedge of 448 /// the specified loop will execute if its exit condition were a conditional 449 /// branch of ExitCond, TBB, and FBB. 450 ExitLimit ComputeExitLimitFromCond(const Loop *L, 451 Value *ExitCond, 452 BasicBlock *TBB, 453 BasicBlock *FBB); 454 455 /// ComputeExitLimitFromICmp - Compute the number of times the backedge of 456 /// the specified loop will execute if its exit condition were a conditional 457 /// branch of the ICmpInst ExitCond, TBB, and FBB. 458 ExitLimit ComputeExitLimitFromICmp(const Loop *L, 459 ICmpInst *ExitCond, 460 BasicBlock *TBB, 461 BasicBlock *FBB); 462 463 /// ComputeLoadConstantCompareExitLimit - Given an exit condition 464 /// of 'icmp op load X, cst', try to see if we can compute the 465 /// backedge-taken count. 466 ExitLimit ComputeLoadConstantCompareExitLimit(LoadInst *LI, 467 Constant *RHS, 468 const Loop *L, 469 ICmpInst::Predicate p); 470 471 /// ComputeExitCountExhaustively - If the loop is known to execute a 472 /// constant number of times (the condition evolves only from constants), 473 /// try to evaluate a few iterations of the loop until we get the exit 474 /// condition gets a value of ExitWhen (true or false). If we cannot 475 /// evaluate the exit count of the loop, return CouldNotCompute. 476 const SCEV *ComputeExitCountExhaustively(const Loop *L, 477 Value *Cond, 478 bool ExitWhen); 479 480 /// HowFarToZero - Return the number of times an exit condition comparing 481 /// the specified value to zero will execute. If not computable, return 482 /// CouldNotCompute. 483 ExitLimit HowFarToZero(const SCEV *V, const Loop *L); 484 485 /// HowFarToNonZero - Return the number of times an exit condition checking 486 /// the specified value for nonzero will execute. If not computable, return 487 /// CouldNotCompute. 488 ExitLimit HowFarToNonZero(const SCEV *V, const Loop *L); 489 490 /// HowManyLessThans - Return the number of times an exit condition 491 /// containing the specified less-than comparison will execute. If not 492 /// computable, return CouldNotCompute. isSigned specifies whether the 493 /// less-than is signed. 494 ExitLimit HowManyLessThans(const SCEV *LHS, const SCEV *RHS, 495 const Loop *L, bool isSigned); 496 497 /// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB 498 /// (which may not be an immediate predecessor) which has exactly one 499 /// successor from which BB is reachable, or null if no such block is 500 /// found. 501 std::pair<BasicBlock *, BasicBlock *> 502 getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB); 503 504 /// isImpliedCond - Test whether the condition described by Pred, LHS, and 505 /// RHS is true whenever the given FoundCondValue value evaluates to true. 506 bool isImpliedCond(ICmpInst::Predicate Pred, 507 const SCEV *LHS, const SCEV *RHS, 508 Value *FoundCondValue, 509 bool Inverse); 510 511 /// isImpliedCondOperands - Test whether the condition described by Pred, 512 /// LHS, and RHS is true whenever the condition described by Pred, FoundLHS, 513 /// and FoundRHS is true. 514 bool isImpliedCondOperands(ICmpInst::Predicate Pred, 515 const SCEV *LHS, const SCEV *RHS, 516 const SCEV *FoundLHS, const SCEV *FoundRHS); 517 518 /// isImpliedCondOperandsHelper - Test whether the condition described by 519 /// Pred, LHS, and RHS is true whenever the condition described by Pred, 520 /// FoundLHS, and FoundRHS is true. 521 bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred, 522 const SCEV *LHS, const SCEV *RHS, 523 const SCEV *FoundLHS, 524 const SCEV *FoundRHS); 525 526 /// getConstantEvolutionLoopExitValue - If we know that the specified Phi is 527 /// in the header of its containing loop, we know the loop executes a 528 /// constant number of times, and the PHI node is just a recurrence 529 /// involving constants, fold it. 530 Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs, 531 const Loop *L); 532 533 /// isKnownPredicateWithRanges - Test if the given expression is known to 534 /// satisfy the condition described by Pred and the known constant ranges 535 /// of LHS and RHS. 536 /// 537 bool isKnownPredicateWithRanges(ICmpInst::Predicate Pred, 538 const SCEV *LHS, const SCEV *RHS); 539 540 /// forgetMemoizedResults - Drop memoized information computed for S. 541 void forgetMemoizedResults(const SCEV *S); 542 543 public: 544 static char ID; // Pass identification, replacement for typeid 545 ScalarEvolution(); 546 547 LLVMContext &getContext() const { return F->getContext(); } 548 549 /// isSCEVable - Test if values of the given type are analyzable within 550 /// the SCEV framework. This primarily includes integer types, and it 551 /// can optionally include pointer types if the ScalarEvolution class 552 /// has access to target-specific information. 553 bool isSCEVable(Type *Ty) const; 554 555 /// getTypeSizeInBits - Return the size in bits of the specified type, 556 /// for which isSCEVable must return true. 557 uint64_t getTypeSizeInBits(Type *Ty) const; 558 559 /// getEffectiveSCEVType - Return a type with the same bitwidth as 560 /// the given type and which represents how SCEV will treat the given 561 /// type, for which isSCEVable must return true. For pointer types, 562 /// this is the pointer-sized integer type. 563 Type *getEffectiveSCEVType(Type *Ty) const; 564 565 /// getSCEV - Return a SCEV expression for the full generality of the 566 /// specified expression. 567 const SCEV *getSCEV(Value *V); 568 569 const SCEV *getConstant(ConstantInt *V); 570 const SCEV *getConstant(const APInt& Val); 571 const SCEV *getConstant(Type *Ty, uint64_t V, bool isSigned = false); 572 const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty); 573 const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty); 574 const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty); 575 const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty); 576 const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops, 577 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap); 578 const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS, 579 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) { 580 SmallVector<const SCEV *, 2> Ops; 581 Ops.push_back(LHS); 582 Ops.push_back(RHS); 583 return getAddExpr(Ops, Flags); 584 } 585 const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, 586 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) { 587 SmallVector<const SCEV *, 3> Ops; 588 Ops.push_back(Op0); 589 Ops.push_back(Op1); 590 Ops.push_back(Op2); 591 return getAddExpr(Ops, Flags); 592 } 593 const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops, 594 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap); 595 const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS, 596 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) 597 { 598 SmallVector<const SCEV *, 2> Ops; 599 Ops.push_back(LHS); 600 Ops.push_back(RHS); 601 return getMulExpr(Ops, Flags); 602 } 603 const SCEV *getMulExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, 604 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) { 605 SmallVector<const SCEV *, 3> Ops; 606 Ops.push_back(Op0); 607 Ops.push_back(Op1); 608 Ops.push_back(Op2); 609 return getMulExpr(Ops, Flags); 610 } 611 const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS); 612 const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step, 613 const Loop *L, SCEV::NoWrapFlags Flags); 614 const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands, 615 const Loop *L, SCEV::NoWrapFlags Flags); 616 const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands, 617 const Loop *L, SCEV::NoWrapFlags Flags) { 618 SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end()); 619 return getAddRecExpr(NewOp, L, Flags); 620 } 621 const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS); 622 const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands); 623 const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS); 624 const SCEV *getUMaxExpr(SmallVectorImpl<const SCEV *> &Operands); 625 const SCEV *getSMinExpr(const SCEV *LHS, const SCEV *RHS); 626 const SCEV *getUMinExpr(const SCEV *LHS, const SCEV *RHS); 627 const SCEV *getUnknown(Value *V); 628 const SCEV *getCouldNotCompute(); 629 630 /// getSizeOfExpr - Return an expression for sizeof on the given type. 631 /// 632 const SCEV *getSizeOfExpr(Type *AllocTy); 633 634 /// getAlignOfExpr - Return an expression for alignof on the given type. 635 /// 636 const SCEV *getAlignOfExpr(Type *AllocTy); 637 638 /// getOffsetOfExpr - Return an expression for offsetof on the given field. 639 /// 640 const SCEV *getOffsetOfExpr(StructType *STy, unsigned FieldNo); 641 642 /// getOffsetOfExpr - Return an expression for offsetof on the given field. 643 /// 644 const SCEV *getOffsetOfExpr(Type *CTy, Constant *FieldNo); 645 646 /// getNegativeSCEV - Return the SCEV object corresponding to -V. 647 /// 648 const SCEV *getNegativeSCEV(const SCEV *V); 649 650 /// getNotSCEV - Return the SCEV object corresponding to ~V. 651 /// 652 const SCEV *getNotSCEV(const SCEV *V); 653 654 /// getMinusSCEV - Return LHS-RHS. Minus is represented in SCEV as A+B*-1. 655 const SCEV *getMinusSCEV(const SCEV *LHS, const SCEV *RHS, 656 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap); 657 658 /// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion 659 /// of the input value to the specified type. If the type must be 660 /// extended, it is zero extended. 661 const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty); 662 663 /// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion 664 /// of the input value to the specified type. If the type must be 665 /// extended, it is sign extended. 666 const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty); 667 668 /// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of 669 /// the input value to the specified type. If the type must be extended, 670 /// it is zero extended. The conversion must not be narrowing. 671 const SCEV *getNoopOrZeroExtend(const SCEV *V, Type *Ty); 672 673 /// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of 674 /// the input value to the specified type. If the type must be extended, 675 /// it is sign extended. The conversion must not be narrowing. 676 const SCEV *getNoopOrSignExtend(const SCEV *V, Type *Ty); 677 678 /// getNoopOrAnyExtend - Return a SCEV corresponding to a conversion of 679 /// the input value to the specified type. If the type must be extended, 680 /// it is extended with unspecified bits. The conversion must not be 681 /// narrowing. 682 const SCEV *getNoopOrAnyExtend(const SCEV *V, Type *Ty); 683 684 /// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the 685 /// input value to the specified type. The conversion must not be 686 /// widening. 687 const SCEV *getTruncateOrNoop(const SCEV *V, Type *Ty); 688 689 /// getUMaxFromMismatchedTypes - Promote the operands to the wider of 690 /// the types using zero-extension, and then perform a umax operation 691 /// with them. 692 const SCEV *getUMaxFromMismatchedTypes(const SCEV *LHS, 693 const SCEV *RHS); 694 695 /// getUMinFromMismatchedTypes - Promote the operands to the wider of 696 /// the types using zero-extension, and then perform a umin operation 697 /// with them. 698 const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS, 699 const SCEV *RHS); 700 701 /// getPointerBase - Transitively follow the chain of pointer-type operands 702 /// until reaching a SCEV that does not have a single pointer operand. This 703 /// returns a SCEVUnknown pointer for well-formed pointer-type expressions, 704 /// but corner cases do exist. 705 const SCEV *getPointerBase(const SCEV *V); 706 707 /// getSCEVAtScope - Return a SCEV expression for the specified value 708 /// at the specified scope in the program. The L value specifies a loop 709 /// nest to evaluate the expression at, where null is the top-level or a 710 /// specified loop is immediately inside of the loop. 711 /// 712 /// This method can be used to compute the exit value for a variable defined 713 /// in a loop by querying what the value will hold in the parent loop. 714 /// 715 /// In the case that a relevant loop exit value cannot be computed, the 716 /// original value V is returned. 717 const SCEV *getSCEVAtScope(const SCEV *S, const Loop *L); 718 719 /// getSCEVAtScope - This is a convenience function which does 720 /// getSCEVAtScope(getSCEV(V), L). 721 const SCEV *getSCEVAtScope(Value *V, const Loop *L); 722 723 /// isLoopEntryGuardedByCond - Test whether entry to the loop is protected 724 /// by a conditional between LHS and RHS. This is used to help avoid max 725 /// expressions in loop trip counts, and to eliminate casts. 726 bool isLoopEntryGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, 727 const SCEV *LHS, const SCEV *RHS); 728 729 /// isLoopBackedgeGuardedByCond - Test whether the backedge of the loop is 730 /// protected by a conditional between LHS and RHS. This is used to 731 /// to eliminate casts. 732 bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, 733 const SCEV *LHS, const SCEV *RHS); 734 735 /// getSmallConstantTripCount - Returns the maximum trip count of this loop 736 /// as a normal unsigned value. Returns 0 if the trip count is unknown or 737 /// not constant. This "trip count" assumes that control exits via 738 /// ExitingBlock. More precisely, it is the number of times that control may 739 /// reach ExitingBlock before taking the branch. For loops with multiple 740 /// exits, it may not be the number times that the loop header executes if 741 /// the loop exits prematurely via another branch. 742 unsigned getSmallConstantTripCount(Loop *L, BasicBlock *ExitingBlock); 743 744 /// getSmallConstantTripMultiple - Returns the largest constant divisor of 745 /// the trip count of this loop as a normal unsigned value, if 746 /// possible. This means that the actual trip count is always a multiple of 747 /// the returned value (don't forget the trip count could very well be zero 748 /// as well!). As explained in the comments for getSmallConstantTripCount, 749 /// this assumes that control exits the loop via ExitingBlock. 750 unsigned getSmallConstantTripMultiple(Loop *L, BasicBlock *ExitingBlock); 751 752 // getExitCount - Get the expression for the number of loop iterations for 753 // which this loop is guaranteed not to exit via ExitingBlock. Otherwise 754 // return SCEVCouldNotCompute. 755 const SCEV *getExitCount(Loop *L, BasicBlock *ExitingBlock); 756 757 /// getBackedgeTakenCount - If the specified loop has a predictable 758 /// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute 759 /// object. The backedge-taken count is the number of times the loop header 760 /// will be branched to from within the loop. This is one less than the 761 /// trip count of the loop, since it doesn't count the first iteration, 762 /// when the header is branched to from outside the loop. 763 /// 764 /// Note that it is not valid to call this method on a loop without a 765 /// loop-invariant backedge-taken count (see 766 /// hasLoopInvariantBackedgeTakenCount). 767 /// 768 const SCEV *getBackedgeTakenCount(const Loop *L); 769 770 /// getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except 771 /// return the least SCEV value that is known never to be less than the 772 /// actual backedge taken count. 773 const SCEV *getMaxBackedgeTakenCount(const Loop *L); 774 775 /// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop 776 /// has an analyzable loop-invariant backedge-taken count. 777 bool hasLoopInvariantBackedgeTakenCount(const Loop *L); 778 779 /// forgetLoop - This method should be called by the client when it has 780 /// changed a loop in a way that may effect ScalarEvolution's ability to 781 /// compute a trip count, or if the loop is deleted. 782 void forgetLoop(const Loop *L); 783 784 /// forgetValue - This method should be called by the client when it has 785 /// changed a value in a way that may effect its value, or which may 786 /// disconnect it from a def-use chain linking it to a loop. 787 void forgetValue(Value *V); 788 789 /// GetMinTrailingZeros - Determine the minimum number of zero bits that S 790 /// is guaranteed to end in (at every loop iteration). It is, at the same 791 /// time, the minimum number of times S is divisible by 2. For example, 792 /// given {4,+,8} it returns 2. If S is guaranteed to be 0, it returns the 793 /// bitwidth of S. 794 uint32_t GetMinTrailingZeros(const SCEV *S); 795 796 /// getUnsignedRange - Determine the unsigned range for a particular SCEV. 797 /// 798 ConstantRange getUnsignedRange(const SCEV *S); 799 800 /// getSignedRange - Determine the signed range for a particular SCEV. 801 /// 802 ConstantRange getSignedRange(const SCEV *S); 803 804 /// isKnownNegative - Test if the given expression is known to be negative. 805 /// 806 bool isKnownNegative(const SCEV *S); 807 808 /// isKnownPositive - Test if the given expression is known to be positive. 809 /// 810 bool isKnownPositive(const SCEV *S); 811 812 /// isKnownNonNegative - Test if the given expression is known to be 813 /// non-negative. 814 /// 815 bool isKnownNonNegative(const SCEV *S); 816 817 /// isKnownNonPositive - Test if the given expression is known to be 818 /// non-positive. 819 /// 820 bool isKnownNonPositive(const SCEV *S); 821 822 /// isKnownNonZero - Test if the given expression is known to be 823 /// non-zero. 824 /// 825 bool isKnownNonZero(const SCEV *S); 826 827 /// isKnownPredicate - Test if the given expression is known to satisfy 828 /// the condition described by Pred, LHS, and RHS. 829 /// 830 bool isKnownPredicate(ICmpInst::Predicate Pred, 831 const SCEV *LHS, const SCEV *RHS); 832 833 /// SimplifyICmpOperands - Simplify LHS and RHS in a comparison with 834 /// predicate Pred. Return true iff any changes were made. If the 835 /// operands are provably equal or inequal, LHS and RHS are set to 836 /// the same value and Pred is set to either ICMP_EQ or ICMP_NE. 837 /// 838 bool SimplifyICmpOperands(ICmpInst::Predicate &Pred, 839 const SCEV *&LHS, 840 const SCEV *&RHS, 841 unsigned Depth = 0); 842 843 /// getLoopDisposition - Return the "disposition" of the given SCEV with 844 /// respect to the given loop. 845 LoopDisposition getLoopDisposition(const SCEV *S, const Loop *L); 846 847 /// isLoopInvariant - Return true if the value of the given SCEV is 848 /// unchanging in the specified loop. 849 bool isLoopInvariant(const SCEV *S, const Loop *L); 850 851 /// hasComputableLoopEvolution - Return true if the given SCEV changes value 852 /// in a known way in the specified loop. This property being true implies 853 /// that the value is variant in the loop AND that we can emit an expression 854 /// to compute the value of the expression at any particular loop iteration. 855 bool hasComputableLoopEvolution(const SCEV *S, const Loop *L); 856 857 /// getLoopDisposition - Return the "disposition" of the given SCEV with 858 /// respect to the given block. 859 BlockDisposition getBlockDisposition(const SCEV *S, const BasicBlock *BB); 860 861 /// dominates - Return true if elements that makes up the given SCEV 862 /// dominate the specified basic block. 863 bool dominates(const SCEV *S, const BasicBlock *BB); 864 865 /// properlyDominates - Return true if elements that makes up the given SCEV 866 /// properly dominate the specified basic block. 867 bool properlyDominates(const SCEV *S, const BasicBlock *BB); 868 869 /// hasOperand - Test whether the given SCEV has Op as a direct or 870 /// indirect operand. 871 bool hasOperand(const SCEV *S, const SCEV *Op) const; 872 873 virtual bool runOnFunction(Function &F); 874 virtual void releaseMemory(); 875 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 876 virtual void print(raw_ostream &OS, const Module* = 0) const; 877 878 private: 879 FoldingSet<SCEV> UniqueSCEVs; 880 BumpPtrAllocator SCEVAllocator; 881 882 /// FirstUnknown - The head of a linked list of all SCEVUnknown 883 /// values that have been allocated. This is used by releaseMemory 884 /// to locate them all and call their destructors. 885 SCEVUnknown *FirstUnknown; 886 }; 887} 888 889#endif 890