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