aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/Analysis/ScalarEvolution.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:50:12 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:50:12 +0000
commite6d1592492a3a379186bfb02bd0f4eda0669c0d5 (patch)
tree599ab169a01f1c86eda9adc774edaedde2f2db5b /include/llvm/Analysis/ScalarEvolution.h
parent1a56a5ead7a2e84bee8240f5f6b033b5f1707154 (diff)
Notes
Diffstat (limited to 'include/llvm/Analysis/ScalarEvolution.h')
-rw-r--r--include/llvm/Analysis/ScalarEvolution.h72
1 files changed, 56 insertions, 16 deletions
diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h
index 8f4200b07e5c..0bd98ef37e7a 100644
--- a/include/llvm/Analysis/ScalarEvolution.h
+++ b/include/llvm/Analysis/ScalarEvolution.h
@@ -1,9 +1,8 @@
//===- llvm/Analysis/ScalarEvolution.h - Scalar Evolution -------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -85,6 +84,9 @@ class SCEV : public FoldingSetNode {
const unsigned short SCEVType;
protected:
+ // Estimated complexity of this node's expression tree size.
+ const unsigned short ExpressionSize;
+
/// This field is initialized to zero and may be used in subclasses to store
/// miscellaneous information.
unsigned short SubclassData = 0;
@@ -116,8 +118,9 @@ public:
NoWrapMask = (1 << 3) - 1
};
- explicit SCEV(const FoldingSetNodeIDRef ID, unsigned SCEVTy)
- : FastID(ID), SCEVType(SCEVTy) {}
+ explicit SCEV(const FoldingSetNodeIDRef ID, unsigned SCEVTy,
+ unsigned short ExpressionSize)
+ : FastID(ID), SCEVType(SCEVTy), ExpressionSize(ExpressionSize) {}
SCEV(const SCEV &) = delete;
SCEV &operator=(const SCEV &) = delete;
@@ -138,6 +141,19 @@ public:
/// Return true if the specified scev is negated, but not a constant.
bool isNonConstantNegative() const;
+ // Returns estimated size of the mathematical expression represented by this
+ // SCEV. The rules of its calculation are following:
+ // 1) Size of a SCEV without operands (like constants and SCEVUnknown) is 1;
+ // 2) Size SCEV with operands Op1, Op2, ..., OpN is calculated by formula:
+ // (1 + Size(Op1) + ... + Size(OpN)).
+ // This value gives us an estimation of time we need to traverse through this
+ // SCEV and all its operands recursively. We may use it to avoid performing
+ // heavy transformations on SCEVs of excessive size for sake of saving the
+ // compilation time.
+ unsigned short getExpressionSize() const {
+ return ExpressionSize;
+ }
+
/// Print out the internal representation of this scalar to the specified
/// stream. This should really only be used for debugging purposes.
void print(raw_ostream &OS) const;
@@ -521,7 +537,7 @@ public:
const SCEV *getConstant(ConstantInt *V);
const SCEV *getConstant(const APInt &Val);
const SCEV *getConstant(Type *Ty, uint64_t V, bool isSigned = false);
- const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty);
+ const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0);
const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0);
const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0);
const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty);
@@ -582,6 +598,8 @@ public:
/// \p IndexExprs The expressions for the indices.
const SCEV *getGEPExpr(GEPOperator *GEP,
const SmallVectorImpl<const SCEV *> &IndexExprs);
+ const SCEV *getMinMaxExpr(unsigned Kind,
+ SmallVectorImpl<const SCEV *> &Operands);
const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS);
@@ -619,11 +637,13 @@ public:
/// Return a SCEV corresponding to a conversion of the input value to the
/// specified type. If the type must be extended, it is zero extended.
- const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty);
+ 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. If the type must be extended, it is sign extended.
- const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty);
+ 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. If the type must be extended, it is zero extended. The
@@ -726,9 +746,12 @@ public:
unsigned getSmallConstantTripMultiple(const Loop *L,
BasicBlock *ExitingBlock);
- /// Get the expression for the number of loop iterations for which this loop
- /// is guaranteed not to exit via ExitingBlock. Otherwise return
- /// SCEVCouldNotCompute.
+ /// Return the number of times the backedge executes before the given exit
+ /// would be taken; if not exactly computable, return SCEVCouldNotCompute.
+ /// For a single exit loop, this value is equivelent to the result of
+ /// getBackedgeTakenCount. The loop is guaranteed to exit (via *some* exit)
+ /// before the backedge is executed (ExitCount + 1) times. Note that there
+ /// is no guarantee about *which* exit is taken on the exiting iteration.
const SCEV *getExitCount(const Loop *L, BasicBlock *ExitingBlock);
/// If the specified loop has a predictable backedge-taken count, return it,
@@ -764,6 +787,13 @@ public:
/// backedge-taken count.
bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
+ // This method should be called by the client when it made any change that
+ // would invalidate SCEV's answers, and the client wants to remove all loop
+ // information held internally by ScalarEvolution. This is intended to be used
+ // when the alternative to forget a loop is too expensive (i.e. large loop
+ // bodies).
+ void forgetAllLoops();
+
/// This method should be called by the client when it has changed a loop in
/// a way that may effect ScalarEvolution's ability to compute a trip count,
/// or if the loop is deleted. This call is potentially expensive for large
@@ -1273,7 +1303,7 @@ private:
using EdgeExitInfo = std::pair<BasicBlock *, ExitLimit>;
/// Initialize BackedgeTakenInfo from a list of exact exit counts.
- BackedgeTakenInfo(SmallVectorImpl<EdgeExitInfo> &&ExitCounts, bool Complete,
+ BackedgeTakenInfo(ArrayRef<EdgeExitInfo> ExitCounts, bool Complete,
const SCEV *MaxCount, bool MaxOrZero);
/// Test whether this BackedgeTakenInfo contains any computed information,
@@ -1826,15 +1856,15 @@ private:
bool NoWrap);
/// Get add expr already created or create a new one.
- const SCEV *getOrCreateAddExpr(SmallVectorImpl<const SCEV *> &Ops,
+ const SCEV *getOrCreateAddExpr(ArrayRef<const SCEV *> Ops,
SCEV::NoWrapFlags Flags);
/// Get mul expr already created or create a new one.
- const SCEV *getOrCreateMulExpr(SmallVectorImpl<const SCEV *> &Ops,
+ const SCEV *getOrCreateMulExpr(ArrayRef<const SCEV *> Ops,
SCEV::NoWrapFlags Flags);
// Get addrec expr already created or create a new one.
- const SCEV *getOrCreateAddRecExpr(SmallVectorImpl<const SCEV *> &Ops,
+ const SCEV *getOrCreateAddRecExpr(ArrayRef<const SCEV *> Ops,
const Loop *L, SCEV::NoWrapFlags Flags);
/// Return x if \p Val is f(x) where f is a 1-1 function.
@@ -1853,6 +1883,16 @@ private:
/// Assign A and B to LHS and RHS, respectively.
bool matchURem(const SCEV *Expr, const SCEV *&LHS, const SCEV *&RHS);
+ /// Look for a SCEV expression with type `SCEVType` and operands `Ops` in
+ /// `UniqueSCEVs`.
+ ///
+ /// The first component of the returned tuple is the SCEV if found and null
+ /// otherwise. The second component is the `FoldingSetNodeID` that was
+ /// constructed to look up the SCEV and the third component is the insertion
+ /// point.
+ std::tuple<const SCEV *, FoldingSetNodeID, void *>
+ findExistingSCEVInCache(int SCEVType, ArrayRef<const SCEV *> Ops);
+
FoldingSet<SCEV> UniqueSCEVs;
FoldingSet<SCEVPredicate> UniquePreds;
BumpPtrAllocator SCEVAllocator;