21 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H
22 #define LLVM_ANALYSIS_SCALAREVOLUTION_H
32 #include "llvm/Support/DataTypes.h"
42 class ScalarEvolution;
44 class TargetLibraryInfo;
51 template<>
struct FoldingSetTrait<SCEV>;
65 const unsigned short SCEVType;
74 void operator=(const
SCEV &) LLVM_DELETED_FUNCTION;
144 return ID == X.FastID;
210 virtual void deleted();
211 virtual void allUsesReplacedWith(
Value *New);
264 ExitLimit(
const SCEV *E) : Exact(E), Max(E) {}
266 ExitLimit(
const SCEV *E,
const SCEV *M) : Exact(E), Max(M) {}
270 bool hasAnyInfo()
const {
271 return !isa<SCEVCouldNotCompute>(Exact) ||
272 !isa<SCEVCouldNotCompute>(Max);
278 struct ExitNotTakenInfo {
279 AssertingVH<BasicBlock> ExitingBlock;
280 const SCEV *ExactNotTaken;
281 PointerIntPair<ExitNotTakenInfo*, 1> NextExit;
283 ExitNotTakenInfo() : ExitingBlock(0), ExactNotTaken(0) {}
286 bool isCompleteList()
const {
287 return NextExit.getInt() == 0;
290 void setIncomplete() { NextExit.setInt(1); }
293 ExitNotTakenInfo *getNextExit()
const {
294 return NextExit.getPointer();
297 void setNextExit(ExitNotTakenInfo *ENT) { NextExit.setPointer(ENT); }
303 class BackedgeTakenInfo {
306 ExitNotTakenInfo ExitNotTaken;
313 BackedgeTakenInfo() : Max(0) {}
317 SmallVectorImpl< std::pair<BasicBlock *, const SCEV *> > &ExitCounts,
318 bool Complete,
const SCEV *MaxCount);
323 bool hasAnyInfo()
const {
324 return ExitNotTaken.ExitingBlock || !isa<SCEVCouldNotCompute>(Max);
352 DenseMap<const Loop*, BackedgeTakenInfo> BackedgeTakenCounts;
359 DenseMap<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
364 DenseMap<
const SCEV *,
365 SmallVector<std::pair<const Loop *, const SCEV *>, 2> > ValuesAtScopes;
368 DenseMap<
const SCEV *,
369 SmallVector<std::pair<const Loop *, LoopDisposition>, 2> > LoopDispositions;
375 DenseMap<
const SCEV *,
376 SmallVector<std::pair<const BasicBlock *, BlockDisposition>, 2> > BlockDispositions;
382 DenseMap<const SCEV *, ConstantRange> UnsignedRanges;
385 DenseMap<const SCEV *, ConstantRange> SignedRanges;
388 const ConstantRange &setUnsignedRange(
const SCEV *S,
389 const ConstantRange &CR) {
390 std::pair<DenseMap<const SCEV *, ConstantRange>::iterator,
bool> Pair =
391 UnsignedRanges.insert(std::make_pair(S, CR));
393 Pair.first->second = CR;
394 return Pair.first->second;
398 const ConstantRange &setSignedRange(
const SCEV *S,
399 const ConstantRange &CR) {
400 std::pair<DenseMap<const SCEV *, ConstantRange>::iterator,
bool> Pair =
401 SignedRanges.insert(std::make_pair(S, CR));
403 Pair.first->second = CR;
404 return Pair.first->second;
409 const SCEV *createSCEV(Value *V);
413 const SCEV *createNodeForPHI(PHINode *PN);
417 const SCEV *createNodeForGEP(GEPOperator *GEP);
422 const SCEV *computeSCEVAtScope(
const SCEV *S,
const Loop *L);
428 void ForgetSymbolicName(Instruction *
I,
const SCEV *SymName);
433 const BackedgeTakenInfo &getBackedgeTakenInfo(
const Loop *L);
437 BackedgeTakenInfo ComputeBackedgeTakenCount(
const Loop *L);
441 ExitLimit ComputeExitLimit(
const Loop *L,
BasicBlock *ExitingBlock);
446 ExitLimit ComputeExitLimitFromCond(
const Loop *L,
455 ExitLimit ComputeExitLimitFromICmp(
const Loop *L,
464 ExitLimit ComputeLoadConstantCompareExitLimit(LoadInst *LI,
474 const SCEV *ComputeExitCountExhaustively(
const Loop *L,
481 ExitLimit HowFarToZero(
const SCEV *V,
const Loop *L,
bool IsSubExpr);
486 ExitLimit HowFarToNonZero(
const SCEV *V,
const Loop *L);
492 ExitLimit HowManyLessThans(
const SCEV *LHS,
const SCEV *RHS,
493 const Loop *L,
bool isSigned,
bool IsSubExpr);
494 ExitLimit HowManyGreaterThans(
const SCEV *LHS,
const SCEV *RHS,
495 const Loop *L,
bool isSigned,
bool IsSubExpr);
501 std::pair<BasicBlock *, BasicBlock *>
502 getPredecessorWithUniqueSuccessorForBB(
BasicBlock *BB);
507 const SCEV *LHS,
const SCEV *RHS,
508 Value *FoundCondValue,
515 const SCEV *LHS,
const SCEV *RHS,
516 const SCEV *FoundLHS,
const SCEV *FoundRHS);
522 const SCEV *LHS,
const SCEV *RHS,
523 const SCEV *FoundLHS,
524 const SCEV *FoundRHS);
530 Constant *getConstantEvolutionLoopExitValue(PHINode *PN,
const APInt& BEs,
538 const SCEV *LHS,
const SCEV *RHS);
541 void forgetMemoizedResults(
const SCEV *S);
545 bool checkValidity(
const SCEV *S)
const;
880 const SCEV *computeBECount(
const SCEV *Delta,
const SCEV *Stride,
886 bool doesIVOverflowOnLT(
const SCEV *RHS,
const SCEV *Stride,
887 bool IsSigned,
bool NoWrap);
892 bool doesIVOverflowOnGT(
const SCEV *RHS,
const SCEV *Stride,
893 bool IsSigned,
bool NoWrap);
const SCEV * getTruncateOrNoop(const SCEV *V, Type *Ty)
COFF::RelocationTypeX86 Type
void push_back(const T &Elt)
The SCEV properly dominates the block.
LLVMContext & getContext() const
#define LLVM_ATTRIBUTE_UNUSED_RESULT
virtual void verifyAnalysis() const
const SCEV * getExitCount(Loop *L, BasicBlock *ExitingBlock)
const SCEV * getConstant(ConstantInt *V)
The main container class for the LLVM Intermediate Representation.
LLVMContext & getContext() const
const SCEV * getMulExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
const SCEV * getPointerBase(const SCEV *V)
bool isKnownNonNegative(const SCEV *S)
const SCEV * getMulExpr(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
const SCEV * getAddExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
bool properlyDominates(const SCEV *S, const BasicBlock *BB)
uint32_t GetMinTrailingZeros(const SCEV *S)
virtual void print(raw_ostream &OS, const Module *=0) const
bool isLoopInvariant(const SCEV *S, const Loop *L)
ConstantRange getUnsignedRange(const SCEV *S)
bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
const SCEV * getUMaxFromMismatchedTypes(const SCEV *LHS, const SCEV *RHS)
LoopInfoBase< BlockT, LoopT > * LI
virtual bool runOnFunction(Function &F)
bool isKnownNonPositive(const SCEV *S)
The SCEV is loop-invariant.
const SCEV * getAddExpr(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
unsigned ComputeHash() const
unsigned short SubclassData
uint64_t getTypeSizeInBits(Type *Ty) const
ID
LLVM Calling Convention Representation.
virtual void getAnalysisUsage(AnalysisUsage &AU) const
static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT clearFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags)
bool isKnownPredicate(ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
const SCEV * getOffsetOfExpr(Type *IntTy, StructType *STy, unsigned FieldNo)
unsigned getSmallConstantTripMultiple(Loop *L, BasicBlock *ExitingBlock)
const SCEV * getSizeOfExpr(Type *IntTy, Type *AllocTy)
Type * getEffectiveSCEVType(Type *Ty) const
const SCEV * getAddRecExpr(const SCEV *Start, const SCEV *Step, const Loop *L, SCEV::NoWrapFlags Flags)
const SCEV * getAddRecExpr(const SmallVectorImpl< const SCEV * > &Operands, const Loop *L, SCEV::NoWrapFlags Flags)
bool isLoopEntryGuardedByCond(const Loop *L, ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
const SCEV * getCouldNotCompute()
bool isSCEVable(Type *Ty) const
static bool Equals(const SCEV &X, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID)
LLVM Basic Block Representation.
LoopDisposition getLoopDisposition(const SCEV *S, const Loop *L)
Instr is a loop (backwards branch).
const SCEV * getSMaxExpr(const SCEV *LHS, const SCEV *RHS)
const SCEV * getSCEVAtScope(const SCEV *S, const Loop *L)
bool hasOperand(const SCEV *S, const SCEV *Op) const
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
getMinusSCEV - Return LHS-RHS. Minus is represented in SCEV as A+B*-1.
const SCEV * getMaxBackedgeTakenCount(const Loop *L)
bool isKnownNegative(const SCEV *S)
void forgetValue(Value *V)
static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags)
const SCEV * getUMinFromMismatchedTypes(const SCEV *LHS, const SCEV *RHS)
bool isNonConstantNegative() const
const SCEV * getNoopOrZeroExtend(const SCEV *V, Type *Ty)
static unsigned ComputeHash(const SCEV &X, FoldingSetNodeID &TempID)
The SCEV is loop-variant (unknown).
const SCEV * getSMinExpr(const SCEV *LHS, const SCEV *RHS)
Class for constant integers.
bool isKnownPositive(const SCEV *S)
const SCEV * getTruncateExpr(const SCEV *Op, Type *Ty)
const SCEV * getTruncateOrSignExtend(const SCEV *V, Type *Ty)
bool isAllOnesValue() const
The SCEV dominates the block.
const SCEV * getNoopOrSignExtend(const SCEV *V, Type *Ty)
ConstantRange getSignedRange(const SCEV *S)
static void Profile(const SCEV &X, FoldingSetNodeID &ID)
const SCEV * getUMaxExpr(const SCEV *LHS, const SCEV *RHS)
static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT maskFlags(SCEV::NoWrapFlags Flags, int Mask)
#define LLVM_DELETED_FUNCTION
Class for arbitrary precision integers.
const SCEV * getSignExtendExpr(const SCEV *Op, Type *Ty)
unsigned getSmallConstantTripCount(Loop *L, BasicBlock *ExitingBlock)
const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
The SCEV does not dominate the block.
void forgetLoop(const Loop *L)
SCEV(const FoldingSetNodeIDRef ID, unsigned SCEVTy)
bool isKnownNonZero(const SCEV *S)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
const SCEV * getBackedgeTakenCount(const Loop *L)
virtual void releaseMemory()
bool SimplifyICmpOperands(ICmpInst::Predicate &Pred, const SCEV *&LHS, const SCEV *&RHS, unsigned Depth=0)
unsigned getSCEVType() const
const SCEV * getUMinExpr(const SCEV *LHS, const SCEV *RHS)
void print(raw_ostream &OS) const
LLVM Value Representation.
const SCEV * getSCEV(Value *V)
const SCEV * getUDivExpr(const SCEV *LHS, const SCEV *RHS)
const SCEV * getUnknown(Value *V)
The SCEV varies predictably with the loop.
bool dominates(const SCEV *S, const BasicBlock *BB)
BlockDisposition getBlockDisposition(const SCEV *S, const BasicBlock *BB)
const SCEV * getTruncateOrZeroExtend(const SCEV *V, Type *Ty)
const SCEV * getNegativeSCEV(const SCEV *V)
const SCEV * getZeroExtendExpr(const SCEV *Op, Type *Ty)
bool hasComputableLoopEvolution(const SCEV *S, const Loop *L)
const SCEV * getNoopOrAnyExtend(const SCEV *V, Type *Ty)
friend class SCEVCallbackVH
const SCEV * getNotSCEV(const SCEV *V)
getNotSCEV - Return a SCEV corresponding to ~V = -1-V
const SCEV * getMulExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
static RegisterPass< NVPTXAllocaHoisting > X("alloca-hoisting","Hoisting alloca instructions in non-entry ""blocks to the entry block")
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const SCEV * getAnyExtendExpr(const SCEV *Op, Type *Ty)