[llvm] r175294 - add ScevApplyRewriter

Sebastian Pop spop at codeaurora.org
Fri Feb 15 12:55:36 PST 2013


Author: spop
Date: Fri Feb 15 14:55:36 2013
New Revision: 175294

URL: http://llvm.org/viewvc/llvm-project?rev=175294&view=rev
Log:
add ScevApplyRewriter

Modified:
    llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h

Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h?rev=175294&r1=175293&r2=175294&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h Fri Feb 15 14:55:36 2013
@@ -652,6 +652,45 @@ namespace llvm {
     ValueToValueMap ⤅
   };
 
+  typedef DenseMap<const Loop*, const SCEV*> LoopToScevMapT;
+
+  /// The ScevApplyRewriter takes a scalar evolution expression and applies
+  /// the Map (Loop -> SCEV) to all AddRecExprs.
+  struct ScevApplyRewriter: public ScevRewriter {
+  public:
+    static const SCEV *rewrite(const SCEV *Scev, LoopToScevMapT &Map,
+                               ScalarEvolution &SE) {
+      ScevApplyRewriter Rewriter(SE, Map);
+      return Rewriter.visit(Scev);
+    }
+    ScevApplyRewriter(ScalarEvolution &S, LoopToScevMapT &M)
+      : ScevRewriter(S), Map(M) {}
+
+    virtual const SCEV *visitAddRecExpr(const SCEVAddRecExpr *Expr) {
+      SmallVector<const SCEV *, 2> Operands;
+      for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
+        Operands.push_back(visit(Expr->getOperand(i)));
+
+      const Loop *L = Expr->getLoop();
+      const SCEV *Res = SE.getAddRecExpr(Operands, L, Expr->getNoWrapFlags());
+
+      if (0 == Map.count(L))
+        return Res;
+
+      const SCEVAddRecExpr *Rec = (const SCEVAddRecExpr *) Res;
+      return Rec->evaluateAtIteration(Map[L], SE);
+    }
+
+  private:
+    LoopToScevMapT ⤅
+  };
+
+/// Applies the Map (Loop -> SCEV) to the given Scev.
+static inline const SCEV *apply(const SCEV *Scev, LoopToScevMapT &Map,
+                                ScalarEvolution &SE) {
+  return ScevApplyRewriter::rewrite(Scev, Map, SE);
+}
+
 }
 
 #endif





More information about the llvm-commits mailing list