comparison include/llvm/Analysis/ScalarEvolution.h @ 77:54457678186b LLVM3.6

LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 08 Sep 2014 22:06:00 +0900
parents 95c75e76d11b
children 60c9769439b8
comparison
equal deleted inserted replaced
34:e874dbf0ad9d 77:54457678186b
21 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H 21 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H
22 #define LLVM_ANALYSIS_SCALAREVOLUTION_H 22 #define LLVM_ANALYSIS_SCALAREVOLUTION_H
23 23
24 #include "llvm/ADT/DenseSet.h" 24 #include "llvm/ADT/DenseSet.h"
25 #include "llvm/ADT/FoldingSet.h" 25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/IR/ConstantRange.h"
26 #include "llvm/IR/Function.h" 27 #include "llvm/IR/Function.h"
27 #include "llvm/IR/Instructions.h" 28 #include "llvm/IR/Instructions.h"
28 #include "llvm/IR/Operator.h" 29 #include "llvm/IR/Operator.h"
30 #include "llvm/IR/ValueHandle.h"
29 #include "llvm/Pass.h" 31 #include "llvm/Pass.h"
30 #include "llvm/Support/Allocator.h" 32 #include "llvm/Support/Allocator.h"
31 #include "llvm/Support/ConstantRange.h"
32 #include "llvm/Support/DataTypes.h" 33 #include "llvm/Support/DataTypes.h"
33 #include "llvm/Support/ValueHandle.h"
34 #include <map> 34 #include <map>
35 35
36 namespace llvm { 36 namespace llvm {
37 class APInt; 37 class APInt;
38 class AssumptionTracker;
38 class Constant; 39 class Constant;
39 class ConstantInt; 40 class ConstantInt;
40 class DominatorTree; 41 class DominatorTree;
41 class Type; 42 class Type;
42 class ScalarEvolution; 43 class ScalarEvolution;
205 private: 206 private:
206 /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be 207 /// SCEVCallbackVH - A CallbackVH to arrange for ScalarEvolution to be
207 /// notified whenever a Value is deleted. 208 /// notified whenever a Value is deleted.
208 class SCEVCallbackVH : public CallbackVH { 209 class SCEVCallbackVH : public CallbackVH {
209 ScalarEvolution *SE; 210 ScalarEvolution *SE;
210 virtual void deleted(); 211 void deleted() override;
211 virtual void allUsesReplacedWith(Value *New); 212 void allUsesReplacedWith(Value *New) override;
212 public: 213 public:
213 SCEVCallbackVH(Value *V, ScalarEvolution *SE = 0); 214 SCEVCallbackVH(Value *V, ScalarEvolution *SE = nullptr);
214 }; 215 };
215 216
216 friend class SCEVCallbackVH; 217 friend class SCEVCallbackVH;
217 friend class SCEVExpander; 218 friend class SCEVExpander;
218 friend class SCEVUnknown; 219 friend class SCEVUnknown;
219 220
220 /// F - The function we are analyzing. 221 /// F - The function we are analyzing.
221 /// 222 ///
222 Function *F; 223 Function *F;
223 224
225 /// The tracker for @llvm.assume intrinsics in this function.
226 AssumptionTracker *AT;
227
224 /// LI - The loop information for the function we are currently analyzing. 228 /// LI - The loop information for the function we are currently analyzing.
225 /// 229 ///
226 LoopInfo *LI; 230 LoopInfo *LI;
227 231
228 /// TD - The target data information for the target we are targeting. 232 /// The DataLayout information for the target we are targeting.
229 /// 233 ///
230 DataLayout *TD; 234 const DataLayout *DL;
231 235
232 /// TLI - The target library information for the target we are targeting. 236 /// TLI - The target library information for the target we are targeting.
233 /// 237 ///
234 TargetLibraryInfo *TLI; 238 TargetLibraryInfo *TLI;
235 239
251 ValueExprMapType ValueExprMap; 255 ValueExprMapType ValueExprMap;
252 256
253 /// Mark predicate values currently being processed by isImpliedCond. 257 /// Mark predicate values currently being processed by isImpliedCond.
254 DenseSet<Value*> PendingLoopPredicates; 258 DenseSet<Value*> PendingLoopPredicates;
255 259
256 /// ExitLimit - Information about the number of loop iterations for 260 /// ExitLimit - Information about the number of loop iterations for which a
257 /// which a loop exit's branch condition evaluates to the not-taken path. 261 /// loop exit's branch condition evaluates to the not-taken path. This is a
258 /// This is a temporary pair of exact and max expressions that are 262 /// temporary pair of exact and max expressions that are eventually
259 /// eventually summarized in ExitNotTakenInfo and BackedgeTakenInfo. 263 /// summarized in ExitNotTakenInfo and BackedgeTakenInfo.
264 ///
265 /// If MustExit is true, then the exit must be taken when the BECount
266 /// reaches Exact (and before surpassing Max). If MustExit is false, then
267 /// BECount may exceed Exact or Max if the loop exits via another branch. In
268 /// either case, the loop may exit early via another branch.
269 ///
270 /// MustExit is true for most cases. However, an exit guarded by an
271 /// (in)equality on a nonunit stride may be skipped.
260 struct ExitLimit { 272 struct ExitLimit {
261 const SCEV *Exact; 273 const SCEV *Exact;
262 const SCEV *Max; 274 const SCEV *Max;
263 275 bool MustExit;
264 /*implicit*/ ExitLimit(const SCEV *E) : Exact(E), Max(E) {} 276
265 277 /*implicit*/ ExitLimit(const SCEV *E)
266 ExitLimit(const SCEV *E, const SCEV *M) : Exact(E), Max(M) {} 278 : Exact(E), Max(E), MustExit(true) {}
279
280 ExitLimit(const SCEV *E, const SCEV *M, bool MustExit)
281 : Exact(E), Max(M), MustExit(MustExit) {}
267 282
268 /// hasAnyInfo - Test whether this ExitLimit contains any computed 283 /// hasAnyInfo - Test whether this ExitLimit contains any computed
269 /// information, or whether it's all SCEVCouldNotCompute values. 284 /// information, or whether it's all SCEVCouldNotCompute values.
270 bool hasAnyInfo() const { 285 bool hasAnyInfo() const {
271 return !isa<SCEVCouldNotCompute>(Exact) || 286 return !isa<SCEVCouldNotCompute>(Exact) ||
278 struct ExitNotTakenInfo { 293 struct ExitNotTakenInfo {
279 AssertingVH<BasicBlock> ExitingBlock; 294 AssertingVH<BasicBlock> ExitingBlock;
280 const SCEV *ExactNotTaken; 295 const SCEV *ExactNotTaken;
281 PointerIntPair<ExitNotTakenInfo*, 1> NextExit; 296 PointerIntPair<ExitNotTakenInfo*, 1> NextExit;
282 297
283 ExitNotTakenInfo() : ExitingBlock(0), ExactNotTaken(0) {} 298 ExitNotTakenInfo() : ExitingBlock(nullptr), ExactNotTaken(nullptr) {}
284 299
285 /// isCompleteList - Return true if all loop exits are computable. 300 /// isCompleteList - Return true if all loop exits are computable.
286 bool isCompleteList() const { 301 bool isCompleteList() const {
287 return NextExit.getInt() == 0; 302 return NextExit.getInt() == 0;
288 } 303 }
308 /// Max - An expression indicating the least maximum backedge-taken 323 /// Max - An expression indicating the least maximum backedge-taken
309 /// count of the loop that is known, or a SCEVCouldNotCompute. 324 /// count of the loop that is known, or a SCEVCouldNotCompute.
310 const SCEV *Max; 325 const SCEV *Max;
311 326
312 public: 327 public:
313 BackedgeTakenInfo() : Max(0) {} 328 BackedgeTakenInfo() : Max(nullptr) {}
314 329
315 /// Initialize BackedgeTakenInfo from a list of exact exit counts. 330 /// Initialize BackedgeTakenInfo from a list of exact exit counts.
316 BackedgeTakenInfo( 331 BackedgeTakenInfo(
317 SmallVectorImpl< std::pair<BasicBlock *, const SCEV *> > &ExitCounts, 332 SmallVectorImpl< std::pair<BasicBlock *, const SCEV *> > &ExitCounts,
318 bool Complete, const SCEV *MaxCount); 333 bool Complete, const SCEV *MaxCount);
455 ExitLimit ComputeExitLimitFromICmp(const Loop *L, 470 ExitLimit ComputeExitLimitFromICmp(const Loop *L,
456 ICmpInst *ExitCond, 471 ICmpInst *ExitCond,
457 BasicBlock *TBB, 472 BasicBlock *TBB,
458 BasicBlock *FBB, 473 BasicBlock *FBB,
459 bool IsSubExpr); 474 bool IsSubExpr);
475
476 /// ComputeExitLimitFromSingleExitSwitch - Compute the number of times the
477 /// backedge of the specified loop will execute if its exit condition were a
478 /// switch with a single exiting case to ExitingBB.
479 ExitLimit
480 ComputeExitLimitFromSingleExitSwitch(const Loop *L, SwitchInst *Switch,
481 BasicBlock *ExitingBB, bool IsSubExpr);
460 482
461 /// ComputeLoadConstantCompareExitLimit - Given an exit condition 483 /// ComputeLoadConstantCompareExitLimit - Given an exit condition
462 /// of 'icmp op load X, cst', try to see if we can compute the 484 /// of 'icmp op load X, cst', try to see if we can compute the
463 /// backedge-taken count. 485 /// backedge-taken count.
464 ExitLimit ComputeLoadConstantCompareExitLimit(LoadInst *LI, 486 ExitLimit ComputeLoadConstantCompareExitLimit(LoadInst *LI,
611 Ops.push_back(Op1); 633 Ops.push_back(Op1);
612 Ops.push_back(Op2); 634 Ops.push_back(Op2);
613 return getMulExpr(Ops, Flags); 635 return getMulExpr(Ops, Flags);
614 } 636 }
615 const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS); 637 const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
638 const SCEV *getUDivExactExpr(const SCEV *LHS, const SCEV *RHS);
616 const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step, 639 const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
617 const Loop *L, SCEV::NoWrapFlags Flags); 640 const Loop *L, SCEV::NoWrapFlags Flags);
618 const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands, 641 const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
619 const Loop *L, SCEV::NoWrapFlags Flags); 642 const Loop *L, SCEV::NoWrapFlags Flags);
620 const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands, 643 const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
774 /// has an analyzable loop-invariant backedge-taken count. 797 /// has an analyzable loop-invariant backedge-taken count.
775 bool hasLoopInvariantBackedgeTakenCount(const Loop *L); 798 bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
776 799
777 /// forgetLoop - This method should be called by the client when it has 800 /// forgetLoop - This method should be called by the client when it has
778 /// changed a loop in a way that may effect ScalarEvolution's ability to 801 /// changed a loop in a way that may effect ScalarEvolution's ability to
779 /// compute a trip count, or if the loop is deleted. 802 /// compute a trip count, or if the loop is deleted. This call is
803 /// potentially expensive for large loop bodies.
780 void forgetLoop(const Loop *L); 804 void forgetLoop(const Loop *L);
781 805
782 /// forgetValue - This method should be called by the client when it has 806 /// forgetValue - This method should be called by the client when it has
783 /// changed a value in a way that may effect its value, or which may 807 /// changed a value in a way that may effect its value, or which may
784 /// disconnect it from a def-use chain linking it to a loop. 808 /// disconnect it from a def-use chain linking it to a loop.
785 void forgetValue(Value *V); 809 void forgetValue(Value *V);
810
811 /// \brief Called when the client has changed the disposition of values in
812 /// this loop.
813 ///
814 /// We don't have a way to invalidate per-loop dispositions. Clear and
815 /// recompute is simpler.
816 void forgetLoopDispositions(const Loop *L) { LoopDispositions.clear(); }
786 817
787 /// GetMinTrailingZeros - Determine the minimum number of zero bits that S 818 /// GetMinTrailingZeros - Determine the minimum number of zero bits that S
788 /// is guaranteed to end in (at every loop iteration). It is, at the same 819 /// is guaranteed to end in (at every loop iteration). It is, at the same
789 /// time, the minimum number of times S is divisible by 2. For example, 820 /// time, the minimum number of times S is divisible by 2. For example,
790 /// given {4,+,8} it returns 2. If S is guaranteed to be 0, it returns the 821 /// given {4,+,8} it returns 2. If S is guaranteed to be 0, it returns the
866 897
867 /// hasOperand - Test whether the given SCEV has Op as a direct or 898 /// hasOperand - Test whether the given SCEV has Op as a direct or
868 /// indirect operand. 899 /// indirect operand.
869 bool hasOperand(const SCEV *S, const SCEV *Op) const; 900 bool hasOperand(const SCEV *S, const SCEV *Op) const;
870 901
871 virtual bool runOnFunction(Function &F); 902 /// Return the size of an element read or written by Inst.
872 virtual void releaseMemory(); 903 const SCEV *getElementSize(Instruction *Inst);
873 virtual void getAnalysisUsage(AnalysisUsage &AU) const; 904
874 virtual void print(raw_ostream &OS, const Module* = 0) const; 905 /// Compute the array dimensions Sizes from the set of Terms extracted from
875 virtual void verifyAnalysis() const; 906 /// the memory access function of this SCEVAddRecExpr.
907 void findArrayDimensions(SmallVectorImpl<const SCEV *> &Terms,
908 SmallVectorImpl<const SCEV *> &Sizes,
909 const SCEV *ElementSize) const;
910
911 bool runOnFunction(Function &F) override;
912 void releaseMemory() override;
913 void getAnalysisUsage(AnalysisUsage &AU) const override;
914 void print(raw_ostream &OS, const Module* = nullptr) const override;
915 void verifyAnalysis() const override;
876 916
877 private: 917 private:
878 /// Compute the backedge taken count knowing the interval difference, the 918 /// Compute the backedge taken count knowing the interval difference, the
879 /// stride and presence of the equality in the comparison. 919 /// stride and presence of the equality in the comparison.
880 const SCEV *computeBECount(const SCEV *Delta, const SCEV *Stride, 920 const SCEV *computeBECount(const SCEV *Delta, const SCEV *Stride,
881 bool Equality); 921 bool Equality);
882 922
883 /// Verify if an linear IV with positive stride can overflow when in a 923 /// Verify if an linear IV with positive stride can overflow when in a
884 /// less-than comparison, knowing the invariant term of the comparison, 924 /// less-than comparison, knowing the invariant term of the comparison,
885 /// the stride and the knowledge of NSW/NUW flags on the recurrence. 925 /// the stride and the knowledge of NSW/NUW flags on the recurrence.
886 bool doesIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride, 926 bool doesIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride,
887 bool IsSigned, bool NoWrap); 927 bool IsSigned, bool NoWrap);
888 928
889 /// Verify if an linear IV with negative stride can overflow when in a 929 /// Verify if an linear IV with negative stride can overflow when in a
890 /// greater-than comparison, knowing the invariant term of the comparison, 930 /// greater-than comparison, knowing the invariant term of the comparison,
891 /// the stride and the knowledge of NSW/NUW flags on the recurrence. 931 /// the stride and the knowledge of NSW/NUW flags on the recurrence.
892 bool doesIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride, 932 bool doesIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride,
893 bool IsSigned, bool NoWrap); 933 bool IsSigned, bool NoWrap);
894 934