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