Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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_NODES_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_H_ |
| 19 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 20 | #include "locations.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 21 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 22 | #include "primitive.h" |
Ian Rogers | 0279ebb | 2014-10-08 17:27:48 -0700 | [diff] [blame] | 23 | #include "utils/arena_object.h" |
Nicolas Geoffray | 0e33643 | 2014-02-26 18:24:38 +0000 | [diff] [blame] | 24 | #include "utils/arena_bit_vector.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 25 | #include "utils/growable_array.h" |
| 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | class HBasicBlock; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 30 | class HEnvironment; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 31 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 32 | class HIntConstant; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 33 | class HGraphVisitor; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 34 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 35 | class HSuspendCheck; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 36 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 37 | class LocationSummary; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 38 | |
| 39 | static const int kDefaultNumberOfBlocks = 8; |
| 40 | static const int kDefaultNumberOfSuccessors = 2; |
| 41 | static const int kDefaultNumberOfPredecessors = 2; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 42 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 43 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 44 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 45 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 46 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 47 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 48 | enum IfCondition { |
| 49 | kCondEQ, |
| 50 | kCondNE, |
| 51 | kCondLT, |
| 52 | kCondLE, |
| 53 | kCondGT, |
| 54 | kCondGE, |
| 55 | }; |
| 56 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 57 | class HInstructionList { |
| 58 | public: |
| 59 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 60 | |
| 61 | void AddInstruction(HInstruction* instruction); |
| 62 | void RemoveInstruction(HInstruction* instruction); |
| 63 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 64 | // Return true if this list contains `instruction`. |
| 65 | bool Contains(HInstruction* instruction) const; |
| 66 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 67 | // Return true if `instruction1` is found before `instruction2` in |
| 68 | // this instruction list and false otherwise. Abort if none |
| 69 | // of these instructions is found. |
| 70 | bool FoundBefore(const HInstruction* instruction1, |
| 71 | const HInstruction* instruction2) const; |
| 72 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 73 | private: |
| 74 | HInstruction* first_instruction_; |
| 75 | HInstruction* last_instruction_; |
| 76 | |
| 77 | friend class HBasicBlock; |
| 78 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 79 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 80 | |
| 81 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 82 | }; |
| 83 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 84 | // Control-flow graph of a method. Contains a list of basic blocks. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 85 | class HGraph : public ArenaObject<kArenaAllocMisc> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 86 | public: |
| 87 | explicit HGraph(ArenaAllocator* arena) |
| 88 | : arena_(arena), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 89 | blocks_(arena, kDefaultNumberOfBlocks), |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 90 | reverse_post_order_(arena, kDefaultNumberOfBlocks), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 91 | entry_block_(nullptr), |
| 92 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 93 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 94 | number_of_vregs_(0), |
| 95 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 96 | temporaries_vreg_slots_(0), |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 97 | current_instruction_id_(0) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 98 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 99 | ArenaAllocator* GetArena() const { return arena_; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 100 | const GrowableArray<HBasicBlock*>& GetBlocks() const { return blocks_; } |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 101 | HBasicBlock* GetBlock(size_t id) const { return blocks_.Get(id); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 102 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 103 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 104 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 105 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 106 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 107 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 108 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 109 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 110 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 111 | void BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 112 | void TransformToSSA(); |
| 113 | void SimplifyCFG(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 114 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 115 | // Analyze all natural loops in this graph. Returns false if one |
| 116 | // loop is not natural, that is the header does not dominate the |
| 117 | // back edge. |
| 118 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 119 | |
| 120 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 121 | void SimplifyLoop(HBasicBlock* header); |
| 122 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 123 | int GetNextInstructionId() { |
| 124 | return current_instruction_id_++; |
| 125 | } |
| 126 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 127 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 128 | return maximum_number_of_out_vregs_; |
| 129 | } |
| 130 | |
| 131 | void UpdateMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 132 | maximum_number_of_out_vregs_ = std::max(new_value, maximum_number_of_out_vregs_); |
| 133 | } |
| 134 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 135 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 136 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 139 | size_t GetTemporariesVRegSlots() const { |
| 140 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 143 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 144 | number_of_vregs_ = number_of_vregs; |
| 145 | } |
| 146 | |
| 147 | uint16_t GetNumberOfVRegs() const { |
| 148 | return number_of_vregs_; |
| 149 | } |
| 150 | |
| 151 | void SetNumberOfInVRegs(uint16_t value) { |
| 152 | number_of_in_vregs_ = value; |
| 153 | } |
| 154 | |
| 155 | uint16_t GetNumberOfInVRegs() const { |
| 156 | return number_of_in_vregs_; |
| 157 | } |
| 158 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 159 | uint16_t GetNumberOfLocalVRegs() const { |
| 160 | return number_of_vregs_ - number_of_in_vregs_; |
| 161 | } |
| 162 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 163 | const GrowableArray<HBasicBlock*>& GetReversePostOrder() const { |
| 164 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 165 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 166 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 167 | private: |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 168 | HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const; |
| 169 | void VisitBlockForDominatorTree(HBasicBlock* block, |
| 170 | HBasicBlock* predecessor, |
| 171 | GrowableArray<size_t>* visits); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 172 | void FindBackEdges(ArenaBitVector* visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 173 | void VisitBlockForBackEdges(HBasicBlock* block, |
| 174 | ArenaBitVector* visited, |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 175 | ArenaBitVector* visiting); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame^] | 176 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 177 | void RemoveDeadBlocks(const ArenaBitVector& visited) const; |
| 178 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 179 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 180 | |
| 181 | // List of blocks in insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 182 | GrowableArray<HBasicBlock*> blocks_; |
| 183 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 184 | // List of blocks to perform a reverse post order tree traversal. |
| 185 | GrowableArray<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 186 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 187 | HBasicBlock* entry_block_; |
| 188 | HBasicBlock* exit_block_; |
| 189 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 190 | // The maximum number of virtual registers arguments passed to a HInvoke in this graph. |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 191 | uint16_t maximum_number_of_out_vregs_; |
| 192 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 193 | // The number of virtual registers in this method. Contains the parameters. |
| 194 | uint16_t number_of_vregs_; |
| 195 | |
| 196 | // The number of virtual registers used by parameters of this method. |
| 197 | uint16_t number_of_in_vregs_; |
| 198 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 199 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 200 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 201 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 202 | // The current id to assign to a newly added instruction. See HInstruction.id_. |
| 203 | int current_instruction_id_; |
| 204 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 205 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 206 | }; |
| 207 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 208 | class HLoopInformation : public ArenaObject<kArenaAllocMisc> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 209 | public: |
| 210 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 211 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 212 | suspend_check_(nullptr), |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 213 | back_edges_(graph->GetArena(), kDefaultNumberOfBackEdges), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 214 | // Make bit vector growable, as the number of blocks may change. |
| 215 | blocks_(graph->GetArena(), graph->GetBlocks().Size(), true) {} |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 216 | |
| 217 | HBasicBlock* GetHeader() const { |
| 218 | return header_; |
| 219 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 220 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 221 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 222 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 223 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 224 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 225 | void AddBackEdge(HBasicBlock* back_edge) { |
| 226 | back_edges_.Add(back_edge); |
| 227 | } |
| 228 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 229 | void RemoveBackEdge(HBasicBlock* back_edge) { |
| 230 | back_edges_.Delete(back_edge); |
| 231 | } |
| 232 | |
| 233 | bool IsBackEdge(HBasicBlock* block) { |
| 234 | for (size_t i = 0, e = back_edges_.Size(); i < e; ++i) { |
| 235 | if (back_edges_.Get(i) == block) return true; |
| 236 | } |
| 237 | return false; |
| 238 | } |
| 239 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 240 | size_t NumberOfBackEdges() const { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 241 | return back_edges_.Size(); |
| 242 | } |
| 243 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 244 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 245 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 246 | const GrowableArray<HBasicBlock*>& GetBackEdges() const { |
| 247 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 250 | void ClearBackEdges() { |
| 251 | back_edges_.Reset(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 254 | // Find blocks that are part of this loop. Returns whether the loop is a natural loop, |
| 255 | // that is the header dominates the back edge. |
| 256 | bool Populate(); |
| 257 | |
| 258 | // Returns whether this loop information contains `block`. |
| 259 | // Note that this loop information *must* be populated before entering this function. |
| 260 | bool Contains(const HBasicBlock& block) const; |
| 261 | |
| 262 | // Returns whether this loop information is an inner loop of `other`. |
| 263 | // Note that `other` *must* be populated before entering this function. |
| 264 | bool IsIn(const HLoopInformation& other) const; |
| 265 | |
| 266 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 267 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 268 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 269 | // Internal recursive implementation of `Populate`. |
| 270 | void PopulateRecursive(HBasicBlock* block); |
| 271 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 272 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 273 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 274 | GrowableArray<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 275 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 276 | |
| 277 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 278 | }; |
| 279 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 280 | static constexpr size_t kNoLifetime = -1; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 281 | static constexpr uint32_t kNoDexPc = -1; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 282 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 283 | // A block in a method. Contains the list of instructions represented |
| 284 | // as a double linked list. Each block knows its predecessors and |
| 285 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 286 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 287 | class HBasicBlock : public ArenaObject<kArenaAllocMisc> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 288 | public: |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 289 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 290 | : graph_(graph), |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 291 | predecessors_(graph->GetArena(), kDefaultNumberOfPredecessors), |
| 292 | successors_(graph->GetArena(), kDefaultNumberOfSuccessors), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 293 | loop_information_(nullptr), |
| 294 | dominator_(nullptr), |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 295 | dominated_blocks_(graph->GetArena(), kDefaultNumberOfDominatedBlocks), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 296 | block_id_(-1), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 297 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 298 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 299 | lifetime_end_(kNoLifetime), |
| 300 | is_catch_block_(false) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 301 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 302 | const GrowableArray<HBasicBlock*>& GetPredecessors() const { |
| 303 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 306 | const GrowableArray<HBasicBlock*>& GetSuccessors() const { |
| 307 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 310 | const GrowableArray<HBasicBlock*>& GetDominatedBlocks() const { |
| 311 | return dominated_blocks_; |
| 312 | } |
| 313 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 314 | bool IsEntryBlock() const { |
| 315 | return graph_->GetEntryBlock() == this; |
| 316 | } |
| 317 | |
| 318 | bool IsExitBlock() const { |
| 319 | return graph_->GetExitBlock() == this; |
| 320 | } |
| 321 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 322 | void AddBackEdge(HBasicBlock* back_edge) { |
| 323 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 324 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 325 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 326 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 327 | loop_information_->AddBackEdge(back_edge); |
| 328 | } |
| 329 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 330 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 331 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 332 | int GetBlockId() const { return block_id_; } |
| 333 | void SetBlockId(int id) { block_id_ = id; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 334 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 335 | HBasicBlock* GetDominator() const { return dominator_; } |
| 336 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 337 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.Add(block); } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 338 | |
| 339 | int NumberOfBackEdges() const { |
| 340 | return loop_information_ == nullptr |
| 341 | ? 0 |
| 342 | : loop_information_->NumberOfBackEdges(); |
| 343 | } |
| 344 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 345 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 346 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 347 | const HInstructionList& GetInstructions() const { return instructions_; } |
| 348 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 349 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 350 | |
| 351 | void AddSuccessor(HBasicBlock* block) { |
| 352 | successors_.Add(block); |
| 353 | block->predecessors_.Add(this); |
| 354 | } |
| 355 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 356 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 357 | size_t successor_index = GetSuccessorIndexOf(existing); |
| 358 | DCHECK_NE(successor_index, static_cast<size_t>(-1)); |
| 359 | existing->RemovePredecessor(this); |
| 360 | new_block->predecessors_.Add(this); |
| 361 | successors_.Put(successor_index, new_block); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 364 | void RemovePredecessor(HBasicBlock* block) { |
| 365 | predecessors_.Delete(block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | void ClearAllPredecessors() { |
| 369 | predecessors_.Reset(); |
| 370 | } |
| 371 | |
| 372 | void AddPredecessor(HBasicBlock* block) { |
| 373 | predecessors_.Add(block); |
| 374 | block->successors_.Add(this); |
| 375 | } |
| 376 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 377 | void SwapPredecessors() { |
Nicolas Geoffray | c83d441 | 2014-09-18 16:46:20 +0100 | [diff] [blame] | 378 | DCHECK_EQ(predecessors_.Size(), 2u); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 379 | HBasicBlock* temp = predecessors_.Get(0); |
| 380 | predecessors_.Put(0, predecessors_.Get(1)); |
| 381 | predecessors_.Put(1, temp); |
| 382 | } |
| 383 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 384 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) { |
| 385 | for (size_t i = 0, e = predecessors_.Size(); i < e; ++i) { |
| 386 | if (predecessors_.Get(i) == predecessor) { |
| 387 | return i; |
| 388 | } |
| 389 | } |
| 390 | return -1; |
| 391 | } |
| 392 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 393 | size_t GetSuccessorIndexOf(HBasicBlock* successor) { |
| 394 | for (size_t i = 0, e = successors_.Size(); i < e; ++i) { |
| 395 | if (successors_.Get(i) == successor) { |
| 396 | return i; |
| 397 | } |
| 398 | } |
| 399 | return -1; |
| 400 | } |
| 401 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 402 | void AddInstruction(HInstruction* instruction); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 403 | void RemoveInstruction(HInstruction* instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 404 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 405 | // Replace instruction `initial` with `replacement` within this block. |
| 406 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 407 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 408 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 409 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 410 | void RemovePhi(HPhi* phi); |
| 411 | |
| 412 | bool IsLoopHeader() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 413 | return (loop_information_ != nullptr) && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 414 | } |
| 415 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 416 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 417 | DCHECK(IsLoopHeader()); |
| 418 | DCHECK(!GetPredecessors().IsEmpty()); |
| 419 | return GetPredecessors().Get(0) == GetLoopInformation()->GetPreHeader(); |
| 420 | } |
| 421 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 422 | HLoopInformation* GetLoopInformation() const { |
| 423 | return loop_information_; |
| 424 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 425 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 426 | // Set the loop_information_ on this block. This method overrides the current |
| 427 | // loop_information if it is an outer loop of the passed loop information. |
| 428 | void SetInLoop(HLoopInformation* info) { |
| 429 | if (IsLoopHeader()) { |
| 430 | // Nothing to do. This just means `info` is an outer loop. |
| 431 | } else if (loop_information_ == nullptr) { |
| 432 | loop_information_ = info; |
| 433 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 434 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 435 | // Note that a non loop header having a loop information means this loop information |
| 436 | // has already been populated |
| 437 | loop_information_ = info; |
| 438 | } else { |
| 439 | // Block is part of an inner loop. Do not update the loop information. |
| 440 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 441 | // at this point, because this method is being called while populating `info`. |
| 442 | } |
| 443 | } |
| 444 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 445 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 446 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 447 | // Returns wheter this block dominates the blocked passed as parameter. |
| 448 | bool Dominates(HBasicBlock* block) const; |
| 449 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 450 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 451 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 452 | |
| 453 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 454 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 455 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 456 | uint32_t GetDexPc() const { return dex_pc_; } |
| 457 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 458 | bool IsCatchBlock() const { return is_catch_block_; } |
| 459 | void SetIsCatchBlock() { is_catch_block_ = true; } |
| 460 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 461 | private: |
| 462 | HGraph* const graph_; |
| 463 | GrowableArray<HBasicBlock*> predecessors_; |
| 464 | GrowableArray<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 465 | HInstructionList instructions_; |
| 466 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 467 | HLoopInformation* loop_information_; |
| 468 | HBasicBlock* dominator_; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 469 | GrowableArray<HBasicBlock*> dominated_blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 470 | int block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 471 | // The dex program counter of the first instruction of this block. |
| 472 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 473 | size_t lifetime_start_; |
| 474 | size_t lifetime_end_; |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 475 | bool is_catch_block_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 476 | |
| 477 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 478 | }; |
| 479 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 480 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 481 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 482 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 483 | M(ArrayGet, Instruction) \ |
| 484 | M(ArrayLength, Instruction) \ |
| 485 | M(ArraySet, Instruction) \ |
| 486 | M(BoundsCheck, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 487 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 488 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 489 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 490 | M(Condition, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 491 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 492 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 493 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 494 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 495 | M(Exit, Instruction) \ |
| 496 | M(FloatConstant, Constant) \ |
| 497 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 498 | M(GreaterThan, Condition) \ |
| 499 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 500 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 501 | M(InstanceFieldGet, Instruction) \ |
| 502 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 503 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 504 | M(IntConstant, Constant) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 505 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 506 | M(InvokeStatic, Invoke) \ |
| 507 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 508 | M(LessThan, Condition) \ |
| 509 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 510 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 511 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 512 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 513 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 514 | M(Local, Instruction) \ |
| 515 | M(LongConstant, Constant) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 516 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 517 | M(Mul, BinaryOperation) \ |
| 518 | M(Neg, UnaryOperation) \ |
| 519 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 520 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 521 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 522 | M(NotEqual, Condition) \ |
| 523 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 524 | M(Or, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 525 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 526 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 527 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 528 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 529 | M(Return, Instruction) \ |
| 530 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 531 | M(Shl, BinaryOperation) \ |
| 532 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 533 | M(StaticFieldGet, Instruction) \ |
| 534 | M(StaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 535 | M(StoreLocal, Instruction) \ |
| 536 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 537 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 538 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 539 | M(Throw, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 540 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 541 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 542 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 543 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 544 | #define FOR_EACH_INSTRUCTION(M) \ |
| 545 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 546 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 547 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 548 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 549 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 550 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 551 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 552 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 553 | #undef FORWARD_DECLARATION |
| 554 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 555 | #define DECLARE_INSTRUCTION(type) \ |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 556 | virtual InstructionKind GetKind() const { return k##type; } \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 557 | virtual const char* DebugName() const { return #type; } \ |
| 558 | virtual const H##type* As##type() const OVERRIDE { return this; } \ |
| 559 | virtual H##type* As##type() OVERRIDE { return this; } \ |
| 560 | virtual bool InstructionTypeEquals(HInstruction* other) const { \ |
| 561 | return other->Is##type(); \ |
| 562 | } \ |
| 563 | virtual void Accept(HGraphVisitor* visitor) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 564 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 565 | template <typename T> |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 566 | class HUseListNode : public ArenaObject<kArenaAllocMisc> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 567 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 568 | HUseListNode(T* user, size_t index, HUseListNode* tail) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 569 | : user_(user), index_(index), tail_(tail) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 570 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 571 | HUseListNode* GetTail() const { return tail_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 572 | T* GetUser() const { return user_; } |
| 573 | size_t GetIndex() const { return index_; } |
| 574 | |
| 575 | void SetTail(HUseListNode<T>* node) { tail_ = node; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 576 | |
| 577 | private: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 578 | T* const user_; |
| 579 | const size_t index_; |
| 580 | HUseListNode<T>* tail_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 581 | |
| 582 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 583 | }; |
| 584 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 585 | // Represents the side effects an instruction may have. |
| 586 | class SideEffects : public ValueObject { |
| 587 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 588 | SideEffects() : flags_(0) {} |
| 589 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 590 | static SideEffects None() { |
| 591 | return SideEffects(0); |
| 592 | } |
| 593 | |
| 594 | static SideEffects All() { |
| 595 | return SideEffects(ChangesSomething().flags_ | DependsOnSomething().flags_); |
| 596 | } |
| 597 | |
| 598 | static SideEffects ChangesSomething() { |
| 599 | return SideEffects((1 << kFlagChangesCount) - 1); |
| 600 | } |
| 601 | |
| 602 | static SideEffects DependsOnSomething() { |
| 603 | int count = kFlagDependsOnCount - kFlagChangesCount; |
| 604 | return SideEffects(((1 << count) - 1) << kFlagChangesCount); |
| 605 | } |
| 606 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 607 | SideEffects Union(SideEffects other) const { |
| 608 | return SideEffects(flags_ | other.flags_); |
| 609 | } |
| 610 | |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 611 | bool HasSideEffects() const { |
| 612 | size_t all_bits_set = (1 << kFlagChangesCount) - 1; |
| 613 | return (flags_ & all_bits_set) != 0; |
| 614 | } |
| 615 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 616 | bool HasAllSideEffects() const { |
| 617 | size_t all_bits_set = (1 << kFlagChangesCount) - 1; |
| 618 | return all_bits_set == (flags_ & all_bits_set); |
| 619 | } |
| 620 | |
| 621 | bool DependsOn(SideEffects other) const { |
| 622 | size_t depends_flags = other.ComputeDependsFlags(); |
| 623 | return (flags_ & depends_flags) != 0; |
| 624 | } |
| 625 | |
| 626 | bool HasDependencies() const { |
| 627 | int count = kFlagDependsOnCount - kFlagChangesCount; |
| 628 | size_t all_bits_set = (1 << count) - 1; |
| 629 | return ((flags_ >> kFlagChangesCount) & all_bits_set) != 0; |
| 630 | } |
| 631 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 632 | private: |
| 633 | static constexpr int kFlagChangesSomething = 0; |
| 634 | static constexpr int kFlagChangesCount = kFlagChangesSomething + 1; |
| 635 | |
| 636 | static constexpr int kFlagDependsOnSomething = kFlagChangesCount; |
| 637 | static constexpr int kFlagDependsOnCount = kFlagDependsOnSomething + 1; |
| 638 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 639 | explicit SideEffects(size_t flags) : flags_(flags) {} |
| 640 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 641 | size_t ComputeDependsFlags() const { |
| 642 | return flags_ << kFlagChangesCount; |
| 643 | } |
| 644 | |
| 645 | size_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 646 | }; |
| 647 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 648 | class HInstruction : public ArenaObject<kArenaAllocMisc> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 649 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 650 | explicit HInstruction(SideEffects side_effects) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 651 | : previous_(nullptr), |
| 652 | next_(nullptr), |
| 653 | block_(nullptr), |
| 654 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 655 | ssa_index_(-1), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 656 | uses_(nullptr), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 657 | env_uses_(nullptr), |
| 658 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 659 | locations_(nullptr), |
| 660 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 661 | lifetime_position_(kNoLifetime), |
| 662 | side_effects_(side_effects) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 663 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 664 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 665 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 666 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 667 | enum InstructionKind { |
| 668 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 669 | }; |
| 670 | #undef DECLARE_KIND |
| 671 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 672 | HInstruction* GetNext() const { return next_; } |
| 673 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 674 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 675 | HBasicBlock* GetBlock() const { return block_; } |
| 676 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 677 | bool IsInBlock() const { return block_ != nullptr; } |
| 678 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 679 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 680 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 681 | virtual size_t InputCount() const = 0; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 682 | virtual HInstruction* InputAt(size_t i) const = 0; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 683 | |
| 684 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 685 | virtual const char* DebugName() const = 0; |
| 686 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 687 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 688 | virtual void SetRawInputAt(size_t index, HInstruction* input) = 0; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 689 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 690 | virtual bool NeedsEnvironment() const { return false; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 691 | virtual bool IsControlFlow() const { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 692 | virtual bool CanThrow() const { return false; } |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 693 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 694 | |
| 695 | void AddUseAt(HInstruction* user, size_t index) { |
| 696 | uses_ = new (block_->GetGraph()->GetArena()) HUseListNode<HInstruction>(user, index, uses_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 697 | } |
| 698 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 699 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 700 | DCHECK(user != nullptr); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 701 | env_uses_ = new (block_->GetGraph()->GetArena()) HUseListNode<HEnvironment>( |
| 702 | user, index, env_uses_); |
| 703 | } |
| 704 | |
| 705 | void RemoveUser(HInstruction* user, size_t index); |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 706 | void RemoveEnvironmentUser(HEnvironment* user, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 707 | |
| 708 | HUseListNode<HInstruction>* GetUses() const { return uses_; } |
| 709 | HUseListNode<HEnvironment>* GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 710 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 711 | bool HasUses() const { return uses_ != nullptr || env_uses_ != nullptr; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 712 | bool HasEnvironmentUses() const { return env_uses_ != nullptr; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 713 | |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 714 | size_t NumberOfUses() const { |
Nicolas Geoffray | 0d3f578 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 715 | // TODO: Optimize this method if it is used outside of the HGraphVisualizer. |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 716 | size_t result = 0; |
| 717 | HUseListNode<HInstruction>* current = uses_; |
| 718 | while (current != nullptr) { |
| 719 | current = current->GetTail(); |
| 720 | ++result; |
| 721 | } |
| 722 | return result; |
| 723 | } |
| 724 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 725 | // Does this instruction strictly dominate `other_instruction`? |
| 726 | // Returns false if this instruction and `other_instruction` are the same. |
| 727 | // Aborts if this instruction and `other_instruction` are both phis. |
| 728 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 729 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 730 | int GetId() const { return id_; } |
| 731 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 732 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 733 | int GetSsaIndex() const { return ssa_index_; } |
| 734 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 735 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 736 | |
| 737 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 738 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 739 | void SetEnvironment(HEnvironment* environment) { environment_ = environment; } |
| 740 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 741 | // Returns the number of entries in the environment. Typically, that is the |
| 742 | // number of dex registers in a method. It could be more in case of inlining. |
| 743 | size_t EnvironmentSize() const; |
| 744 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 745 | LocationSummary* GetLocations() const { return locations_; } |
| 746 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 747 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 748 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 749 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 750 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 751 | bool HasOnlyOneUse() const { |
| 752 | return uses_ != nullptr && uses_->GetTail() == nullptr; |
| 753 | } |
| 754 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 755 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 756 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 757 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 758 | virtual H##type* As##type() { return nullptr; } |
| 759 | |
| 760 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 761 | #undef INSTRUCTION_TYPE_CHECK |
| 762 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 763 | // Returns whether the instruction can be moved within the graph. |
| 764 | virtual bool CanBeMoved() const { return false; } |
| 765 | |
| 766 | // Returns whether the two instructions are of the same kind. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 767 | virtual bool InstructionTypeEquals(HInstruction* other) const { |
| 768 | UNUSED(other); |
| 769 | return false; |
| 770 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 771 | |
| 772 | // Returns whether any data encoded in the two instructions is equal. |
| 773 | // This method does not look at the inputs. Both instructions must be |
| 774 | // of the same type, otherwise the method has undefined behavior. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 775 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 776 | UNUSED(other); |
| 777 | return false; |
| 778 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 779 | |
| 780 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 781 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 782 | // 2) Their inputs are identical. |
| 783 | bool Equals(HInstruction* other) const; |
| 784 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 785 | virtual InstructionKind GetKind() const = 0; |
| 786 | |
| 787 | virtual size_t ComputeHashCode() const { |
| 788 | size_t result = GetKind(); |
| 789 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 790 | result = (result * 31) + InputAt(i)->GetId(); |
| 791 | } |
| 792 | return result; |
| 793 | } |
| 794 | |
| 795 | SideEffects GetSideEffects() const { return side_effects_; } |
| 796 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 797 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 798 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 799 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 800 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 801 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 802 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 803 | private: |
| 804 | HInstruction* previous_; |
| 805 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 806 | HBasicBlock* block_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 807 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 808 | // An instruction gets an id when it is added to the graph. |
| 809 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 810 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 811 | int id_; |
| 812 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 813 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 814 | int ssa_index_; |
| 815 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 816 | // List of instructions that have this instruction as input. |
| 817 | HUseListNode<HInstruction>* uses_; |
| 818 | |
| 819 | // List of environments that contain this instruction. |
| 820 | HUseListNode<HEnvironment>* env_uses_; |
| 821 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 822 | // The environment associated with this instruction. Not null if the instruction |
| 823 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 824 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 825 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 826 | // Set by the code generator. |
| 827 | LocationSummary* locations_; |
| 828 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 829 | // Set by the liveness analysis. |
| 830 | LiveInterval* live_interval_; |
| 831 | |
| 832 | // Set by the liveness analysis, this is the position in a linear |
| 833 | // order of blocks where this instruction's live interval start. |
| 834 | size_t lifetime_position_; |
| 835 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 836 | const SideEffects side_effects_; |
| 837 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 838 | friend class HBasicBlock; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 839 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 840 | |
| 841 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 842 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 843 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 844 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 845 | template<typename T> |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 846 | class HUseIterator : public ValueObject { |
| 847 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 848 | explicit HUseIterator(HUseListNode<T>* uses) : current_(uses) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 849 | |
| 850 | bool Done() const { return current_ == nullptr; } |
| 851 | |
| 852 | void Advance() { |
| 853 | DCHECK(!Done()); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 854 | current_ = current_->GetTail(); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 855 | } |
| 856 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 857 | HUseListNode<T>* Current() const { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 858 | DCHECK(!Done()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 859 | return current_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | private: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 863 | HUseListNode<T>* current_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 864 | |
| 865 | friend class HValue; |
| 866 | }; |
| 867 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 868 | // A HEnvironment object contains the values of virtual registers at a given location. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 869 | class HEnvironment : public ArenaObject<kArenaAllocMisc> { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 870 | public: |
| 871 | HEnvironment(ArenaAllocator* arena, size_t number_of_vregs) : vregs_(arena, number_of_vregs) { |
| 872 | vregs_.SetSize(number_of_vregs); |
| 873 | for (size_t i = 0; i < number_of_vregs; i++) { |
| 874 | vregs_.Put(i, nullptr); |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | void Populate(const GrowableArray<HInstruction*>& env) { |
| 879 | for (size_t i = 0; i < env.Size(); i++) { |
| 880 | HInstruction* instruction = env.Get(i); |
| 881 | vregs_.Put(i, instruction); |
| 882 | if (instruction != nullptr) { |
| 883 | instruction->AddEnvUseAt(this, i); |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
| 889 | vregs_.Put(index, instruction); |
| 890 | } |
| 891 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 892 | HInstruction* GetInstructionAt(size_t index) const { |
| 893 | return vregs_.Get(index); |
| 894 | } |
| 895 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 896 | GrowableArray<HInstruction*>* GetVRegs() { |
| 897 | return &vregs_; |
| 898 | } |
| 899 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 900 | size_t Size() const { return vregs_.Size(); } |
| 901 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 902 | private: |
| 903 | GrowableArray<HInstruction*> vregs_; |
| 904 | |
| 905 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 906 | }; |
| 907 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 908 | class HInputIterator : public ValueObject { |
| 909 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 910 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 911 | |
| 912 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 913 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 914 | void Advance() { index_++; } |
| 915 | |
| 916 | private: |
| 917 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 918 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 919 | |
| 920 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 921 | }; |
| 922 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 923 | class HInstructionIterator : public ValueObject { |
| 924 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 925 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 926 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 927 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 930 | bool Done() const { return instruction_ == nullptr; } |
| 931 | HInstruction* Current() const { return instruction_; } |
| 932 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 933 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 934 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | private: |
| 938 | HInstruction* instruction_; |
| 939 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 940 | |
| 941 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 942 | }; |
| 943 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 944 | class HBackwardInstructionIterator : public ValueObject { |
| 945 | public: |
| 946 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 947 | : instruction_(instructions.last_instruction_) { |
| 948 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 949 | } |
| 950 | |
| 951 | bool Done() const { return instruction_ == nullptr; } |
| 952 | HInstruction* Current() const { return instruction_; } |
| 953 | void Advance() { |
| 954 | instruction_ = next_; |
| 955 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 956 | } |
| 957 | |
| 958 | private: |
| 959 | HInstruction* instruction_; |
| 960 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 961 | |
| 962 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 963 | }; |
| 964 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 965 | // An embedded container with N elements of type T. Used (with partial |
| 966 | // specialization for N=0) because embedded arrays cannot have size 0. |
| 967 | template<typename T, intptr_t N> |
| 968 | class EmbeddedArray { |
| 969 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 970 | EmbeddedArray() : elements_() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 971 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 972 | intptr_t GetLength() const { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 973 | |
| 974 | const T& operator[](intptr_t i) const { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 975 | DCHECK_LT(i, GetLength()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 976 | return elements_[i]; |
| 977 | } |
| 978 | |
| 979 | T& operator[](intptr_t i) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 980 | DCHECK_LT(i, GetLength()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 981 | return elements_[i]; |
| 982 | } |
| 983 | |
| 984 | const T& At(intptr_t i) const { |
| 985 | return (*this)[i]; |
| 986 | } |
| 987 | |
| 988 | void SetAt(intptr_t i, const T& val) { |
| 989 | (*this)[i] = val; |
| 990 | } |
| 991 | |
| 992 | private: |
| 993 | T elements_[N]; |
| 994 | }; |
| 995 | |
| 996 | template<typename T> |
| 997 | class EmbeddedArray<T, 0> { |
| 998 | public: |
| 999 | intptr_t length() const { return 0; } |
| 1000 | const T& operator[](intptr_t i) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1001 | UNUSED(i); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1002 | LOG(FATAL) << "Unreachable"; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1003 | UNREACHABLE(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1004 | } |
| 1005 | T& operator[](intptr_t i) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1006 | UNUSED(i); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1007 | LOG(FATAL) << "Unreachable"; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1008 | UNREACHABLE(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1009 | } |
| 1010 | }; |
| 1011 | |
| 1012 | template<intptr_t N> |
| 1013 | class HTemplateInstruction: public HInstruction { |
| 1014 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1015 | HTemplateInstruction<N>(SideEffects side_effects) |
| 1016 | : HInstruction(side_effects), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1017 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1018 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1019 | virtual size_t InputCount() const { return N; } |
| 1020 | virtual HInstruction* InputAt(size_t i) const { return inputs_[i]; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1021 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1022 | protected: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1023 | virtual void SetRawInputAt(size_t i, HInstruction* instruction) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1024 | inputs_[i] = instruction; |
| 1025 | } |
| 1026 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1027 | private: |
| 1028 | EmbeddedArray<HInstruction*, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1029 | |
| 1030 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1031 | }; |
| 1032 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1033 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1034 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1035 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1036 | HExpression<N>(Primitive::Type type, SideEffects side_effects) |
| 1037 | : HTemplateInstruction<N>(side_effects), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1038 | virtual ~HExpression() {} |
| 1039 | |
| 1040 | virtual Primitive::Type GetType() const { return type_; } |
| 1041 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1042 | protected: |
| 1043 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1044 | }; |
| 1045 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1046 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 1047 | // instruction that branches to the exit block. |
| 1048 | class HReturnVoid : public HTemplateInstruction<0> { |
| 1049 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1050 | HReturnVoid() : HTemplateInstruction(SideEffects::None()) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1051 | |
| 1052 | virtual bool IsControlFlow() const { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1053 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1054 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1055 | |
| 1056 | private: |
| 1057 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 1058 | }; |
| 1059 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1060 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 1061 | // instruction that branches to the exit block. |
| 1062 | class HReturn : public HTemplateInstruction<1> { |
| 1063 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1064 | explicit HReturn(HInstruction* value) : HTemplateInstruction(SideEffects::None()) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1065 | SetRawInputAt(0, value); |
| 1066 | } |
| 1067 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1068 | virtual bool IsControlFlow() const { return true; } |
| 1069 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1070 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1071 | |
| 1072 | private: |
| 1073 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 1074 | }; |
| 1075 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1076 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1077 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1078 | // exit block. |
| 1079 | class HExit : public HTemplateInstruction<0> { |
| 1080 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1081 | HExit() : HTemplateInstruction(SideEffects::None()) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1082 | |
| 1083 | virtual bool IsControlFlow() const { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1084 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1085 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1086 | |
| 1087 | private: |
| 1088 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 1089 | }; |
| 1090 | |
| 1091 | // Jumps from one block to another. |
| 1092 | class HGoto : public HTemplateInstruction<0> { |
| 1093 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1094 | HGoto() : HTemplateInstruction(SideEffects::None()) {} |
| 1095 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1096 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1097 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1098 | HBasicBlock* GetSuccessor() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1099 | return GetBlock()->GetSuccessors().Get(0); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1102 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1103 | |
| 1104 | private: |
| 1105 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 1106 | }; |
| 1107 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1108 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1109 | // Conditional branch. A block ending with an HIf instruction must have |
| 1110 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1111 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1112 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1113 | explicit HIf(HInstruction* input) : HTemplateInstruction(SideEffects::None()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1114 | SetRawInputAt(0, input); |
| 1115 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1116 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1117 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1118 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1119 | HBasicBlock* IfTrueSuccessor() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1120 | return GetBlock()->GetSuccessors().Get(0); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | HBasicBlock* IfFalseSuccessor() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1124 | return GetBlock()->GetSuccessors().Get(1); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1127 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1128 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1129 | virtual bool IsIfInstruction() const { return true; } |
| 1130 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1131 | private: |
| 1132 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 1133 | }; |
| 1134 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1135 | class HUnaryOperation : public HExpression<1> { |
| 1136 | public: |
| 1137 | HUnaryOperation(Primitive::Type result_type, HInstruction* input) |
| 1138 | : HExpression(result_type, SideEffects::None()) { |
| 1139 | SetRawInputAt(0, input); |
| 1140 | } |
| 1141 | |
| 1142 | HInstruction* GetInput() const { return InputAt(0); } |
| 1143 | Primitive::Type GetResultType() const { return GetType(); } |
| 1144 | |
| 1145 | virtual bool CanBeMoved() const { return true; } |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1146 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1147 | UNUSED(other); |
| 1148 | return true; |
| 1149 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1150 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 1151 | // Try to statically evaluate `operation` and return a HConstant |
| 1152 | // containing the result of this evaluation. If `operation` cannot |
| 1153 | // be evaluated as a constant, return nullptr. |
| 1154 | HConstant* TryStaticEvaluation() const; |
| 1155 | |
| 1156 | // Apply this operation to `x`. |
| 1157 | virtual int32_t Evaluate(int32_t x) const = 0; |
| 1158 | virtual int64_t Evaluate(int64_t x) const = 0; |
| 1159 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1160 | DECLARE_INSTRUCTION(UnaryOperation); |
| 1161 | |
| 1162 | private: |
| 1163 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 1164 | }; |
| 1165 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1166 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1167 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1168 | HBinaryOperation(Primitive::Type result_type, |
| 1169 | HInstruction* left, |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1170 | HInstruction* right) : HExpression(result_type, SideEffects::None()) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1171 | SetRawInputAt(0, left); |
| 1172 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1175 | HInstruction* GetLeft() const { return InputAt(0); } |
| 1176 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1177 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1178 | |
| 1179 | virtual bool IsCommutative() { return false; } |
| 1180 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1181 | virtual bool CanBeMoved() const { return true; } |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1182 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1183 | UNUSED(other); |
| 1184 | return true; |
| 1185 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1186 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 1187 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1188 | // containing the result of this evaluation. If `operation` cannot |
| 1189 | // be evaluated as a constant, return nullptr. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 1190 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1191 | |
| 1192 | // Apply this operation to `x` and `y`. |
| 1193 | virtual int32_t Evaluate(int32_t x, int32_t y) const = 0; |
| 1194 | virtual int64_t Evaluate(int64_t x, int64_t y) const = 0; |
| 1195 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1196 | DECLARE_INSTRUCTION(BinaryOperation); |
| 1197 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1198 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1199 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 1200 | }; |
| 1201 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1202 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1203 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1204 | HCondition(HInstruction* first, HInstruction* second) |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1205 | : HBinaryOperation(Primitive::kPrimBoolean, first, second), |
| 1206 | needs_materialization_(true) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1207 | |
| 1208 | virtual bool IsCommutative() { return true; } |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1209 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1210 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 1211 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1212 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 1213 | // For code generation purposes, returns whether this instruction is just before |
| 1214 | // `if_`, and disregard moves in between. |
| 1215 | bool IsBeforeWhenDisregardMoves(HIf* if_) const; |
| 1216 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1217 | DECLARE_INSTRUCTION(Condition); |
| 1218 | |
| 1219 | virtual IfCondition GetCondition() const = 0; |
| 1220 | |
| 1221 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1222 | // For register allocation purposes, returns whether this instruction needs to be |
| 1223 | // materialized (that is, not just be in the processor flags). |
| 1224 | bool needs_materialization_; |
| 1225 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1226 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 1227 | }; |
| 1228 | |
| 1229 | // Instruction to check if two inputs are equal to each other. |
| 1230 | class HEqual : public HCondition { |
| 1231 | public: |
| 1232 | HEqual(HInstruction* first, HInstruction* second) |
| 1233 | : HCondition(first, second) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1234 | |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 1235 | virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1236 | return x == y ? 1 : 0; |
| 1237 | } |
| 1238 | virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1239 | return x == y ? 1 : 0; |
| 1240 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1241 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1242 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1243 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1244 | virtual IfCondition GetCondition() const { |
| 1245 | return kCondEQ; |
| 1246 | } |
| 1247 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1248 | private: |
| 1249 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 1250 | }; |
| 1251 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1252 | class HNotEqual : public HCondition { |
| 1253 | public: |
| 1254 | HNotEqual(HInstruction* first, HInstruction* second) |
| 1255 | : HCondition(first, second) {} |
| 1256 | |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 1257 | virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1258 | return x != y ? 1 : 0; |
| 1259 | } |
| 1260 | virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1261 | return x != y ? 1 : 0; |
| 1262 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1263 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1264 | DECLARE_INSTRUCTION(NotEqual); |
| 1265 | |
| 1266 | virtual IfCondition GetCondition() const { |
| 1267 | return kCondNE; |
| 1268 | } |
| 1269 | |
| 1270 | private: |
| 1271 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 1272 | }; |
| 1273 | |
| 1274 | class HLessThan : public HCondition { |
| 1275 | public: |
| 1276 | HLessThan(HInstruction* first, HInstruction* second) |
| 1277 | : HCondition(first, second) {} |
| 1278 | |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 1279 | virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1280 | return x < y ? 1 : 0; |
| 1281 | } |
| 1282 | virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1283 | return x < y ? 1 : 0; |
| 1284 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1285 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1286 | DECLARE_INSTRUCTION(LessThan); |
| 1287 | |
| 1288 | virtual IfCondition GetCondition() const { |
| 1289 | return kCondLT; |
| 1290 | } |
| 1291 | |
| 1292 | private: |
| 1293 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 1294 | }; |
| 1295 | |
| 1296 | class HLessThanOrEqual : public HCondition { |
| 1297 | public: |
| 1298 | HLessThanOrEqual(HInstruction* first, HInstruction* second) |
| 1299 | : HCondition(first, second) {} |
| 1300 | |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 1301 | virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1302 | return x <= y ? 1 : 0; |
| 1303 | } |
| 1304 | virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1305 | return x <= y ? 1 : 0; |
| 1306 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1307 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1308 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 1309 | |
| 1310 | virtual IfCondition GetCondition() const { |
| 1311 | return kCondLE; |
| 1312 | } |
| 1313 | |
| 1314 | private: |
| 1315 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 1316 | }; |
| 1317 | |
| 1318 | class HGreaterThan : public HCondition { |
| 1319 | public: |
| 1320 | HGreaterThan(HInstruction* first, HInstruction* second) |
| 1321 | : HCondition(first, second) {} |
| 1322 | |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 1323 | virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1324 | return x > y ? 1 : 0; |
| 1325 | } |
| 1326 | virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1327 | return x > y ? 1 : 0; |
| 1328 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1329 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1330 | DECLARE_INSTRUCTION(GreaterThan); |
| 1331 | |
| 1332 | virtual IfCondition GetCondition() const { |
| 1333 | return kCondGT; |
| 1334 | } |
| 1335 | |
| 1336 | private: |
| 1337 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 1338 | }; |
| 1339 | |
| 1340 | class HGreaterThanOrEqual : public HCondition { |
| 1341 | public: |
| 1342 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second) |
| 1343 | : HCondition(first, second) {} |
| 1344 | |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 1345 | virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1346 | return x >= y ? 1 : 0; |
| 1347 | } |
| 1348 | virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1349 | return x >= y ? 1 : 0; |
| 1350 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1351 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1352 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 1353 | |
| 1354 | virtual IfCondition GetCondition() const { |
| 1355 | return kCondGE; |
| 1356 | } |
| 1357 | |
| 1358 | private: |
| 1359 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 1360 | }; |
| 1361 | |
| 1362 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1363 | // Instruction to check how two inputs compare to each other. |
| 1364 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 1365 | class HCompare : public HBinaryOperation { |
| 1366 | public: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1367 | // The bias applies for floating point operations and indicates how NaN |
| 1368 | // comparisons are treated: |
| 1369 | enum Bias { |
| 1370 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 1371 | kGtBias, // return 1 for NaN comparisons |
| 1372 | kLtBias, // return -1 for NaN comparisons |
| 1373 | }; |
| 1374 | |
| 1375 | HCompare(Primitive::Type type, HInstruction* first, HInstruction* second, Bias bias) |
| 1376 | : HBinaryOperation(Primitive::kPrimInt, first, second), bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1377 | DCHECK_EQ(type, first->GetType()); |
| 1378 | DCHECK_EQ(type, second->GetType()); |
| 1379 | } |
| 1380 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1381 | int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1382 | return |
| 1383 | x == y ? 0 : |
| 1384 | x > y ? 1 : |
| 1385 | -1; |
| 1386 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1387 | |
| 1388 | int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1389 | return |
| 1390 | x == y ? 0 : |
| 1391 | x > y ? 1 : |
| 1392 | -1; |
| 1393 | } |
| 1394 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1395 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 1396 | return bias_ == other->AsCompare()->bias_; |
| 1397 | } |
| 1398 | |
| 1399 | bool IsGtBias() { return bias_ == kGtBias; } |
| 1400 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1401 | DECLARE_INSTRUCTION(Compare); |
| 1402 | |
| 1403 | private: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1404 | const Bias bias_; |
| 1405 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 1406 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 1407 | }; |
| 1408 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1409 | // A local in the graph. Corresponds to a Dex register. |
| 1410 | class HLocal : public HTemplateInstruction<0> { |
| 1411 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1412 | explicit HLocal(uint16_t reg_number) |
| 1413 | : HTemplateInstruction(SideEffects::None()), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1414 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1415 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1416 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1417 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1418 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1419 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1420 | // The Dex register number. |
| 1421 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1422 | |
| 1423 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 1424 | }; |
| 1425 | |
| 1426 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1427 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1428 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 1429 | HLoadLocal(HLocal* local, Primitive::Type type) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1430 | : HExpression(type, SideEffects::None()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1431 | SetRawInputAt(0, local); |
| 1432 | } |
| 1433 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1434 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 1435 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1436 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1437 | |
| 1438 | private: |
| 1439 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 1440 | }; |
| 1441 | |
| 1442 | // Store a value in a given local. This instruction has two inputs: the value |
| 1443 | // and the local. |
| 1444 | class HStoreLocal : public HTemplateInstruction<2> { |
| 1445 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1446 | HStoreLocal(HLocal* local, HInstruction* value) : HTemplateInstruction(SideEffects::None()) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1447 | SetRawInputAt(0, local); |
| 1448 | SetRawInputAt(1, value); |
| 1449 | } |
| 1450 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1451 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 1452 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1453 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1454 | |
| 1455 | private: |
| 1456 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 1457 | }; |
| 1458 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1459 | class HConstant : public HExpression<0> { |
| 1460 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1461 | explicit HConstant(Primitive::Type type) : HExpression(type, SideEffects::None()) {} |
| 1462 | |
| 1463 | virtual bool CanBeMoved() const { return true; } |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1464 | |
| 1465 | DECLARE_INSTRUCTION(Constant); |
| 1466 | |
| 1467 | private: |
| 1468 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 1469 | }; |
| 1470 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1471 | class HFloatConstant : public HConstant { |
| 1472 | public: |
| 1473 | explicit HFloatConstant(float value) : HConstant(Primitive::kPrimFloat), value_(value) {} |
| 1474 | |
| 1475 | float GetValue() const { return value_; } |
| 1476 | |
| 1477 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1478 | return bit_cast<float, int32_t>(other->AsFloatConstant()->value_) == |
| 1479 | bit_cast<float, int32_t>(value_); |
| 1480 | } |
| 1481 | |
| 1482 | virtual size_t ComputeHashCode() const { return static_cast<size_t>(GetValue()); } |
| 1483 | |
| 1484 | DECLARE_INSTRUCTION(FloatConstant); |
| 1485 | |
| 1486 | private: |
| 1487 | const float value_; |
| 1488 | |
| 1489 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 1490 | }; |
| 1491 | |
| 1492 | class HDoubleConstant : public HConstant { |
| 1493 | public: |
| 1494 | explicit HDoubleConstant(double value) : HConstant(Primitive::kPrimDouble), value_(value) {} |
| 1495 | |
| 1496 | double GetValue() const { return value_; } |
| 1497 | |
| 1498 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1499 | return bit_cast<double, int64_t>(other->AsDoubleConstant()->value_) == |
| 1500 | bit_cast<double, int64_t>(value_); |
| 1501 | } |
| 1502 | |
| 1503 | virtual size_t ComputeHashCode() const { return static_cast<size_t>(GetValue()); } |
| 1504 | |
| 1505 | DECLARE_INSTRUCTION(DoubleConstant); |
| 1506 | |
| 1507 | private: |
| 1508 | const double value_; |
| 1509 | |
| 1510 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 1511 | }; |
| 1512 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1513 | // Constants of the type int. Those can be from Dex instructions, or |
| 1514 | // synthesized (for example with the if-eqz instruction). |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1515 | class HIntConstant : public HConstant { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1516 | public: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1517 | explicit HIntConstant(int32_t value) : HConstant(Primitive::kPrimInt), value_(value) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1518 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1519 | int32_t GetValue() const { return value_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1520 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1521 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1522 | return other->AsIntConstant()->value_ == value_; |
| 1523 | } |
| 1524 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1525 | virtual size_t ComputeHashCode() const { return GetValue(); } |
| 1526 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1527 | DECLARE_INSTRUCTION(IntConstant); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1528 | |
| 1529 | private: |
| 1530 | const int32_t value_; |
| 1531 | |
| 1532 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 1533 | }; |
| 1534 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1535 | class HLongConstant : public HConstant { |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1536 | public: |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 1537 | explicit HLongConstant(int64_t value) : HConstant(Primitive::kPrimLong), value_(value) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1538 | |
| 1539 | int64_t GetValue() const { return value_; } |
| 1540 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1541 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1542 | return other->AsLongConstant()->value_ == value_; |
| 1543 | } |
| 1544 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1545 | virtual size_t ComputeHashCode() const { return static_cast<size_t>(GetValue()); } |
| 1546 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1547 | DECLARE_INSTRUCTION(LongConstant); |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1548 | |
| 1549 | private: |
| 1550 | const int64_t value_; |
| 1551 | |
| 1552 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 1553 | }; |
| 1554 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1555 | class HInvoke : public HInstruction { |
| 1556 | public: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1557 | HInvoke(ArenaAllocator* arena, |
| 1558 | uint32_t number_of_arguments, |
| 1559 | Primitive::Type return_type, |
| 1560 | uint32_t dex_pc) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1561 | : HInstruction(SideEffects::All()), |
| 1562 | inputs_(arena, number_of_arguments), |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1563 | return_type_(return_type), |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1564 | dex_pc_(dex_pc) { |
| 1565 | inputs_.SetSize(number_of_arguments); |
| 1566 | } |
| 1567 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1568 | virtual size_t InputCount() const { return inputs_.Size(); } |
| 1569 | virtual HInstruction* InputAt(size_t i) const { return inputs_.Get(i); } |
| 1570 | |
| 1571 | // Runtime needs to walk the stack, so Dex -> Dex calls need to |
| 1572 | // know their environment. |
| 1573 | virtual bool NeedsEnvironment() const { return true; } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1574 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1575 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1576 | SetRawInputAt(index, argument); |
| 1577 | } |
| 1578 | |
| 1579 | virtual void SetRawInputAt(size_t index, HInstruction* input) { |
| 1580 | inputs_.Put(index, input); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1583 | virtual Primitive::Type GetType() const { return return_type_; } |
| 1584 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1585 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1586 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1587 | DECLARE_INSTRUCTION(Invoke); |
| 1588 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1589 | protected: |
| 1590 | GrowableArray<HInstruction*> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1591 | const Primitive::Type return_type_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1592 | const uint32_t dex_pc_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1593 | |
| 1594 | private: |
| 1595 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 1596 | }; |
| 1597 | |
| 1598 | class HInvokeStatic : public HInvoke { |
| 1599 | public: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1600 | HInvokeStatic(ArenaAllocator* arena, |
| 1601 | uint32_t number_of_arguments, |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1602 | Primitive::Type return_type, |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1603 | uint32_t dex_pc, |
| 1604 | uint32_t index_in_dex_cache) |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1605 | : HInvoke(arena, number_of_arguments, return_type, dex_pc), |
| 1606 | index_in_dex_cache_(index_in_dex_cache) {} |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1607 | |
| 1608 | uint32_t GetIndexInDexCache() const { return index_in_dex_cache_; } |
| 1609 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1610 | DECLARE_INSTRUCTION(InvokeStatic); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1611 | |
| 1612 | private: |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 1613 | const uint32_t index_in_dex_cache_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1614 | |
| 1615 | DISALLOW_COPY_AND_ASSIGN(HInvokeStatic); |
| 1616 | }; |
| 1617 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 1618 | class HInvokeVirtual : public HInvoke { |
| 1619 | public: |
| 1620 | HInvokeVirtual(ArenaAllocator* arena, |
| 1621 | uint32_t number_of_arguments, |
| 1622 | Primitive::Type return_type, |
| 1623 | uint32_t dex_pc, |
| 1624 | uint32_t vtable_index) |
| 1625 | : HInvoke(arena, number_of_arguments, return_type, dex_pc), |
| 1626 | vtable_index_(vtable_index) {} |
| 1627 | |
| 1628 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 1629 | |
| 1630 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 1631 | |
| 1632 | private: |
| 1633 | const uint32_t vtable_index_; |
| 1634 | |
| 1635 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 1636 | }; |
| 1637 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1638 | class HInvokeInterface : public HInvoke { |
| 1639 | public: |
| 1640 | HInvokeInterface(ArenaAllocator* arena, |
| 1641 | uint32_t number_of_arguments, |
| 1642 | Primitive::Type return_type, |
| 1643 | uint32_t dex_pc, |
| 1644 | uint32_t dex_method_index, |
| 1645 | uint32_t imt_index) |
| 1646 | : HInvoke(arena, number_of_arguments, return_type, dex_pc), |
| 1647 | dex_method_index_(dex_method_index), |
| 1648 | imt_index_(imt_index) {} |
| 1649 | |
| 1650 | uint32_t GetImtIndex() const { return imt_index_; } |
| 1651 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 1652 | |
| 1653 | DECLARE_INSTRUCTION(InvokeInterface); |
| 1654 | |
| 1655 | private: |
| 1656 | const uint32_t dex_method_index_; |
| 1657 | const uint32_t imt_index_; |
| 1658 | |
| 1659 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 1660 | }; |
| 1661 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1662 | class HNewInstance : public HExpression<0> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1663 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1664 | HNewInstance(uint32_t dex_pc, uint16_t type_index) |
| 1665 | : HExpression(Primitive::kPrimNot, SideEffects::None()), |
| 1666 | dex_pc_(dex_pc), |
| 1667 | type_index_(type_index) {} |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1668 | |
| 1669 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1670 | uint16_t GetTypeIndex() const { return type_index_; } |
| 1671 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1672 | // Calls runtime so needs an environment. |
| 1673 | virtual bool NeedsEnvironment() const { return true; } |
| 1674 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1675 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 1676 | |
| 1677 | private: |
| 1678 | const uint32_t dex_pc_; |
| 1679 | const uint16_t type_index_; |
| 1680 | |
| 1681 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 1682 | }; |
| 1683 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1684 | class HNeg : public HUnaryOperation { |
| 1685 | public: |
| 1686 | explicit HNeg(Primitive::Type result_type, HInstruction* input) |
| 1687 | : HUnaryOperation(result_type, input) {} |
| 1688 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 1689 | virtual int32_t Evaluate(int32_t x) const OVERRIDE { return -x; } |
| 1690 | virtual int64_t Evaluate(int64_t x) const OVERRIDE { return -x; } |
| 1691 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1692 | DECLARE_INSTRUCTION(Neg); |
| 1693 | |
| 1694 | private: |
| 1695 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 1696 | }; |
| 1697 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 1698 | class HNewArray : public HExpression<1> { |
| 1699 | public: |
| 1700 | HNewArray(HInstruction* length, uint32_t dex_pc, uint16_t type_index) |
| 1701 | : HExpression(Primitive::kPrimNot, SideEffects::None()), |
| 1702 | dex_pc_(dex_pc), |
| 1703 | type_index_(type_index) { |
| 1704 | SetRawInputAt(0, length); |
| 1705 | } |
| 1706 | |
| 1707 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1708 | uint16_t GetTypeIndex() const { return type_index_; } |
| 1709 | |
| 1710 | // Calls runtime so needs an environment. |
| 1711 | virtual bool NeedsEnvironment() const { return true; } |
| 1712 | |
| 1713 | DECLARE_INSTRUCTION(NewArray); |
| 1714 | |
| 1715 | private: |
| 1716 | const uint32_t dex_pc_; |
| 1717 | const uint16_t type_index_; |
| 1718 | |
| 1719 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 1720 | }; |
| 1721 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1722 | class HAdd : public HBinaryOperation { |
| 1723 | public: |
| 1724 | HAdd(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1725 | : HBinaryOperation(result_type, left, right) {} |
| 1726 | |
| 1727 | virtual bool IsCommutative() { return true; } |
| 1728 | |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 1729 | virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1730 | return x + y; |
| 1731 | } |
| 1732 | virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1733 | return x + y; |
| 1734 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1735 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 1736 | DECLARE_INSTRUCTION(Add); |
| 1737 | |
| 1738 | private: |
| 1739 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 1740 | }; |
| 1741 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1742 | class HSub : public HBinaryOperation { |
| 1743 | public: |
| 1744 | HSub(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1745 | : HBinaryOperation(result_type, left, right) {} |
| 1746 | |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 1747 | virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1748 | return x - y; |
| 1749 | } |
| 1750 | virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1751 | return x - y; |
| 1752 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 1753 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1754 | DECLARE_INSTRUCTION(Sub); |
| 1755 | |
| 1756 | private: |
| 1757 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 1758 | }; |
| 1759 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1760 | class HMul : public HBinaryOperation { |
| 1761 | public: |
| 1762 | HMul(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1763 | : HBinaryOperation(result_type, left, right) {} |
| 1764 | |
| 1765 | virtual bool IsCommutative() { return true; } |
| 1766 | |
| 1767 | virtual int32_t Evaluate(int32_t x, int32_t y) const { return x * y; } |
| 1768 | virtual int64_t Evaluate(int64_t x, int64_t y) const { return x * y; } |
| 1769 | |
| 1770 | DECLARE_INSTRUCTION(Mul); |
| 1771 | |
| 1772 | private: |
| 1773 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 1774 | }; |
| 1775 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1776 | class HDiv : public HBinaryOperation { |
| 1777 | public: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1778 | HDiv(Primitive::Type result_type, HInstruction* left, HInstruction* right, uint32_t dex_pc) |
| 1779 | : HBinaryOperation(result_type, left, right), dex_pc_(dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1780 | |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 1781 | virtual int32_t Evaluate(int32_t x, int32_t y) const { |
| 1782 | // Our graph structure ensures we never have 0 for `y` during constant folding. |
| 1783 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1784 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 1785 | return (y == -1) ? -x : x / y; |
| 1786 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1787 | |
| 1788 | virtual int64_t Evaluate(int64_t x, int64_t y) const { |
| 1789 | DCHECK_NE(y, 0); |
| 1790 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 1791 | return (y == -1) ? -x : x / y; |
| 1792 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1793 | |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1794 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1795 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1796 | DECLARE_INSTRUCTION(Div); |
| 1797 | |
| 1798 | private: |
Calin Juravle | d6fb6cf | 2014-11-11 19:07:44 +0000 | [diff] [blame] | 1799 | const uint32_t dex_pc_; |
| 1800 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1801 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 1802 | }; |
| 1803 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 1804 | class HRem : public HBinaryOperation { |
| 1805 | public: |
| 1806 | HRem(Primitive::Type result_type, HInstruction* left, HInstruction* right, uint32_t dex_pc) |
| 1807 | : HBinaryOperation(result_type, left, right), dex_pc_(dex_pc) {} |
| 1808 | |
| 1809 | virtual int32_t Evaluate(int32_t x, int32_t y) const { |
| 1810 | DCHECK_NE(y, 0); |
| 1811 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 1812 | return (y == -1) ? 0 : x % y; |
| 1813 | } |
| 1814 | |
| 1815 | virtual int64_t Evaluate(int64_t x, int64_t y) const { |
| 1816 | DCHECK_NE(y, 0); |
| 1817 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 1818 | return (y == -1) ? 0 : x % y; |
| 1819 | } |
| 1820 | |
| 1821 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1822 | |
| 1823 | DECLARE_INSTRUCTION(Rem); |
| 1824 | |
| 1825 | private: |
| 1826 | const uint32_t dex_pc_; |
| 1827 | |
| 1828 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 1829 | }; |
| 1830 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1831 | class HDivZeroCheck : public HExpression<1> { |
| 1832 | public: |
| 1833 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
| 1834 | : HExpression(value->GetType(), SideEffects::None()), dex_pc_(dex_pc) { |
| 1835 | SetRawInputAt(0, value); |
| 1836 | } |
| 1837 | |
| 1838 | bool CanBeMoved() const OVERRIDE { return true; } |
| 1839 | |
| 1840 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 1841 | UNUSED(other); |
| 1842 | return true; |
| 1843 | } |
| 1844 | |
| 1845 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 1846 | bool CanThrow() const OVERRIDE { return true; } |
| 1847 | |
| 1848 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1849 | |
| 1850 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 1851 | |
| 1852 | private: |
| 1853 | const uint32_t dex_pc_; |
| 1854 | |
| 1855 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 1856 | }; |
| 1857 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1858 | class HShl : public HBinaryOperation { |
| 1859 | public: |
| 1860 | HShl(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1861 | : HBinaryOperation(result_type, left, right) {} |
| 1862 | |
| 1863 | int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x << (y & kMaxIntShiftValue); } |
| 1864 | int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x << (y & kMaxLongShiftValue); } |
| 1865 | |
| 1866 | DECLARE_INSTRUCTION(Shl); |
| 1867 | |
| 1868 | private: |
| 1869 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 1870 | }; |
| 1871 | |
| 1872 | class HShr : public HBinaryOperation { |
| 1873 | public: |
| 1874 | HShr(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1875 | : HBinaryOperation(result_type, left, right) {} |
| 1876 | |
| 1877 | int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x >> (y & kMaxIntShiftValue); } |
| 1878 | int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x >> (y & kMaxLongShiftValue); } |
| 1879 | |
| 1880 | DECLARE_INSTRUCTION(Shr); |
| 1881 | |
| 1882 | private: |
| 1883 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 1884 | }; |
| 1885 | |
| 1886 | class HUShr : public HBinaryOperation { |
| 1887 | public: |
| 1888 | HUShr(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1889 | : HBinaryOperation(result_type, left, right) {} |
| 1890 | |
| 1891 | int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { |
| 1892 | uint32_t ux = static_cast<uint32_t>(x); |
| 1893 | uint32_t uy = static_cast<uint32_t>(y) & kMaxIntShiftValue; |
| 1894 | return static_cast<int32_t>(ux >> uy); |
| 1895 | } |
| 1896 | |
| 1897 | int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { |
| 1898 | uint64_t ux = static_cast<uint64_t>(x); |
| 1899 | uint64_t uy = static_cast<uint64_t>(y) & kMaxLongShiftValue; |
| 1900 | return static_cast<int64_t>(ux >> uy); |
| 1901 | } |
| 1902 | |
| 1903 | DECLARE_INSTRUCTION(UShr); |
| 1904 | |
| 1905 | private: |
| 1906 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 1907 | }; |
| 1908 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1909 | class HAnd : public HBinaryOperation { |
| 1910 | public: |
| 1911 | HAnd(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1912 | : HBinaryOperation(result_type, left, right) {} |
| 1913 | |
| 1914 | bool IsCommutative() OVERRIDE { return true; } |
| 1915 | |
| 1916 | int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x & y; } |
| 1917 | int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x & y; } |
| 1918 | |
| 1919 | DECLARE_INSTRUCTION(And); |
| 1920 | |
| 1921 | private: |
| 1922 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 1923 | }; |
| 1924 | |
| 1925 | class HOr : public HBinaryOperation { |
| 1926 | public: |
| 1927 | HOr(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1928 | : HBinaryOperation(result_type, left, right) {} |
| 1929 | |
| 1930 | bool IsCommutative() OVERRIDE { return true; } |
| 1931 | |
| 1932 | int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x | y; } |
| 1933 | int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x | y; } |
| 1934 | |
| 1935 | DECLARE_INSTRUCTION(Or); |
| 1936 | |
| 1937 | private: |
| 1938 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 1939 | }; |
| 1940 | |
| 1941 | class HXor : public HBinaryOperation { |
| 1942 | public: |
| 1943 | HXor(Primitive::Type result_type, HInstruction* left, HInstruction* right) |
| 1944 | : HBinaryOperation(result_type, left, right) {} |
| 1945 | |
| 1946 | bool IsCommutative() OVERRIDE { return true; } |
| 1947 | |
| 1948 | int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x ^ y; } |
| 1949 | int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x ^ y; } |
| 1950 | |
| 1951 | DECLARE_INSTRUCTION(Xor); |
| 1952 | |
| 1953 | private: |
| 1954 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 1955 | }; |
| 1956 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1957 | // The value of a parameter in this method. Its location depends on |
| 1958 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1959 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1960 | public: |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1961 | HParameterValue(uint8_t index, Primitive::Type parameter_type) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1962 | : HExpression(parameter_type, SideEffects::None()), index_(index) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 1963 | |
| 1964 | uint8_t GetIndex() const { return index_; } |
| 1965 | |
| 1966 | DECLARE_INSTRUCTION(ParameterValue); |
| 1967 | |
| 1968 | private: |
| 1969 | // The index of this parameter in the parameters list. Must be less |
| 1970 | // than HGraph::number_of_in_vregs_; |
| 1971 | const uint8_t index_; |
| 1972 | |
| 1973 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 1974 | }; |
| 1975 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1976 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1977 | public: |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1978 | explicit HNot(Primitive::Type result_type, HInstruction* input) |
| 1979 | : HUnaryOperation(result_type, input) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1980 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1981 | virtual bool CanBeMoved() const { return true; } |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1982 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1983 | UNUSED(other); |
| 1984 | return true; |
| 1985 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1986 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1987 | virtual int32_t Evaluate(int32_t x) const OVERRIDE { return ~x; } |
| 1988 | virtual int64_t Evaluate(int64_t x) const OVERRIDE { return ~x; } |
| 1989 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 1990 | DECLARE_INSTRUCTION(Not); |
| 1991 | |
| 1992 | private: |
| 1993 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 1994 | }; |
| 1995 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1996 | class HTypeConversion : public HExpression<1> { |
| 1997 | public: |
| 1998 | // Instantiate a type conversion of `input` to `result_type`. |
| 1999 | HTypeConversion(Primitive::Type result_type, HInstruction* input) |
| 2000 | : HExpression(result_type, SideEffects::None()) { |
| 2001 | SetRawInputAt(0, input); |
| 2002 | DCHECK_NE(input->GetType(), result_type); |
| 2003 | } |
| 2004 | |
| 2005 | HInstruction* GetInput() const { return InputAt(0); } |
| 2006 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 2007 | Primitive::Type GetResultType() const { return GetType(); } |
| 2008 | |
| 2009 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 2010 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 2011 | |
| 2012 | DECLARE_INSTRUCTION(TypeConversion); |
| 2013 | |
| 2014 | private: |
| 2015 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 2016 | }; |
| 2017 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2018 | class HPhi : public HInstruction { |
| 2019 | public: |
| 2020 | HPhi(ArenaAllocator* arena, uint32_t reg_number, size_t number_of_inputs, Primitive::Type type) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2021 | : HInstruction(SideEffects::None()), |
| 2022 | inputs_(arena, number_of_inputs), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2023 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2024 | type_(type), |
| 2025 | is_live_(false) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2026 | inputs_.SetSize(number_of_inputs); |
| 2027 | } |
| 2028 | |
| 2029 | virtual size_t InputCount() const { return inputs_.Size(); } |
| 2030 | virtual HInstruction* InputAt(size_t i) const { return inputs_.Get(i); } |
| 2031 | |
| 2032 | virtual void SetRawInputAt(size_t index, HInstruction* input) { |
| 2033 | inputs_.Put(index, input); |
| 2034 | } |
| 2035 | |
| 2036 | void AddInput(HInstruction* input); |
| 2037 | |
| 2038 | virtual Primitive::Type GetType() const { return type_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2039 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2040 | |
| 2041 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2042 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2043 | void SetDead() { is_live_ = false; } |
| 2044 | void SetLive() { is_live_ = true; } |
| 2045 | bool IsDead() const { return !is_live_; } |
| 2046 | bool IsLive() const { return is_live_; } |
| 2047 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2048 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2049 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 2050 | private: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2051 | GrowableArray<HInstruction*> inputs_; |
| 2052 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2053 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2054 | bool is_live_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2055 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2056 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2057 | }; |
| 2058 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2059 | class HNullCheck : public HExpression<1> { |
| 2060 | public: |
| 2061 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2062 | : HExpression(value->GetType(), SideEffects::None()), dex_pc_(dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2063 | SetRawInputAt(0, value); |
| 2064 | } |
| 2065 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2066 | virtual bool CanBeMoved() const { return true; } |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2067 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 2068 | UNUSED(other); |
| 2069 | return true; |
| 2070 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2071 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2072 | virtual bool NeedsEnvironment() const { return true; } |
| 2073 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 2074 | virtual bool CanThrow() const { return true; } |
| 2075 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2076 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2077 | |
| 2078 | DECLARE_INSTRUCTION(NullCheck); |
| 2079 | |
| 2080 | private: |
| 2081 | const uint32_t dex_pc_; |
| 2082 | |
| 2083 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 2084 | }; |
| 2085 | |
| 2086 | class FieldInfo : public ValueObject { |
| 2087 | public: |
Roland Levillain | 5799fc0 | 2014-09-25 12:15:20 +0100 | [diff] [blame] | 2088 | FieldInfo(MemberOffset field_offset, Primitive::Type field_type) |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2089 | : field_offset_(field_offset), field_type_(field_type) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2090 | |
| 2091 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2092 | Primitive::Type GetFieldType() const { return field_type_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2093 | |
| 2094 | private: |
| 2095 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2096 | const Primitive::Type field_type_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2097 | }; |
| 2098 | |
| 2099 | class HInstanceFieldGet : public HExpression<1> { |
| 2100 | public: |
| 2101 | HInstanceFieldGet(HInstruction* value, |
| 2102 | Primitive::Type field_type, |
| 2103 | MemberOffset field_offset) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2104 | : HExpression(field_type, SideEffects::DependsOnSomething()), |
| 2105 | field_info_(field_offset, field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2106 | SetRawInputAt(0, value); |
| 2107 | } |
| 2108 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2109 | virtual bool CanBeMoved() const { return true; } |
| 2110 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 2111 | size_t other_offset = other->AsInstanceFieldGet()->GetFieldOffset().SizeValue(); |
| 2112 | return other_offset == GetFieldOffset().SizeValue(); |
| 2113 | } |
| 2114 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2115 | virtual size_t ComputeHashCode() const { |
| 2116 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 2117 | } |
| 2118 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2119 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2120 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2121 | |
| 2122 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 2123 | |
| 2124 | private: |
| 2125 | const FieldInfo field_info_; |
| 2126 | |
| 2127 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 2128 | }; |
| 2129 | |
| 2130 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 2131 | public: |
| 2132 | HInstanceFieldSet(HInstruction* object, |
| 2133 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2134 | Primitive::Type field_type, |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2135 | MemberOffset field_offset) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2136 | : HTemplateInstruction(SideEffects::ChangesSomething()), |
| 2137 | field_info_(field_offset, field_type) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2138 | SetRawInputAt(0, object); |
| 2139 | SetRawInputAt(1, value); |
| 2140 | } |
| 2141 | |
| 2142 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2143 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2144 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2145 | HInstruction* GetValue() const { return InputAt(1); } |
| 2146 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2147 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 2148 | |
| 2149 | private: |
| 2150 | const FieldInfo field_info_; |
| 2151 | |
| 2152 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 2153 | }; |
| 2154 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2155 | class HArrayGet : public HExpression<2> { |
| 2156 | public: |
| 2157 | HArrayGet(HInstruction* array, HInstruction* index, Primitive::Type type) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2158 | : HExpression(type, SideEffects::DependsOnSomething()) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2159 | SetRawInputAt(0, array); |
| 2160 | SetRawInputAt(1, index); |
| 2161 | } |
| 2162 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2163 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2164 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2165 | UNUSED(other); |
| 2166 | return true; |
| 2167 | } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2168 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2169 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2170 | HInstruction* GetArray() const { return InputAt(0); } |
| 2171 | HInstruction* GetIndex() const { return InputAt(1); } |
| 2172 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2173 | DECLARE_INSTRUCTION(ArrayGet); |
| 2174 | |
| 2175 | private: |
| 2176 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 2177 | }; |
| 2178 | |
| 2179 | class HArraySet : public HTemplateInstruction<3> { |
| 2180 | public: |
| 2181 | HArraySet(HInstruction* array, |
| 2182 | HInstruction* index, |
| 2183 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2184 | Primitive::Type expected_component_type, |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2185 | uint32_t dex_pc) |
| 2186 | : HTemplateInstruction(SideEffects::ChangesSomething()), |
| 2187 | dex_pc_(dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2188 | expected_component_type_(expected_component_type), |
| 2189 | needs_type_check_(value->GetType() == Primitive::kPrimNot) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2190 | SetRawInputAt(0, array); |
| 2191 | SetRawInputAt(1, index); |
| 2192 | SetRawInputAt(2, value); |
| 2193 | } |
| 2194 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2195 | bool NeedsEnvironment() const { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2196 | // We currently always call a runtime method to catch array store |
| 2197 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2198 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2199 | } |
| 2200 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2201 | void ClearNeedsTypeCheck() { |
| 2202 | needs_type_check_ = false; |
| 2203 | } |
| 2204 | |
| 2205 | bool NeedsTypeCheck() const { return needs_type_check_; } |
| 2206 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2207 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2208 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2209 | HInstruction* GetArray() const { return InputAt(0); } |
| 2210 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2211 | HInstruction* GetValue() const { return InputAt(2); } |
| 2212 | |
| 2213 | Primitive::Type GetComponentType() const { |
| 2214 | // The Dex format does not type floating point index operations. Since the |
| 2215 | // `expected_component_type_` is set during building and can therefore not |
| 2216 | // be correct, we also check what is the value type. If it is a floating |
| 2217 | // point type, we must use that type. |
| 2218 | Primitive::Type value_type = GetValue()->GetType(); |
| 2219 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 2220 | ? value_type |
| 2221 | : expected_component_type_; |
| 2222 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2223 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2224 | DECLARE_INSTRUCTION(ArraySet); |
| 2225 | |
| 2226 | private: |
| 2227 | const uint32_t dex_pc_; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2228 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2229 | bool needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2230 | |
| 2231 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 2232 | }; |
| 2233 | |
| 2234 | class HArrayLength : public HExpression<1> { |
| 2235 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2236 | explicit HArrayLength(HInstruction* array) |
| 2237 | : HExpression(Primitive::kPrimInt, SideEffects::None()) { |
| 2238 | // Note that arrays do not change length, so the instruction does not |
| 2239 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2240 | SetRawInputAt(0, array); |
| 2241 | } |
| 2242 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2243 | virtual bool CanBeMoved() const { return true; } |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2244 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 2245 | UNUSED(other); |
| 2246 | return true; |
| 2247 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2248 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2249 | DECLARE_INSTRUCTION(ArrayLength); |
| 2250 | |
| 2251 | private: |
| 2252 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 2253 | }; |
| 2254 | |
| 2255 | class HBoundsCheck : public HExpression<2> { |
| 2256 | public: |
| 2257 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2258 | : HExpression(index->GetType(), SideEffects::None()), dex_pc_(dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2259 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 2260 | SetRawInputAt(0, index); |
| 2261 | SetRawInputAt(1, length); |
| 2262 | } |
| 2263 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2264 | virtual bool CanBeMoved() const { return true; } |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2265 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 2266 | UNUSED(other); |
| 2267 | return true; |
| 2268 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2269 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2270 | virtual bool NeedsEnvironment() const { return true; } |
| 2271 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 2272 | virtual bool CanThrow() const { return true; } |
| 2273 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 2274 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2275 | |
| 2276 | DECLARE_INSTRUCTION(BoundsCheck); |
| 2277 | |
| 2278 | private: |
| 2279 | const uint32_t dex_pc_; |
| 2280 | |
| 2281 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 2282 | }; |
| 2283 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2284 | /** |
| 2285 | * Some DEX instructions are folded into multiple HInstructions that need |
| 2286 | * to stay live until the last HInstruction. This class |
| 2287 | * is used as a marker for the baseline compiler to ensure its preceding |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 2288 | * HInstruction stays live. `index` represents the stack location index of the |
| 2289 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2290 | */ |
| 2291 | class HTemporary : public HTemplateInstruction<0> { |
| 2292 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2293 | explicit HTemporary(size_t index) : HTemplateInstruction(SideEffects::None()), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2294 | |
| 2295 | size_t GetIndex() const { return index_; } |
| 2296 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 2297 | Primitive::Type GetType() const OVERRIDE { |
| 2298 | // The previous instruction is the one that will be stored in the temporary location. |
| 2299 | DCHECK(GetPrevious() != nullptr); |
| 2300 | return GetPrevious()->GetType(); |
| 2301 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 2302 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 2303 | DECLARE_INSTRUCTION(Temporary); |
| 2304 | |
| 2305 | private: |
| 2306 | const size_t index_; |
| 2307 | |
| 2308 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 2309 | }; |
| 2310 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2311 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 2312 | public: |
| 2313 | explicit HSuspendCheck(uint32_t dex_pc) |
Nicolas Geoffray | 9ebc72c | 2014-09-25 16:33:42 +0100 | [diff] [blame] | 2314 | : HTemplateInstruction(SideEffects::None()), dex_pc_(dex_pc) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 2315 | |
| 2316 | virtual bool NeedsEnvironment() const { |
| 2317 | return true; |
| 2318 | } |
| 2319 | |
| 2320 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2321 | |
| 2322 | DECLARE_INSTRUCTION(SuspendCheck); |
| 2323 | |
| 2324 | private: |
| 2325 | const uint32_t dex_pc_; |
| 2326 | |
| 2327 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 2328 | }; |
| 2329 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2330 | /** |
| 2331 | * Instruction to load a Class object. |
| 2332 | */ |
| 2333 | class HLoadClass : public HExpression<0> { |
| 2334 | public: |
| 2335 | HLoadClass(uint16_t type_index, |
| 2336 | bool is_referrers_class, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2337 | uint32_t dex_pc) |
| 2338 | : HExpression(Primitive::kPrimNot, SideEffects::None()), |
| 2339 | type_index_(type_index), |
| 2340 | is_referrers_class_(is_referrers_class), |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2341 | dex_pc_(dex_pc), |
| 2342 | generate_clinit_check_(false) {} |
| 2343 | |
| 2344 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2345 | |
| 2346 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2347 | return other->AsLoadClass()->type_index_ == type_index_; |
| 2348 | } |
| 2349 | |
| 2350 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 2351 | |
| 2352 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2353 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2354 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2355 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2356 | bool NeedsEnvironment() const OVERRIDE { |
| 2357 | // Will call runtime and load the class if the class is not loaded yet. |
| 2358 | // TODO: finer grain decision. |
| 2359 | return !is_referrers_class_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2360 | } |
| 2361 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2362 | bool MustGenerateClinitCheck() const { |
| 2363 | return generate_clinit_check_; |
| 2364 | } |
| 2365 | |
| 2366 | void SetMustGenerateClinitCheck() { |
| 2367 | generate_clinit_check_ = true; |
| 2368 | } |
| 2369 | |
| 2370 | bool CanCallRuntime() const { |
| 2371 | return MustGenerateClinitCheck() || !is_referrers_class_; |
| 2372 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2373 | |
| 2374 | DECLARE_INSTRUCTION(LoadClass); |
| 2375 | |
| 2376 | private: |
| 2377 | const uint16_t type_index_; |
| 2378 | const bool is_referrers_class_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2379 | const uint32_t dex_pc_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2380 | // Whether this instruction must generate the initialization check. |
| 2381 | // Used for code generation. |
| 2382 | bool generate_clinit_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2383 | |
| 2384 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 2385 | }; |
| 2386 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2387 | class HLoadString : public HExpression<0> { |
| 2388 | public: |
| 2389 | HLoadString(uint32_t string_index, uint32_t dex_pc) |
| 2390 | : HExpression(Primitive::kPrimNot, SideEffects::None()), |
| 2391 | string_index_(string_index), |
| 2392 | dex_pc_(dex_pc) {} |
| 2393 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2394 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2395 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 2396 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2397 | return other->AsLoadString()->string_index_ == string_index_; |
| 2398 | } |
| 2399 | |
| 2400 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 2401 | |
| 2402 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2403 | uint32_t GetStringIndex() const { return string_index_; } |
| 2404 | |
| 2405 | // TODO: Can we deopt or debug when we resolve a string? |
| 2406 | bool NeedsEnvironment() const OVERRIDE { return false; } |
| 2407 | |
| 2408 | DECLARE_INSTRUCTION(LoadString); |
| 2409 | |
| 2410 | private: |
| 2411 | const uint32_t string_index_; |
| 2412 | const uint32_t dex_pc_; |
| 2413 | |
| 2414 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 2415 | }; |
| 2416 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2417 | // TODO: Pass this check to HInvokeStatic nodes. |
| 2418 | /** |
| 2419 | * Performs an initialization check on its Class object input. |
| 2420 | */ |
| 2421 | class HClinitCheck : public HExpression<1> { |
| 2422 | public: |
| 2423 | explicit HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
| 2424 | : HExpression(Primitive::kPrimNot, SideEffects::All()), |
| 2425 | dex_pc_(dex_pc) { |
| 2426 | SetRawInputAt(0, constant); |
| 2427 | } |
| 2428 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 2429 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2430 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2431 | UNUSED(other); |
| 2432 | return true; |
| 2433 | } |
| 2434 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2435 | bool NeedsEnvironment() const OVERRIDE { |
| 2436 | // May call runtime to initialize the class. |
| 2437 | return true; |
| 2438 | } |
| 2439 | |
| 2440 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2441 | |
| 2442 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 2443 | |
| 2444 | DECLARE_INSTRUCTION(ClinitCheck); |
| 2445 | |
| 2446 | private: |
| 2447 | const uint32_t dex_pc_; |
| 2448 | |
| 2449 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 2450 | }; |
| 2451 | |
| 2452 | class HStaticFieldGet : public HExpression<1> { |
| 2453 | public: |
| 2454 | HStaticFieldGet(HInstruction* cls, |
| 2455 | Primitive::Type field_type, |
| 2456 | MemberOffset field_offset) |
| 2457 | : HExpression(field_type, SideEffects::DependsOnSomething()), |
| 2458 | field_info_(field_offset, field_type) { |
| 2459 | SetRawInputAt(0, cls); |
| 2460 | } |
| 2461 | |
| 2462 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2463 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2464 | size_t other_offset = other->AsStaticFieldGet()->GetFieldOffset().SizeValue(); |
| 2465 | return other_offset == GetFieldOffset().SizeValue(); |
| 2466 | } |
| 2467 | |
| 2468 | size_t ComputeHashCode() const OVERRIDE { |
| 2469 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 2470 | } |
| 2471 | |
| 2472 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 2473 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
| 2474 | |
| 2475 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 2476 | |
| 2477 | private: |
| 2478 | const FieldInfo field_info_; |
| 2479 | |
| 2480 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 2481 | }; |
| 2482 | |
| 2483 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 2484 | public: |
| 2485 | HStaticFieldSet(HInstruction* cls, |
| 2486 | HInstruction* value, |
| 2487 | Primitive::Type field_type, |
| 2488 | MemberOffset field_offset) |
| 2489 | : HTemplateInstruction(SideEffects::ChangesSomething()), |
| 2490 | field_info_(field_offset, field_type) { |
| 2491 | SetRawInputAt(0, cls); |
| 2492 | SetRawInputAt(1, value); |
| 2493 | } |
| 2494 | |
| 2495 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 2496 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
| 2497 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 2498 | HInstruction* GetValue() const { return InputAt(1); } |
| 2499 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 2500 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 2501 | |
| 2502 | private: |
| 2503 | const FieldInfo field_info_; |
| 2504 | |
| 2505 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 2506 | }; |
| 2507 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2508 | // Implement the move-exception DEX instruction. |
| 2509 | class HLoadException : public HExpression<0> { |
| 2510 | public: |
| 2511 | HLoadException() : HExpression(Primitive::kPrimNot, SideEffects::None()) {} |
| 2512 | |
| 2513 | DECLARE_INSTRUCTION(LoadException); |
| 2514 | |
| 2515 | private: |
| 2516 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 2517 | }; |
| 2518 | |
| 2519 | class HThrow : public HTemplateInstruction<1> { |
| 2520 | public: |
| 2521 | HThrow(HInstruction* exception, uint32_t dex_pc) |
| 2522 | : HTemplateInstruction(SideEffects::None()), dex_pc_(dex_pc) { |
| 2523 | SetRawInputAt(0, exception); |
| 2524 | } |
| 2525 | |
| 2526 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2527 | |
| 2528 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2529 | |
| 2530 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2531 | |
| 2532 | DECLARE_INSTRUCTION(Throw); |
| 2533 | |
| 2534 | private: |
| 2535 | uint32_t dex_pc_; |
| 2536 | |
| 2537 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 2538 | }; |
| 2539 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2540 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2541 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2542 | HInstanceOf(HInstruction* object, |
| 2543 | HLoadClass* constant, |
| 2544 | bool class_is_final, |
| 2545 | uint32_t dex_pc) |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2546 | : HExpression(Primitive::kPrimBoolean, SideEffects::None()), |
| 2547 | class_is_final_(class_is_final), |
| 2548 | dex_pc_(dex_pc) { |
| 2549 | SetRawInputAt(0, object); |
| 2550 | SetRawInputAt(1, constant); |
| 2551 | } |
| 2552 | |
| 2553 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2554 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2555 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2556 | return true; |
| 2557 | } |
| 2558 | |
| 2559 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2560 | return false; |
| 2561 | } |
| 2562 | |
| 2563 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2564 | |
| 2565 | bool IsClassFinal() const { return class_is_final_; } |
| 2566 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2567 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2568 | |
| 2569 | private: |
| 2570 | const bool class_is_final_; |
| 2571 | const uint32_t dex_pc_; |
| 2572 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 2573 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 2574 | }; |
| 2575 | |
| 2576 | class HCheckCast : public HTemplateInstruction<2> { |
| 2577 | public: |
| 2578 | HCheckCast(HInstruction* object, |
| 2579 | HLoadClass* constant, |
| 2580 | bool class_is_final, |
| 2581 | uint32_t dex_pc) |
| 2582 | : HTemplateInstruction(SideEffects::None()), |
| 2583 | class_is_final_(class_is_final), |
| 2584 | dex_pc_(dex_pc) { |
| 2585 | SetRawInputAt(0, object); |
| 2586 | SetRawInputAt(1, constant); |
| 2587 | } |
| 2588 | |
| 2589 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2590 | |
| 2591 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2592 | return true; |
| 2593 | } |
| 2594 | |
| 2595 | bool NeedsEnvironment() const OVERRIDE { |
| 2596 | // Instruction may throw a CheckCastError. |
| 2597 | return true; |
| 2598 | } |
| 2599 | |
| 2600 | bool CanThrow() const OVERRIDE { return true; } |
| 2601 | |
| 2602 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2603 | |
| 2604 | bool IsClassFinal() const { return class_is_final_; } |
| 2605 | |
| 2606 | DECLARE_INSTRUCTION(CheckCast); |
| 2607 | |
| 2608 | private: |
| 2609 | const bool class_is_final_; |
| 2610 | const uint32_t dex_pc_; |
| 2611 | |
| 2612 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2613 | }; |
| 2614 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 2615 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 2616 | public: |
| 2617 | enum OperationKind { |
| 2618 | kEnter, |
| 2619 | kExit, |
| 2620 | }; |
| 2621 | |
| 2622 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
| 2623 | : HTemplateInstruction(SideEffects::None()), kind_(kind), dex_pc_(dex_pc) { |
| 2624 | SetRawInputAt(0, object); |
| 2625 | } |
| 2626 | |
| 2627 | // Instruction may throw a Java exception, so we need an environment. |
| 2628 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2629 | bool CanThrow() const OVERRIDE { return true; } |
| 2630 | |
| 2631 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2632 | |
| 2633 | bool IsEnter() const { return kind_ == kEnter; } |
| 2634 | |
| 2635 | DECLARE_INSTRUCTION(MonitorOperation); |
| 2636 | |
| 2637 | protected: |
| 2638 | const OperationKind kind_; |
| 2639 | const uint32_t dex_pc_; |
| 2640 | |
| 2641 | private: |
| 2642 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 2643 | }; |
| 2644 | |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 2645 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2646 | class MoveOperands : public ArenaObject<kArenaAllocMisc> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2647 | public: |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 2648 | MoveOperands(Location source, Location destination, HInstruction* instruction) |
| 2649 | : source_(source), destination_(destination), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2650 | |
| 2651 | Location GetSource() const { return source_; } |
| 2652 | Location GetDestination() const { return destination_; } |
| 2653 | |
| 2654 | void SetSource(Location value) { source_ = value; } |
| 2655 | void SetDestination(Location value) { destination_ = value; } |
| 2656 | |
| 2657 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 2658 | // destination (but not the source). |
| 2659 | Location MarkPending() { |
| 2660 | DCHECK(!IsPending()); |
| 2661 | Location dest = destination_; |
| 2662 | destination_ = Location::NoLocation(); |
| 2663 | return dest; |
| 2664 | } |
| 2665 | |
| 2666 | void ClearPending(Location dest) { |
| 2667 | DCHECK(IsPending()); |
| 2668 | destination_ = dest; |
| 2669 | } |
| 2670 | |
| 2671 | bool IsPending() const { |
| 2672 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 2673 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 2674 | } |
| 2675 | |
| 2676 | // True if this blocks a move from the given location. |
| 2677 | bool Blocks(Location loc) const { |
| 2678 | return !IsEliminated() && source_.Equals(loc); |
| 2679 | } |
| 2680 | |
| 2681 | // A move is redundant if it's been eliminated, if its source and |
| 2682 | // destination are the same, or if its destination is unneeded. |
| 2683 | bool IsRedundant() const { |
| 2684 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 2685 | } |
| 2686 | |
| 2687 | // We clear both operands to indicate move that's been eliminated. |
| 2688 | void Eliminate() { |
| 2689 | source_ = destination_ = Location::NoLocation(); |
| 2690 | } |
| 2691 | |
| 2692 | bool IsEliminated() const { |
| 2693 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 2694 | return source_.IsInvalid(); |
| 2695 | } |
| 2696 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 2697 | HInstruction* GetInstruction() const { return instruction_; } |
| 2698 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2699 | private: |
| 2700 | Location source_; |
| 2701 | Location destination_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 2702 | // The instruction this move is assocatied with. Null when this move is |
| 2703 | // for moving an input in the expected locations of user (including a phi user). |
| 2704 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 2705 | // in the same parallel move. |
| 2706 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2707 | |
| 2708 | DISALLOW_COPY_AND_ASSIGN(MoveOperands); |
| 2709 | }; |
| 2710 | |
| 2711 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 2712 | |
| 2713 | class HParallelMove : public HTemplateInstruction<0> { |
| 2714 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2715 | explicit HParallelMove(ArenaAllocator* arena) |
| 2716 | : HTemplateInstruction(SideEffects::None()), moves_(arena, kDefaultNumberOfMoves) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2717 | |
| 2718 | void AddMove(MoveOperands* move) { |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 2719 | if (kIsDebugBuild && move->GetInstruction() != nullptr) { |
| 2720 | for (size_t i = 0, e = moves_.Size(); i < e; ++i) { |
| 2721 | DCHECK_NE(moves_.Get(i)->GetInstruction(), move->GetInstruction()) |
| 2722 | << "Doing parallel moves for the same instruction."; |
| 2723 | } |
| 2724 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2725 | moves_.Add(move); |
| 2726 | } |
| 2727 | |
| 2728 | MoveOperands* MoveOperandsAt(size_t index) const { |
| 2729 | return moves_.Get(index); |
| 2730 | } |
| 2731 | |
| 2732 | size_t NumMoves() const { return moves_.Size(); } |
| 2733 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2734 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 2735 | |
| 2736 | private: |
| 2737 | GrowableArray<MoveOperands*> moves_; |
| 2738 | |
| 2739 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 2740 | }; |
| 2741 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2742 | class HGraphVisitor : public ValueObject { |
| 2743 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2744 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 2745 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2746 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2747 | virtual void VisitInstruction(HInstruction* instruction) { UNUSED(instruction); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2748 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 2749 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 2750 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2751 | void VisitInsertionOrder(); |
| 2752 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 2753 | // Visit the graph following dominator tree reverse post-order. |
| 2754 | void VisitReversePostOrder(); |
| 2755 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2756 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2757 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2758 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2759 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2760 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 2761 | |
| 2762 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 2763 | |
| 2764 | #undef DECLARE_VISIT_INSTRUCTION |
| 2765 | |
| 2766 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 2767 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2768 | |
| 2769 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 2770 | }; |
| 2771 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2772 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 2773 | public: |
| 2774 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 2775 | virtual ~HGraphDelegateVisitor() {} |
| 2776 | |
| 2777 | // Visit functions that delegate to to super class. |
| 2778 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| 2779 | virtual void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
| 2780 | |
| 2781 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 2782 | |
| 2783 | #undef DECLARE_VISIT_INSTRUCTION |
| 2784 | |
| 2785 | private: |
| 2786 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 2787 | }; |
| 2788 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2789 | class HInsertionOrderIterator : public ValueObject { |
| 2790 | public: |
| 2791 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 2792 | |
| 2793 | bool Done() const { return index_ == graph_.GetBlocks().Size(); } |
| 2794 | HBasicBlock* Current() const { return graph_.GetBlocks().Get(index_); } |
| 2795 | void Advance() { ++index_; } |
| 2796 | |
| 2797 | private: |
| 2798 | const HGraph& graph_; |
| 2799 | size_t index_; |
| 2800 | |
| 2801 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 2802 | }; |
| 2803 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 2804 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2805 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 2806 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2807 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 2808 | bool Done() const { return index_ == graph_.GetReversePostOrder().Size(); } |
| 2809 | HBasicBlock* Current() const { return graph_.GetReversePostOrder().Get(index_); } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2810 | void Advance() { ++index_; } |
| 2811 | |
| 2812 | private: |
| 2813 | const HGraph& graph_; |
| 2814 | size_t index_; |
| 2815 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 2816 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2817 | }; |
| 2818 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 2819 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2820 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 2821 | explicit HPostOrderIterator(const HGraph& graph) |
| 2822 | : graph_(graph), index_(graph_.GetReversePostOrder().Size()) {} |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2823 | |
| 2824 | bool Done() const { return index_ == 0; } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 2825 | HBasicBlock* Current() const { return graph_.GetReversePostOrder().Get(index_ - 1); } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2826 | void Advance() { --index_; } |
| 2827 | |
| 2828 | private: |
| 2829 | const HGraph& graph_; |
| 2830 | size_t index_; |
| 2831 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 2832 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2833 | }; |
| 2834 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2835 | } // namespace art |
| 2836 | |
| 2837 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |