#include "llvm/Pass.h"
#include "llvm/Instructions.h"
#include "llvm/Function.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/System/DataTypes.h"
#include "llvm/Support/ValueHandle.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/ConstantRange.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/DenseMap.h"
-#include <iosfwd>
#include <map>
namespace llvm {
class Type;
class ScalarEvolution;
class TargetData;
- struct LLVMContext;
+ class LLVMContext;
class Loop;
class LoopInfo;
class Operator;
/// the specified basic block.
virtual bool dominates(BasicBlock *BB, DominatorTree *DT) const = 0;
+ /// properlyDominates - Return true if elements that makes up this SCEV
+ /// properly dominate the specified basic block.
+ virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const = 0;
+
/// print - Print out the internal representation of this scalar to the
/// specified stream. This should really only be used for debugging
/// purposes.
virtual void print(raw_ostream &OS) const = 0;
- void print(std::ostream &OS) const;
- void print(std::ostream *OS) const { if (OS) print(*OS); }
/// dump - This method is used for debugging.
///
return OS;
}
- inline std::ostream &operator<<(std::ostream &OS, const SCEV &S) {
- S.print(OS);
- return OS;
- }
-
/// SCEVCouldNotCompute - An object of this class is returned by queries that
/// could not be answered. For example, if you ask for the number of
/// iterations of a linked-list traversal loop, you will get one of these.
return true;
}
+ virtual bool properlyDominates(BasicBlock *BB, DominatorTree *DT) const {
+ return true;
+ }
+
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const SCEVCouldNotCompute *S) { return true; }
static bool classof(const SCEV *S);
/// exit value.
std::map<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
- /// ValuesAtScopes - This map contains entries for all the instructions
- /// that we attempt to compute getSCEVAtScope information for without
- /// using SCEV techniques, which can be expensive.
- std::map<Instruction *, std::map<const Loop *, Constant *> > ValuesAtScopes;
+ /// ValuesAtScopes - This map contains entries for all the expressions
+ /// that we attempt to compute getSCEVAtScope information for, which can
+ /// be expensive in extreme cases.
+ std::map<const SCEV *,
+ std::map<const Loop *, const SCEV *> > ValuesAtScopes;
/// createSCEV - We know that there is no SCEV for the specified value.
/// Analyze the expression.
/// createNodeForGEP - Provide the special handling we need to analyze GEP
/// SCEVs.
- const SCEV *createNodeForGEP(Operator *GEP);
+ const SCEV *createNodeForGEP(GEPOperator *GEP);
+
+ /// computeSCEVAtScope - Implementation code for getSCEVAtScope; called
+ /// at most once for each SCEV+Loop pair.
+ ///
+ const SCEV *computeSCEVAtScope(const SCEV *S, const Loop *L);
/// ForgetSymbolicValue - This looks up computed SCEV values for all
/// instructions that depend on the given instruction and removes them from
/// CouldNotCompute if an intermediate computation overflows.
const SCEV *getBECount(const SCEV *Start,
const SCEV *End,
- const SCEV *Step);
+ const SCEV *Step,
+ bool NoWrap);
/// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given
/// loop, lazily computing new values if the loop hasn't been analyzed
/// this is the pointer-sized integer type.
const Type *getEffectiveSCEVType(const Type *Ty) const;
- /// getSCEV - Return a SCEV expression handle for the full generality of the
+ /// getSCEV - Return a SCEV expression for the full generality of the
/// specified expression.
const SCEV *getSCEV(Value *V);
const SCEV *getZeroExtendExpr(const SCEV *Op, const Type *Ty);
const SCEV *getSignExtendExpr(const SCEV *Op, const Type *Ty);
const SCEV *getAnyExtendExpr(const SCEV *Op, const Type *Ty);
- const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops);
- const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS) {
+ const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
+ bool HasNUW = false, bool HasNSW = false);
+ const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS,
+ bool HasNUW = false, bool HasNSW = false) {
SmallVector<const SCEV *, 2> Ops;
Ops.push_back(LHS);
Ops.push_back(RHS);
- return getAddExpr(Ops);
+ return getAddExpr(Ops, HasNUW, HasNSW);
}
const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1,
- const SCEV *Op2) {
+ const SCEV *Op2,
+ bool HasNUW = false, bool HasNSW = false) {
SmallVector<const SCEV *, 3> Ops;
Ops.push_back(Op0);
Ops.push_back(Op1);
Ops.push_back(Op2);
- return getAddExpr(Ops);
+ return getAddExpr(Ops, HasNUW, HasNSW);
}
- const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops);
- const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS) {
+ const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
+ bool HasNUW = false, bool HasNSW = false);
+ const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS,
+ bool HasNUW = false, bool HasNSW = false) {
SmallVector<const SCEV *, 2> Ops;
Ops.push_back(LHS);
Ops.push_back(RHS);
- return getMulExpr(Ops);
+ return getMulExpr(Ops, HasNUW, HasNSW);
}
const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
- const Loop *L);
+ const Loop *L,
+ bool HasNUW = false, bool HasNSW = false);
const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
- const Loop *L);
+ const Loop *L,
+ bool HasNUW = false, bool HasNSW = false);
const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
- const Loop *L) {
+ const Loop *L,
+ bool HasNUW = false, bool HasNSW = false) {
SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
- return getAddRecExpr(NewOp, L);
+ return getAddRecExpr(NewOp, L, HasNUW, HasNSW);
}
const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
const SCEV *getUMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
const SCEV *getSMinExpr(const SCEV *LHS, const SCEV *RHS);
const SCEV *getUMinExpr(const SCEV *LHS, const SCEV *RHS);
+ const SCEV *getFieldOffsetExpr(const StructType *STy, unsigned FieldNo);
+ const SCEV *getAllocSizeExpr(const Type *AllocTy);
const SCEV *getUnknown(Value *V);
const SCEV *getCouldNotCompute();
const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS,
const SCEV *RHS);
- /// getSCEVAtScope - Return a SCEV expression handle for the specified value
+ /// getSCEVAtScope - Return a SCEV expression for the specified value
/// at the specified scope in the program. The L value specifies a loop
/// nest to evaluate the expression at, where null is the top-level or a
/// specified loop is immediately inside of the loop.
/// has an analyzable loop-invariant backedge-taken count.
bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
- /// forgetLoopBackedgeTakenCount - This method should be called by the
- /// client when it has changed a loop in a way that may effect
- /// ScalarEvolution's ability to compute a trip count, or if the loop
- /// is deleted.
- void forgetLoopBackedgeTakenCount(const Loop *L);
+ /// forgetLoop - This method should be called by the client when it has
+ /// changed a loop in a way that may effect ScalarEvolution's ability to
+ /// compute a trip count, or if the loop is deleted.
+ void forgetLoop(const Loop *L);
/// GetMinTrailingZeros - Determine the minimum number of zero bits that S
/// is guaranteed to end in (at every loop iteration). It is, at the same
virtual bool runOnFunction(Function &F);
virtual void releaseMemory();
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
- void print(raw_ostream &OS, const Module* = 0) const;
- virtual void print(std::ostream &OS, const Module* = 0) const;
- void print(std::ostream *OS, const Module* M = 0) const {
- if (OS) print(*OS, M);
- }
+ virtual void print(raw_ostream &OS, const Module* = 0) const;
private:
FoldingSet<SCEV> UniqueSCEVs;