class SCEVHandle;
class ScalarEvolution;
class TargetData;
+ class SCEVConstant;
+ class SCEVTruncateExpr;
+ class SCEVZeroExtendExpr;
+ class SCEVCommutativeExpr;
+ class SCEVUDivExpr;
+ class SCEVSignExtendExpr;
+ class SCEVAddRecExpr;
+ class SCEVUnknown;
template<> struct DenseMapInfo<SCEVHandle>;
/// SCEV - This class represents an analyzed expression in the program. These
///
class SCEV {
const unsigned SCEVType; // The SCEV baseclass this node corresponds to
- mutable unsigned RefCount;
friend class SCEVHandle;
friend class DenseMapInfo<SCEVHandle>;
- void addRef() const { ++RefCount; }
- void dropRef() const {
- if (--RefCount == 0)
- delete this;
- }
const ScalarEvolution* parent;
virtual ~SCEV();
public:
explicit SCEV(unsigned SCEVTy, const ScalarEvolution* p) :
- SCEVType(SCEVTy), RefCount(0), parent(p) {}
+ SCEVType(SCEVTy), parent(p) {}
unsigned getSCEVType() const { return SCEVType; }
public:
SCEVHandle(const SCEV *s) : S(s) {
assert(S && "Cannot create a handle to a null SCEV!");
- S->addRef();
- }
- SCEVHandle(const SCEVHandle &RHS) : S(RHS.S) {
- S->addRef();
}
- ~SCEVHandle() { S->dropRef(); }
+ SCEVHandle(const SCEVHandle &RHS) : S(RHS.S) { }
+ ~SCEVHandle() { }
operator const SCEV*() const { return S; }
const SCEVHandle &operator=(SCEV *RHS) {
if (S != RHS) {
- S->dropRef();
S = RHS;
- S->addRef();
}
return *this;
}
const SCEVHandle &operator=(const SCEVHandle &RHS) {
if (S != RHS.S) {
- S->dropRef();
S = RHS.S;
- S->addRef();
}
return *this;
}
struct DenseMapInfo<SCEVHandle> {
static inline SCEVHandle getEmptyKey() {
static SCEVCouldNotCompute Empty(0);
- if (Empty.RefCount == 0)
- Empty.addRef();
return &Empty;
}
static inline SCEVHandle getTombstoneKey() {
static SCEVCouldNotCompute Tombstone(0);
- if (Tombstone.RefCount == 0)
- Tombstone.addRef();
return &Tombstone;
}
static unsigned getHashValue(const SCEVHandle &Val) {
void print(std::ostream *OS, const Module* M = 0) const {
if (OS) print(*OS, M);
}
+
+ private:
+ // Uniquing tables.
+ std::map<ConstantInt*, SCEVConstant*> SCEVConstants;
+ std::map<std::pair<const SCEV*, const Type*>,
+ SCEVTruncateExpr*> SCEVTruncates;
+ std::map<std::pair<const SCEV*, const Type*>,
+ SCEVZeroExtendExpr*> SCEVZeroExtends;
+ std::map<std::pair<unsigned, std::vector<const SCEV*> >,
+ SCEVCommutativeExpr*> SCEVCommExprs;
+ std::map<std::pair<const SCEV*, const SCEV*>,
+ SCEVUDivExpr*> SCEVUDivs;
+ std::map<std::pair<const SCEV*, const Type*>,
+ SCEVSignExtendExpr*> SCEVSignExtends;
+ std::map<std::pair<const Loop *, std::vector<const SCEV*> >,
+ SCEVAddRecExpr*> SCEVAddRecExprs;
+ std::map<Value*, SCEVUnknown*> SCEVUnknowns;
};
}
// SCEVConstants - Only allow the creation of one SCEVConstant for any
// particular value. Don't use a SCEVHandle here, or else the object will
// never be deleted!
-static ManagedStatic<std::map<ConstantInt*, SCEVConstant*> > SCEVConstants;
-
-
-SCEVConstant::~SCEVConstant() {
- SCEVConstants->erase(V);
-}
SCEVHandle ScalarEvolution::getConstant(ConstantInt *V) {
- SCEVConstant *&R = (*SCEVConstants)[V];
+ SCEVConstant *&R = SCEVConstants[V];
if (R == 0) R = new SCEVConstant(V, this);
return R;
}
// 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!
-static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
- SCEVTruncateExpr*> > SCEVTruncates;
SCEVTruncateExpr::SCEVTruncateExpr(const SCEVHandle &op, const Type *ty,
const ScalarEvolution* p)
"Cannot truncate non-integer value!");
}
-SCEVTruncateExpr::~SCEVTruncateExpr() {
- SCEVTruncates->erase(std::make_pair(Op, Ty));
-}
void SCEVTruncateExpr::print(raw_ostream &OS) const {
OS << "(trunc " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
// SCEVZeroExtends - Only allow the creation of one SCEVZeroExtendExpr for any
// particular input. Don't use a SCEVHandle here, or else the object will never
// be deleted!
-static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
- SCEVZeroExtendExpr*> > SCEVZeroExtends;
SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty,
const ScalarEvolution* p)
"Cannot zero extend non-integer value!");
}
-SCEVZeroExtendExpr::~SCEVZeroExtendExpr() {
- SCEVZeroExtends->erase(std::make_pair(Op, Ty));
-}
-
void SCEVZeroExtendExpr::print(raw_ostream &OS) const {
OS << "(zext " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
}
// SCEVSignExtends - Only allow the creation of one SCEVSignExtendExpr for any
// particular input. Don't use a SCEVHandle here, or else the object will never
// be deleted!
-static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
- SCEVSignExtendExpr*> > SCEVSignExtends;
SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty,
const ScalarEvolution* p)
"Cannot sign extend non-integer value!");
}
-SCEVSignExtendExpr::~SCEVSignExtendExpr() {
- SCEVSignExtends->erase(std::make_pair(Op, Ty));
-}
-
void SCEVSignExtendExpr::print(raw_ostream &OS) const {
OS << "(sext " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
}
// SCEVCommExprs - Only allow the creation of one SCEVCommutativeExpr for any
// particular input. Don't use a SCEVHandle here, or else the object will never
// be deleted!
-static ManagedStatic<std::map<std::pair<unsigned, std::vector<const SCEV*> >,
- SCEVCommutativeExpr*> > SCEVCommExprs;
-
-SCEVCommutativeExpr::~SCEVCommutativeExpr() {
- std::vector<const SCEV*> SCEVOps(Operands.begin(), Operands.end());
- SCEVCommExprs->erase(std::make_pair(getSCEVType(), SCEVOps));
-}
void SCEVCommutativeExpr::print(raw_ostream &OS) const {
assert(Operands.size() > 1 && "This plus expr shouldn't exist!");
// SCEVUDivs - Only allow the creation of one SCEVUDivExpr for any particular
// input. Don't use a SCEVHandle here, or else the object will never be
// deleted!
-static ManagedStatic<std::map<std::pair<const SCEV*, const SCEV*>,
- SCEVUDivExpr*> > SCEVUDivs;
-
-SCEVUDivExpr::~SCEVUDivExpr() {
- SCEVUDivs->erase(std::make_pair(LHS, RHS));
-}
bool SCEVUDivExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
return LHS->dominates(BB, DT) && RHS->dominates(BB, DT);
// SCEVAddRecExprs - Only allow the creation of one SCEVAddRecExpr for any
// particular input. Don't use a SCEVHandle here, or else the object will never
// be deleted!
-static ManagedStatic<std::map<std::pair<const Loop *,
- std::vector<const SCEV*> >,
- SCEVAddRecExpr*> > SCEVAddRecExprs;
-
-SCEVAddRecExpr::~SCEVAddRecExpr() {
- std::vector<const SCEV*> SCEVOps(Operands.begin(), Operands.end());
- SCEVAddRecExprs->erase(std::make_pair(L, SCEVOps));
-}
SCEVHandle SCEVAddRecExpr::
replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
// SCEVUnknowns - Only allow the creation of one SCEVUnknown for any particular
// value. Don't use a SCEVHandle here, or else the object will never be
// deleted!
-static ManagedStatic<std::map<Value*, SCEVUnknown*> > SCEVUnknowns;
-
-SCEVUnknown::~SCEVUnknown() { SCEVUnknowns->erase(V); }
bool SCEVUnknown::isLoopInvariant(const Loop *L) const {
// All non-instruction values are loop invariant. All instructions are loop
return getAddRecExpr(Operands, AddRec->getLoop());
}
- SCEVTruncateExpr *&Result = (*SCEVTruncates)[std::make_pair(Op, Ty)];
+ SCEVTruncateExpr *&Result = SCEVTruncates[std::make_pair(Op, Ty)];
if (Result == 0) Result = new SCEVTruncateExpr(Op, Ty, this);
return Result;
}
}
}
- SCEVZeroExtendExpr *&Result = (*SCEVZeroExtends)[std::make_pair(Op, Ty)];
+ SCEVZeroExtendExpr *&Result = SCEVZeroExtends[std::make_pair(Op, Ty)];
if (Result == 0) Result = new SCEVZeroExtendExpr(Op, Ty, this);
return Result;
}
}
}
- SCEVSignExtendExpr *&Result = (*SCEVSignExtends)[std::make_pair(Op, Ty)];
+ SCEVSignExtendExpr *&Result = SCEVSignExtends[std::make_pair(Op, Ty)];
if (Result == 0) Result = new SCEVSignExtendExpr(Op, Ty, this);
return Result;
}
// Okay, it looks like we really DO need an add expr. Check to see if we
// already have one, otherwise create a new one.
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
- SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scAddExpr,
+ SCEVCommutativeExpr *&Result = SCEVCommExprs[std::make_pair(scAddExpr,
SCEVOps)];
if (Result == 0) Result = new SCEVAddExpr(Ops, this);
return Result;
// Okay, it looks like we really DO need an mul expr. Check to see if we
// already have one, otherwise create a new one.
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
- SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scMulExpr,
+ SCEVCommutativeExpr *&Result = SCEVCommExprs[std::make_pair(scMulExpr,
SCEVOps)];
if (Result == 0)
Result = new SCEVMulExpr(Ops, this);
}
}
- SCEVUDivExpr *&Result = (*SCEVUDivs)[std::make_pair(LHS, RHS)];
+ SCEVUDivExpr *&Result = SCEVUDivs[std::make_pair(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)];
+ SCEVAddRecExpr *&Result = SCEVAddRecExprs[std::make_pair(L, SCEVOps)];
if (Result == 0) Result = new SCEVAddRecExpr(Operands, L, this);
return Result;
}
// Okay, it looks like we really DO need an smax expr. Check to see if we
// already have one, otherwise create a new one.
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
- SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scSMaxExpr,
+ SCEVCommutativeExpr *&Result = SCEVCommExprs[std::make_pair(scSMaxExpr,
SCEVOps)];
if (Result == 0) Result = new SCEVSMaxExpr(Ops, this);
return Result;
// Okay, it looks like we really DO need a umax expr. Check to see if we
// already have one, otherwise create a new one.
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
- SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scUMaxExpr,
+ SCEVCommutativeExpr *&Result = SCEVCommExprs[std::make_pair(scUMaxExpr,
SCEVOps)];
if (Result == 0) Result = new SCEVUMaxExpr(Ops, this);
return Result;
return getConstant(CI);
if (isa<ConstantPointerNull>(V))
return getIntegerSCEV(0, V->getType());
- SCEVUnknown *&Result = (*SCEVUnknowns)[V];
+ SCEVUnknown *&Result = SCEVUnknowns[V];
if (Result == 0) Result = new SCEVUnknown(V, this);
return Result;
}
BackedgeTakenCounts.clear();
ConstantEvolutionLoopExitValue.clear();
ValuesAtScopes.clear();
+
+ for (std::map<ConstantInt*, SCEVConstant*>::iterator
+ I = SCEVConstants.begin(), E = SCEVConstants.end(); I != E; ++I)
+ delete I->second;
+ for (std::map<std::pair<const SCEV*, const Type*>,
+ SCEVTruncateExpr*>::iterator I = SCEVTruncates.begin(),
+ E = SCEVTruncates.end(); I != E; ++I)
+ delete I->second;
+ for (std::map<std::pair<const SCEV*, const Type*>,
+ SCEVZeroExtendExpr*>::iterator I = SCEVZeroExtends.begin(),
+ E = SCEVZeroExtends.end(); I != E; ++I)
+ delete I->second;
+ for (std::map<std::pair<unsigned, std::vector<const SCEV*> >,
+ SCEVCommutativeExpr*>::iterator I = SCEVCommExprs.begin(),
+ E = SCEVCommExprs.end(); I != E; ++I)
+ delete I->second;
+ for (std::map<std::pair<const SCEV*, const SCEV*>, SCEVUDivExpr*>::iterator
+ I = SCEVUDivs.begin(), E = SCEVUDivs.end(); I != E; ++I)
+ delete I->second;
+ for (std::map<std::pair<const SCEV*, const Type*>,
+ SCEVSignExtendExpr*>::iterator I = SCEVSignExtends.begin(),
+ E = SCEVSignExtends.end(); I != E; ++I)
+ delete I->second;
+ for (std::map<std::pair<const Loop *, std::vector<const SCEV*> >,
+ SCEVAddRecExpr*>::iterator I = SCEVAddRecExprs.begin(),
+ E = SCEVAddRecExprs.end(); I != E; ++I)
+ delete I->second;
+ for (std::map<Value*, SCEVUnknown*>::iterator I = SCEVUnknowns.begin(),
+ E = SCEVUnknowns.end(); I != E; ++I)
+ delete I->second;
+
+ SCEVConstants.clear();
+ SCEVTruncates.clear();
+ SCEVZeroExtends.clear();
+ SCEVCommExprs.clear();
+ SCEVUDivs.clear();
+ SCEVSignExtends.clear();
+ SCEVAddRecExprs.clear();
+ SCEVUnknowns.clear();
}
void ScalarEvolution::getAnalysisUsage(AnalysisUsage &AU) const {