20#ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H
21#define LLVM_ANALYSIS_SCALAREVOLUTION_H
49struct AnalysisOptions;
123template <
typename SCEVPtrT = const SCEV *>
136 template <
typename OtherPtrT,
typename = std::enable_if_t<
137 std::is_convertible_v<OtherPtrT, SCEVPtrT>>>
223 U.setFromOpaqueValue(
P);
237 return LHS.getOpaqueValue() ==
RHS.getOpaqueValue();
251template <
typename ToSCEVPtrT>
253 std::enable_if_t<!is_simple_type<SCEVUse>::value>> {
254 using To = std::remove_cv_t<std::remove_pointer_t<ToSCEVPtrT>>;
269template <
typename ToSCEVPtrT>
271 std::enable_if_t<!is_simple_type<const SCEVUse>::value>>
272 :
CastInfo<SCEVUseT<ToSCEVPtrT>, SCEVUse> {};
373 return ID ==
X.FastID;
451 return ID ==
X.FastID;
535 "Invalid flags value!");
552 "Invalid flags value!");
559 IncrementWrapFlags Flags;
564 IncrementWrapFlags Flags);
573 bool isAlwaysTrue()
const override;
614 bool isAlwaysTrue()
const override;
656 return Flags | OnFlags;
660 return Flags & ~OffFlags;
663 return TestFlags ==
maskFlags(Flags, TestFlags);
770 unsigned Depth = 0) {
780 SCEVFlagsPair Flags = {},
unsigned Depth = 0);
782 unsigned Depth = 0) {
795 SCEVFlagsPair Flags);
797 const Loop *L, SCEVFlagsPair Flags);
809 std::pair<const SCEV *, SmallVector<const SCEVPredicate *, 3>>>
835 bool Sequential =
false);
837 bool Sequential =
false);
937 bool Sequential =
false);
942 bool Sequential =
false);
1048 const SCEV *ExitCount);
1217 if (
const APInt *
C = getConstantAPIntOrNull(S))
1219 return getRangeRef(S, HINT_RANGE_UNSIGNED);
1224 if (
const APInt *
C = getConstantAPIntOrNull(S))
1226 return getRangeRef(S, HINT_RANGE_UNSIGNED).getUnsignedMin();
1231 if (
const APInt *
C = getConstantAPIntOrNull(S))
1233 return getRangeRef(S, HINT_RANGE_UNSIGNED).getUnsignedMax();
1239 if (
const APInt *
C = getConstantAPIntOrNull(S))
1241 return getRangeRef(S, HINT_RANGE_SIGNED);
1246 if (
const APInt *
C = getConstantAPIntOrNull(S))
1248 return getRangeRef(S, HINT_RANGE_SIGNED).getSignedMin();
1253 if (
const APInt *
C = getConstantAPIntOrNull(S))
1255 return getRangeRef(S, HINT_RANGE_SIGNED).getSignedMax();
1282 bool OrNegative =
false);
1311 LLVM_ABI std::pair<const SCEV *, const SCEV *>
1422 bool ControlsOnlyExit,
1423 bool AllowPredicates =
false);
1440 LLVM_ABI std::optional<MonotonicPredicateType>
1455 LLVM_ABI std::optional<LoopInvariantPredicate>
1464 LLVM_ABI std::optional<LoopInvariantPredicate>
1469 const SCEV *MaxIter);
1471 LLVM_ABI std::optional<LoopInvariantPredicate>
1544 FunctionAnalysisManager::Invalidator &Inv);
1587 bool PreserveNUW =
false;
1588 bool PreserveNSW =
false;
1591 const Loop *PendingLoop =
nullptr;
1599 void collectPending();
1608 unsigned Depth = 0);
1614 static void collectFromPHI(
1623 LoopGuards Guards(SE);
1624 Guards.PendingLoop = L;
1641 return getLoopProperties(L).HasNoAbnormalExits;
1664 const Type *Ty =
nullptr;
1678 reinterpret_cast<uintptr_t>(Op.getOpaqueValue()),
1683 return std::tie(Op, Ty, C) == std::tie(
RHS.Op,
RHS.Ty,
RHS.C);
1693 void deleted()
override;
1694 void allUsesReplacedWith(
Value *New)
override;
1700 friend class SCEVCallbackVH;
1707 const AnalysisOptions &Opts;
1733 std::unique_ptr<SCEVCouldNotCompute> CouldNotCompute;
1739 HasRecMapType HasRecMap;
1746 ExprValueMapType ExprValueMap;
1749 using ValueExprMapType =
1753 ValueExprMapType ValueExprMap;
1768 bool WalkingBEDominatingConds =
false;
1772 bool ProvingSplitPredicate =
false;
1782 APInt getConstantMultipleImpl(
const SCEV *S,
1787 struct ExitNotTakenInfo {
1789 const SCEV *ExactNotTaken;
1790 const SCEV *ConstantMaxNotTaken;
1791 const SCEV *SymbolicMaxNotTaken;
1795 const SCEV *ExactNotTaken,
1796 const SCEV *ConstantMaxNotTaken,
1797 const SCEV *SymbolicMaxNotTaken,
1799 : ExitingBlock(ExitingBlock), ExactNotTaken(ExactNotTaken),
1800 ConstantMaxNotTaken(ConstantMaxNotTaken),
1801 SymbolicMaxNotTaken(SymbolicMaxNotTaken), Predicates(Predicates) {}
1803 bool hasAlwaysTruePredicate()
const {
1804 return Predicates.
empty();
1811 class BackedgeTakenInfo {
1812 friend class ScalarEvolution;
1816 SmallVector<ExitNotTakenInfo, 1> ExitNotTaken;
1821 const SCEV *ConstantMax =
nullptr;
1825 bool IsComplete =
false;
1829 const SCEV *SymbolicMax =
nullptr;
1832 bool MaxOrZero =
false;
1834 bool isComplete()
const {
return IsComplete; }
1835 const SCEV *getConstantMax()
const {
return ConstantMax; }
1837 LLVM_ABI const ExitNotTakenInfo *getExitNotTaken(
1838 const BasicBlock *ExitingBlock,
1839 SmallVectorImpl<const SCEVPredicate *> *Predicates =
nullptr)
const;
1842 BackedgeTakenInfo() =
default;
1843 BackedgeTakenInfo(BackedgeTakenInfo &&) =
default;
1844 BackedgeTakenInfo &operator=(BackedgeTakenInfo &&) =
default;
1846 using EdgeExitInfo = std::pair<BasicBlock *, ExitLimit>;
1850 bool IsComplete,
const SCEV *ConstantMax,
1855 bool hasAnyInfo()
const {
1856 return !ExitNotTaken.empty() ||
1861 bool hasFullInfo()
const {
return isComplete(); }
1882 const Loop *L, ScalarEvolution *SE,
1883 SmallVectorImpl<const SCEVPredicate *> *Predicates =
nullptr)
const;
1890 const SCEV *getExact(
1891 const BasicBlock *ExitingBlock, ScalarEvolution *SE,
1892 SmallVectorImpl<const SCEVPredicate *> *Predicates =
nullptr)
const {
1893 if (
auto *ENT = getExitNotTaken(ExitingBlock, Predicates))
1894 return ENT->ExactNotTaken;
1896 return SE->getCouldNotCompute();
1900 LLVM_ABI const SCEV *getConstantMax(
1901 ScalarEvolution *SE,
1902 SmallVectorImpl<const SCEVPredicate *> *Predicates =
nullptr)
const;
1905 const SCEV *getConstantMax(
1906 const BasicBlock *ExitingBlock, ScalarEvolution *SE,
1907 SmallVectorImpl<const SCEVPredicate *> *Predicates =
nullptr)
const {
1908 if (
auto *ENT = getExitNotTaken(ExitingBlock, Predicates))
1909 return ENT->ConstantMaxNotTaken;
1911 return SE->getCouldNotCompute();
1915 LLVM_ABI const SCEV *getSymbolicMax(
1916 const Loop *L, ScalarEvolution *SE,
1917 SmallVectorImpl<const SCEVPredicate *> *Predicates =
nullptr);
1920 const SCEV *getSymbolicMax(
1921 const BasicBlock *ExitingBlock, ScalarEvolution *SE,
1922 SmallVectorImpl<const SCEVPredicate *> *Predicates =
nullptr)
const {
1923 if (
auto *ENT = getExitNotTaken(ExitingBlock, Predicates))
1924 return ENT->SymbolicMaxNotTaken;
1926 return SE->getCouldNotCompute();
1931 LLVM_ABI bool isConstantMaxOrZero(ScalarEvolution *SE)
const;
1936 DenseMap<const Loop *, BackedgeTakenInfo> BackedgeTakenCounts;
1940 DenseMap<const Loop *, BackedgeTakenInfo> PredicatedBackedgeTakenCounts;
1943 DenseMap<const SCEV *, SmallPtrSet<PointerIntPair<const Loop *, 1, bool>, 4>>
1950 DenseMap<PHINode *, Constant *> ConstantEvolutionLoopExitValue;
1955 DenseMap<const SCEV *, SmallVector<std::pair<const Loop *, SCEVUse>, 2>>
1960 DenseMap<const SCEV *, SmallVector<std::pair<const Loop *, const SCEV *>, 2>>
1961 ValuesAtScopesUsers;
1964 DenseMap<
const SCEV *,
1968 struct LoopProperties {
1974 bool HasNoAbnormalExits;
1978 bool HasNoSideEffects;
1982 DenseMap<const Loop *, LoopProperties> LoopPropertiesCache;
1985 LLVM_ABI LoopProperties getLoopProperties(
const Loop *L);
1987 bool loopHasNoSideEffects(
const Loop *L) {
1988 return getLoopProperties(L).HasNoSideEffects;
2001 BlockDisposition computeBlockDisposition(
const SCEV *S,
const BasicBlock *BB);
2004 DenseMap<const SCEV *, SmallPtrSet<const SCEV *, 8> > SCEVUsers;
2007 DenseMap<const SCEV *, ConstantRange> UnsignedRanges;
2010 DenseMap<const SCEV *, ConstantRange> SignedRanges;
2013 enum RangeSignHint { HINT_RANGE_UNSIGNED, HINT_RANGE_SIGNED };
2016 const ConstantRange &setRange(
const SCEV *S, RangeSignHint Hint,
2018 DenseMap<const SCEV *, ConstantRange> &Cache =
2019 Hint == HINT_RANGE_UNSIGNED ? UnsignedRanges : SignedRanges;
2021 auto Pair = Cache.insert_or_assign(S, std::move(CR));
2022 return Pair.first->second;
2028 LLVM_ABI const ConstantRange &getRangeRef(
const SCEV *S, RangeSignHint Hint,
2029 unsigned Depth = 0);
2033 const ConstantRange &getRangeRefIter(
const SCEV *S, RangeSignHint Hint);
2037 std::pair<ConstantRange, SCEVFlags>
2038 getRangeForAffineAR(
const SCEV *Start,
const SCEV *Step,
2039 const APInt &MaxBECount);
2042 LLVM_ABI static const APInt *getConstantAPIntOrNull(
const SCEV *S);
2046 ConstantRange getRangeForAffineNoSelfWrappingAR(
const SCEVAddRecExpr *AddRec,
2047 const SCEV *MaxBECount,
2049 RangeSignHint SignHint);
2054 ConstantRange getRangeViaFactoring(
const SCEV *Start,
const SCEV *Step,
2055 const APInt &MaxBECount);
2061 ConstantRange getRangeForUnknownRecurrence(
const SCEVUnknown *U);
2065 const SCEV *createSCEV(
Value *V);
2069 const SCEV *createSCEVIter(
Value *V);
2073 const SCEV *getOperandsToCreate(
Value *V, SmallVectorImpl<Value *> &
Ops);
2077 const SCEV *createNodeForPHIWithIdenticalOperands(PHINode *PN);
2080 const SCEV *createNodeForPHI(PHINode *PN);
2083 const SCEV *createAddRecFromPHI(PHINode *PN);
2086 const SCEV *createSimpleAffineAddRec(PHINode *PN,
Value *BEValueV,
2087 Value *StartValueV);
2090 const SCEV *createNodeFromSelectLikePHI(PHINode *PN);
2096 std::optional<const SCEV *>
2097 createNodeForSelectOrPHIInstWithICmpInstCond(
Type *Ty, ICmpInst *
Cond,
2113 const SCEV *createNodeForGEP(GEPOperator *
GEP);
2117 SCEVUse computeSCEVAtScope(
const SCEV *S,
const Loop *L);
2122 BackedgeTakenInfo &getBackedgeTakenInfo(
const Loop *L);
2126 BackedgeTakenInfo &getPredicatedBackedgeTakenInfo(
const Loop *L);
2131 BackedgeTakenInfo computeBackedgeTakenCount(
const Loop *L,
2132 bool AllowPredicates =
false);
2143 ExitLimit computeExitLimit(
const Loop *L, BasicBlock *ExitingBlock,
2144 bool IsOnlyExit,
bool AllowPredicates =
false);
2149 class ExitLimitCache {
2155 SmallDenseMap<PointerIntPair<Value *, 1>, ExitLimit> TripCountMap;
2159 bool AllowPredicates;
2162 ExitLimitCache(
const Loop *L,
bool ExitIfTrue,
bool AllowPredicates)
2163 : L(L), ExitIfTrue(ExitIfTrue), AllowPredicates(AllowPredicates) {}
2167 bool ControlsOnlyExit,
2168 bool AllowPredicates);
2171 bool ControlsOnlyExit,
bool AllowPredicates,
2172 const ExitLimit &EL);
2175 using ExitLimitCacheTy = ExitLimitCache;
2177 ExitLimit computeExitLimitFromCondCached(ExitLimitCacheTy &Cache,
2180 bool ControlsOnlyExit,
2181 bool AllowPredicates);
2182 ExitLimit computeExitLimitFromCondImpl(ExitLimitCacheTy &Cache,
const Loop *L,
2183 Value *ExitCond,
bool ExitIfTrue,
2184 bool ControlsOnlyExit,
2185 bool AllowPredicates);
2186 std::optional<ScalarEvolution::ExitLimit>
2187 computeExitLimitFromCondFromBinOp(ExitLimitCacheTy &Cache,
const Loop *L,
2188 Value *ExitCond,
bool ExitIfTrue,
2189 bool AllowPredicates);
2196 ExitLimit computeExitLimitFromICmp(
const Loop *L, ICmpInst *ExitCond,
2199 bool AllowPredicates =
false);
2205 ExitLimit computeExitLimitFromICmp(
const Loop *L, CmpPredicate Pred,
2207 bool AllowPredicates =
false);
2212 ExitLimit computeExitLimitFromSingleExitSwitch(
const Loop *L,
2214 BasicBlock *ExitingBB,
2232 const SCEV *computeExitCountExhaustively(
const Loop *L,
Value *
Cond,
2239 ExitLimit howFarToZero(
const SCEV *V,
const Loop *L,
bool IsSubExpr,
2240 bool AllowPredicates =
false);
2262 bool IsSigned,
bool Invert,
bool ControlsOnlyExit,
2263 bool AllowPredicates =
false);
2268 std::pair<const BasicBlock *, const BasicBlock *>
2269 getPredecessorWithUniqueSuccessorForBB(
const BasicBlock *BB)
const;
2275 LLVM_ABI bool isImpliedCond(CmpPredicate Pred,
const SCEV *
LHS,
2276 const SCEV *
RHS,
const Value *FoundCondValue,
2278 const Instruction *
Context =
nullptr);
2287 const Instruction *CtxI);
2293 LLVM_ABI bool isImpliedCond(CmpPredicate Pred,
const SCEV *
LHS,
2294 const SCEV *
RHS, CmpPredicate FoundPred,
2295 const SCEV *FoundLHS,
const SCEV *FoundRHS,
2296 const Instruction *
Context =
nullptr);
2302 bool isImpliedCondOperands(CmpPredicate Pred,
const SCEV *
LHS,
2303 const SCEV *
RHS,
const SCEV *FoundLHS,
2304 const SCEV *FoundRHS,
2305 const Instruction *
Context =
nullptr);
2311 bool isImpliedViaOperations(CmpPredicate Pred,
const SCEV *
LHS,
2312 const SCEV *
RHS,
const SCEV *FoundLHS,
2313 const SCEV *FoundRHS,
unsigned Depth = 0);
2317 bool isKnownViaNonRecursiveReasoning(CmpPredicate Pred,
SCEVUse LHS,
2323 bool isImpliedCondOperandsHelper(CmpPredicate Pred,
const SCEV *
LHS,
2324 const SCEV *
RHS,
const SCEV *FoundLHS,
2325 const SCEV *FoundRHS);
2331 bool isImpliedCondOperandsViaRanges(CmpPredicate Pred,
const SCEV *
LHS,
2332 const SCEV *
RHS, CmpPredicate FoundPred,
2333 const SCEV *FoundLHS,
2334 const SCEV *FoundRHS);
2339 bool isImpliedCondViaSignFlippedPred(CmpPredicate Pred,
const SCEV *
LHS,
2340 const SCEV *
RHS,
const SCEV *FoundLHS,
2341 const SCEV *FoundRHS,
2342 const Instruction *CtxI);
2346 bool isImpliedViaGuard(
const BasicBlock *BB, CmpPredicate Pred,
2347 const SCEV *
LHS,
const SCEV *
RHS);
2355 bool isImpliedCondOperandsViaNoOverflow(CmpPredicate Pred,
const SCEV *
LHS,
2356 const SCEV *
RHS,
const SCEV *FoundLHS,
2357 const SCEV *FoundRHS);
2365 bool isImpliedCondOperandsViaAddRecStart(CmpPredicate Pred,
const SCEV *
LHS,
2367 const SCEV *FoundLHS,
2368 const SCEV *FoundRHS,
2369 const Instruction *CtxI);
2378 bool isImpliedViaMerge(CmpPredicate Pred,
const SCEV *
LHS,
const SCEV *
RHS,
2379 const SCEV *FoundLHS,
const SCEV *FoundRHS,
2387 bool isImpliedCondOperandsViaShift(CmpPredicate Pred,
const SCEV *
LHS,
2388 const SCEV *
RHS,
const SCEV *FoundLHS,
2389 const SCEV *FoundRHS);
2396 bool isImpliedCondOperandsViaMatchingDiff(CmpPredicate Pred,
const SCEV *
LHS,
2398 const SCEV *FoundLHS,
2399 const SCEV *FoundRHS);
2404 Constant *getConstantEvolutionLoopExitValue(PHINode *PN,
const APInt &BEs,
2409 bool isKnownPredicateViaConstantRanges(CmpPredicate Pred,
SCEVUse LHS,
2417 bool isKnownPredicateViaNoOverflow(CmpPredicate Pred,
SCEVUse LHS,
2422 bool isKnownPredicateViaSplitting(CmpPredicate Pred,
SCEVUse LHS,
2435 void forgetMemoizedResultsImpl(
const SCEV *S);
2439 void visitAndClearUsers(SmallVectorImpl<Instruction *> &Worklist,
2440 SmallPtrSetImpl<Instruction *> &Visited,
2441 SmallVectorImpl<SCEVUse> &ToForget);
2444 void eraseValueFromMap(
Value *V);
2447 void insertValueToMap(
Value *V,
const SCEV *S);
2451 bool checkValidity(
const SCEV *S)
const;
2458 template <
typename ExtendOpTy>
2459 bool proveNoWrapByVaryingStart(
const SCEV *Start,
const SCEV *Step,
2463 void inferNoWrapViaConstantRanges(
const SCEVAddRecExpr *AR);
2467 SCEVFlags proveNoSignedWrapViaInduction(
const SCEVAddRecExpr *AR);
2471 SCEVFlags proveNoUnsignedWrapViaInduction(
const SCEVAddRecExpr *AR);
2473 std::optional<MonotonicPredicateType>
2474 getMonotonicPredicateTypeImpl(
const SCEVAddRecExpr *
LHS,
2486 const Instruction *getNonTrivialDefiningScopeBound(
const SCEV *S);
2500 bool isGuaranteedToTransferExecutionTo(
const Instruction *
A,
2501 const Instruction *
B);
2519 bool isSCEVExprNeverPoison(
const Instruction *
I);
2525 bool isAddRecNeverPoison(
const Instruction *
I,
const Loop *L);
2537 std::optional<std::pair<const SCEV *, SmallVector<const SCEVPredicate *, 3>>>
2538 createAddRecFromPHIWithCastsImpl(
const SCEVUnknown *SymbolicPHI);
2542 APInt getRangeMin(
const SCEV *S,
bool IsSigned,
bool Invert =
false) {
2544 return ~getRangeMax(S, IsSigned);
2549 APInt getRangeMax(
const SCEV *S,
bool IsSigned,
bool Invert =
false) {
2551 return ~getRangeMin(S, IsSigned);
2565 const SCEV *computeMaxBECountForLT(
const SCEV *Start,
const SCEV *Stride,
2567 bool IsSigned,
bool Invert);
2572 bool canIVOverflowOnLT(
const SCEV *
RHS,
const SCEV *Stride,
bool IsSigned,
2573 bool Invert =
false);
2589 const SCEV *stripInjectiveFunctions(
const SCEV *Val)
const;
2594 void getUsedLoops(
const SCEV *S, SmallPtrSetImpl<const Loop *> &LoopsUsed);
2600 const Loop *L =
nullptr);
2604 void getReachableBlocks(SmallPtrSetImpl<BasicBlock *> &Reachable,
2609 const SCEV *getWithOperands(
const SCEV *S, SmallVectorImpl<SCEVUse> &NewOps);
2617 DenseMap<ConstantInt *, SCEVConstant *> ConstantSCEVs;
2620 DenseMap<const Loop *, SmallVector<const SCEVAddRecExpr *, 4>> LoopUsers;
2624 DenseMap<std::pair<const SCEVUnknown *, const Loop *>,
2625 std::pair<const SCEV *, SmallVector<const SCEVPredicate *, 3>>>
2626 PredicatedSCEVRewrites;
2630 SmallPtrSet<const SCEVAddRecExpr *, 16> UnsignedWrapViaInductionTried;
2634 SmallPtrSet<const SCEVAddRecExpr *, 16> SignedWrapViaInductionTried;
2642 unsigned NextUnknownOrderID = 0;
2677 std::unique_ptr<ScalarEvolution> SE;
2688 void releaseMemory()
override;
2691 void verifyAnalysis()
const override;
2770 void updateGeneration();
2774 using RewriteEntry = std::pair<unsigned, const SCEV *>;
2781 DenseMap<const SCEV *, RewriteEntry> RewriteMap;
2784 ScalarEvolution &SE;
2791 std::unique_ptr<SCEVUnionPredicate> Preds;
2797 unsigned Generation = 0;
2800 const SCEV *BackedgeCount =
nullptr;
2803 const SCEV *SymbolicMaxBackedgeCount =
nullptr;
2806 std::optional<unsigned> SmallConstantMaxTripCount;
2826 if (
A.getPointer() ==
B.getPointer()) {
2827 A.setInt(
A.getInt() |
B.getInt());
2830 if (
A.getCanonical() ==
B.getCanonical())
2831 return A.getCanonical();
2835template <
typename SCEVPtrT>
2845#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
2846template <
typename SCEVPtrT>
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
SmallPtrSet< const BasicBlock *, 8 > VisitedBlocks
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
static bool isSigned(unsigned Opcode)
This file defines a hash set that can be used to remove duplication of nodes in a graph.
Value * getPointer(Value *Ptr)
This header defines various interfaces for pass management in LLVM.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
This file defines the PointerIntPair class.
SmallVector< MachineOperand, 4 > Cond
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
Class for arbitrary precision integers.
static APInt getOneBitSet(unsigned numBits, unsigned BitNo)
Return an APInt with exactly one bit set in the result.
Represent the analysis usage information of a pass.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
Value handle with callbacks on RAUW and destruction.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
This is the shared class of boolean and integer constants.
This class represents a range of values.
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
This class describes a reference to an interned FoldingSetNodeID, which can be a useful to store node...
This class is used to gather all the unique data bits of a node.
Represents flags for the getelementptr instruction/expression.
static GEPNoWrapFlags none()
This is an important class for using LLVM in a threaded context.
Represents a single loop in the control flow graph.
A Module instance is used to store all the information related to an LLVM module.
Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.
void * getOpaqueValue() const
constexpr PointerIntPair()=default
bool operator>(const PointerIntPair &RHS) const
SCEVPtrT getPointer() const
void setFromOpaqueValue(void *Val) &
Value handle that poisons itself if the Value is deleted.
An interface layer with SCEV used to manage how we see SCEV expressions for values in the context of ...
LLVM_ABI void addPredicate(const SCEVPredicate &Pred)
Adds a new predicate.
ScalarEvolution * getSE() const
Returns the ScalarEvolution analysis used.
LLVM_ABI const SCEVPredicate & getPredicate() const
LLVM_ABI const SCEV * getPredicatedSCEV(const SCEV *Expr)
Returns the rewritten SCEV for Expr in the context of the current SCEV predicate.
LLVM_ABI bool areAddRecsEqualWithPreds(const SCEVAddRecExpr *AR1, const SCEVAddRecExpr *AR2, ArrayRef< const SCEVPredicate * > ExtraPreds={}) const
Check if AR1 and AR2 are equal, while taking into account Equal predicates in Preds and ExtraPreds.
LLVM_ABI const SCEVAddRecExpr * getAsAddRec(Value *V, SmallVectorImpl< const SCEVPredicate * > *WrapPredsAdded=nullptr)
Attempts to produce an AddRecExpr for V by adding additional SCEV predicates.
LLVM_ABI void print(raw_ostream &OS, unsigned Depth) const
Print the SCEV mappings done by the Predicated Scalar Evolution.
LLVM_ABI PredicatedScalarEvolution(ScalarEvolution &SE, Loop &L)
LLVM_ABI unsigned getSmallConstantMaxTripCount()
Returns the upper bound of the loop trip count as a normal unsigned value, or 0 if the trip count is ...
LLVM_ABI void addPredicates(ArrayRef< const SCEVPredicate * > Preds)
Adds all predicates in Preds.
LLVM_ABI const SCEV * getBackedgeTakenCount()
Get the (predicated) backedge count for the analyzed loop.
LLVM_ABI const SCEV * getSymbolicMaxBackedgeTakenCount()
Get the (predicated) symbolic max backedge count for the analyzed loop.
LLVM_ABI const SCEV * getSCEV(Value *V)
Returns the SCEV expression of V, in the context of the current SCEV predicate.
A set of analyses that are preserved following a run of a transformation pass.
This node represents a polynomial recurrence on the trip count of the specified loop.
SCEVComparePredicate(const FoldingSetNodeIDRef ID, const ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
const SCEV * getRHS() const
Returns the right hand side of the predicate.
ICmpInst::Predicate getPredicate() const
bool isAlwaysTrue() const override
Returns true if the predicate is always true.
const SCEV * getLHS() const
Returns the left hand side of the predicate.
static bool classof(const SCEVPredicate *P)
Methods for support type inquiry through isa, cast, and dyn_cast:
bool implies(const SCEVPredicate *N, ScalarEvolution &SE) const override
Implementation of the SCEVPredicate interface.
This class represents a constant integer value.
This class represents an assumption made using SCEV expressions which can be checked at run-time.
SCEVPredicateKind getKind() const
virtual unsigned getComplexity() const
Returns the estimated complexity of this predicate.
SCEVPredicate & operator=(const SCEVPredicate &)=default
SCEVPredicate(const SCEVPredicate &)=default
virtual bool implies(const SCEVPredicate *N, ScalarEvolution &SE) const =0
Returns true if this predicate implies N.
virtual void print(raw_ostream &OS, unsigned Depth=0) const =0
Prints a textual representation of this predicate with an indentation of Depth.
virtual bool isAlwaysTrue() const =0
Returns true if the predicate is always true.
unsigned getComplexity() const override
We estimate the complexity of a union predicate as the size number of predicates in the union.
SCEVUnionPredicate(ArrayRef< const SCEVPredicate * > Preds, ScalarEvolution &SE)
Union predicates don't get cached so create a dummy set ID for it.
SCEVUnionPredicate getUnionWith(const SCEVPredicate *N, ScalarEvolution &SE) const
Returns a new SCEVUnionPredicate that is the union of this predicate and the given predicate N.
ArrayRef< const SCEVPredicate * > getPredicates() const
static bool classof(const SCEVPredicate *P)
Methods for support type inquiry through isa, cast, and dyn_cast:
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
This class represents an assumption made on an AddRec expression.
IncrementWrapFlags
Similar to SCEVFlags, but with slightly different semantics for FlagNUSW.
SCEVWrapPredicate(const FoldingSetNodeIDRef ID, const SCEVAddRecExpr *AR, IncrementWrapFlags Flags)
static SCEVWrapPredicate::IncrementWrapFlags setFlags(SCEVWrapPredicate::IncrementWrapFlags Flags, SCEVWrapPredicate::IncrementWrapFlags OnFlags)
static SCEVWrapPredicate::IncrementWrapFlags clearFlags(SCEVWrapPredicate::IncrementWrapFlags Flags, SCEVWrapPredicate::IncrementWrapFlags OffFlags)
Convenient IncrementWrapFlags manipulation methods.
static bool classof(const SCEVPredicate *P)
Methods for support type inquiry through isa, cast, and dyn_cast:
IncrementWrapFlags getFlags() const
Returns the set assumed no overflow flags.
static SCEVWrapPredicate::IncrementWrapFlags maskFlags(SCEVWrapPredicate::IncrementWrapFlags Flags, int Mask)
This class represents an analyzed expression in the program.
unsigned short getExpressionSize() const
SCEV & operator=(const SCEV &)=delete
static constexpr auto FlagsNoWrapMask
LLVM_ABI bool isOne() const
Return true if the expression is a constant one.
SCEV(const FoldingSetNodeIDRef ID, SCEVTypes SCEVTy, unsigned short ExpressionSize, Type *Ty)
static constexpr auto FlagNUW
LLVM_ABI void computeAndSetCanonical(ScalarEvolution &SE)
Compute and set the canonical SCEV, by constructing a SCEV with the same operands,...
LLVM_ABI bool isZero() const
Return true if the expression is a constant zero.
const SCEV * getCanonical() const
Return the canonical SCEV.
SCEV(const SCEV &)=delete
static constexpr auto FlagsMask
const SCEV * CanonicalSCEV
Pointer to the canonical version of the SCEV, i.e.
LLVM_ABI void dump() const
This method is used for debugging.
Type *const Ty
Immutable type of the SCEV.
LLVM_ABI bool isAllOnesValue() const
Return true if the expression is a constant all-ones value.
LLVM_ABI bool isNonConstantNegative() const
Return true if the specified scev is negated, but not a constant.
static constexpr auto FlagNSW
LLVM_ABI ArrayRef< SCEVUse > operands() const
Return operands of this SCEV expression.
const unsigned short ExpressionSize
Type * getType() const
Return the LLVM type of this SCEV expression.
static constexpr auto FlagNone
LLVM_ABI void print(raw_ostream &OS) const
Print out the internal representation of this scalar to the specified stream.
SCEVTypes getSCEVType() const
unsigned short SubclassData
This field is initialized to zero and may be used in subclasses to store miscellaneous information.
static constexpr auto FlagNW
Analysis pass that exposes the ScalarEvolution for a function.
LLVM_ABI ScalarEvolution run(Function &F, FunctionAnalysisManager &AM)
ScalarEvolutionPrinterPass(raw_ostream &OS)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Verifier pass for the ScalarEvolutionAnalysis results.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
ScalarEvolution & getSE()
ScalarEvolutionWrapperPass()
const ScalarEvolution & getSE() const
bool operator==(const FoldID &RHS) const
FoldID(SCEVTypes C, SCEVUse Op, const Type *Ty)
unsigned computeHash() const
friend class ScalarEvolution
static LoopGuards collectOnDemand(const Loop *L, ScalarEvolution &SE)
Return loop guards for loop L, which are collected on first use.
LLVM_ABI const SCEV * rewrite(const SCEV *Expr) const
Try to apply the collected loop guards to Expr.
The main scalar evolution driver.
LLVM_ABI const SCEV * getUDivExpr(SCEVUse LHS, SCEVUse RHS)
Get a canonical unsigned division expression, or something simpler if possible.
const SCEV * getConstantMaxBackedgeTakenCount(const Loop *L)
When successful, this returns a SCEVConstant that is greater than or equal to (i.e.
const DataLayout & getDataLayout() const
Return the DataLayout associated with the module this SCEV instance is operating on.
LLVM_ABI bool isKnownNonNegative(const SCEV *S)
Test if the given expression is known to be non-negative.
LLVM_ABI bool isKnownOnEveryIteration(CmpPredicate Pred, const SCEVAddRecExpr *LHS, const SCEV *RHS)
Test if the condition described by Pred, LHS, RHS is known to be true on every iteration of the loop ...
static bool hasFlags(SCEVFlags Flags, SCEVFlags TestFlags)
LLVM_ABI std::optional< LoopInvariantPredicate > getLoopInvariantExitCondDuringFirstIterationsImpl(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, const Instruction *CtxI, const SCEV *MaxIter)
LLVM_ABI const SCEV * getZeroExtendExpr(SCEVUse Op, Type *Ty, unsigned Depth=0)
LLVM_ABI const SCEV * getUDivCeilSCEV(const SCEV *N, const SCEV *D)
Compute ceil(N / D).
LLVM_ABI std::optional< LoopInvariantPredicate > getLoopInvariantExitCondDuringFirstIterations(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, const Instruction *CtxI, const SCEV *MaxIter)
If the result of the predicate LHS Pred RHS is loop invariant with respect to L at given Context duri...
LLVM_ABI Type * getWiderType(Type *Ty1, Type *Ty2) const
LLVM_ABI const SCEV * getAbsExpr(const SCEV *Op, bool IsNSW)
LLVM_ABI bool isKnownNonPositive(const SCEV *S)
Test if the given expression is known to be non-positive.
LLVM_ABI const SCEV * getElementCount(Type *Ty, ElementCount EC, SCEVFlags Flags=SCEV::FlagNone)
LLVM_ABI bool isKnownNegative(const SCEV *S)
Test if the given expression is known to be negative.
LLVM_ABI const SCEV * getPredicatedConstantMaxBackedgeTakenCount(const Loop *L, SmallVectorImpl< const SCEVPredicate * > &Predicates)
Similar to getConstantMaxBackedgeTakenCount, except it will add a set of SCEV predicates to Predicate...
LLVM_ABI const SCEV * removePointerBase(const SCEV *S)
Compute an expression equivalent to S - getPointerBase(S).
LLVM_ABI bool isLoopEntryGuardedByCond(const Loop *L, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
Test whether entry to the loop is protected by a conditional between LHS and RHS.
LLVM_ABI bool isKnownNonZero(const SCEV *S)
Test if the given expression is known to be non-zero.
LLVM_ABI const SCEV * getURemExpr(SCEVUse LHS, SCEVUse RHS)
Represents an unsigned remainder expression based on unsigned division.
LLVM_ABI const SCEV * getBackedgeTakenCount(const Loop *L, ExitCountKind Kind=Exact)
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCould...
LLVM_ABI const SCEV * getSMinExpr(SCEVUse LHS, SCEVUse RHS)
LLVM_ABI const SCEV * getUMaxFromMismatchedTypes(const SCEV *LHS, const SCEV *RHS)
Promote the operands to the wider of the types using zero-extension, and then perform a umax operatio...
const SCEV * getZero(Type *Ty)
Return a SCEV for the constant 0 of a specific type.
LLVM_ABI bool willNotOverflow(Instruction::BinaryOps BinOp, bool Signed, const SCEV *LHS, const SCEV *RHS, const Instruction *CtxI=nullptr)
Is operation BinOp between LHS and RHS provably does not have a signed/unsigned overflow (Signed)?
LLVM_ABI const SCEV * getMinusSCEV(SCEVUse LHS, SCEVUse RHS, SCEVFlags Flags=SCEV::FlagNone, unsigned Depth=0)
Return LHS-RHS.
LLVM_ABI ExitLimit computeExitLimitFromCond(const Loop *L, Value *ExitCond, bool ExitIfTrue, bool ControlsOnlyExit, bool AllowPredicates=false)
Compute the number of times the backedge of the specified loop will execute if its exit condition wer...
LLVM_ABI const SCEV * getMinMaxExpr(SCEVTypes Kind, SmallVectorImpl< SCEVUse > &Operands)
LLVM_ABI const SCEVPredicate * getEqualPredicate(const SCEV *LHS, const SCEV *RHS)
LLVM_ABI unsigned getSmallConstantTripMultiple(const Loop *L, const SCEV *ExitCount)
Returns the largest constant divisor of the trip count as a normal unsigned value,...
LLVM_ABI SCEVUse getSCEVAtScope(const SCEV *S, const Loop *L)
Return a SCEV expression for the specified value at the specified scope in the program.
LLVM_ABI uint64_t getTypeSizeInBits(Type *Ty) const
Return the size in bits of the specified type, for which isSCEVable must return true.
LLVM_ABI void registerUser(const SCEV *User, ArrayRef< SCEVUse > Ops)
Notify this ScalarEvolution that User directly uses SCEVs in Ops.
LLVM_ABI const SCEV * getConstant(ConstantInt *V)
LLVM_ABI const SCEV * getPredicatedBackedgeTakenCount(const Loop *L, SmallVectorImpl< const SCEVPredicate * > &Predicates)
Similar to getBackedgeTakenCount, except it will add a set of SCEV predicates to Predicates that are ...
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
SCEVUse getSCEVAtExit(Value *V, const Loop *L, const BasicBlock *ExitingBlock)
This is a convenience function which does getSCEVAtExit(getSCEV(V), L, ExitingBlock).
ConstantRange getSignedRange(const SCEV *S)
Determine the signed range for a particular SCEV.
friend class SCEVExpander
LLVM_ABI const SCEV * getNoopOrSignExtend(const SCEV *V, Type *Ty)
Return a SCEV corresponding to a conversion of the input value to the specified type.
SCEVUse getAddExpr(SCEVUse Op0, SCEVUse Op1, SCEVUse Op2, SCEVFlagsPair Flags={}, unsigned Depth=0)
static SCEVFlags setFlags(SCEVFlags Flags, SCEVFlags OnFlags)
static LLVM_ABI bool isGuaranteedNotToBePoison(const SCEV *Op)
Returns true if Op is guaranteed to not be poison.
bool loopHasNoAbnormalExits(const Loop *L)
Return true if the loop has no abnormal exits.
LLVM_ABI const SCEV * getTripCountFromExitCount(const SCEV *ExitCount)
A version of getTripCountFromExitCount below which always picks an evaluation type which can not resu...
LLVM_ABI ScalarEvolution(Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC, DominatorTree &DT, LoopInfo &LI)
SCEVUse getAddExpr(SCEVUse LHS, SCEVUse RHS, SCEVFlagsPair Flags={}, unsigned Depth=0)
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
LLVM_ABI const SCEV * getTruncateOrNoop(const SCEV *V, Type *Ty)
Return a SCEV corresponding to a conversion of the input value to the specified type.
LLVM_ABI void forgetValues(ArrayRef< Value * > Values)
Batched forgetValue: invalidates all Values in one shared def-use walk, avoiding the redundant re-tra...
LLVM_ABI const SCEV * getSequentialMinMaxExpr(SCEVTypes Kind, SmallVectorImpl< SCEVUse > &Operands)
LLVM_ABI const SCEV * getCastExpr(SCEVTypes Kind, SCEVUse Op, Type *Ty)
LLVM_ABI std::optional< bool > evaluatePredicateAt(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Instruction *CtxI)
Check whether the condition described by Pred, LHS, and RHS is true or false in the given Context.
LLVM_ABI SCEVUse getAddRecExpr(SCEVUse Start, SCEVUse Step, const Loop *L, SCEVFlagsPair Flags)
Get an add recurrence expression for the specified loop.
LLVM_ABI unsigned getSmallConstantMaxTripCount(const Loop *L, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
Returns the upper bound of the loop trip count as a normal unsigned value.
LLVM_ABI bool isKnownMultipleOf(const SCEV *S, uint64_t M, SmallVectorImpl< const SCEVPredicate * > *Predicates=nullptr)
Check that S is a multiple of M.
LLVM_ABI bool isBackedgeTakenCountMaxOrZero(const Loop *L)
Return true if the backedge taken count is either the value returned by getConstantMaxBackedgeTakenCo...
LLVM_ABI void forgetLoop(const Loop *L)
This method should be called by the client when it has changed a loop in a way that may effect Scalar...
LLVM_ABI bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
LLVM_ABI bool isKnownPositive(const SCEV *S)
Test if the given expression is known to be positive.
LLVM_ABI bool SimplifyICmpOperands(CmpPredicate &Pred, SCEVUse &LHS, SCEVUse &RHS, unsigned Depth=0)
Simplify LHS and RHS in a comparison with predicate Pred.
APInt getUnsignedRangeMin(const SCEV *S)
Determine the min of the unsigned range for a particular SCEV.
static SCEVFlags clearFlags(SCEVFlags Flags, SCEVFlags OffFlags)
LLVM_ABI const SCEV * getOffsetOfExpr(Type *IntTy, StructType *STy, unsigned FieldNo)
Return an expression for offsetof on the given field with type IntTy.
LLVM_ABI LoopDisposition getLoopDisposition(const SCEV *S, const Loop *L)
Return the "disposition" of the given SCEV with respect to the given loop.
static SCEVFlags maskFlags(SCEVFlags Flags, SCEVFlags Mask)
Convenient SCEVFlags manipulation.
LLVM_ABI bool containsAddRecurrence(const SCEV *S)
Return true if the SCEV is a scAddRecExpr or it contains scAddRecExpr.
SCEVUse getMulExpr(SCEVUse LHS, SCEVUse RHS, SCEVFlagsPair Flags={}, unsigned Depth=0)
LLVM_ABI const SCEV * getTruncateExpr(SCEVUse Op, Type *Ty, unsigned Depth=0)
LLVM_ABI SCEVUse getAddExpr(SmallVectorImpl< SCEVUse > &Ops, SCEVFlagsPair Flags={}, unsigned Depth=0)
Get a canonical add expression, or something simpler if possible.
LLVM_ABI const SCEV * getZeroExtendExprImpl(SCEVUse Op, Type *Ty, unsigned Depth=0)
LLVM_ABI bool isSCEVable(Type *Ty) const
Test if values of the given type are analyzable within the SCEV framework.
LLVM_ABI Type * getEffectiveSCEVType(Type *Ty) const
Return a type with the same bitwidth as the given type and which represents how SCEV will treat the g...
LLVM_ABI const SCEVPredicate * getComparePredicate(ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS)
LLVM_ABI bool haveSameSign(const SCEV *S1, const SCEV *S2)
Return true if we know that S1 and S2 must have the same sign.
LLVM_ABI const SCEV * getNotSCEV(const SCEV *V)
Return the SCEV object corresponding to ~V.
LLVM_ABI bool instructionCouldExistWithOperands(const SCEV *A, const SCEV *B)
Return true if there exists a point in the program at which both A and B could be operands to the sam...
LLVM_ABI std::optional< SCEVFlags > getStrengthenedNoWrapFlagsFromBinOp(const OverflowingBinaryOperator *OBO)
Parse NSW/NUW flags from add/sub/mul IR binary operation Op into SCEV no-wrap flags,...
ConstantRange getUnsignedRange(const SCEV *S)
Determine the unsigned range for a particular SCEV.
LLVM_ABI void print(raw_ostream &OS) const
LLVM_ABI const SCEV * getAnyExtendExpr(SCEVUse Op, Type *Ty)
getAnyExtendExpr - Return a SCEV for the given operand extended with unspecified bits out to the give...
LLVM_ABI const SCEV * getPredicatedExitCount(const Loop *L, const BasicBlock *ExitingBlock, SmallVectorImpl< const SCEVPredicate * > *Predicates, ExitCountKind Kind=Exact)
Same as above except this uses the predicated backedge taken info and may require predicates.
friend class VPSCEVExpander
LLVM_ABI void forgetTopmostLoop(const Loop *L)
friend class ScalarEvolutionsTest
LLVM_ABI void forgetValue(Value *V)
This method should be called by the client when it has changed a value in a way that may effect its v...
APInt getSignedRangeMin(const SCEV *S)
Determine the min of the signed range for a particular SCEV.
LLVM_ABI bool isLoopUniform(const SCEV *S, const Loop *L)
Returns true if the given SCEV is loop-uniform with respect to the specified loop L.
LLVM_ABI const SCEV * getNoopOrAnyExtend(const SCEV *V, Type *Ty)
Return a SCEV corresponding to a conversion of the input value to the specified type.
LLVM_ABI void forgetBlockAndLoopDispositions(Value *V=nullptr)
Called when the client has changed the disposition of values in a loop or block.
LLVM_ABI const SCEV * getSignExtendExpr(SCEVUse Op, Type *Ty, unsigned Depth=0)
LLVM_ABI const SCEV * getUMaxExpr(SCEVUse LHS, SCEVUse RHS)
MonotonicPredicateType
A predicate is said to be monotonically increasing if may go from being false to being true as the lo...
@ MonotonicallyDecreasing
@ MonotonicallyIncreasing
LLVM_ABI std::optional< LoopInvariantPredicate > getLoopInvariantPredicate(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Loop *L, const Instruction *CtxI=nullptr)
If the result of the predicate LHS Pred RHS is loop invariant with respect to L, return a LoopInvaria...
LLVM_ABI const SCEV * getStoreSizeOfExpr(Type *IntTy, Type *StoreTy)
Return an expression for the store size of StoreTy that is type IntTy.
LLVM_ABI const SCEVPredicate * getWrapPredicate(const SCEVAddRecExpr *AR, SCEVWrapPredicate::IncrementWrapFlags AddedFlags)
LLVM_ABI bool isLoopBackedgeGuardedByCond(const Loop *L, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
Test whether the backedge of the loop is protected by a conditional between LHS and RHS.
LLVM_ABI APInt getNonZeroConstantMultiple(const SCEV *S)
const SCEV * getMinusOne(Type *Ty)
Return a SCEV for the constant -1 of a specific type.
LLVM_ABI bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
Return true if the specified loop has an analyzable loop-invariant backedge-taken count.
LLVM_ABI BlockDisposition getBlockDisposition(const SCEV *S, const BasicBlock *BB)
Return the "disposition" of the given SCEV with respect to the given block.
LLVM_ABI const SCEV * getNoopOrZeroExtend(const SCEV *V, Type *Ty)
Return a SCEV corresponding to a conversion of the input value to the specified type.
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
LLVM_ABI const SCEV * getUMinFromMismatchedTypes(const SCEV *LHS, const SCEV *RHS, bool Sequential=false)
Promote the operands to the wider of the types using zero-extension, and then perform a umin operatio...
LLVM_ABI bool loopIsFiniteByAssumption(const Loop *L)
Return true if this loop is finite by assumption.
LLVM_ABI SCEVUse getSCEVAtExit(const SCEV *S, const Loop *L, const BasicBlock *ExitingBlock)
Return the SCEV expression at the specified loop exit.
LLVM_ABI const SCEV * getExistingSCEV(Value *V)
Return an existing SCEV for V if there is one, otherwise return nullptr.
SCEVUse getMulExpr(SCEVUse Op0, SCEVUse Op1, SCEVUse Op2, SCEVFlagsPair Flags={}, unsigned Depth=0)
LLVM_ABI APInt getConstantMultiple(const SCEV *S, const Instruction *CtxI=nullptr)
Returns the max constant multiple of S.
LoopDisposition
An enum describing the relationship between a SCEV and a loop.
@ LoopComputable
The SCEV varies predictably with the loop.
@ LoopVariant
The SCEV is loop-variant (unknown).
@ LoopInvariant
The SCEV is loop-invariant.
@ LoopUniform
The SCEV is loop-uniform.
friend class SCEVCallbackVH
LLVM_ABI bool isKnownToBeAPowerOfTwo(const SCEV *S, bool OrZero=false, bool OrNegative=false)
Test if the given expression is known to be a power of 2.
LLVM_ABI void forgetLcssaPhiWithNewPredecessor(Loop *L, PHINode *V)
Forget LCSSA phi node V of loop L to which a new predecessor was added, such that it may no longer be...
LLVM_ABI bool containsUndefs(const SCEV *S) const
Return true if the SCEV expression contains an undef value.
LLVM_ABI std::optional< MonotonicPredicateType > getMonotonicPredicateType(const SCEVAddRecExpr *LHS, ICmpInst::Predicate Pred)
If, for all loop invariant X, the predicate "LHS `Pred` X" is monotonically increasing or decreasing,...
LLVM_ABI const SCEV * getCouldNotCompute()
LLVM_ABI bool isAvailableAtLoopEntry(const SCEV *S, const Loop *L)
Determine if the SCEV can be evaluated at loop's entry.
LLVM_ABI uint32_t getMinTrailingZeros(const SCEV *S, const Instruction *CtxI=nullptr)
Determine the minimum number of zero bits that S is guaranteed to end in (at every loop iteration).
BlockDisposition
An enum describing the relationship between a SCEV and a basic block.
@ DominatesBlock
The SCEV dominates the block.
@ ProperlyDominatesBlock
The SCEV properly dominates the block.
@ DoesNotDominateBlock
The SCEV does not dominate the block.
LLVM_ABI const SCEV * getExitCount(const Loop *L, const BasicBlock *ExitingBlock, ExitCountKind Kind=Exact)
Return the number of times the backedge executes before the given exit would be taken; if not exactly...
LLVM_ABI void getPoisonGeneratingValues(SmallPtrSetImpl< const Value * > &Result, const SCEV *S)
Return the set of Values that, if poison, will definitively result in S being poison as well.
LLVM_ABI void setNoWrapFlags(SCEVAddRecExpr *AddRec, SCEVFlags Flags)
Update no-wrap flags of an AddRec.
LLVM_ABI void forgetLoopDispositions()
Called when the client has changed the disposition of values in this loop.
LLVM_ABI const SCEV * getVScale(Type *Ty)
LLVM_ABI SCEVUse getMulExpr(SmallVectorImpl< SCEVUse > &Ops, SCEVFlagsPair Flags={}, unsigned Depth=0)
Get a canonical multiply expression, or something simpler if possible.
LLVM_ABI unsigned getSmallConstantTripCount(const Loop *L)
Returns the exact trip count of the loop if we can compute it, and the result is a small constant.
LLVM_ABI bool hasComputableLoopEvolution(const SCEV *S, const Loop *L)
Return true if the given SCEV changes value in a known way in the specified loop.
LLVM_ABI const SCEV * getPointerBase(const SCEV *V)
Transitively follow the chain of pointer-type operands until reaching a SCEV that does not have a sin...
const SCEV * getPowerOfTwo(Type *Ty, unsigned Power)
Return a SCEV for the constant Power of two.
LLVM_ABI void forgetAllLoops()
LLVM_ABI const SCEV * getSignExtendExprImpl(SCEVUse Op, Type *Ty, unsigned Depth=0)
LLVM_ABI bool dominates(const SCEV *S, const BasicBlock *BB)
Return true if elements that makes up the given SCEV dominate the specified basic block.
APInt getUnsignedRangeMax(const SCEV *S)
Determine the max of the unsigned range for a particular SCEV.
ExitCountKind
The terms "backedge taken count" and "exit count" are used interchangeably to refer to the number of ...
@ SymbolicMaximum
An expression which provides an upper bound on the exact trip count.
@ ConstantMaximum
A constant which provides an upper bound on the exact trip count.
@ Exact
An expression exactly describing the number of times the backedge has executed when a loop is exited.
LLVM_ABI bool isKnownPredicate(CmpPredicate Pred, SCEVUse LHS, SCEVUse RHS)
Test if the given expression is known to satisfy the condition described by Pred, LHS,...
LLVM_ABI const SCEV * applyLoopGuards(const SCEV *Expr, const Loop *L)
Try to apply information from loop guards for L to Expr.
LLVM_ABI const SCEV * getPtrToAddrExpr(const SCEV *Op)
LLVM_ABI const SCEVAddRecExpr * convertSCEVToAddRecWithPredicates(const SCEV *S, const Loop *L, SmallVectorImpl< const SCEVPredicate * > &Preds)
Tries to convert the S expression to an AddRec expression, adding additional predicates to Preds as r...
SCEVUse getAddRecExpr(const SmallVectorImpl< SCEVUse > &Operands, const Loop *L, SCEVFlagsPair Flags)
Module & getModule() const
LLVM_ABI const SCEV * getSMaxExpr(SCEVUse LHS, SCEVUse RHS)
LLVM_ABI const SCEV * getElementSize(Instruction *Inst)
Return the size of an element read or written by Inst.
LLVM_ABI bool isGuaranteedNotToCauseUB(const SCEV *Op)
Returns true if Op is guaranteed not to cause immediate UB.
LLVM_ABI const SCEV * getSizeOfExpr(Type *IntTy, TypeSize Size)
Return an expression for a TypeSize.
LLVM_ABI std::optional< bool > evaluatePredicate(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
Check whether the condition described by Pred, LHS, and RHS is true or false.
LLVM_ABI const SCEV * getUnknown(Value *V)
LLVM_ABI std::optional< std::pair< const SCEV *, SmallVector< const SCEVPredicate *, 3 > > > createAddRecFromPHIWithCasts(const SCEVUnknown *SymbolicPHI)
Checks if SymbolicPHI can be rewritten as an AddRecExpr under some Predicates.
LLVM_ABI const SCEV * getTruncateOrZeroExtend(const SCEV *V, Type *Ty, unsigned Depth=0)
Return a SCEV corresponding to a conversion of the input value to the specified type.
LLVM_ABI bool isKnownViaInduction(CmpPredicate Pred, SCEVUse LHS, SCEVUse RHS)
We'd like to check the predicate on every iteration of the most dominated loop between loops used in ...
LLVM_ABI std::optional< APInt > computeConstantDifference(const SCEV *LHS, const SCEV *RHS)
Compute LHS - RHS and returns the result as an APInt if it is a constant, and std::nullopt if it isn'...
LLVM_ABI bool properlyDominates(const SCEV *S, const BasicBlock *BB)
Return true if elements that makes up the given SCEV properly dominate the specified basic block.
LLVM_ABI const SCEV * getNegativeSCEV(const SCEV *V, SCEVFlags Flags=SCEV::FlagNone)
Return the SCEV object corresponding to -V.
LLVM_ABI const SCEV * getUDivExactExpr(SCEVUse LHS, SCEVUse RHS)
Get a canonical unsigned division expression, or something simpler if possible.
LLVM_ABI const SCEV * rewriteUsingPredicate(const SCEV *S, const Loop *L, const SCEVPredicate &A)
Re-writes the SCEV according to the Predicates in A.
LLVM_ABI std::pair< const SCEV *, const SCEV * > SplitIntoInitAndPostInc(const Loop *L, const SCEV *S)
Splits SCEV expression S into two SCEVs.
LLVM_ABI bool canReuseInstruction(const SCEV *S, Instruction *I, SmallVectorImpl< Instruction * > &DropPoisonGeneratingInsts)
Check whether it is poison-safe to represent the expression S using the instruction I.
LLVM_ABI bool isKnownPredicateAt(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Instruction *CtxI)
Test if the given expression is known to satisfy the condition described by Pred, LHS,...
LLVM_ABI const SCEV * getPredicatedSymbolicMaxBackedgeTakenCount(const Loop *L, SmallVectorImpl< const SCEVPredicate * > &Predicates)
Similar to getSymbolicMaxBackedgeTakenCount, except it will add a set of SCEV predicates to Predicate...
LLVM_ABI ~ScalarEvolution()
LLVM_ABI const SCEV * getGEPExpr(GEPOperator *GEP, ArrayRef< SCEVUse > IndexExprs)
Returns an expression for a GEP.
LLVM_ABI const SCEV * getUMinExpr(SCEVUse LHS, SCEVUse RHS, bool Sequential=false)
LLVM_ABI bool isBasicBlockEntryGuardedByCond(const BasicBlock *BB, CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
Test whether entry to the basic block is protected by a conditional between LHS and RHS.
LLVM_ABI const SCEV * getTruncateOrSignExtend(const SCEV *V, Type *Ty, unsigned Depth=0)
Return a SCEV corresponding to a conversion of the input value to the specified type.
LLVM_ABI bool containsErasedValue(const SCEV *S) const
Return true if the SCEV expression contains a Value that has been optimised out and is now a nullptr.
const SCEV * getSymbolicMaxBackedgeTakenCount(const Loop *L)
When successful, this returns a SCEV that is greater than or equal to (i.e.
APInt getSignedRangeMax(const SCEV *S)
Determine the max of the signed range for a particular SCEV.
LLVM_ABI void verify() const
LLVMContext & getContext() const
Implements a dense probed hash-table based set with some number of buckets stored inline.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Class to represent struct types.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
Lightweight SCEV-to-VPlan expander.
LLVM Value Representation.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned combineHashValue(unsigned a, unsigned b)
Simplistic combination of 32-bit hash values into 32-bit hash values.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
RelativeUniformCounterPtr Values
@ LLVM_MARK_AS_BITMASK_ENUM
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
SCEVUseT(SCEVPtrT) -> SCEVUseT< SCEVPtrT >
Deduction guide for various SCEV subclass pointers.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
DWARFExpression::Operation Op
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
SCEVFlags
SCEVFlags are bitfield indices into SCEV's SubclassData.
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
@ End
Run the machine verifier once, at the end of the pipeline.
FoldingSetImpl< T, Trait > FoldingSet
This template class is used to instantiate a specialized implementation of the folding set to the nod...
SCEVUseT< const SCEV * > SCEVUse
Implement std::hash so that hash_code can be used in STL containers.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
std::remove_cv_t< std::remove_pointer_t< ToSCEVPtrT > > To
static bool isPossible(const SCEVUse &U)
static CastReturnType castFailed()
SCEVUseT< ToSCEVPtrT > CastReturnType
static CastReturnType doCast(const SCEVUse &U)
static CastReturnType doCastIfPossible(const SCEVUse &U)
This struct provides a method for customizing the way a cast is performed.
static CastReturnType castFailed()
static CastReturnType doCast(const From &f)
typename cast_retty< To, From >::ret_type CastReturnType
static bool isPossible(const From &f)
This class provides default implementations for FoldingSetTrait implementations.
static bool isEqual(const SCEVUse LHS, const SCEVUse RHS)
static unsigned getHashValue(SCEVUse U)
static unsigned getHashValue(const ScalarEvolution::FoldID &Val)
static bool isEqual(const ScalarEvolution::FoldID &LHS, const ScalarEvolution::FoldID &RHS)
An information struct used to provide DenseMap with the various necessary components for a given valu...
static void Profile(const SCEVPredicate &X, FoldingSetNodeID &ID)
static bool Equals(const SCEVPredicate &X, const FoldingSetNodeID &ID)
static bool Equals(const SCEV &X, const FoldingSetNodeID &ID)
static void Profile(const SCEV &X, FoldingSetNodeID &ID)
This trait class is used to define behavior of how to "profile" (in the FoldingSet parlance) an objec...
static constexpr int NumLowBitsAvailable
The Low bits are used by the PointerIntPair.
static void * getAsVoidPointer(SCEVUse U)
static SCEVUse getFromVoidPointer(void *P)
A traits type that is used to handle pointer types and things that are just wrappers for pointers as ...
A CRTP mix-in for passes that should not be skipped.
LLVM_ABI SCEVCouldNotCompute()
static LLVM_ABI bool classof(const SCEV *S)
Methods for support type inquiry through isa, cast, and dyn_cast:
The no-wrap flags to apply when creating a SCEV expression, to the expression and use respectively.
SCEVFlags ExprFlags
Flags applied directly to a SCEV expression, must be valid wherever the expression is valid.
constexpr SCEVFlagsPair(SCEVFlags ExprFlags=SCEVFlags::FlagNone, SCEVFlags UseFlags=SCEVFlags::FlagNone)
SCEVFlags UseFlags
Flags only applied to a SCEVUse.
SCEVFlags getUseNoWrapFlags() const
bool operator==(const SCEVUseT &RHS) const
const SCEV * getCanonical() const
Return the canonical SCEV for this SCEVUse.
bool operator!=(const SCEVUseT &RHS) const
SCEVPtrT operator->() const
SCEVFlags getNoWrapFlags(SCEVFlags Mask=SCEVFlags::FlagsNoWrapMask) const
Return the flags for this SCEVUse, which is the union of the use-specific flags and the underlying SC...
SCEVUseT(SCEVPtrT S, SCEVFlags Flags)
Construct with SCEVFlags; only NUW/NSW are encoded, NW is dropped.
static SCEVUseT getCommon(SCEVUseT A, SCEVUseT B)
Return a SCEVUse that can replace both A and B.
SCEVUseT(const SCEVUseT< OtherPtrT > &Other)
void * getOpaqueValue() const
bool isCanonical() const
Returns true if the SCEVUse is canonical, i.e.
const SCEV * getPointer() const
bool operator==(const SCEV *RHS) const
void dump() const
This method is used for debugging.
bool operator>(const SCEVUseT &RHS) const
PointerIntPair< SCEVPtrT, 2 > Base
bool operator!=(const SCEV *RHS) const
SCEVFlags getUseFlags() const
void print(raw_ostream &OS) const
Print out the internal representation of this scalar to the specified stream.
bool hasUseFlags() const
Returns true if this use itself carries use-specific no-wrap flags.
Information about the number of loop iterations for which a loop exit's branch condition evaluates to...
LLVM_ABI ExitLimit(const SCEV *E)
Construct either an exact exit limit from a constant, or an unknown one from a SCEVCouldNotCompute.
bool hasAnyInfo() const
Test whether this ExitLimit contains any computed information, or whether it's all SCEVCouldNotComput...
const SCEV * ExactNotTaken
const SCEV * SymbolicMaxNotTaken
SmallVector< const SCEVPredicate *, 4 > Predicates
A vector of predicate guards for this ExitLimit.
bool hasFullInfo() const
Test whether this ExitLimit contains all information.
const SCEV * ConstantMaxNotTaken
LoopInvariantPredicate(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS)
static SimpleType getSimplifiedValue(SCEVUse &Val)
Define a template that can be specialized by smart pointers to reflect the fact that they are automat...