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