[llvm-commits] CVS: llvm/include/llvm/Analysis/ScalarEvolution.h ScalarEvolutionExpressions.h
Chris Lattner
lattner at cs.uiuc.edu
Fri Apr 23 16:29:01 PDT 2004
Changes in directory llvm/include/llvm/Analysis:
ScalarEvolution.h updated: 1.4 -> 1.5
ScalarEvolutionExpressions.h updated: 1.1 -> 1.2
---
Log message:
Remove the SCEV::expandCodeFor method, add a new SCEVVisitor class.
---
Diffs of the changes: (+40 -86)
Index: llvm/include/llvm/Analysis/ScalarEvolution.h
diff -u llvm/include/llvm/Analysis/ScalarEvolution.h:1.4 llvm/include/llvm/Analysis/ScalarEvolution.h:1.5
--- llvm/include/llvm/Analysis/ScalarEvolution.h:1.4 Thu Apr 22 10:00:36 2004
+++ llvm/include/llvm/Analysis/ScalarEvolution.h Fri Apr 23 16:28:25 2004
@@ -31,7 +31,6 @@
class Loop;
class LoopInfo;
class SCEVHandle;
- class ScalarEvolutionRewriter;
/// SCEV - This class represent an analyzed expression in the program. These
/// are reference counted opaque objects that the client is not allowed to
@@ -75,13 +74,6 @@
///
virtual const Type *getType() const = 0;
- /// expandCodeFor - Given a rewriter object, expand this SCEV into a closed
- /// form expression and return a Value corresponding to the expression in
- /// question.
- virtual Value *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt) = 0;
-
-
/// print - Print out the internal representation of this scalar to the
/// specified stream. This should really only be used for debugging
/// purposes.
@@ -109,7 +101,6 @@
virtual bool isLoopInvariant(const Loop *L) const;
virtual const Type *getType() const;
virtual bool hasComputableLoopEvolution(const Loop *L) const;
- virtual Value *expandCodeFor(ScalarEvolutionRewriter &, Instruction *);
virtual void print(std::ostream &OS) const;
@@ -218,54 +209,6 @@
virtual void releaseMemory();
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
virtual void print(std::ostream &OS) const;
- };
-
- /// ScalarEvolutionRewriter - This class uses information about analyze
- /// scalars to rewrite expressions in canonical form. This can be used for
- /// induction variable substitution, strength reduction, or loop exit value
- /// replacement.
- ///
- /// Clients should create an instance of this class when rewriting is needed,
- /// and destroying it when finished to allow the release of the associated
- /// memory.
- class ScalarEvolutionRewriter {
- ScalarEvolution &SE;
- LoopInfo &LI;
- std::map<SCEVHandle, Value*> InsertedExpressions;
- std::set<Instruction*> InsertedInstructions;
- public:
- ScalarEvolutionRewriter(ScalarEvolution &se, LoopInfo &li)
- : SE(se), LI(li) {}
-
- /// isInsertedInstruction - Return true if the specified instruction was
- /// inserted by the code rewriter. If so, the client should not modify the
- /// instruction.
- bool isInsertedInstruction(Instruction *I) const {
- return InsertedInstructions.count(I);
- }
-
- /// GetOrInsertCanonicalInductionVariable - This method returns the
- /// canonical induction variable of the specified type for the specified
- /// loop (inserts one if there is none). A canonical induction variable
- /// starts at zero and steps by one on each iteration.
- Value *GetOrInsertCanonicalInductionVariable(const Loop *L, const Type *Ty);
-
-
- /// addInsertedValue - Remember the specified instruction as being the
- /// canonical form for the specified SCEV.
- void addInsertedValue(Instruction *I, SCEV *S) {
- InsertedExpressions[S] = (Value*)I;
- InsertedInstructions.insert(I);
- }
-
- /// ExpandCodeFor - Insert code to directly compute the specified SCEV
- /// expression into the program. The inserted code is inserted into the
- /// specified block.
- ///
- /// If a particular value sign is required, a type may be specified for the
- /// result.
- Value *ExpandCodeFor(SCEVHandle SH, Instruction *InsertPt,
- const Type *Ty = 0);
};
}
Index: llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
diff -u llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h:1.1 llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h:1.2
--- llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h:1.1 Thu Apr 15 10:06:59 2004
+++ llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h Fri Apr 23 16:28:25 2004
@@ -56,11 +56,6 @@
virtual const Type *getType() const;
- Value *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt) {
- return (Value*)getValue();
- }
-
virtual void print(std::ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -99,9 +94,6 @@
/// known to have. This method is only valid on integer SCEV objects.
virtual ConstantRange getValueRange() const;
- Value *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt);
-
virtual void print(std::ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -140,9 +132,6 @@
/// known to have. This method is only valid on integer SCEV objects.
virtual ConstantRange getValueRange() const;
- Value *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt);
-
virtual void print(std::ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -236,9 +225,6 @@
virtual const char *getOperationStr() const { return " + "; }
- Value *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt);
-
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SCEVAddExpr *S) { return true; }
static inline bool classof(const SCEV *S) {
@@ -266,9 +252,6 @@
virtual const char *getOperationStr() const { return " * "; }
- Value *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt);
-
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SCEVMulExpr *S) { return true; }
static inline bool classof(const SCEV *S) {
@@ -305,9 +288,6 @@
virtual const Type *getType() const;
- Value *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt);
-
void print(std::ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -376,10 +356,6 @@
virtual const Type *getType() const { return Operands[0]->getType(); }
- Value *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt);
-
-
/// isAffine - Return true if this is an affine AddRec (i.e., it represents
/// an expressions A+B*x where A and B are loop invariant values.
bool isAffine() const {
@@ -433,12 +409,11 @@
/// SCEVUnknown.
static SCEVHandle get(Value *V);
- Value *getValue() const { return 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 *expandCodeFor(ScalarEvolutionRewriter &SER,
- Instruction *InsertPt) {
- return V;
- }
+ Value *getValue() const { return V; }
virtual bool isLoopInvariant(const Loop *L) const;
virtual bool hasComputableLoopEvolution(const Loop *QL) const {
@@ -453,6 +428,42 @@
static inline bool classof(const SCEVUnknown *S) { return true; }
static inline bool classof(const SCEV *S) {
return S->getSCEVType() == scUnknown;
+ }
+ };
+
+ /// SCEVVisitor - This class defines a simple visitor class that may be used
+ /// for various SCEV analysis purposes.
+ template<typename SC, typename RetVal=void>
+ struct SCEVVisitor {
+ RetVal visit(SCEV *S) {
+ switch (S->getSCEVType()) {
+ case scConstant:
+ return ((SC*)this)->visitConstant((SCEVConstant*)S);
+ case scTruncate:
+ return ((SC*)this)->visitTruncateExpr((SCEVTruncateExpr*)S);
+ case scZeroExtend:
+ return ((SC*)this)->visitZeroExtendExpr((SCEVZeroExtendExpr*)S);
+ case scAddExpr:
+ return ((SC*)this)->visitAddExpr((SCEVAddExpr*)S);
+ case scMulExpr:
+ return ((SC*)this)->visitMulExpr((SCEVMulExpr*)S);
+ case scUDivExpr:
+ return ((SC*)this)->visitUDivExpr((SCEVUDivExpr*)S);
+ case scAddRecExpr:
+ return ((SC*)this)->visitAddRecExpr((SCEVAddRecExpr*)S);
+ case scUnknown:
+ return ((SC*)this)->visitUnknown((SCEVUnknown*)S);
+ case scCouldNotCompute:
+ return ((SC*)this)->visitCouldNotCompute((SCEVCouldNotCompute*)S);
+ default:
+ assert(0 && "Unknown SCEV type!");
+ }
+ }
+
+ RetVal visitCouldNotCompute(SCEVCouldNotCompute *S) {
+ assert(0 && "Invalid use of SCEVCouldNotCompute!");
+ abort();
+ return RetVal();
}
};
}
More information about the llvm-commits
mailing list