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-08-18 16:46:41 +00:00
|
|
|
scUDivExpr, scAddRecExpr, scUMaxExpr, scSMaxExpr,
|
2010-01-28 02:15:55 +00:00
|
|
|
scUnknown, 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;
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVConstant(const FoldingSetNodeIDRef ID, ConstantInt *v) :
|
2009-07-13 20:50:19 +00:00
|
|
|
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-09-27 15:26:03 +00:00
|
|
|
bool properlyDominates(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
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVCastExpr(const FoldingSetNodeIDRef ID,
|
2009-07-13 20:50:19 +00:00
|
|
|
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;
|
|
|
|
|
2009-09-27 15:26:03 +00:00
|
|
|
virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2009-04-21 01:25:57 +00:00
|
|
|
/// 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;
|
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVTruncateExpr(const FoldingSetNodeIDRef ID,
|
2009-07-13 20:50:19 +00:00
|
|
|
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;
|
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVZeroExtendExpr(const FoldingSetNodeIDRef ID,
|
2009-07-13 20:50:19 +00:00
|
|
|
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;
|
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVSignExtendExpr(const FoldingSetNodeIDRef ID,
|
2009-07-13 20:50:19 +00:00
|
|
|
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:
|
2010-03-18 01:17:13 +00:00
|
|
|
// Since SCEVs are immutable, ScalarEvolution allocates operand
|
|
|
|
// arrays with its SCEVAllocator, so this class just needs a simple
|
|
|
|
// pointer rather than a more elaborate vector-like data structure.
|
|
|
|
// This also avoids the need for a non-trivial destructor.
|
|
|
|
const SCEV *const *Operands;
|
|
|
|
size_t NumOperands;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVNAryExpr(const FoldingSetNodeIDRef ID,
|
2010-03-18 01:17:13 +00:00
|
|
|
enum SCEVTypes T, const SCEV *const *O, size_t N)
|
|
|
|
: SCEV(ID, T), Operands(O), NumOperands(N) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
public:
|
2010-03-18 01:17:13 +00:00
|
|
|
size_t getNumOperands() const { return NumOperands; }
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getOperand(unsigned i) const {
|
2010-03-18 01:17:13 +00:00
|
|
|
assert(i < NumOperands && "Operand index out of range!");
|
2004-04-15 15:06:59 +00:00
|
|
|
return Operands[i];
|
|
|
|
}
|
|
|
|
|
2010-03-18 01:17:13 +00:00
|
|
|
typedef const SCEV *const *op_iterator;
|
|
|
|
op_iterator op_begin() const { return Operands; }
|
|
|
|
op_iterator op_end() const { return Operands + NumOperands; }
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-09-27 15:26:03 +00:00
|
|
|
bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2009-05-07 14:00:19 +00:00
|
|
|
virtual const Type *getType() const { return getOperand(0)->getType(); }
|
|
|
|
|
2009-10-09 00:10:36 +00:00
|
|
|
bool hasNoUnsignedWrap() const { return SubclassData & (1 << 0); }
|
|
|
|
void setHasNoUnsignedWrap(bool B) {
|
|
|
|
SubclassData = (SubclassData & ~(1 << 0)) | (B << 0);
|
|
|
|
}
|
|
|
|
bool hasNoSignedWrap() const { return SubclassData & (1 << 1); }
|
|
|
|
void setHasNoSignedWrap(bool B) {
|
|
|
|
SubclassData = (SubclassData & ~(1 << 1)) | (B << 1);
|
|
|
|
}
|
|
|
|
|
2009-05-07 14:00:19 +00:00
|
|
|
/// 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:
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVCommutativeExpr(const FoldingSetNodeIDRef ID,
|
|
|
|
enum SCEVTypes T, const SCEV *const *O, size_t N)
|
2010-03-18 01:17:13 +00:00
|
|
|
: SCEVNAryExpr(ID, T, O, N) {}
|
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;
|
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVAddExpr(const FoldingSetNodeIDRef ID,
|
2010-03-18 01:17:13 +00:00
|
|
|
const SCEV *const *O, size_t N)
|
|
|
|
: SCEVCommutativeExpr(ID, scAddExpr, O, N) {
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual const char *getOperationStr() const { return " + "; }
|
|
|
|
|
2010-01-19 22:53:50 +00:00
|
|
|
virtual const Type *getType() const {
|
|
|
|
// Use the type of the last operand, which is likely to be a pointer
|
|
|
|
// type, if there is one. This doesn't usually matter, but it can help
|
|
|
|
// reduce casts when the expressions are expanded.
|
|
|
|
return getOperand(getNumOperands() - 1)->getType();
|
|
|
|
}
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
/// 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;
|
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVMulExpr(const FoldingSetNodeIDRef ID,
|
2010-03-18 01:17:13 +00:00
|
|
|
const SCEV *const *O, size_t N)
|
|
|
|
: SCEVCommutativeExpr(ID, scMulExpr, O, N) {
|
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;
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVUDivExpr(const FoldingSetNodeIDRef ID, const SCEV *lhs, const SCEV *rhs)
|
2009-07-13 20:50:19 +00:00
|
|
|
: 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
|
|
|
|
2009-09-27 15:26:03 +00:00
|
|
|
bool properlyDominates(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
|
|
|
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;
|
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVAddRecExpr(const FoldingSetNodeIDRef ID,
|
2010-03-18 01:17:13 +00:00
|
|
|
const SCEV *const *O, size_t N, const Loop *l)
|
|
|
|
: SCEVNAryExpr(ID, scAddRecExpr, O, N), L(l) {
|
|
|
|
for (size_t i = 0, e = NumOperands; 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 {
|
2010-02-10 15:54:22 +00:00
|
|
|
return L == QL;
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isLoopInvariant(const Loop *QueryLoop) const;
|
|
|
|
|
2010-02-13 00:19:39 +00:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
|
|
|
bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
/// 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-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;
|
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVSMaxExpr(const FoldingSetNodeIDRef ID,
|
2010-03-18 01:17:13 +00:00
|
|
|
const SCEV *const *O, size_t N)
|
|
|
|
: SCEVCommutativeExpr(ID, scSMaxExpr, O, N) {
|
2009-10-09 00:10:36 +00:00
|
|
|
// Max never overflows.
|
|
|
|
setHasNoUnsignedWrap(true);
|
|
|
|
setHasNoSignedWrap(true);
|
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;
|
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVUMaxExpr(const FoldingSetNodeIDRef ID,
|
2010-03-18 01:17:13 +00:00
|
|
|
const SCEV *const *O, size_t N)
|
|
|
|
: SCEVCommutativeExpr(ID, scUMaxExpr, O, N) {
|
2009-10-09 00:10:36 +00:00
|
|
|
// Max never overflows.
|
|
|
|
setHasNoUnsignedWrap(true);
|
|
|
|
setHasNoSignedWrap(true);
|
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
|
2009-09-15 15:08:33 +00:00
|
|
|
/// value, and only represent it as its LLVM Value. This is the "bottom"
|
2004-04-15 15:06:59 +00:00
|
|
|
/// 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;
|
2010-03-18 16:16:38 +00:00
|
|
|
SCEVUnknown(const FoldingSetNodeIDRef ID, Value *v) :
|
2009-07-13 20:50:19 +00:00
|
|
|
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
|
|
|
|
2010-01-28 02:15:55 +00:00
|
|
|
/// isSizeOf, isAlignOf, isOffsetOf - Test whether this is a special
|
|
|
|
/// constant representing a type size, alignment, or field offset in
|
|
|
|
/// a target-independent manner, and hasn't happened to have been
|
|
|
|
/// folded with other operations into something unrecognizable. This
|
|
|
|
/// is mainly only useful for pretty-printing and other situations
|
|
|
|
/// where it isn't absolutely required for these to succeed.
|
|
|
|
bool isSizeOf(const Type *&AllocTy) const;
|
|
|
|
bool isAlignOf(const Type *&AllocTy) const;
|
2010-02-01 18:27:38 +00:00
|
|
|
bool isOffsetOf(const Type *&STy, Constant *&FieldNo) const;
|
2010-01-28 02:15:55 +00:00
|
|
|
|
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;
|
|
|
|
|
2009-09-27 15:26:03 +00:00
|
|
|
bool properlyDominates(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
|