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