summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-04-21 01:25:57 +0000
committerDan Gohman <gohman@apple.com>2009-04-21 01:25:57 +0000
commit4860db61be85b4fc7bfffe212cee5b3e2a9188f2 (patch)
tree372850da551a9d52e4ad4da399979d759d30f171 /llvm
parent9ebf9516af5f4be3acf29e2f7dda51219da90d6a (diff)
downloadbcm5719-llvm-4860db61be85b4fc7bfffe212cee5b3e2a9188f2.tar.gz
bcm5719-llvm-4860db61be85b4fc7bfffe212cee5b3e2a9188f2.zip
Factor out a common base class from SCEVTruncateExpr, SCEVZeroExtendExpr,
and SCEVSignExtendExpr. llvm-svn: 69649
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h76
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp28
-rw-r--r--llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp8
3 files changed, 48 insertions, 64 deletions
diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
index 1cfc6390ccb..d94a9ebcb57 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolutionExpressions.h
@@ -73,16 +73,16 @@ namespace llvm {
};
//===--------------------------------------------------------------------===//
- /// SCEVTruncateExpr - This class represents a truncation of an integer value
- /// to a smaller integer value.
+ /// SCEVCastExpr - This is the base class for unary cast operator classes.
///
- class SCEVTruncateExpr : public SCEV {
- friend class ScalarEvolution;
-
+ class SCEVCastExpr : public SCEV {
+ protected:
SCEVHandle Op;
const Type *Ty;
- SCEVTruncateExpr(const SCEVHandle &op, const Type *ty);
- virtual ~SCEVTruncateExpr();
+
+ SCEVCastExpr(unsigned SCEVTy, const SCEVHandle &op, const Type *ty);
+ virtual ~SCEVCastExpr();
+
public:
const SCEVHandle &getOperand() const { return Op; }
virtual const Type *getType() const { return Ty; }
@@ -95,6 +95,28 @@ namespace llvm {
return Op->hasComputableLoopEvolution(L);
}
+ virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const;
+
+ /// Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const SCEVCastExpr *S) { return true; }
+ static inline bool classof(const SCEV *S) {
+ return S->getSCEVType() == scTruncate ||
+ S->getSCEVType() == scZeroExtend ||
+ S->getSCEVType() == scSignExtend;
+ }
+ };
+
+ //===--------------------------------------------------------------------===//
+ /// SCEVTruncateExpr - This class represents a truncation of an integer value
+ /// to a smaller integer value.
+ ///
+ class SCEVTruncateExpr : public SCEVCastExpr {
+ friend class ScalarEvolution;
+
+ SCEVTruncateExpr(const SCEVHandle &op, const Type *ty);
+ virtual ~SCEVTruncateExpr();
+
+ public:
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
const SCEVHandle &Conc,
ScalarEvolution &SE) const {
@@ -104,8 +126,6 @@ namespace llvm {
return SE.getTruncateExpr(H, Ty);
}
- virtual 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:
@@ -119,25 +139,13 @@ namespace llvm {
/// SCEVZeroExtendExpr - This class represents a zero extension of a small
/// integer value to a larger integer value.
///
- class SCEVZeroExtendExpr : public SCEV {
+ class SCEVZeroExtendExpr : public SCEVCastExpr {
friend class ScalarEvolution;
- SCEVHandle Op;
- const Type *Ty;
SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty);
virtual ~SCEVZeroExtendExpr();
- public:
- const SCEVHandle &getOperand() const { return Op; }
- virtual const Type *getType() const { return Ty; }
-
- virtual bool isLoopInvariant(const Loop *L) const {
- return Op->isLoopInvariant(L);
- }
-
- virtual bool hasComputableLoopEvolution(const Loop *L) const {
- return Op->hasComputableLoopEvolution(L);
- }
+ public:
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
const SCEVHandle &Conc,
ScalarEvolution &SE) const {
@@ -147,8 +155,6 @@ namespace llvm {
return SE.getZeroExtendExpr(H, Ty);
}
- 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:
@@ -162,25 +168,13 @@ namespace llvm {
/// SCEVSignExtendExpr - This class represents a sign extension of a small
/// integer value to a larger integer value.
///
- class SCEVSignExtendExpr : public SCEV {
+ class SCEVSignExtendExpr : public SCEVCastExpr {
friend class ScalarEvolution;
- SCEVHandle Op;
- const Type *Ty;
SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty);
virtual ~SCEVSignExtendExpr();
- public:
- const SCEVHandle &getOperand() const { return Op; }
- virtual const Type *getType() const { return Ty; }
-
- virtual bool isLoopInvariant(const Loop *L) const {
- return Op->isLoopInvariant(L);
- }
-
- virtual bool hasComputableLoopEvolution(const Loop *L) const {
- return Op->hasComputableLoopEvolution(L);
- }
+ public:
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
const SCEVHandle &Conc,
ScalarEvolution &SE) const {
@@ -190,8 +184,6 @@ namespace llvm {
return SE.getSignExtendExpr(H, Ty);
}
- 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:
@@ -207,8 +199,6 @@ namespace llvm {
/// operators.
///
class SCEVCommutativeExpr : public SCEV {
- friend class ScalarEvolution;
-
std::vector<SCEVHandle> Operands;
protected:
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 5300dbe49f3..5308b8d0f53 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -190,6 +190,16 @@ void SCEVConstant::print(raw_ostream &OS) const {
WriteAsOperand(OS, V, false);
}
+SCEVCastExpr::SCEVCastExpr(unsigned SCEVTy,
+ const SCEVHandle &op, const Type *ty)
+ : SCEV(SCEVTy), Op(op), Ty(ty) {}
+
+SCEVCastExpr::~SCEVCastExpr() {}
+
+bool SCEVCastExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
+ return Op->dominates(BB, DT);
+}
+
// SCEVTruncates - Only allow the creation of one SCEVTruncateExpr for any
// particular input. Don't use a SCEVHandle here, or else the object will
// never be deleted!
@@ -197,7 +207,7 @@ static ManagedStatic<std::map<std::pair<SCEV*, const Type*>,
SCEVTruncateExpr*> > SCEVTruncates;
SCEVTruncateExpr::SCEVTruncateExpr(const SCEVHandle &op, const Type *ty)
- : SCEV(scTruncate), Op(op), Ty(ty) {
+ : SCEVCastExpr(scTruncate, op, ty) {
assert((Op->getType()->isInteger() || isa<PointerType>(Op->getType())) &&
(Ty->isInteger() || isa<PointerType>(Ty)) &&
"Cannot truncate non-integer value!");
@@ -207,10 +217,6 @@ SCEVTruncateExpr::~SCEVTruncateExpr() {
SCEVTruncates->erase(std::make_pair(Op, Ty));
}
-bool SCEVTruncateExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
- return Op->dominates(BB, DT);
-}
-
void SCEVTruncateExpr::print(raw_ostream &OS) const {
OS << "(truncate " << *Op << " to " << *Ty << ")";
}
@@ -222,7 +228,7 @@ static ManagedStatic<std::map<std::pair<SCEV*, const Type*>,
SCEVZeroExtendExpr*> > SCEVZeroExtends;
SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty)
- : SCEV(scZeroExtend), Op(op), Ty(ty) {
+ : SCEVCastExpr(scZeroExtend, op, ty) {
assert((Op->getType()->isInteger() || isa<PointerType>(Op->getType())) &&
(Ty->isInteger() || isa<PointerType>(Ty)) &&
"Cannot zero extend non-integer value!");
@@ -232,10 +238,6 @@ SCEVZeroExtendExpr::~SCEVZeroExtendExpr() {
SCEVZeroExtends->erase(std::make_pair(Op, Ty));
}
-bool SCEVZeroExtendExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
- return Op->dominates(BB, DT);
-}
-
void SCEVZeroExtendExpr::print(raw_ostream &OS) const {
OS << "(zeroextend " << *Op << " to " << *Ty << ")";
}
@@ -247,7 +249,7 @@ static ManagedStatic<std::map<std::pair<SCEV*, const Type*>,
SCEVSignExtendExpr*> > SCEVSignExtends;
SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty)
- : SCEV(scSignExtend), Op(op), Ty(ty) {
+ : SCEVCastExpr(scSignExtend, op, ty) {
assert((Op->getType()->isInteger() || isa<PointerType>(Op->getType())) &&
(Ty->isInteger() || isa<PointerType>(Ty)) &&
"Cannot sign extend non-integer value!");
@@ -257,10 +259,6 @@ SCEVSignExtendExpr::~SCEVSignExtendExpr() {
SCEVSignExtends->erase(std::make_pair(Op, Ty));
}
-bool SCEVSignExtendExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
- return Op->dominates(BB, DT);
-}
-
void SCEVSignExtendExpr::print(raw_ostream &OS) const {
OS << "(signextend " << *Op << " to " << *Ty << ")";
}
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 78198b5e0bf..c436cec26ed 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -300,12 +300,8 @@ static bool containsAddRecFromDifferentLoop(SCEVHandle S, Loop *L) {
return containsAddRecFromDifferentLoop(DE->getLHS(), L) ||
containsAddRecFromDifferentLoop(DE->getRHS(), L);
#endif
- if (const SCEVTruncateExpr *TE = dyn_cast<SCEVTruncateExpr>(S))
- return containsAddRecFromDifferentLoop(TE->getOperand(), L);
- if (const SCEVZeroExtendExpr *ZE = dyn_cast<SCEVZeroExtendExpr>(S))
- return containsAddRecFromDifferentLoop(ZE->getOperand(), L);
- if (const SCEVSignExtendExpr *SE = dyn_cast<SCEVSignExtendExpr>(S))
- return containsAddRecFromDifferentLoop(SE->getOperand(), L);
+ if (const SCEVCastExpr *CE = dyn_cast<SCEVCastExpr>(S))
+ return containsAddRecFromDifferentLoop(CE->getOperand(), L);
return false;
}
OpenPOWER on IntegriCloud