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