friend class ScalarEvolution;
ConstantInt *V;
- SCEVConstant(const FoldingSetNodeIDRef ID, unsigned Num, ConstantInt *v)
- : SCEV(ID, Num, scConstant), V(v) {}
+ SCEVConstant(const FoldingSetNodeIDRef ID, ConstantInt *v) :
+ SCEV(ID, scConstant), V(v) {}
public:
ConstantInt *getValue() const { return V; }
const SCEV *Op;
const Type *Ty;
- SCEVCastExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVCastExpr(const FoldingSetNodeIDRef ID,
unsigned SCEVTy, const SCEV *op, const Type *ty);
public:
class SCEVTruncateExpr : public SCEVCastExpr {
friend class ScalarEvolution;
- SCEVTruncateExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVTruncateExpr(const FoldingSetNodeIDRef ID,
const SCEV *op, const Type *ty);
public:
class SCEVZeroExtendExpr : public SCEVCastExpr {
friend class ScalarEvolution;
- SCEVZeroExtendExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVZeroExtendExpr(const FoldingSetNodeIDRef ID,
const SCEV *op, const Type *ty);
public:
class SCEVSignExtendExpr : public SCEVCastExpr {
friend class ScalarEvolution;
- SCEVSignExtendExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVSignExtendExpr(const FoldingSetNodeIDRef ID,
const SCEV *op, const Type *ty);
public:
const SCEV *const *Operands;
size_t NumOperands;
- SCEVNAryExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVNAryExpr(const FoldingSetNodeIDRef ID,
enum SCEVTypes T, const SCEV *const *O, size_t N)
- : SCEV(ID, Num, T), Operands(O), NumOperands(N) {}
+ : SCEV(ID, T), Operands(O), NumOperands(N) {}
public:
size_t getNumOperands() const { return NumOperands; }
op_iterator op_begin() const { return Operands; }
op_iterator op_end() const { return Operands + NumOperands; }
- virtual bool isLoopInvariant(const Loop *L) const {
- for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- if (!getOperand(i)->isLoopInvariant(L)) return false;
- return true;
- }
+ virtual bool isLoopInvariant(const Loop *L) const;
// hasComputableLoopEvolution - N-ary expressions have computable loop
// evolutions iff they have at least one operand that varies with the loop,
// but that all varying operands are computable.
- virtual bool hasComputableLoopEvolution(const Loop *L) const {
- bool HasVarying = false;
- for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- if (!getOperand(i)->isLoopInvariant(L)) {
- if (getOperand(i)->hasComputableLoopEvolution(L))
- HasVarying = true;
- else
- return false;
- }
- return HasVarying;
- }
+ virtual bool hasComputableLoopEvolution(const Loop *L) const;
- virtual bool hasOperand(const SCEV *O) const {
- for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- if (O == getOperand(i) || getOperand(i)->hasOperand(O))
- return true;
- return false;
- }
+ virtual bool hasOperand(const SCEV *O) const;
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
///
class SCEVCommutativeExpr : public SCEVNAryExpr {
protected:
- SCEVCommutativeExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVCommutativeExpr(const FoldingSetNodeIDRef ID,
enum SCEVTypes T, const SCEV *const *O, size_t N)
- : SCEVNAryExpr(ID, Num, T, O, N) {}
+ : SCEVNAryExpr(ID, T, O, N) {}
public:
virtual const char *getOperationStr() const = 0;
class SCEVAddExpr : public SCEVCommutativeExpr {
friend class ScalarEvolution;
- SCEVAddExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVAddExpr(const FoldingSetNodeIDRef ID,
const SCEV *const *O, size_t N)
- : SCEVCommutativeExpr(ID, Num, scAddExpr, O, N) {
+ : SCEVCommutativeExpr(ID, scAddExpr, O, N) {
}
public:
class SCEVMulExpr : public SCEVCommutativeExpr {
friend class ScalarEvolution;
- SCEVMulExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVMulExpr(const FoldingSetNodeIDRef ID,
const SCEV *const *O, size_t N)
- : SCEVCommutativeExpr(ID, Num, scMulExpr, O, N) {
+ : SCEVCommutativeExpr(ID, scMulExpr, O, N) {
}
public:
const SCEV *LHS;
const SCEV *RHS;
- SCEVUDivExpr(const FoldingSetNodeIDRef ID, unsigned Num,
- const SCEV *lhs, const SCEV *rhs)
- : SCEV(ID, Num, scUDivExpr), LHS(lhs), RHS(rhs) {}
+ SCEVUDivExpr(const FoldingSetNodeIDRef ID, const SCEV *lhs, const SCEV *rhs)
+ : SCEV(ID, scUDivExpr), LHS(lhs), RHS(rhs) {}
public:
const SCEV *getLHS() const { return LHS; }
const Loop *L;
- SCEVAddRecExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVAddRecExpr(const FoldingSetNodeIDRef ID,
const SCEV *const *O, size_t N, const Loop *l)
- : SCEVNAryExpr(ID, Num, scAddRecExpr, O, N), L(l) {
+ : SCEVNAryExpr(ID, scAddRecExpr, O, N), L(l) {
for (size_t i = 0, e = NumOperands; i != e; ++i)
assert(Operands[i]->isLoopInvariant(l) &&
"Operands of AddRec must be loop-invariant!");
class SCEVSMaxExpr : public SCEVCommutativeExpr {
friend class ScalarEvolution;
- SCEVSMaxExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVSMaxExpr(const FoldingSetNodeIDRef ID,
const SCEV *const *O, size_t N)
- : SCEVCommutativeExpr(ID, Num, scSMaxExpr, O, N) {
+ : SCEVCommutativeExpr(ID, scSMaxExpr, O, N) {
// Max never overflows.
setHasNoUnsignedWrap(true);
setHasNoSignedWrap(true);
class SCEVUMaxExpr : public SCEVCommutativeExpr {
friend class ScalarEvolution;
- SCEVUMaxExpr(const FoldingSetNodeIDRef ID, unsigned Num,
+ SCEVUMaxExpr(const FoldingSetNodeIDRef ID,
const SCEV *const *O, size_t N)
- : SCEVCommutativeExpr(ID, Num, scUMaxExpr, O, N) {
+ : SCEVCommutativeExpr(ID, scUMaxExpr, O, N) {
// Max never overflows.
setHasNoUnsignedWrap(true);
setHasNoSignedWrap(true);
/// value, and only represent it as its LLVM Value. This is the "bottom"
/// value for the analysis.
///
- class SCEVUnknown : public SCEV {
+ class SCEVUnknown : public SCEV, private CallbackVH {
friend class ScalarEvolution;
- Value *V;
- SCEVUnknown(const FoldingSetNodeIDRef ID, unsigned Num, Value *v)
- : SCEV(ID, Num, scUnknown), V(v) {}
+ // Implement CallbackVH.
+ virtual void deleted();
+ virtual void allUsesReplacedWith(Value *New);
+
+ /// SE - The parent ScalarEvolution value. This is used to update
+ /// the parent's maps when the value associated with a SCEVUnknown
+ /// is deleted or RAUW'd.
+ ScalarEvolution *SE;
+
+ /// Next - The next pointer in the linked list of all
+ /// SCEVUnknown instances owned by a ScalarEvolution.
+ SCEVUnknown *Next;
+
+ SCEVUnknown(const FoldingSetNodeIDRef ID, Value *V,
+ ScalarEvolution *se, SCEVUnknown *next) :
+ SCEV(ID, scUnknown), CallbackVH(V), SE(se), Next(next) {}
public:
- Value *getValue() const { return V; }
+ Value *getValue() const { return getValPtr(); }
/// isSizeOf, isAlignOf, isOffsetOf - Test whether this is a special
/// constant representing a type size, alignment, or field offset in