diff options
author | Dan Gohman <gohman@apple.com> | 2007-10-22 18:31:58 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2007-10-22 18:31:58 +0000 |
commit | 246b2564d3bbbafe06ebf6a67745cd24141b5cb4 (patch) | |
tree | 44ca6627cdb239fbc1e2bdbe853716f4ccb29696 /include/llvm/Analysis | |
parent | 245741d2a1ccec53a87bb5d02b711244c179f07a (diff) | |
download | external_llvm-246b2564d3bbbafe06ebf6a67745cd24141b5cb4.zip external_llvm-246b2564d3bbbafe06ebf6a67745cd24141b5cb4.tar.gz external_llvm-246b2564d3bbbafe06ebf6a67745cd24141b5cb4.tar.bz2 |
Move the SCEV object factors from being static members of the individual
SCEV subclasses to being non-static member functions of the ScalarEvolution
class.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43224 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Analysis')
-rw-r--r-- | include/llvm/Analysis/ScalarEvolution.h | 71 | ||||
-rw-r--r-- | include/llvm/Analysis/ScalarEvolutionExpander.h | 4 | ||||
-rw-r--r-- | include/llvm/Analysis/ScalarEvolutionExpressions.h | 139 |
3 files changed, 112 insertions, 102 deletions
diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h index b6a58fe..9e9da6c 100644 --- a/include/llvm/Analysis/ScalarEvolution.h +++ b/include/llvm/Analysis/ScalarEvolution.h @@ -27,12 +27,15 @@ #include <set> namespace llvm { + class APInt; + class ConstantInt; class Instruction; class Type; class ConstantRange; class Loop; class LoopInfo; class SCEVHandle; + class ScalarEvolution; /// SCEV - This class represent an analyzed expression in the program. These /// are reference counted opaque objects that the client is not allowed to @@ -56,16 +59,6 @@ namespace llvm { public: explicit SCEV(unsigned SCEVTy) : SCEVType(SCEVTy), RefCount(0) {} - /// getNegativeSCEV - Return the SCEV object corresponding to -V. - /// - static SCEVHandle getNegativeSCEV(const SCEVHandle &V); - - /// getMinusSCEV - Return LHS-RHS. - /// - static SCEVHandle getMinusSCEV(const SCEVHandle &LHS, - const SCEVHandle &RHS); - - unsigned getSCEVType() const { return SCEVType; } /// getValueRange - Return the tightest constant bounds that this value is @@ -97,7 +90,8 @@ namespace llvm { /// returns itself. virtual SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const = 0; + const SCEVHandle &Conc, + ScalarEvolution &SE) const = 0; /// print - Print out the internal representation of this scalar to the /// specified stream. This should really only be used for debugging @@ -131,7 +125,8 @@ namespace llvm { void print(std::ostream *OS) const { if (OS) print(*OS); } virtual SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const; + const SCEVHandle &Conc, + ScalarEvolution &SE) const; /// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const SCEVCouldNotCompute *S) { return true; } @@ -204,6 +199,58 @@ namespace llvm { /// specified expression. SCEVHandle getSCEV(Value *V) const; + SCEVHandle getConstant(ConstantInt *V); + SCEVHandle getConstant(const APInt& Val); + SCEVHandle getTruncateExpr(const SCEVHandle &Op, const Type *Ty); + SCEVHandle getZeroExtendExpr(const SCEVHandle &Op, const Type *Ty); + SCEVHandle getSignExtendExpr(const SCEVHandle &Op, const Type *Ty); + SCEVHandle getAddExpr(std::vector<SCEVHandle> &Ops); + SCEVHandle getAddExpr(const SCEVHandle &LHS, const SCEVHandle &RHS) { + std::vector<SCEVHandle> Ops; + Ops.push_back(LHS); + Ops.push_back(RHS); + return getAddExpr(Ops); + } + SCEVHandle getAddExpr(const SCEVHandle &Op0, const SCEVHandle &Op1, + const SCEVHandle &Op2) { + std::vector<SCEVHandle> Ops; + Ops.push_back(Op0); + Ops.push_back(Op1); + Ops.push_back(Op2); + return getAddExpr(Ops); + } + SCEVHandle getMulExpr(std::vector<SCEVHandle> &Ops); + SCEVHandle getMulExpr(const SCEVHandle &LHS, const SCEVHandle &RHS) { + std::vector<SCEVHandle> Ops; + Ops.push_back(LHS); + Ops.push_back(RHS); + return getMulExpr(Ops); + } + SCEVHandle getSDivExpr(const SCEVHandle &LHS, const SCEVHandle &RHS); + SCEVHandle getAddRecExpr(const SCEVHandle &Start, const SCEVHandle &Step, + const Loop *L); + SCEVHandle getAddRecExpr(std::vector<SCEVHandle> &Operands, + const Loop *L); + SCEVHandle getAddRecExpr(const std::vector<SCEVHandle> &Operands, + const Loop *L) { + std::vector<SCEVHandle> NewOp(Operands); + return getAddRecExpr(NewOp, L); + } + SCEVHandle getUnknown(Value *V); + + /// getNegativeSCEV - Return the SCEV object corresponding to -V. + /// + SCEVHandle getNegativeSCEV(const SCEVHandle &V); + + /// getMinusSCEV - Return LHS-RHS. + /// + SCEVHandle getMinusSCEV(const SCEVHandle &LHS, + const SCEVHandle &RHS); + + /// getIntegerSCEV - Given an integer or FP type, create a constant for the + /// specified signed integer value and return a SCEV for the constant. + SCEVHandle getIntegerSCEV(int Val, const Type *Ty); + /// hasSCEV - Return true if the SCEV for this value has already been /// computed. bool hasSCEV(Value *V) const; diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h index 8866de5..8582067 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpander.h +++ b/include/llvm/Analysis/ScalarEvolutionExpander.h @@ -61,8 +61,8 @@ namespace llvm { /// starts at zero and steps by one on each iteration. Value *getOrInsertCanonicalInductionVariable(const Loop *L, const Type *Ty){ assert(Ty->isInteger() && "Can only insert integer induction variables!"); - SCEVHandle H = SCEVAddRecExpr::get(SCEVUnknown::getIntegerSCEV(0, Ty), - SCEVUnknown::getIntegerSCEV(1, Ty), L); + SCEVHandle H = SE.getAddRecExpr(SE.getIntegerSCEV(0, Ty), + SE.getIntegerSCEV(1, Ty), L); return expand(H); } diff --git a/include/llvm/Analysis/ScalarEvolutionExpressions.h b/include/llvm/Analysis/ScalarEvolutionExpressions.h index af1656e..7fbeff7 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpressions.h +++ b/include/llvm/Analysis/ScalarEvolutionExpressions.h @@ -32,16 +32,13 @@ namespace llvm { /// SCEVConstant - This class represents a constant integer value. /// class SCEVConstant : public SCEV { + friend class ScalarEvolution; + ConstantInt *V; explicit SCEVConstant(ConstantInt *v) : SCEV(scConstant), V(v) {} virtual ~SCEVConstant(); public: - /// get method - This just gets and returns a new SCEVConstant object. - /// - static SCEVHandle get(ConstantInt *V); - static SCEVHandle get(const APInt& Val); - ConstantInt *getValue() const { return V; } /// getValueRange - Return the tightest constant bounds that this value is @@ -59,7 +56,8 @@ namespace llvm { virtual const Type *getType() const; SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const { + const SCEVHandle &Conc, + ScalarEvolution &SE) const { return this; } @@ -78,15 +76,13 @@ namespace llvm { /// to a smaller integer value. /// class SCEVTruncateExpr : public SCEV { + friend class ScalarEvolution; + SCEVHandle Op; const Type *Ty; SCEVTruncateExpr(const SCEVHandle &op, const Type *ty); virtual ~SCEVTruncateExpr(); public: - /// get method - This just gets and returns a new SCEVTruncate object - /// - static SCEVHandle get(const SCEVHandle &Op, const Type *Ty); - const SCEVHandle &getOperand() const { return Op; } virtual const Type *getType() const { return Ty; } @@ -99,11 +95,12 @@ namespace llvm { } SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const { - SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc); + const SCEVHandle &Conc, + ScalarEvolution &SE) const { + SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (H == Op) return this; - return get(H, Ty); + return SE.getTruncateExpr(H, Ty); } /// getValueRange - Return the tightest constant bounds that this value is @@ -125,15 +122,13 @@ namespace llvm { /// integer value to a larger integer value. /// class SCEVZeroExtendExpr : public SCEV { + friend class ScalarEvolution; + SCEVHandle Op; const Type *Ty; SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty); virtual ~SCEVZeroExtendExpr(); public: - /// get method - This just gets and returns a new SCEVZeroExtend object - /// - static SCEVHandle get(const SCEVHandle &Op, const Type *Ty); - const SCEVHandle &getOperand() const { return Op; } virtual const Type *getType() const { return Ty; } @@ -150,11 +145,12 @@ namespace llvm { virtual ConstantRange getValueRange() const; SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const { - SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc); + const SCEVHandle &Conc, + ScalarEvolution &SE) const { + SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (H == Op) return this; - return get(H, Ty); + return SE.getZeroExtendExpr(H, Ty); } virtual void print(std::ostream &OS) const; @@ -172,15 +168,13 @@ namespace llvm { /// integer value to a larger integer value. /// class SCEVSignExtendExpr : public SCEV { + friend class ScalarEvolution; + SCEVHandle Op; const Type *Ty; SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty); virtual ~SCEVSignExtendExpr(); public: - /// get method - This just gets and returns a new SCEVSignExtend object - /// - static SCEVHandle get(const SCEVHandle &Op, const Type *Ty); - const SCEVHandle &getOperand() const { return Op; } virtual const Type *getType() const { return Ty; } @@ -197,11 +191,12 @@ namespace llvm { virtual ConstantRange getValueRange() const; SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const { - SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc); + const SCEVHandle &Conc, + ScalarEvolution &SE) const { + SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (H == Op) return this; - return get(H, Ty); + return SE.getSignExtendExpr(H, Ty); } virtual void print(std::ostream &OS) const; @@ -220,6 +215,8 @@ namespace llvm { /// operators. /// class SCEVCommutativeExpr : public SCEV { + friend class ScalarEvolution; + std::vector<SCEVHandle> Operands; protected: @@ -264,7 +261,8 @@ namespace llvm { } SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const; + const SCEVHandle &Conc, + ScalarEvolution &SE) const; virtual const char *getOperationStr() const = 0; @@ -285,29 +283,13 @@ namespace llvm { /// SCEVAddExpr - This node represents an addition of some number of SCEVs. /// class SCEVAddExpr : public SCEVCommutativeExpr { + friend class ScalarEvolution; + SCEVAddExpr(const std::vector<SCEVHandle> &ops) : SCEVCommutativeExpr(scAddExpr, ops) { } public: - static SCEVHandle get(std::vector<SCEVHandle> &Ops); - - static SCEVHandle get(const SCEVHandle &LHS, const SCEVHandle &RHS) { - std::vector<SCEVHandle> Ops; - Ops.push_back(LHS); - Ops.push_back(RHS); - return get(Ops); - } - - static SCEVHandle get(const SCEVHandle &Op0, const SCEVHandle &Op1, - const SCEVHandle &Op2) { - std::vector<SCEVHandle> Ops; - Ops.push_back(Op0); - Ops.push_back(Op1); - Ops.push_back(Op2); - return get(Ops); - } - virtual const char *getOperationStr() const { return " + "; } /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -321,20 +303,13 @@ namespace llvm { /// SCEVMulExpr - This node represents multiplication of some number of SCEVs. /// class SCEVMulExpr : public SCEVCommutativeExpr { + friend class ScalarEvolution; + SCEVMulExpr(const std::vector<SCEVHandle> &ops) : SCEVCommutativeExpr(scMulExpr, ops) { } public: - static SCEVHandle get(std::vector<SCEVHandle> &Ops); - - static SCEVHandle get(const SCEVHandle &LHS, const SCEVHandle &RHS) { - std::vector<SCEVHandle> Ops; - Ops.push_back(LHS); - Ops.push_back(RHS); - return get(Ops); - } - virtual const char *getOperationStr() const { return " * "; } /// Methods for support type inquiry through isa, cast, and dyn_cast: @@ -349,16 +324,14 @@ namespace llvm { /// SCEVSDivExpr - This class represents a binary signed division operation. /// class SCEVSDivExpr : public SCEV { + friend class ScalarEvolution; + SCEVHandle LHS, RHS; SCEVSDivExpr(const SCEVHandle &lhs, const SCEVHandle &rhs) : SCEV(scSDivExpr), LHS(lhs), RHS(rhs) {} virtual ~SCEVSDivExpr(); public: - /// get method - This just gets and returns a new SCEVSDiv object. - /// - static SCEVHandle get(const SCEVHandle &LHS, const SCEVHandle &RHS); - const SCEVHandle &getLHS() const { return LHS; } const SCEVHandle &getRHS() const { return RHS; } @@ -372,13 +345,14 @@ namespace llvm { } SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const { - SCEVHandle L = LHS->replaceSymbolicValuesWithConcrete(Sym, Conc); - SCEVHandle R = RHS->replaceSymbolicValuesWithConcrete(Sym, Conc); + const SCEVHandle &Conc, + ScalarEvolution &SE) const { + SCEVHandle L = LHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); + SCEVHandle R = RHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE); if (L == LHS && R == RHS) return this; else - return get(L, R); + return SE.getSDivExpr(L, R); } @@ -402,6 +376,8 @@ namespace llvm { /// All operands of an AddRec are required to be loop invariant. /// class SCEVAddRecExpr : public SCEV { + friend class ScalarEvolution; + std::vector<SCEVHandle> Operands; const Loop *L; @@ -413,16 +389,6 @@ namespace llvm { } ~SCEVAddRecExpr(); public: - static SCEVHandle get(const SCEVHandle &Start, const SCEVHandle &Step, - const Loop *); - static SCEVHandle get(std::vector<SCEVHandle> &Operands, - const Loop *); - static SCEVHandle get(const std::vector<SCEVHandle> &Operands, - const Loop *L) { - std::vector<SCEVHandle> NewOp(Operands); - return get(NewOp, L); - } - typedef std::vector<SCEVHandle>::const_iterator op_iterator; op_iterator op_begin() const { return Operands.begin(); } op_iterator op_end() const { return Operands.end(); } @@ -436,10 +402,10 @@ namespace llvm { /// getStepRecurrence - This method constructs and returns the recurrence /// indicating how much this expression steps by. If this is a polynomial /// of degree N, it returns a chrec of degree N-1. - SCEVHandle getStepRecurrence() const { + SCEVHandle getStepRecurrence(ScalarEvolution &SE) const { if (getNumOperands() == 2) return getOperand(1); - return SCEVAddRecExpr::get(std::vector<SCEVHandle>(op_begin()+1,op_end()), - getLoop()); + return SE.getAddRecExpr(std::vector<SCEVHandle>(op_begin()+1,op_end()), + getLoop()); } virtual bool hasComputableLoopEvolution(const Loop *QL) const { @@ -468,7 +434,7 @@ namespace llvm { /// evaluateAtIteration - Return the value of this chain of recurrences at /// the specified iteration number. - SCEVHandle evaluateAtIteration(SCEVHandle It) const; + SCEVHandle evaluateAtIteration(SCEVHandle It, ScalarEvolution &SE) const; /// getNumIterationsInRange - Return the number of iterations of this loop /// that produce values in the specified constant range. Another way of @@ -476,10 +442,12 @@ namespace llvm { /// value is not in the condition, thus computing the exit count. If the /// iteration count can't be computed, an instance of SCEVCouldNotCompute is /// returned. - SCEVHandle getNumIterationsInRange(ConstantRange Range) const; + SCEVHandle getNumIterationsInRange(ConstantRange Range, + ScalarEvolution &SE) const; SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const; + const SCEVHandle &Conc, + ScalarEvolution &SE) const; virtual void print(std::ostream &OS) const; void print(std::ostream *OS) const { if (OS) print(*OS); } @@ -497,20 +465,14 @@ namespace llvm { /// value for the analysis. /// class SCEVUnknown : public SCEV { + friend class ScalarEvolution; + Value *V; SCEVUnknown(Value *v) : SCEV(scUnknown), V(v) {} protected: ~SCEVUnknown(); public: - /// get method - For SCEVUnknown, this just gets and returns a new - /// SCEVUnknown. - static SCEVHandle get(Value *V); - - /// getIntegerSCEV - Given an integer or FP type, create a constant for the - /// specified signed integer value and return a SCEV for the constant. - static SCEVHandle getIntegerSCEV(int Val, const Type *Ty); - Value *getValue() const { return V; } virtual bool isLoopInvariant(const Loop *L) const; @@ -519,7 +481,8 @@ namespace llvm { } SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym, - const SCEVHandle &Conc) const { + const SCEVHandle &Conc, + ScalarEvolution &SE) const { if (&*Sym == this) return Conc; return this; } |