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
|
|
|
|
|
|
|
|
#include "llvm/Pass.h"
|
2009-07-13 22:19:41 +00:00
|
|
|
#include "llvm/Instructions.h"
|
2009-08-11 16:02:12 +00:00
|
|
|
#include "llvm/Function.h"
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2009-05-04 22:30:44 +00:00
|
|
|
#include "llvm/Support/ValueHandle.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"
|
2009-06-27 21:21:31 +00:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2009-06-14 22:55:07 +00:00
|
|
|
#include "llvm/ADT/DenseMap.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;
|
2009-04-21 23:15:49 +00:00
|
|
|
class TargetData;
|
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:
|
2004-04-02 20:23:17 +00:00
|
|
|
SCEV(const SCEV &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const SCEV &); // DO NOT IMPLEMENT
|
2010-11-17 22:27:42 +00:00
|
|
|
|
2004-04-02 20:23:17 +00:00
|
|
|
public:
|
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.
|
|
|
|
///
|
2010-11-17 22:27:42 +00:00
|
|
|
const 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;
|
|
|
|
|
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,
|
|
|
|
FoldingSetNodeID &TempID) {
|
|
|
|
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 inline bool classof(const SCEVCouldNotCompute *S) { return true; }
|
|
|
|
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.
|
|
|
|
};
|
|
|
|
|
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
|
|
|
///
|
|
|
|
TargetData *TD;
|
|
|
|
|
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
|
|
|
|
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
|
|
|
///
|
|
|
|
struct BackedgeTakenInfo {
|
|
|
|
/// Exact - An expression indicating the exact backedge-taken count of
|
|
|
|
/// the loop if it is known, or a SCEVCouldNotCompute otherwise.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *Exact;
|
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
|
|
|
|
2009-07-07 17:06:11 +00:00
|
|
|
/*implicit*/ BackedgeTakenInfo(const SCEV *exact) :
|
2009-04-30 20:47:05 +00:00
|
|
|
Exact(exact), Max(exact) {}
|
|
|
|
|
2009-07-07 17:06:11 +00:00
|
|
|
BackedgeTakenInfo(const SCEV *exact, const SCEV *max) :
|
2009-04-30 20:47:05 +00:00
|
|
|
Exact(exact), Max(max) {}
|
|
|
|
|
|
|
|
/// hasAnyInfo - Test whether this BackedgeTakenInfo contains any
|
|
|
|
/// computed information, or whether it's all SCEVCouldNotCompute
|
|
|
|
/// values.
|
|
|
|
bool hasAnyInfo() const {
|
|
|
|
return !isa<SCEVCouldNotCompute>(Exact) ||
|
|
|
|
!isa<SCEVCouldNotCompute>(Max);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-21 23:15:49 +00:00
|
|
|
/// BackedgeTakenCounts - Cache the backedge-taken count of the loops for
|
|
|
|
/// this function as they are computed.
|
2009-04-30 20:47:05 +00:00
|
|
|
std::map<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.
|
|
|
|
std::map<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
|
|
|
|
|
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.
|
|
|
|
std::map<const SCEV *,
|
|
|
|
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.
|
|
|
|
std::map<const SCEV *,
|
|
|
|
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.
|
|
|
|
std::map<const SCEV *,
|
|
|
|
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
|
|
|
|
2009-06-22 00:31:57 +00:00
|
|
|
/// ComputeBackedgeTakenCountFromExit - Compute the number of times the
|
|
|
|
/// backedge of the specified loop will execute if it exits via the
|
|
|
|
/// specified block.
|
|
|
|
BackedgeTakenInfo ComputeBackedgeTakenCountFromExit(const Loop *L,
|
|
|
|
BasicBlock *ExitingBlock);
|
|
|
|
|
|
|
|
/// ComputeBackedgeTakenCountFromExitCond - 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.
|
|
|
|
BackedgeTakenInfo
|
|
|
|
ComputeBackedgeTakenCountFromExitCond(const Loop *L,
|
|
|
|
Value *ExitCond,
|
|
|
|
BasicBlock *TBB,
|
|
|
|
BasicBlock *FBB);
|
|
|
|
|
|
|
|
/// ComputeBackedgeTakenCountFromExitCondICmp - 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.
|
|
|
|
BackedgeTakenInfo
|
|
|
|
ComputeBackedgeTakenCountFromExitCondICmp(const Loop *L,
|
|
|
|
ICmpInst *ExitCond,
|
|
|
|
BasicBlock *TBB,
|
|
|
|
BasicBlock *FBB);
|
|
|
|
|
2009-04-21 23:15:49 +00:00
|
|
|
/// ComputeLoadConstantCompareBackedgeTakenCount - 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.
|
2010-02-24 17:31:30 +00:00
|
|
|
BackedgeTakenInfo
|
2009-04-21 23:15:49 +00:00
|
|
|
ComputeLoadConstantCompareBackedgeTakenCount(LoadInst *LI,
|
|
|
|
Constant *RHS,
|
|
|
|
const Loop *L,
|
|
|
|
ICmpInst::Predicate p);
|
|
|
|
|
2009-07-27 16:09:48 +00:00
|
|
|
/// ComputeBackedgeTakenCountExhaustively - If the loop is known to execute
|
2009-04-21 23:15:49 +00:00
|
|
|
/// a constant number of times (the condition evolves only from constants),
|
|
|
|
/// 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
|
2009-07-25 16:18:38 +00:00
|
|
|
/// evaluate the backedge-taken count of the loop, return CouldNotCompute.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *ComputeBackedgeTakenCountExhaustively(const Loop *L,
|
2009-06-24 04:47:54 +00:00
|
|
|
Value *Cond,
|
|
|
|
bool ExitWhen);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
|
|
|
/// HowFarToZero - Return the number of times a backedge comparing the
|
|
|
|
/// specified value to zero will execute. If not computable, return
|
2009-06-06 14:37:11 +00:00
|
|
|
/// CouldNotCompute.
|
2010-02-24 17:31:30 +00:00
|
|
|
BackedgeTakenInfo HowFarToZero(const SCEV *V, const Loop *L);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
|
|
|
/// HowFarToNonZero - Return the number of times a backedge checking the
|
|
|
|
/// specified value for nonzero will execute. If not computable, return
|
2009-06-06 14:37:11 +00:00
|
|
|
/// CouldNotCompute.
|
2010-02-24 17:31:30 +00:00
|
|
|
BackedgeTakenInfo HowFarToNonZero(const SCEV *V, const Loop *L);
|
2009-04-21 23:15:49 +00:00
|
|
|
|
|
|
|
/// HowManyLessThans - Return the number of times a backedge containing the
|
|
|
|
/// specified less-than comparison will execute. If not computable, return
|
2009-06-06 14:37:11 +00:00
|
|
|
/// CouldNotCompute. isSigned specifies whether the less-than is signed.
|
2009-05-04 22:30:44 +00:00
|
|
|
BackedgeTakenInfo 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,
|
|
|
|
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.
|
|
|
|
bool isSCEVable(const Type *Ty) const;
|
|
|
|
|
|
|
|
/// getTypeSizeInBits - Return the size in bits of the specified type,
|
|
|
|
/// for which isSCEVable must return true.
|
|
|
|
uint64_t getTypeSizeInBits(const Type *Ty) const;
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
const Type *getEffectiveSCEVType(const 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);
|
|
|
|
const SCEV *getConstant(const Type *Ty, uint64_t V, bool isSigned = false);
|
|
|
|
const SCEV *getTruncateExpr(const SCEV *Op, const Type *Ty);
|
|
|
|
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);
|
2009-10-09 00:10:36 +00:00
|
|
|
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) {
|
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);
|
2009-10-09 00:10:36 +00:00
|
|
|
return getAddExpr(Ops, HasNUW, HasNSW);
|
2007-10-22 18:31:58 +00:00
|
|
|
}
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1,
|
2009-10-09 00:10:36 +00:00
|
|
|
const SCEV *Op2,
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
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);
|
2009-10-09 00:10:36 +00:00
|
|
|
return getAddExpr(Ops, HasNUW, HasNSW);
|
2007-10-22 18:31:58 +00:00
|
|
|
}
|
2009-10-09 00:10:36 +00:00
|
|
|
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) {
|
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);
|
2009-10-09 00:10:36 +00:00
|
|
|
return getMulExpr(Ops, HasNUW, HasNSW);
|
2007-10-22 18:31:58 +00:00
|
|
|
}
|
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,
|
2009-10-09 00:10:36 +00:00
|
|
|
const Loop *L,
|
|
|
|
bool HasNUW = false, bool HasNSW = false);
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
|
2009-10-09 00:10:36 +00:00
|
|
|
const Loop *L,
|
|
|
|
bool HasNUW = false, bool HasNSW = false);
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
|
2009-10-09 00:10:36 +00:00
|
|
|
const Loop *L,
|
|
|
|
bool HasNUW = false, bool HasNSW = false) {
|
2009-07-07 17:06:11 +00:00
|
|
|
SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
|
2009-10-09 00:10:36 +00:00
|
|
|
return getAddRecExpr(NewOp, L, HasNUW, HasNSW);
|
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.
|
|
|
|
///
|
|
|
|
const SCEV *getSizeOfExpr(const Type *AllocTy);
|
|
|
|
|
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
|
|
|
///
|
|
|
|
const SCEV *getAlignOfExpr(const Type *AllocTy);
|
|
|
|
|
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
|
|
|
///
|
|
|
|
const SCEV *getOffsetOfExpr(const StructType *STy, unsigned FieldNo);
|
|
|
|
|
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
|
|
|
///
|
|
|
|
const SCEV *getOffsetOfExpr(const Type *CTy, Constant *FieldNo);
|
|
|
|
|
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
|
|
|
|
2007-10-22 18:31:58 +00:00
|
|
|
/// getMinusSCEV - Return LHS-RHS.
|
|
|
|
///
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getMinusSCEV(const SCEV *LHS,
|
2009-07-24 00:55:33 +00:00
|
|
|
const SCEV *RHS);
|
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.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getTruncateOrZeroExtend(const SCEV *V, const 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.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getTruncateOrSignExtend(const SCEV *V, const 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.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getNoopOrZeroExtend(const SCEV *V, const 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.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getNoopOrSignExtend(const SCEV *V, const 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.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getNoopOrAnyExtend(const SCEV *V, const 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.
|
2009-07-07 17:06:11 +00:00
|
|
|
const SCEV *getTruncateOrNoop(const SCEV *V, const 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
|
|
|
|
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);
|
|
|
|
|
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
|
2010-04-30 18:33:41 +00:00
|
|
|
/// predicate Pred. Return true iff any changes were made. If the
|
|
|
|
/// operands are provably equal or inequal, LHS and RHS are set to
|
|
|
|
/// 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,
|
|
|
|
const SCEV *&RHS);
|
|
|
|
|
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;
|
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
|