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;
|
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-06-22 21:57:23 +00:00
|
|
|
explicit SCEVConstant(ConstantInt *v) :
|
|
|
|
SCEV(scConstant), V(v) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
public:
|
2009-06-27 21:21:31 +00:00
|
|
|
virtual void Profile(FoldingSetNodeID &ID) const;
|
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
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-06-22 21:39:50 +00:00
|
|
|
const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym,
|
|
|
|
const SCEV* Conc,
|
2007-10-22 18:31:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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-06-22 21:39:50 +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-06-22 21:57:23 +00:00
|
|
|
SCEVCastExpr(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-06-27 21:21:31 +00:00
|
|
|
virtual void Profile(FoldingSetNodeID &ID) const;
|
|
|
|
|
2009-06-22 21:39:50 +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-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-06-22 21:57:23 +00:00
|
|
|
SCEVTruncateExpr(const SCEV* op, const Type *ty);
|
2009-04-21 01:25:57 +00:00
|
|
|
|
|
|
|
public:
|
2009-06-22 21:39:50 +00:00
|
|
|
const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym,
|
|
|
|
const SCEV* Conc,
|
2007-10-22 18:31:58 +00:00
|
|
|
ScalarEvolution &SE) const {
|
2009-06-22 21:39:50 +00:00
|
|
|
const SCEV* 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-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-06-22 21:57:23 +00:00
|
|
|
SCEVZeroExtendExpr(const SCEV* op, const Type *ty);
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2009-04-21 01:25:57 +00:00
|
|
|
public:
|
2009-06-22 21:39:50 +00:00
|
|
|
const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym,
|
|
|
|
const SCEV* Conc,
|
2007-10-22 18:31:58 +00:00
|
|
|
ScalarEvolution &SE) const {
|
2009-06-22 21:39:50 +00:00
|
|
|
const SCEV* 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-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-06-22 21:57:23 +00:00
|
|
|
SCEVSignExtendExpr(const SCEV* op, const Type *ty);
|
2007-06-15 14:38:12 +00:00
|
|
|
|
2009-04-21 01:25:57 +00:00
|
|
|
public:
|
2009-06-22 21:39:50 +00:00
|
|
|
const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym,
|
|
|
|
const SCEV* Conc,
|
2007-10-22 18:31:58 +00:00
|
|
|
ScalarEvolution &SE) const {
|
2009-06-22 21:39:50 +00:00
|
|
|
const SCEV* 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-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-06-22 21:39:50 +00:00
|
|
|
SmallVector<const SCEV*, 8> Operands;
|
2004-04-15 15:06:59 +00:00
|
|
|
|
2009-06-22 21:57:23 +00:00
|
|
|
SCEVNAryExpr(enum SCEVTypes T, const SmallVectorImpl<const SCEV*> &ops)
|
|
|
|
: SCEV(T), Operands(ops.begin(), ops.end()) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
public:
|
2009-06-27 21:21:31 +00:00
|
|
|
virtual void Profile(FoldingSetNodeID &ID) const;
|
|
|
|
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned getNumOperands() const { return (unsigned)Operands.size(); }
|
2009-06-22 21:39:50 +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-06-22 21:39:50 +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-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-06-18 22:25:12 +00:00
|
|
|
SCEVCommutativeExpr(enum SCEVTypes T,
|
2009-06-22 21:57:23 +00:00
|
|
|
const SmallVectorImpl<const SCEV*> &ops)
|
|
|
|
: SCEVNAryExpr(T, ops) {}
|
2009-05-07 14:00:19 +00:00
|
|
|
|
|
|
|
public:
|
2009-06-22 21:39:50 +00:00
|
|
|
const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym,
|
|
|
|
const SCEV* Conc,
|
2007-10-22 18:31:58 +00:00
|
|
|
ScalarEvolution &SE) const;
|
2005-02-13 04:34:51 +00:00
|
|
|
|
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-06-22 21:57:23 +00:00
|
|
|
explicit SCEVAddExpr(const SmallVectorImpl<const SCEV*> &ops)
|
|
|
|
: SCEVCommutativeExpr(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-06-22 21:57:23 +00:00
|
|
|
explicit SCEVMulExpr(const SmallVectorImpl<const SCEV*> &ops)
|
|
|
|
: SCEVCommutativeExpr(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-06-22 21:39:50 +00:00
|
|
|
const SCEV* LHS;
|
|
|
|
const SCEV* RHS;
|
2009-06-22 21:57:23 +00:00
|
|
|
SCEVUDivExpr(const SCEV* lhs, const SCEV* rhs)
|
|
|
|
: SCEV(scUDivExpr), LHS(lhs), RHS(rhs) {}
|
2004-04-15 15:06:59 +00:00
|
|
|
|
|
|
|
public:
|
2009-06-27 21:21:31 +00:00
|
|
|
virtual void Profile(FoldingSetNodeID &ID) const;
|
|
|
|
|
2009-06-22 21:39:50 +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-06-22 21:39:50 +00:00
|
|
|
const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym,
|
|
|
|
const SCEV* Conc,
|
2007-10-22 18:31:58 +00:00
|
|
|
ScalarEvolution &SE) const {
|
2009-06-22 21:39:50 +00:00
|
|
|
const SCEV* L = LHS->replaceSymbolicValuesWithConcrete(Sym, Conc, SE);
|
|
|
|
const SCEV* 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;
|
|
|
|
|
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-06-22 21:57:23 +00:00
|
|
|
SCEVAddRecExpr(const SmallVectorImpl<const SCEV*> &ops, const Loop *l)
|
|
|
|
: SCEVNAryExpr(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-06-27 21:21:31 +00:00
|
|
|
virtual void Profile(FoldingSetNodeID &ID) const;
|
|
|
|
|
2009-06-22 21:39:50 +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-06-22 21:39:50 +00:00
|
|
|
const SCEV* getStepRecurrence(ScalarEvolution &SE) const {
|
2008-06-22 19:23:09 +00:00
|
|
|
if (isAffine()) return getOperand(1);
|
2009-06-22 21:39:50 +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-06-22 21:39:50 +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-06-22 21:39:50 +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-06-22 21:39:50 +00:00
|
|
|
const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym,
|
|
|
|
const SCEV* Conc,
|
2007-10-22 18:31:58 +00:00
|
|
|
ScalarEvolution &SE) const;
|
2004-04-15 15:06:59 +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;
|
|
|
|
|
2009-06-22 21:57:23 +00:00
|
|
|
explicit SCEVSMaxExpr(const SmallVectorImpl<const SCEV*> &ops)
|
|
|
|
: SCEVCommutativeExpr(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-06-22 21:57:23 +00:00
|
|
|
explicit SCEVUMaxExpr(const SmallVectorImpl<const SCEV*> &ops)
|
|
|
|
: SCEVCommutativeExpr(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-06-22 21:57:23 +00:00
|
|
|
explicit SCEVUnknown(Value *v) :
|
|
|
|
SCEV(scUnknown), V(v) {}
|
2009-06-22 18:25:46 +00:00
|
|
|
|
2004-04-15 15:06:59 +00:00
|
|
|
public:
|
2009-06-27 21:21:31 +00:00
|
|
|
virtual void Profile(FoldingSetNodeID &ID) const;
|
|
|
|
|
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-06-22 21:39:50 +00:00
|
|
|
const SCEV* replaceSymbolicValuesWithConcrete(const SCEV* Sym,
|
|
|
|
const SCEV* Conc,
|
2007-10-22 18:31:58 +00:00
|
|
|
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;
|
|
|
|
|
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:
|
|
|
|
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
|