mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-01 02:33:44 +00:00
Banish global state from ScalarEvolution! SCEV uniquing is now done by tables attached to the ScalarEvolution pass.
This also throws out the SCEV reference counting scheme, as the the SCEVs now have a lifetime controlled by the ScalarEvolution pass. Note that SCEVHandle is now a no-op, and will be remove in a future commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73892 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
75d6ffd53f
commit
08367b6163
@ -35,6 +35,14 @@ namespace llvm {
|
|||||||
class SCEVHandle;
|
class SCEVHandle;
|
||||||
class ScalarEvolution;
|
class ScalarEvolution;
|
||||||
class TargetData;
|
class TargetData;
|
||||||
|
class SCEVConstant;
|
||||||
|
class SCEVTruncateExpr;
|
||||||
|
class SCEVZeroExtendExpr;
|
||||||
|
class SCEVCommutativeExpr;
|
||||||
|
class SCEVUDivExpr;
|
||||||
|
class SCEVSignExtendExpr;
|
||||||
|
class SCEVAddRecExpr;
|
||||||
|
class SCEVUnknown;
|
||||||
template<> struct DenseMapInfo<SCEVHandle>;
|
template<> struct DenseMapInfo<SCEVHandle>;
|
||||||
|
|
||||||
/// SCEV - This class represents an analyzed expression in the program. These
|
/// SCEV - This class represents an analyzed expression in the program. These
|
||||||
@ -43,15 +51,9 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
class SCEV {
|
class SCEV {
|
||||||
const unsigned SCEVType; // The SCEV baseclass this node corresponds to
|
const unsigned SCEVType; // The SCEV baseclass this node corresponds to
|
||||||
mutable unsigned RefCount;
|
|
||||||
|
|
||||||
friend class SCEVHandle;
|
friend class SCEVHandle;
|
||||||
friend class DenseMapInfo<SCEVHandle>;
|
friend class DenseMapInfo<SCEVHandle>;
|
||||||
void addRef() const { ++RefCount; }
|
|
||||||
void dropRef() const {
|
|
||||||
if (--RefCount == 0)
|
|
||||||
delete this;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ScalarEvolution* parent;
|
const ScalarEvolution* parent;
|
||||||
|
|
||||||
@ -61,7 +63,7 @@ namespace llvm {
|
|||||||
virtual ~SCEV();
|
virtual ~SCEV();
|
||||||
public:
|
public:
|
||||||
explicit SCEV(unsigned SCEVTy, const ScalarEvolution* p) :
|
explicit SCEV(unsigned SCEVTy, const ScalarEvolution* p) :
|
||||||
SCEVType(SCEVTy), RefCount(0), parent(p) {}
|
SCEVType(SCEVTy), parent(p) {}
|
||||||
|
|
||||||
unsigned getSCEVType() const { return SCEVType; }
|
unsigned getSCEVType() const { return SCEVType; }
|
||||||
|
|
||||||
@ -159,12 +161,9 @@ namespace llvm {
|
|||||||
public:
|
public:
|
||||||
SCEVHandle(const SCEV *s) : S(s) {
|
SCEVHandle(const SCEV *s) : S(s) {
|
||||||
assert(S && "Cannot create a handle to a null SCEV!");
|
assert(S && "Cannot create a handle to a null SCEV!");
|
||||||
S->addRef();
|
|
||||||
}
|
}
|
||||||
SCEVHandle(const SCEVHandle &RHS) : S(RHS.S) {
|
SCEVHandle(const SCEVHandle &RHS) : S(RHS.S) { }
|
||||||
S->addRef();
|
~SCEVHandle() { }
|
||||||
}
|
|
||||||
~SCEVHandle() { S->dropRef(); }
|
|
||||||
|
|
||||||
operator const SCEV*() const { return S; }
|
operator const SCEV*() const { return S; }
|
||||||
|
|
||||||
@ -176,18 +175,14 @@ namespace llvm {
|
|||||||
|
|
||||||
const SCEVHandle &operator=(SCEV *RHS) {
|
const SCEVHandle &operator=(SCEV *RHS) {
|
||||||
if (S != RHS) {
|
if (S != RHS) {
|
||||||
S->dropRef();
|
|
||||||
S = RHS;
|
S = RHS;
|
||||||
S->addRef();
|
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SCEVHandle &operator=(const SCEVHandle &RHS) {
|
const SCEVHandle &operator=(const SCEVHandle &RHS) {
|
||||||
if (S != RHS.S) {
|
if (S != RHS.S) {
|
||||||
S->dropRef();
|
|
||||||
S = RHS.S;
|
S = RHS.S;
|
||||||
S->addRef();
|
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -209,14 +204,10 @@ namespace llvm {
|
|||||||
struct DenseMapInfo<SCEVHandle> {
|
struct DenseMapInfo<SCEVHandle> {
|
||||||
static inline SCEVHandle getEmptyKey() {
|
static inline SCEVHandle getEmptyKey() {
|
||||||
static SCEVCouldNotCompute Empty(0);
|
static SCEVCouldNotCompute Empty(0);
|
||||||
if (Empty.RefCount == 0)
|
|
||||||
Empty.addRef();
|
|
||||||
return &Empty;
|
return &Empty;
|
||||||
}
|
}
|
||||||
static inline SCEVHandle getTombstoneKey() {
|
static inline SCEVHandle getTombstoneKey() {
|
||||||
static SCEVCouldNotCompute Tombstone(0);
|
static SCEVCouldNotCompute Tombstone(0);
|
||||||
if (Tombstone.RefCount == 0)
|
|
||||||
Tombstone.addRef();
|
|
||||||
return &Tombstone;
|
return &Tombstone;
|
||||||
}
|
}
|
||||||
static unsigned getHashValue(const SCEVHandle &Val) {
|
static unsigned getHashValue(const SCEVHandle &Val) {
|
||||||
@ -639,6 +630,23 @@ namespace llvm {
|
|||||||
void print(std::ostream *OS, const Module* M = 0) const {
|
void print(std::ostream *OS, const Module* M = 0) const {
|
||||||
if (OS) print(*OS, M);
|
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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,6 @@ namespace llvm {
|
|||||||
ConstantInt *V;
|
ConstantInt *V;
|
||||||
explicit SCEVConstant(ConstantInt *v, const ScalarEvolution* p) :
|
explicit SCEVConstant(ConstantInt *v, const ScalarEvolution* p) :
|
||||||
SCEV(scConstant, p), V(v) {}
|
SCEV(scConstant, p), V(v) {}
|
||||||
|
|
||||||
virtual ~SCEVConstant();
|
|
||||||
public:
|
public:
|
||||||
ConstantInt *getValue() const { return V; }
|
ConstantInt *getValue() const { return V; }
|
||||||
|
|
||||||
@ -116,7 +114,6 @@ namespace llvm {
|
|||||||
|
|
||||||
SCEVTruncateExpr(const SCEVHandle &op, const Type *ty,
|
SCEVTruncateExpr(const SCEVHandle &op, const Type *ty,
|
||||||
const ScalarEvolution* p);
|
const ScalarEvolution* p);
|
||||||
virtual ~SCEVTruncateExpr();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
||||||
@ -146,7 +143,6 @@ namespace llvm {
|
|||||||
|
|
||||||
SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty,
|
SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty,
|
||||||
const ScalarEvolution* p);
|
const ScalarEvolution* p);
|
||||||
virtual ~SCEVZeroExtendExpr();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
||||||
@ -176,7 +172,6 @@ namespace llvm {
|
|||||||
|
|
||||||
SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty,
|
SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty,
|
||||||
const ScalarEvolution* p);
|
const ScalarEvolution* p);
|
||||||
virtual ~SCEVSignExtendExpr();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
||||||
@ -269,7 +264,6 @@ namespace llvm {
|
|||||||
const SmallVectorImpl<SCEVHandle> &ops,
|
const SmallVectorImpl<SCEVHandle> &ops,
|
||||||
const ScalarEvolution* p)
|
const ScalarEvolution* p)
|
||||||
: SCEVNAryExpr(T, ops, p) {}
|
: SCEVNAryExpr(T, ops, p) {}
|
||||||
~SCEVCommutativeExpr();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
||||||
@ -345,7 +339,6 @@ namespace llvm {
|
|||||||
const ScalarEvolution* p)
|
const ScalarEvolution* p)
|
||||||
: SCEV(scUDivExpr, p), LHS(lhs), RHS(rhs) {}
|
: SCEV(scUDivExpr, p), LHS(lhs), RHS(rhs) {}
|
||||||
|
|
||||||
virtual ~SCEVUDivExpr();
|
|
||||||
public:
|
public:
|
||||||
const SCEVHandle &getLHS() const { return LHS; }
|
const SCEVHandle &getLHS() const { return LHS; }
|
||||||
const SCEVHandle &getRHS() const { return RHS; }
|
const SCEVHandle &getRHS() const { return RHS; }
|
||||||
@ -405,7 +398,6 @@ namespace llvm {
|
|||||||
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();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const SCEVHandle &getStart() const { return Operands[0]; }
|
const SCEVHandle &getStart() const { return Operands[0]; }
|
||||||
@ -525,8 +517,6 @@ namespace llvm {
|
|||||||
explicit SCEVUnknown(Value *v, const ScalarEvolution* p) :
|
explicit SCEVUnknown(Value *v, const ScalarEvolution* p) :
|
||||||
SCEV(scUnknown, p), V(v) {}
|
SCEV(scUnknown, p), V(v) {}
|
||||||
|
|
||||||
protected:
|
|
||||||
~SCEVUnknown();
|
|
||||||
public:
|
public:
|
||||||
Value *getValue() const { return V; }
|
Value *getValue() const { return V; }
|
||||||
|
|
||||||
|
@ -171,15 +171,9 @@ bool SCEVCouldNotCompute::classof(const SCEV *S) {
|
|||||||
// SCEVConstants - Only allow the creation of one SCEVConstant for any
|
// SCEVConstants - Only allow the creation of one SCEVConstant for any
|
||||||
// particular value. Don't use a SCEVHandle here, or else the object will
|
// particular value. Don't use a SCEVHandle here, or else the object will
|
||||||
// never be deleted!
|
// never be deleted!
|
||||||
static ManagedStatic<std::map<ConstantInt*, SCEVConstant*> > SCEVConstants;
|
|
||||||
|
|
||||||
|
|
||||||
SCEVConstant::~SCEVConstant() {
|
|
||||||
SCEVConstants->erase(V);
|
|
||||||
}
|
|
||||||
|
|
||||||
SCEVHandle ScalarEvolution::getConstant(ConstantInt *V) {
|
SCEVHandle ScalarEvolution::getConstant(ConstantInt *V) {
|
||||||
SCEVConstant *&R = (*SCEVConstants)[V];
|
SCEVConstant *&R = SCEVConstants[V];
|
||||||
if (R == 0) R = new SCEVConstant(V, this);
|
if (R == 0) R = new SCEVConstant(V, this);
|
||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
@ -213,8 +207,6 @@ bool SCEVCastExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
|
|||||||
// SCEVTruncates - Only allow the creation of one SCEVTruncateExpr for any
|
// SCEVTruncates - Only allow the creation of one SCEVTruncateExpr for any
|
||||||
// particular input. Don't use a SCEVHandle here, or else the object will
|
// particular input. Don't use a SCEVHandle here, or else the object will
|
||||||
// never be deleted!
|
// never be deleted!
|
||||||
static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
|
|
||||||
SCEVTruncateExpr*> > SCEVTruncates;
|
|
||||||
|
|
||||||
SCEVTruncateExpr::SCEVTruncateExpr(const SCEVHandle &op, const Type *ty,
|
SCEVTruncateExpr::SCEVTruncateExpr(const SCEVHandle &op, const Type *ty,
|
||||||
const ScalarEvolution* p)
|
const ScalarEvolution* p)
|
||||||
@ -224,9 +216,6 @@ SCEVTruncateExpr::SCEVTruncateExpr(const SCEVHandle &op, const Type *ty,
|
|||||||
"Cannot truncate non-integer value!");
|
"Cannot truncate non-integer value!");
|
||||||
}
|
}
|
||||||
|
|
||||||
SCEVTruncateExpr::~SCEVTruncateExpr() {
|
|
||||||
SCEVTruncates->erase(std::make_pair(Op, Ty));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SCEVTruncateExpr::print(raw_ostream &OS) const {
|
void SCEVTruncateExpr::print(raw_ostream &OS) const {
|
||||||
OS << "(trunc " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
|
OS << "(trunc " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
|
||||||
@ -235,8 +224,6 @@ void SCEVTruncateExpr::print(raw_ostream &OS) const {
|
|||||||
// SCEVZeroExtends - Only allow the creation of one SCEVZeroExtendExpr for any
|
// SCEVZeroExtends - Only allow the creation of one SCEVZeroExtendExpr for any
|
||||||
// particular input. Don't use a SCEVHandle here, or else the object will never
|
// particular input. Don't use a SCEVHandle here, or else the object will never
|
||||||
// be deleted!
|
// be deleted!
|
||||||
static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
|
|
||||||
SCEVZeroExtendExpr*> > SCEVZeroExtends;
|
|
||||||
|
|
||||||
SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty,
|
SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty,
|
||||||
const ScalarEvolution* p)
|
const ScalarEvolution* p)
|
||||||
@ -246,10 +233,6 @@ SCEVZeroExtendExpr::SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty,
|
|||||||
"Cannot zero extend non-integer value!");
|
"Cannot zero extend non-integer value!");
|
||||||
}
|
}
|
||||||
|
|
||||||
SCEVZeroExtendExpr::~SCEVZeroExtendExpr() {
|
|
||||||
SCEVZeroExtends->erase(std::make_pair(Op, Ty));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SCEVZeroExtendExpr::print(raw_ostream &OS) const {
|
void SCEVZeroExtendExpr::print(raw_ostream &OS) const {
|
||||||
OS << "(zext " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
|
OS << "(zext " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
|
||||||
}
|
}
|
||||||
@ -257,8 +240,6 @@ void SCEVZeroExtendExpr::print(raw_ostream &OS) const {
|
|||||||
// SCEVSignExtends - Only allow the creation of one SCEVSignExtendExpr for any
|
// SCEVSignExtends - Only allow the creation of one SCEVSignExtendExpr for any
|
||||||
// particular input. Don't use a SCEVHandle here, or else the object will never
|
// particular input. Don't use a SCEVHandle here, or else the object will never
|
||||||
// be deleted!
|
// be deleted!
|
||||||
static ManagedStatic<std::map<std::pair<const SCEV*, const Type*>,
|
|
||||||
SCEVSignExtendExpr*> > SCEVSignExtends;
|
|
||||||
|
|
||||||
SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty,
|
SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty,
|
||||||
const ScalarEvolution* p)
|
const ScalarEvolution* p)
|
||||||
@ -268,10 +249,6 @@ SCEVSignExtendExpr::SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty,
|
|||||||
"Cannot sign extend non-integer value!");
|
"Cannot sign extend non-integer value!");
|
||||||
}
|
}
|
||||||
|
|
||||||
SCEVSignExtendExpr::~SCEVSignExtendExpr() {
|
|
||||||
SCEVSignExtends->erase(std::make_pair(Op, Ty));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SCEVSignExtendExpr::print(raw_ostream &OS) const {
|
void SCEVSignExtendExpr::print(raw_ostream &OS) const {
|
||||||
OS << "(sext " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
|
OS << "(sext " << *Op->getType() << " " << *Op << " to " << *Ty << ")";
|
||||||
}
|
}
|
||||||
@ -279,13 +256,6 @@ void SCEVSignExtendExpr::print(raw_ostream &OS) const {
|
|||||||
// SCEVCommExprs - Only allow the creation of one SCEVCommutativeExpr for any
|
// SCEVCommExprs - Only allow the creation of one SCEVCommutativeExpr for any
|
||||||
// particular input. Don't use a SCEVHandle here, or else the object will never
|
// particular input. Don't use a SCEVHandle here, or else the object will never
|
||||||
// be deleted!
|
// 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 {
|
void SCEVCommutativeExpr::print(raw_ostream &OS) const {
|
||||||
assert(Operands.size() > 1 && "This plus expr shouldn't exist!");
|
assert(Operands.size() > 1 && "This plus expr shouldn't exist!");
|
||||||
@ -340,12 +310,6 @@ bool SCEVNAryExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
|
|||||||
// SCEVUDivs - Only allow the creation of one SCEVUDivExpr for any particular
|
// 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
|
// input. Don't use a SCEVHandle here, or else the object will never be
|
||||||
// deleted!
|
// 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 {
|
bool SCEVUDivExpr::dominates(BasicBlock *BB, DominatorTree *DT) const {
|
||||||
return LHS->dominates(BB, DT) && RHS->dominates(BB, DT);
|
return LHS->dominates(BB, DT) && RHS->dominates(BB, DT);
|
||||||
@ -367,14 +331,6 @@ const Type *SCEVUDivExpr::getType() const {
|
|||||||
// SCEVAddRecExprs - Only allow the creation of one SCEVAddRecExpr for any
|
// SCEVAddRecExprs - Only allow the creation of one SCEVAddRecExpr for any
|
||||||
// particular input. Don't use a SCEVHandle here, or else the object will never
|
// particular input. Don't use a SCEVHandle here, or else the object will never
|
||||||
// be deleted!
|
// 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::
|
SCEVHandle SCEVAddRecExpr::
|
||||||
replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
||||||
@ -420,9 +376,6 @@ void SCEVAddRecExpr::print(raw_ostream &OS) const {
|
|||||||
// SCEVUnknowns - Only allow the creation of one SCEVUnknown for any particular
|
// 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
|
// value. Don't use a SCEVHandle here, or else the object will never be
|
||||||
// deleted!
|
// deleted!
|
||||||
static ManagedStatic<std::map<Value*, SCEVUnknown*> > SCEVUnknowns;
|
|
||||||
|
|
||||||
SCEVUnknown::~SCEVUnknown() { SCEVUnknowns->erase(V); }
|
|
||||||
|
|
||||||
bool SCEVUnknown::isLoopInvariant(const Loop *L) const {
|
bool SCEVUnknown::isLoopInvariant(const Loop *L) const {
|
||||||
// All non-instruction values are loop invariant. All instructions are loop
|
// All non-instruction values are loop invariant. All instructions are loop
|
||||||
@ -791,7 +744,7 @@ SCEVHandle ScalarEvolution::getTruncateExpr(const SCEVHandle &Op,
|
|||||||
return getAddRecExpr(Operands, AddRec->getLoop());
|
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);
|
if (Result == 0) Result = new SCEVTruncateExpr(Op, Ty, this);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@ -879,7 +832,7 @@ SCEVHandle ScalarEvolution::getZeroExtendExpr(const SCEVHandle &Op,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
if (Result == 0) Result = new SCEVZeroExtendExpr(Op, Ty, this);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@ -951,7 +904,7 @@ SCEVHandle ScalarEvolution::getSignExtendExpr(const SCEVHandle &Op,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
if (Result == 0) Result = new SCEVSignExtendExpr(Op, Ty, this);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@ -1412,7 +1365,7 @@ SCEVHandle ScalarEvolution::getAddExpr(SmallVectorImpl<SCEVHandle> &Ops) {
|
|||||||
// Okay, it looks like we really DO need an add expr. Check to see if we
|
// Okay, it looks like we really DO need an add expr. Check to see if we
|
||||||
// already have one, otherwise create a new one.
|
// already have one, otherwise create a new one.
|
||||||
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
|
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
|
||||||
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scAddExpr,
|
SCEVCommutativeExpr *&Result = SCEVCommExprs[std::make_pair(scAddExpr,
|
||||||
SCEVOps)];
|
SCEVOps)];
|
||||||
if (Result == 0) Result = new SCEVAddExpr(Ops, this);
|
if (Result == 0) Result = new SCEVAddExpr(Ops, this);
|
||||||
return Result;
|
return Result;
|
||||||
@ -1577,7 +1530,7 @@ SCEVHandle ScalarEvolution::getMulExpr(SmallVectorImpl<SCEVHandle> &Ops) {
|
|||||||
// Okay, it looks like we really DO need an mul expr. Check to see if we
|
// Okay, it looks like we really DO need an mul expr. Check to see if we
|
||||||
// already have one, otherwise create a new one.
|
// already have one, otherwise create a new one.
|
||||||
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
|
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
|
||||||
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scMulExpr,
|
SCEVCommutativeExpr *&Result = SCEVCommExprs[std::make_pair(scMulExpr,
|
||||||
SCEVOps)];
|
SCEVOps)];
|
||||||
if (Result == 0)
|
if (Result == 0)
|
||||||
Result = new SCEVMulExpr(Ops, this);
|
Result = new SCEVMulExpr(Ops, this);
|
||||||
@ -1670,7 +1623,7 @@ SCEVHandle ScalarEvolution::getUDivExpr(const SCEVHandle &LHS,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
if (Result == 0) Result = new SCEVUDivExpr(LHS, RHS, this);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@ -1724,7 +1677,7 @@ SCEVHandle ScalarEvolution::getAddRecExpr(SmallVectorImpl<SCEVHandle> &Operands,
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const SCEV*> SCEVOps(Operands.begin(), Operands.end());
|
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);
|
if (Result == 0) Result = new SCEVAddRecExpr(Operands, L, this);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@ -1810,7 +1763,7 @@ ScalarEvolution::getSMaxExpr(SmallVectorImpl<SCEVHandle> &Ops) {
|
|||||||
// Okay, it looks like we really DO need an smax expr. Check to see if we
|
// Okay, it looks like we really DO need an smax expr. Check to see if we
|
||||||
// already have one, otherwise create a new one.
|
// already have one, otherwise create a new one.
|
||||||
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
|
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
|
||||||
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scSMaxExpr,
|
SCEVCommutativeExpr *&Result = SCEVCommExprs[std::make_pair(scSMaxExpr,
|
||||||
SCEVOps)];
|
SCEVOps)];
|
||||||
if (Result == 0) Result = new SCEVSMaxExpr(Ops, this);
|
if (Result == 0) Result = new SCEVSMaxExpr(Ops, this);
|
||||||
return Result;
|
return Result;
|
||||||
@ -1897,7 +1850,7 @@ ScalarEvolution::getUMaxExpr(SmallVectorImpl<SCEVHandle> &Ops) {
|
|||||||
// Okay, it looks like we really DO need a umax expr. Check to see if we
|
// Okay, it looks like we really DO need a umax expr. Check to see if we
|
||||||
// already have one, otherwise create a new one.
|
// already have one, otherwise create a new one.
|
||||||
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
|
std::vector<const SCEV*> SCEVOps(Ops.begin(), Ops.end());
|
||||||
SCEVCommutativeExpr *&Result = (*SCEVCommExprs)[std::make_pair(scUMaxExpr,
|
SCEVCommutativeExpr *&Result = SCEVCommExprs[std::make_pair(scUMaxExpr,
|
||||||
SCEVOps)];
|
SCEVOps)];
|
||||||
if (Result == 0) Result = new SCEVUMaxExpr(Ops, this);
|
if (Result == 0) Result = new SCEVUMaxExpr(Ops, this);
|
||||||
return Result;
|
return Result;
|
||||||
@ -1920,7 +1873,7 @@ SCEVHandle ScalarEvolution::getUnknown(Value *V) {
|
|||||||
return getConstant(CI);
|
return getConstant(CI);
|
||||||
if (isa<ConstantPointerNull>(V))
|
if (isa<ConstantPointerNull>(V))
|
||||||
return getIntegerSCEV(0, V->getType());
|
return getIntegerSCEV(0, V->getType());
|
||||||
SCEVUnknown *&Result = (*SCEVUnknowns)[V];
|
SCEVUnknown *&Result = SCEVUnknowns[V];
|
||||||
if (Result == 0) Result = new SCEVUnknown(V, this);
|
if (Result == 0) Result = new SCEVUnknown(V, this);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@ -4324,6 +4277,45 @@ void ScalarEvolution::releaseMemory() {
|
|||||||
BackedgeTakenCounts.clear();
|
BackedgeTakenCounts.clear();
|
||||||
ConstantEvolutionLoopExitValue.clear();
|
ConstantEvolutionLoopExitValue.clear();
|
||||||
ValuesAtScopes.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 {
|
void ScalarEvolution::getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user