| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_INDUCTION_VAR_ANALYSIS_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_INDUCTION_VAR_ANALYSIS_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | |
| Vladimir Marko | e272715 | 2019-10-10 10:46:42 +0100 | [diff] [blame^] | 22 | #include "base/macros.h" |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 23 | #include "nodes.h" |
| 24 | #include "optimization.h" |
| 25 | |
| Vladimir Marko | e272715 | 2019-10-10 10:46:42 +0100 | [diff] [blame^] | 26 | namespace art HIDDEN { |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 29 | * Induction variable analysis. This class does not have a direct public API. |
| 30 | * Instead, the results of induction variable analysis can be queried through |
| 31 | * friend classes, such as InductionVarRange. |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 32 | * |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 33 | * The analysis implementation is based on the paper by M. Gerlek et al. |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 34 | * "Beyond Induction Variables: Detecting and Classifying Sequences Using a Demand-Driven SSA Form" |
| 35 | * (ACM Transactions on Programming Languages and Systems, Volume 17 Issue 1, Jan. 1995). |
| 36 | */ |
| 37 | class HInductionVarAnalysis : public HOptimization { |
| 38 | public: |
| Aart Bik | 2ca10eb | 2017-11-15 15:17:53 -0800 | [diff] [blame] | 39 | explicit HInductionVarAnalysis(HGraph* graph, const char* name = kInductionPassName); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 40 | |
| Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 41 | bool Run() override; |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 42 | |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 43 | static constexpr const char* kInductionPassName = "induction_var_analysis"; |
| 44 | |
| Wojciech Staszkiewicz | 5319d3c | 2016-08-01 17:48:59 -0700 | [diff] [blame] | 45 | private: |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 46 | struct NodeInfo { |
| 47 | explicit NodeInfo(uint32_t d) : depth(d), done(false) {} |
| 48 | uint32_t depth; |
| 49 | bool done; |
| 50 | }; |
| 51 | |
| 52 | enum InductionClass { |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 53 | kInvariant, |
| 54 | kLinear, |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 55 | kPolynomial, |
| 56 | kGeometric, |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 57 | kWrapAround, |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 58 | kPeriodic |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | enum InductionOp { |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 62 | // Operations. |
| Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 63 | kNop, |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 64 | kAdd, |
| 65 | kSub, |
| 66 | kNeg, |
| 67 | kMul, |
| 68 | kDiv, |
| Aart Bik | df7822e | 2016-12-06 10:05:30 -0800 | [diff] [blame] | 69 | kRem, |
| Aart Bik | 7dc9693 | 2016-10-12 10:01:05 -0700 | [diff] [blame] | 70 | kXor, |
| Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 71 | kFetch, |
| Aart Bik | 22f0587 | 2015-10-27 15:56:28 -0700 | [diff] [blame] | 72 | // Trip-counts. |
| 73 | kTripCountInLoop, // valid in full loop; loop is finite |
| 74 | kTripCountInBody, // valid in body only; loop is finite |
| 75 | kTripCountInLoopUnsafe, // valid in full loop; loop may be infinite |
| 76 | kTripCountInBodyUnsafe, // valid in body only; loop may be infinite |
| 77 | // Comparisons for trip-count tests. |
| 78 | kLT, |
| 79 | kLE, |
| 80 | kGT, |
| 81 | kGE |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * Defines a detected induction as: |
| 86 | * (1) invariant: |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 87 | * op: a + b, a - b, -b, a * b, a / b, a % b, a ^ b, fetch |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 88 | * (2) linear: |
| 89 | * nop: a * i + b |
| Aart Bik | df7822e | 2016-12-06 10:05:30 -0800 | [diff] [blame] | 90 | * (3) polynomial: |
| 91 | * nop: sum_lt(a) + b, for linear a |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 92 | * (4) geometric: |
| Aart Bik | df7822e | 2016-12-06 10:05:30 -0800 | [diff] [blame] | 93 | * op: a * fetch^i + b, a * fetch^-i + b |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 94 | * (5) wrap-around |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 95 | * nop: a, then defined by b |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 96 | * (6) periodic |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 97 | * nop: a, then defined by b (repeated when exhausted) |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 98 | * (7) trip-count: |
| Aart Bik | 22f0587 | 2015-10-27 15:56:28 -0700 | [diff] [blame] | 99 | * tc: defined by a, taken-test in b |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 100 | */ |
| Vladimir Marko | 5233f93 | 2015-09-29 19:01:15 +0100 | [diff] [blame] | 101 | struct InductionInfo : public ArenaObject<kArenaAllocInductionVarAnalysis> { |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 102 | InductionInfo(InductionClass ic, |
| 103 | InductionOp op, |
| 104 | InductionInfo* a, |
| 105 | InductionInfo* b, |
| Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 106 | HInstruction* f, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 107 | DataType::Type t) |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 108 | : induction_class(ic), |
| 109 | operation(op), |
| 110 | op_a(a), |
| 111 | op_b(b), |
| Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 112 | fetch(f), |
| 113 | type(t) {} |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 114 | InductionClass induction_class; |
| 115 | InductionOp operation; |
| 116 | InductionInfo* op_a; |
| 117 | InductionInfo* op_b; |
| 118 | HInstruction* fetch; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 119 | DataType::Type type; // precision of operation |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 120 | }; |
| 121 | |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 122 | bool IsVisitedNode(HInstruction* instruction) const { |
| 123 | return map_.find(instruction) != map_.end(); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 126 | InductionInfo* CreateInvariantOp(InductionOp op, InductionInfo* a, InductionInfo* b) { |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 127 | DCHECK(((op != kNeg && a != nullptr) || (op == kNeg && a == nullptr)) && b != nullptr); |
| Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 128 | return CreateSimplifiedInvariant(op, a, b); |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 131 | InductionInfo* CreateInvariantFetch(HInstruction* f) { |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 132 | DCHECK(f != nullptr); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 133 | return new (graph_->GetAllocator()) |
| Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 134 | InductionInfo(kInvariant, kFetch, nullptr, nullptr, f, f->GetType()); |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 137 | InductionInfo* CreateTripCount(InductionOp op, |
| 138 | InductionInfo* a, |
| 139 | InductionInfo* b, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 140 | DataType::Type type) { |
| Aart Bik | 52be7e7 | 2016-06-23 11:20:41 -0700 | [diff] [blame] | 141 | DCHECK(a != nullptr && b != nullptr); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 142 | return new (graph_->GetAllocator()) InductionInfo(kInvariant, op, a, b, nullptr, type); |
| Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 145 | InductionInfo* CreateInduction(InductionClass ic, |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 146 | InductionOp op, |
| Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 147 | InductionInfo* a, |
| 148 | InductionInfo* b, |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 149 | HInstruction* f, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 150 | DataType::Type type) { |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 151 | DCHECK(a != nullptr && b != nullptr); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 152 | return new (graph_->GetAllocator()) InductionInfo(ic, op, a, b, f, type); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | // Methods for analysis. |
| 156 | void VisitLoop(HLoopInformation* loop); |
| 157 | void VisitNode(HLoopInformation* loop, HInstruction* instruction); |
| 158 | uint32_t VisitDescendant(HLoopInformation* loop, HInstruction* instruction); |
| 159 | void ClassifyTrivial(HLoopInformation* loop, HInstruction* instruction); |
| 160 | void ClassifyNonTrivial(HLoopInformation* loop); |
| Aart Bik | f475bee | 2015-09-16 12:50:25 -0700 | [diff] [blame] | 161 | InductionInfo* RotatePeriodicInduction(InductionInfo* induction, InductionInfo* last); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 162 | |
| 163 | // Transfer operations. |
| Aart Bik | d0a022d | 2016-12-13 11:22:31 -0800 | [diff] [blame] | 164 | InductionInfo* TransferPhi(HLoopInformation* loop, |
| 165 | HInstruction* phi, |
| 166 | size_t input_index, |
| 167 | size_t adjust_input_size); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 168 | InductionInfo* TransferAddSub(InductionInfo* a, InductionInfo* b, InductionOp op); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 169 | InductionInfo* TransferNeg(InductionInfo* a); |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 170 | InductionInfo* TransferMul(InductionInfo* a, InductionInfo* b); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 171 | InductionInfo* TransferConversion(InductionInfo* a, DataType::Type from, DataType::Type to); |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 172 | |
| 173 | // Solvers. |
| Aart Bik | d0a022d | 2016-12-13 11:22:31 -0800 | [diff] [blame] | 174 | InductionInfo* SolvePhi(HInstruction* phi, size_t input_index, size_t adjust_input_size); |
| Aart Bik | f475bee | 2015-09-16 12:50:25 -0700 | [diff] [blame] | 175 | InductionInfo* SolvePhiAllInputs(HLoopInformation* loop, |
| 176 | HInstruction* entry_phi, |
| 177 | HInstruction* phi); |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 178 | InductionInfo* SolveAddSub(HLoopInformation* loop, |
| Aart Bik | f475bee | 2015-09-16 12:50:25 -0700 | [diff] [blame] | 179 | HInstruction* entry_phi, |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 180 | HInstruction* instruction, |
| 181 | HInstruction* x, |
| 182 | HInstruction* y, |
| 183 | InductionOp op, |
| Aart Bik | 7dc9693 | 2016-10-12 10:01:05 -0700 | [diff] [blame] | 184 | bool is_first_call); // possibly swaps x and y to try again |
| Aart Bik | df7822e | 2016-12-06 10:05:30 -0800 | [diff] [blame] | 185 | InductionInfo* SolveOp(HLoopInformation* loop, |
| 186 | HInstruction* entry_phi, |
| 187 | HInstruction* instruction, |
| 188 | HInstruction* x, |
| 189 | HInstruction* y, |
| 190 | InductionOp op); |
| Aart Bik | 639cc8c | 2016-10-18 13:03:31 -0700 | [diff] [blame] | 191 | InductionInfo* SolveTest(HLoopInformation* loop, |
| 192 | HInstruction* entry_phi, |
| 193 | HInstruction* instruction, |
| 194 | int64_t oppositive_value); |
| Aart Bik | e6bd027 | 2016-12-16 13:57:52 -0800 | [diff] [blame] | 195 | InductionInfo* SolveConversion(HLoopInformation* loop, |
| 196 | HInstruction* entry_phi, |
| 197 | HTypeConversion* conversion); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 198 | |
| Aart Bik | ceb0693 | 2017-11-13 10:31:17 -0800 | [diff] [blame] | 199 | // |
| 200 | // Loop trip count analysis methods. |
| 201 | // |
| 202 | |
| Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 203 | // Trip count information. |
| 204 | void VisitControl(HLoopInformation* loop); |
| 205 | void VisitCondition(HLoopInformation* loop, |
| Aart Bik | ceb0693 | 2017-11-13 10:31:17 -0800 | [diff] [blame] | 206 | HBasicBlock* body, |
| Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 207 | InductionInfo* a, |
| 208 | InductionInfo* b, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 209 | DataType::Type type, |
| Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 210 | IfCondition cmp); |
| 211 | void VisitTripCount(HLoopInformation* loop, |
| Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 212 | InductionInfo* lower_expr, |
| 213 | InductionInfo* upper_expr, |
| Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 214 | InductionInfo* stride, |
| Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 215 | int64_t stride_value, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 216 | DataType::Type type, |
| Aart Bik | f475bee | 2015-09-16 12:50:25 -0700 | [diff] [blame] | 217 | IfCondition cmp); |
| Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 218 | bool IsTaken(InductionInfo* lower_expr, InductionInfo* upper_expr, IfCondition cmp); |
| 219 | bool IsFinite(InductionInfo* upper_expr, |
| 220 | int64_t stride_value, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 221 | DataType::Type type, |
| Aart Bik | 9401f53 | 2015-09-28 16:25:56 -0700 | [diff] [blame] | 222 | IfCondition cmp); |
| Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 223 | bool FitsNarrowerControl(InductionInfo* lower_expr, |
| 224 | InductionInfo* upper_expr, |
| 225 | int64_t stride_value, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 226 | DataType::Type type, |
| Aart Bik | 0d345cf | 2016-03-16 10:49:38 -0700 | [diff] [blame] | 227 | IfCondition cmp); |
| Aart Bik | ceb0693 | 2017-11-13 10:31:17 -0800 | [diff] [blame] | 228 | bool RewriteBreakLoop(HLoopInformation* loop, |
| 229 | HBasicBlock* body, |
| 230 | int64_t stride_value, |
| 231 | DataType::Type type); |
| 232 | |
| 233 | // |
| 234 | // Helper methods. |
| 235 | // |
| Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 236 | |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 237 | // Assign and lookup. |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 238 | void AssignInfo(HLoopInformation* loop, HInstruction* instruction, InductionInfo* info); |
| 239 | InductionInfo* LookupInfo(HLoopInformation* loop, HInstruction* instruction); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 240 | InductionInfo* CreateConstant(int64_t value, DataType::Type type); |
| Aart Bik | 471a203 | 2015-09-04 18:22:11 -0700 | [diff] [blame] | 241 | InductionInfo* CreateSimplifiedInvariant(InductionOp op, InductionInfo* a, InductionInfo* b); |
| Aart Bik | d0a022d | 2016-12-13 11:22:31 -0800 | [diff] [blame] | 242 | HInstruction* GetShiftConstant(HLoopInformation* loop, |
| 243 | HInstruction* instruction, |
| 244 | InductionInfo* initial); |
| Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 245 | void AssignCycle(HPhi* phi); |
| 246 | ArenaSet<HInstruction*>* LookupCycle(HPhi* phi); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 247 | |
| Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 248 | // Constants. |
| Aart Bik | 97412c92 | 2016-02-19 20:14:38 -0800 | [diff] [blame] | 249 | bool IsExact(InductionInfo* info, /*out*/ int64_t* value); |
| 250 | bool IsAtMost(InductionInfo* info, /*out*/ int64_t* value); |
| 251 | bool IsAtLeast(InductionInfo* info, /*out*/ int64_t* value); |
| Aart Bik | 7d57d7f | 2015-12-09 14:39:48 -0800 | [diff] [blame] | 252 | |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 253 | // Helpers. |
| Aart Bik | e6bd027 | 2016-12-16 13:57:52 -0800 | [diff] [blame] | 254 | static bool IsNarrowingLinear(InductionInfo* info); |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 255 | static bool InductionEqual(InductionInfo* info1, InductionInfo* info2); |
| Aart Bik | c071a01 | 2016-12-01 10:22:31 -0800 | [diff] [blame] | 256 | static std::string FetchToString(HInstruction* fetch); |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 257 | static std::string InductionToString(InductionInfo* info); |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 258 | |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 259 | // TODO: fine tune the following data structures, only keep relevant data. |
| 260 | |
| 261 | // Temporary book-keeping during the analysis. |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 262 | uint32_t global_depth_; |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 263 | ArenaVector<HInstruction*> stack_; |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 264 | ArenaSafeMap<HInstruction*, NodeInfo> map_; |
| Aart Bik | 7dc9693 | 2016-10-12 10:01:05 -0700 | [diff] [blame] | 265 | ArenaVector<HInstruction*> scc_; |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 266 | ArenaSafeMap<HInstruction*, InductionInfo*> cycle_; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 267 | DataType::Type type_; |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 268 | |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 269 | /** |
| 270 | * Maintains the results of the analysis as a mapping from loops to a mapping from instructions |
| 271 | * to the induction information for that instruction in that loop. |
| 272 | */ |
| 273 | ArenaSafeMap<HLoopInformation*, ArenaSafeMap<HInstruction*, InductionInfo*>> induction_; |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 274 | |
| Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 275 | /** |
| 276 | * Preserves induction cycle information for each loop-phi. |
| 277 | */ |
| 278 | ArenaSafeMap<HPhi*, ArenaSet<HInstruction*>> cycles_; |
| 279 | |
| Aart Bik | e609b7c | 2015-08-27 13:46:58 -0700 | [diff] [blame] | 280 | friend class InductionVarAnalysisTest; |
| Aart Bik | d14c595 | 2015-09-08 15:25:15 -0700 | [diff] [blame] | 281 | friend class InductionVarRange; |
| 282 | friend class InductionVarRangeTest; |
| Aart Bik | 30efb4e | 2015-07-30 12:14:31 -0700 | [diff] [blame] | 283 | |
| 284 | DISALLOW_COPY_AND_ASSIGN(HInductionVarAnalysis); |
| 285 | }; |
| 286 | |
| 287 | } // namespace art |
| 288 | |
| 289 | #endif // ART_COMPILER_OPTIMIZING_INDUCTION_VAR_ANALYSIS_H_ |