delete this;
}
+ const ScalarEvolution* parent;
+
SCEV(const SCEV &); // DO NOT IMPLEMENT
void operator=(const SCEV &); // DO NOT IMPLEMENT
protected:
virtual ~SCEV();
public:
- explicit SCEV(unsigned SCEVTy) : SCEVType(SCEVTy), RefCount(0) {}
+ explicit SCEV(unsigned SCEVTy, const ScalarEvolution* p) :
+ SCEVType(SCEVTy), RefCount(0), parent(p) {}
unsigned getSCEVType() const { return SCEVType; }
/// None of the standard SCEV operations are valid on this class, it is just a
/// marker.
struct SCEVCouldNotCompute : public SCEV {
- SCEVCouldNotCompute();
+ SCEVCouldNotCompute(const ScalarEvolution* p);
~SCEVCouldNotCompute();
// None of these methods are valid for this object.
template<>
struct DenseMapInfo<SCEVHandle> {
static inline SCEVHandle getEmptyKey() {
- static SCEVCouldNotCompute Empty;
+ static SCEVCouldNotCompute Empty(0);
if (Empty.RefCount == 0)
Empty.addRef();
return &Empty;
}
static inline SCEVHandle getTombstoneKey() {
- static SCEVCouldNotCompute Tombstone;
+ static SCEVCouldNotCompute Tombstone(0);
if (Tombstone.RefCount == 0)
Tombstone.addRef();
return &Tombstone;
friend class ScalarEvolution;
ConstantInt *V;
- explicit SCEVConstant(ConstantInt *v) : SCEV(scConstant), V(v) {}
+ explicit SCEVConstant(ConstantInt *v, const ScalarEvolution* p) :
+ SCEV(scConstant, p), V(v) {}
virtual ~SCEVConstant();
public:
SCEVHandle Op;
const Type *Ty;
- SCEVCastExpr(unsigned SCEVTy, const SCEVHandle &op, const Type *ty);
+ SCEVCastExpr(unsigned SCEVTy, const SCEVHandle &op, const Type *ty,
+ const ScalarEvolution* p);
virtual ~SCEVCastExpr();
public:
class SCEVTruncateExpr : public SCEVCastExpr {
friend class ScalarEvolution;
- SCEVTruncateExpr(const SCEVHandle &op, const Type *ty);
+ SCEVTruncateExpr(const SCEVHandle &op, const Type *ty,
+ const ScalarEvolution* p);
virtual ~SCEVTruncateExpr();
public:
class SCEVZeroExtendExpr : public SCEVCastExpr {
friend class ScalarEvolution;
- SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty);
+ SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty,
+ const ScalarEvolution* p);
virtual ~SCEVZeroExtendExpr();
public:
class SCEVSignExtendExpr : public SCEVCastExpr {
friend class ScalarEvolution;
- SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty);
+ SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty,
+ const ScalarEvolution* p);
virtual ~SCEVSignExtendExpr();
public:
protected:
SmallVector<SCEVHandle, 8> Operands;
- SCEVNAryExpr(enum SCEVTypes T, const SmallVectorImpl<SCEVHandle> &ops)
- : SCEV(T), Operands(ops.begin(), ops.end()) {}
+ SCEVNAryExpr(enum SCEVTypes T, const SmallVectorImpl<SCEVHandle> &ops,
+ const ScalarEvolution* p)
+ : SCEV(T, p), Operands(ops.begin(), ops.end()) {}
virtual ~SCEVNAryExpr() {}
public:
///
class SCEVCommutativeExpr : public SCEVNAryExpr {
protected:
- SCEVCommutativeExpr(enum SCEVTypes T, const SmallVectorImpl<SCEVHandle> &ops)
- : SCEVNAryExpr(T, ops) {}
+ SCEVCommutativeExpr(enum SCEVTypes T,
+ const SmallVectorImpl<SCEVHandle> &ops,
+ const ScalarEvolution* p)
+ : SCEVNAryExpr(T, ops, p) {}
~SCEVCommutativeExpr();
public:
class SCEVAddExpr : public SCEVCommutativeExpr {
friend class ScalarEvolution;
- explicit SCEVAddExpr(const SmallVectorImpl<SCEVHandle> &ops)
- : SCEVCommutativeExpr(scAddExpr, ops) {
+ explicit SCEVAddExpr(const SmallVectorImpl<SCEVHandle> &ops,
+ const ScalarEvolution* p)
+ : SCEVCommutativeExpr(scAddExpr, ops, p) {
}
public:
class SCEVMulExpr : public SCEVCommutativeExpr {
friend class ScalarEvolution;
- explicit SCEVMulExpr(const SmallVectorImpl<SCEVHandle> &ops)
- : SCEVCommutativeExpr(scMulExpr, ops) {
+ explicit SCEVMulExpr(const SmallVectorImpl<SCEVHandle> &ops,
+ const ScalarEvolution* p)
+ : SCEVCommutativeExpr(scMulExpr, ops, p) {
}
public:
friend class ScalarEvolution;
SCEVHandle LHS, RHS;
- SCEVUDivExpr(const SCEVHandle &lhs, const SCEVHandle &rhs)
- : SCEV(scUDivExpr), LHS(lhs), RHS(rhs) {}
+ SCEVUDivExpr(const SCEVHandle &lhs, const SCEVHandle &rhs,
+ const ScalarEvolution* p)
+ : SCEV(scUDivExpr, p), LHS(lhs), RHS(rhs) {}
virtual ~SCEVUDivExpr();
public:
const Loop *L;
- SCEVAddRecExpr(const SmallVectorImpl<SCEVHandle> &ops, const Loop *l)
- : SCEVNAryExpr(scAddRecExpr, ops), L(l) {
+ SCEVAddRecExpr(const SmallVectorImpl<SCEVHandle> &ops, const Loop *l,
+ const ScalarEvolution* p)
+ : SCEVNAryExpr(scAddRecExpr, ops, p), 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!");
class SCEVSMaxExpr : public SCEVCommutativeExpr {
friend class ScalarEvolution;
- explicit SCEVSMaxExpr(const SmallVectorImpl<SCEVHandle> &ops)
- : SCEVCommutativeExpr(scSMaxExpr, ops) {
+ explicit SCEVSMaxExpr(const SmallVectorImpl<SCEVHandle> &ops,
+ const ScalarEvolution* p)
+ : SCEVCommutativeExpr(scSMaxExpr, ops, p) {
}
public:
class SCEVUMaxExpr : public SCEVCommutativeExpr {
friend class ScalarEvolution;
- explicit SCEVUMaxExpr(const SmallVectorImpl<SCEVHandle> &ops)
- : SCEVCommutativeExpr(scUMaxExpr, ops) {
+ explicit SCEVUMaxExpr(const SmallVectorImpl<SCEVHandle> &ops,
+ const ScalarEvolution* p)
+ : SCEVCommutativeExpr(scUMaxExpr, ops, p) {
}
public:
friend class ScalarEvolution;
Value *V;
- explicit SCEVUnknown(Value *v) : SCEV(scUnknown), V(v) {}
+ explicit SCEVUnknown(Value *v, const ScalarEvolution* p) :
+ SCEV(scUnknown, p), V(v) {}
protected:
~SCEVUnknown();
return false;
}
-SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {}
+SCEVCouldNotCompute::SCEVCouldNotCompute(const ScalarEvolution* p) :
+ SCEV(scCouldNotCompute, p) {}
SCEVCouldNotCompute::~SCEVCouldNotCompute() {}
bool SCEVCouldNotCompute::isLoopInvariant(const Loop *L) const {
SCEVHandle ScalarEvolution::getConstant(ConstantInt *V) {
SCEVConstant *&R = (*SCEVConstants)[V];
- if (R == 0) R = new SCEVConstant(V);
+ if (R == 0) R = new SCEVConstant(V, this);
return R;
}
}
SCEVCastExpr::SCEVCastExpr(unsigned SCEVTy,
- const SCEVHandle &op, const Type *ty)
- : SCEV(SCEVTy), Op(op), Ty(ty) {}
+ const SCEVHandle &op, const Type *ty,
+ const ScalarEvolution* p)
+ : SCEV(SCEVTy, p), Op(op), Ty(ty) {}
SCEVCastExpr::~SCEVCastExpr() {}
static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
SCEVTruncateExpr*> > SCEVTruncates;
-SCEVTruncateExpr::SCEVTruncateExpr(const SCEVHandle &op, const Type *ty)
- : SCEVCastExpr(scTruncate, op, ty) {
+SCEVTruncateExpr::SCEVTruncateExpr(const SCEVHandle &op, const Type *ty,
+ const ScalarEvolution* p)
+ : SCEVCastExpr(scTruncate, op, ty, p) {
assert((Op->getType()->isInteger() || isa<PointerType>(Op->getType())) &&
(Ty->isInteger() || isa<PointerType>(Ty)) &&
"Cannot truncate non-integer value!");
static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
SCEVZeroExtendExpr*> > SCEVZeroExtends;
-SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty)
- : SCEVCastExpr(scZeroExtend, op, ty) {
+SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty,
+ const ScalarEvolution* p)
+ : SCEVCastExpr(scZeroExtend, op, ty, p) {
assert((Op->getType()->isInteger() || isa<PointerType>(Op->getType())) &&
(Ty->isInteger() || isa<PointerType>(Ty)) &&
"Cannot zero extend non-integer value!");
static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
SCEVSignExtendExpr*> > SCEVSignExtends;
-SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty)
- : SCEVCastExpr(scSignExtend, op, ty) {
+SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty,
+ const ScalarEvolution* p)
+ : SCEVCastExpr(scSignExtend, op, ty, p) {
assert((Op->getType()->isInteger() || isa<PointerType>(Op->getType())) &&
(Ty->isInteger() || isa<PointerType>(Ty)) &&
"Cannot sign extend non-integer value!");
}
SCEVTruncateExpr *&Result = (*SCEVTruncates)[std::make_pair(Op, Ty)];
- if (Result == 0) Result = new SCEVTruncateExpr(Op, Ty);
+ if (Result == 0) Result = new SCEVTruncateExpr(Op, Ty, this);
return Result;
}
}
SCEVZeroExtendExpr *&Result = (*SCEVZeroExtends)[std::make_pair(Op, Ty)];
- if (Result == 0) Result = new SCEVZeroExtendExpr(Op, Ty);
+ if (Result == 0) Result = new SCEVZeroExtendExpr(Op, Ty, this);
return Result;
}
}
SCEVSignExtendExpr *&Result = (*SCEVSignExtends)[std::make_pair(Op, Ty)];
- if (Result == 0) Result = new SCEVSignExtendExpr(Op, Ty);
+ if (Result == 0) Result = new SCEVSignExtendExpr(Op, Ty, this);
return Result;
}
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scAddExpr,
SCEVOps)];
- if (Result == 0) Result = new SCEVAddExpr(Ops);
+ if (Result == 0) Result = new SCEVAddExpr(Ops, this);
return Result;
}
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scMulExpr,
SCEVOps)];
if (Result == 0)
- Result = new SCEVMulExpr(Ops);
+ Result = new SCEVMulExpr(Ops, this);
return Result;
}
}
SCEVUDivExpr *&Result = (*SCEVUDivs)[std::make_pair(LHS, RHS)];
- if (Result == 0) Result = new SCEVUDivExpr(LHS, RHS);
+ if (Result == 0) Result = new SCEVUDivExpr(LHS, RHS, this);
return Result;
}
std::vector<const SCEV*> SCEVOps(Operands.begin(), Operands.end());
SCEVAddRecExpr *&Result = (*SCEVAddRecExprs)[std::make_pair(L, SCEVOps)];
- if (Result == 0) Result = new SCEVAddRecExpr(Operands, L);
+ if (Result == 0) Result = new SCEVAddRecExpr(Operands, L, this);
return Result;
}
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scSMaxExpr,
SCEVOps)];
- if (Result == 0) Result = new SCEVSMaxExpr(Ops);
+ if (Result == 0) Result = new SCEVSMaxExpr(Ops, this);
return Result;
}
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scUMaxExpr,
SCEVOps)];
- if (Result == 0) Result = new SCEVUMaxExpr(Ops);
+ if (Result == 0) Result = new SCEVUMaxExpr(Ops, this);
return Result;
}
if (isa<ConstantPointerNull>(V))
return getIntegerSCEV(0, V->getType());
SCEVUnknown *&Result = (*SCEVUnknowns)[V];
- if (Result == 0) Result = new SCEVUnknown(V);
+ if (Result == 0) Result = new SCEVUnknown(V, this);
return Result;
}
//===----------------------------------------------------------------------===//
ScalarEvolution::ScalarEvolution()
- : FunctionPass(&ID), CouldNotCompute(new SCEVCouldNotCompute()) {
+ : FunctionPass(&ID), CouldNotCompute(new SCEVCouldNotCompute(0)) {
}
bool ScalarEvolution::runOnFunction(Function &F) {