class ScalarEvolution;
class SCEV;
-/// 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
-};
-
-/// PostIncLoopSet - A set of loops.
typedef SmallPtrSet<const Loop *, 2> PostIncLoopSet;
typedef function_ref<bool(const SCEVAddRecExpr *)> NormalizePredTy;
-/// TransformForPostIncUse - Transform the given expression according to the
-/// given transformation kind.
-const SCEV *TransformForPostIncUse(TransformKind Kind, const SCEV *S,
- Optional<NormalizePredTy> Pred,
- PostIncLoopSet &Loops, ScalarEvolution &SE);
-}
+/// Normalize \p S to be post-increment for all loops present in \p
+/// Loops.
+const SCEV *normalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops,
+ ScalarEvolution &SE);
+
+/// Normalize \p S for all add recurrence sub-expressions for which \p
+/// Pred returns true.
+const SCEV *normalizeForPostIncUseIf(const SCEV *S, NormalizePredTy Pred,
+ ScalarEvolution &SE);
+
+/// Denormalize \p S to be post-increment for all loops present in \p
+/// Loops.
+const SCEV *denormalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops,
+ ScalarEvolution &SE);
+} // namespace llvm
#endif
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.
/// 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) {
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.
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);
/// 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);
+}
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);
}
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)));
}
// 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.