[llvm-commits] [llvm] r71157 - in /llvm/trunk: include/llvm/Analysis/ScalarEvolutionExpressions.h lib/Analysis/ScalarEvolution.cpp
Dan Gohman
gohman at apple.com
Thu May 7 07:00:20 PDT 2009
Author: djg
Date: Thu May 7 09:00:19 2009
New Revision: 71157
URL: http://llvm.org/viewvc/llvm-project?rev=71157&view=rev
Log:
Factor out a common base class between SCEVCommutativeExpr and
SCEVAddRecExpr. This eliminates redundant code for visiting
all the operands of an expression.
Modified:
llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h?rev=71157&r1=71156&r2=71157&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h Thu May 7 09:00:19 2009
@@ -194,20 +194,13 @@
};
- //===--------------------------------------------------------------------===//
- /// SCEVCommutativeExpr - This node is the base class for n'ary commutative
- /// operators.
- ///
- class SCEVCommutativeExpr : public SCEV {
+ class SCEVNAryExpr : public SCEV {
+ protected:
std::vector<SCEVHandle> Operands;
- protected:
- SCEVCommutativeExpr(enum SCEVTypes T, const std::vector<SCEVHandle> &ops)
- : SCEV(T) {
- Operands.reserve(ops.size());
- Operands.insert(Operands.end(), ops.begin(), ops.end());
- }
- ~SCEVCommutativeExpr();
+ SCEVNAryExpr(enum SCEVTypes T, const std::vector<SCEVHandle> &ops)
+ : SCEV(T), Operands(ops) {}
+ virtual ~SCEVNAryExpr() {}
public:
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
@@ -221,7 +214,6 @@
op_iterator op_begin() const { return Operands.begin(); }
op_iterator op_end() const { return Operands.end(); }
-
virtual bool isLoopInvariant(const Loop *L) const {
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
if (!getOperand(i)->isLoopInvariant(L)) return false;
@@ -243,15 +235,38 @@
return HasVarying;
}
+ bool dominates(BasicBlock *BB, DominatorTree *DT) const;
+
+ virtual const Type *getType() const { return getOperand(0)->getType(); }
+
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const SCEVNAryExpr *S) { return true; }
+ static inline bool classof(const SCEV *S) {
+ return S->getSCEVType() == scAddExpr ||
+ S->getSCEVType() == scMulExpr ||
+ S->getSCEVType() == scSMaxExpr ||
+ S->getSCEVType() == scUMaxExpr ||
+ S->getSCEVType() == scAddRecExpr;
+ }
+ };
+
+ //===--------------------------------------------------------------------===//
+ /// SCEVCommutativeExpr - This node is the base class for n'ary commutative
+ /// operators.
+ ///
+ class SCEVCommutativeExpr : public SCEVNAryExpr {
+ protected:
+ SCEVCommutativeExpr(enum SCEVTypes T, const std::vector<SCEVHandle> &ops)
+ : SCEVNAryExpr(T, ops) {}
+ ~SCEVCommutativeExpr();
+
+ public:
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
const SCEVHandle &Conc,
ScalarEvolution &SE) const;
- bool dominates(BasicBlock *BB, DominatorTree *DT) const;
-
virtual const char *getOperationStr() const = 0;
- virtual const Type *getType() const { return getOperand(0)->getType(); }
virtual void print(raw_ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
@@ -364,30 +379,23 @@
///
/// All operands of an AddRec are required to be loop invariant.
///
- class SCEVAddRecExpr : public SCEV {
+ class SCEVAddRecExpr : public SCEVNAryExpr {
friend class ScalarEvolution;
- std::vector<SCEVHandle> Operands;
const Loop *L;
SCEVAddRecExpr(const std::vector<SCEVHandle> &ops, const Loop *l)
- : SCEV(scAddRecExpr), Operands(ops), L(l) {
+ : SCEVNAryExpr(scAddRecExpr, ops), L(l) {
for (size_t i = 0, e = Operands.size(); i != e; ++i)
assert(Operands[i]->isLoopInvariant(l) &&
"Operands of AddRec must be loop-invariant!");
}
~SCEVAddRecExpr();
- public:
- typedef std::vector<SCEVHandle>::const_iterator op_iterator;
- op_iterator op_begin() const { return Operands.begin(); }
- op_iterator op_end() const { return Operands.end(); }
- unsigned getNumOperands() const { return (unsigned)Operands.size(); }
- const SCEVHandle &getOperand(unsigned i) const { return Operands[i]; }
+ public:
const SCEVHandle &getStart() const { return Operands[0]; }
const Loop *getLoop() const { return L; }
-
/// 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.
@@ -404,8 +412,6 @@
virtual bool isLoopInvariant(const Loop *QueryLoop) const;
- virtual const Type *getType() const { return Operands[0]->getType(); }
-
/// 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 {
@@ -438,8 +444,6 @@
const SCEVHandle &Conc,
ScalarEvolution &SE) const;
- bool dominates(BasicBlock *BB, DominatorTree *DT) const;
-
virtual void print(raw_ostream &OS) const;
/// Methods for support type inquiry through isa, cast, and dyn_cast:
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=71157&r1=71156&r2=71157&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Thu May 7 09:00:19 2009
@@ -316,7 +316,7 @@
return this;
}
-bool SCEVCommutativeExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
+bool SCEVNAryExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
if (!getOperand(i)->dominates(BB, DT))
return false;
@@ -359,15 +359,6 @@
SCEVAddRecExprs->erase(std::make_pair(L, SCEVOps));
}
-bool SCEVAddRecExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
- for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
- if (!getOperand(i)->dominates(BB, DT))
- return false;
- }
- return true;
-}
-
-
SCEVHandle SCEVAddRecExpr::
replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
const SCEVHandle &Conc,
More information about the llvm-commits
mailing list