Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_LOOP_OPTIMIZATION_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_LOOP_OPTIMIZATION_H_ |
| 19 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 20 | #include "base/scoped_arena_allocator.h" |
| 21 | #include "base/scoped_arena_containers.h" |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 22 | #include "induction_var_range.h" |
Artem Serov | 121f203 | 2017-10-23 19:19:06 +0100 | [diff] [blame] | 23 | #include "loop_analysis.h" |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 24 | #include "nodes.h" |
| 25 | #include "optimization.h" |
Artem Serov | 121f203 | 2017-10-23 19:19:06 +0100 | [diff] [blame] | 26 | #include "superblock_cloner.h" |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 27 | |
| 28 | namespace art { |
| 29 | |
Aart Bik | 92685a8 | 2017-03-06 11:13:43 -0800 | [diff] [blame] | 30 | class CompilerDriver; |
Artem Serov | cf43fb6 | 2018-02-15 14:43:48 +0000 | [diff] [blame^] | 31 | class ArchNoOptsLoopHelper; |
Aart Bik | 92685a8 | 2017-03-06 11:13:43 -0800 | [diff] [blame] | 32 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Loop optimizations. Builds a loop hierarchy and applies optimizations to |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 35 | * the detected nested loops, such as removal of dead induction and empty loops |
| 36 | * and inner loop vectorization. |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 37 | */ |
| 38 | class HLoopOptimization : public HOptimization { |
| 39 | public: |
Aart Bik | 92685a8 | 2017-03-06 11:13:43 -0800 | [diff] [blame] | 40 | HLoopOptimization(HGraph* graph, |
| 41 | CompilerDriver* compiler_driver, |
Aart Bik | b92cc33 | 2017-09-06 15:53:17 -0700 | [diff] [blame] | 42 | HInductionVarAnalysis* induction_analysis, |
Aart Bik | 2ca10eb | 2017-11-15 15:17:53 -0800 | [diff] [blame] | 43 | OptimizingCompilerStats* stats, |
| 44 | const char* name = kLoopOptimizationPassName); |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 45 | |
Aart Bik | 2477320 | 2018-04-26 10:28:51 -0700 | [diff] [blame] | 46 | bool Run() OVERRIDE; |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 47 | |
| 48 | static constexpr const char* kLoopOptimizationPassName = "loop_optimization"; |
| 49 | |
| 50 | private: |
| 51 | /** |
| 52 | * A single loop inside the loop hierarchy representation. |
| 53 | */ |
Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 54 | struct LoopNode : public ArenaObject<kArenaAllocLoopOptimization> { |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 55 | explicit LoopNode(HLoopInformation* lp_info) |
| 56 | : loop_info(lp_info), |
| 57 | outer(nullptr), |
| 58 | inner(nullptr), |
| 59 | previous(nullptr), |
| 60 | next(nullptr) {} |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 61 | HLoopInformation* loop_info; |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 62 | LoopNode* outer; |
| 63 | LoopNode* inner; |
| 64 | LoopNode* previous; |
| 65 | LoopNode* next; |
| 66 | }; |
| 67 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 68 | /* |
| 69 | * Vectorization restrictions (bit mask). |
| 70 | */ |
| 71 | enum VectorRestrictions { |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 72 | kNone = 0, // no restrictions |
| 73 | kNoMul = 1 << 0, // no multiplication |
| 74 | kNoDiv = 1 << 1, // no division |
| 75 | kNoShift = 1 << 2, // no shift |
| 76 | kNoShr = 1 << 3, // no arithmetic shift right |
| 77 | kNoHiBits = 1 << 4, // "wider" operations cannot bring in higher order bits |
| 78 | kNoSignedHAdd = 1 << 5, // no signed halving add |
| 79 | kNoUnroundedHAdd = 1 << 6, // no unrounded halving add |
| 80 | kNoAbs = 1 << 7, // no absolute value |
Aart Bik | 3f08e9b | 2018-05-01 13:42:03 -0700 | [diff] [blame] | 81 | kNoStringCharAt = 1 << 8, // no StringCharAt |
| 82 | kNoReduction = 1 << 9, // no reduction |
| 83 | kNoSAD = 1 << 10, // no sum of absolute differences (SAD) |
| 84 | kNoWideSAD = 1 << 11, // no sum of absolute differences (SAD) with operand widening |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 85 | }; |
Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 86 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 87 | /* |
| 88 | * Vectorization mode during synthesis |
| 89 | * (sequential peeling/cleanup loop or vector loop). |
| 90 | */ |
| 91 | enum VectorMode { |
| 92 | kSequential, |
| 93 | kVector |
| 94 | }; |
| 95 | |
| 96 | /* |
| 97 | * Representation of a unit-stride array reference. |
| 98 | */ |
| 99 | struct ArrayReference { |
Aart Bik | 38a3f21 | 2017-10-20 17:02:21 -0700 | [diff] [blame] | 100 | ArrayReference(HInstruction* b, HInstruction* o, DataType::Type t, bool l, bool c = false) |
| 101 | : base(b), offset(o), type(t), lhs(l), is_string_char_at(c) { } |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 102 | bool operator<(const ArrayReference& other) const { |
| 103 | return |
| 104 | (base < other.base) || |
| 105 | (base == other.base && |
| 106 | (offset < other.offset || (offset == other.offset && |
| 107 | (type < other.type || |
Aart Bik | 38a3f21 | 2017-10-20 17:02:21 -0700 | [diff] [blame] | 108 | (type == other.type && |
| 109 | (lhs < other.lhs || |
| 110 | (lhs == other.lhs && |
| 111 | is_string_char_at < other.is_string_char_at))))))); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 112 | } |
Aart Bik | 38a3f21 | 2017-10-20 17:02:21 -0700 | [diff] [blame] | 113 | HInstruction* base; // base address |
| 114 | HInstruction* offset; // offset + i |
| 115 | DataType::Type type; // component type |
| 116 | bool lhs; // def/use |
| 117 | bool is_string_char_at; // compressed string read |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 118 | }; |
| 119 | |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 120 | // |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 121 | // Loop setup and traversal. |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 122 | // |
| 123 | |
Aart Bik | 2477320 | 2018-04-26 10:28:51 -0700 | [diff] [blame] | 124 | bool LocalRun(); |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 125 | void AddLoop(HLoopInformation* loop_info); |
| 126 | void RemoveLoop(LoopNode* node); |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 127 | |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 128 | // Traverses all loops inner to outer to perform simplifications and optimizations. |
| 129 | // Returns true if loops nested inside current loop (node) have changed. |
| 130 | bool TraverseLoopsInnerToOuter(LoopNode* node); |
| 131 | |
| 132 | // |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 133 | // Optimization. |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 134 | // |
| 135 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 136 | void SimplifyInduction(LoopNode* node); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 137 | void SimplifyBlocks(LoopNode* node); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 138 | |
Artem Serov | 121f203 | 2017-10-23 19:19:06 +0100 | [diff] [blame] | 139 | // Performs optimizations specific to inner loop with finite header logic (empty loop removal, |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 140 | // unrolling, vectorization). Returns true if anything changed. |
Artem Serov | 121f203 | 2017-10-23 19:19:06 +0100 | [diff] [blame] | 141 | bool TryOptimizeInnerLoopFinite(LoopNode* node); |
| 142 | |
| 143 | // Performs optimizations specific to inner loop. Returns true if anything changed. |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 144 | bool OptimizeInnerLoop(LoopNode* node); |
| 145 | |
Artem Serov | 121f203 | 2017-10-23 19:19:06 +0100 | [diff] [blame] | 146 | // Tries to apply loop unrolling for branch penalty reduction and better instruction scheduling |
| 147 | // opportunities. Returns whether transformation happened. |
| 148 | bool TryUnrollingForBranchPenaltyReduction(LoopNode* loop_node); |
| 149 | |
Artem Serov | 72411e6 | 2017-10-19 16:18:07 +0100 | [diff] [blame] | 150 | // Tries to apply loop peeling for loop invariant exits elimination. Returns whether |
| 151 | // transformation happened. |
| 152 | bool TryPeelingForLoopInvariantExitsElimination(LoopNode* loop_node); |
| 153 | |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 154 | // |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 155 | // Vectorization analysis and synthesis. |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 156 | // |
| 157 | |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 158 | bool ShouldVectorize(LoopNode* node, HBasicBlock* block, int64_t trip_count); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 159 | void Vectorize(LoopNode* node, HBasicBlock* block, HBasicBlock* exit, int64_t trip_count); |
| 160 | void GenerateNewLoop(LoopNode* node, |
| 161 | HBasicBlock* block, |
| 162 | HBasicBlock* new_preheader, |
| 163 | HInstruction* lo, |
| 164 | HInstruction* hi, |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 165 | HInstruction* step, |
| 166 | uint32_t unroll); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 167 | bool VectorizeDef(LoopNode* node, HInstruction* instruction, bool generate_code); |
| 168 | bool VectorizeUse(LoopNode* node, |
| 169 | HInstruction* instruction, |
| 170 | bool generate_code, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 171 | DataType::Type type, |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 172 | uint64_t restrictions); |
Aart Bik | 38a3f21 | 2017-10-20 17:02:21 -0700 | [diff] [blame] | 173 | uint32_t GetVectorSizeInBytes(); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 174 | bool TrySetVectorType(DataType::Type type, /*out*/ uint64_t* restrictions); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 175 | bool TrySetVectorLength(uint32_t length); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 176 | void GenerateVecInv(HInstruction* org, DataType::Type type); |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 177 | void GenerateVecSub(HInstruction* org, HInstruction* offset); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 178 | void GenerateVecMem(HInstruction* org, |
| 179 | HInstruction* opa, |
| 180 | HInstruction* opb, |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 181 | HInstruction* offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 182 | DataType::Type type); |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 183 | void GenerateVecReductionPhi(HPhi* phi); |
| 184 | void GenerateVecReductionPhiInputs(HPhi* phi, HInstruction* reduction); |
| 185 | HInstruction* ReduceAndExtractIfNeeded(HInstruction* instruction); |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 186 | void GenerateVecOp(HInstruction* org, |
| 187 | HInstruction* opa, |
| 188 | HInstruction* opb, |
Aart Bik | 3f08e9b | 2018-05-01 13:42:03 -0700 | [diff] [blame] | 189 | DataType::Type type); |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 190 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 191 | // Vectorization idioms. |
Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 192 | bool VectorizeSaturationIdiom(LoopNode* node, |
| 193 | HInstruction* instruction, |
| 194 | bool generate_code, |
| 195 | DataType::Type type, |
| 196 | uint64_t restrictions); |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 197 | bool VectorizeHalvingAddIdiom(LoopNode* node, |
| 198 | HInstruction* instruction, |
| 199 | bool generate_code, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 200 | DataType::Type type, |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 201 | uint64_t restrictions); |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 202 | bool VectorizeSADIdiom(LoopNode* node, |
| 203 | HInstruction* instruction, |
| 204 | bool generate_code, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 205 | DataType::Type type, |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 206 | uint64_t restrictions); |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 207 | |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 208 | // Vectorization heuristics. |
Aart Bik | 38a3f21 | 2017-10-20 17:02:21 -0700 | [diff] [blame] | 209 | Alignment ComputeAlignment(HInstruction* offset, |
| 210 | DataType::Type type, |
| 211 | bool is_string_char_at, |
| 212 | uint32_t peeling = 0); |
| 213 | void SetAlignmentStrategy(uint32_t peeling_votes[], |
| 214 | const ArrayReference* peeling_candidate); |
| 215 | uint32_t MaxNumberPeeled(); |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 216 | bool IsVectorizationProfitable(int64_t trip_count); |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 217 | |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 218 | // |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 219 | // Helpers. |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 220 | // |
| 221 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 222 | bool TrySetPhiInduction(HPhi* phi, bool restrict_uses); |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 223 | bool TrySetPhiReduction(HPhi* phi); |
| 224 | |
| 225 | // Detects loop header with a single induction (returned in main_phi), possibly |
| 226 | // other phis for reductions, but no other side effects. Returns true on success. |
| 227 | bool TrySetSimpleLoopHeader(HBasicBlock* block, /*out*/ HPhi** main_phi); |
| 228 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 229 | bool IsEmptyBody(HBasicBlock* block); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 230 | bool IsOnlyUsedAfterLoop(HLoopInformation* loop_info, |
Aart Bik | 8c4a854 | 2016-10-06 11:36:57 -0700 | [diff] [blame] | 231 | HInstruction* instruction, |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 232 | bool collect_loop_uses, |
Aart Bik | 38a3f21 | 2017-10-20 17:02:21 -0700 | [diff] [blame] | 233 | /*out*/ uint32_t* use_count); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 234 | bool IsUsedOutsideLoop(HLoopInformation* loop_info, |
| 235 | HInstruction* instruction); |
Nicolas Geoffray | 1a0a519 | 2017-06-22 11:56:01 +0100 | [diff] [blame] | 236 | bool TryReplaceWithLastValue(HLoopInformation* loop_info, |
| 237 | HInstruction* instruction, |
| 238 | HBasicBlock* block); |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 239 | bool TryAssignLastValue(HLoopInformation* loop_info, |
| 240 | HInstruction* instruction, |
| 241 | HBasicBlock* block, |
| 242 | bool collect_loop_uses); |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 243 | void RemoveDeadInstructions(const HInstructionList& list); |
Nicolas Geoffray | 1a0a519 | 2017-06-22 11:56:01 +0100 | [diff] [blame] | 244 | bool CanRemoveCycle(); // Whether the current 'iset_' is removable. |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 245 | |
Aart Bik | 92685a8 | 2017-03-06 11:13:43 -0800 | [diff] [blame] | 246 | // Compiler driver (to query ISA features). |
| 247 | const CompilerDriver* compiler_driver_; |
| 248 | |
Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 249 | // Range information based on prior induction variable analysis. |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 250 | InductionVarRange induction_range_; |
| 251 | |
| 252 | // Phase-local heap memory allocator for the loop optimizer. Storage obtained |
Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 253 | // through this allocator is immediately released when the loop optimizer is done. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 254 | ScopedArenaAllocator* loop_allocator_; |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 255 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 256 | // Global heap memory allocator. Used to build HIR. |
| 257 | ArenaAllocator* global_allocator_; |
| 258 | |
Aart Bik | 9620230 | 2016-10-04 17:33:56 -0700 | [diff] [blame] | 259 | // Entries into the loop hierarchy representation. The hierarchy resides |
| 260 | // in phase-local heap memory. |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 261 | LoopNode* top_loop_; |
| 262 | LoopNode* last_loop_; |
| 263 | |
Aart Bik | 8c4a854 | 2016-10-06 11:36:57 -0700 | [diff] [blame] | 264 | // Temporary bookkeeping of a set of instructions. |
| 265 | // Contents reside in phase-local heap memory. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 266 | ScopedArenaSet<HInstruction*>* iset_; |
Aart Bik | 8c4a854 | 2016-10-06 11:36:57 -0700 | [diff] [blame] | 267 | |
Aart Bik | b29f684 | 2017-07-28 15:58:41 -0700 | [diff] [blame] | 268 | // Temporary bookkeeping of reduction instructions. Mapping is two-fold: |
| 269 | // (1) reductions in the loop-body are mapped back to their phi definition, |
| 270 | // (2) phi definitions are mapped to their initial value (updated during |
| 271 | // code generation to feed the proper values into the new chain). |
| 272 | // Contents reside in phase-local heap memory. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 273 | ScopedArenaSafeMap<HInstruction*, HInstruction*>* reductions_; |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 274 | |
Aart Bik | df7822e | 2016-12-06 10:05:30 -0800 | [diff] [blame] | 275 | // Flag that tracks if any simplifications have occurred. |
| 276 | bool simplified_; |
| 277 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 278 | // Number of "lanes" for selected packed type. |
| 279 | uint32_t vector_length_; |
| 280 | |
| 281 | // Set of array references in the vector loop. |
| 282 | // Contents reside in phase-local heap memory. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 283 | ScopedArenaSet<ArrayReference>* vector_refs_; |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 284 | |
Aart Bik | 38a3f21 | 2017-10-20 17:02:21 -0700 | [diff] [blame] | 285 | // Static or dynamic loop peeling for alignment. |
| 286 | uint32_t vector_static_peeling_factor_; |
| 287 | const ArrayReference* vector_dynamic_peeling_candidate_; |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 288 | |
| 289 | // Dynamic data dependence test of the form a != b. |
| 290 | HInstruction* vector_runtime_test_a_; |
| 291 | HInstruction* vector_runtime_test_b_; |
| 292 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 293 | // Mapping used during vectorization synthesis for both the scalar peeling/cleanup |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 294 | // loop (mode is kSequential) and the actual vector loop (mode is kVector). The data |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 295 | // structure maps original instructions into the new instructions. |
| 296 | // Contents reside in phase-local heap memory. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 297 | ScopedArenaSafeMap<HInstruction*, HInstruction*>* vector_map_; |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 298 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 299 | // Permanent mapping used during vectorization synthesis. |
| 300 | // Contents reside in phase-local heap memory. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 301 | ScopedArenaSafeMap<HInstruction*, HInstruction*>* vector_permanent_map_; |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 302 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 303 | // Temporary vectorization bookkeeping. |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 304 | VectorMode vector_mode_; // synthesis mode |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 305 | HBasicBlock* vector_preheader_; // preheader of the new loop |
| 306 | HBasicBlock* vector_header_; // header of the new loop |
| 307 | HBasicBlock* vector_body_; // body of the new loop |
Aart Bik | 14a68b4 | 2017-06-08 14:06:58 -0700 | [diff] [blame] | 308 | HInstruction* vector_index_; // normalized index of the new loop |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 309 | |
Artem Serov | 121f203 | 2017-10-23 19:19:06 +0100 | [diff] [blame] | 310 | // Helper for target-specific behaviour for loop optimizations. |
Artem Serov | cf43fb6 | 2018-02-15 14:43:48 +0000 | [diff] [blame^] | 311 | ArchNoOptsLoopHelper* arch_loop_helper_; |
Artem Serov | 121f203 | 2017-10-23 19:19:06 +0100 | [diff] [blame] | 312 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 313 | friend class LoopOptimizationTest; |
| 314 | |
| 315 | DISALLOW_COPY_AND_ASSIGN(HLoopOptimization); |
| 316 | }; |
| 317 | |
| 318 | } // namespace art |
| 319 | |
| 320 | #endif // ART_COMPILER_OPTIMIZING_LOOP_OPTIMIZATION_H_ |