2004-04-02 20:23:17 +00:00
|
|
|
//===- llvm/Analysis/ScalarEvolution.h - Scalar Evolution -------*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2004-04-02 20:23:17 +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-02 20:23:17 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The ScalarEvolution class is an LLVM pass which can be used to analyze and
|
2010-03-01 17:49:51 +00:00
|
|
|
// categorize scalar expressions in loops. It specializes in recognizing
|
2004-04-02 20:23:17 +00:00
|
|
|
// general induction variables, representing them with the abstract and opaque
|
|
|
|
// SCEV class. Given this analysis, trip counts of loops and other important
|
|
|
|
// properties can be obtained.
|
|
|
|
//
|
|
|
|
// This analysis is primarily useful for induction variable substitution and
|
|
|
|
// strength reduction.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2004-04-02 20:23:17 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H
|
|
|
|
#define LLVM_ANALYSIS_SCALAREVOLUTION_H
|
|
|
|
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Operator.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Pass.h"
|
2009-06-27 21:21:31 +00:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2009-07-13 21:35:55 +00:00
|
|
|
#include "llvm/Support/ConstantRange.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2009-07-13 22:19:41 +00:00
|
|
|
#include <map>
|
2004-04-02 20:23:17 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2007-10-22 18:31:58 +00:00
|
|
|
class APInt;
|
2009-07-13 22:19:41 +00:00
|
|
|
class Constant;
|
2007-10-22 18:31:58 +00:00
|
|
|
class ConstantInt;
|
2009-07-13 22:19:41 +00:00
|
|
|
class DominatorTree;
|
2004-04-02 20:23:17 +00:00
|
|
|
class Type;
|
2007-10-22 18:31:58 +00:00
|
|
|
class ScalarEvolution;
|
2012-10-08 16:38:25 +00:00
|
|
|
class DataLayout;
|
2011-12-01 03:08:23 +00:00
|
|
|
class TargetLibraryInfo;
|
2009-08-11 17:45:13 +00:00
|
|
|
class LLVMContext;
|
2009-07-13 22:19:41 +00:00
|
|
|
class Loop;
|
|
|
|
class LoopInfo;
|
2009-07-17 21:03:54 +00:00
|
|
|
class Operator;
|
2010-07-28 17:09:24 +00:00
|
|
|
class SCEVUnknown;
|
2010-08-16 15:31:45 +00:00
|
|
|
class SCEV;
|
2010-08-16 17:01:55 +00:00
|
|
|
template<> struct FoldingSetTrait<SCEV>;
|
2004-04-02 20:23:17 +00:00
|
|
|
|
2009-05-24 23:45:28 +00:00
|
|
|
/// SCEV - This class represents an analyzed expression in the program. These
|
2009-06-24 04:47:54 +00:00
|
|
|
/// are opaque objects that the client is not allowed to do much with
|
|
|
|
/// directly.
|
2004-04-02 20:23:17 +00:00
|
|
|
///
|
2010-03-18 16:16:38 +00:00
|
|
|
class SCEV : public FoldingSetNode {
|
2010-08-16 17:01:55 +00:00
|
|
|
friend struct FoldingSetTrait<SCEV>;
|
2010-08-16 15:31:45 +00:00
|
|
|
|
2010-03-18 16:16:38 +00:00
|
|
|
/// FastID - A reference to an Interned FoldingSetNodeID for this node.
|
|
|
|
/// The ScalarEvolution's BumpPtrAllocator holds the data.
|
|
|
|
FoldingSetNodeIDRef FastID;
|
|
|
|
|
2009-07-24 00:59:53 +00:00
|
|
|
// The SCEV baseclass this node corresponds to
|
|
|
|
const unsigned short SCEVType;
|
2004-04-02 20:23:17 +00:00
|
|
|
|
2009-07-24 00:59:53 +00:00
|
|
|
protected:
|
|
|
|
/// SubclassData - This field is initialized to zero and may be used in
|
2010-03-01 17:49:51 +00:00
|
|
|
/// subclasses to store miscellaneous information.
|
2009-07-24 00:59:53 +00:00
|
|
|
unsigned short SubclassData;
|
|
|
|
|
|
|
|
private:
|
2012-09-17 06:43:55 +00:00
|
|
|
SCEV(const SCEV &) LLVM_DELETED_FUNCTION;
|
|
|
|
void operator=(const SCEV &) LLVM_DELETED_FUNCTION;
|
2010-11-17 22:27:42 +00:00
|
|
|
|
2004-04-02 20:23:17 +00:00
|
|
|
public:
|
2011-03-14 16:50:06 +00:00
|
|
|
/// NoWrapFlags are bitfield indices into SubclassData.
|
|
|
|
///
|
|
|
|
/// Add and Mul expressions may have no-unsigned-wrap <NUW> or
|
|
|
|
/// no-signed-wrap <NSW> properties, which are derived from the IR
|
|
|
|
/// operator. NSW is a misnomer that we use to mean no signed overflow or
|
|
|
|
/// underflow.
|
|
|
|
///
|
|
|
|
/// AddRec expression may have a no-self-wraparound <NW> property if the
|
|
|
|
/// result can never reach the start value. This property is independent of
|
|
|
|
/// the actual start value and step direction. Self-wraparound is defined
|
|
|
|
/// purely in terms of the recurrence's loop, step size, and
|
|
|
|
/// bitwidth. Formally, a recurrence with no self-wraparound satisfies:
|
|
|
|
/// abs(step) * max-iteration(loop) <= unsigned-max(bitwidth).
|
|
|
|
///
|
|
|
|
/// Note that NUW and NSW are also valid properties of a recurrence, and
|
|
|
|
/// either implies NW. For convenience, NW will be set for a recurrence
|
|
|
|
/// whenever either NUW or NSW are set.
|
|
|
|
enum NoWrapFlags { FlagAnyWrap = 0, // No guarantee.
|
|
|
|
FlagNW = (1 << 0), // No self-wrap.
|
|
|
|
FlagNUW = (1 << 1), // No unsigned wrap.
|
|
|
|
FlagNSW = (1 << 2), // No signed wrap.
|
|
|
|
NoWrapMask = (1 << 3) -1 };
|
|
|
|
|
2010-06-18 19:54:20 +00:00
|
|
|
explicit SCEV(const FoldingSetNodeIDRef ID, unsigned SCEVTy) :
|
|
|
|
FastID(ID), SCEVType(SCEVTy), SubclassData(0) {}
|
2009-06-27 21:21:31 +00:00
|
|
|
|
2004-04-02 20:23:17 +00:00
|
|
|
unsigned getSCEVType() const { return SCEVType; }
|
|
|
|
|
|
|
|
/// getType - Return the LLVM type of this SCEV expression.
|
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *getType() const;
|
2004-04-02 20:23:17 +00:00
|
|
|
|
2008-06-18 16:23:07 +00:00
|
|
|
/// isZero - Return true if the expression is a constant zero.
|
|
|
|
///
|
|
|
|
bool isZero() const;
|
|
|
|
|
2009-05-18 15:22:39 +00:00
|
|
|
/// isOne - Return true if the expression is a constant one.
|
|
|
|
///
|
|
|
|
bool isOne() const;
|
|
|
|
|
2009-06-24 00:30:26 +00:00
|
|
|
/// isAllOnesValue - Return true if the expression is a constant
|
|
|
|
/// all-ones value.
|
|
|
|
///
|
|
|
|
bool isAllOnesValue() const;
|
|
|
|
|
2012-01-07 00:27:31 +00:00
|
|
|
/// isNonConstantNegative - Return true if the specified scev is negated,
|
|
|
|
/// but not a constant.
|
|
|
|
bool isNonConstantNegative() const;
|
|
|
|
|
2004-04-02 20:23:17 +00:00
|
|
|
/// print - Print out the internal representation of this scalar to the
|
|
|
|
/// specified stream. This should really only be used for debugging
|
|
|
|
/// purposes.
|
2010-11-17 22:27:42 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2004-04-02 20:23:17 +00:00
|
|
|
|
|
|
|
/// dump - This method is used for debugging.
|
|
|
|
///
|
|
|
|
void dump() const;
|
|
|
|
};
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2010-08-16 15:31:45 +00:00
|
|
|
// Specialize FoldingSetTrait for SCEV to avoid needing to compute
|
|
|
|
// temporary FoldingSetNodeID values.
|
|
|
|
template<> struct FoldingSetTrait<SCEV> : DefaultFoldingSetTrait<SCEV> {
|
|
|
|
static void Profile(const SCEV &X, FoldingSetNodeID& ID) {
|
|
|
|
ID = X.FastID;
|
|
|
|
}
|
|
|
|
static bool Equals(const SCEV &X, const FoldingSetNodeID &ID,
|
2012-04-11 14:06:47 +00:00
|
|
|
unsigned IDHash, FoldingSetNodeID &TempID) {
|
2010-08-16 15:31:45 +00:00
|
|
|
return ID == X.FastID;
|
|
|
|
}
|
|
|
|
static unsigned ComputeHash(const SCEV &X, FoldingSetNodeID &TempID) {
|
|
|
|
return X.FastID.ComputeHash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-21 00:47:46 +00:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const SCEV &S) {
|
|
|
|
S.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2004-04-02 20:23:17 +00:00
|
|
|
/// 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.
|
|
|
|
/// None of the standard SCEV operations are valid on this class, it is just a
|
|
|
|
/// marker.
|
|
|
|
struct SCEVCouldNotCompute : public SCEV {
|
2009-06-22 21:57:23 +00:00
|
|
|
SCEVCouldNotCompute();
|
2004-04-02 20:23:17 +00:00
|
|
|
|
|
|
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
|
|
|
static bool classof(const SCEV *S);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// ScalarEvolution - This class is the main scalar evolution driver. Because
|
|
|
|
/// client code (intentionally) can't do much with the SCEV objects directly,
|
|
|
|
/// they must ask this class for services.
|
|
|
|
///
|
|
|
|
class ScalarEvolution : public FunctionPass {
|
2010-11-17 23:21:44 +00:00
|
|
|
public:
|
|
|
|
/// LoopDisposition - An enum describing the relationship between a
|
|
|
|
/// SCEV and a loop.
|
|
|
|
enum LoopDisposition {
|
|
|
|
LoopVariant, ///< The SCEV is loop-variant (unknown).
|
|
|
|
LoopInvariant, ///< The SCEV is loop-invariant.
|
|
|
|
LoopComputable ///< The SCEV varies predictably with the loop.
|
|
|
|
};
|
|
|
|
|
2010-11-18 00:34:22 +00:00
|
|
|
/// BlockDisposition - An enum describing the relationship between a
|
|
|
|
/// SCEV and a basic block.
|
|
|
|
enum BlockDisposition {
|
|
|
|
DoesNotDominateBlock, ///< The SCEV does not dominate the block.
|
|
|
|
DominatesBlock, ///< The SCEV dominates the block.
|
|
|
|
ProperlyDominatesBlock ///< The SCEV properly dominates the block.
|
|
|
|
};
|
|
|
|
|
2011-03-14 16:50:06 +00:00
|
|
|
/// Convenient NoWrapFlags manipulation that hides enum casts and is
|
|
|
|
/// visible in the ScalarEvolution name space.
|
|
|
|
static SCEV::NoWrapFlags maskFlags(SCEV::NoWrapFlags Flags, int Mask) {
|
|
|
|
return (SCEV::NoWrapFlags)(Flags & Mask);
|
|
|
|
}
|
|
|
|
static SCEV::NoWrapFlags setFlags(SCEV::NoWrapFlags Flags,
|
|
|
|
SCEV::NoWrapFlags OnFlags) {
|
|
|
|
return (SCEV::NoWrapFlags)(Flags | OnFlags);
|
|
|
|
}
|
|
|
|
static SCEV::NoWrapFlags clearFlags(SCEV::NoWrapFlags Flags,
|
|
|
|
SCEV::NoWrapFlags OffFlags) {
|
|
|
|
return (SCEV::NoWrapFlags)(Flags & ~OffFlags);
|
|
|
|
}
|
|
|
|
|
2010-11-17 23:21:44 +00:00
|
|
|
private:
|
2009-05-19 19:22:47 +00:00
|
|
|
/// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
|
|
|
|
/// notified whenever a Value is deleted.
|
|
|
|
class SCEVCallbackVH : public CallbackVH {
|
|
|
|
ScalarEvolution *SE;
|
|
|
|
virtual void deleted();
|
|
|
|
virtual void allUsesReplacedWith(Value *New);
|
|
|
|
public:
|
|
|
|
SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0);
|
|
|
|
};
|
|
|
|
|
2009-05-04 22:30:44 +00:00
|
|
|
friend class SCEVCallbackVH;
|
2010-01-21 15:40:14 +00:00
|
|
|
friend class SCEVExpander;
|
2010-07-28 17:09:24 +00:00
|
|
|
friend class SCEVUnknown;
|
2009-05-04 22:30:44 +00:00
|
|
|
|
2009-04-21 23:15:49 +00:00
|
|
|
/// F - The function we are analyzing.
|
|
|
|
///
|
|
|
|
Function *F;
|
|
|
|
|
|
|
|
/// LI - The loop information for the function we are currently analyzing.
|
|
|
|
///
|
|
|
|
LoopInfo *LI;
|
|
|
|
|
2010-03-01 17:49:51 +00:00
|
|
|
/// TD - The target data information for the target we are targeting.
|
2009-04-21 23:15:49 +00:00
|
|
|
///
|
2012-10-08 16:38:25 +00:00
|
|
|
DataLayout *TD;
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2011-12-01 03:08:23 +00:00
|
|
|
/// TLI - The target library information for the target we are targeting.
|
|
|
|
///
|
|
|
|
TargetLibraryInfo *TLI;
|
|
|
|
|
2010-01-19 22:21:27 +00:00
|
|
|
/// DT - The dominator tree.
|
|
|
|
///
|
|
|
|
DominatorTree *DT;
|
|
|
|
|
2009-06-06 14:37:11 +00:00
|
|
|
/// CouldNotCompute - This SCEV is used to represent unknown trip
|
|
|
|
/// counts and things.
|
2009-06-27 21:21:31 +00:00
|
|
|
SCEVCouldNotCompute CouldNotCompute;
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2010-08-27 18:55:03 +00:00
|
|
|
/// ValueExprMapType - The typedef for ValueExprMap.
|
2009-04-21 23:15:49 +00:00
|
|
|
///
|
2010-08-27 18:55:03 +00:00
|
|
|
typedef DenseMap<SCEVCallbackVH, const SCEV *, DenseMapInfo<Value *> >
|
|
|
|
ValueExprMapType;
|
|
|
|
|
|
|
|
/// ValueExprMap - This is a cache of the values we have analyzed so far.
|
|
|
|
///
|
|
|
|
ValueExprMapType ValueExprMap;
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2012-05-19 00:48:25 +00:00
|
|
|
/// Mark predicate values currently being processed by isImpliedCond.
|
|
|
|
DenseSet<Value*> PendingLoopPredicates;
|
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
/// ExitLimit - Information about the number of loop iterations for
|
|
|
|
/// which a loop exit's branch condition evaluates to the not-taken path.
|
|
|
|
/// This is a temporary pair of exact and max expressions that are
|
|
|
|
/// eventually summarized in ExitNotTakenInfo and BackedgeTakenInfo.
|
|
|
|
struct ExitLimit {
|
|
|
|
const SCEV *Exact;
|
|
|
|
const SCEV *Max;
|
|
|
|
|
|
|
|
/*implicit*/ ExitLimit(const SCEV *E) : Exact(E), Max(E) {}
|
|
|
|
|
|
|
|
ExitLimit(const SCEV *E, const SCEV *M) : Exact(E), Max(M) {}
|
|
|
|
|
|
|
|
/// hasAnyInfo - Test whether this ExitLimit contains any computed
|
|
|
|
/// information, or whether it's all SCEVCouldNotCompute values.
|
|
|
|
bool hasAnyInfo() const {
|
|
|
|
return !isa<SCEVCouldNotCompute>(Exact) ||
|
|
|
|
!isa<SCEVCouldNotCompute>(Max);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// ExitNotTakenInfo - Information about the number of times a particular
|
|
|
|
/// loop exit may be reached before exiting the loop.
|
|
|
|
struct ExitNotTakenInfo {
|
2011-08-03 18:32:11 +00:00
|
|
|
AssertingVH<BasicBlock> ExitingBlock;
|
2011-07-26 17:19:55 +00:00
|
|
|
const SCEV *ExactNotTaken;
|
|
|
|
PointerIntPair<ExitNotTakenInfo*, 1> NextExit;
|
|
|
|
|
2011-08-02 04:23:35 +00:00
|
|
|
ExitNotTakenInfo() : ExitingBlock(0), ExactNotTaken(0) {}
|
2011-07-26 17:19:55 +00:00
|
|
|
|
|
|
|
/// isCompleteList - Return true if all loop exits are computable.
|
|
|
|
bool isCompleteList() const {
|
|
|
|
return NextExit.getInt() == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIncomplete() { NextExit.setInt(1); }
|
|
|
|
|
|
|
|
/// getNextExit - Return a pointer to the next exit's not-taken info.
|
|
|
|
ExitNotTakenInfo *getNextExit() const {
|
|
|
|
return NextExit.getPointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setNextExit(ExitNotTakenInfo *ENT) { NextExit.setPointer(ENT); }
|
|
|
|
};
|
|
|
|
|
2009-04-30 20:47:05 +00:00
|
|
|
/// BackedgeTakenInfo - Information about the backedge-taken count
|
2010-03-01 17:49:51 +00:00
|
|
|
/// of a loop. This currently includes an exact count and a maximum count.
|
2009-04-30 20:47:05 +00:00
|
|
|
///
|
2011-07-26 17:19:55 +00:00
|
|
|
class BackedgeTakenInfo {
|
|
|
|
/// ExitNotTaken - A list of computable exits and their not-taken counts.
|
|
|
|
/// Loops almost never have more than one computable exit.
|
|
|
|
ExitNotTakenInfo ExitNotTaken;
|
2009-04-30 20:47:05 +00:00
|
|
|
|
2009-07-09 22:14:25 +00:00
|
|
|
/// Max - An expression indicating the least maximum backedge-taken
|
2009-04-30 20:47:05 +00:00
|
|
|
/// count of the loop that is known, or a SCEVCouldNotCompute.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *Max;
|
2009-04-30 20:47:05 +00:00
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
public:
|
|
|
|
BackedgeTakenInfo() : Max(0) {}
|
2009-04-30 20:47:05 +00:00
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
/// Initialize BackedgeTakenInfo from a list of exact exit counts.
|
|
|
|
BackedgeTakenInfo(
|
|
|
|
SmallVectorImpl< std::pair<BasicBlock *, const SCEV *> > &ExitCounts,
|
|
|
|
bool Complete, const SCEV *MaxCount);
|
2009-04-30 20:47:05 +00:00
|
|
|
|
|
|
|
/// hasAnyInfo - Test whether this BackedgeTakenInfo contains any
|
|
|
|
/// computed information, or whether it's all SCEVCouldNotCompute
|
|
|
|
/// values.
|
|
|
|
bool hasAnyInfo() const {
|
2011-08-02 04:23:35 +00:00
|
|
|
return ExitNotTaken.ExitingBlock || !isa<SCEVCouldNotCompute>(Max);
|
2009-04-30 20:47:05 +00:00
|
|
|
}
|
2011-07-26 17:19:55 +00:00
|
|
|
|
|
|
|
/// getExact - Return an expression indicating the exact backedge-taken
|
|
|
|
/// count of the loop if it is known, or SCEVCouldNotCompute
|
|
|
|
/// otherwise. This is the number of times the loop header can be
|
|
|
|
/// guaranteed to execute, minus one.
|
|
|
|
const SCEV *getExact(ScalarEvolution *SE) const;
|
|
|
|
|
|
|
|
/// getExact - Return the number of times this loop exit may fall through
|
2011-09-02 21:20:46 +00:00
|
|
|
/// to the back edge, or SCEVCouldNotCompute. The loop is guaranteed not
|
|
|
|
/// to exit via this block before this number of iterations, but may exit
|
|
|
|
/// via another block.
|
2011-08-02 04:23:35 +00:00
|
|
|
const SCEV *getExact(BasicBlock *ExitingBlock, ScalarEvolution *SE) const;
|
2011-07-26 17:19:55 +00:00
|
|
|
|
|
|
|
/// getMax - Get the max backedge taken count for the loop.
|
|
|
|
const SCEV *getMax(ScalarEvolution *SE) const;
|
|
|
|
|
2013-03-26 03:14:53 +00:00
|
|
|
/// Return true if any backedge taken count expressions refer to the given
|
|
|
|
/// subexpression.
|
|
|
|
bool hasOperand(const SCEV *S, ScalarEvolution *SE) const;
|
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
/// clear - Invalidate this result and free associated memory.
|
|
|
|
void clear();
|
2009-04-30 20:47:05 +00:00
|
|
|
};
|
|
|
|
|
2009-04-21 23:15:49 +00:00
|
|
|
/// BackedgeTakenCounts - Cache the backedge-taken count of the loops for
|
|
|
|
/// this function as they are computed.
|
2011-05-09 18:44:09 +00:00
|
|
|
DenseMap<const Loop*, BackedgeTakenInfo> BackedgeTakenCounts;
|
2009-04-21 23:15:49 +00:00
|
|
|
|
|
|
|
/// ConstantEvolutionLoopExitValue - This map contains entries for all of
|
|
|
|
/// the PHI instructions that we attempt to compute constant evolutions for.
|
|
|
|
/// This allows us to avoid potentially expensive recomputation of these
|
|
|
|
/// properties. An instruction maps to null if we are unable to compute its
|
|
|
|
/// exit value.
|
2011-05-09 18:44:09 +00:00
|
|
|
DenseMap<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2009-08-31 21:15:23 +00:00
|
|
|
/// ValuesAtScopes - This map contains entries for all the expressions
|
|
|
|
/// that we attempt to compute getSCEVAtScope information for, which can
|
|
|
|
/// be expensive in extreme cases.
|
2011-05-09 18:44:09 +00:00
|
|
|
DenseMap<const SCEV *,
|
2009-08-31 21:15:23 +00:00
|
|
|
std::map<const Loop *, const SCEV *> > ValuesAtScopes;
|
2009-05-08 20:47:27 +00:00
|
|
|
|
2010-11-17 23:21:44 +00:00
|
|
|
/// LoopDispositions - Memoized computeLoopDisposition results.
|
2011-05-09 18:44:09 +00:00
|
|
|
DenseMap<const SCEV *,
|
2010-11-17 23:21:44 +00:00
|
|
|
std::map<const Loop *, LoopDisposition> > LoopDispositions;
|
|
|
|
|
|
|
|
/// computeLoopDisposition - Compute a LoopDisposition value.
|
|
|
|
LoopDisposition computeLoopDisposition(const SCEV *S, const Loop *L);
|
|
|
|
|
2010-11-18 00:34:22 +00:00
|
|
|
/// BlockDispositions - Memoized computeBlockDisposition results.
|
2011-05-09 18:44:09 +00:00
|
|
|
DenseMap<const SCEV *,
|
2010-11-18 00:34:22 +00:00
|
|
|
std::map<const BasicBlock *, BlockDisposition> > BlockDispositions;
|
|
|
|
|
|
|
|
/// computeBlockDisposition - Compute a BlockDisposition value.
|
|
|
|
BlockDisposition computeBlockDisposition(const SCEV *S, const BasicBlock *BB);
|
|
|
|
|
2010-11-17 02:44:44 +00:00
|
|
|
/// UnsignedRanges - Memoized results from getUnsignedRange
|
|
|
|
DenseMap<const SCEV *, ConstantRange> UnsignedRanges;
|
|
|
|
|
|
|
|
/// SignedRanges - Memoized results from getSignedRange
|
|
|
|
DenseMap<const SCEV *, ConstantRange> SignedRanges;
|
|
|
|
|
2010-11-17 20:23:08 +00:00
|
|
|
/// setUnsignedRange - Set the memoized unsigned range for the given SCEV.
|
|
|
|
const ConstantRange &setUnsignedRange(const SCEV *S,
|
|
|
|
const ConstantRange &CR) {
|
|
|
|
std::pair<DenseMap<const SCEV *, ConstantRange>::iterator, bool> Pair =
|
|
|
|
UnsignedRanges.insert(std::make_pair(S, CR));
|
|
|
|
if (!Pair.second)
|
|
|
|
Pair.first->second = CR;
|
|
|
|
return Pair.first->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// setUnsignedRange - Set the memoized signed range for the given SCEV.
|
|
|
|
const ConstantRange &setSignedRange(const SCEV *S,
|
|
|
|
const ConstantRange &CR) {
|
|
|
|
std::pair<DenseMap<const SCEV *, ConstantRange>::iterator, bool> Pair =
|
|
|
|
SignedRanges.insert(std::make_pair(S, CR));
|
|
|
|
if (!Pair.second)
|
|
|
|
Pair.first->second = CR;
|
|
|
|
return Pair.first->second;
|
|
|
|
}
|
|
|
|
|
2009-04-21 23:15:49 +00:00
|
|
|
/// createSCEV - We know that there is no SCEV for the specified value.
|
|
|
|
/// Analyze the expression.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *createSCEV(Value *V);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
|
|
|
/// createNodeForPHI - Provide the special handling we need to analyze PHI
|
|
|
|
/// SCEVs.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *createNodeForPHI(PHINode *PN);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2009-05-08 20:26:55 +00:00
|
|
|
/// createNodeForGEP - Provide the special handling we need to analyze GEP
|
|
|
|
/// SCEVs.
|
2009-12-18 02:09:29 +00:00
|
|
|
const SCEV *createNodeForGEP(GEPOperator *GEP);
|
2009-05-08 20:26:55 +00:00
|
|
|
|
2009-08-31 21:15:23 +00:00
|
|
|
/// computeSCEVAtScope - Implementation code for getSCEVAtScope; called
|
|
|
|
/// at most once for each SCEV+Loop pair.
|
|
|
|
///
|
|
|
|
const SCEV *computeSCEVAtScope(const SCEV *S, const Loop *L);
|
|
|
|
|
2009-07-25 01:13:03 +00:00
|
|
|
/// ForgetSymbolicValue - This looks up computed SCEV values for all
|
|
|
|
/// instructions that depend on the given instruction and removes them from
|
2010-08-27 18:55:03 +00:00
|
|
|
/// the ValueExprMap map if they reference SymName. This is used during PHI
|
2009-07-25 01:13:03 +00:00
|
|
|
/// resolution.
|
|
|
|
void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2009-06-21 23:46:38 +00:00
|
|
|
/// getBECount - Subtract the end and start values and divide by the step,
|
|
|
|
/// rounding up, to get the number of times the backedge is executed. Return
|
|
|
|
/// CouldNotCompute if an intermediate computation overflows.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getBECount(const SCEV *Start,
|
2009-07-24 00:55:33 +00:00
|
|
|
const SCEV *End,
|
2009-09-17 18:05:20 +00:00
|
|
|
const SCEV *Step,
|
|
|
|
bool NoWrap);
|
2009-06-21 23:46:38 +00:00
|
|
|
|
2009-04-30 20:47:05 +00:00
|
|
|
/// getBackedgeTakenInfo - Return the BackedgeTakenInfo for the given
|
|
|
|
/// loop, lazily computing new values if the loop hasn't been analyzed
|
|
|
|
/// yet.
|
|
|
|
const BackedgeTakenInfo &getBackedgeTakenInfo(const Loop *L);
|
|
|
|
|
2009-04-21 23:15:49 +00:00
|
|
|
/// ComputeBackedgeTakenCount - Compute the number of times the specified
|
|
|
|
/// loop will iterate.
|
2009-04-30 20:47:05 +00:00
|
|
|
BackedgeTakenInfo ComputeBackedgeTakenCount(const Loop *L);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
/// ComputeExitLimit - Compute the number of times the backedge of the
|
|
|
|
/// specified loop will execute if it exits via the specified block.
|
|
|
|
ExitLimit ComputeExitLimit(const Loop *L, BasicBlock *ExitingBlock);
|
|
|
|
|
|
|
|
/// ComputeExitLimitFromCond - Compute the number of times the backedge of
|
|
|
|
/// the specified loop will execute if its exit condition were a conditional
|
|
|
|
/// branch of ExitCond, TBB, and FBB.
|
|
|
|
ExitLimit ComputeExitLimitFromCond(const Loop *L,
|
|
|
|
Value *ExitCond,
|
|
|
|
BasicBlock *TBB,
|
|
|
|
BasicBlock *FBB);
|
|
|
|
|
|
|
|
/// ComputeExitLimitFromICmp - Compute the number of times the backedge of
|
|
|
|
/// the specified loop will execute if its exit condition were a conditional
|
|
|
|
/// branch of the ICmpInst ExitCond, TBB, and FBB.
|
|
|
|
ExitLimit ComputeExitLimitFromICmp(const Loop *L,
|
|
|
|
ICmpInst *ExitCond,
|
|
|
|
BasicBlock *TBB,
|
|
|
|
BasicBlock *FBB);
|
|
|
|
|
|
|
|
/// ComputeLoadConstantCompareExitLimit - Given an exit condition
|
2009-07-25 16:18:38 +00:00
|
|
|
/// of 'icmp op load X, cst', try to see if we can compute the
|
|
|
|
/// backedge-taken count.
|
2011-07-26 17:19:55 +00:00
|
|
|
ExitLimit ComputeLoadConstantCompareExitLimit(LoadInst *LI,
|
|
|
|
Constant *RHS,
|
|
|
|
const Loop *L,
|
|
|
|
ICmpInst::Predicate p);
|
|
|
|
|
|
|
|
/// ComputeExitCountExhaustively - If the loop is known to execute a
|
|
|
|
/// constant number of times (the condition evolves only from constants),
|
2009-04-21 23:15:49 +00:00
|
|
|
/// try to evaluate a few iterations of the loop until we get the exit
|
|
|
|
/// condition gets a value of ExitWhen (true or false). If we cannot
|
2011-07-26 17:19:55 +00:00
|
|
|
/// evaluate the exit count of the loop, return CouldNotCompute.
|
|
|
|
const SCEV *ComputeExitCountExhaustively(const Loop *L,
|
|
|
|
Value *Cond,
|
|
|
|
bool ExitWhen);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
/// HowFarToZero - Return the number of times an exit condition comparing
|
|
|
|
/// the specified value to zero will execute. If not computable, return
|
2009-06-06 14:37:11 +00:00
|
|
|
/// CouldNotCompute.
|
2011-07-26 17:19:55 +00:00
|
|
|
ExitLimit HowFarToZero(const SCEV *V, const Loop *L);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
/// HowFarToNonZero - Return the number of times an exit condition checking
|
|
|
|
/// the specified value for nonzero will execute. If not computable, return
|
2009-06-06 14:37:11 +00:00
|
|
|
/// CouldNotCompute.
|
2011-07-26 17:19:55 +00:00
|
|
|
ExitLimit HowFarToNonZero(const SCEV *V, const Loop *L);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
/// HowManyLessThans - Return the number of times an exit condition
|
|
|
|
/// containing the specified less-than comparison will execute. If not
|
|
|
|
/// computable, return CouldNotCompute. isSigned specifies whether the
|
|
|
|
/// less-than is signed.
|
|
|
|
ExitLimit HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
|
|
|
|
const Loop *L, bool isSigned);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
|
|
|
/// getPredecessorWithUniqueSuccessorForBB - Return a predecessor of BB
|
|
|
|
/// (which may not be an immediate predecessor) which has exactly one
|
|
|
|
/// successor from which BB is reachable, or null if no such block is
|
|
|
|
/// found.
|
2010-04-15 16:19:08 +00:00
|
|
|
std::pair<BasicBlock *, BasicBlock *>
|
|
|
|
getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
2010-08-10 23:46:30 +00:00
|
|
|
/// isImpliedCond - Test whether the condition described by Pred, LHS, and
|
|
|
|
/// RHS is true whenever the given FoundCondValue value evaluates to true.
|
|
|
|
bool isImpliedCond(ICmpInst::Predicate Pred,
|
2009-07-21 23:03:19 +00:00
|
|
|
const SCEV *LHS, const SCEV *RHS,
|
2010-08-10 23:46:30 +00:00
|
|
|
Value *FoundCondValue,
|
2009-07-21 23:03:19 +00:00
|
|
|
bool Inverse);
|
|
|
|
|
|
|
|
/// isImpliedCondOperands - Test whether the condition described by Pred,
|
2010-03-01 17:49:51 +00:00
|
|
|
/// LHS, and RHS is true whenever the condition described by Pred, FoundLHS,
|
2009-07-21 23:03:19 +00:00
|
|
|
/// and FoundRHS is true.
|
|
|
|
bool isImpliedCondOperands(ICmpInst::Predicate Pred,
|
|
|
|
const SCEV *LHS, const SCEV *RHS,
|
|
|
|
const SCEV *FoundLHS, const SCEV *FoundRHS);
|
|
|
|
|
|
|
|
/// isImpliedCondOperandsHelper - Test whether the condition described by
|
2010-03-01 17:49:51 +00:00
|
|
|
/// Pred, LHS, and RHS is true whenever the condition described by Pred,
|
2009-07-21 23:03:19 +00:00
|
|
|
/// FoundLHS, and FoundRHS is true.
|
|
|
|
bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred,
|
|
|
|
const SCEV *LHS, const SCEV *RHS,
|
2011-08-11 23:36:16 +00:00
|
|
|
const SCEV *FoundLHS,
|
|
|
|
const SCEV *FoundRHS);
|
2009-07-13 21:35:55 +00:00
|
|
|
|
2009-04-21 23:15:49 +00:00
|
|
|
/// getConstantEvolutionLoopExitValue - If we know that the specified Phi is
|
|
|
|
/// in the header of its containing loop, we know the loop executes a
|
|
|
|
/// constant number of times, and the PHI node is just a recurrence
|
|
|
|
/// involving constants, fold it.
|
|
|
|
Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs,
|
|
|
|
const Loop *L);
|
|
|
|
|
2010-04-11 22:16:48 +00:00
|
|
|
/// isKnownPredicateWithRanges - Test if the given expression is known to
|
|
|
|
/// satisfy the condition described by Pred and the known constant ranges
|
|
|
|
/// of LHS and RHS.
|
|
|
|
///
|
|
|
|
bool isKnownPredicateWithRanges(ICmpInst::Predicate Pred,
|
|
|
|
const SCEV *LHS, const SCEV *RHS);
|
|
|
|
|
2010-11-17 23:28:48 +00:00
|
|
|
/// forgetMemoizedResults - Drop memoized information computed for S.
|
|
|
|
void forgetMemoizedResults(const SCEV *S);
|
|
|
|
|
2004-04-02 20:23:17 +00:00
|
|
|
public:
|
2007-05-06 13:37:16 +00:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2009-04-21 23:15:49 +00:00
|
|
|
ScalarEvolution();
|
2005-04-21 20:19:05 +00:00
|
|
|
|
2009-07-22 00:24:57 +00:00
|
|
|
LLVMContext &getContext() const { return F->getContext(); }
|
2009-07-06 18:42:36 +00:00
|
|
|
|
2009-04-21 01:07:12 +00:00
|
|
|
/// isSCEVable - Test if values of the given type are analyzable within
|
|
|
|
/// the SCEV framework. This primarily includes integer types, and it
|
|
|
|
/// can optionally include pointer types if the ScalarEvolution class
|
|
|
|
/// has access to target-specific information.
|
2011-07-18 04:54:35 +00:00
|
|
|
bool isSCEVable(Type *Ty) const;
|
2009-04-21 01:07:12 +00:00
|
|
|
|
|
|
|
/// getTypeSizeInBits - Return the size in bits of the specified type,
|
|
|
|
/// for which isSCEVable must return true.
|
2011-07-18 04:54:35 +00:00
|
|
|
uint64_t getTypeSizeInBits(Type *Ty) const;
|
2009-04-21 01:07:12 +00:00
|
|
|
|
|
|
|
/// getEffectiveSCEVType - Return a type with the same bitwidth as
|
|
|
|
/// the given type and which represents how SCEV will treat the given
|
|
|
|
/// type, for which isSCEVable must return true. For pointer types,
|
|
|
|
/// this is the pointer-sized integer type.
|
2011-07-18 04:54:35 +00:00
|
|
|
Type *getEffectiveSCEVType(Type *Ty) const;
|
2009-04-16 03:18:22 +00:00
|
|
|
|
2009-09-03 15:00:26 +00:00
|
|
|
/// getSCEV - Return a SCEV expression for the full generality of the
|
2004-04-02 20:23:17 +00:00
|
|
|
/// specified expression.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getSCEV(Value *V);
|
|
|
|
|
|
|
|
const SCEV *getConstant(ConstantInt *V);
|
|
|
|
const SCEV *getConstant(const APInt& Val);
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getConstant(Type *Ty, uint64_t V, bool isSigned = false);
|
|
|
|
const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty);
|
|
|
|
const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty);
|
|
|
|
const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty);
|
|
|
|
const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty);
|
2009-10-09 00:10:36 +00:00
|
|
|
const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
|
2011-03-14 16:50:06 +00:00
|
|
|
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
|
2009-10-09 00:10:36 +00:00
|
|
|
const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS,
|
2011-03-14 16:50:06 +00:00
|
|
|
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) {
|
2009-07-07 17:06:11 +00:00
|
|
|
SmallVector<const SCEV *, 2> Ops;
|
2007-10-22 18:31:58 +00:00
|
|
|
Ops.push_back(LHS);
|
|
|
|
Ops.push_back(RHS);
|
2011-03-14 16:50:06 +00:00
|
|
|
return getAddExpr(Ops, Flags);
|
2007-10-22 18:31:58 +00:00
|
|
|
}
|
2011-03-14 16:50:06 +00:00
|
|
|
const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2,
|
|
|
|
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) {
|
2009-07-07 17:06:11 +00:00
|
|
|
SmallVector<const SCEV *, 3> Ops;
|
2007-10-22 18:31:58 +00:00
|
|
|
Ops.push_back(Op0);
|
|
|
|
Ops.push_back(Op1);
|
|
|
|
Ops.push_back(Op2);
|
2011-03-14 16:50:06 +00:00
|
|
|
return getAddExpr(Ops, Flags);
|
2007-10-22 18:31:58 +00:00
|
|
|
}
|
2009-10-09 00:10:36 +00:00
|
|
|
const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
|
2011-03-14 16:50:06 +00:00
|
|
|
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
|
2009-10-09 00:10:36 +00:00
|
|
|
const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS,
|
2011-03-14 16:50:06 +00:00
|
|
|
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap)
|
|
|
|
{
|
2009-07-07 17:06:11 +00:00
|
|
|
SmallVector<const SCEV *, 2> Ops;
|
2007-10-22 18:31:58 +00:00
|
|
|
Ops.push_back(LHS);
|
|
|
|
Ops.push_back(RHS);
|
2011-03-14 16:50:06 +00:00
|
|
|
return getMulExpr(Ops, Flags);
|
2007-10-22 18:31:58 +00:00
|
|
|
}
|
2011-10-04 06:51:26 +00:00
|
|
|
const SCEV *getMulExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2,
|
|
|
|
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) {
|
|
|
|
SmallVector<const SCEV *, 3> Ops;
|
|
|
|
Ops.push_back(Op0);
|
|
|
|
Ops.push_back(Op1);
|
|
|
|
Ops.push_back(Op2);
|
|
|
|
return getMulExpr(Ops, Flags);
|
|
|
|
}
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
|
|
|
|
const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
|
2011-03-14 16:50:06 +00:00
|
|
|
const Loop *L, SCEV::NoWrapFlags Flags);
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
|
2011-03-14 16:50:06 +00:00
|
|
|
const Loop *L, SCEV::NoWrapFlags Flags);
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
|
2011-03-14 16:50:06 +00:00
|
|
|
const Loop *L, SCEV::NoWrapFlags Flags) {
|
2009-07-07 17:06:11 +00:00
|
|
|
SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
|
2011-03-14 16:50:06 +00:00
|
|
|
return getAddRecExpr(NewOp, L, Flags);
|
2007-10-22 18:31:58 +00:00
|
|
|
}
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
|
|
|
|
const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
|
|
|
|
const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS);
|
|
|
|
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 *getUnknown(Value *V);
|
|
|
|
const SCEV *getCouldNotCompute();
|
2007-10-22 18:31:58 +00:00
|
|
|
|
2010-02-01 18:27:38 +00:00
|
|
|
/// getSizeOfExpr - Return an expression for sizeof on the given type.
|
|
|
|
///
|
2012-11-01 08:07:29 +00:00
|
|
|
const SCEV *getSizeOfExpr(Type *AllocTy);
|
2010-02-01 18:27:38 +00:00
|
|
|
|
2010-02-02 21:10:27 +00:00
|
|
|
/// getAlignOfExpr - Return an expression for alignof on the given type.
|
2010-02-01 18:27:38 +00:00
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getAlignOfExpr(Type *AllocTy);
|
2010-02-01 18:27:38 +00:00
|
|
|
|
2010-02-02 21:10:27 +00:00
|
|
|
/// getOffsetOfExpr - Return an expression for offsetof on the given field.
|
2010-02-01 18:27:38 +00:00
|
|
|
///
|
2012-11-01 08:07:29 +00:00
|
|
|
const SCEV *getOffsetOfExpr(StructType *STy, unsigned FieldNo);
|
2010-02-01 18:27:38 +00:00
|
|
|
|
2010-02-02 21:10:27 +00:00
|
|
|
/// getOffsetOfExpr - Return an expression for offsetof on the given field.
|
2010-02-01 18:27:38 +00:00
|
|
|
///
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getOffsetOfExpr(Type *CTy, Constant *FieldNo);
|
2010-02-01 18:27:38 +00:00
|
|
|
|
2007-10-22 18:31:58 +00:00
|
|
|
/// getNegativeSCEV - Return the SCEV object corresponding to -V.
|
|
|
|
///
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getNegativeSCEV(const SCEV *V);
|
2007-10-22 18:31:58 +00:00
|
|
|
|
2008-02-20 06:48:22 +00:00
|
|
|
/// getNotSCEV - Return the SCEV object corresponding to ~V.
|
|
|
|
///
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getNotSCEV(const SCEV *V);
|
2008-02-20 06:48:22 +00:00
|
|
|
|
2011-03-14 16:50:06 +00:00
|
|
|
/// getMinusSCEV - Return LHS-RHS. Minus is represented in SCEV as A+B*-1.
|
2011-01-09 22:26:35 +00:00
|
|
|
const SCEV *getMinusSCEV(const SCEV *LHS, const SCEV *RHS,
|
2011-03-14 16:50:06 +00:00
|
|
|
SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
|
2007-10-22 18:31:58 +00:00
|
|
|
|
2008-06-13 04:38:55 +00:00
|
|
|
/// getTruncateOrZeroExtend - Return a SCEV corresponding to a conversion
|
|
|
|
/// of the input value to the specified type. If the type must be
|
|
|
|
/// extended, it is zero extended.
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty);
|
2008-06-13 04:38:55 +00:00
|
|
|
|
2009-02-18 17:22:41 +00:00
|
|
|
/// getTruncateOrSignExtend - Return a SCEV corresponding to a conversion
|
|
|
|
/// of the input value to the specified type. If the type must be
|
|
|
|
/// extended, it is sign extended.
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty);
|
2009-02-18 17:22:41 +00:00
|
|
|
|
2009-05-13 03:46:30 +00:00
|
|
|
/// getNoopOrZeroExtend - Return a SCEV corresponding to a conversion of
|
|
|
|
/// the input value to the specified type. If the type must be extended,
|
|
|
|
/// it is zero extended. The conversion must not be narrowing.
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getNoopOrZeroExtend(const SCEV *V, Type *Ty);
|
2009-05-13 03:46:30 +00:00
|
|
|
|
|
|
|
/// getNoopOrSignExtend - Return a SCEV corresponding to a conversion of
|
|
|
|
/// the input value to the specified type. If the type must be extended,
|
|
|
|
/// it is sign extended. The conversion must not be narrowing.
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getNoopOrSignExtend(const SCEV *V, Type *Ty);
|
2009-05-13 03:46:30 +00:00
|
|
|
|
2009-06-13 15:56:47 +00:00
|
|
|
/// getNoopOrAnyExtend - Return a SCEV corresponding to a conversion of
|
|
|
|
/// the input value to the specified type. If the type must be extended,
|
|
|
|
/// it is extended with unspecified bits. The conversion must not be
|
|
|
|
/// narrowing.
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getNoopOrAnyExtend(const SCEV *V, Type *Ty);
|
2009-06-13 15:56:47 +00:00
|
|
|
|
2009-05-13 03:46:30 +00:00
|
|
|
/// getTruncateOrNoop - Return a SCEV corresponding to a conversion of the
|
|
|
|
/// input value to the specified type. The conversion must not be
|
|
|
|
/// widening.
|
2011-07-18 04:54:35 +00:00
|
|
|
const SCEV *getTruncateOrNoop(const SCEV *V, Type *Ty);
|
2009-05-13 03:46:30 +00:00
|
|
|
|
2009-06-22 00:31:57 +00:00
|
|
|
/// getUMaxFromMismatchedTypes - Promote the operands to the wider of
|
|
|
|
/// the types using zero-extension, and then perform a umax operation
|
|
|
|
/// with them.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getUMaxFromMismatchedTypes(const SCEV *LHS,
|
2009-07-24 00:55:33 +00:00
|
|
|
const SCEV *RHS);
|
2009-06-22 00:31:57 +00:00
|
|
|
|
2009-06-22 15:03:27 +00:00
|
|
|
/// getUMinFromMismatchedTypes - Promote the operands to the wider of
|
|
|
|
/// the types using zero-extension, and then perform a umin operation
|
|
|
|
/// with them.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS,
|
|
|
|
const SCEV *RHS);
|
2009-06-22 15:03:27 +00:00
|
|
|
|
2011-03-17 23:51:11 +00:00
|
|
|
/// getPointerBase - Transitively follow the chain of pointer-type operands
|
|
|
|
/// until reaching a SCEV that does not have a single pointer operand. This
|
|
|
|
/// returns a SCEVUnknown pointer for well-formed pointer-type expressions,
|
|
|
|
/// but corner cases do exist.
|
|
|
|
const SCEV *getPointerBase(const SCEV *V);
|
|
|
|
|
2009-09-03 15:00:26 +00:00
|
|
|
/// getSCEVAtScope - Return a SCEV expression for the specified value
|
2004-04-02 20:23:17 +00:00
|
|
|
/// 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.
|
|
|
|
///
|
|
|
|
/// This method can be used to compute the exit value for a variable defined
|
|
|
|
/// in a loop by querying what the value will hold in the parent loop.
|
|
|
|
///
|
2009-05-24 23:25:42 +00:00
|
|
|
/// In the case that a relevant loop exit value cannot be computed, the
|
|
|
|
/// original value V is returned.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getSCEVAtScope(const SCEV *S, const Loop *L);
|
2009-05-08 20:38:54 +00:00
|
|
|
|
|
|
|
/// getSCEVAtScope - This is a convenience function which does
|
|
|
|
/// getSCEVAtScope(getSCEV(V), L).
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getSCEVAtScope(Value *V, const Loop *L);
|
2004-04-02 20:23:17 +00:00
|
|
|
|
2010-04-11 19:27:13 +00:00
|
|
|
/// isLoopEntryGuardedByCond - Test whether entry to the loop is protected
|
|
|
|
/// by a conditional between LHS and RHS. This is used to help avoid max
|
2009-07-13 21:35:55 +00:00
|
|
|
/// expressions in loop trip counts, and to eliminate casts.
|
2010-04-11 19:27:13 +00:00
|
|
|
bool isLoopEntryGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
|
|
|
|
const SCEV *LHS, const SCEV *RHS);
|
2009-02-12 22:19:27 +00:00
|
|
|
|
2009-07-13 21:35:55 +00:00
|
|
|
/// isLoopBackedgeGuardedByCond - Test whether the backedge of the loop is
|
|
|
|
/// protected by a conditional between LHS and RHS. This is used to
|
|
|
|
/// to eliminate casts.
|
|
|
|
bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
|
|
|
|
const SCEV *LHS, const SCEV *RHS);
|
|
|
|
|
2011-08-11 23:36:16 +00:00
|
|
|
/// getSmallConstantTripCount - Returns the maximum trip count of this loop
|
2012-01-11 06:52:55 +00:00
|
|
|
/// as a normal unsigned value. Returns 0 if the trip count is unknown or
|
|
|
|
/// not constant. This "trip count" assumes that control exits via
|
|
|
|
/// ExitingBlock. More precisely, it is the number of times that control may
|
|
|
|
/// reach ExitingBlock before taking the branch. For loops with multiple
|
|
|
|
/// exits, it may not be the number times that the loop header executes if
|
|
|
|
/// the loop exits prematurely via another branch.
|
|
|
|
unsigned getSmallConstantTripCount(Loop *L, BasicBlock *ExitingBlock);
|
2011-08-11 23:36:16 +00:00
|
|
|
|
|
|
|
/// getSmallConstantTripMultiple - Returns the largest constant divisor of
|
|
|
|
/// the trip count of this loop as a normal unsigned value, if
|
|
|
|
/// possible. This means that the actual trip count is always a multiple of
|
|
|
|
/// the returned value (don't forget the trip count could very well be zero
|
2012-01-11 06:52:55 +00:00
|
|
|
/// as well!). As explained in the comments for getSmallConstantTripCount,
|
|
|
|
/// this assumes that control exits the loop via ExitingBlock.
|
|
|
|
unsigned getSmallConstantTripMultiple(Loop *L, BasicBlock *ExitingBlock);
|
2011-08-11 23:36:16 +00:00
|
|
|
|
2011-07-26 17:19:55 +00:00
|
|
|
// getExitCount - Get the expression for the number of loop iterations for
|
2011-08-02 04:23:35 +00:00
|
|
|
// which this loop is guaranteed not to exit via ExitingBlock. Otherwise
|
|
|
|
// return SCEVCouldNotCompute.
|
|
|
|
const SCEV *getExitCount(Loop *L, BasicBlock *ExitingBlock);
|
2011-07-26 17:19:55 +00:00
|
|
|
|
2009-02-24 18:55:53 +00:00
|
|
|
/// getBackedgeTakenCount - If the specified loop has a predictable
|
|
|
|
/// backedge-taken count, return it, otherwise return a SCEVCouldNotCompute
|
|
|
|
/// object. The backedge-taken count is the number of times the loop header
|
|
|
|
/// will be branched to from within the loop. This is one less than the
|
|
|
|
/// trip count of the loop, since it doesn't count the first iteration,
|
|
|
|
/// when the header is branched to from outside the loop.
|
|
|
|
///
|
|
|
|
/// Note that it is not valid to call this method on a loop without a
|
|
|
|
/// loop-invariant backedge-taken count (see
|
|
|
|
/// hasLoopInvariantBackedgeTakenCount).
|
|
|
|
///
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getBackedgeTakenCount(const Loop *L);
|
2004-04-02 20:23:17 +00:00
|
|
|
|
2009-04-30 20:47:05 +00:00
|
|
|
/// getMaxBackedgeTakenCount - Similar to getBackedgeTakenCount, except
|
|
|
|
/// return the least SCEV value that is known never to be less than the
|
|
|
|
/// actual backedge taken count.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getMaxBackedgeTakenCount(const Loop *L);
|
2009-04-30 20:47:05 +00:00
|
|
|
|
2009-02-24 18:55:53 +00:00
|
|
|
/// hasLoopInvariantBackedgeTakenCount - Return true if the specified loop
|
|
|
|
/// has an analyzable loop-invariant backedge-taken count.
|
2009-04-21 23:15:49 +00:00
|
|
|
bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
|
2004-04-02 20:23:17 +00:00
|
|
|
|
2009-10-31 15:04:55 +00:00
|
|
|
/// 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);
|
2009-02-17 20:49:49 +00:00
|
|
|
|
2010-02-19 07:14:22 +00:00
|
|
|
/// forgetValue - This method should be called by the client when it has
|
|
|
|
/// changed a value in a way that may effect its value, or which may
|
|
|
|
/// disconnect it from a def-use chain linking it to a loop.
|
|
|
|
void forgetValue(Value *V);
|
|
|
|
|
2009-06-24 04:47:54 +00:00
|
|
|
/// GetMinTrailingZeros - Determine the minimum number of zero bits that S
|
|
|
|
/// is guaranteed to end in (at every loop iteration). It is, at the same
|
|
|
|
/// time, the minimum number of times S is divisible by 2. For example,
|
|
|
|
/// given {4,+,8} it returns 2. If S is guaranteed to be 0, it returns the
|
|
|
|
/// bitwidth of S.
|
2009-07-07 17:06:11 +00:00
|
|
|
uint32_t GetMinTrailingZeros(const SCEV *S);
|
2009-06-19 23:29:04 +00:00
|
|
|
|
2009-07-13 21:35:55 +00:00
|
|
|
/// getUnsignedRange - Determine the unsigned range for a particular SCEV.
|
|
|
|
///
|
|
|
|
ConstantRange getUnsignedRange(const SCEV *S);
|
|
|
|
|
|
|
|
/// getSignedRange - Determine the signed range for a particular SCEV.
|
|
|
|
///
|
|
|
|
ConstantRange getSignedRange(const SCEV *S);
|
|
|
|
|
|
|
|
/// isKnownNegative - Test if the given expression is known to be negative.
|
|
|
|
///
|
|
|
|
bool isKnownNegative(const SCEV *S);
|
|
|
|
|
|
|
|
/// isKnownPositive - Test if the given expression is known to be positive.
|
|
|
|
///
|
|
|
|
bool isKnownPositive(const SCEV *S);
|
|
|
|
|
|
|
|
/// isKnownNonNegative - Test if the given expression is known to be
|
|
|
|
/// non-negative.
|
|
|
|
///
|
|
|
|
bool isKnownNonNegative(const SCEV *S);
|
|
|
|
|
|
|
|
/// isKnownNonPositive - Test if the given expression is known to be
|
|
|
|
/// non-positive.
|
|
|
|
///
|
|
|
|
bool isKnownNonPositive(const SCEV *S);
|
|
|
|
|
|
|
|
/// isKnownNonZero - Test if the given expression is known to be
|
|
|
|
/// non-zero.
|
|
|
|
///
|
|
|
|
bool isKnownNonZero(const SCEV *S);
|
2009-06-19 23:29:04 +00:00
|
|
|
|
2010-04-11 22:07:56 +00:00
|
|
|
/// isKnownPredicate - Test if the given expression is known to satisfy
|
2009-07-13 21:35:55 +00:00
|
|
|
/// the condition described by Pred, LHS, and RHS.
|
|
|
|
///
|
|
|
|
bool isKnownPredicate(ICmpInst::Predicate Pred,
|
|
|
|
const SCEV *LHS, const SCEV *RHS);
|
2009-06-19 23:29:04 +00:00
|
|
|
|
2010-04-24 01:28:42 +00:00
|
|
|
/// SimplifyICmpOperands - Simplify LHS and RHS in a comparison with
|
2012-09-27 10:14:43 +00:00
|
|
|
/// predicate Pred. Return true iff any changes were made. If the
|
2013-03-05 22:05:16 +00:00
|
|
|
/// operands are provably equal or unequal, LHS and RHS are set to
|
2010-04-30 18:33:41 +00:00
|
|
|
/// the same value and Pred is set to either ICMP_EQ or ICMP_NE.
|
2010-04-24 01:28:42 +00:00
|
|
|
///
|
|
|
|
bool SimplifyICmpOperands(ICmpInst::Predicate &Pred,
|
|
|
|
const SCEV *&LHS,
|
2012-05-30 18:32:23 +00:00
|
|
|
const SCEV *&RHS,
|
|
|
|
unsigned Depth = 0);
|
2010-04-24 01:28:42 +00:00
|
|
|
|
2010-11-17 23:21:44 +00:00
|
|
|
/// getLoopDisposition - Return the "disposition" of the given SCEV with
|
|
|
|
/// respect to the given loop.
|
|
|
|
LoopDisposition getLoopDisposition(const SCEV *S, const Loop *L);
|
|
|
|
|
2010-11-17 21:23:15 +00:00
|
|
|
/// isLoopInvariant - Return true if the value of the given SCEV is
|
|
|
|
/// unchanging in the specified loop.
|
|
|
|
bool isLoopInvariant(const SCEV *S, const Loop *L);
|
|
|
|
|
|
|
|
/// hasComputableLoopEvolution - Return true if the given SCEV changes value
|
|
|
|
/// in a known way in the specified loop. This property being true implies
|
|
|
|
/// that the value is variant in the loop AND that we can emit an expression
|
|
|
|
/// to compute the value of the expression at any particular loop iteration.
|
|
|
|
bool hasComputableLoopEvolution(const SCEV *S, const Loop *L);
|
|
|
|
|
2010-11-18 00:34:22 +00:00
|
|
|
/// getLoopDisposition - Return the "disposition" of the given SCEV with
|
|
|
|
/// respect to the given block.
|
|
|
|
BlockDisposition getBlockDisposition(const SCEV *S, const BasicBlock *BB);
|
|
|
|
|
2010-11-17 21:41:58 +00:00
|
|
|
/// dominates - Return true if elements that makes up the given SCEV
|
|
|
|
/// dominate the specified basic block.
|
2010-11-18 00:34:22 +00:00
|
|
|
bool dominates(const SCEV *S, const BasicBlock *BB);
|
2010-11-17 21:41:58 +00:00
|
|
|
|
|
|
|
/// properlyDominates - Return true if elements that makes up the given SCEV
|
|
|
|
/// properly dominate the specified basic block.
|
2010-11-18 00:34:22 +00:00
|
|
|
bool properlyDominates(const SCEV *S, const BasicBlock *BB);
|
2010-11-17 21:41:58 +00:00
|
|
|
|
2010-11-17 22:27:42 +00:00
|
|
|
/// hasOperand - Test whether the given SCEV has Op as a direct or
|
|
|
|
/// indirect operand.
|
|
|
|
bool hasOperand(const SCEV *S, const SCEV *Op) const;
|
|
|
|
|
2004-04-02 20:23:17 +00:00
|
|
|
virtual bool runOnFunction(Function &F);
|
|
|
|
virtual void releaseMemory();
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
|
2009-08-23 06:03:38 +00:00
|
|
|
virtual void print(raw_ostream &OS, const Module* = 0) const;
|
2012-10-26 17:31:32 +00:00
|
|
|
virtual void verifyAnalysis() const;
|
2009-06-27 21:21:31 +00:00
|
|
|
|
2009-06-22 18:25:46 +00:00
|
|
|
private:
|
2009-06-27 21:21:31 +00:00
|
|
|
FoldingSet<SCEV> UniqueSCEVs;
|
|
|
|
BumpPtrAllocator SCEVAllocator;
|
2010-08-02 23:49:30 +00:00
|
|
|
|
|
|
|
/// FirstUnknown - The head of a linked list of all SCEVUnknown
|
|
|
|
/// values that have been allocated. This is used by releaseMemory
|
|
|
|
/// to locate them all and call their destructors.
|
|
|
|
SCEVUnknown *FirstUnknown;
|
2004-04-02 20:23:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|