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