Tighten the API for ScalarEvolutionNormalization
llvm-svn: 300331
diff --git a/llvm/lib/Analysis/IVUsers.cpp b/llvm/lib/Analysis/IVUsers.cpp
index de38cf8..fde805a 100644
--- a/llvm/lib/Analysis/IVUsers.cpp
+++ b/llvm/lib/Analysis/IVUsers.cpp
@@ -270,17 +270,15 @@
return Result;
};
- ISE = TransformForPostIncUse(Normalize, ISE,
- Optional<NormalizePredTy>(NormalizePred),
- NewUse.PostIncLoops, *SE);
+ ISE = normalizeForPostIncUseIf(ISE, NormalizePred, *SE);
// PostIncNormalization effectively simplifies the expression under
// pre-increment assumptions. Those assumptions (no wrapping) might not
// hold for the post-inc value. Catch such cases by making sure the
// transformation is invertible.
if (OriginalISE != ISE) {
- const SCEV *DenormalizedISE = TransformForPostIncUse(
- Denormalize, ISE, None, NewUse.PostIncLoops, *SE);
+ const SCEV *DenormalizedISE =
+ denormalizeForPostIncUse(ISE, NewUse.PostIncLoops, *SE);
// If we normalized the expression, but denormalization doesn't give the
// original one, discard this user.
@@ -398,9 +396,8 @@
/// getExpr - Return the expression for the use.
const SCEV *IVUsers::getExpr(const IVStrideUse &IU) const {
- return TransformForPostIncUse(
- Normalize, getReplacementExpr(IU), None,
- const_cast<PostIncLoopSet &>(IU.getPostIncLoops()), *SE);
+ return normalizeForPostIncUse(getReplacementExpr(IU), IU.getPostIncLoops(),
+ *SE);
}
static const SCEVAddRecExpr *findAddRecForLoop(const SCEV *S, const Loop *L) {
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
index 66df34d..6dd1044 100644
--- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -1268,8 +1268,7 @@
if (PostIncLoops.count(L)) {
PostIncLoopSet Loops;
Loops.insert(L);
- Normalized = cast<SCEVAddRecExpr>(
- TransformForPostIncUse(Normalize, S, None, Loops, SE));
+ Normalized = cast<SCEVAddRecExpr>(normalizeForPostIncUse(S, Loops, SE));
}
// Strip off any non-loop-dominating component from the addrec start.
diff --git a/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp b/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp
index becc4bb..8923727 100644
--- a/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp
+++ b/llvm/lib/Analysis/ScalarEvolutionNormalization.cpp
@@ -19,19 +19,29 @@
namespace {
+/// TransformKind - Different types of transformations that
+/// TransformForPostIncUse can do.
+enum TransformKind {
+ /// Normalize - Normalize according to the given loops.
+ Normalize,
+ /// Denormalize - Perform the inverse transform on the expression with the
+ /// given loop set.
+ Denormalize
+};
+
/// Hold the state used during post-inc expression transformation, including a
/// map of transformed expressions.
class PostIncTransform {
TransformKind Kind;
Optional<NormalizePredTy> Pred;
- PostIncLoopSet &Loops;
+ const PostIncLoopSet &Loops;
ScalarEvolution &SE;
DenseMap<const SCEV*, const SCEV*> Transformed;
public:
PostIncTransform(TransformKind kind, Optional<NormalizePredTy> Pred,
- PostIncLoopSet &loops, ScalarEvolution &se)
+ const PostIncLoopSet &loops, ScalarEvolution &se)
: Kind(kind), Pred(Pred), Loops(loops), SE(se) {}
const SCEV *TransformSubExpr(const SCEV *S);
@@ -160,10 +170,28 @@
/// Top level driver for transforming an expression DAG into its requested
/// post-inc form (either "Normalized" or "Denormalized").
-const SCEV *llvm::TransformForPostIncUse(TransformKind Kind, const SCEV *S,
- Optional<NormalizePredTy> Pred,
- PostIncLoopSet &Loops,
- ScalarEvolution &SE) {
+static const SCEV *TransformForPostIncUse(TransformKind Kind, const SCEV *S,
+ Optional<NormalizePredTy> Pred,
+ const PostIncLoopSet &Loops,
+ ScalarEvolution &SE) {
PostIncTransform Transform(Kind, Pred, Loops, SE);
return Transform.TransformSubExpr(S);
}
+
+const SCEV *llvm::normalizeForPostIncUse(const SCEV *S,
+ const PostIncLoopSet &Loops,
+ ScalarEvolution &SE) {
+ return TransformForPostIncUse(Normalize, S, None, Loops, SE);
+}
+
+const SCEV *llvm::normalizeForPostIncUseIf(const SCEV *S, NormalizePredTy Pred,
+ ScalarEvolution &SE) {
+ PostIncLoopSet Empty;
+ return TransformForPostIncUse(Normalize, S, Pred, Empty, SE);
+}
+
+const SCEV *llvm::denormalizeForPostIncUse(const SCEV *S,
+ const PostIncLoopSet &Loops,
+ ScalarEvolution &SE) {
+ return TransformForPostIncUse(Denormalize, S, None, Loops, SE);
+}
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index b584e00..af137f6 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -3160,7 +3160,7 @@
if (SE.isLoopInvariant(N, L) && isSafeToExpand(N, SE)) {
// S is normalized, so normalize N before folding it into S
// to keep the result normalized.
- N = TransformForPostIncUse(Normalize, N, None, TmpPostIncLoops, SE);
+ N = normalizeForPostIncUse(N, TmpPostIncLoops, SE);
Kind = LSRUse::ICmpZero;
S = SE.getMinusSCEV(N, S);
}
@@ -4798,8 +4798,7 @@
assert(!Reg->isZero() && "Zero allocated in a base register!");
// If we're expanding for a post-inc user, make the post-inc adjustment.
- PostIncLoopSet &Loops = const_cast<PostIncLoopSet &>(LF.PostIncLoops);
- Reg = TransformForPostIncUse(Denormalize, Reg, None, Loops, SE);
+ Reg = denormalizeForPostIncUse(Reg, LF.PostIncLoops, SE);
Ops.push_back(SE.getUnknown(Rewriter.expandCodeFor(Reg, nullptr)));
}
@@ -4810,7 +4809,7 @@
// If we're expanding for a post-inc user, make the post-inc adjustment.
PostIncLoopSet &Loops = const_cast<PostIncLoopSet &>(LF.PostIncLoops);
- ScaledS = TransformForPostIncUse(Denormalize, ScaledS, None, Loops, SE);
+ ScaledS = denormalizeForPostIncUse(ScaledS, Loops, SE);
if (LU.Kind == LSRUse::ICmpZero) {
// Expand ScaleReg as if it was part of the base regs.