Add a parent pointer to SCEV, in preparation for getting rid of the global uniquing tables. No functionality change.

llvm-svn: 73728
This commit is contained in:
Owen Anderson 2009-06-18 22:25:12 +00:00
parent 32270cc78e
commit 38830b19e9
3 changed files with 70 additions and 47 deletions

View File

@ -53,12 +53,15 @@ namespace llvm {
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; }
@ -126,7 +129,7 @@ namespace llvm {
/// 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.
@ -205,13 +208,13 @@ namespace llvm {
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;

View File

@ -36,7 +36,8 @@ namespace llvm {
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:
@ -79,7 +80,8 @@ namespace llvm {
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:
@ -112,7 +114,8 @@ namespace llvm {
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:
@ -141,7 +144,8 @@ namespace llvm {
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:
@ -170,7 +174,8 @@ namespace llvm {
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:
@ -201,8 +206,9 @@ namespace llvm {
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:
@ -259,8 +265,10 @@ namespace llvm {
///
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:
@ -289,8 +297,9 @@ namespace llvm {
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:
@ -309,8 +318,9 @@ namespace llvm {
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:
@ -331,8 +341,9 @@ namespace llvm {
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:
@ -387,8 +398,9 @@ namespace llvm {
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!");
@ -463,8 +475,9 @@ namespace llvm {
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:
@ -484,8 +497,9 @@ namespace llvm {
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:
@ -508,7 +522,8 @@ namespace llvm {
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();

View File

@ -133,7 +133,8 @@ bool SCEV::isOne() const {
return false;
}
SCEVCouldNotCompute::SCEVCouldNotCompute() : SCEV(scCouldNotCompute) {}
SCEVCouldNotCompute::SCEVCouldNotCompute(const ScalarEvolution* p) :
SCEV(scCouldNotCompute, p) {}
SCEVCouldNotCompute::~SCEVCouldNotCompute() {}
bool SCEVCouldNotCompute::isLoopInvariant(const Loop *L) const {
@ -179,7 +180,7 @@ SCEVConstant::~SCEVConstant() {
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;
}
@ -199,8 +200,9 @@ void SCEVConstant::print(raw_ostream &OS) const {
}
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() {}
@ -214,8 +216,9 @@ bool SCEVCastExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
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!");
@ -235,8 +238,9 @@ void SCEVTruncateExpr::print(raw_ostream &OS) const {
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!");
@ -256,8 +260,9 @@ void SCEVZeroExtendExpr::print(raw_ostream &OS) const {
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!");
@ -787,7 +792,7 @@ SCEVHandle ScalarEvolution::getTruncateExpr(const SCEVHandle &Op,
}
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;
}
@ -875,7 +880,7 @@ SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op,
}
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;
}
@ -947,7 +952,7 @@ SCEVHandle ScalarEvolution::getSignExtendExpr(const SCEVHandle &Op,
}
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;
}
@ -1409,7 +1414,7 @@ SCEVHandle ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVHandle> &Ops) {
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;
}
@ -1575,7 +1580,7 @@ SCEVHandle ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVHandle> &Ops) {
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scMulExpr,
SCEVOps)];
if (Result == 0)
Result = new SCEVMulExpr(Ops);
Result = new SCEVMulExpr(Ops, this);
return Result;
}
@ -1666,7 +1671,7 @@ SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS,
}
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;
}
@ -1720,7 +1725,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVHandle> &Operands,
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;
}
@ -1807,7 +1812,7 @@ ScalarEvolution::getSMaxExpr(SmallVectorImpl<SCEVHandle> &Ops) {
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;
}
@ -1894,7 +1899,7 @@ ScalarEvolution::getUMaxExpr(SmallVectorImpl<SCEVHandle> &Ops) {
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;
}
@ -1904,7 +1909,7 @@ SCEVHandle ScalarEvolution::getUnknown(Value *V) {
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;
}
@ -3978,7 +3983,7 @@ ScalarEvolution::SCEVCallbackVH::SCEVCallbackVH(Value *V, ScalarEvolution *se)
//===----------------------------------------------------------------------===//
ScalarEvolution::ScalarEvolution()
: FunctionPass(&ID), CouldNotCompute(new SCEVCouldNotCompute()) {
: FunctionPass(&ID), CouldNotCompute(new SCEVCouldNotCompute(0)) {
}
bool ScalarEvolution::runOnFunction(Function &F) {