2004-04-15 15:06:59 +00:00
|
|
|
//===- llvm/Analysis/ScalarEvolutionExpressions.h - SCEV Exprs --*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2004-04-15 15:06:59 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2004-04-15 15:06:59 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the classes used to represent and build scalar expressions.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2004-04-15 15:06:59 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_SCALAREVOLUTION_EXPRESSIONS_H
|
|
|
|
#define LLVM_ANALYSIS_SCALAREVOLUTION_EXPRESSIONS_H
|
|
|
|
|
|
|
|
#include "llvm/Analysis/ScalarEvolution.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class ConstantInt;
|
|
|
|
class ConstantRange;
|
2009-02-17 00:13:06 +00:00
|
|
|
class DominatorTree;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
enum SCEVTypes {
|
|
|
|
// These should be ordered in terms of increasing complexity to make the
|
|
|
|
// folders simpler.
|
2007-06-15 14:38:12 +00:00
|
|
|
scConstant, scTruncate, scZeroExtend, scSignExtend, scAddExpr, scMulExpr,
|
2009-01-13 09:18:58 +00:00
|
|
|
scUDivExpr, scAddRecExpr, scUMaxExpr, scSMaxExpr, scUnknown,
|
2008-02-20 06:48:22 +00:00
|
|
|
scCouldNotCompute
|
2004-04-15 15:06:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVConstant - This class represents a constant integer value.
|
|
|
|
///
|
|
|
|
class SCEVConstant : public SCEV {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
ConstantInt *V;
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVConstant(const FoldingSetNodeID &ID, ConstantInt *v) :
|
|
|
|
SCEV(ID, scConstant), V(v) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
public:
|
|
|
|
ConstantInt *getValue() const { return V; }
|
|
|
|
|
|
|
|
virtual bool isLoopInvariant(const Loop *L) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *L) const {
|
|
|
|
return false; // Not loop variant
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual const Type *getType() const;
|
|
|
|
|
2009-07-25 01:13:03 +00:00
|
|
|
virtual bool hasOperand(const SCEV *) const {
|
|
|
|
return false;
|
2005-02-13 04:34:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 00:13:06 +00:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-04-21 00:47:46 +00:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVConstant *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scConstant;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2009-04-21 01:25:57 +00:00
|
|
|
/// SCEVCastExpr - This is the base class for unary cast operator classes.
|
2004-04-15 15:06:59 +00:00
|
|
|
///
|
2009-04-21 01:25:57 +00:00
|
|
|
class SCEVCastExpr : public SCEV {
|
|
|
|
protected:
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *Op;
|
2004-04-15 15:06:59 +00:00
|
|
|
const Type *Ty;
|
2009-04-21 01:25:57 +00:00
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVCastExpr(const FoldingSetNodeID &ID,
|
|
|
|
unsigned SCEVTy, const SCEV *op, const Type *ty);
|
2009-04-21 01:25:57 +00:00
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
public:
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getOperand() const { return Op; }
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual const Type *getType() const { return Ty; }
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual bool isLoopInvariant(const Loop *L) const {
|
|
|
|
return Op->isLoopInvariant(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *L) const {
|
|
|
|
return Op->hasComputableLoopEvolution(L);
|
|
|
|
}
|
|
|
|
|
2009-07-25 01:13:03 +00:00
|
|
|
virtual bool hasOperand(const SCEV *O) const {
|
|
|
|
return Op == O || Op->hasOperand(O);
|
|
|
|
}
|
|
|
|
|
2009-04-21 01:25:57 +00:00
|
|
|
virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVCastExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scTruncate ||
|
|
|
|
S->getSCEVType() == scZeroExtend ||
|
|
|
|
S->getSCEVType() == scSignExtend;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVTruncateExpr - This class represents a truncation of an integer value
|
|
|
|
/// to a smaller integer value.
|
|
|
|
///
|
|
|
|
class SCEVTruncateExpr : public SCEVCastExpr {
|
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVTruncateExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SCEV *op, const Type *ty);
|
2009-04-21 01:25:57 +00:00
|
|
|
|
|
|
|
public:
|
2009-04-21 00:47:46 +00:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVTruncateExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scTruncate;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVZeroExtendExpr - This class represents a zero extension of a small
|
|
|
|
/// integer value to a larger integer value.
|
|
|
|
///
|
2009-04-21 01:25:57 +00:00
|
|
|
class SCEVZeroExtendExpr : public SCEVCastExpr {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVZeroExtendExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SCEV *op, const Type *ty);
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2009-04-21 01:25:57 +00:00
|
|
|
public:
|
2009-04-21 00:47:46 +00:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVZeroExtendExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scZeroExtend;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-06-15 14:38:12 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVSignExtendExpr - This class represents a sign extension of a small
|
|
|
|
/// integer value to a larger integer value.
|
|
|
|
///
|
2009-04-21 01:25:57 +00:00
|
|
|
class SCEVSignExtendExpr : public SCEVCastExpr {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVSignExtendExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SCEV *op, const Type *ty);
|
2007-06-15 14:38:12 +00:00
|
|
|
|
2009-04-21 01:25:57 +00:00
|
|
|
public:
|
2009-04-21 00:47:46 +00:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2007-06-15 14:38:12 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVSignExtendExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scSignExtend;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2009-05-26 17:42:32 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVNAryExpr - This node is a base class providing common
|
|
|
|
/// functionality for n'ary operators.
|
|
|
|
///
|
2009-05-07 14:00:19 +00:00
|
|
|
class SCEVNAryExpr : public SCEV {
|
|
|
|
protected:
|
2009-07-07 17:06:11 +00:00
|
|
|
SmallVector<const SCEV *, 8> Operands;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVNAryExpr(const FoldingSetNodeID &ID,
|
|
|
|
enum SCEVTypes T, const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEV(ID, T), Operands(ops.begin(), ops.end()) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
public:
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getOperand(unsigned i) const {
|
2004-04-15 15:06:59 +00:00
|
|
|
assert(i < Operands.size() && "Operand index out of range!");
|
|
|
|
return Operands[i];
|
|
|
|
}
|
|
|
|
|
2009-07-07 17:06:11 +00:00
|
|
|
const SmallVectorImpl<const SCEV *> &getOperands() const {
|
|
|
|
return Operands;
|
|
|
|
}
|
|
|
|
typedef SmallVectorImpl<const SCEV *>::const_iterator op_iterator;
|
2004-04-15 15:06:59 +00:00
|
|
|
op_iterator op_begin() const { return Operands.begin(); }
|
|
|
|
op_iterator op_end() const { return Operands.end(); }
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-05-18 22:15:25 +00:00
|
|
|
// hasComputableLoopEvolution - N-ary expressions have computable loop
|
2005-02-26 18:40:02 +00:00
|
|
|
// evolutions iff they have at least one operand that varies with the loop,
|
|
|
|
// but that all varying operands are computable.
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *L) const {
|
2005-02-26 18:40:02 +00:00
|
|
|
bool HasVarying = false;
|
2004-04-15 15:06:59 +00:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
2008-02-20 11:08:44 +00:00
|
|
|
if (!getOperand(i)->isLoopInvariant(L)) {
|
2005-02-26 18:40:02 +00:00
|
|
|
if (getOperand(i)->hasComputableLoopEvolution(L))
|
|
|
|
HasVarying = true;
|
|
|
|
else
|
|
|
|
return false;
|
2008-02-20 11:08:44 +00:00
|
|
|
}
|
2005-02-26 18:40:02 +00:00
|
|
|
return HasVarying;
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
2009-07-25 01:13:03 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-05-07 14:00:19 +00:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
|
|
|
virtual const Type *getType() const { return getOperand(0)->getType(); }
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVNAryExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scAddExpr ||
|
|
|
|
S->getSCEVType() == scMulExpr ||
|
|
|
|
S->getSCEVType() == scSMaxExpr ||
|
|
|
|
S->getSCEVType() == scUMaxExpr ||
|
|
|
|
S->getSCEVType() == scAddRecExpr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVCommutativeExpr - This node is the base class for n'ary commutative
|
|
|
|
/// operators.
|
|
|
|
///
|
|
|
|
class SCEVCommutativeExpr : public SCEVNAryExpr {
|
|
|
|
protected:
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVCommutativeExpr(const FoldingSetNodeID &ID,
|
|
|
|
enum SCEVTypes T,
|
2009-07-07 17:06:11 +00:00
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
2009-07-13 20:50:19 +00:00
|
|
|
: SCEVNAryExpr(ID, T, ops) {}
|
2009-05-07 14:00:19 +00:00
|
|
|
|
|
|
|
public:
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual const char *getOperationStr() const = 0;
|
|
|
|
|
2009-04-21 00:47:46 +00:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVCommutativeExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scAddExpr ||
|
2007-11-25 22:41:31 +00:00
|
|
|
S->getSCEVType() == scMulExpr ||
|
2008-02-20 06:48:22 +00:00
|
|
|
S->getSCEVType() == scSMaxExpr ||
|
|
|
|
S->getSCEVType() == scUMaxExpr;
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVAddExpr - This node represents an addition of some number of SCEVs.
|
|
|
|
///
|
|
|
|
class SCEVAddExpr : public SCEVCommutativeExpr {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVAddExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEVCommutativeExpr(ID, scAddExpr, ops) {
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual const char *getOperationStr() const { return " + "; }
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVAddExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scAddExpr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVMulExpr - This node represents multiplication of some number of SCEVs.
|
|
|
|
///
|
|
|
|
class SCEVMulExpr : public SCEVCommutativeExpr {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVMulExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEVCommutativeExpr(ID, scMulExpr, ops) {
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual const char *getOperationStr() const { return " * "; }
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVMulExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scMulExpr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
2008-02-11 11:03:14 +00:00
|
|
|
/// SCEVUDivExpr - This class represents a binary unsigned division operation.
|
2004-04-15 15:06:59 +00:00
|
|
|
///
|
2008-02-11 11:03:14 +00:00
|
|
|
class SCEVUDivExpr : public SCEV {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *LHS;
|
|
|
|
const SCEV *RHS;
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVUDivExpr(const FoldingSetNodeID &ID, const SCEV *lhs, const SCEV *rhs)
|
|
|
|
: SCEV(ID, scUDivExpr), LHS(lhs), RHS(rhs) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
public:
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getLHS() const { return LHS; }
|
|
|
|
const SCEV *getRHS() const { return RHS; }
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
virtual bool isLoopInvariant(const Loop *L) const {
|
|
|
|
return LHS->isLoopInvariant(L) && RHS->isLoopInvariant(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *L) const {
|
|
|
|
return LHS->hasComputableLoopEvolution(L) &&
|
|
|
|
RHS->hasComputableLoopEvolution(L);
|
|
|
|
}
|
|
|
|
|
2009-07-25 01:13:03 +00:00
|
|
|
virtual bool hasOperand(const SCEV *O) const {
|
|
|
|
return O == LHS || O == RHS || LHS->hasOperand(O) || RHS->hasOperand(O);
|
2005-02-13 04:34:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 00:13:06 +00:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
2005-02-13 04:34:51 +00:00
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual const Type *getType() const;
|
|
|
|
|
2009-04-21 00:47:46 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2008-02-11 11:03:14 +00:00
|
|
|
static inline bool classof(const SCEVUDivExpr *S) { return true; }
|
2004-04-15 15:06:59 +00:00
|
|
|
static inline bool classof(const SCEV *S) {
|
2008-02-11 11:03:14 +00:00
|
|
|
return S->getSCEVType() == scUDivExpr;
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVAddRecExpr - This node represents a polynomial recurrence on the trip
|
2009-04-29 00:59:03 +00:00
|
|
|
/// count of the specified loop. This is the primary focus of the
|
|
|
|
/// ScalarEvolution framework; all the other SCEV subclasses are mostly just
|
|
|
|
/// supporting infrastructure to allow SCEVAddRecExpr expressions to be
|
|
|
|
/// created and analyzed.
|
2004-04-15 15:06:59 +00:00
|
|
|
///
|
|
|
|
/// All operands of an AddRec are required to be loop invariant.
|
|
|
|
///
|
2009-05-07 14:00:19 +00:00
|
|
|
class SCEVAddRecExpr : public SCEVNAryExpr {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
const Loop *L;
|
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVAddRecExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops, const Loop *l)
|
|
|
|
: SCEVNAryExpr(ID, scAddRecExpr, ops), L(l) {
|
2008-05-05 18:30:58 +00:00
|
|
|
for (size_t i = 0, e = Operands.size(); i != e; ++i)
|
2004-04-15 15:06:59 +00:00
|
|
|
assert(Operands[i]->isLoopInvariant(l) &&
|
|
|
|
"Operands of AddRec must be loop-invariant!");
|
|
|
|
}
|
|
|
|
|
2009-05-07 14:00:19 +00:00
|
|
|
public:
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getStart() const { return Operands[0]; }
|
2004-04-15 15:06:59 +00:00
|
|
|
const Loop *getLoop() const { return L; }
|
|
|
|
|
|
|
|
/// getStepRecurrence - This method constructs and returns the recurrence
|
|
|
|
/// indicating how much this expression steps by. If this is a polynomial
|
|
|
|
/// of degree N, it returns a chrec of degree N-1.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getStepRecurrence(ScalarEvolution &SE) const {
|
2008-06-22 19:23:09 +00:00
|
|
|
if (isAffine()) return getOperand(1);
|
2009-07-07 17:06:11 +00:00
|
|
|
return SE.getAddRecExpr(SmallVector<const SCEV *, 3>(op_begin()+1,
|
|
|
|
op_end()),
|
2007-10-22 18:31:58 +00:00
|
|
|
getLoop());
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *QL) const {
|
|
|
|
if (L == QL) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isLoopInvariant(const Loop *QueryLoop) const;
|
|
|
|
|
|
|
|
/// isAffine - Return true if this is an affine AddRec (i.e., it represents
|
|
|
|
/// an expressions A+B*x where A and B are loop invariant values.
|
|
|
|
bool isAffine() const {
|
|
|
|
// We know that the start value is invariant. This expression is thus
|
|
|
|
// affine iff the step is also invariant.
|
|
|
|
return getNumOperands() == 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isQuadratic - Return true if this is an quadratic AddRec (i.e., it
|
|
|
|
/// represents an expressions A+B*x+C*x^2 where A, B and C are loop
|
|
|
|
/// invariant values. This corresponds to an addrec of the form {L,+,M,+,N}
|
|
|
|
bool isQuadratic() const {
|
|
|
|
return getNumOperands() == 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// evaluateAtIteration - Return the value of this chain of recurrences at
|
|
|
|
/// the specified iteration number.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
/// getNumIterationsInRange - Return the number of iterations of this loop
|
|
|
|
/// that produce values in the specified constant range. Another way of
|
|
|
|
/// looking at this is that it returns the first iteration number where the
|
|
|
|
/// value is not in the condition, thus computing the exit count. If the
|
|
|
|
/// iteration count can't be computed, an instance of SCEVCouldNotCompute is
|
2007-07-16 02:08:00 +00:00
|
|
|
/// returned.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getNumIterationsInRange(ConstantRange Range,
|
2007-10-22 18:31:58 +00:00
|
|
|
ScalarEvolution &SE) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
/// getPostIncExpr - Return an expression representing the value of
|
|
|
|
/// this expression one iteration of the loop ahead.
|
2009-07-25 01:13:03 +00:00
|
|
|
const SCEVAddRecExpr *getPostIncExpr(ScalarEvolution &SE) const {
|
|
|
|
return cast<SCEVAddRecExpr>(SE.getAddExpr(this, getStepRecurrence(SE)));
|
2009-07-13 20:50:19 +00:00
|
|
|
}
|
|
|
|
|
2009-07-24 01:01:06 +00:00
|
|
|
bool hasNoUnsignedOverflow() const { return SubclassData & (1 << 0); }
|
|
|
|
void setHasNoUnsignedOverflow(bool B) {
|
|
|
|
SubclassData = (SubclassData & ~(1 << 0)) | (B << 0);
|
|
|
|
}
|
|
|
|
bool hasNoSignedOverflow() const { return SubclassData & (1 << 1); }
|
|
|
|
void setHasNoSignedOverflow(bool B) {
|
|
|
|
SubclassData = (SubclassData & ~(1 << 1)) | (B << 1);
|
|
|
|
}
|
|
|
|
|
2009-04-21 00:47:46 +00:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVAddRecExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scAddRecExpr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-11-25 22:41:31 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVSMaxExpr - This class represents a signed maximum selection.
|
|
|
|
///
|
|
|
|
class SCEVSMaxExpr : public SCEVCommutativeExpr {
|
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVSMaxExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEVCommutativeExpr(ID, scSMaxExpr, ops) {
|
2007-11-25 22:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual const char *getOperationStr() const { return " smax "; }
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVSMaxExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scSMaxExpr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-02-20 06:48:22 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVUMaxExpr - This class represents an unsigned maximum selection.
|
|
|
|
///
|
|
|
|
class SCEVUMaxExpr : public SCEVCommutativeExpr {
|
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVUMaxExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEVCommutativeExpr(ID, scUMaxExpr, ops) {
|
2008-02-20 06:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual const char *getOperationStr() const { return " umax "; }
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVUMaxExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scUMaxExpr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVUnknown - This means that we are dealing with an entirely unknown SCEV
|
|
|
|
/// value, and only represent it as it's LLVM Value. This is the "bottom"
|
|
|
|
/// value for the analysis.
|
|
|
|
///
|
|
|
|
class SCEVUnknown : public SCEV {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
Value *V;
|
2009-07-13 20:50:19 +00:00
|
|
|
SCEVUnknown(const FoldingSetNodeID &ID, Value *v) :
|
|
|
|
SCEV(ID, scUnknown), V(v) {}
|
2009-06-27 21:21:31 +00:00
|
|
|
|
2009-07-13 20:50:19 +00:00
|
|
|
public:
|
2004-04-23 21:28:25 +00:00
|
|
|
Value *getValue() const { return V; }
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
virtual bool isLoopInvariant(const Loop *L) const;
|
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *QL) const {
|
|
|
|
return false; // not computable
|
|
|
|
}
|
|
|
|
|
2009-07-25 01:13:03 +00:00
|
|
|
virtual bool hasOperand(const SCEV *) const {
|
|
|
|
return false;
|
2005-02-13 04:34:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 00:13:06 +00:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual const Type *getType() const;
|
|
|
|
|
2009-04-21 00:47:46 +00:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVUnknown *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scUnknown;
|
|
|
|
}
|
|
|
|
};
|
2004-04-23 21:28:25 +00:00
|
|
|
|
|
|
|
/// SCEVVisitor - This class defines a simple visitor class that may be used
|
|
|
|
/// for various SCEV analysis purposes.
|
|
|
|
template<typename SC, typename RetVal=void>
|
|
|
|
struct SCEVVisitor {
|
2009-04-18 17:56:28 +00:00
|
|
|
RetVal visit(const SCEV *S) {
|
2004-04-23 21:28:25 +00:00
|
|
|
switch (S->getSCEVType()) {
|
|
|
|
case scConstant:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitConstant((const SCEVConstant*)S);
|
2004-04-23 21:28:25 +00:00
|
|
|
case scTruncate:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitTruncateExpr((const SCEVTruncateExpr*)S);
|
2004-04-23 21:28:25 +00:00
|
|
|
case scZeroExtend:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitZeroExtendExpr((const SCEVZeroExtendExpr*)S);
|
2007-06-15 14:38:12 +00:00
|
|
|
case scSignExtend:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitSignExtendExpr((const SCEVSignExtendExpr*)S);
|
2004-04-23 21:28:25 +00:00
|
|
|
case scAddExpr:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitAddExpr((const SCEVAddExpr*)S);
|
2004-04-23 21:28:25 +00:00
|
|
|
case scMulExpr:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitMulExpr((const SCEVMulExpr*)S);
|
2008-02-11 11:03:14 +00:00
|
|
|
case scUDivExpr:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitUDivExpr((const SCEVUDivExpr*)S);
|
2004-04-23 21:28:25 +00:00
|
|
|
case scAddRecExpr:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitAddRecExpr((const SCEVAddRecExpr*)S);
|
2007-11-25 22:41:31 +00:00
|
|
|
case scSMaxExpr:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitSMaxExpr((const SCEVSMaxExpr*)S);
|
2008-02-20 06:48:22 +00:00
|
|
|
case scUMaxExpr:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitUMaxExpr((const SCEVUMaxExpr*)S);
|
2004-04-23 21:28:25 +00:00
|
|
|
case scUnknown:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitUnknown((const SCEVUnknown*)S);
|
2004-04-23 21:28:25 +00:00
|
|
|
case scCouldNotCompute:
|
2009-04-18 17:56:28 +00:00
|
|
|
return ((SC*)this)->visitCouldNotCompute((const SCEVCouldNotCompute*)S);
|
2004-04-23 21:28:25 +00:00
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unknown SCEV type!");
|
2004-04-23 21:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 17:56:28 +00:00
|
|
|
RetVal visitCouldNotCompute(const SCEVCouldNotCompute *S) {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Invalid use of SCEVCouldNotCompute!");
|
2004-04-23 21:28:25 +00:00
|
|
|
return RetVal();
|
|
|
|
}
|
|
|
|
};
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|