21 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H
22 #define LLVM_ANALYSIS_SCALAREVOLUTION_H
36 #include "llvm/Support/DataTypes.h"
40 class AssumptionCache;
45 class ScalarEvolution;
47 class TargetLibraryInfo;
58 template <>
struct FoldingSetTrait<SCEV>;
59 template <>
struct FoldingSetTrait<SCEVPredicate>;
72 const unsigned short SCEVType;
81 void operator=(
const SCEV &) =
delete;
149 return ID == X.FastID;
231 return ID == X.FastID;
315 assert((OffFlags & IncrementNoWrapMask) == OffFlags &&
316 "Invalid flags value!");
323 assert((Mask & IncrementNoWrapMask) == Mask &&
"Invalid mask value!");
332 assert((OnFlags & IncrementNoWrapMask) == OnFlags &&
333 "Invalid flags value!");
428 ProperlyDominatesBlock
449 class SCEVCallbackVH final :
public CallbackVH {
451 void deleted()
override;
452 void allUsesReplacedWith(
Value *New)
override;
458 friend class SCEVCallbackVH;
488 std::unique_ptr<SCEVCouldNotCompute> CouldNotCompute;
499 typedef std::pair<Value *, ConstantInt *> ValueOffsetPair;
538 bool WalkingBEDominatingConds;
542 bool ProvingSplitPredicate;
555 const SCEV *ExactNotTaken;
556 const SCEV *MaxNotTaken;
565 assert(!isa<SCEVUnionPredicate>(P) &&
"Only add leaf predicates here!");
566 Predicates.insert(P);
569 ExitLimit(
const SCEV *
E);
572 const SCEV *
E,
const SCEV *M,
bool MaxOrZero,
575 ExitLimit(
const SCEV *
E,
const SCEV *M,
bool MaxOrZero,
578 ExitLimit(
const SCEV *
E,
const SCEV *M,
bool MaxOrZero);
582 bool hasAnyInfo()
const {
583 return !isa<SCEVCouldNotCompute>(ExactNotTaken) ||
584 !isa<SCEVCouldNotCompute>(MaxNotTaken);
588 bool hasFullInfo()
const {
589 return !isa<SCEVCouldNotCompute>(ExactNotTaken);
595 struct ExitNotTakenInfo {
596 PoisoningVH<BasicBlock> ExitingBlock;
597 const SCEV *ExactNotTaken;
598 std::unique_ptr<SCEVUnionPredicate>
Predicate;
599 bool hasAlwaysTruePredicate()
const {
603 explicit ExitNotTakenInfo(PoisoningVH<BasicBlock> ExitingBlock,
604 const SCEV *ExactNotTaken,
605 std::unique_ptr<SCEVUnionPredicate>
Predicate)
606 : ExitingBlock(ExitingBlock), ExactNotTaken(ExactNotTaken),
607 Predicate(std::move(Predicate)) {}
613 class BackedgeTakenInfo {
616 SmallVector<ExitNotTakenInfo, 1> ExitNotTaken;
625 PointerIntPair<const SCEV *, 1> MaxAndComplete;
632 bool isComplete()
const {
return MaxAndComplete.getInt(); }
633 const SCEV *getMax()
const {
return MaxAndComplete.getPointer(); }
637 BackedgeTakenInfo() : MaxAndComplete(nullptr, 0), MaxOrZero(
false) {}
639 BackedgeTakenInfo(BackedgeTakenInfo &&) =
default;
640 BackedgeTakenInfo &
operator=(BackedgeTakenInfo &&) =
default;
642 typedef std::pair<BasicBlock *, ExitLimit> EdgeExitInfo;
645 BackedgeTakenInfo(SmallVectorImpl<EdgeExitInfo> &&ExitCounts,
bool Complete,
646 const SCEV *MaxCount,
bool MaxOrZero);
650 bool hasAnyInfo()
const {
651 return !ExitNotTaken.empty() || !isa<SCEVCouldNotCompute>(getMax());
655 bool hasFullInfo()
const {
return isComplete(); }
675 const SCEV *getExact(ScalarEvolution *SE,
676 SCEVUnionPredicate *Predicates =
nullptr)
const;
682 const SCEV *getExact(
BasicBlock *ExitingBlock, ScalarEvolution *SE)
const;
685 const SCEV *getMax(ScalarEvolution *SE)
const;
689 bool isMaxOrZero(ScalarEvolution *SE)
const;
693 bool hasOperand(
const SCEV *S, ScalarEvolution *SE)
const;
701 DenseMap<const Loop *, BackedgeTakenInfo> BackedgeTakenCounts;
705 DenseMap<const Loop *, BackedgeTakenInfo> PredicatedBackedgeTakenCounts;
711 DenseMap<PHINode *, Constant *> ConstantEvolutionLoopExitValue;
716 DenseMap<const SCEV *, SmallVector<std::pair<const Loop *, const SCEV *>, 2>>
720 DenseMap<
const SCEV *,
721 SmallVector<PointerIntPair<const Loop *, 2, LoopDisposition>, 2>>
724 struct LoopProperties {
727 bool HasNoAbnormalExits;
734 bool HasNoSideEffects;
738 DenseMap<const Loop *, LoopProperties> LoopPropertiesCache;
741 LoopProperties getLoopProperties(
const Loop *
L);
743 bool loopHasNoSideEffects(
const Loop *
L) {
744 return getLoopProperties(L).HasNoSideEffects;
747 bool loopHasNoAbnormalExits(
const Loop *
L) {
748 return getLoopProperties(L).HasNoAbnormalExits;
752 LoopDisposition computeLoopDisposition(
const SCEV *S,
const Loop *
L);
757 SmallVector<PointerIntPair<const BasicBlock *, 2, BlockDisposition>, 2>>
761 BlockDisposition computeBlockDisposition(
const SCEV *S,
const BasicBlock *BB);
764 DenseMap<const SCEV *, ConstantRange> UnsignedRanges;
767 DenseMap<const SCEV *, ConstantRange> SignedRanges;
770 enum RangeSignHint { HINT_RANGE_UNSIGNED, HINT_RANGE_SIGNED };
773 const ConstantRange &setRange(
const SCEV *S, RangeSignHint Hint,
775 DenseMap<const SCEV *, ConstantRange> &Cache =
776 Hint == HINT_RANGE_UNSIGNED ? UnsignedRanges : SignedRanges;
778 auto Pair = Cache.try_emplace(S, std::move(CR));
780 Pair.first->second = std::move(CR);
781 return Pair.first->second;
787 const ConstantRange &getRangeRef(
const SCEV *S, RangeSignHint Hint);
791 ConstantRange getRangeForAffineAR(
const SCEV *Start,
const SCEV *Stop,
792 const SCEV *MaxBECount,
unsigned BitWidth);
797 ConstantRange getRangeViaFactoring(
const SCEV *Start,
const SCEV *Stop,
798 const SCEV *MaxBECount,
unsigned BitWidth);
802 const SCEV *createSCEV(Value *V);
805 const SCEV *createNodeForPHI(PHINode *PN);
808 const SCEV *createAddRecFromPHI(PHINode *PN);
811 const SCEV *createSimpleAffineAddRec(PHINode *PN, Value *BEValueV,
815 const SCEV *createNodeFromSelectLikePHI(PHINode *PN);
821 const SCEV *createNodeForSelectOrPHI(Instruction *
I, Value *Cond,
822 Value *TrueVal, Value *FalseVal);
825 const SCEV *createNodeForGEP(GEPOperator *
GEP);
830 const SCEV *computeSCEVAtScope(
const SCEV *S,
const Loop *
L);
835 void forgetSymbolicName(Instruction *
I,
const SCEV *SymName);
840 const BackedgeTakenInfo &getBackedgeTakenInfo(
const Loop *
L);
844 const BackedgeTakenInfo &getPredicatedBackedgeTakenInfo(
const Loop *
L);
849 BackedgeTakenInfo computeBackedgeTakenCount(
const Loop *
L,
850 bool AllowPredicates =
false);
856 ExitLimit computeExitLimit(
const Loop *
L,
BasicBlock *ExitingBlock,
857 bool AllowPredicates =
false);
870 ExitLimit computeExitLimitFromCond(
const Loop *
L, Value *ExitCond,
873 bool AllowPredicates =
false);
878 class ExitLimitCache {
884 SmallDenseMap<PointerIntPair<Value *, 1>, ExitLimit> TripCountMap;
889 bool AllowPredicates;
893 bool AllowPredicates)
894 : L(L), TBB(TBB), FBB(FBB), AllowPredicates(AllowPredicates) {}
896 Optional<ExitLimit>
find(
const Loop *
L, Value *ExitCond,
BasicBlock *TBB,
898 bool AllowPredicates);
900 void insert(
const Loop *
L, Value *ExitCond,
BasicBlock *TBB,
901 BasicBlock *FBB,
bool ControlsExit,
bool AllowPredicates,
902 const ExitLimit &EL);
905 typedef ExitLimitCache ExitLimitCacheTy;
906 ExitLimit computeExitLimitFromCondCached(ExitLimitCacheTy &Cache,
907 const Loop *
L, Value *ExitCond,
910 bool AllowPredicates);
911 ExitLimit computeExitLimitFromCondImpl(ExitLimitCacheTy &Cache,
const Loop *
L,
914 bool AllowPredicates);
921 ExitLimit computeExitLimitFromICmp(
const Loop *
L, ICmpInst *ExitCond,
924 bool AllowPredicates =
false);
929 ExitLimit computeExitLimitFromSingleExitSwitch(
const Loop *
L,
936 ExitLimit computeLoadConstantCompareExitLimit(LoadInst *LI, Constant *RHS,
947 ExitLimit computeShiftCompareExitLimit(Value *LHS, Value *RHS,
const Loop *
L,
955 const SCEV *computeExitCountExhaustively(
const Loop *
L, Value *Cond,
962 ExitLimit howFarToZero(
const SCEV *V,
const Loop *
L,
bool IsSubExpr,
963 bool AllowPredicates =
false);
968 ExitLimit howFarToNonZero(
const SCEV *V,
const Loop *
L);
982 ExitLimit howManyLessThans(
const SCEV *LHS,
const SCEV *RHS,
const Loop *
L,
983 bool isSigned,
bool ControlsExit,
984 bool AllowPredicates =
false);
986 ExitLimit howManyGreaterThans(
const SCEV *LHS,
const SCEV *RHS,
const Loop *
L,
987 bool isSigned,
bool IsSubExpr,
988 bool AllowPredicates =
false);
993 std::pair<BasicBlock *, BasicBlock *>
994 getPredecessorWithUniqueSuccessorForBB(
BasicBlock *BB);
999 Value *FoundCondValue,
bool Inverse);
1006 const SCEV *FoundRHS);
1012 const SCEV *RHS,
const SCEV *FoundLHS,
1013 const SCEV *FoundRHS);
1020 const SCEV *LHS,
const SCEV *RHS,
1021 const SCEV *FoundLHS,
const SCEV *FoundRHS,
1022 unsigned Depth = 0);
1027 const SCEV *LHS,
const SCEV *RHS);
1033 const SCEV *RHS,
const SCEV *FoundLHS,
1034 const SCEV *FoundRHS);
1041 const SCEV *RHS,
const SCEV *FoundLHS,
1042 const SCEV *FoundRHS);
1047 const SCEV *LHS,
const SCEV *RHS);
1056 const SCEV *LHS,
const SCEV *RHS,
1057 const SCEV *FoundLHS,
1058 const SCEV *FoundRHS);
1063 Constant *getConstantEvolutionLoopExitValue(PHINode *PN,
const APInt &BEs,
1070 const SCEV *LHS,
const SCEV *RHS);
1086 bool splitBinaryAdd(
const SCEV *Expr,
const SCEV *&
L,
const SCEV *&R,
1096 Optional<APInt> computeConstantDifference(
const SCEV *LHS,
const SCEV *RHS);
1099 void forgetMemoizedResults(
const SCEV *S);
1102 const SCEV *getExistingSCEV(Value *V);
1106 bool checkValidity(
const SCEV *S)
const;
1114 template <
typename ExtendOpTy>
1115 bool proveNoWrapByVaryingStart(
const SCEV *Start,
const SCEV *Step,
1121 bool isMonotonicPredicateImpl(
const SCEVAddRecExpr *LHS,
1145 bool isSCEVExprNeverPoison(
const Instruction *
I);
1151 bool isAddRecNeverPoison(
const Instruction *
I,
const Loop *
L);
1154 ScalarEvolution(Function &
F, TargetLibraryInfo &TLI, AssumptionCache &AC,
1155 DominatorTree &DT, LoopInfo &LI);
1157 ScalarEvolution(ScalarEvolution &&Arg);
1165 bool isSCEVable(
Type *Ty)
const;
1169 uint64_t getTypeSizeInBits(
Type *Ty)
const;
1174 Type *getEffectiveSCEVType(
Type *Ty)
const;
1182 bool containsAddRecurrence(
const SCEV *S);
1188 void eraseValueFromMap(
Value *V);
1195 const SCEV *getConstant(
const APInt &Val);
1196 const SCEV *getConstant(
Type *Ty, uint64_t V,
bool isSigned =
false);
1203 unsigned Depth = 0);
1206 unsigned Depth = 0) {
1208 return getAddExpr(Ops, Flags,
Depth);
1212 unsigned Depth = 0) {
1214 return getAddExpr(Ops, Flags,
Depth);
1218 unsigned Depth = 0);
1221 unsigned Depth = 0) {
1223 return getMulExpr(Ops, Flags,
Depth);
1227 unsigned Depth = 0) {
1229 return getMulExpr(Ops, Flags,
Depth);
1231 const SCEV *getUDivExpr(
const SCEV *LHS,
const SCEV *RHS);
1232 const SCEV *getUDivExactExpr(
const SCEV *LHS,
const SCEV *RHS);
1240 return getAddRecExpr(NewOp, L, Flags);
1248 createAddRecFromPHIWithCasts(
const SCEVUnknown *SymbolicPHI);
1257 const SCEV *getSMaxExpr(
const SCEV *LHS,
const SCEV *RHS);
1259 const SCEV *getUMaxExpr(
const SCEV *LHS,
const SCEV *RHS);
1261 const SCEV *getSMinExpr(
const SCEV *LHS,
const SCEV *RHS);
1262 const SCEV *getUMinExpr(
const SCEV *LHS,
const SCEV *RHS);
1264 const SCEV *getCouldNotCompute();
1282 const SCEV *getNegativeSCEV(
const SCEV *V,
1287 const SCEV *getNotSCEV(
const SCEV *V);
1290 const SCEV *getMinusSCEV(
const SCEV *LHS,
const SCEV *RHS,
1292 unsigned Depth = 0);
1296 const SCEV *getTruncateOrZeroExtend(
const SCEV *V,
Type *Ty);
1300 const SCEV *getTruncateOrSignExtend(
const SCEV *V,
Type *Ty);
1305 const SCEV *getNoopOrZeroExtend(
const SCEV *V,
Type *Ty);
1310 const SCEV *getNoopOrSignExtend(
const SCEV *V,
Type *Ty);
1315 const SCEV *getNoopOrAnyExtend(
const SCEV *V,
Type *Ty);
1319 const SCEV *getTruncateOrNoop(
const SCEV *V,
Type *Ty);
1323 const SCEV *getUMaxFromMismatchedTypes(
const SCEV *LHS,
const SCEV *RHS);
1327 const SCEV *getUMinFromMismatchedTypes(
const SCEV *LHS,
const SCEV *RHS);
1333 const SCEV *getPointerBase(
const SCEV *V);
1366 unsigned getSmallConstantTripCount(
const Loop *
L);
1375 unsigned getSmallConstantTripCount(
const Loop *
L,
BasicBlock *ExitingBlock);
1380 unsigned getSmallConstantMaxTripCount(
const Loop *
L);
1388 unsigned getSmallConstantTripMultiple(
const Loop *
L);
1396 unsigned getSmallConstantTripMultiple(
const Loop *
L,
1415 const SCEV *getBackedgeTakenCount(
const Loop *
L);
1421 const SCEV *getPredicatedBackedgeTakenCount(
const Loop *
L,
1428 const SCEV *getMaxBackedgeTakenCount(
const Loop *
L);
1432 bool isBackedgeTakenCountMaxOrZero(
const Loop *
L);
1436 bool hasLoopInvariantBackedgeTakenCount(
const Loop *
L);
1442 void forgetLoop(
const Loop *
L);
1447 void forgetValue(
Value *V);
1465 return getRangeRef(S, HINT_RANGE_UNSIGNED);
1470 return getRangeRef(S, HINT_RANGE_UNSIGNED).getUnsignedMin();
1475 return getRangeRef(S, HINT_RANGE_UNSIGNED).getUnsignedMax();
1481 return getRangeRef(S, HINT_RANGE_SIGNED);
1486 return getRangeRef(S, HINT_RANGE_SIGNED).getSignedMin();
1491 return getRangeRef(S, HINT_RANGE_SIGNED).getSignedMax();
1508 bool isKnownNonPositive(
const SCEV *S);
1539 const SCEV *&InvariantLHS,
1540 const SCEV *&InvariantRHS);
1552 LoopDisposition getLoopDisposition(
const SCEV *S,
const Loop *
L);
1561 bool isAvailableAtLoopEntry(
const SCEV *S,
const Loop *
L);
1567 bool hasComputableLoopEvolution(
const SCEV *S,
const Loop *
L);
1571 BlockDisposition getBlockDisposition(
const SCEV *S,
const BasicBlock *BB);
1582 bool hasOperand(
const SCEV *S,
const SCEV *
Op)
const;
1592 const SCEV *ElementSize);
1601 void collectParametricTerms(
const SCEV *Expr,
1606 void computeAccessFunctions(
const SCEV *Expr,
1676 const SCEV *ElementSize);
1681 return F.getParent()->getDataLayout();
1691 const SCEV *rewriteUsingPredicate(
const SCEV *S,
const Loop *
L,
1711 createAddRecFromPHIWithCastsImpl(
const SCEVUnknown *SymbolicPHI);
1715 const SCEV *computeBECount(
const SCEV *Delta,
const SCEV *Stride,
1721 bool doesIVOverflowOnLT(
const SCEV *RHS,
const SCEV *Stride,
bool IsSigned,
1727 bool doesIVOverflowOnGT(
const SCEV *RHS,
const SCEV *Stride,
bool IsSigned,
1746 std::pair<const SCEV *, SmallVector<const SCEVPredicate *, 3>>>
1747 PredicatedSCEVRewrites;
1778 std::unique_ptr<ScalarEvolution> SE;
1788 bool runOnFunction(
Function &
F)
override;
1789 void releaseMemory()
override;
1792 void verifyAnalysis()
const override;
1820 const SCEV *getBackedgeTakenCount();
1851 void updateGeneration();
1855 typedef std::pair<unsigned, const SCEV *> RewriteEntry;
1881 unsigned Generation;
1884 const SCEV *BackedgeCount;
virtual const SCEV * getExpr() const =0
Returns the SCEV to which this predicate applies, or nullptr if this is a SCEVUnionPredicate.
IncrementWrapFlags getFlags() const
Returns the set assumed no overflow flags.
A parsed version of the target data layout string in and methods for querying it. ...
static bool isLoopInvariant(Value *V, const Loop *L, const DominatorTree *DT)
Perform a quick domtree based check for loop invariance assuming that V is used within the loop...
bool isOne() const
Return true if the expression is a constant one.
static unsigned ComputeHash(const SCEVPredicate &X, FoldingSetNodeID &TempID)
A Module instance is used to store all the information related to an LLVM module. ...
LLVMContext & getContext() const
bool isZero() const
Return true if the expression is a constant zero.
virtual bool implies(const SCEVPredicate *N) const =0
Returns true if this predicate implies N.
The main scalar evolution driver.
IncrementWrapFlags
Similar to SCEV::NoWrapFlags, but with slightly different semantics for FlagNUSW. ...
static LLVM_NODISCARD SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags)
static bool Equals(const SCEVPredicate &X, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID)
A cache of .assume calls within a function.
APInt getSignedRangeMin(const SCEV *S)
Determine the min of the signed range for a particular SCEV.
An object of this class is returned by queries that could not be answered.
const SCEV * getExpr() const override
Returns the SCEV to which this predicate applies, or nullptr if this is a SCEVUnionPredicate.
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
APInt getSignedRangeMax(const SCEV *S)
Determine the max of the signed range for a particular SCEV.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
const SCEV * getZero(Type *Ty)
Return a SCEV for the constant 0 of a specific type.
The SCEV is loop-invariant.
static LLVM_NODISCARD SCEVWrapPredicate::IncrementWrapFlags setFlags(SCEVWrapPredicate::IncrementWrapFlags Flags, SCEVWrapPredicate::IncrementWrapFlags OnFlags)
bool isAlwaysTrue() const override
Returns true if the predicate is always true.
const SCEV * getAddExpr(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
const SCEV * getRHS() const
Returns the right hand side of the equality.
const DataLayout & getDataLayout() const
Return the DataLayout associated with the module this SCEV instance is operating on.
unsigned ComputeHash() const
ComputeHash - Compute a strong hash value for this FoldingSetNodeIDRef, used to lookup the node in th...
virtual unsigned getComplexity() const
Returns the estimated complexity of this predicate.
Class to represent struct types.
APInt getUnsignedRangeMax(const SCEV *S)
Determine the max of the unsigned range for a particular SCEV.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
unsigned short SubclassData
This field is initialized to zero and may be used in subclasses to store miscellaneous information...
ScalarEvolution & getSE()
ConstantRange getSignedRange(const SCEV *S)
Determine the signed range for a particular SCEV.
This node represents a polynomial recurrence on the trip count of the specified loop.
bool implies(const SCEVPredicate *N) const override
Implementation of the SCEVPredicate interface.
A CRTP mix-in to automatically provide informational APIs needed for passes.
static bool classof(const SCEVPredicate *P)
Methods for support type inquiry through isa, cast, and dyn_cast:
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
static Optional< bool > isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS, const Value *ARHS, const Value *BLHS, const Value *BRHS, const DataLayout &DL, unsigned Depth, AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT)
Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred ALHS ARHS" is true.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
const SCEV * getAddRecExpr(const SmallVectorImpl< const SCEV * > &Operands, const Loop *L, SCEV::NoWrapFlags Flags)
void forgetLoopDispositions(const Loop *L)
Called when the client has changed the disposition of values in this loop.
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Printer pass for the ScalarEvolutionAnalysis results.
Function Alias Analysis false
virtual bool isAlwaysTrue() const =0
Returns true if the predicate is always true.
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
APInt getUnsignedRangeMin(const SCEV *S)
Determine the min of the unsigned range for a particular SCEV.
FoldingSetTrait - This trait class is used to define behavior of how to "profile" (in the FoldingSet ...
A set of analyses that are preserved following a run of a transformation pass.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
static bool Equals(const SCEV &X, const FoldingSetNodeID &ID, unsigned IDHash, FoldingSetNodeID &TempID)
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Type * getType() const
Return the LLVM type of this SCEV expression.
Allocate memory in an ever growing pool, as if by bump-pointer.
bool isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the give value is known to be non-negative.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
void print(raw_ostream &OS, unsigned Depth=0) const override
Prints a textual representation of this predicate with an indentation of Depth.
static Type * getWiderType(const DataLayout &DL, Type *Ty0, Type *Ty1)
SCEVWrapPredicate(const FoldingSetNodeIDRef ID, const SCEVAddRecExpr *AR, IncrementWrapFlags Flags)
const SCEV * getExpr() const override
Implementation of the SCEVPredicate interface.
SCEVEqualPredicate(const FoldingSetNodeIDRef ID, const SCEV *LHS, const SCEV *RHS)
A CRTP mix-in that provides informational APIs needed for analysis passes.
ScalarEvolutionPrinterPass(raw_ostream &OS)
Represent the analysis usage information of a pass.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
FunctionPass class - This class is used to implement most global optimizations.
static LLVM_NODISCARD SCEV::NoWrapFlags clearFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags)
bool isNonConstantNegative() const
Return true if the specified scev is negated, but not a constant.
SCEVPredicateKind getKind() const
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
static unsigned ComputeHash(const SCEV &X, FoldingSetNodeID &TempID)
The SCEV is loop-variant (unknown).
This class represents an assumption made using SCEV expressions which can be checked at run-time...
void dump() const
This method is used for debugging.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
auto find(R &&Range, const T &Val) -> decltype(std::begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
static LLVM_NODISCARD SCEVWrapPredicate::IncrementWrapFlags clearFlags(SCEVWrapPredicate::IncrementWrapFlags Flags, SCEVWrapPredicate::IncrementWrapFlags OffFlags)
Convenient IncrementWrapFlags manipulation methods.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isAllOnesValue() const
Return true if the expression is a constant all-ones value.
Provides information about what library functions are available for the current target.
The SCEV dominates the block.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
This class represents a range of values.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
static LLVM_NODISCARD SCEVWrapPredicate::IncrementWrapFlags getImpliedFlags(const SCEVAddRecExpr *AR, ScalarEvolution &SE)
Returns the set of SCEVWrapPredicate no wrap flags implied by a SCEVAddRecExpr.
static LLVM_NODISCARD SCEVWrapPredicate::IncrementWrapFlags maskFlags(SCEVWrapPredicate::IncrementWrapFlags Flags, int Mask)
static void Profile(const SCEV &X, FoldingSetNodeID &ID)
SCEVPredicate & operator=(const SCEVPredicate &)=default
static void Profile(const SCEVPredicate &X, FoldingSetNodeID &ID)
LoopDisposition
An enum describing the relationship between a SCEV and a loop.
Class for arbitrary precision integers.
virtual void print(raw_ostream &OS, unsigned Depth=0) const =0
Prints a textual representation of this predicate with an indentation of Depth.
This class uses information about analyze scalars to rewrite expressions in canonical form...
static void clear(coro::Shape &Shape)
static bool classof(const SCEVPredicate *P)
Methods for support type inquiry through isa, cast, and dyn_cast:
SCEVPredicate(const SCEVPredicate &)=default
Analysis pass that exposes the ScalarEvolution for a function.
bool isKnownNegative(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the given value is known be negative (i.e.
unsigned getComplexity() const override
We estimate the complexity of a union predicate as the size number of predicates in the union...
const SCEV * getLHS() const
Returns the left hand side of the equality.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
The SCEV does not dominate the block.
FoldingSetNodeIDRef - This class describes a reference to an interned FoldingSetNodeID, which can be a useful to store node id data rather than using plain FoldingSetNodeIDs, since the 32-element SmallVector is often much larger than necessary, and the possibility of heap allocation means it requires a non-trivial destructor call.
Node - This class is used to maintain the singly linked bucket list in a folding set.
This class represents an analyzed expression in the program.
const ScalarEvolution & getSE() const
const SCEV * getMulExpr(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
SCEV(const FoldingSetNodeIDRef ID, unsigned SCEVTy)
Represents a single loop in the control flow graph.
ScalarEvolution * getSE() const
Returns the ScalarEvolution analysis used.
BlockDisposition
An enum describing the relationship between a SCEV and a basic block.
static LLVM_NODISCARD SCEV::NoWrapFlags maskFlags(SCEV::NoWrapFlags Flags, int Mask)
Convenient NoWrapFlags manipulation that hides enum casts and is visible in the ScalarEvolution name ...
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
#define LLVM_NODISCARD
LLVM_NODISCARD - Warn if a type or return value is discarded.
API to communicate dependencies between analyses during invalidation.
ConstantRange getUnsignedRange(const SCEV *S)
Determine the unsigned range for a particular SCEV.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class represents a composition of other SCEV predicates, and is the class that most clients will...
unsigned getSCEVType() const
const SCEV * getMulExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
void print(raw_ostream &OS) const
Print out the internal representation of this scalar to the specified stream.
LLVM Value Representation.
A vector that has set insertion semantics.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isKnownPositive(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Returns true if the given value is known be positive (i.e.
DefaultFoldingSetTrait - This class provides default implementations for FoldingSetTrait implementati...
This class implements an extremely fast bulk output stream that can only output to a stream...
bool implies(const SCEVPredicate *N) const override
Returns true if this predicate implies N.
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to be non-zero when defined.
Value handle with callbacks on RAUW and destruction.
A container for analyses that lazily runs them and caches their results.
bool isAlwaysTrue() const override
Returns true if the predicate is always true.
This header defines various interfaces for pass management in LLVM.
const SCEV * getAddExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap, unsigned Depth=0)
This class represents an assumption made on an AddRec expression.
static bool classof(const SCEVPredicate *P)
Methods for support type inquiry through isa, cast, and dyn_cast:
NoWrapFlags
NoWrapFlags are bitfield indices into SubclassData.
This class represents an assumption that two SCEV expressions are equal, and this can be checked at r...
A special type used by analysis passes to provide an address that identifies that particular analysis...
static bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
const SmallVectorImpl< const SCEVPredicate * > & getPredicates() const
void print(raw_ostream &OS, unsigned Depth=0) const override
Prints a textual representation of this predicate with an indentation of Depth.