0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 //===- llvm/Analysis/ScalarEvolution.h - Scalar Evolution -------*- C++ -*-===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 // The ScalarEvolution class is an LLVM pass which can be used to analyze and
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 // categorize scalar expressions in loops. It specializes in recognizing
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 // general induction variables, representing them with the abstract and opaque
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 // SCEV class. Given this analysis, trip counts of loops and other important
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 // properties can be obtained.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 // This analysis is primarily useful for induction variable substitution and
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 // strength reduction.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
19 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_H
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 #define LLVM_ANALYSIS_SCALAREVOLUTION_H
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 #include "llvm/ADT/DenseSet.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 #include "llvm/ADT/FoldingSet.h"
|
77
|
26 #include "llvm/IR/ConstantRange.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 #include "llvm/IR/Function.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28 #include "llvm/IR/Instructions.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
29 #include "llvm/IR/Operator.h"
|
95
|
30 #include "llvm/IR/PassManager.h"
|
77
|
31 #include "llvm/IR/ValueHandle.h"
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
32 #include "llvm/Pass.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
33 #include "llvm/Support/Allocator.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
34 #include "llvm/Support/DataTypes.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
35 #include <map>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
37 namespace llvm {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
38 class APInt;
|
83
|
39 class AssumptionCache;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
40 class Constant;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
41 class ConstantInt;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
42 class DominatorTree;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 class Type;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44 class ScalarEvolution;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 class DataLayout;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
46 class TargetLibraryInfo;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
47 class LLVMContext;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48 class Loop;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 class LoopInfo;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50 class Operator;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
51 class SCEVUnknown;
|
95
|
52 class SCEVAddRecExpr;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 class SCEV;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
54 template<> struct FoldingSetTrait<SCEV>;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55
|
95
|
56 /// This class represents an analyzed expression in the program. These are
|
|
57 /// opaque objects that the client is not allowed to do much with directly.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
58 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
59 class SCEV : public FoldingSetNode {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
60 friend struct FoldingSetTrait<SCEV>;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
61
|
95
|
62 /// A reference to an Interned FoldingSetNodeID for this node. The
|
|
63 /// ScalarEvolution's BumpPtrAllocator holds the data.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
64 FoldingSetNodeIDRef FastID;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
65
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
66 // The SCEV baseclass this node corresponds to
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
67 const unsigned short SCEVType;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
68
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
69 protected:
|
95
|
70 /// This field is initialized to zero and may be used in subclasses to store
|
|
71 /// miscellaneous information.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
72 unsigned short SubclassData;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
73
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
74 private:
|
83
|
75 SCEV(const SCEV &) = delete;
|
|
76 void operator=(const SCEV &) = delete;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
77
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
78 public:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
79 /// NoWrapFlags are bitfield indices into SubclassData.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
80 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
81 /// Add and Mul expressions may have no-unsigned-wrap <NUW> or
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
82 /// no-signed-wrap <NSW> properties, which are derived from the IR
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
83 /// operator. NSW is a misnomer that we use to mean no signed overflow or
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
84 /// underflow.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
85 ///
|
83
|
86 /// AddRec expressions may have a no-self-wraparound <NW> property if, in
|
|
87 /// the integer domain, abs(step) * max-iteration(loop) <=
|
|
88 /// unsigned-max(bitwidth). This means that the recurrence will never reach
|
|
89 /// its start value if the step is non-zero. Computing the same value on
|
|
90 /// each iteration is not considered wrapping, and recurrences with step = 0
|
|
91 /// are trivially <NW>. <NW> is independent of the sign of step and the
|
|
92 /// value the add recurrence starts with.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
93 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
94 /// Note that NUW and NSW are also valid properties of a recurrence, and
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
95 /// either implies NW. For convenience, NW will be set for a recurrence
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
96 /// whenever either NUW or NSW are set.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
97 enum NoWrapFlags { FlagAnyWrap = 0, // No guarantee.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 FlagNW = (1 << 0), // No self-wrap.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99 FlagNUW = (1 << 1), // No unsigned wrap.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 FlagNSW = (1 << 2), // No signed wrap.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101 NoWrapMask = (1 << 3) -1 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
103 explicit SCEV(const FoldingSetNodeIDRef ID, unsigned SCEVTy) :
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
104 FastID(ID), SCEVType(SCEVTy), SubclassData(0) {}
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
105
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
106 unsigned getSCEVType() const { return SCEVType; }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
107
|
95
|
108 /// Return the LLVM type of this SCEV expression.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
109 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 Type *getType() const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111
|
95
|
112 /// Return true if the expression is a constant zero.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
113 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
114 bool isZero() const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
115
|
95
|
116 /// Return true if the expression is a constant one.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
118 bool isOne() const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119
|
95
|
120 /// Return true if the expression is a constant all-ones value.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
122 bool isAllOnesValue() const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
123
|
95
|
124 /// Return true if the specified scev is negated, but not a constant.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
125 bool isNonConstantNegative() const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
126
|
95
|
127 /// Print out the internal representation of this scalar to the specified
|
|
128 /// stream. This should really only be used for debugging purposes.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
129 void print(raw_ostream &OS) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
130
|
83
|
131 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
95
|
132 /// This method is used for debugging.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
134 void dump() const;
|
83
|
135 #endif
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
136 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
137
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
138 // Specialize FoldingSetTrait for SCEV to avoid needing to compute
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
139 // temporary FoldingSetNodeID values.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
140 template<> struct FoldingSetTrait<SCEV> : DefaultFoldingSetTrait<SCEV> {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
141 static void Profile(const SCEV &X, FoldingSetNodeID& ID) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
142 ID = X.FastID;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
143 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
144 static bool Equals(const SCEV &X, const FoldingSetNodeID &ID,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
145 unsigned IDHash, FoldingSetNodeID &TempID) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
146 return ID == X.FastID;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
147 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
148 static unsigned ComputeHash(const SCEV &X, FoldingSetNodeID &TempID) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
149 return X.FastID.ComputeHash();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
151 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
152
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
153 inline raw_ostream &operator<<(raw_ostream &OS, const SCEV &S) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
154 S.print(OS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
155 return OS;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
156 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
157
|
95
|
158 /// An object of this class is returned by queries that could not be answered.
|
|
159 /// For example, if you ask for the number of iterations of a linked-list
|
|
160 /// traversal loop, you will get one of these. None of the standard SCEV
|
|
161 /// operations are valid on this class, it is just a marker.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
162 struct SCEVCouldNotCompute : public SCEV {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
163 SCEVCouldNotCompute();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
164
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
165 /// Methods for support type inquiry through isa, cast, and dyn_cast:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
166 static bool classof(const SCEV *S);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
167 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
168
|
95
|
169 /// The main scalar evolution driver. Because client code (intentionally)
|
|
170 /// can't do much with the SCEV objects directly, they must ask this class
|
|
171 /// for services.
|
|
172 class ScalarEvolution {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
173 public:
|
95
|
174 /// An enum describing the relationship between a SCEV and a loop.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
175 enum LoopDisposition {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 LoopVariant, ///< The SCEV is loop-variant (unknown).
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
177 LoopInvariant, ///< The SCEV is loop-invariant.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
178 LoopComputable ///< The SCEV varies predictably with the loop.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
179 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
180
|
95
|
181 /// An enum describing the relationship between a SCEV and a basic block.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
182 enum BlockDisposition {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
183 DoesNotDominateBlock, ///< The SCEV does not dominate the block.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
184 DominatesBlock, ///< The SCEV dominates the block.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
185 ProperlyDominatesBlock ///< The SCEV properly dominates the block.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
186 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
187
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
188 /// Convenient NoWrapFlags manipulation that hides enum casts and is
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
189 /// visible in the ScalarEvolution name space.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
190 static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
191 maskFlags(SCEV::NoWrapFlags Flags, int Mask) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
192 return (SCEV::NoWrapFlags)(Flags & Mask);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
193 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
194 static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
195 setFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OnFlags) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
196 return (SCEV::NoWrapFlags)(Flags | OnFlags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
197 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
198 static SCEV::NoWrapFlags LLVM_ATTRIBUTE_UNUSED_RESULT
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
199 clearFlags(SCEV::NoWrapFlags Flags, SCEV::NoWrapFlags OffFlags) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
200 return (SCEV::NoWrapFlags)(Flags & ~OffFlags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
201 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
202
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
203 private:
|
95
|
204 /// A CallbackVH to arrange for ScalarEvolution to be notified whenever a
|
|
205 /// Value is deleted.
|
|
206 class SCEVCallbackVH final : public CallbackVH {
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
207 ScalarEvolution *SE;
|
77
|
208 void deleted() override;
|
|
209 void allUsesReplacedWith(Value *New) override;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
210 public:
|
77
|
211 SCEVCallbackVH(Value *V, ScalarEvolution *SE = nullptr);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
212 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
214 friend class SCEVCallbackVH;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
215 friend class SCEVExpander;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
216 friend class SCEVUnknown;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
217
|
95
|
218 /// The function we are analyzing.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 ///
|
95
|
220 Function &F;
|
|
221
|
|
222 /// The target library information for the target we are targeting.
|
|
223 ///
|
|
224 TargetLibraryInfo &TLI;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
225
|
77
|
226 /// The tracker for @llvm.assume intrinsics in this function.
|
95
|
227 AssumptionCache &AC;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
228
|
95
|
229 /// The dominator tree.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
230 ///
|
95
|
231 DominatorTree &DT;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
232
|
95
|
233 /// The loop information for the function we are currently analyzing.
|
|
234 ///
|
|
235 LoopInfo &LI;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
236
|
95
|
237 /// This SCEV is used to represent unknown trip counts and things.
|
|
238 std::unique_ptr<SCEVCouldNotCompute> CouldNotCompute;
|
|
239
|
|
240 /// The typedef for ValueExprMap.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
241 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
242 typedef DenseMap<SCEVCallbackVH, const SCEV *, DenseMapInfo<Value *> >
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
243 ValueExprMapType;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
244
|
95
|
245 /// This is a cache of the values we have analyzed so far.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
246 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
247 ValueExprMapType ValueExprMap;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
248
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
249 /// Mark predicate values currently being processed by isImpliedCond.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
250 DenseSet<Value*> PendingLoopPredicates;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
251
|
95
|
252 /// Set to true by isLoopBackedgeGuardedByCond when we're walking the set of
|
|
253 /// conditions dominating the backedge of a loop.
|
|
254 bool WalkingBEDominatingConds;
|
|
255
|
|
256 /// Set to true by isKnownPredicateViaSplitting when we're trying to prove a
|
|
257 /// predicate by splitting it into a set of independent predicates.
|
|
258 bool ProvingSplitPredicate;
|
|
259
|
|
260 /// Information about the number of loop iterations for which a loop exit's
|
|
261 /// branch condition evaluates to the not-taken path. This is a temporary
|
|
262 /// pair of exact and max expressions that are eventually summarized in
|
|
263 /// ExitNotTakenInfo and BackedgeTakenInfo.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
264 struct ExitLimit {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
265 const SCEV *Exact;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
266 const SCEV *Max;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
267
|
83
|
268 /*implicit*/ ExitLimit(const SCEV *E) : Exact(E), Max(E) {}
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
269
|
83
|
270 ExitLimit(const SCEV *E, const SCEV *M) : Exact(E), Max(M) {}
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
271
|
95
|
272 /// Test whether this ExitLimit contains any computed information, or
|
|
273 /// whether it's all SCEVCouldNotCompute values.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
274 bool hasAnyInfo() const {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
275 return !isa<SCEVCouldNotCompute>(Exact) ||
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
276 !isa<SCEVCouldNotCompute>(Max);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
277 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
278 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
279
|
95
|
280 /// Information about the number of times a particular loop exit may be
|
|
281 /// reached before exiting the loop.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
282 struct ExitNotTakenInfo {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
283 AssertingVH<BasicBlock> ExitingBlock;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
284 const SCEV *ExactNotTaken;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
285 PointerIntPair<ExitNotTakenInfo*, 1> NextExit;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
286
|
77
|
287 ExitNotTakenInfo() : ExitingBlock(nullptr), ExactNotTaken(nullptr) {}
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
288
|
95
|
289 /// Return true if all loop exits are computable.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
290 bool isCompleteList() const {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
291 return NextExit.getInt() == 0;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
292 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
293
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
294 void setIncomplete() { NextExit.setInt(1); }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
295
|
95
|
296 /// Return a pointer to the next exit's not-taken info.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
297 ExitNotTakenInfo *getNextExit() const {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
298 return NextExit.getPointer();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
299 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
300
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
301 void setNextExit(ExitNotTakenInfo *ENT) { NextExit.setPointer(ENT); }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
302 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
303
|
95
|
304 /// Information about the backedge-taken count of a loop. This currently
|
|
305 /// includes an exact count and a maximum count.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
306 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
307 class BackedgeTakenInfo {
|
95
|
308 /// A list of computable exits and their not-taken counts. Loops almost
|
|
309 /// never have more than one computable exit.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
310 ExitNotTakenInfo ExitNotTaken;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
311
|
95
|
312 /// An expression indicating the least maximum backedge-taken count of the
|
|
313 /// loop that is known, or a SCEVCouldNotCompute.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
314 const SCEV *Max;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
315
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
316 public:
|
77
|
317 BackedgeTakenInfo() : Max(nullptr) {}
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
318
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
319 /// Initialize BackedgeTakenInfo from a list of exact exit counts.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
320 BackedgeTakenInfo(
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
321 SmallVectorImpl< std::pair<BasicBlock *, const SCEV *> > &ExitCounts,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
322 bool Complete, const SCEV *MaxCount);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
323
|
95
|
324 /// Test whether this BackedgeTakenInfo contains any computed information,
|
|
325 /// or whether it's all SCEVCouldNotCompute values.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
326 bool hasAnyInfo() const {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
327 return ExitNotTaken.ExitingBlock || !isa<SCEVCouldNotCompute>(Max);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
328 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
329
|
95
|
330 /// Return an expression indicating the exact backedge-taken count of the
|
|
331 /// loop if it is known, or SCEVCouldNotCompute otherwise. This is the
|
|
332 /// number of times the loop header can be guaranteed to execute, minus
|
|
333 /// one.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
334 const SCEV *getExact(ScalarEvolution *SE) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
335
|
95
|
336 /// Return the number of times this loop exit may fall through to the back
|
|
337 /// edge, or SCEVCouldNotCompute. The loop is guaranteed not to exit via
|
|
338 /// this block before this number of iterations, but may exit via another
|
|
339 /// block.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
340 const SCEV *getExact(BasicBlock *ExitingBlock, ScalarEvolution *SE) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
341
|
95
|
342 /// Get the max backedge taken count for the loop.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
343 const SCEV *getMax(ScalarEvolution *SE) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
344
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
345 /// Return true if any backedge taken count expressions refer to the given
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
346 /// subexpression.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
347 bool hasOperand(const SCEV *S, ScalarEvolution *SE) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
348
|
95
|
349 /// Invalidate this result and free associated memory.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
350 void clear();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
351 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
352
|
95
|
353 /// Cache the backedge-taken count of the loops for this function as they
|
|
354 /// are computed.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
355 DenseMap<const Loop*, BackedgeTakenInfo> BackedgeTakenCounts;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
356
|
95
|
357 /// This map contains entries for all of the PHI instructions that we
|
|
358 /// attempt to compute constant evolutions for. This allows us to avoid
|
|
359 /// potentially expensive recomputation of these properties. An instruction
|
|
360 /// maps to null if we are unable to compute its exit value.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
361 DenseMap<PHINode*, Constant*> ConstantEvolutionLoopExitValue;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
362
|
95
|
363 /// This map contains entries for all the expressions that we attempt to
|
|
364 /// compute getSCEVAtScope information for, which can be expensive in
|
|
365 /// extreme cases.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
366 DenseMap<const SCEV *,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
367 SmallVector<std::pair<const Loop *, const SCEV *>, 2> > ValuesAtScopes;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
368
|
95
|
369 /// Memoized computeLoopDisposition results.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
370 DenseMap<const SCEV *,
|
83
|
371 SmallVector<PointerIntPair<const Loop *, 2, LoopDisposition>, 2>>
|
|
372 LoopDispositions;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
373
|
95
|
374 /// Compute a LoopDisposition value.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
375 LoopDisposition computeLoopDisposition(const SCEV *S, const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
376
|
95
|
377 /// Memoized computeBlockDisposition results.
|
83
|
378 DenseMap<
|
|
379 const SCEV *,
|
|
380 SmallVector<PointerIntPair<const BasicBlock *, 2, BlockDisposition>, 2>>
|
|
381 BlockDispositions;
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
382
|
95
|
383 /// Compute a BlockDisposition value.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
384 BlockDisposition computeBlockDisposition(const SCEV *S, const BasicBlock *BB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
385
|
95
|
386 /// Memoized results from getRange
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
387 DenseMap<const SCEV *, ConstantRange> UnsignedRanges;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
388
|
95
|
389 /// Memoized results from getRange
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
390 DenseMap<const SCEV *, ConstantRange> SignedRanges;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
391
|
95
|
392 /// Used to parameterize getRange
|
|
393 enum RangeSignHint { HINT_RANGE_UNSIGNED, HINT_RANGE_SIGNED };
|
|
394
|
|
395 /// Set the memoized range for the given SCEV.
|
|
396 const ConstantRange &setRange(const SCEV *S, RangeSignHint Hint,
|
|
397 const ConstantRange &CR) {
|
|
398 DenseMap<const SCEV *, ConstantRange> &Cache =
|
|
399 Hint == HINT_RANGE_UNSIGNED ? UnsignedRanges : SignedRanges;
|
|
400
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
401 std::pair<DenseMap<const SCEV *, ConstantRange>::iterator, bool> Pair =
|
95
|
402 Cache.insert(std::make_pair(S, CR));
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
403 if (!Pair.second)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
404 Pair.first->second = CR;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
405 return Pair.first->second;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
406 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
407
|
95
|
408 /// Determine the range for a particular SCEV.
|
|
409 ConstantRange getRange(const SCEV *S, RangeSignHint Hint);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
410
|
95
|
411 /// We know that there is no SCEV for the specified value. Analyze the
|
|
412 /// expression.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
413 const SCEV *createSCEV(Value *V);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
414
|
95
|
415 /// Provide the special handling we need to analyze PHI SCEVs.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
416 const SCEV *createNodeForPHI(PHINode *PN);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
417
|
95
|
418 /// Helper function called from createNodeForPHI.
|
|
419 const SCEV *createAddRecFromPHI(PHINode *PN);
|
|
420
|
|
421 /// Helper function called from createNodeForPHI.
|
|
422 const SCEV *createNodeFromSelectLikePHI(PHINode *PN);
|
|
423
|
|
424 /// Provide special handling for a select-like instruction (currently this
|
|
425 /// is either a select instruction or a phi node). \p I is the instruction
|
|
426 /// being processed, and it is assumed equivalent to "Cond ? TrueVal :
|
|
427 /// FalseVal".
|
|
428 const SCEV *createNodeForSelectOrPHI(Instruction *I, Value *Cond,
|
|
429 Value *TrueVal, Value *FalseVal);
|
|
430
|
|
431 /// Provide the special handling we need to analyze GEP SCEVs.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
432 const SCEV *createNodeForGEP(GEPOperator *GEP);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
433
|
95
|
434 /// Implementation code for getSCEVAtScope; called at most once for each
|
|
435 /// SCEV+Loop pair.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
436 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
437 const SCEV *computeSCEVAtScope(const SCEV *S, const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
438
|
95
|
439 /// This looks up computed SCEV values for all instructions that depend on
|
|
440 /// the given instruction and removes them from the ValueExprMap map if they
|
|
441 /// reference SymName. This is used during PHI resolution.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
442 void ForgetSymbolicName(Instruction *I, const SCEV *SymName);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
443
|
95
|
444 /// Return the BackedgeTakenInfo for the given loop, lazily computing new
|
|
445 /// values if the loop hasn't been analyzed yet.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
446 const BackedgeTakenInfo &getBackedgeTakenInfo(const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
447
|
95
|
448 /// Compute the number of times the specified loop will iterate.
|
|
449 BackedgeTakenInfo computeBackedgeTakenCount(const Loop *L);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
450
|
95
|
451 /// Compute the number of times the backedge of the specified loop will
|
|
452 /// execute if it exits via the specified block.
|
|
453 ExitLimit computeExitLimit(const Loop *L, BasicBlock *ExitingBlock);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
454
|
95
|
455 /// Compute the number of times the backedge of the specified loop will
|
|
456 /// execute if its exit condition were a conditional branch of ExitCond,
|
|
457 /// TBB, and FBB.
|
|
458 ExitLimit computeExitLimitFromCond(const Loop *L,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
459 Value *ExitCond,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
460 BasicBlock *TBB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
461 BasicBlock *FBB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
462 bool IsSubExpr);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
463
|
95
|
464 /// Compute the number of times the backedge of the specified loop will
|
|
465 /// execute if its exit condition were a conditional branch of the ICmpInst
|
|
466 /// ExitCond, TBB, and FBB.
|
|
467 ExitLimit computeExitLimitFromICmp(const Loop *L,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
468 ICmpInst *ExitCond,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
469 BasicBlock *TBB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
470 BasicBlock *FBB,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
471 bool IsSubExpr);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
472
|
95
|
473 /// Compute the number of times the backedge of the specified loop will
|
|
474 /// execute if its exit condition were a switch with a single exiting case
|
|
475 /// to ExitingBB.
|
77
|
476 ExitLimit
|
95
|
477 computeExitLimitFromSingleExitSwitch(const Loop *L, SwitchInst *Switch,
|
77
|
478 BasicBlock *ExitingBB, bool IsSubExpr);
|
|
479
|
95
|
480 /// Given an exit condition of 'icmp op load X, cst', try to see if we can
|
|
481 /// compute the backedge-taken count.
|
|
482 ExitLimit computeLoadConstantCompareExitLimit(LoadInst *LI,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
483 Constant *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
484 const Loop *L,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
485 ICmpInst::Predicate p);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
486
|
95
|
487 /// If the loop is known to execute a constant number of times (the
|
|
488 /// condition evolves only from constants), try to evaluate a few iterations
|
|
489 /// of the loop until we get the exit condition gets a value of ExitWhen
|
|
490 /// (true or false). If we cannot evaluate the exit count of the loop,
|
|
491 /// return CouldNotCompute.
|
|
492 const SCEV *computeExitCountExhaustively(const Loop *L,
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
493 Value *Cond,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
494 bool ExitWhen);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
495
|
95
|
496 /// Return the number of times an exit condition comparing the specified
|
|
497 /// value to zero will execute. If not computable, return CouldNotCompute.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
498 ExitLimit HowFarToZero(const SCEV *V, const Loop *L, bool IsSubExpr);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
499
|
95
|
500 /// Return the number of times an exit condition checking the specified
|
|
501 /// value for nonzero will execute. If not computable, return
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
502 /// CouldNotCompute.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
503 ExitLimit HowFarToNonZero(const SCEV *V, const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
504
|
95
|
505 /// Return the number of times an exit condition containing the specified
|
|
506 /// less-than comparison will execute. If not computable, return
|
|
507 /// CouldNotCompute. isSigned specifies whether the less-than is signed.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
508 ExitLimit HowManyLessThans(const SCEV *LHS, const SCEV *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
509 const Loop *L, bool isSigned, bool IsSubExpr);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
510 ExitLimit HowManyGreaterThans(const SCEV *LHS, const SCEV *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
511 const Loop *L, bool isSigned, bool IsSubExpr);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
512
|
95
|
513 /// Return a predecessor of BB (which may not be an immediate predecessor)
|
|
514 /// which has exactly one successor from which BB is reachable, or null if
|
|
515 /// no such block is found.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
516 std::pair<BasicBlock *, BasicBlock *>
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
517 getPredecessorWithUniqueSuccessorForBB(BasicBlock *BB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
518
|
95
|
519 /// Test whether the condition described by Pred, LHS, and RHS is true
|
|
520 /// whenever the given FoundCondValue value evaluates to true.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
521 bool isImpliedCond(ICmpInst::Predicate Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
522 const SCEV *LHS, const SCEV *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
523 Value *FoundCondValue,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
524 bool Inverse);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
525
|
95
|
526 /// Test whether the condition described by Pred, LHS, and RHS is true
|
|
527 /// whenever the condition described by FoundPred, FoundLHS, FoundRHS is
|
|
528 /// true.
|
|
529 bool isImpliedCond(ICmpInst::Predicate Pred, const SCEV *LHS,
|
|
530 const SCEV *RHS, ICmpInst::Predicate FoundPred,
|
|
531 const SCEV *FoundLHS, const SCEV *FoundRHS);
|
|
532
|
|
533 /// Test whether the condition described by Pred, LHS, and RHS is true
|
|
534 /// whenever the condition described by Pred, FoundLHS, and FoundRHS is
|
|
535 /// true.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
536 bool isImpliedCondOperands(ICmpInst::Predicate Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
537 const SCEV *LHS, const SCEV *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
538 const SCEV *FoundLHS, const SCEV *FoundRHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
539
|
95
|
540 /// Test whether the condition described by Pred, LHS, and RHS is true
|
|
541 /// whenever the condition described by Pred, FoundLHS, and FoundRHS is
|
|
542 /// true.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
543 bool isImpliedCondOperandsHelper(ICmpInst::Predicate Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
544 const SCEV *LHS, const SCEV *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
545 const SCEV *FoundLHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
546 const SCEV *FoundRHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
547
|
95
|
548 /// Test whether the condition described by Pred, LHS, and RHS is true
|
|
549 /// whenever the condition described by Pred, FoundLHS, and FoundRHS is
|
|
550 /// true. Utility function used by isImpliedCondOperands.
|
|
551 bool isImpliedCondOperandsViaRanges(ICmpInst::Predicate Pred,
|
|
552 const SCEV *LHS, const SCEV *RHS,
|
|
553 const SCEV *FoundLHS,
|
|
554 const SCEV *FoundRHS);
|
|
555
|
|
556 /// Test whether the condition described by Pred, LHS, and RHS is true
|
|
557 /// whenever the condition described by Pred, FoundLHS, and FoundRHS is
|
|
558 /// true.
|
|
559 ///
|
|
560 /// This routine tries to rule out certain kinds of integer overflow, and
|
|
561 /// then tries to reason about arithmetic properties of the predicates.
|
|
562 bool isImpliedCondOperandsViaNoOverflow(ICmpInst::Predicate Pred,
|
|
563 const SCEV *LHS, const SCEV *RHS,
|
|
564 const SCEV *FoundLHS,
|
|
565 const SCEV *FoundRHS);
|
|
566
|
|
567 /// If we know that the specified Phi is in the header of its containing
|
|
568 /// loop, we know the loop executes a constant number of times, and the PHI
|
|
569 /// node is just a recurrence involving constants, fold it.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
570 Constant *getConstantEvolutionLoopExitValue(PHINode *PN, const APInt& BEs,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
571 const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
572
|
95
|
573 /// Test if the given expression is known to satisfy the condition described
|
|
574 /// by Pred and the known constant ranges of LHS and RHS.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
575 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
576 bool isKnownPredicateWithRanges(ICmpInst::Predicate Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
577 const SCEV *LHS, const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
578
|
95
|
579 /// Try to split Pred LHS RHS into logical conjunctions (and's) and try to
|
|
580 /// prove them individually.
|
|
581 bool isKnownPredicateViaSplitting(ICmpInst::Predicate Pred, const SCEV *LHS,
|
|
582 const SCEV *RHS);
|
|
583
|
|
584 /// Try to match the Expr as "(L + R)<Flags>".
|
|
585 bool splitBinaryAdd(const SCEV *Expr, const SCEV *&L, const SCEV *&R,
|
|
586 SCEV::NoWrapFlags &Flags);
|
|
587
|
|
588 /// Return true if More == (Less + C), where C is a constant. This is
|
|
589 /// intended to be used as a cheaper substitute for full SCEV subtraction.
|
|
590 bool computeConstantDifference(const SCEV *Less, const SCEV *More,
|
|
591 APInt &C);
|
|
592
|
|
593 /// Drop memoized information computed for S.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
594 void forgetMemoizedResults(const SCEV *S);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
595
|
95
|
596 /// Return an existing SCEV for V if there is one, otherwise return nullptr.
|
|
597 const SCEV *getExistingSCEV(Value *V);
|
|
598
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
599 /// Return false iff given SCEV contains a SCEVUnknown with NULL value-
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
600 /// pointer.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
601 bool checkValidity(const SCEV *S) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
602
|
95
|
603 /// Return true if `ExtendOpTy`({`Start`,+,`Step`}) can be proved to be
|
|
604 /// equal to {`ExtendOpTy`(`Start`),+,`ExtendOpTy`(`Step`)}. This is
|
|
605 /// equivalent to proving no signed (resp. unsigned) wrap in
|
|
606 /// {`Start`,+,`Step`} if `ExtendOpTy` is `SCEVSignExtendExpr`
|
|
607 /// (resp. `SCEVZeroExtendExpr`).
|
|
608 ///
|
|
609 template<typename ExtendOpTy>
|
|
610 bool proveNoWrapByVaryingStart(const SCEV *Start, const SCEV *Step,
|
|
611 const Loop *L);
|
|
612
|
|
613 bool isMonotonicPredicateImpl(const SCEVAddRecExpr *LHS,
|
|
614 ICmpInst::Predicate Pred, bool &Increasing);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
615
|
95
|
616 /// Return true if, for all loop invariant X, the predicate "LHS `Pred` X"
|
|
617 /// is monotonically increasing or decreasing. In the former case set
|
|
618 /// `Increasing` to true and in the latter case set `Increasing` to false.
|
|
619 ///
|
|
620 /// A predicate is said to be monotonically increasing if may go from being
|
|
621 /// false to being true as the loop iterates, but never the other way
|
|
622 /// around. A predicate is said to be monotonically decreasing if may go
|
|
623 /// from being true to being false as the loop iterates, but never the other
|
|
624 /// way around.
|
|
625 bool isMonotonicPredicate(const SCEVAddRecExpr *LHS,
|
|
626 ICmpInst::Predicate Pred, bool &Increasing);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
627
|
95
|
628 // Return SCEV no-wrap flags that can be proven based on reasoning
|
|
629 // about how poison produced from no-wrap flags on this value
|
|
630 // (e.g. a nuw add) would trigger undefined behavior on overflow.
|
|
631 SCEV::NoWrapFlags getNoWrapFlagsFromUB(const Value *V);
|
|
632
|
|
633 public:
|
|
634 ScalarEvolution(Function &F, TargetLibraryInfo &TLI, AssumptionCache &AC,
|
|
635 DominatorTree &DT, LoopInfo &LI);
|
|
636 ~ScalarEvolution();
|
|
637 ScalarEvolution(ScalarEvolution &&Arg);
|
|
638
|
|
639 LLVMContext &getContext() const { return F.getContext(); }
|
|
640
|
|
641 /// Test if values of the given type are analyzable within the SCEV
|
|
642 /// framework. This primarily includes integer types, and it can optionally
|
|
643 /// include pointer types if the ScalarEvolution class has access to
|
|
644 /// target-specific information.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
645 bool isSCEVable(Type *Ty) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
646
|
95
|
647 /// Return the size in bits of the specified type, for which isSCEVable must
|
|
648 /// return true.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
649 uint64_t getTypeSizeInBits(Type *Ty) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
650
|
95
|
651 /// Return a type with the same bitwidth as the given type and which
|
|
652 /// represents how SCEV will treat the given type, for which isSCEVable must
|
|
653 /// return true. For pointer types, this is the pointer-sized integer type.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
654 Type *getEffectiveSCEVType(Type *Ty) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
655
|
95
|
656 /// Return a SCEV expression for the full generality of the specified
|
|
657 /// expression.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
658 const SCEV *getSCEV(Value *V);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
659
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
660 const SCEV *getConstant(ConstantInt *V);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
661 const SCEV *getConstant(const APInt& Val);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
662 const SCEV *getConstant(Type *Ty, uint64_t V, bool isSigned = false);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
663 const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
664 const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
665 const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
666 const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
667 const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
668 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
669 const SCEV *getAddExpr(const SCEV *LHS, const SCEV *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
670 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
671 SmallVector<const SCEV *, 2> Ops;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
672 Ops.push_back(LHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
673 Ops.push_back(RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
674 return getAddExpr(Ops, Flags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
675 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
676 const SCEV *getAddExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
677 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
678 SmallVector<const SCEV *, 3> Ops;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
679 Ops.push_back(Op0);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
680 Ops.push_back(Op1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
681 Ops.push_back(Op2);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
682 return getAddExpr(Ops, Flags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
683 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
684 const SCEV *getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
685 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
686 const SCEV *getMulExpr(const SCEV *LHS, const SCEV *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
687 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap)
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
688 {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
689 SmallVector<const SCEV *, 2> Ops;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
690 Ops.push_back(LHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
691 Ops.push_back(RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
692 return getMulExpr(Ops, Flags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
693 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
694 const SCEV *getMulExpr(const SCEV *Op0, const SCEV *Op1, const SCEV *Op2,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
695 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
696 SmallVector<const SCEV *, 3> Ops;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
697 Ops.push_back(Op0);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
698 Ops.push_back(Op1);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
699 Ops.push_back(Op2);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
700 return getMulExpr(Ops, Flags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
701 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
702 const SCEV *getUDivExpr(const SCEV *LHS, const SCEV *RHS);
|
77
|
703 const SCEV *getUDivExactExpr(const SCEV *LHS, const SCEV *RHS);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
704 const SCEV *getAddRecExpr(const SCEV *Start, const SCEV *Step,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
705 const Loop *L, SCEV::NoWrapFlags Flags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
706 const SCEV *getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
707 const Loop *L, SCEV::NoWrapFlags Flags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
708 const SCEV *getAddRecExpr(const SmallVectorImpl<const SCEV *> &Operands,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
709 const Loop *L, SCEV::NoWrapFlags Flags) {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
710 SmallVector<const SCEV *, 4> NewOp(Operands.begin(), Operands.end());
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
711 return getAddRecExpr(NewOp, L, Flags);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
712 }
|
95
|
713 /// \brief Returns an expression for a GEP
|
|
714 ///
|
|
715 /// \p PointeeType The type used as the basis for the pointer arithmetics
|
|
716 /// \p BaseExpr The expression for the pointer operand.
|
|
717 /// \p IndexExprs The expressions for the indices.
|
|
718 /// \p InBounds Whether the GEP is in bounds.
|
|
719 const SCEV *getGEPExpr(Type *PointeeType, const SCEV *BaseExpr,
|
|
720 const SmallVectorImpl<const SCEV *> &IndexExprs,
|
|
721 bool InBounds = false);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
722 const SCEV *getSMaxExpr(const SCEV *LHS, const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
723 const SCEV *getSMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
724 const SCEV *getUMaxExpr(const SCEV *LHS, const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
725 const SCEV *getUMaxExpr(SmallVectorImpl<const SCEV *> &Operands);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
726 const SCEV *getSMinExpr(const SCEV *LHS, const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
727 const SCEV *getUMinExpr(const SCEV *LHS, const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
728 const SCEV *getUnknown(Value *V);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
729 const SCEV *getCouldNotCompute();
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
730
|
95
|
731 /// \brief Return a SCEV for the constant 0 of a specific type.
|
|
732 const SCEV *getZero(Type *Ty) { return getConstant(Ty, 0); }
|
|
733
|
|
734 /// \brief Return a SCEV for the constant 1 of a specific type.
|
|
735 const SCEV *getOne(Type *Ty) { return getConstant(Ty, 1); }
|
|
736
|
|
737 /// Return an expression for sizeof AllocTy that is type IntTy
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
738 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
739 const SCEV *getSizeOfExpr(Type *IntTy, Type *AllocTy);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
740
|
95
|
741 /// Return an expression for offsetof on the given field with type IntTy
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
742 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
743 const SCEV *getOffsetOfExpr(Type *IntTy, StructType *STy, unsigned FieldNo);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
744
|
95
|
745 /// Return the SCEV object corresponding to -V.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
746 ///
|
95
|
747 const SCEV *getNegativeSCEV(const SCEV *V,
|
|
748 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
749
|
95
|
750 /// Return the SCEV object corresponding to ~V.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
751 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
752 const SCEV *getNotSCEV(const SCEV *V);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
753
|
95
|
754 /// Return LHS-RHS. Minus is represented in SCEV as A+B*-1.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
755 const SCEV *getMinusSCEV(const SCEV *LHS, const SCEV *RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
756 SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
757
|
95
|
758 /// Return a SCEV corresponding to a conversion of the input value to the
|
|
759 /// specified type. If the type must be extended, it is zero extended.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
760 const SCEV *getTruncateOrZeroExtend(const SCEV *V, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
761
|
95
|
762 /// Return a SCEV corresponding to a conversion of the input value to the
|
|
763 /// specified type. If the type must be extended, it is sign extended.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
764 const SCEV *getTruncateOrSignExtend(const SCEV *V, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
765
|
95
|
766 /// Return a SCEV corresponding to a conversion of the input value to the
|
|
767 /// specified type. If the type must be extended, it is zero extended. The
|
|
768 /// conversion must not be narrowing.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
769 const SCEV *getNoopOrZeroExtend(const SCEV *V, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
770
|
95
|
771 /// Return a SCEV corresponding to a conversion of the input value to the
|
|
772 /// specified type. If the type must be extended, it is sign extended. The
|
|
773 /// conversion must not be narrowing.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
774 const SCEV *getNoopOrSignExtend(const SCEV *V, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
775
|
95
|
776 /// Return a SCEV corresponding to a conversion of the input value to the
|
|
777 /// specified type. If the type must be extended, it is extended with
|
|
778 /// unspecified bits. The conversion must not be narrowing.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
779 const SCEV *getNoopOrAnyExtend(const SCEV *V, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
780
|
95
|
781 /// Return a SCEV corresponding to a conversion of the input value to the
|
|
782 /// specified type. The conversion must not be widening.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
783 const SCEV *getTruncateOrNoop(const SCEV *V, Type *Ty);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
784
|
95
|
785 /// Promote the operands to the wider of the types using zero-extension, and
|
|
786 /// then perform a umax operation with them.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
787 const SCEV *getUMaxFromMismatchedTypes(const SCEV *LHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
788 const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
789
|
95
|
790 /// Promote the operands to the wider of the types using zero-extension, and
|
|
791 /// then perform a umin operation with them.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
792 const SCEV *getUMinFromMismatchedTypes(const SCEV *LHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
793 const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
794
|
95
|
795 /// Transitively follow the chain of pointer-type operands until reaching a
|
|
796 /// SCEV that does not have a single pointer operand. This returns a
|
|
797 /// SCEVUnknown pointer for well-formed pointer-type expressions, but corner
|
|
798 /// cases do exist.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
799 const SCEV *getPointerBase(const SCEV *V);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
800
|
95
|
801 /// Return a SCEV expression for the specified value at the specified scope
|
|
802 /// in the program. The L value specifies a loop nest to evaluate the
|
|
803 /// expression at, where null is the top-level or a specified loop is
|
|
804 /// immediately inside of the loop.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
805 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
806 /// This method can be used to compute the exit value for a variable defined
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
807 /// in a loop by querying what the value will hold in the parent loop.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
808 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
809 /// In the case that a relevant loop exit value cannot be computed, the
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
810 /// original value V is returned.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
811 const SCEV *getSCEVAtScope(const SCEV *S, const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
812
|
95
|
813 /// This is a convenience function which does getSCEVAtScope(getSCEV(V), L).
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
814 const SCEV *getSCEVAtScope(Value *V, const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
815
|
95
|
816 /// Test whether entry to the loop is protected by a conditional between LHS
|
|
817 /// and RHS. This is used to help avoid max expressions in loop trip
|
|
818 /// counts, and to eliminate casts.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
819 bool isLoopEntryGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
820 const SCEV *LHS, const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
821
|
95
|
822 /// Test whether the backedge of the loop is protected by a conditional
|
|
823 /// between LHS and RHS. This is used to to eliminate casts.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
824 bool isLoopBackedgeGuardedByCond(const Loop *L, ICmpInst::Predicate Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
825 const SCEV *LHS, const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
826
|
83
|
827 /// \brief Returns the maximum trip count of the loop if it is a single-exit
|
|
828 /// loop and we can compute a small maximum for that loop.
|
|
829 ///
|
|
830 /// Implemented in terms of the \c getSmallConstantTripCount overload with
|
|
831 /// the single exiting block passed to it. See that routine for details.
|
|
832 unsigned getSmallConstantTripCount(Loop *L);
|
|
833
|
95
|
834 /// Returns the maximum trip count of this loop as a normal unsigned
|
|
835 /// value. Returns 0 if the trip count is unknown or not constant. This
|
|
836 /// "trip count" assumes that control exits via ExitingBlock. More
|
|
837 /// precisely, it is the number of times that control may reach ExitingBlock
|
|
838 /// before taking the branch. For loops with multiple exits, it may not be
|
|
839 /// the number times that the loop header executes if the loop exits
|
|
840 /// prematurely via another branch.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
841 unsigned getSmallConstantTripCount(Loop *L, BasicBlock *ExitingBlock);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
842
|
83
|
843 /// \brief Returns the largest constant divisor of the trip count of the
|
|
844 /// loop if it is a single-exit loop and we can compute a small maximum for
|
|
845 /// that loop.
|
|
846 ///
|
|
847 /// Implemented in terms of the \c getSmallConstantTripMultiple overload with
|
|
848 /// the single exiting block passed to it. See that routine for details.
|
|
849 unsigned getSmallConstantTripMultiple(Loop *L);
|
|
850
|
95
|
851 /// Returns the largest constant divisor of the trip count of this loop as a
|
|
852 /// normal unsigned value, if possible. This means that the actual trip
|
|
853 /// count is always a multiple of the returned value (don't forget the trip
|
|
854 /// count could very well be zero as well!). As explained in the comments
|
|
855 /// for getSmallConstantTripCount, this assumes that control exits the loop
|
|
856 /// via ExitingBlock.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
857 unsigned getSmallConstantTripMultiple(Loop *L, BasicBlock *ExitingBlock);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
858
|
95
|
859 /// Get the expression for the number of loop iterations for which this loop
|
|
860 /// is guaranteed not to exit via ExitingBlock. Otherwise return
|
|
861 /// SCEVCouldNotCompute.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
862 const SCEV *getExitCount(Loop *L, BasicBlock *ExitingBlock);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
863
|
95
|
864 /// If the specified loop has a predictable backedge-taken count, return it,
|
|
865 /// otherwise return a SCEVCouldNotCompute object. The backedge-taken count
|
|
866 /// is the number of times the loop header will be branched to from within
|
|
867 /// the loop. This is one less than the trip count of the loop, since it
|
|
868 /// doesn't count the first iteration, when the header is branched to from
|
|
869 /// outside the loop.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
870 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
871 /// Note that it is not valid to call this method on a loop without a
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
872 /// loop-invariant backedge-taken count (see
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
873 /// hasLoopInvariantBackedgeTakenCount).
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
874 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
875 const SCEV *getBackedgeTakenCount(const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
876
|
95
|
877 /// Similar to getBackedgeTakenCount, except return the least SCEV value
|
|
878 /// that is known never to be less than the actual backedge taken count.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
879 const SCEV *getMaxBackedgeTakenCount(const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
880
|
95
|
881 /// Return true if the specified loop has an analyzable loop-invariant
|
|
882 /// backedge-taken count.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
883 bool hasLoopInvariantBackedgeTakenCount(const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
884
|
95
|
885 /// This method should be called by the client when it has changed a loop in
|
|
886 /// a way that may effect ScalarEvolution's ability to compute a trip count,
|
|
887 /// or if the loop is deleted. This call is potentially expensive for large
|
|
888 /// loop bodies.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
889 void forgetLoop(const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
890
|
95
|
891 /// This method should be called by the client when it has changed a value
|
|
892 /// in a way that may effect its value, or which may disconnect it from a
|
|
893 /// def-use chain linking it to a loop.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
894 void forgetValue(Value *V);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
895
|
77
|
896 /// \brief Called when the client has changed the disposition of values in
|
|
897 /// this loop.
|
|
898 ///
|
|
899 /// We don't have a way to invalidate per-loop dispositions. Clear and
|
|
900 /// recompute is simpler.
|
|
901 void forgetLoopDispositions(const Loop *L) { LoopDispositions.clear(); }
|
|
902
|
95
|
903 /// Determine the minimum number of zero bits that S is guaranteed to end in
|
|
904 /// (at every loop iteration). It is, at the same time, the minimum number
|
|
905 /// of times S is divisible by 2. For example, given {4,+,8} it returns 2.
|
|
906 /// If S is guaranteed to be 0, it returns the bitwidth of S.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
907 uint32_t GetMinTrailingZeros(const SCEV *S);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
908
|
95
|
909 /// Determine the unsigned range for a particular SCEV.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
910 ///
|
95
|
911 ConstantRange getUnsignedRange(const SCEV *S) {
|
|
912 return getRange(S, HINT_RANGE_UNSIGNED);
|
|
913 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
914
|
95
|
915 /// Determine the signed range for a particular SCEV.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
916 ///
|
95
|
917 ConstantRange getSignedRange(const SCEV *S) {
|
|
918 return getRange(S, HINT_RANGE_SIGNED);
|
|
919 }
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
920
|
95
|
921 /// Test if the given expression is known to be negative.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
922 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
923 bool isKnownNegative(const SCEV *S);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
924
|
95
|
925 /// Test if the given expression is known to be positive.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
926 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
927 bool isKnownPositive(const SCEV *S);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
928
|
95
|
929 /// Test if the given expression is known to be non-negative.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
930 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
931 bool isKnownNonNegative(const SCEV *S);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
932
|
95
|
933 /// Test if the given expression is known to be non-positive.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
934 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
935 bool isKnownNonPositive(const SCEV *S);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
936
|
95
|
937 /// Test if the given expression is known to be non-zero.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
938 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
939 bool isKnownNonZero(const SCEV *S);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
940
|
95
|
941 /// Test if the given expression is known to satisfy the condition described
|
|
942 /// by Pred, LHS, and RHS.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
943 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
944 bool isKnownPredicate(ICmpInst::Predicate Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
945 const SCEV *LHS, const SCEV *RHS);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
946
|
95
|
947 /// Return true if the result of the predicate LHS `Pred` RHS is loop
|
|
948 /// invariant with respect to L. Set InvariantPred, InvariantLHS and
|
|
949 /// InvariantLHS so that InvariantLHS `InvariantPred` InvariantRHS is the
|
|
950 /// loop invariant form of LHS `Pred` RHS.
|
|
951 bool isLoopInvariantPredicate(ICmpInst::Predicate Pred, const SCEV *LHS,
|
|
952 const SCEV *RHS, const Loop *L,
|
|
953 ICmpInst::Predicate &InvariantPred,
|
|
954 const SCEV *&InvariantLHS,
|
|
955 const SCEV *&InvariantRHS);
|
|
956
|
|
957 /// Simplify LHS and RHS in a comparison with predicate Pred. Return true
|
|
958 /// iff any changes were made. If the operands are provably equal or
|
|
959 /// unequal, LHS and RHS are set to the same value and Pred is set to either
|
|
960 /// ICMP_EQ or ICMP_NE.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
961 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
962 bool SimplifyICmpOperands(ICmpInst::Predicate &Pred,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
963 const SCEV *&LHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
964 const SCEV *&RHS,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
965 unsigned Depth = 0);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
966
|
95
|
967 /// Return the "disposition" of the given SCEV with respect to the given
|
|
968 /// loop.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
969 LoopDisposition getLoopDisposition(const SCEV *S, const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
970
|
95
|
971 /// Return true if the value of the given SCEV is unchanging in the
|
|
972 /// specified loop.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
973 bool isLoopInvariant(const SCEV *S, const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
974
|
95
|
975 /// Return true if the given SCEV changes value in a known way in the
|
|
976 /// specified loop. This property being true implies that the value is
|
|
977 /// variant in the loop AND that we can emit an expression to compute the
|
|
978 /// value of the expression at any particular loop iteration.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
979 bool hasComputableLoopEvolution(const SCEV *S, const Loop *L);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
980
|
95
|
981 /// Return the "disposition" of the given SCEV with respect to the given
|
|
982 /// block.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
983 BlockDisposition getBlockDisposition(const SCEV *S, const BasicBlock *BB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
984
|
95
|
985 /// Return true if elements that makes up the given SCEV dominate the
|
|
986 /// specified basic block.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
987 bool dominates(const SCEV *S, const BasicBlock *BB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
988
|
95
|
989 /// Return true if elements that makes up the given SCEV properly dominate
|
|
990 /// the specified basic block.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
991 bool properlyDominates(const SCEV *S, const BasicBlock *BB);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
992
|
95
|
993 /// Test whether the given SCEV has Op as a direct or indirect operand.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
994 bool hasOperand(const SCEV *S, const SCEV *Op) const;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
995
|
77
|
996 /// Return the size of an element read or written by Inst.
|
|
997 const SCEV *getElementSize(Instruction *Inst);
|
|
998
|
|
999 /// Compute the array dimensions Sizes from the set of Terms extracted from
|
|
1000 /// the memory access function of this SCEVAddRecExpr.
|
|
1001 void findArrayDimensions(SmallVectorImpl<const SCEV *> &Terms,
|
|
1002 SmallVectorImpl<const SCEV *> &Sizes,
|
|
1003 const SCEV *ElementSize) const;
|
|
1004
|
95
|
1005 void print(raw_ostream &OS) const;
|
|
1006 void verify() const;
|
|
1007
|
|
1008 /// Collect parametric terms occurring in step expressions.
|
|
1009 void collectParametricTerms(const SCEV *Expr,
|
|
1010 SmallVectorImpl<const SCEV *> &Terms);
|
|
1011
|
|
1012
|
|
1013
|
|
1014 /// Return in Subscripts the access functions for each dimension in Sizes.
|
|
1015 void computeAccessFunctions(const SCEV *Expr,
|
|
1016 SmallVectorImpl<const SCEV *> &Subscripts,
|
|
1017 SmallVectorImpl<const SCEV *> &Sizes);
|
|
1018
|
|
1019 /// Split this SCEVAddRecExpr into two vectors of SCEVs representing the
|
|
1020 /// subscripts and sizes of an array access.
|
|
1021 ///
|
|
1022 /// The delinearization is a 3 step process: the first two steps compute the
|
|
1023 /// sizes of each subscript and the third step computes the access functions
|
|
1024 /// for the delinearized array:
|
|
1025 ///
|
|
1026 /// 1. Find the terms in the step functions
|
|
1027 /// 2. Compute the array size
|
|
1028 /// 3. Compute the access function: divide the SCEV by the array size
|
|
1029 /// starting with the innermost dimensions found in step 2. The Quotient
|
|
1030 /// is the SCEV to be divided in the next step of the recursion. The
|
|
1031 /// Remainder is the subscript of the innermost dimension. Loop over all
|
|
1032 /// array dimensions computed in step 2.
|
|
1033 ///
|
|
1034 /// To compute a uniform array size for several memory accesses to the same
|
|
1035 /// object, one can collect in step 1 all the step terms for all the memory
|
|
1036 /// accesses, and compute in step 2 a unique array shape. This guarantees
|
|
1037 /// that the array shape will be the same across all memory accesses.
|
|
1038 ///
|
|
1039 /// FIXME: We could derive the result of steps 1 and 2 from a description of
|
|
1040 /// the array shape given in metadata.
|
|
1041 ///
|
|
1042 /// Example:
|
|
1043 ///
|
|
1044 /// A[][n][m]
|
|
1045 ///
|
|
1046 /// for i
|
|
1047 /// for j
|
|
1048 /// for k
|
|
1049 /// A[j+k][2i][5i] =
|
|
1050 ///
|
|
1051 /// The initial SCEV:
|
|
1052 ///
|
|
1053 /// A[{{{0,+,2*m+5}_i, +, n*m}_j, +, n*m}_k]
|
|
1054 ///
|
|
1055 /// 1. Find the different terms in the step functions:
|
|
1056 /// -> [2*m, 5, n*m, n*m]
|
|
1057 ///
|
|
1058 /// 2. Compute the array size: sort and unique them
|
|
1059 /// -> [n*m, 2*m, 5]
|
|
1060 /// find the GCD of all the terms = 1
|
|
1061 /// divide by the GCD and erase constant terms
|
|
1062 /// -> [n*m, 2*m]
|
|
1063 /// GCD = m
|
|
1064 /// divide by GCD -> [n, 2]
|
|
1065 /// remove constant terms
|
|
1066 /// -> [n]
|
|
1067 /// size of the array is A[unknown][n][m]
|
|
1068 ///
|
|
1069 /// 3. Compute the access function
|
|
1070 /// a. Divide {{{0,+,2*m+5}_i, +, n*m}_j, +, n*m}_k by the innermost size m
|
|
1071 /// Quotient: {{{0,+,2}_i, +, n}_j, +, n}_k
|
|
1072 /// Remainder: {{{0,+,5}_i, +, 0}_j, +, 0}_k
|
|
1073 /// The remainder is the subscript of the innermost array dimension: [5i].
|
|
1074 ///
|
|
1075 /// b. Divide Quotient: {{{0,+,2}_i, +, n}_j, +, n}_k by next outer size n
|
|
1076 /// Quotient: {{{0,+,0}_i, +, 1}_j, +, 1}_k
|
|
1077 /// Remainder: {{{0,+,2}_i, +, 0}_j, +, 0}_k
|
|
1078 /// The Remainder is the subscript of the next array dimension: [2i].
|
|
1079 ///
|
|
1080 /// The subscript of the outermost dimension is the Quotient: [j+k].
|
|
1081 ///
|
|
1082 /// Overall, we have: A[][n][m], and the access function: A[j+k][2i][5i].
|
|
1083 void delinearize(const SCEV *Expr,
|
|
1084 SmallVectorImpl<const SCEV *> &Subscripts,
|
|
1085 SmallVectorImpl<const SCEV *> &Sizes,
|
|
1086 const SCEV *ElementSize);
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1087
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1088 private:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1089 /// Compute the backedge taken count knowing the interval difference, the
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1090 /// stride and presence of the equality in the comparison.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1091 const SCEV *computeBECount(const SCEV *Delta, const SCEV *Stride,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1092 bool Equality);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1093
|
77
|
1094 /// Verify if an linear IV with positive stride can overflow when in a
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1095 /// less-than comparison, knowing the invariant term of the comparison,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1096 /// the stride and the knowledge of NSW/NUW flags on the recurrence.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1097 bool doesIVOverflowOnLT(const SCEV *RHS, const SCEV *Stride,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1098 bool IsSigned, bool NoWrap);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1099
|
77
|
1100 /// Verify if an linear IV with negative stride can overflow when in a
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1101 /// greater-than comparison, knowing the invariant term of the comparison,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1102 /// the stride and the knowledge of NSW/NUW flags on the recurrence.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1103 bool doesIVOverflowOnGT(const SCEV *RHS, const SCEV *Stride,
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1104 bool IsSigned, bool NoWrap);
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1105
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1106 private:
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1107 FoldingSet<SCEV> UniqueSCEVs;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1108 BumpPtrAllocator SCEVAllocator;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1109
|
95
|
1110 /// The head of a linked list of all SCEVUnknown values that have been
|
|
1111 /// allocated. This is used by releaseMemory to locate them all and call
|
|
1112 /// their destructors.
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1113 SCEVUnknown *FirstUnknown;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1114 };
|
95
|
1115
|
|
1116 /// \brief Analysis pass that exposes the \c ScalarEvolution for a function.
|
|
1117 class ScalarEvolutionAnalysis {
|
|
1118 static char PassID;
|
|
1119
|
|
1120 public:
|
|
1121 typedef ScalarEvolution Result;
|
|
1122
|
|
1123 /// \brief Opaque, unique identifier for this analysis pass.
|
|
1124 static void *ID() { return (void *)&PassID; }
|
|
1125
|
|
1126 /// \brief Provide a name for the analysis for debugging and logging.
|
|
1127 static StringRef name() { return "ScalarEvolutionAnalysis"; }
|
|
1128
|
|
1129 ScalarEvolution run(Function &F, AnalysisManager<Function> *AM);
|
|
1130 };
|
|
1131
|
|
1132 /// \brief Printer pass for the \c ScalarEvolutionAnalysis results.
|
|
1133 class ScalarEvolutionPrinterPass {
|
|
1134 raw_ostream &OS;
|
|
1135
|
|
1136 public:
|
|
1137 explicit ScalarEvolutionPrinterPass(raw_ostream &OS) : OS(OS) {}
|
|
1138 PreservedAnalyses run(Function &F, AnalysisManager<Function> *AM);
|
|
1139
|
|
1140 static StringRef name() { return "ScalarEvolutionPrinterPass"; }
|
|
1141 };
|
|
1142
|
|
1143 class ScalarEvolutionWrapperPass : public FunctionPass {
|
|
1144 std::unique_ptr<ScalarEvolution> SE;
|
|
1145
|
|
1146 public:
|
|
1147 static char ID;
|
|
1148
|
|
1149 ScalarEvolutionWrapperPass();
|
|
1150
|
|
1151 ScalarEvolution &getSE() { return *SE; }
|
|
1152 const ScalarEvolution &getSE() const { return *SE; }
|
|
1153
|
|
1154 bool runOnFunction(Function &F) override;
|
|
1155 void releaseMemory() override;
|
|
1156 void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
1157 void print(raw_ostream &OS, const Module * = nullptr) const override;
|
|
1158 void verifyAnalysis() const override;
|
|
1159 };
|
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1160 }
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1161
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1162 #endif
|