2004-04-15 17:06:59 +02:00
|
|
|
//===- llvm/Analysis/ScalarEvolutionExpressions.h - SCEV Exprs --*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2004-04-15 17:06:59 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2004-04-15 17:06:59 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the classes used to represent and build scalar expressions.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2004-04-15 17:06:59 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_SCALAREVOLUTION_EXPRESSIONS_H
|
|
|
|
#define LLVM_ANALYSIS_SCALAREVOLUTION_EXPRESSIONS_H
|
|
|
|
|
|
|
|
#include "llvm/Analysis/ScalarEvolution.h"
|
2009-07-11 22:10:48 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2004-04-15 17:06:59 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class ConstantInt;
|
|
|
|
class ConstantRange;
|
2009-02-17 01:13:06 +01:00
|
|
|
class DominatorTree;
|
2004-04-15 17:06:59 +02:00
|
|
|
|
|
|
|
enum SCEVTypes {
|
|
|
|
// These should be ordered in terms of increasing complexity to make the
|
|
|
|
// folders simpler.
|
2007-06-15 16:38:12 +02:00
|
|
|
scConstant, scTruncate, scZeroExtend, scSignExtend, scAddExpr, scMulExpr,
|
2009-08-18 18:46:41 +02:00
|
|
|
scUDivExpr, scAddRecExpr, scUMaxExpr, scSMaxExpr,
|
|
|
|
scFieldOffset, scAllocSize, scUnknown, scCouldNotCompute
|
2004-04-15 17:06:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVConstant - This class represents a constant integer value.
|
|
|
|
///
|
|
|
|
class SCEVConstant : public SCEV {
|
2007-10-22 20:31:58 +02:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 17:06:59 +02:00
|
|
|
ConstantInt *V;
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVConstant(const FoldingSetNodeID &ID, ConstantInt *v) :
|
|
|
|
SCEV(ID, scConstant), V(v) {}
|
2004-04-15 17:06:59 +02: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 03:13:03 +02:00
|
|
|
virtual bool hasOperand(const SCEV *) const {
|
|
|
|
return false;
|
2005-02-13 05:34:51 +01:00
|
|
|
}
|
|
|
|
|
2009-02-17 01:13:06 +01:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-27 17:26:03 +02:00
|
|
|
bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-04-21 02:47:46 +02:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 17:06:59 +02: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 03:25:57 +02:00
|
|
|
/// SCEVCastExpr - This is the base class for unary cast operator classes.
|
2004-04-15 17:06:59 +02:00
|
|
|
///
|
2009-04-21 03:25:57 +02:00
|
|
|
class SCEVCastExpr : public SCEV {
|
|
|
|
protected:
|
2009-07-07 19:06:11 +02:00
|
|
|
const SCEV *Op;
|
2004-04-15 17:06:59 +02:00
|
|
|
const Type *Ty;
|
2009-04-21 03:25:57 +02:00
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVCastExpr(const FoldingSetNodeID &ID,
|
|
|
|
unsigned SCEVTy, const SCEV *op, const Type *ty);
|
2009-04-21 03:25:57 +02:00
|
|
|
|
2004-04-15 17:06:59 +02:00
|
|
|
public:
|
2009-07-07 19:06:11 +02:00
|
|
|
const SCEV *getOperand() const { return Op; }
|
2004-04-15 17:06:59 +02:00
|
|
|
virtual const Type *getType() const { return Ty; }
|
2005-04-21 22:19:05 +02:00
|
|
|
|
2004-04-15 17:06:59 +02: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 03:13:03 +02:00
|
|
|
virtual bool hasOperand(const SCEV *O) const {
|
|
|
|
return Op == O || Op->hasOperand(O);
|
|
|
|
}
|
|
|
|
|
2009-04-21 03:25:57 +02:00
|
|
|
virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2009-09-27 17:26:03 +02:00
|
|
|
virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2009-04-21 03:25:57 +02: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;
|
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVTruncateExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SCEV *op, const Type *ty);
|
2009-04-21 03:25:57 +02:00
|
|
|
|
|
|
|
public:
|
2009-04-21 02:47:46 +02:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 17:06:59 +02: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 03:25:57 +02:00
|
|
|
class SCEVZeroExtendExpr : public SCEVCastExpr {
|
2007-10-22 20:31:58 +02:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVZeroExtendExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SCEV *op, const Type *ty);
|
2004-04-15 17:06:59 +02:00
|
|
|
|
2009-04-21 03:25:57 +02:00
|
|
|
public:
|
2009-04-21 02:47:46 +02:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 17:06:59 +02: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 16:38:12 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVSignExtendExpr - This class represents a sign extension of a small
|
|
|
|
/// integer value to a larger integer value.
|
|
|
|
///
|
2009-04-21 03:25:57 +02:00
|
|
|
class SCEVSignExtendExpr : public SCEVCastExpr {
|
2007-10-22 20:31:58 +02:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVSignExtendExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SCEV *op, const Type *ty);
|
2007-06-15 16:38:12 +02:00
|
|
|
|
2009-04-21 03:25:57 +02:00
|
|
|
public:
|
2009-04-21 02:47:46 +02:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2007-06-15 16:38:12 +02: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 17:06:59 +02:00
|
|
|
|
2009-05-26 19:42:32 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVNAryExpr - This node is a base class providing common
|
|
|
|
/// functionality for n'ary operators.
|
|
|
|
///
|
2009-05-07 16:00:19 +02:00
|
|
|
class SCEVNAryExpr : public SCEV {
|
|
|
|
protected:
|
2009-07-07 19:06:11 +02:00
|
|
|
SmallVector<const SCEV *, 8> Operands;
|
2004-04-15 17:06:59 +02:00
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVNAryExpr(const FoldingSetNodeID &ID,
|
|
|
|
enum SCEVTypes T, const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEV(ID, T), Operands(ops.begin(), ops.end()) {}
|
2004-04-15 17:06:59 +02:00
|
|
|
|
|
|
|
public:
|
2008-05-05 20:30:58 +02:00
|
|
|
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
2009-07-07 19:06:11 +02:00
|
|
|
const SCEV *getOperand(unsigned i) const {
|
2004-04-15 17:06:59 +02:00
|
|
|
assert(i < Operands.size() && "Operand index out of range!");
|
|
|
|
return Operands[i];
|
|
|
|
}
|
|
|
|
|
2009-07-07 19:06:11 +02:00
|
|
|
const SmallVectorImpl<const SCEV *> &getOperands() const {
|
|
|
|
return Operands;
|
|
|
|
}
|
|
|
|
typedef SmallVectorImpl<const SCEV *>::const_iterator op_iterator;
|
2004-04-15 17:06:59 +02: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-19 00:15:25 +02:00
|
|
|
// hasComputableLoopEvolution - N-ary expressions have computable loop
|
2005-02-26 19:40:02 +01:00
|
|
|
// evolutions iff they have at least one operand that varies with the loop,
|
|
|
|
// but that all varying operands are computable.
|
2004-04-15 17:06:59 +02:00
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *L) const {
|
2005-02-26 19:40:02 +01:00
|
|
|
bool HasVarying = false;
|
2004-04-15 17:06:59 +02:00
|
|
|
for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
|
2008-02-20 12:08:44 +01:00
|
|
|
if (!getOperand(i)->isLoopInvariant(L)) {
|
2005-02-26 19:40:02 +01:00
|
|
|
if (getOperand(i)->hasComputableLoopEvolution(L))
|
|
|
|
HasVarying = true;
|
|
|
|
else
|
|
|
|
return false;
|
2008-02-20 12:08:44 +01:00
|
|
|
}
|
2005-02-26 19:40:02 +01:00
|
|
|
return HasVarying;
|
2004-04-15 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
2009-07-25 03:13:03 +02: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 16:00:19 +02:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2009-09-27 17:26:03 +02:00
|
|
|
bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2009-05-07 16:00:19 +02:00
|
|
|
virtual const Type *getType() const { return getOperand(0)->getType(); }
|
|
|
|
|
2009-10-09 02:10:36 +02: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 16:00:19 +02: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:
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVCommutativeExpr(const FoldingSetNodeID &ID,
|
|
|
|
enum SCEVTypes T,
|
2009-07-07 19:06:11 +02:00
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
2009-07-13 22:50:19 +02:00
|
|
|
: SCEVNAryExpr(ID, T, ops) {}
|
2009-05-07 16:00:19 +02:00
|
|
|
|
|
|
|
public:
|
2004-04-15 17:06:59 +02:00
|
|
|
virtual const char *getOperationStr() const = 0;
|
|
|
|
|
2009-04-21 02:47:46 +02:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 17:06:59 +02: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 23:41:31 +01:00
|
|
|
S->getSCEVType() == scMulExpr ||
|
2008-02-20 07:48:22 +01:00
|
|
|
S->getSCEVType() == scSMaxExpr ||
|
|
|
|
S->getSCEVType() == scUMaxExpr;
|
2004-04-15 17:06:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVAddExpr - This node represents an addition of some number of SCEVs.
|
|
|
|
///
|
|
|
|
class SCEVAddExpr : public SCEVCommutativeExpr {
|
2007-10-22 20:31:58 +02:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVAddExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEVCommutativeExpr(ID, scAddExpr, ops) {
|
2004-04-15 17:06:59 +02: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 20:31:58 +02:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVMulExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEVCommutativeExpr(ID, scMulExpr, ops) {
|
2004-04-15 17:06:59 +02: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 12:03:14 +01:00
|
|
|
/// SCEVUDivExpr - This class represents a binary unsigned division operation.
|
2004-04-15 17:06:59 +02:00
|
|
|
///
|
2008-02-11 12:03:14 +01:00
|
|
|
class SCEVUDivExpr : public SCEV {
|
2007-10-22 20:31:58 +02:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-07 19:06:11 +02:00
|
|
|
const SCEV *LHS;
|
|
|
|
const SCEV *RHS;
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVUDivExpr(const FoldingSetNodeID &ID, const SCEV *lhs, const SCEV *rhs)
|
|
|
|
: SCEV(ID, scUDivExpr), LHS(lhs), RHS(rhs) {}
|
2004-04-15 17:06:59 +02:00
|
|
|
|
|
|
|
public:
|
2009-07-07 19:06:11 +02:00
|
|
|
const SCEV *getLHS() const { return LHS; }
|
|
|
|
const SCEV *getRHS() const { return RHS; }
|
2004-04-15 17:06:59 +02: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 03:13:03 +02:00
|
|
|
virtual bool hasOperand(const SCEV *O) const {
|
|
|
|
return O == LHS || O == RHS || LHS->hasOperand(O) || RHS->hasOperand(O);
|
2005-02-13 05:34:51 +01:00
|
|
|
}
|
|
|
|
|
2009-02-17 01:13:06 +01:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
2005-02-13 05:34:51 +01:00
|
|
|
|
2009-09-27 17:26:03 +02:00
|
|
|
bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2004-04-15 17:06:59 +02:00
|
|
|
virtual const Type *getType() const;
|
|
|
|
|
2009-04-21 02:47:46 +02:00
|
|
|
void print(raw_ostream &OS) const;
|
2004-04-15 17:06:59 +02:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
2008-02-11 12:03:14 +01:00
|
|
|
static inline bool classof(const SCEVUDivExpr *S) { return true; }
|
2004-04-15 17:06:59 +02:00
|
|
|
static inline bool classof(const SCEV *S) {
|
2008-02-11 12:03:14 +01:00
|
|
|
return S->getSCEVType() == scUDivExpr;
|
2004-04-15 17:06:59 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVAddRecExpr - This node represents a polynomial recurrence on the trip
|
2009-04-29 02:59:03 +02: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 17:06:59 +02:00
|
|
|
///
|
|
|
|
/// All operands of an AddRec are required to be loop invariant.
|
|
|
|
///
|
2009-05-07 16:00:19 +02:00
|
|
|
class SCEVAddRecExpr : public SCEVNAryExpr {
|
2007-10-22 20:31:58 +02:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 17:06:59 +02:00
|
|
|
const Loop *L;
|
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVAddRecExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops, const Loop *l)
|
|
|
|
: SCEVNAryExpr(ID, scAddRecExpr, ops), L(l) {
|
2008-05-05 20:30:58 +02:00
|
|
|
for (size_t i = 0, e = Operands.size(); i != e; ++i)
|
2004-04-15 17:06:59 +02:00
|
|
|
assert(Operands[i]->isLoopInvariant(l) &&
|
|
|
|
"Operands of AddRec must be loop-invariant!");
|
|
|
|
}
|
|
|
|
|
2009-05-07 16:00:19 +02:00
|
|
|
public:
|
2009-07-07 19:06:11 +02:00
|
|
|
const SCEV *getStart() const { return Operands[0]; }
|
2004-04-15 17:06:59 +02: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 19:06:11 +02:00
|
|
|
const SCEV *getStepRecurrence(ScalarEvolution &SE) const {
|
2008-06-22 21:23:09 +02:00
|
|
|
if (isAffine()) return getOperand(1);
|
2009-07-07 19:06:11 +02:00
|
|
|
return SE.getAddRecExpr(SmallVector<const SCEV *, 3>(op_begin()+1,
|
|
|
|
op_end()),
|
2007-10-22 20:31:58 +02:00
|
|
|
getLoop());
|
2004-04-15 17:06:59 +02: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 19:06:11 +02:00
|
|
|
const SCEV *evaluateAtIteration(const SCEV *It, ScalarEvolution &SE) const;
|
2004-04-15 17:06:59 +02: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 04:08:00 +02:00
|
|
|
/// returned.
|
2009-07-07 19:06:11 +02:00
|
|
|
const SCEV *getNumIterationsInRange(ConstantRange Range,
|
2007-10-22 20:31:58 +02:00
|
|
|
ScalarEvolution &SE) const;
|
2004-04-15 17:06:59 +02:00
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
/// getPostIncExpr - Return an expression representing the value of
|
|
|
|
/// this expression one iteration of the loop ahead.
|
2009-07-25 03:13:03 +02:00
|
|
|
const SCEVAddRecExpr *getPostIncExpr(ScalarEvolution &SE) const {
|
|
|
|
return cast<SCEVAddRecExpr>(SE.getAddExpr(this, getStepRecurrence(SE)));
|
2009-07-13 22:50:19 +02:00
|
|
|
}
|
|
|
|
|
2009-04-21 02:47:46 +02:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 17:06:59 +02: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 23:41:31 +01:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVSMaxExpr - This class represents a signed maximum selection.
|
|
|
|
///
|
|
|
|
class SCEVSMaxExpr : public SCEVCommutativeExpr {
|
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVSMaxExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEVCommutativeExpr(ID, scSMaxExpr, ops) {
|
2009-10-09 02:10:36 +02:00
|
|
|
// Max never overflows.
|
|
|
|
setHasNoUnsignedWrap(true);
|
|
|
|
setHasNoSignedWrap(true);
|
2007-11-25 23:41:31 +01: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 07:48:22 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVUMaxExpr - This class represents an unsigned maximum selection.
|
|
|
|
///
|
|
|
|
class SCEVUMaxExpr : public SCEVCommutativeExpr {
|
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVUMaxExpr(const FoldingSetNodeID &ID,
|
|
|
|
const SmallVectorImpl<const SCEV *> &ops)
|
|
|
|
: SCEVCommutativeExpr(ID, scUMaxExpr, ops) {
|
2009-10-09 02:10:36 +02:00
|
|
|
// Max never overflows.
|
|
|
|
setHasNoUnsignedWrap(true);
|
|
|
|
setHasNoSignedWrap(true);
|
2008-02-20 07:48:22 +01: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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-08-18 18:46:41 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVTargetDataConstant - This node is the base class for representing
|
|
|
|
/// target-dependent values in a target-independent way.
|
|
|
|
///
|
|
|
|
class SCEVTargetDataConstant : public SCEV {
|
|
|
|
protected:
|
|
|
|
const Type *Ty;
|
|
|
|
SCEVTargetDataConstant(const FoldingSetNodeID &ID, enum SCEVTypes T,
|
|
|
|
const Type *ty) :
|
|
|
|
SCEV(ID, T), Ty(ty) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual bool isLoopInvariant(const Loop *) const { return true; }
|
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *) const {
|
|
|
|
return false; // not computable
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool hasOperand(const SCEV *) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dominates(BasicBlock *, DominatorTree *) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-27 17:26:03 +02:00
|
|
|
bool properlyDominates(BasicBlock *, DominatorTree *) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-18 18:46:41 +02:00
|
|
|
virtual const Type *getType() const { return Ty; }
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVTargetDataConstant *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scFieldOffset ||
|
|
|
|
S->getSCEVType() == scAllocSize;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVFieldOffsetExpr - This node represents an offsetof expression.
|
|
|
|
///
|
|
|
|
class SCEVFieldOffsetExpr : public SCEVTargetDataConstant {
|
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
|
|
|
const StructType *STy;
|
|
|
|
unsigned FieldNo;
|
|
|
|
SCEVFieldOffsetExpr(const FoldingSetNodeID &ID, const Type *ty,
|
|
|
|
const StructType *sty, unsigned fieldno) :
|
|
|
|
SCEVTargetDataConstant(ID, scFieldOffset, ty),
|
|
|
|
STy(sty), FieldNo(fieldno) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
const StructType *getStructType() const { return STy; }
|
|
|
|
unsigned getFieldNo() const { return FieldNo; }
|
|
|
|
|
|
|
|
virtual void print(raw_ostream &OS) const;
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVFieldOffsetExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scFieldOffset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVAllocSize - This node represents a sizeof expression.
|
|
|
|
///
|
|
|
|
class SCEVAllocSizeExpr : public SCEVTargetDataConstant {
|
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
|
|
|
const Type *AllocTy;
|
|
|
|
SCEVAllocSizeExpr(const FoldingSetNodeID &ID,
|
|
|
|
const Type *ty, const Type *allocty) :
|
|
|
|
SCEVTargetDataConstant(ID, scAllocSize, ty),
|
|
|
|
AllocTy(allocty) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
const Type *getAllocType() const { return AllocTy; }
|
|
|
|
|
|
|
|
virtual void print(raw_ostream &OS) const;
|
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static inline bool classof(const SCEVAllocSizeExpr *S) { return true; }
|
|
|
|
static inline bool classof(const SCEV *S) {
|
|
|
|
return S->getSCEVType() == scAllocSize;
|
|
|
|
}
|
|
|
|
};
|
2008-02-20 07:48:22 +01:00
|
|
|
|
2004-04-15 17:06:59 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVUnknown - This means that we are dealing with an entirely unknown SCEV
|
2009-09-15 17:08:33 +02:00
|
|
|
/// value, and only represent it as its LLVM Value. This is the "bottom"
|
2004-04-15 17:06:59 +02:00
|
|
|
/// value for the analysis.
|
|
|
|
///
|
|
|
|
class SCEVUnknown : public SCEV {
|
2007-10-22 20:31:58 +02:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 17:06:59 +02:00
|
|
|
Value *V;
|
2009-07-13 22:50:19 +02:00
|
|
|
SCEVUnknown(const FoldingSetNodeID &ID, Value *v) :
|
|
|
|
SCEV(ID, scUnknown), V(v) {}
|
2009-06-27 23:21:31 +02:00
|
|
|
|
2009-07-13 22:50:19 +02:00
|
|
|
public:
|
2004-04-23 23:28:25 +02:00
|
|
|
Value *getValue() const { return V; }
|
2004-04-15 17:06:59 +02:00
|
|
|
|
|
|
|
virtual bool isLoopInvariant(const Loop *L) const;
|
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *QL) const {
|
|
|
|
return false; // not computable
|
|
|
|
}
|
|
|
|
|
2009-07-25 03:13:03 +02:00
|
|
|
virtual bool hasOperand(const SCEV *) const {
|
|
|
|
return false;
|
2005-02-13 05:34:51 +01:00
|
|
|
}
|
|
|
|
|
2009-02-17 01:13:06 +01:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2009-09-27 17:26:03 +02:00
|
|
|
bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2004-04-15 17:06:59 +02:00
|
|
|
virtual const Type *getType() const;
|
|
|
|
|
2009-04-21 02:47:46 +02:00
|
|
|
virtual void print(raw_ostream &OS) const;
|
2004-04-15 17:06:59 +02: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 23:28:25 +02: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 19:56:28 +02:00
|
|
|
RetVal visit(const SCEV *S) {
|
2004-04-23 23:28:25 +02:00
|
|
|
switch (S->getSCEVType()) {
|
|
|
|
case scConstant:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitConstant((const SCEVConstant*)S);
|
2004-04-23 23:28:25 +02:00
|
|
|
case scTruncate:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitTruncateExpr((const SCEVTruncateExpr*)S);
|
2004-04-23 23:28:25 +02:00
|
|
|
case scZeroExtend:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitZeroExtendExpr((const SCEVZeroExtendExpr*)S);
|
2007-06-15 16:38:12 +02:00
|
|
|
case scSignExtend:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitSignExtendExpr((const SCEVSignExtendExpr*)S);
|
2004-04-23 23:28:25 +02:00
|
|
|
case scAddExpr:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitAddExpr((const SCEVAddExpr*)S);
|
2004-04-23 23:28:25 +02:00
|
|
|
case scMulExpr:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitMulExpr((const SCEVMulExpr*)S);
|
2008-02-11 12:03:14 +01:00
|
|
|
case scUDivExpr:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitUDivExpr((const SCEVUDivExpr*)S);
|
2004-04-23 23:28:25 +02:00
|
|
|
case scAddRecExpr:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitAddRecExpr((const SCEVAddRecExpr*)S);
|
2007-11-25 23:41:31 +01:00
|
|
|
case scSMaxExpr:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitSMaxExpr((const SCEVSMaxExpr*)S);
|
2008-02-20 07:48:22 +01:00
|
|
|
case scUMaxExpr:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitUMaxExpr((const SCEVUMaxExpr*)S);
|
2009-08-18 18:46:41 +02:00
|
|
|
case scFieldOffset:
|
|
|
|
return ((SC*)this)->visitFieldOffsetExpr((const SCEVFieldOffsetExpr*)S);
|
|
|
|
case scAllocSize:
|
|
|
|
return ((SC*)this)->visitAllocSizeExpr((const SCEVAllocSizeExpr*)S);
|
2004-04-23 23:28:25 +02:00
|
|
|
case scUnknown:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitUnknown((const SCEVUnknown*)S);
|
2004-04-23 23:28:25 +02:00
|
|
|
case scCouldNotCompute:
|
2009-04-18 19:56:28 +02:00
|
|
|
return ((SC*)this)->visitCouldNotCompute((const SCEVCouldNotCompute*)S);
|
2004-04-23 23:28:25 +02:00
|
|
|
default:
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Unknown SCEV type!");
|
2004-04-23 23:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 19:56:28 +02:00
|
|
|
RetVal visitCouldNotCompute(const SCEVCouldNotCompute *S) {
|
2009-07-14 18:55:14 +02:00
|
|
|
llvm_unreachable("Invalid use of SCEVCouldNotCompute!");
|
2004-04-23 23:28:25 +02:00
|
|
|
return RetVal();
|
|
|
|
}
|
|
|
|
};
|
2004-04-15 17:06:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|