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"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class ConstantInt;
|
|
|
|
class ConstantRange;
|
2007-03-01 22:28:51 +00:00
|
|
|
class APInt;
|
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;
|
2007-07-09 15:25:17 +00:00
|
|
|
explicit SCEVConstant(ConstantInt *v) : SCEV(scConstant), V(v) {}
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual ~SCEVConstant();
|
|
|
|
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;
|
|
|
|
|
2005-02-13 04:34:51 +00:00
|
|
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
2007-10-22 18:31:58 +00:00
|
|
|
const SCEVHandle &Conc,
|
|
|
|
ScalarEvolution &SE) const {
|
2005-02-13 04:34:51 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2009-02-17 00:13:06 +00:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVTruncateExpr - This class represents a truncation of an integer value
|
|
|
|
/// to a smaller integer value.
|
|
|
|
///
|
|
|
|
class SCEVTruncateExpr : public SCEV {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
SCEVHandle Op;
|
|
|
|
const Type *Ty;
|
|
|
|
SCEVTruncateExpr(const SCEVHandle &op, const Type *ty);
|
|
|
|
virtual ~SCEVTruncateExpr();
|
|
|
|
public:
|
|
|
|
const SCEVHandle &getOperand() const { return Op; }
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-02-13 04:34:51 +00:00
|
|
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
2007-10-22 18:31:58 +00:00
|
|
|
const SCEVHandle &Conc,
|
|
|
|
ScalarEvolution &SE) const {
|
|
|
|
SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
|
2005-02-13 04:34:51 +00:00
|
|
|
if (H == Op)
|
|
|
|
return this;
|
2007-10-22 18:31:58 +00:00
|
|
|
return SE.getTruncateExpr(H, Ty);
|
2005-02-13 04:34:51 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 00:13:06 +00:00
|
|
|
virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
virtual void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
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.
|
|
|
|
///
|
|
|
|
class SCEVZeroExtendExpr : public SCEV {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
SCEVHandle Op;
|
|
|
|
const Type *Ty;
|
|
|
|
SCEVZeroExtendExpr(const SCEVHandle &op, const Type *ty);
|
|
|
|
virtual ~SCEVZeroExtendExpr();
|
|
|
|
public:
|
|
|
|
const SCEVHandle &getOperand() const { return Op; }
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-02-13 04:34:51 +00:00
|
|
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
2007-10-22 18:31:58 +00:00
|
|
|
const SCEVHandle &Conc,
|
|
|
|
ScalarEvolution &SE) const {
|
|
|
|
SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
|
2005-02-13 04:34:51 +00:00
|
|
|
if (H == Op)
|
|
|
|
return this;
|
2007-10-22 18:31:58 +00:00
|
|
|
return SE.getZeroExtendExpr(H, Ty);
|
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 void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
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.
|
|
|
|
///
|
|
|
|
class SCEVSignExtendExpr : public SCEV {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2007-06-15 14:38:12 +00:00
|
|
|
SCEVHandle Op;
|
|
|
|
const Type *Ty;
|
|
|
|
SCEVSignExtendExpr(const SCEVHandle &op, const Type *ty);
|
|
|
|
virtual ~SCEVSignExtendExpr();
|
|
|
|
public:
|
|
|
|
const SCEVHandle &getOperand() const { return Op; }
|
|
|
|
virtual const Type *getType() const { return Ty; }
|
|
|
|
|
|
|
|
virtual bool isLoopInvariant(const Loop *L) const {
|
|
|
|
return Op->isLoopInvariant(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool hasComputableLoopEvolution(const Loop *L) const {
|
|
|
|
return Op->hasComputableLoopEvolution(L);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
2007-10-22 18:31:58 +00:00
|
|
|
const SCEVHandle &Conc,
|
|
|
|
ScalarEvolution &SE) const {
|
|
|
|
SCEVHandle H = Op->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
|
2007-06-15 14:38:12 +00:00
|
|
|
if (H == Op)
|
|
|
|
return this;
|
2007-10-22 18:31:58 +00:00
|
|
|
return SE.getSignExtendExpr(H, Ty);
|
2007-06-15 14:38:12 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 00:13:06 +00:00
|
|
|
bool dominates(BasicBlock *BB, DominatorTree *DT) const;
|
|
|
|
|
2007-06-15 14:38:12 +00:00
|
|
|
virtual void print(std::ostream &OS) const;
|
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
/// SCEVCommutativeExpr - This node is the base class for n'ary commutative
|
|
|
|
/// operators.
|
|
|
|
///
|
|
|
|
class SCEVCommutativeExpr : public SCEV {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
std::vector<SCEVHandle> Operands;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SCEVCommutativeExpr(enum SCEVTypes T, const std::vector<SCEVHandle> &ops)
|
|
|
|
: SCEV(T) {
|
|
|
|
Operands.reserve(ops.size());
|
|
|
|
Operands.insert(Operands.end(), ops.begin(), ops.end());
|
|
|
|
}
|
|
|
|
~SCEVCommutativeExpr();
|
|
|
|
|
|
|
|
public:
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
2004-04-15 15:06:59 +00:00
|
|
|
const SCEVHandle &getOperand(unsigned i) const {
|
|
|
|
assert(i < Operands.size() && "Operand index out of range!");
|
|
|
|
return Operands[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<SCEVHandle> &getOperands() const { return Operands; }
|
|
|
|
typedef std::vector<SCEVHandle>::const_iterator op_iterator;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-02-26 18:40:02 +00:00
|
|
|
// hasComputableLoopEvolution - Commutative expressions have computable loop
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2005-02-13 04:34:51 +00:00
|
|
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
2007-10-22 18:31:58 +00:00
|
|
|
const SCEVHandle &Conc,
|
|
|
|
ScalarEvolution &SE) const;
|
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 char *getOperationStr() const = 0;
|
|
|
|
|
|
|
|
virtual const Type *getType() const { return getOperand(0)->getType(); }
|
|
|
|
virtual void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
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;
|
|
|
|
|
2007-11-19 15:30:20 +00:00
|
|
|
explicit SCEVAddExpr(const std::vector<SCEVHandle> &ops)
|
2004-04-15 15:06:59 +00:00
|
|
|
: SCEVCommutativeExpr(scAddExpr, ops) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2007-11-19 15:30:20 +00:00
|
|
|
explicit SCEVMulExpr(const std::vector<SCEVHandle> &ops)
|
2004-04-15 15:06:59 +00:00
|
|
|
: SCEVCommutativeExpr(scMulExpr, ops) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
SCEVHandle LHS, RHS;
|
2008-02-11 11:03:14 +00:00
|
|
|
SCEVUDivExpr(const SCEVHandle &lhs, const SCEVHandle &rhs)
|
|
|
|
: SCEV(scUDivExpr), LHS(lhs), RHS(rhs) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2008-02-11 11:03:14 +00:00
|
|
|
virtual ~SCEVUDivExpr();
|
2004-04-15 15:06:59 +00:00
|
|
|
public:
|
|
|
|
const SCEVHandle &getLHS() const { return LHS; }
|
|
|
|
const SCEVHandle &getRHS() const { return RHS; }
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-02-13 04:34:51 +00:00
|
|
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
2007-10-22 18:31:58 +00:00
|
|
|
const SCEVHandle &Conc,
|
|
|
|
ScalarEvolution &SE) const {
|
|
|
|
SCEVHandle L = LHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
|
|
|
|
SCEVHandle R = RHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
|
2005-02-13 04:34:51 +00:00
|
|
|
if (L == LHS && R == RHS)
|
|
|
|
return this;
|
|
|
|
else
|
2008-02-11 11:03:14 +00:00
|
|
|
return SE.getUDivExpr(L, R);
|
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;
|
|
|
|
|
|
|
|
void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
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
|
|
|
|
/// count of the specified loop.
|
|
|
|
///
|
|
|
|
/// All operands of an AddRec are required to be loop invariant.
|
|
|
|
///
|
|
|
|
class SCEVAddRecExpr : public SCEV {
|
2007-10-22 18:31:58 +00:00
|
|
|
friend class ScalarEvolution;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
std::vector<SCEVHandle> Operands;
|
|
|
|
const Loop *L;
|
|
|
|
|
|
|
|
SCEVAddRecExpr(const std::vector<SCEVHandle> &ops, const Loop *l)
|
|
|
|
: SCEV(scAddRecExpr), Operands(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!");
|
|
|
|
}
|
|
|
|
~SCEVAddRecExpr();
|
|
|
|
public:
|
|
|
|
typedef std::vector<SCEVHandle>::const_iterator op_iterator;
|
|
|
|
op_iterator op_begin() const { return Operands.begin(); }
|
|
|
|
op_iterator op_end() const { return Operands.end(); }
|
|
|
|
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
2004-04-15 15:06:59 +00:00
|
|
|
const SCEVHandle &getOperand(unsigned i) const { return Operands[i]; }
|
|
|
|
const SCEVHandle &getStart() const { return Operands[0]; }
|
|
|
|
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.
|
2007-10-22 18:31:58 +00:00
|
|
|
SCEVHandle getStepRecurrence(ScalarEvolution &SE) const {
|
2008-06-22 19:23:09 +00:00
|
|
|
if (isAffine()) return getOperand(1);
|
2007-10-22 18:31:58 +00:00
|
|
|
return SE.getAddRecExpr(std::vector<SCEVHandle>(op_begin()+1,op_end()),
|
|
|
|
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;
|
|
|
|
|
|
|
|
virtual const Type *getType() const { return Operands[0]->getType(); }
|
|
|
|
|
|
|
|
/// 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.
|
2007-10-22 18:31:58 +00:00
|
|
|
SCEVHandle evaluateAtIteration(SCEVHandle 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.
|
2007-10-22 18:31:58 +00:00
|
|
|
SCEVHandle getNumIterationsInRange(ConstantRange Range,
|
|
|
|
ScalarEvolution &SE) const;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2005-02-13 04:34:51 +00:00
|
|
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
2007-10-22 18:31:58 +00:00
|
|
|
const SCEVHandle &Conc,
|
|
|
|
ScalarEvolution &SE) const;
|
2004-04-15 15:06:59 +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 void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
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;
|
|
|
|
|
|
|
|
explicit SCEVSMaxExpr(const std::vector<SCEVHandle> &ops)
|
|
|
|
: SCEVCommutativeExpr(scSMaxExpr, ops) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
explicit SCEVUMaxExpr(const std::vector<SCEVHandle> &ops)
|
|
|
|
: SCEVCommutativeExpr(scUMaxExpr, ops) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2007-11-19 15:30:20 +00:00
|
|
|
explicit SCEVUnknown(Value *v) : SCEV(scUnknown), V(v) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
~SCEVUnknown();
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2005-02-13 04:34:51 +00:00
|
|
|
SCEVHandle replaceSymbolicValuesWithConcrete(const SCEVHandle &Sym,
|
2007-10-22 18:31:58 +00:00
|
|
|
const SCEVHandle &Conc,
|
|
|
|
ScalarEvolution &SE) const {
|
2005-02-13 04:34:51 +00:00
|
|
|
if (&*Sym == this) return Conc;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
virtual void print(std::ostream &OS) const;
|
2006-12-17 05:15:13 +00:00
|
|
|
void print(std::ostream *OS) const { if (OS) print(*OS); }
|
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:
|
|
|
|
assert(0 && "Unknown SCEV type!");
|
2004-04-27 18:21:56 +00:00
|
|
|
abort();
|
2004-04-23 21:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 17:56:28 +00:00
|
|
|
RetVal visitCouldNotCompute(const SCEVCouldNotCompute *S) {
|
2004-04-23 21:28:25 +00:00
|
|
|
assert(0 && "Invalid use of SCEVCouldNotCompute!");
|
|
|
|
abort();
|
|
|
|
return RetVal();
|
|
|
|
}
|
|
|
|
};
|
2004-04-15 15:06:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|