mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-23 16:19:52 +00:00
Factor out a common base class between SCEVCommutativeExpr and
SCEVAddRecExpr. This eliminates redundant code for visiting all the operands of an expression. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71157 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -194,20 +194,13 @@ namespace llvm {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//===--------------------------------------------------------------------===//
|
class SCEVNAryExpr : public SCEV {
|
||||||
/// SCEVCommutativeExpr - This node is the base class for n'ary commutative
|
protected:
|
||||||
/// operators.
|
|
||||||
///
|
|
||||||
class SCEVCommutativeExpr : public SCEV {
|
|
||||||
std::vector<SCEVHandle> Operands;
|
std::vector<SCEVHandle> Operands;
|
||||||
|
|
||||||
protected:
|
SCEVNAryExpr(enum SCEVTypes T, const std::vector<SCEVHandle> &ops)
|
||||||
SCEVCommutativeExpr(enum SCEVTypes T, const std::vector<SCEVHandle> &ops)
|
: SCEV(T), Operands(ops) {}
|
||||||
: SCEV(T) {
|
virtual ~SCEVNAryExpr() {}
|
||||||
Operands.reserve(ops.size());
|
|
||||||
Operands.insert(Operands.end(), ops.begin(), ops.end());
|
|
||||||
}
|
|
||||||
~SCEVCommutativeExpr();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
||||||
@@ -221,7 +214,6 @@ namespace llvm {
|
|||||||
op_iterator op_begin() const { return Operands.begin(); }
|
op_iterator op_begin() const { return Operands.begin(); }
|
||||||
op_iterator op_end() const { return Operands.end(); }
|
op_iterator op_end() const { return Operands.end(); }
|
||||||
|
|
||||||
|
|
||||||
virtual bool isLoopInvariant(const Loop *L) const {
|
virtual bool isLoopInvariant(const Loop *L) const {
|
||||||
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
||||||
if (!getOperand(i)->isLoopInvariant(L)) return false;
|
if (!getOperand(i)->isLoopInvariant(L)) return false;
|
||||||
@@ -243,15 +235,38 @@ namespace llvm {
|
|||||||
return HasVarying;
|
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,
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
||||||
const SCEVHandle &Conc,
|
const SCEVHandle &Conc,
|
||||||
ScalarEvolution &SE) const;
|
ScalarEvolution &SE) const;
|
||||||
|
|
||||||
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
||||||
|
|
||||||
virtual const char *getOperationStr() const = 0;
|
virtual const char *getOperationStr() const = 0;
|
||||||
|
|
||||||
virtual const Type *getType() const { return getOperand(0)->getType(); }
|
|
||||||
virtual void print(raw_ostream &OS) const;
|
virtual void print(raw_ostream &OS) const;
|
||||||
|
|
||||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
@@ -364,30 +379,23 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
/// All operands of an AddRec are required to be loop invariant.
|
/// All operands of an AddRec are required to be loop invariant.
|
||||||
///
|
///
|
||||||
class SCEVAddRecExpr : public SCEV {
|
class SCEVAddRecExpr : public SCEVNAryExpr {
|
||||||
friend class ScalarEvolution;
|
friend class ScalarEvolution;
|
||||||
|
|
||||||
std::vector<SCEVHandle> Operands;
|
|
||||||
const Loop *L;
|
const Loop *L;
|
||||||
|
|
||||||
SCEVAddRecExpr(const std::vector<SCEVHandle> &ops, 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)
|
for (size_t i = 0, e = Operands.size(); i != e; ++i)
|
||||||
assert(Operands[i]->isLoopInvariant(l) &&
|
assert(Operands[i]->isLoopInvariant(l) &&
|
||||||
"Operands of AddRec must be loop-invariant!");
|
"Operands of AddRec must be loop-invariant!");
|
||||||
}
|
}
|
||||||
~SCEVAddRecExpr();
|
~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(); }
|
public:
|
||||||
const SCEVHandle &getOperand(unsigned i) const { return Operands[i]; }
|
|
||||||
const SCEVHandle &getStart() const { return Operands[0]; }
|
const SCEVHandle &getStart() const { return Operands[0]; }
|
||||||
const Loop *getLoop() const { return L; }
|
const Loop *getLoop() const { return L; }
|
||||||
|
|
||||||
|
|
||||||
/// getStepRecurrence - This method constructs and returns the recurrence
|
/// getStepRecurrence - This method constructs and returns the recurrence
|
||||||
/// indicating how much this expression steps by. If this is a polynomial
|
/// indicating how much this expression steps by. If this is a polynomial
|
||||||
/// of degree N, it returns a chrec of degree N-1.
|
/// of degree N, it returns a chrec of degree N-1.
|
||||||
@@ -404,8 +412,6 @@ namespace llvm {
|
|||||||
|
|
||||||
virtual bool isLoopInvariant(const Loop *QueryLoop) const;
|
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
|
/// 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.
|
/// an expressions A+B*x where A and B are loop invariant values.
|
||||||
bool isAffine() const {
|
bool isAffine() const {
|
||||||
@@ -438,8 +444,6 @@ namespace llvm {
|
|||||||
const SCEVHandle &Conc,
|
const SCEVHandle &Conc,
|
||||||
ScalarEvolution &SE) const;
|
ScalarEvolution &SE) const;
|
||||||
|
|
||||||
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
||||||
|
|
||||||
virtual void print(raw_ostream &OS) const;
|
virtual void print(raw_ostream &OS) const;
|
||||||
|
|
||||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
|||||||
return this;
|
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) {
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
|
||||||
if (!getOperand(i)->dominates(BB, DT))
|
if (!getOperand(i)->dominates(BB, DT))
|
||||||
return false;
|
return false;
|
||||||
@@ -359,15 +359,6 @@ SCEVAddRecExpr::~SCEVAddRecExpr() {
|
|||||||
SCEVAddRecExprs->erase(std::make_pair(L, SCEVOps));
|
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::
|
SCEVHandle SCEVAddRecExpr::
|
||||||
replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
||||||
const SCEVHandle &Conc,
|
const SCEVHandle &Conc,
|
||||||
|
|||||||
Reference in New Issue
Block a user