[llvm] r300331 - Tighten the API for ScalarEvolutionNormalization

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 08:49:59 PDT 2017


Author: sanjoy
Date: Fri Apr 14 10:49:59 2017
New Revision: 300331

URL: http://llvm.org/viewvc/llvm-project?rev=300331&view=rev
Log:
Tighten the API for ScalarEvolutionNormalization

Modified:
    llvm/trunk/include/llvm/Analysis/ScalarEvolutionNormalization.h
    llvm/trunk/lib/Analysis/IVUsers.cpp
    llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
    llvm/trunk/lib/Analysis/ScalarEvolutionNormalization.cpp
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionNormalization.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionNormalization.h?rev=300331&r1=300330&r2=300331&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolutionNormalization.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionNormalization.h Fri Apr 14 10:49:59 2017
@@ -44,26 +44,24 @@ class Loop;
 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

Modified: llvm/trunk/lib/Analysis/IVUsers.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IVUsers.cpp?rev=300331&r1=300330&r2=300331&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/IVUsers.cpp (original)
+++ llvm/trunk/lib/Analysis/IVUsers.cpp Fri Apr 14 10:49:59 2017
@@ -270,17 +270,15 @@ bool IVUsers::AddUsersImpl(Instruction *
         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 @@ const SCEV *IVUsers::getReplacementExpr(
 
 /// 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) {

Modified: llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp?rev=300331&r1=300330&r2=300331&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionExpander.cpp Fri Apr 14 10:49:59 2017
@@ -1268,8 +1268,7 @@ Value *SCEVExpander::expandAddRecExprLit
   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.

Modified: llvm/trunk/lib/Analysis/ScalarEvolutionNormalization.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolutionNormalization.cpp?rev=300331&r1=300330&r2=300331&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolutionNormalization.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolutionNormalization.cpp Fri Apr 14 10:49:59 2017
@@ -19,19 +19,29 @@ using namespace llvm;
 
 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 @@ const SCEV *PostIncTransform::TransformS
 
 /// 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);
+}

Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=300331&r1=300330&r2=300331&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Fri Apr 14 10:49:59 2017
@@ -3160,7 +3160,7 @@ void LSRInstance::CollectFixupsAndInitia
         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 @@ Value *LSRInstance::Expand(const LSRUse
     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 @@ Value *LSRInstance::Expand(const LSRUse
 
     // 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.




More information about the llvm-commits mailing list