[llvm] r175293 - add SCEVParameterRewriter

Hal Finkel hfinkel at anl.gov
Fri Feb 15 13:01:16 PST 2013


----- Original Message -----
> From: "Sebastian Pop" <spop at codeaurora.org>
> To: llvm-commits at cs.uiuc.edu
> Sent: Friday, February 15, 2013 2:55:33 PM
> Subject: [llvm] r175293 - add SCEVParameterRewriter
> 
> Author: spop
> Date: Fri Feb 15 14:55:33 2013
> New Revision: 175293
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=175293&view=rev
> Log:
> add SCEVParameterRewriter

In your code, this is spelled as ScevRewriter; please capitalize SCEV to match the current naming convention.

 -Hal

> 
> 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=175293&r1=175292&r2=175293&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h
> (original)
> +++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h Fri
> Feb 15 14:55:33 2013
> @@ -548,6 +548,110 @@ namespace llvm {
>      SCEVTraversal<SV> T(Visitor);
>      T.visitAll(Root);
>    }
> +
> +  /// The ScevRewriter takes a scalar evolution expression and
> copies all its
> +  /// components. The result after a rewrite is an identical SCEV.
> +  struct ScevRewriter
> +    : public SCEVVisitor<ScevRewriter, const SCEV*> {
> +  public:
> +    ScevRewriter(ScalarEvolution &S) : SE(S) {}
> +
> +    virtual const SCEV *visitConstant(const SCEVConstant *Constant)
> {
> +      return Constant;
> +    }
> +
> +    virtual const SCEV *visitTruncateExpr(const SCEVTruncateExpr
> *Expr) {
> +      const SCEV *Operand = visit(Expr->getOperand());
> +      return SE.getTruncateExpr(Operand, Expr->getType());
> +    }
> +
> +    virtual const SCEV *visitZeroExtendExpr(const SCEVZeroExtendExpr
> *Expr) {
> +      const SCEV *Operand = visit(Expr->getOperand());
> +      return SE.getZeroExtendExpr(Operand, Expr->getType());
> +    }
> +
> +    virtual const SCEV *visitSignExtendExpr(const SCEVSignExtendExpr
> *Expr) {
> +      const SCEV *Operand = visit(Expr->getOperand());
> +      return SE.getSignExtendExpr(Operand, Expr->getType());
> +    }
> +
> +    virtual const SCEV *visitAddExpr(const SCEVAddExpr *Expr) {
> +      SmallVector<const SCEV *, 2> Operands;
> +      for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
> +        Operands.push_back(visit(Expr->getOperand(i)));
> +      return SE.getAddExpr(Operands);
> +    }
> +
> +    virtual const SCEV *visitMulExpr(const SCEVMulExpr *Expr) {
> +      SmallVector<const SCEV *, 2> Operands;
> +      for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
> +        Operands.push_back(visit(Expr->getOperand(i)));
> +      return SE.getMulExpr(Operands);
> +    }
> +
> +    virtual const SCEV *visitUDivExpr(const SCEVUDivExpr *Expr) {
> +      return SE.getUDivExpr(visit(Expr->getLHS()),
> visit(Expr->getRHS()));
> +    }
> +
> +    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)));
> +      return SE.getAddRecExpr(Operands, Expr->getLoop(),
> +                              Expr->getNoWrapFlags());
> +    }
> +
> +    virtual const SCEV *visitSMaxExpr(const SCEVSMaxExpr *Expr) {
> +      SmallVector<const SCEV *, 2> Operands;
> +      for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
> +        Operands.push_back(visit(Expr->getOperand(i)));
> +      return SE.getSMaxExpr(Operands);
> +    }
> +
> +    virtual const SCEV *visitUMaxExpr(const SCEVUMaxExpr *Expr) {
> +      SmallVector<const SCEV *, 2> Operands;
> +      for (int i = 0, e = Expr->getNumOperands(); i < e; ++i)
> +        Operands.push_back(visit(Expr->getOperand(i)));
> +      return SE.getUMaxExpr(Operands);
> +    }
> +
> +    virtual const SCEV *visitUnknown(const SCEVUnknown *Expr) {
> +      return Expr;
> +    }
> +
> +    virtual const SCEV *visitCouldNotCompute(const
> SCEVCouldNotCompute *Expr) {
> +      return Expr;
> +    }
> +
> +  protected:
> +    ScalarEvolution &SE;
> +  };
> +
> +  typedef DenseMap<const Value*, Value*> ValueToValueMap;
> +
> +  /// The ScevParameterRewriter takes a scalar evolution expression
> and updates
> +  /// the SCEVUnknown components following the Map (Value -> Value).
> +  struct ScevParameterRewriter: public ScevRewriter {
> +  public:
> +    static const SCEV *rewrite(const SCEV *Scev, ScalarEvolution
> &SE,
> +                               ValueToValueMap &Map) {
> +      ScevParameterRewriter Rewriter(SE, Map);
> +      return Rewriter.visit(Scev);
> +    }
> +    ScevParameterRewriter(ScalarEvolution &S, ValueToValueMap &M)
> +      : ScevRewriter(S), Map(M) {}
> +
> +    virtual const SCEV *visitUnknown(const SCEVUnknown *Expr) {
> +      Value *V = Expr->getValue();
> +      if (Map.count(V))
> +        return SE.getUnknown(Map[V]);
> +      return Expr;
> +    }
> +
> +  private:
> +    ValueToValueMap ⤅
> +  };
> +
>  }
>  
>  #endif
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> 



More information about the llvm-commits mailing list