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 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 24 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 25 | #include "base/arena_object.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 26 | #include "base/stl_util.h" |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 27 | #include "dex/compiler_enums.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 29 | #include "handle.h" |
| 30 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 31 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 32 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 33 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 34 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 35 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 36 | #include "primitive.h" |
Nicolas Geoffray | 0e33643 | 2014-02-26 18:24:38 +0000 | [diff] [blame] | 37 | #include "utils/arena_bit_vector.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 38 | #include "utils/growable_array.h" |
| 39 | |
| 40 | namespace art { |
| 41 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 42 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 43 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 45 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 46 | class HEnvironment; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 47 | class HFakeString; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 48 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 49 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 51 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 52 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 53 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 55 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 56 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 57 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 58 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 59 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 60 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 61 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 62 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 63 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 64 | namespace mirror { |
| 65 | class DexCache; |
| 66 | } // namespace mirror |
| 67 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 68 | static const int kDefaultNumberOfBlocks = 8; |
| 69 | static const int kDefaultNumberOfSuccessors = 2; |
| 70 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 72 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 73 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 74 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 75 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 76 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 77 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 78 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
| 79 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 80 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 81 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 82 | static constexpr uint32_t kNoDexPc = -1; |
| 83 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 84 | enum IfCondition { |
| 85 | kCondEQ, |
| 86 | kCondNE, |
| 87 | kCondLT, |
| 88 | kCondLE, |
| 89 | kCondGT, |
| 90 | kCondGE, |
| 91 | }; |
| 92 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 93 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 94 | public: |
| 95 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 96 | |
| 97 | void AddInstruction(HInstruction* instruction); |
| 98 | void RemoveInstruction(HInstruction* instruction); |
| 99 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 100 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 101 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 102 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 103 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 104 | // Return true if this list contains `instruction`. |
| 105 | bool Contains(HInstruction* instruction) const; |
| 106 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 107 | // Return true if `instruction1` is found before `instruction2` in |
| 108 | // this instruction list and false otherwise. Abort if none |
| 109 | // of these instructions is found. |
| 110 | bool FoundBefore(const HInstruction* instruction1, |
| 111 | const HInstruction* instruction2) const; |
| 112 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 113 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 114 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 115 | |
| 116 | // Update the block of all instructions to be `block`. |
| 117 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 118 | |
| 119 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 120 | void Add(const HInstructionList& instruction_list); |
| 121 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 122 | // Return the number of instructions in the list. This is an expensive operation. |
| 123 | size_t CountSize() const; |
| 124 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 125 | private: |
| 126 | HInstruction* first_instruction_; |
| 127 | HInstruction* last_instruction_; |
| 128 | |
| 129 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 130 | friend class HGraph; |
| 131 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 132 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 133 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 134 | |
| 135 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 136 | }; |
| 137 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 138 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 139 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 140 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 141 | HGraph(ArenaAllocator* arena, |
| 142 | const DexFile& dex_file, |
| 143 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 144 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 145 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 146 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 147 | bool debuggable = false, |
| 148 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 149 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 150 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 151 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 152 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 153 | entry_block_(nullptr), |
| 154 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 155 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 156 | number_of_vregs_(0), |
| 157 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 158 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 159 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 160 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 161 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 162 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 163 | dex_file_(dex_file), |
| 164 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 165 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 166 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 167 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 168 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 169 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 170 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 171 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 172 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 173 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 174 | cached_current_method_(nullptr) { |
| 175 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 176 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 177 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 178 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 179 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 180 | |
| 181 | HBasicBlock* GetBlock(size_t id) const { |
| 182 | DCHECK_LT(id, blocks_.size()); |
| 183 | return blocks_[id]; |
| 184 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 185 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 186 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 187 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 188 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 189 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 190 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 191 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 192 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 193 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 194 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 195 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 196 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 197 | // Try building the SSA form of this graph, with dominance computation and loop |
| 198 | // recognition. Returns whether it was successful in doing all these steps. |
| 199 | bool TryBuildingSsa() { |
| 200 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 201 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 202 | // elimination phase checks the consistency of the graph when doing a post-order |
| 203 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 204 | // users remaining when being visited. |
| 205 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 206 | // Precompute per-block try membership before entering the SSA builder, |
| 207 | // which needs the information to build catch block phis from values of |
| 208 | // locals at throwing instructions inside try blocks. |
| 209 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 210 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 211 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 212 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 215 | void ComputeDominanceInformation(); |
| 216 | void ClearDominanceInformation(); |
| 217 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 218 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 219 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 220 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 221 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 222 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 223 | // Analyze all natural loops in this graph. Returns false if one |
| 224 | // loop is not natural, that is the header does not dominate the |
| 225 | // back edge. |
| 226 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 227 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 228 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 229 | // order and loop information. |
| 230 | void ComputeTryBlockInformation(); |
| 231 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 232 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 233 | // Returns the instruction used to replace the invoke expression or null if the |
| 234 | // invoke is for a void method. |
| 235 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 236 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 237 | // Need to add a couple of blocks to test if the loop body is entered and |
| 238 | // put deoptimization instructions, etc. |
| 239 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 240 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 241 | // Removes `block` from the graph. |
| 242 | void DeleteDeadBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 243 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 244 | // Splits the edge between `block` and `successor` while preserving the |
| 245 | // indices in the predecessor/successor lists. If there are multiple edges |
| 246 | // between the blocks, the lowest indices are used. |
| 247 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 248 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 249 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 250 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 251 | void SimplifyLoop(HBasicBlock* header); |
| 252 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 253 | int32_t GetNextInstructionId() { |
| 254 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 255 | return current_instruction_id_++; |
| 256 | } |
| 257 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 258 | int32_t GetCurrentInstructionId() const { |
| 259 | return current_instruction_id_; |
| 260 | } |
| 261 | |
| 262 | void SetCurrentInstructionId(int32_t id) { |
| 263 | current_instruction_id_ = id; |
| 264 | } |
| 265 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 266 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 267 | return maximum_number_of_out_vregs_; |
| 268 | } |
| 269 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 270 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 271 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 274 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 275 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 276 | } |
| 277 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 278 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 279 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 282 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 283 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 284 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 287 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 288 | number_of_vregs_ = number_of_vregs; |
| 289 | } |
| 290 | |
| 291 | uint16_t GetNumberOfVRegs() const { |
| 292 | return number_of_vregs_; |
| 293 | } |
| 294 | |
| 295 | void SetNumberOfInVRegs(uint16_t value) { |
| 296 | number_of_in_vregs_ = value; |
| 297 | } |
| 298 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 299 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 300 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 301 | return number_of_vregs_ - number_of_in_vregs_; |
| 302 | } |
| 303 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 304 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 305 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 306 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 307 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 308 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 309 | return linear_order_; |
| 310 | } |
| 311 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 312 | bool HasBoundsChecks() const { |
| 313 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 316 | void SetHasBoundsChecks(bool value) { |
| 317 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 320 | bool ShouldGenerateConstructorBarrier() const { |
| 321 | return should_generate_constructor_barrier_; |
| 322 | } |
| 323 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 324 | bool IsDebuggable() const { return debuggable_; } |
| 325 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 326 | // 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] | 327 | // already, it is created and inserted into the graph. This method is only for |
| 328 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 329 | HConstant* GetConstant(Primitive::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 330 | |
| 331 | // TODO: This is problematic for the consistency of reference type propagation |
| 332 | // because it can be created anytime after the pass and thus it will be left |
| 333 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 334 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 335 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 336 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 337 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 338 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 339 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 340 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 341 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 342 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 343 | return CreateConstant(bit_cast<int32_t, float>(value), &cached_float_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 344 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 345 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 346 | return CreateConstant(bit_cast<int64_t, double>(value), &cached_double_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 347 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 348 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 349 | HCurrentMethod* GetCurrentMethod(); |
| 350 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 351 | HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const; |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 352 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 353 | const DexFile& GetDexFile() const { |
| 354 | return dex_file_; |
| 355 | } |
| 356 | |
| 357 | uint32_t GetMethodIdx() const { |
| 358 | return method_idx_; |
| 359 | } |
| 360 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 361 | InvokeType GetInvokeType() const { |
| 362 | return invoke_type_; |
| 363 | } |
| 364 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 365 | InstructionSet GetInstructionSet() const { |
| 366 | return instruction_set_; |
| 367 | } |
| 368 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 369 | bool HasTryCatch() const { return has_try_catch_; } |
| 370 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 371 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 372 | private: |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 373 | void VisitBlockForDominatorTree(HBasicBlock* block, |
| 374 | HBasicBlock* predecessor, |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 375 | ArenaVector<size_t>* visits); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 376 | void FindBackEdges(ArenaBitVector* visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 377 | void VisitBlockForBackEdges(HBasicBlock* block, |
| 378 | ArenaBitVector* visited, |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 379 | ArenaBitVector* visiting); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 380 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 381 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 382 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 383 | template <class InstructionType, typename ValueType> |
| 384 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 385 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 386 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 387 | // Try to find an existing constant of the given value. |
| 388 | InstructionType* constant = nullptr; |
| 389 | auto cached_constant = cache->find(value); |
| 390 | if (cached_constant != cache->end()) { |
| 391 | constant = cached_constant->second; |
| 392 | } |
| 393 | |
| 394 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 395 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 396 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 397 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 398 | cache->Overwrite(value, constant); |
| 399 | InsertConstant(constant); |
| 400 | } |
| 401 | return constant; |
| 402 | } |
| 403 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 404 | void InsertConstant(HConstant* instruction); |
| 405 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 406 | // Cache a float constant into the graph. This method should only be |
| 407 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 408 | void CacheFloatConstant(HFloatConstant* constant); |
| 409 | |
| 410 | // See CacheFloatConstant comment. |
| 411 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 412 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 413 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 414 | |
| 415 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 416 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 417 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 418 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 419 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 420 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 421 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 422 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 423 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 424 | HBasicBlock* entry_block_; |
| 425 | HBasicBlock* exit_block_; |
| 426 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 427 | // 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] | 428 | uint16_t maximum_number_of_out_vregs_; |
| 429 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 430 | // The number of virtual registers in this method. Contains the parameters. |
| 431 | uint16_t number_of_vregs_; |
| 432 | |
| 433 | // The number of virtual registers used by parameters of this method. |
| 434 | uint16_t number_of_in_vregs_; |
| 435 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 436 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 437 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 438 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 439 | // Has bounds checks. We can totally skip BCE if it's false. |
| 440 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 441 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 442 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 443 | // try/catch-related passes if false. |
| 444 | bool has_try_catch_; |
| 445 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 446 | // Indicates whether the graph should be compiled in a way that |
| 447 | // ensures full debuggability. If false, we can apply more |
| 448 | // aggressive optimizations that may limit the level of debugging. |
| 449 | const bool debuggable_; |
| 450 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 451 | // 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] | 452 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 453 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 454 | // The dex file from which the method is from. |
| 455 | const DexFile& dex_file_; |
| 456 | |
| 457 | // The method index in the dex file. |
| 458 | const uint32_t method_idx_; |
| 459 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 460 | // If inlined, this encodes how the callee is being invoked. |
| 461 | const InvokeType invoke_type_; |
| 462 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 463 | // Whether the graph has been transformed to SSA form. Only used |
| 464 | // in debug mode to ensure we are not using properties only valid |
| 465 | // for non-SSA form (like the number of temporaries). |
| 466 | bool in_ssa_form_; |
| 467 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 468 | const bool should_generate_constructor_barrier_; |
| 469 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 470 | const InstructionSet instruction_set_; |
| 471 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 472 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 473 | HNullConstant* cached_null_constant_; |
| 474 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 475 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 476 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 477 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 478 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 479 | HCurrentMethod* cached_current_method_; |
| 480 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 481 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 482 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 483 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 484 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 485 | }; |
| 486 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 487 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 488 | public: |
| 489 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 490 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 491 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 492 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 493 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 494 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 495 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 496 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 497 | |
| 498 | HBasicBlock* GetHeader() const { |
| 499 | return header_; |
| 500 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 501 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 502 | void SetHeader(HBasicBlock* block) { |
| 503 | header_ = block; |
| 504 | } |
| 505 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 506 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 507 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 508 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 509 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 510 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 511 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 514 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 515 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 516 | } |
| 517 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 518 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 519 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 520 | } |
| 521 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 522 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 523 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 526 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 527 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 528 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 529 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 532 | // Returns the lifetime position of the back edge that has the |
| 533 | // greatest lifetime position. |
| 534 | size_t GetLifetimeEnd() const; |
| 535 | |
| 536 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 537 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 538 | } |
| 539 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 540 | // 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] | 541 | // that is the header dominates the back edge. |
| 542 | bool Populate(); |
| 543 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 544 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 545 | // Populate(). If there are no back edges left, the loop info is completely |
| 546 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 547 | // inner loops first. |
| 548 | void Update(); |
| 549 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 550 | // Returns whether this loop information contains `block`. |
| 551 | // Note that this loop information *must* be populated before entering this function. |
| 552 | bool Contains(const HBasicBlock& block) const; |
| 553 | |
| 554 | // Returns whether this loop information is an inner loop of `other`. |
| 555 | // Note that `other` *must* be populated before entering this function. |
| 556 | bool IsIn(const HLoopInformation& other) const; |
| 557 | |
| 558 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 559 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 560 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 561 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 562 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 563 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 564 | // Internal recursive implementation of `Populate`. |
| 565 | void PopulateRecursive(HBasicBlock* block); |
| 566 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 567 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 568 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 569 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 570 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 571 | |
| 572 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 573 | }; |
| 574 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 575 | // Stores try/catch information for basic blocks. |
| 576 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 577 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 578 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 579 | public: |
| 580 | // Try block information constructor. |
| 581 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 582 | : try_entry_(&try_entry), |
| 583 | catch_dex_file_(nullptr), |
| 584 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 585 | DCHECK(try_entry_ != nullptr); |
| 586 | } |
| 587 | |
| 588 | // Catch block information constructor. |
| 589 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 590 | : try_entry_(nullptr), |
| 591 | catch_dex_file_(&dex_file), |
| 592 | catch_type_index_(catch_type_index) {} |
| 593 | |
| 594 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 595 | |
| 596 | const HTryBoundary& GetTryEntry() const { |
| 597 | DCHECK(IsTryBlock()); |
| 598 | return *try_entry_; |
| 599 | } |
| 600 | |
| 601 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 602 | |
| 603 | bool IsCatchAllTypeIndex() const { |
| 604 | DCHECK(IsCatchBlock()); |
| 605 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 606 | } |
| 607 | |
| 608 | uint16_t GetCatchTypeIndex() const { |
| 609 | DCHECK(IsCatchBlock()); |
| 610 | return catch_type_index_; |
| 611 | } |
| 612 | |
| 613 | const DexFile& GetCatchDexFile() const { |
| 614 | DCHECK(IsCatchBlock()); |
| 615 | return *catch_dex_file_; |
| 616 | } |
| 617 | |
| 618 | private: |
| 619 | // One of possibly several TryBoundary instructions entering the block's try. |
| 620 | // Only set for try blocks. |
| 621 | const HTryBoundary* try_entry_; |
| 622 | |
| 623 | // Exception type information. Only set for catch blocks. |
| 624 | const DexFile* catch_dex_file_; |
| 625 | const uint16_t catch_type_index_; |
| 626 | }; |
| 627 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 628 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 629 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 630 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 631 | // A block in a method. Contains the list of instructions represented |
| 632 | // as a double linked list. Each block knows its predecessors and |
| 633 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 634 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 635 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 636 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 637 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 638 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 639 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 640 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 641 | loop_information_(nullptr), |
| 642 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 643 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 644 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 645 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 646 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 647 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 648 | try_catch_information_(nullptr) { |
| 649 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 650 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 651 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 652 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 653 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 654 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 655 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 658 | HBasicBlock* GetPredecessor(size_t pred_idx) const { |
| 659 | DCHECK_LT(pred_idx, predecessors_.size()); |
| 660 | return predecessors_[pred_idx]; |
| 661 | } |
| 662 | |
| 663 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 664 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 667 | HBasicBlock* GetSuccessor(size_t succ_idx) const { |
| 668 | DCHECK_LT(succ_idx, successors_.size()); |
| 669 | return successors_[succ_idx]; |
| 670 | } |
| 671 | |
| 672 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 673 | return ContainsElement(successors_, block, start_from); |
| 674 | } |
| 675 | |
| 676 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 677 | return dominated_blocks_; |
| 678 | } |
| 679 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 680 | bool IsEntryBlock() const { |
| 681 | return graph_->GetEntryBlock() == this; |
| 682 | } |
| 683 | |
| 684 | bool IsExitBlock() const { |
| 685 | return graph_->GetExitBlock() == this; |
| 686 | } |
| 687 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 688 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 689 | bool IsSingleTryBoundary() const; |
| 690 | |
| 691 | // Returns true if this block emits nothing but a jump. |
| 692 | bool IsSingleJump() const { |
| 693 | HLoopInformation* loop_info = GetLoopInformation(); |
| 694 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 695 | // Back edges generate a suspend check. |
| 696 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 697 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 698 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 699 | void AddBackEdge(HBasicBlock* back_edge) { |
| 700 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 701 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 702 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 703 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 704 | loop_information_->AddBackEdge(back_edge); |
| 705 | } |
| 706 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 707 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 708 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 709 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 710 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 711 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 712 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 713 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 714 | HBasicBlock* GetDominator() const { return dominator_; } |
| 715 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 716 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 717 | |
| 718 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 719 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 720 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 721 | |
| 722 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 723 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 724 | } |
| 725 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 726 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 727 | |
| 728 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 729 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 732 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 733 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 734 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 735 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 736 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 737 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 738 | |
| 739 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 740 | successors_.push_back(block); |
| 741 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 744 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 745 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 746 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 747 | new_block->predecessors_.push_back(this); |
| 748 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 751 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 752 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 753 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 754 | new_block->successors_.push_back(this); |
| 755 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 758 | // Insert `this` between `predecessor` and `successor. This method |
| 759 | // preserves the indicies, and will update the first edge found between |
| 760 | // `predecessor` and `successor`. |
| 761 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 762 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 763 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 764 | successor->predecessors_[predecessor_index] = this; |
| 765 | predecessor->successors_[successor_index] = this; |
| 766 | successors_.push_back(successor); |
| 767 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 768 | } |
| 769 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 770 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 771 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 772 | } |
| 773 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 774 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 775 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 778 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 779 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 783 | predecessors_.push_back(block); |
| 784 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 785 | } |
| 786 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 787 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 788 | DCHECK_EQ(predecessors_.size(), 2u); |
| 789 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 790 | } |
| 791 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 792 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 793 | DCHECK_EQ(successors_.size(), 2u); |
| 794 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 795 | } |
| 796 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 797 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 798 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 799 | } |
| 800 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 801 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 802 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 803 | } |
| 804 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 805 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 806 | DCHECK_EQ(GetPredecessors().size(), 1u); |
| 807 | return GetPredecessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | DCHECK_EQ(GetSuccessors().size(), 1u); |
| 812 | return GetSuccessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Returns whether the first occurrence of `predecessor` in the list of |
| 816 | // predecessors is at index `idx`. |
| 817 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 818 | DCHECK_EQ(GetPredecessor(idx), predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 819 | return GetPredecessorIndexOf(predecessor) == idx; |
| 820 | } |
| 821 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 822 | // Returns the number of non-exceptional successors. SsaChecker ensures that |
| 823 | // these are stored at the beginning of the successor list. |
| 824 | size_t NumberOfNormalSuccessors() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 825 | return EndsWithTryBoundary() ? 1 : GetSuccessors().size(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 826 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 827 | |
| 828 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 829 | // created, latter block. Note that this method will add the block to the |
| 830 | // graph, create a Goto at the end of the former block and will create an edge |
| 831 | // between the blocks. It will not, however, update the reverse post order or |
| 832 | // loop information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 833 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 834 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 835 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 836 | // created block. Note that this method just updates raw block information, |
| 837 | // like predecessors, successors, dominators, and instruction list. It does not |
| 838 | // update the graph, reverse post order, loop information, nor make sure the |
| 839 | // blocks are consistent (for example ending with a control flow instruction). |
| 840 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 841 | |
| 842 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 843 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 844 | // that this method does not update the graph, reverse post order, loop |
| 845 | // information, nor make sure the blocks are consistent (for example ending |
| 846 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 847 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 848 | |
| 849 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 850 | // of `this` are moved to `other`. |
| 851 | // Note that this method does not update the graph, reverse post order, loop |
| 852 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 853 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 854 | void ReplaceWith(HBasicBlock* other); |
| 855 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 856 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 857 | // order, links to predecessors, successors, dominators and deletes the block |
| 858 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 859 | // predecessor of `other` and vice versa. |
| 860 | void MergeWith(HBasicBlock* other); |
| 861 | |
| 862 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 863 | // removes it from all loops it is included in and eventually from the graph. |
| 864 | // The block must not dominate any other block. Predecessors and successors |
| 865 | // are safely updated. |
| 866 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 867 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 868 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 869 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 870 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 871 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 872 | // Replace instruction `initial` with `replacement` within this block. |
| 873 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 874 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 875 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 876 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 877 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 878 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 879 | // instruction is not in use and removes it from the use lists of its inputs. |
| 880 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 881 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 882 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 883 | |
| 884 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 885 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 886 | } |
| 887 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 888 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 889 | DCHECK(IsLoopHeader()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 890 | return GetPredecessor(0) == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 891 | } |
| 892 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 893 | HLoopInformation* GetLoopInformation() const { |
| 894 | return loop_information_; |
| 895 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 896 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 897 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 898 | // 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] | 899 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 900 | void SetInLoop(HLoopInformation* info) { |
| 901 | if (IsLoopHeader()) { |
| 902 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 903 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 904 | loop_information_ = info; |
| 905 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 906 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 907 | // Note that a non loop header having a loop information means this loop information |
| 908 | // has already been populated |
| 909 | loop_information_ = info; |
| 910 | } else { |
| 911 | // Block is part of an inner loop. Do not update the loop information. |
| 912 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 913 | // at this point, because this method is being called while populating `info`. |
| 914 | } |
| 915 | } |
| 916 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 917 | // Raw update of the loop information. |
| 918 | void SetLoopInformation(HLoopInformation* info) { |
| 919 | loop_information_ = info; |
| 920 | } |
| 921 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 922 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 923 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 924 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 925 | |
| 926 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 927 | try_catch_information_ = try_catch_information; |
| 928 | } |
| 929 | |
| 930 | bool IsTryBlock() const { |
| 931 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 932 | } |
| 933 | |
| 934 | bool IsCatchBlock() const { |
| 935 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 936 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 937 | |
| 938 | // Returns the try entry that this block's successors should have. They will |
| 939 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 940 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 941 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 942 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 943 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 944 | bool Dominates(HBasicBlock* block) const; |
| 945 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 946 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 947 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 948 | |
| 949 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 950 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 951 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 952 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 953 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 954 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 955 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 956 | bool HasSinglePhi() const; |
| 957 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 958 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 959 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 960 | ArenaVector<HBasicBlock*> predecessors_; |
| 961 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 962 | HInstructionList instructions_; |
| 963 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 964 | HLoopInformation* loop_information_; |
| 965 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 966 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 967 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 968 | // The dex program counter of the first instruction of this block. |
| 969 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 970 | size_t lifetime_start_; |
| 971 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 972 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 973 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 974 | friend class HGraph; |
| 975 | friend class HInstruction; |
| 976 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 977 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 978 | }; |
| 979 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 980 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 981 | // from the innermost to the outermost. |
| 982 | class HLoopInformationOutwardIterator : public ValueObject { |
| 983 | public: |
| 984 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 985 | : current_(block.GetLoopInformation()) {} |
| 986 | |
| 987 | bool Done() const { return current_ == nullptr; } |
| 988 | |
| 989 | void Advance() { |
| 990 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 991 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | HLoopInformation* Current() const { |
| 995 | DCHECK(!Done()); |
| 996 | return current_; |
| 997 | } |
| 998 | |
| 999 | private: |
| 1000 | HLoopInformation* current_; |
| 1001 | |
| 1002 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1003 | }; |
| 1004 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1005 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1006 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1007 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1008 | M(ArrayGet, Instruction) \ |
| 1009 | M(ArrayLength, Instruction) \ |
| 1010 | M(ArraySet, Instruction) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1011 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1012 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1013 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1014 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1015 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1016 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1017 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1018 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1019 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1020 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1021 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1022 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1023 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1024 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1025 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1026 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1027 | M(FloatConstant, Constant) \ |
| 1028 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1029 | M(GreaterThan, Condition) \ |
| 1030 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1031 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1032 | M(InstanceFieldGet, Instruction) \ |
| 1033 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1034 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1035 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1036 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1037 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1038 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1039 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1040 | M(LessThan, Condition) \ |
| 1041 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1042 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1043 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1044 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1045 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1046 | M(Local, Instruction) \ |
| 1047 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1048 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1049 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1050 | M(Mul, BinaryOperation) \ |
| 1051 | M(Neg, UnaryOperation) \ |
| 1052 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1053 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1054 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1055 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1056 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1057 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1058 | M(Or, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1059 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1060 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1061 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1062 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1063 | M(Return, Instruction) \ |
| 1064 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1065 | M(Shl, BinaryOperation) \ |
| 1066 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1067 | M(StaticFieldGet, Instruction) \ |
| 1068 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | 23a8e35 | 2015-09-08 19:56:31 +0100 | [diff] [blame] | 1069 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1070 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1071 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1072 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1073 | M(StoreLocal, Instruction) \ |
| 1074 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1075 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1076 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1077 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1078 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1079 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1080 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1081 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1082 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1083 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1084 | |
| 1085 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1086 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1087 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1088 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1089 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1090 | M(X86ComputeBaseMethodAddress, Instruction) \ |
| 1091 | M(X86LoadFromConstantTable, Instruction) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1092 | |
| 1093 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1094 | |
| 1095 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1096 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1097 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1098 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1099 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1100 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1101 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1102 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1103 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1104 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1105 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1106 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1107 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1108 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1109 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1110 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1111 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1112 | #undef FORWARD_DECLARATION |
| 1113 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1114 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1115 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1116 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1117 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1118 | H##type* As##type() OVERRIDE { return this; } \ |
| 1119 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1120 | return other->Is##type(); \ |
| 1121 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1122 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1123 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1124 | template <typename T> class HUseList; |
| 1125 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1126 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1127 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1128 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1129 | HUseListNode* GetPrevious() const { return prev_; } |
| 1130 | HUseListNode* GetNext() const { return next_; } |
| 1131 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1132 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1133 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1134 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1135 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1136 | HUseListNode(T user, size_t index) |
| 1137 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1138 | |
| 1139 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1140 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1141 | HUseListNode<T>* prev_; |
| 1142 | HUseListNode<T>* next_; |
| 1143 | |
| 1144 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1145 | |
| 1146 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1147 | }; |
| 1148 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1149 | template <typename T> |
| 1150 | class HUseList : public ValueObject { |
| 1151 | public: |
| 1152 | HUseList() : first_(nullptr) {} |
| 1153 | |
| 1154 | void Clear() { |
| 1155 | first_ = nullptr; |
| 1156 | } |
| 1157 | |
| 1158 | // Adds a new entry at the beginning of the use list and returns |
| 1159 | // the newly created node. |
| 1160 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1161 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1162 | if (IsEmpty()) { |
| 1163 | first_ = new_node; |
| 1164 | } else { |
| 1165 | first_->prev_ = new_node; |
| 1166 | new_node->next_ = first_; |
| 1167 | first_ = new_node; |
| 1168 | } |
| 1169 | return new_node; |
| 1170 | } |
| 1171 | |
| 1172 | HUseListNode<T>* GetFirst() const { |
| 1173 | return first_; |
| 1174 | } |
| 1175 | |
| 1176 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1177 | DCHECK(node != nullptr); |
| 1178 | DCHECK(Contains(node)); |
| 1179 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1180 | if (node->prev_ != nullptr) { |
| 1181 | node->prev_->next_ = node->next_; |
| 1182 | } |
| 1183 | if (node->next_ != nullptr) { |
| 1184 | node->next_->prev_ = node->prev_; |
| 1185 | } |
| 1186 | if (node == first_) { |
| 1187 | first_ = node->next_; |
| 1188 | } |
| 1189 | } |
| 1190 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1191 | bool Contains(const HUseListNode<T>* node) const { |
| 1192 | if (node == nullptr) { |
| 1193 | return false; |
| 1194 | } |
| 1195 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1196 | if (current == node) { |
| 1197 | return true; |
| 1198 | } |
| 1199 | } |
| 1200 | return false; |
| 1201 | } |
| 1202 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1203 | bool IsEmpty() const { |
| 1204 | return first_ == nullptr; |
| 1205 | } |
| 1206 | |
| 1207 | bool HasOnlyOneUse() const { |
| 1208 | return first_ != nullptr && first_->next_ == nullptr; |
| 1209 | } |
| 1210 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1211 | size_t SizeSlow() const { |
| 1212 | size_t count = 0; |
| 1213 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1214 | ++count; |
| 1215 | } |
| 1216 | return count; |
| 1217 | } |
| 1218 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1219 | private: |
| 1220 | HUseListNode<T>* first_; |
| 1221 | }; |
| 1222 | |
| 1223 | template<typename T> |
| 1224 | class HUseIterator : public ValueObject { |
| 1225 | public: |
| 1226 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1227 | |
| 1228 | bool Done() const { return current_ == nullptr; } |
| 1229 | |
| 1230 | void Advance() { |
| 1231 | DCHECK(!Done()); |
| 1232 | current_ = current_->GetNext(); |
| 1233 | } |
| 1234 | |
| 1235 | HUseListNode<T>* Current() const { |
| 1236 | DCHECK(!Done()); |
| 1237 | return current_; |
| 1238 | } |
| 1239 | |
| 1240 | private: |
| 1241 | HUseListNode<T>* current_; |
| 1242 | |
| 1243 | friend class HValue; |
| 1244 | }; |
| 1245 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1246 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1247 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1248 | // by the used instructions. |
| 1249 | template <typename T> |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1250 | class HUserRecord { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1251 | public: |
| 1252 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1253 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1254 | |
| 1255 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1256 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1257 | DCHECK(instruction_ != nullptr); |
| 1258 | DCHECK(use_node_ != nullptr); |
| 1259 | DCHECK(old_record.use_node_ == nullptr); |
| 1260 | } |
| 1261 | |
| 1262 | HInstruction* GetInstruction() const { return instruction_; } |
| 1263 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1264 | |
| 1265 | private: |
| 1266 | // Instruction used by the user. |
| 1267 | HInstruction* instruction_; |
| 1268 | |
| 1269 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1270 | HUseListNode<T>* use_node_; |
| 1271 | }; |
| 1272 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1273 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1274 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1275 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1276 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1277 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1278 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1279 | * modify the value of a reference field read [although it may modify the |
| 1280 | * reference fetch prior to reading the field, which is represented by its own |
| 1281 | * write/read dependence]). The analysis makes conservative points-to |
| 1282 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1283 | * the same, and any reference read depends on any reference read without |
| 1284 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1285 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1286 | * The internal representation uses 38-bit and is described in the table below. |
| 1287 | * The first line indicates the side effect, and for field/array accesses the |
| 1288 | * second line indicates the type of the access (in the order of the |
| 1289 | * Primitive::Type enum). |
| 1290 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1291 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1292 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1293 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1294 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1295 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1296 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1297 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1298 | * |
| 1299 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1300 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1301 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1302 | class SideEffects : public ValueObject { |
| 1303 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1304 | SideEffects() : flags_(0) {} |
| 1305 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1306 | static SideEffects None() { |
| 1307 | return SideEffects(0); |
| 1308 | } |
| 1309 | |
| 1310 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1311 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1312 | } |
| 1313 | |
| 1314 | static SideEffects AllChanges() { |
| 1315 | return SideEffects(kAllChangeBits); |
| 1316 | } |
| 1317 | |
| 1318 | static SideEffects AllDependencies() { |
| 1319 | return SideEffects(kAllDependOnBits); |
| 1320 | } |
| 1321 | |
| 1322 | static SideEffects AllExceptGCDependency() { |
| 1323 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1324 | } |
| 1325 | |
| 1326 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1327 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1328 | } |
| 1329 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1330 | static SideEffects AllWrites() { |
| 1331 | return SideEffects(kAllWrites); |
| 1332 | } |
| 1333 | |
| 1334 | static SideEffects AllReads() { |
| 1335 | return SideEffects(kAllReads); |
| 1336 | } |
| 1337 | |
| 1338 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1339 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1340 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1341 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1342 | } |
| 1343 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1344 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1345 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1348 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1349 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1350 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1351 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1355 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1356 | } |
| 1357 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1358 | static SideEffects CanTriggerGC() { |
| 1359 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1360 | } |
| 1361 | |
| 1362 | static SideEffects DependsOnGC() { |
| 1363 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1364 | } |
| 1365 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1366 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1367 | SideEffects Union(SideEffects other) const { |
| 1368 | return SideEffects(flags_ | other.flags_); |
| 1369 | } |
| 1370 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1371 | SideEffects Exclusion(SideEffects other) const { |
| 1372 | return SideEffects(flags_ & ~other.flags_); |
| 1373 | } |
| 1374 | |
| 1375 | bool Includes(SideEffects other) const { |
| 1376 | return (other.flags_ & flags_) == other.flags_; |
| 1377 | } |
| 1378 | |
| 1379 | bool HasSideEffects() const { |
| 1380 | return (flags_ & kAllChangeBits); |
| 1381 | } |
| 1382 | |
| 1383 | bool HasDependencies() const { |
| 1384 | return (flags_ & kAllDependOnBits); |
| 1385 | } |
| 1386 | |
| 1387 | // Returns true if there are no side effects or dependencies. |
| 1388 | bool DoesNothing() const { |
| 1389 | return flags_ == 0; |
| 1390 | } |
| 1391 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1392 | // Returns true if something is written. |
| 1393 | bool DoesAnyWrite() const { |
| 1394 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1395 | } |
| 1396 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1397 | // Returns true if something is read. |
| 1398 | bool DoesAnyRead() const { |
| 1399 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1400 | } |
| 1401 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1402 | // Returns true if potentially everything is written and read |
| 1403 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1404 | bool DoesAllReadWrite() const { |
| 1405 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1406 | } |
| 1407 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1408 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1409 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | // Returns true if this may read something written by other. |
| 1413 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1414 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1415 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1419 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1420 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1421 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1422 | for (int s = kLastBit; s >= 0; s--) { |
| 1423 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1424 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1425 | // This is a bit for the GC side effect. |
| 1426 | if (current_bit_is_set) { |
| 1427 | flags += "GC"; |
| 1428 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1429 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1430 | } else { |
| 1431 | // This is a bit for the array/field analysis. |
| 1432 | // The underscore character stands for the 'can trigger GC' bit. |
| 1433 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1434 | if (current_bit_is_set) { |
| 1435 | flags += kDebug[s]; |
| 1436 | } |
| 1437 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1438 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1439 | flags += "|"; |
| 1440 | } |
| 1441 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1442 | } |
| 1443 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1444 | } |
| 1445 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1446 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1447 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1448 | private: |
| 1449 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1450 | |
| 1451 | static constexpr int kFieldWriteOffset = 0; |
| 1452 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1453 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1454 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1455 | |
| 1456 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1457 | |
| 1458 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1459 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1460 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1461 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1462 | |
| 1463 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1464 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1465 | |
| 1466 | // Aliases. |
| 1467 | |
| 1468 | static_assert(kChangeBits == kDependOnBits, |
| 1469 | "the 'change' bits should match the 'depend on' bits."); |
| 1470 | |
| 1471 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1472 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1473 | static constexpr uint64_t kAllWrites = |
| 1474 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1475 | static constexpr uint64_t kAllReads = |
| 1476 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1477 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1478 | // Work around the fact that HIR aliases I/F and J/D. |
| 1479 | // TODO: remove this interceptor once HIR types are clean |
| 1480 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1481 | switch (type) { |
| 1482 | case Primitive::kPrimInt: |
| 1483 | case Primitive::kPrimFloat: |
| 1484 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1485 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1486 | case Primitive::kPrimLong: |
| 1487 | case Primitive::kPrimDouble: |
| 1488 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1489 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1490 | default: |
| 1491 | return TypeFlag(type, offset); |
| 1492 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1493 | } |
| 1494 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1495 | // Translates type to bit flag. |
| 1496 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1497 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1498 | const uint64_t one = 1; |
| 1499 | const int shift = type; // 0-based consecutive enum |
| 1500 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1501 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1502 | return one << (type + offset); |
| 1503 | } |
| 1504 | |
| 1505 | // Private constructor on direct flags value. |
| 1506 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1507 | |
| 1508 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1509 | }; |
| 1510 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1511 | // A HEnvironment object contains the values of virtual registers at a given location. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1512 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1513 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1514 | HEnvironment(ArenaAllocator* arena, |
| 1515 | size_t number_of_vregs, |
| 1516 | const DexFile& dex_file, |
| 1517 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1518 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1519 | InvokeType invoke_type, |
| 1520 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1521 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1522 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1523 | parent_(nullptr), |
| 1524 | dex_file_(dex_file), |
| 1525 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1526 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1527 | invoke_type_(invoke_type), |
| 1528 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1529 | } |
| 1530 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1531 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1532 | : HEnvironment(arena, |
| 1533 | to_copy.Size(), |
| 1534 | to_copy.GetDexFile(), |
| 1535 | to_copy.GetMethodIdx(), |
| 1536 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1537 | to_copy.GetInvokeType(), |
| 1538 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1539 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1540 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1541 | if (parent_ != nullptr) { |
| 1542 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1543 | } else { |
| 1544 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1545 | parent_->CopyFrom(parent); |
| 1546 | if (parent->GetParent() != nullptr) { |
| 1547 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1548 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1549 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1552 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1553 | void CopyFrom(HEnvironment* environment); |
| 1554 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1555 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1556 | // input to the loop phi instead. This is for inserting instructions that |
| 1557 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1558 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1559 | |
| 1560 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1561 | DCHECK_LT(index, Size()); |
| 1562 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
| 1565 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1566 | DCHECK_LT(index, Size()); |
| 1567 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1570 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1571 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1572 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1573 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1574 | HEnvironment* GetParent() const { return parent_; } |
| 1575 | |
| 1576 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1577 | DCHECK_LT(index, Size()); |
| 1578 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1582 | DCHECK_LT(index, Size()); |
| 1583 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | uint32_t GetDexPc() const { |
| 1587 | return dex_pc_; |
| 1588 | } |
| 1589 | |
| 1590 | uint32_t GetMethodIdx() const { |
| 1591 | return method_idx_; |
| 1592 | } |
| 1593 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1594 | InvokeType GetInvokeType() const { |
| 1595 | return invoke_type_; |
| 1596 | } |
| 1597 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1598 | const DexFile& GetDexFile() const { |
| 1599 | return dex_file_; |
| 1600 | } |
| 1601 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1602 | HInstruction* GetHolder() const { |
| 1603 | return holder_; |
| 1604 | } |
| 1605 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1606 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1607 | // Record instructions' use entries of this environment for constant-time removal. |
| 1608 | // It should only be called by HInstruction when a new environment use is added. |
| 1609 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1610 | DCHECK(env_use->GetUser() == this); |
| 1611 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1612 | DCHECK_LT(index, Size()); |
| 1613 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1614 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1615 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1616 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1617 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1618 | HEnvironment* parent_; |
| 1619 | const DexFile& dex_file_; |
| 1620 | const uint32_t method_idx_; |
| 1621 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1622 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1623 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1624 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1625 | HInstruction* const holder_; |
| 1626 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1627 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1628 | |
| 1629 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1630 | }; |
| 1631 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1632 | class ReferenceTypeInfo : ValueObject { |
| 1633 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1634 | typedef Handle<mirror::Class> TypeHandle; |
| 1635 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1636 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1637 | // The constructor will check that the type_handle is valid. |
| 1638 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1639 | } |
| 1640 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1641 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1642 | |
| 1643 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1644 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1647 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1648 | return IsValidHandle(type_handle_); |
| 1649 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1650 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1651 | |
| 1652 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1653 | DCHECK(IsValid()); |
| 1654 | return GetTypeHandle()->IsObjectClass(); |
| 1655 | } |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1656 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1657 | DCHECK(IsValid()); |
| 1658 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1659 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1660 | |
| 1661 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1662 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1663 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1664 | DCHECK(IsValid()); |
| 1665 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1666 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1667 | } |
| 1668 | |
| 1669 | // Returns true if the type information provide the same amount of details. |
| 1670 | // Note that it does not mean that the instructions have the same actual type |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1671 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1672 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1673 | if (!IsValid() && !rti.IsValid()) { |
| 1674 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1675 | return true; |
| 1676 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1677 | if (!IsValid() || !rti.IsValid()) { |
| 1678 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1679 | return false; |
| 1680 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1681 | return IsExact() == rti.IsExact() |
| 1682 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1686 | ReferenceTypeInfo(); |
| 1687 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1688 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1689 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1690 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1691 | // 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] | 1692 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1693 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1694 | }; |
| 1695 | |
| 1696 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1697 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1698 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1699 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1700 | HInstruction(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1701 | : previous_(nullptr), |
| 1702 | next_(nullptr), |
| 1703 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1704 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1705 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1706 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1707 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1708 | locations_(nullptr), |
| 1709 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1710 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1711 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1712 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1713 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1714 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1715 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1716 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1717 | enum InstructionKind { |
| 1718 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1719 | }; |
| 1720 | #undef DECLARE_KIND |
| 1721 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1722 | HInstruction* GetNext() const { return next_; } |
| 1723 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1724 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1725 | HInstruction* GetNextDisregardingMoves() const; |
| 1726 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1727 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1728 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1729 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1730 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1731 | bool IsInBlock() const { return block_ != nullptr; } |
| 1732 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1733 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1734 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1735 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1736 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1737 | |
| 1738 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1739 | virtual const char* DebugName() const = 0; |
| 1740 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1741 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1742 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1743 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1744 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1745 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1746 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1747 | |
| 1748 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1749 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1750 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1751 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1752 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1753 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1754 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1755 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1756 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1757 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1758 | // Does not apply for all instructions, but having this at top level greatly |
| 1759 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1760 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1761 | virtual bool CanBeNull() const { |
| 1762 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1763 | return true; |
| 1764 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1765 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1766 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj) const { |
| 1767 | UNUSED(obj); |
| 1768 | return false; |
| 1769 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1770 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1771 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1772 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1773 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1774 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1775 | return reference_type_info_; |
| 1776 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1777 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1778 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1779 | DCHECK(user != nullptr); |
| 1780 | HUseListNode<HInstruction*>* use = |
| 1781 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1782 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1785 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1786 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1787 | HUseListNode<HEnvironment*>* env_use = |
| 1788 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1789 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1790 | } |
| 1791 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1792 | void RemoveAsUserOfInput(size_t input) { |
| 1793 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1794 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1795 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1796 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1797 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1798 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1799 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1800 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1801 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1802 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1803 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1804 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1805 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1806 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1807 | // Does this instruction strictly dominate `other_instruction`? |
| 1808 | // Returns false if this instruction and `other_instruction` are the same. |
| 1809 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1810 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1811 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1812 | int GetId() const { return id_; } |
| 1813 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1814 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1815 | int GetSsaIndex() const { return ssa_index_; } |
| 1816 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1817 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1818 | |
| 1819 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1820 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1821 | // Set the `environment_` field. Raw because this method does not |
| 1822 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1823 | void SetRawEnvironment(HEnvironment* environment) { |
| 1824 | DCHECK(environment_ == nullptr); |
| 1825 | DCHECK_EQ(environment->GetHolder(), this); |
| 1826 | environment_ = environment; |
| 1827 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1828 | |
| 1829 | // Set the environment of this instruction, copying it from `environment`. While |
| 1830 | // copying, the uses lists are being updated. |
| 1831 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1832 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1833 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1834 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1835 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1836 | if (environment->GetParent() != nullptr) { |
| 1837 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1838 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1839 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1840 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1841 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1842 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1843 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1844 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1845 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1846 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1847 | if (environment->GetParent() != nullptr) { |
| 1848 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1849 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1850 | } |
| 1851 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1852 | // Returns the number of entries in the environment. Typically, that is the |
| 1853 | // number of dex registers in a method. It could be more in case of inlining. |
| 1854 | size_t EnvironmentSize() const; |
| 1855 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1856 | LocationSummary* GetLocations() const { return locations_; } |
| 1857 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1858 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1859 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1860 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1861 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1862 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1863 | // uses of this instruction by `other` are *not* updated. |
| 1864 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1865 | ReplaceWith(other); |
| 1866 | other->ReplaceInput(this, use_index); |
| 1867 | } |
| 1868 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1869 | // Move `this` instruction before `cursor`. |
| 1870 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1871 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1872 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1873 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1874 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1875 | virtual H##type* As##type() { return nullptr; } |
| 1876 | |
| 1877 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1878 | #undef INSTRUCTION_TYPE_CHECK |
| 1879 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1880 | // Returns whether the instruction can be moved within the graph. |
| 1881 | virtual bool CanBeMoved() const { return false; } |
| 1882 | |
| 1883 | // Returns whether the two instructions are of the same kind. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1884 | virtual bool InstructionTypeEquals(HInstruction* other) const { |
| 1885 | UNUSED(other); |
| 1886 | return false; |
| 1887 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1888 | |
| 1889 | // Returns whether any data encoded in the two instructions is equal. |
| 1890 | // This method does not look at the inputs. Both instructions must be |
| 1891 | // of the same type, otherwise the method has undefined behavior. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1892 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1893 | UNUSED(other); |
| 1894 | return false; |
| 1895 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1896 | |
| 1897 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1898 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1899 | // 2) Their inputs are identical. |
| 1900 | bool Equals(HInstruction* other) const; |
| 1901 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1902 | virtual InstructionKind GetKind() const = 0; |
| 1903 | |
| 1904 | virtual size_t ComputeHashCode() const { |
| 1905 | size_t result = GetKind(); |
| 1906 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1907 | result = (result * 31) + InputAt(i)->GetId(); |
| 1908 | } |
| 1909 | return result; |
| 1910 | } |
| 1911 | |
| 1912 | SideEffects GetSideEffects() const { return side_effects_; } |
| 1913 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1914 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1915 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1916 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 1917 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 1918 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 1919 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1920 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 1921 | |
| 1922 | // Returns whether the code generation of the instruction will require to have access |
| 1923 | // to the current method. Such instructions are: |
| 1924 | // (1): Instructions that require an environment, as calling the runtime requires |
| 1925 | // to walk the stack and have the current method stored at a specific stack address. |
| 1926 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 1927 | // fields of the current method. |
| 1928 | bool NeedsCurrentMethod() const { |
| 1929 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 1930 | } |
| 1931 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1932 | virtual bool NeedsDexCache() const { return false; } |
| 1933 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1934 | // Does this instruction have any use in an environment before |
| 1935 | // control flow hits 'other'? |
| 1936 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 1937 | |
| 1938 | // Remove all references to environment uses of this instruction. |
| 1939 | // The caller must ensure that this is safe to do. |
| 1940 | void RemoveEnvironmentUsers(); |
| 1941 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1942 | protected: |
| 1943 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 1944 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 1945 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1946 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1947 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 1948 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1949 | HInstruction* previous_; |
| 1950 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1951 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1952 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1953 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1954 | // An instruction gets an id when it is added to the graph. |
| 1955 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1956 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1957 | int id_; |
| 1958 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1959 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 1960 | int ssa_index_; |
| 1961 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1962 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1963 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1964 | |
| 1965 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1966 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1967 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1968 | // The environment associated with this instruction. Not null if the instruction |
| 1969 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1970 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1971 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1972 | // Set by the code generator. |
| 1973 | LocationSummary* locations_; |
| 1974 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1975 | // Set by the liveness analysis. |
| 1976 | LiveInterval* live_interval_; |
| 1977 | |
| 1978 | // Set by the liveness analysis, this is the position in a linear |
| 1979 | // order of blocks where this instruction's live interval start. |
| 1980 | size_t lifetime_position_; |
| 1981 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1982 | const SideEffects side_effects_; |
| 1983 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1984 | // TODO: for primitive types this should be marked as invalid. |
| 1985 | ReferenceTypeInfo reference_type_info_; |
| 1986 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1987 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1988 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1989 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1990 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1991 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1992 | |
| 1993 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 1994 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1995 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1996 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1997 | class HInputIterator : public ValueObject { |
| 1998 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1999 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2000 | |
| 2001 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2002 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2003 | void Advance() { index_++; } |
| 2004 | |
| 2005 | private: |
| 2006 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2007 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2008 | |
| 2009 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2010 | }; |
| 2011 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2012 | class HInstructionIterator : public ValueObject { |
| 2013 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2014 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2015 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2016 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2019 | bool Done() const { return instruction_ == nullptr; } |
| 2020 | HInstruction* Current() const { return instruction_; } |
| 2021 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2022 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2023 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
| 2026 | private: |
| 2027 | HInstruction* instruction_; |
| 2028 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2029 | |
| 2030 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2031 | }; |
| 2032 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2033 | class HBackwardInstructionIterator : public ValueObject { |
| 2034 | public: |
| 2035 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2036 | : instruction_(instructions.last_instruction_) { |
| 2037 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2038 | } |
| 2039 | |
| 2040 | bool Done() const { return instruction_ == nullptr; } |
| 2041 | HInstruction* Current() const { return instruction_; } |
| 2042 | void Advance() { |
| 2043 | instruction_ = next_; |
| 2044 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2045 | } |
| 2046 | |
| 2047 | private: |
| 2048 | HInstruction* instruction_; |
| 2049 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2050 | |
| 2051 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2052 | }; |
| 2053 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2054 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2055 | class HTemplateInstruction: public HInstruction { |
| 2056 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2057 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2058 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2059 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2060 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2061 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2062 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2063 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2064 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2065 | DCHECK_LT(i, N); |
| 2066 | return inputs_[i]; |
| 2067 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2068 | |
| 2069 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2070 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2071 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2072 | } |
| 2073 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2074 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2075 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2076 | |
| 2077 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2078 | }; |
| 2079 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2080 | // HTemplateInstruction specialization for N=0. |
| 2081 | template<> |
| 2082 | class HTemplateInstruction<0>: public HInstruction { |
| 2083 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2084 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2085 | : HInstruction(side_effects, dex_pc) {} |
| 2086 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2087 | virtual ~HTemplateInstruction() {} |
| 2088 | |
| 2089 | size_t InputCount() const OVERRIDE { return 0; } |
| 2090 | |
| 2091 | protected: |
| 2092 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2093 | LOG(FATAL) << "Unreachable"; |
| 2094 | UNREACHABLE(); |
| 2095 | } |
| 2096 | |
| 2097 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2098 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2099 | LOG(FATAL) << "Unreachable"; |
| 2100 | UNREACHABLE(); |
| 2101 | } |
| 2102 | |
| 2103 | private: |
| 2104 | friend class SsaBuilder; |
| 2105 | }; |
| 2106 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2107 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2108 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2109 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2110 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2111 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2112 | virtual ~HExpression() {} |
| 2113 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2114 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2115 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2116 | protected: |
| 2117 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2118 | }; |
| 2119 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2120 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2121 | // instruction that branches to the exit block. |
| 2122 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2123 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2124 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2125 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2126 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2127 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2128 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2129 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2130 | |
| 2131 | private: |
| 2132 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2133 | }; |
| 2134 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2135 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2136 | // instruction that branches to the exit block. |
| 2137 | class HReturn : public HTemplateInstruction<1> { |
| 2138 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2139 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2140 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2141 | SetRawInputAt(0, value); |
| 2142 | } |
| 2143 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2144 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2145 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2146 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2147 | |
| 2148 | private: |
| 2149 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2150 | }; |
| 2151 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2152 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2153 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2154 | // exit block. |
| 2155 | class HExit : public HTemplateInstruction<0> { |
| 2156 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2157 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2158 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2159 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2160 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2161 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2162 | |
| 2163 | private: |
| 2164 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2165 | }; |
| 2166 | |
| 2167 | // Jumps from one block to another. |
| 2168 | class HGoto : public HTemplateInstruction<0> { |
| 2169 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2170 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2171 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2172 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2173 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2174 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2175 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2178 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2179 | |
| 2180 | private: |
| 2181 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2182 | }; |
| 2183 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2184 | class HConstant : public HExpression<0> { |
| 2185 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2186 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2187 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2188 | |
| 2189 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2190 | |
| 2191 | virtual bool IsMinusOne() const { return false; } |
| 2192 | virtual bool IsZero() const { return false; } |
| 2193 | virtual bool IsOne() const { return false; } |
| 2194 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2195 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2196 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2197 | DECLARE_INSTRUCTION(Constant); |
| 2198 | |
| 2199 | private: |
| 2200 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2201 | }; |
| 2202 | |
| 2203 | class HNullConstant : public HConstant { |
| 2204 | public: |
| 2205 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2206 | return true; |
| 2207 | } |
| 2208 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2209 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2210 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2211 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2212 | |
| 2213 | DECLARE_INSTRUCTION(NullConstant); |
| 2214 | |
| 2215 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2216 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2217 | |
| 2218 | friend class HGraph; |
| 2219 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2220 | }; |
| 2221 | |
| 2222 | // Constants of the type int. Those can be from Dex instructions, or |
| 2223 | // synthesized (for example with the if-eqz instruction). |
| 2224 | class HIntConstant : public HConstant { |
| 2225 | public: |
| 2226 | int32_t GetValue() const { return value_; } |
| 2227 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2228 | uint64_t GetValueAsUint64() const OVERRIDE { return static_cast<uint64_t>(value_); } |
| 2229 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2230 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2231 | DCHECK(other->IsIntConstant()); |
| 2232 | return other->AsIntConstant()->value_ == value_; |
| 2233 | } |
| 2234 | |
| 2235 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2236 | |
| 2237 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2238 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2239 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2240 | |
| 2241 | DECLARE_INSTRUCTION(IntConstant); |
| 2242 | |
| 2243 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2244 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2245 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2246 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2247 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2248 | |
| 2249 | const int32_t value_; |
| 2250 | |
| 2251 | friend class HGraph; |
| 2252 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2253 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2254 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2255 | }; |
| 2256 | |
| 2257 | class HLongConstant : public HConstant { |
| 2258 | public: |
| 2259 | int64_t GetValue() const { return value_; } |
| 2260 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2261 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2262 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2263 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2264 | DCHECK(other->IsLongConstant()); |
| 2265 | return other->AsLongConstant()->value_ == value_; |
| 2266 | } |
| 2267 | |
| 2268 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2269 | |
| 2270 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2271 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2272 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2273 | |
| 2274 | DECLARE_INSTRUCTION(LongConstant); |
| 2275 | |
| 2276 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2277 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2278 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2279 | |
| 2280 | const int64_t value_; |
| 2281 | |
| 2282 | friend class HGraph; |
| 2283 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2284 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2285 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2286 | // Conditional branch. A block ending with an HIf instruction must have |
| 2287 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2288 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2289 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2290 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2291 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2292 | SetRawInputAt(0, input); |
| 2293 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2294 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2295 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2296 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2297 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2298 | return GetBlock()->GetSuccessor(0); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2302 | return GetBlock()->GetSuccessor(1); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2305 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2306 | |
| 2307 | private: |
| 2308 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2309 | }; |
| 2310 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2311 | |
| 2312 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2313 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2314 | // non-exceptional control flow. |
| 2315 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2316 | // higher indices in no particular order. |
| 2317 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2318 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2319 | enum BoundaryKind { |
| 2320 | kEntry, |
| 2321 | kExit, |
| 2322 | }; |
| 2323 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2324 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2325 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2326 | |
| 2327 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2328 | |
| 2329 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2330 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessor(0); } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2331 | |
| 2332 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2333 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2334 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2335 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2336 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | // If not present already, adds `handler` to its block's list of exception |
| 2340 | // handlers. |
| 2341 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2342 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2343 | GetBlock()->AddSuccessor(handler); |
| 2344 | } |
| 2345 | } |
| 2346 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2347 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2348 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2349 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2350 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2351 | DECLARE_INSTRUCTION(TryBoundary); |
| 2352 | |
| 2353 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2354 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2355 | |
| 2356 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2357 | }; |
| 2358 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2359 | // Iterator over exception handlers of a given HTryBoundary, i.e. over |
| 2360 | // exceptional successors of its basic block. |
| 2361 | class HExceptionHandlerIterator : public ValueObject { |
| 2362 | public: |
| 2363 | explicit HExceptionHandlerIterator(const HTryBoundary& try_boundary) |
| 2364 | : block_(*try_boundary.GetBlock()), index_(block_.NumberOfNormalSuccessors()) {} |
| 2365 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2366 | bool Done() const { return index_ == block_.GetSuccessors().size(); } |
| 2367 | HBasicBlock* Current() const { return block_.GetSuccessor(index_); } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2368 | size_t CurrentSuccessorIndex() const { return index_; } |
| 2369 | void Advance() { ++index_; } |
| 2370 | |
| 2371 | private: |
| 2372 | const HBasicBlock& block_; |
| 2373 | size_t index_; |
| 2374 | |
| 2375 | DISALLOW_COPY_AND_ASSIGN(HExceptionHandlerIterator); |
| 2376 | }; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2377 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2378 | // Deoptimize to interpreter, upon checking a condition. |
| 2379 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2380 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2381 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2382 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2383 | SetRawInputAt(0, cond); |
| 2384 | } |
| 2385 | |
| 2386 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2387 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2388 | |
| 2389 | DECLARE_INSTRUCTION(Deoptimize); |
| 2390 | |
| 2391 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2392 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2393 | }; |
| 2394 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2395 | // Represents the ArtMethod that was passed as a first argument to |
| 2396 | // the method. It is used by instructions that depend on it, like |
| 2397 | // instructions that work with the dex cache. |
| 2398 | class HCurrentMethod : public HExpression<0> { |
| 2399 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2400 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2401 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2402 | |
| 2403 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2404 | |
| 2405 | private: |
| 2406 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2407 | }; |
| 2408 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2409 | class HUnaryOperation : public HExpression<1> { |
| 2410 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2411 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2412 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2413 | SetRawInputAt(0, input); |
| 2414 | } |
| 2415 | |
| 2416 | HInstruction* GetInput() const { return InputAt(0); } |
| 2417 | Primitive::Type GetResultType() const { return GetType(); } |
| 2418 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2419 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2420 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2421 | UNUSED(other); |
| 2422 | return true; |
| 2423 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2424 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2425 | // Try to statically evaluate `operation` and return a HConstant |
| 2426 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2427 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2428 | HConstant* TryStaticEvaluation() const; |
| 2429 | |
| 2430 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2431 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2432 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2433 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2434 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2435 | |
| 2436 | private: |
| 2437 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2438 | }; |
| 2439 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2440 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2441 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2442 | HBinaryOperation(Primitive::Type result_type, |
| 2443 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2444 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2445 | SideEffects side_effects = SideEffects::None(), |
| 2446 | uint32_t dex_pc = kNoDexPc) |
| 2447 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2448 | SetRawInputAt(0, left); |
| 2449 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2452 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2453 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2454 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2455 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2456 | virtual bool IsCommutative() const { return false; } |
| 2457 | |
| 2458 | // Put constant on the right. |
| 2459 | // Returns whether order is changed. |
| 2460 | bool OrderInputsWithConstantOnTheRight() { |
| 2461 | HInstruction* left = InputAt(0); |
| 2462 | HInstruction* right = InputAt(1); |
| 2463 | if (left->IsConstant() && !right->IsConstant()) { |
| 2464 | ReplaceInput(right, 0); |
| 2465 | ReplaceInput(left, 1); |
| 2466 | return true; |
| 2467 | } |
| 2468 | return false; |
| 2469 | } |
| 2470 | |
| 2471 | // Order inputs by instruction id, but favor constant on the right side. |
| 2472 | // This helps GVN for commutative ops. |
| 2473 | void OrderInputs() { |
| 2474 | DCHECK(IsCommutative()); |
| 2475 | HInstruction* left = InputAt(0); |
| 2476 | HInstruction* right = InputAt(1); |
| 2477 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2478 | return; |
| 2479 | } |
| 2480 | if (OrderInputsWithConstantOnTheRight()) { |
| 2481 | return; |
| 2482 | } |
| 2483 | // Order according to instruction id. |
| 2484 | if (left->GetId() > right->GetId()) { |
| 2485 | ReplaceInput(right, 0); |
| 2486 | ReplaceInput(left, 1); |
| 2487 | } |
| 2488 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2489 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2490 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2491 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2492 | UNUSED(other); |
| 2493 | return true; |
| 2494 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2495 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2496 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2497 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2498 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2499 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2500 | |
| 2501 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2502 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2503 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2504 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2505 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2506 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2507 | return nullptr; |
| 2508 | } |
| 2509 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2510 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2511 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2512 | return nullptr; |
| 2513 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2514 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2515 | // 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] | 2516 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2517 | HConstant* GetConstantRight() const; |
| 2518 | |
| 2519 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2520 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2521 | HInstruction* GetLeastConstantLeft() const; |
| 2522 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2523 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2524 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2525 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2526 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2527 | }; |
| 2528 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2529 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2530 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2531 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2532 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2533 | kGtBias, // return 1 for NaN comparisons |
| 2534 | kLtBias, // return -1 for NaN comparisons |
| 2535 | }; |
| 2536 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2537 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2538 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2539 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2540 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2541 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2542 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2543 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2544 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2545 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2546 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2547 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2548 | // `instruction`, and disregard moves in between. |
| 2549 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2550 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2551 | DECLARE_INSTRUCTION(Condition); |
| 2552 | |
| 2553 | virtual IfCondition GetCondition() const = 0; |
| 2554 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2555 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2556 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2557 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2558 | |
| 2559 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2560 | |
| 2561 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2562 | return bias_ == other->AsCondition()->bias_; |
| 2563 | } |
| 2564 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2565 | bool IsFPConditionTrueIfNaN() const { |
| 2566 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2567 | IfCondition if_cond = GetCondition(); |
| 2568 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2569 | } |
| 2570 | |
| 2571 | bool IsFPConditionFalseIfNaN() const { |
| 2572 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2573 | IfCondition if_cond = GetCondition(); |
| 2574 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2575 | } |
| 2576 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2577 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2578 | // For register allocation purposes, returns whether this instruction needs to be |
| 2579 | // materialized (that is, not just be in the processor flags). |
| 2580 | bool needs_materialization_; |
| 2581 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2582 | // Needed if we merge a HCompare into a HCondition. |
| 2583 | ComparisonBias bias_; |
| 2584 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2585 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2586 | }; |
| 2587 | |
| 2588 | // Instruction to check if two inputs are equal to each other. |
| 2589 | class HEqual : public HCondition { |
| 2590 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2591 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2592 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2593 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2594 | bool IsCommutative() const OVERRIDE { return true; } |
| 2595 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2596 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2597 | |
| 2598 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2599 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2600 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2601 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2602 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2603 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2604 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2605 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2606 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2607 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2608 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2609 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2610 | return kCondEQ; |
| 2611 | } |
| 2612 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2613 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2614 | return kCondNE; |
| 2615 | } |
| 2616 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2617 | private: |
| 2618 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2619 | }; |
| 2620 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2621 | class HNotEqual : public HCondition { |
| 2622 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2623 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2624 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2625 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2626 | bool IsCommutative() const OVERRIDE { return true; } |
| 2627 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2628 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2629 | |
| 2630 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2631 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2632 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2633 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2634 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2635 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2636 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2637 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2638 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2639 | DECLARE_INSTRUCTION(NotEqual); |
| 2640 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2641 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2642 | return kCondNE; |
| 2643 | } |
| 2644 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2645 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2646 | return kCondEQ; |
| 2647 | } |
| 2648 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2649 | private: |
| 2650 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2651 | }; |
| 2652 | |
| 2653 | class HLessThan : public HCondition { |
| 2654 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2655 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2656 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2657 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2658 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2659 | |
| 2660 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2661 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2662 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2663 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2664 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2665 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2666 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2667 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2668 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2669 | DECLARE_INSTRUCTION(LessThan); |
| 2670 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2671 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2672 | return kCondLT; |
| 2673 | } |
| 2674 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2675 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2676 | return kCondGE; |
| 2677 | } |
| 2678 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2679 | private: |
| 2680 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2681 | }; |
| 2682 | |
| 2683 | class HLessThanOrEqual : public HCondition { |
| 2684 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2685 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2686 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2687 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2688 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2689 | |
| 2690 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2691 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2692 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2693 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2694 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2695 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2696 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2697 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2698 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2699 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2700 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2701 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2702 | return kCondLE; |
| 2703 | } |
| 2704 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2705 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2706 | return kCondGT; |
| 2707 | } |
| 2708 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2709 | private: |
| 2710 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2711 | }; |
| 2712 | |
| 2713 | class HGreaterThan : public HCondition { |
| 2714 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2715 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2716 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2717 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2718 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2719 | |
| 2720 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2721 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2722 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2723 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2724 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2725 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2726 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2727 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2728 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2729 | DECLARE_INSTRUCTION(GreaterThan); |
| 2730 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2731 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2732 | return kCondGT; |
| 2733 | } |
| 2734 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2735 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2736 | return kCondLE; |
| 2737 | } |
| 2738 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2739 | private: |
| 2740 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2741 | }; |
| 2742 | |
| 2743 | class HGreaterThanOrEqual : public HCondition { |
| 2744 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2745 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2746 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2747 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2748 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2749 | |
| 2750 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2751 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2752 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2753 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2754 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2755 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2756 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2757 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2758 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2759 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2760 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2761 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2762 | return kCondGE; |
| 2763 | } |
| 2764 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2765 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2766 | return kCondLT; |
| 2767 | } |
| 2768 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2769 | private: |
| 2770 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2771 | }; |
| 2772 | |
| 2773 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2774 | // Instruction to check how two inputs compare to each other. |
| 2775 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 2776 | class HCompare : public HBinaryOperation { |
| 2777 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2778 | HCompare(Primitive::Type type, |
| 2779 | HInstruction* first, |
| 2780 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2781 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2782 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2783 | : HBinaryOperation(Primitive::kPrimInt, |
| 2784 | first, |
| 2785 | second, |
| 2786 | SideEffectsForArchRuntimeCalls(type), |
| 2787 | dex_pc), |
| 2788 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2789 | DCHECK_EQ(type, first->GetType()); |
| 2790 | DCHECK_EQ(type, second->GetType()); |
| 2791 | } |
| 2792 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2793 | template <typename T> |
| 2794 | int32_t Compute(T x, T y) const { return x == y ? 0 : x > y ? 1 : -1; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2795 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2796 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2797 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2798 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2799 | } |
| 2800 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2801 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2802 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2803 | } |
| 2804 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2805 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2806 | return bias_ == other->AsCompare()->bias_; |
| 2807 | } |
| 2808 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2809 | ComparisonBias GetBias() const { return bias_; } |
| 2810 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2811 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2812 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2813 | |
| 2814 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 2815 | // MIPS64 uses a runtime call for FP comparisons. |
| 2816 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 2817 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2818 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2819 | DECLARE_INSTRUCTION(Compare); |
| 2820 | |
| 2821 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2822 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2823 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2824 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 2825 | }; |
| 2826 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2827 | // A local in the graph. Corresponds to a Dex register. |
| 2828 | class HLocal : public HTemplateInstruction<0> { |
| 2829 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2830 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2831 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2832 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2833 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2834 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2835 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2836 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2837 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2838 | // The Dex register number. |
| 2839 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2840 | |
| 2841 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 2842 | }; |
| 2843 | |
| 2844 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2845 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2846 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2847 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2848 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2849 | SetRawInputAt(0, local); |
| 2850 | } |
| 2851 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2852 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2853 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2854 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2855 | |
| 2856 | private: |
| 2857 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 2858 | }; |
| 2859 | |
| 2860 | // Store a value in a given local. This instruction has two inputs: the value |
| 2861 | // and the local. |
| 2862 | class HStoreLocal : public HTemplateInstruction<2> { |
| 2863 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2864 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2865 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2866 | SetRawInputAt(0, local); |
| 2867 | SetRawInputAt(1, value); |
| 2868 | } |
| 2869 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2870 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2871 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2872 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2873 | |
| 2874 | private: |
| 2875 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 2876 | }; |
| 2877 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2878 | class HFloatConstant : public HConstant { |
| 2879 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2880 | float GetValue() const { return value_; } |
| 2881 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2882 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2883 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2884 | } |
| 2885 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2886 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2887 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2888 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2889 | } |
| 2890 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2891 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2892 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2893 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2894 | 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] | 2895 | } |
| 2896 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2897 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2898 | } |
| 2899 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2900 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2901 | } |
| 2902 | bool IsNaN() const { |
| 2903 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2904 | } |
| 2905 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2906 | DECLARE_INSTRUCTION(FloatConstant); |
| 2907 | |
| 2908 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2909 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2910 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2911 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2912 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2913 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2914 | const float value_; |
| 2915 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2916 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2917 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2918 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2919 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2920 | }; |
| 2921 | |
| 2922 | class HDoubleConstant : public HConstant { |
| 2923 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2924 | double GetValue() const { return value_; } |
| 2925 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2926 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2927 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2928 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2929 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2930 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2931 | } |
| 2932 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2933 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2934 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2935 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2936 | 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] | 2937 | } |
| 2938 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2939 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2940 | } |
| 2941 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2942 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2943 | } |
| 2944 | bool IsNaN() const { |
| 2945 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2948 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2949 | |
| 2950 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2951 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2952 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2953 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2954 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2955 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2956 | const double value_; |
| 2957 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2958 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2959 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2960 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2961 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2962 | }; |
| 2963 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2964 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2965 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2966 | #include "intrinsics_list.h" |
| 2967 | kNone, |
| 2968 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 2969 | #undef INTRINSICS_LIST |
| 2970 | #undef OPTIMIZING_INTRINSICS |
| 2971 | }; |
| 2972 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 2973 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2974 | enum IntrinsicNeedsEnvironmentOrCache { |
| 2975 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 2976 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 2977 | }; |
| 2978 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2979 | class HInvoke : public HInstruction { |
| 2980 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2981 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2982 | |
| 2983 | // Runtime needs to walk the stack, so Dex -> Dex calls need to |
| 2984 | // know their environment. |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2985 | bool NeedsEnvironment() const OVERRIDE { |
| 2986 | return needs_environment_or_cache_ == kNeedsEnvironmentOrCache; |
| 2987 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2988 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2989 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2990 | SetRawInputAt(index, argument); |
| 2991 | } |
| 2992 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2993 | // Return the number of arguments. This number can be lower than |
| 2994 | // the number of inputs returned by InputCount(), as some invoke |
| 2995 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 2996 | // inputs at the end of their list of inputs. |
| 2997 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 2998 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2999 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3000 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3001 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3002 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3003 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3004 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3005 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3006 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3007 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3008 | return intrinsic_; |
| 3009 | } |
| 3010 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3011 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3012 | intrinsic_ = intrinsic; |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3013 | needs_environment_or_cache_ = needs_env_or_cache; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3014 | } |
| 3015 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3016 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3017 | return GetEnvironment()->GetParent() != nullptr; |
| 3018 | } |
| 3019 | |
| 3020 | bool CanThrow() const OVERRIDE { return true; } |
| 3021 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3022 | DECLARE_INSTRUCTION(Invoke); |
| 3023 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3024 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3025 | HInvoke(ArenaAllocator* arena, |
| 3026 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3027 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3028 | Primitive::Type return_type, |
| 3029 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3030 | uint32_t dex_method_index, |
| 3031 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3032 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3033 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3034 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3035 | inputs_(number_of_arguments + number_of_other_inputs, arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3036 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3037 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3038 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3039 | intrinsic_(Intrinsics::kNone), |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3040 | needs_environment_or_cache_(kNeedsEnvironmentOrCache) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3041 | } |
| 3042 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3043 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 3044 | DCHECK_LT(index, InputCount()); |
| 3045 | return inputs_[index]; |
| 3046 | } |
| 3047 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3048 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3049 | DCHECK_LT(index, InputCount()); |
| 3050 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3051 | } |
| 3052 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3053 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3054 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3055 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3056 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3057 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3058 | Intrinsics intrinsic_; |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3059 | IntrinsicNeedsEnvironmentOrCache needs_environment_or_cache_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3060 | |
| 3061 | private: |
| 3062 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3063 | }; |
| 3064 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3065 | class HInvokeUnresolved : public HInvoke { |
| 3066 | public: |
| 3067 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3068 | uint32_t number_of_arguments, |
| 3069 | Primitive::Type return_type, |
| 3070 | uint32_t dex_pc, |
| 3071 | uint32_t dex_method_index, |
| 3072 | InvokeType invoke_type) |
| 3073 | : HInvoke(arena, |
| 3074 | number_of_arguments, |
| 3075 | 0u /* number_of_other_inputs */, |
| 3076 | return_type, |
| 3077 | dex_pc, |
| 3078 | dex_method_index, |
| 3079 | invoke_type) { |
| 3080 | } |
| 3081 | |
| 3082 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3083 | |
| 3084 | private: |
| 3085 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3086 | }; |
| 3087 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3088 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3089 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3090 | // Requirements of this method call regarding the class |
| 3091 | // initialization (clinit) check of its declaring class. |
| 3092 | enum class ClinitCheckRequirement { |
| 3093 | kNone, // Class already initialized. |
| 3094 | kExplicit, // Static call having explicit clinit check as last input. |
| 3095 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3096 | }; |
| 3097 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3098 | // Determines how to load the target ArtMethod*. |
| 3099 | enum class MethodLoadKind { |
| 3100 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3101 | kStringInit, |
| 3102 | |
| 3103 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3104 | kRecursive, |
| 3105 | |
| 3106 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3107 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3108 | kDirectAddress, |
| 3109 | |
| 3110 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3111 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3112 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3113 | // the image relocatable or not. |
| 3114 | kDirectAddressWithFixup, |
| 3115 | |
| 3116 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3117 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3118 | // may cause class initialization (the entry may point to a resolution method), |
| 3119 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3120 | kDexCachePcRelative, |
| 3121 | |
| 3122 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3123 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3124 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3125 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3126 | kDexCacheViaMethod, |
| 3127 | }; |
| 3128 | |
| 3129 | // Determines the location of the code pointer. |
| 3130 | enum class CodePtrLocation { |
| 3131 | // Recursive call, use local PC-relative call instruction. |
| 3132 | kCallSelf, |
| 3133 | |
| 3134 | // Use PC-relative call instruction patched at link time. |
| 3135 | // Used for calls within an oat file, boot->boot or app->app. |
| 3136 | kCallPCRelative, |
| 3137 | |
| 3138 | // Call to a known target address, embed the direct address in code. |
| 3139 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3140 | kCallDirect, |
| 3141 | |
| 3142 | // Call to a target address that will be known at link time, embed the direct |
| 3143 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3144 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3145 | // the image relocatable or not. |
| 3146 | kCallDirectWithFixup, |
| 3147 | |
| 3148 | // Use code pointer from the ArtMethod*. |
| 3149 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3150 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3151 | kCallArtMethod, |
| 3152 | }; |
| 3153 | |
| 3154 | struct DispatchInfo { |
| 3155 | const MethodLoadKind method_load_kind; |
| 3156 | const CodePtrLocation code_ptr_location; |
| 3157 | // The method load data holds |
| 3158 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3159 | // Note that there are multiple string init methods, each having its own offset. |
| 3160 | // - the method address for kDirectAddress |
| 3161 | // - the dex cache arrays offset for kDexCachePcRel. |
| 3162 | const uint64_t method_load_data; |
| 3163 | const uint64_t direct_code_ptr; |
| 3164 | }; |
| 3165 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3166 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3167 | uint32_t number_of_arguments, |
| 3168 | Primitive::Type return_type, |
| 3169 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3170 | uint32_t method_index, |
| 3171 | MethodReference target_method, |
| 3172 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3173 | InvokeType original_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3174 | InvokeType invoke_type, |
| 3175 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3176 | : HInvoke(arena, |
| 3177 | number_of_arguments, |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3178 | // There is one extra argument for the HCurrentMethod node, and |
| 3179 | // potentially one other if the clinit check is explicit, and one other |
| 3180 | // if the method is a string factory. |
| 3181 | 1u + (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3182 | + (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3183 | return_type, |
| 3184 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3185 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3186 | original_invoke_type), |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3187 | invoke_type_(invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3188 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3189 | target_method_(target_method), |
| 3190 | dispatch_info_(dispatch_info) {} |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3191 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3192 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 3193 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3194 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3195 | // TODO: for intrinsics we can generate implicit null checks. |
| 3196 | return false; |
| 3197 | } |
| 3198 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3199 | bool CanBeNull() const OVERRIDE { |
| 3200 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3201 | } |
| 3202 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3203 | InvokeType GetInvokeType() const { return invoke_type_; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3204 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3205 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3206 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3207 | bool NeedsDexCache() const OVERRIDE { |
| 3208 | if (intrinsic_ != Intrinsics::kNone) { return needs_environment_or_cache_; } |
| 3209 | return !IsRecursive() && !IsStringInit(); |
| 3210 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3211 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3212 | uint32_t GetCurrentMethodInputIndex() const { return GetNumberOfArguments(); } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3213 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
| 3214 | bool HasPcRelDexCache() const { return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; } |
| 3215 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3216 | MethodReference GetTargetMethod() const { return target_method_; } |
| 3217 | |
| 3218 | int32_t GetStringInitOffset() const { |
| 3219 | DCHECK(IsStringInit()); |
| 3220 | return dispatch_info_.method_load_data; |
| 3221 | } |
| 3222 | |
| 3223 | uint64_t GetMethodAddress() const { |
| 3224 | DCHECK(HasMethodAddress()); |
| 3225 | return dispatch_info_.method_load_data; |
| 3226 | } |
| 3227 | |
| 3228 | uint32_t GetDexCacheArrayOffset() const { |
| 3229 | DCHECK(HasPcRelDexCache()); |
| 3230 | return dispatch_info_.method_load_data; |
| 3231 | } |
| 3232 | |
| 3233 | uint64_t GetDirectCodePtr() const { |
| 3234 | DCHECK(HasDirectCodePtr()); |
| 3235 | return dispatch_info_.direct_code_ptr; |
| 3236 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3237 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3238 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3239 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3240 | // Is this instruction a call to a static method? |
| 3241 | bool IsStatic() const { |
| 3242 | return GetInvokeType() == kStatic; |
| 3243 | } |
| 3244 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3245 | // Remove the art::HLoadClass instruction set as last input by |
| 3246 | // art::PrepareForRegisterAllocation::VisitClinitCheck in lieu of |
| 3247 | // the initial art::HClinitCheck instruction (only relevant for |
| 3248 | // static calls with explicit clinit check). |
| 3249 | void RemoveLoadClassAsLastInput() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3250 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3251 | size_t last_input_index = InputCount() - 1; |
| 3252 | HInstruction* last_input = InputAt(last_input_index); |
| 3253 | DCHECK(last_input != nullptr); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3254 | DCHECK(last_input->IsLoadClass()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3255 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3256 | inputs_.pop_back(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3257 | clinit_check_requirement_ = ClinitCheckRequirement::kImplicit; |
| 3258 | DCHECK(IsStaticWithImplicitClinitCheck()); |
| 3259 | } |
| 3260 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3261 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3262 | if (!IsStringInit()) return false; |
| 3263 | // +1 for the current method. |
| 3264 | if (InputCount() == (number_of_arguments_ + 1)) return false; |
| 3265 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3266 | } |
| 3267 | |
| 3268 | void RemoveFakeStringArgumentAsLastInput() { |
| 3269 | DCHECK(IsStringInit()); |
| 3270 | size_t last_input_index = InputCount() - 1; |
| 3271 | HInstruction* last_input = InputAt(last_input_index); |
| 3272 | DCHECK(last_input != nullptr); |
| 3273 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3274 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3275 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3276 | } |
| 3277 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3278 | // Is this a call to a static method whose declaring class has an |
| 3279 | // explicit intialization check in the graph? |
| 3280 | bool IsStaticWithExplicitClinitCheck() const { |
| 3281 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3282 | } |
| 3283 | |
| 3284 | // Is this a call to a static method whose declaring class has an |
| 3285 | // implicit intialization check requirement? |
| 3286 | bool IsStaticWithImplicitClinitCheck() const { |
| 3287 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3288 | } |
| 3289 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3290 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3291 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3292 | protected: |
| 3293 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3294 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3295 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3296 | HInstruction* input = input_record.GetInstruction(); |
| 3297 | // `input` is the last input of a static invoke marked as having |
| 3298 | // an explicit clinit check. It must either be: |
| 3299 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3300 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3301 | DCHECK(input != nullptr); |
| 3302 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3303 | } |
| 3304 | return input_record; |
| 3305 | } |
| 3306 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3307 | private: |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3308 | const InvokeType invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3309 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3310 | // The target method may refer to different dex file or method index than the original |
| 3311 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3312 | // in derived class to increase visibility. |
| 3313 | MethodReference target_method_; |
| 3314 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3315 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3316 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3317 | }; |
| 3318 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3319 | class HInvokeVirtual : public HInvoke { |
| 3320 | public: |
| 3321 | HInvokeVirtual(ArenaAllocator* arena, |
| 3322 | uint32_t number_of_arguments, |
| 3323 | Primitive::Type return_type, |
| 3324 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3325 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3326 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3327 | : 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] | 3328 | vtable_index_(vtable_index) {} |
| 3329 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3330 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3331 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3332 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3335 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3336 | |
| 3337 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3338 | |
| 3339 | private: |
| 3340 | const uint32_t vtable_index_; |
| 3341 | |
| 3342 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3343 | }; |
| 3344 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3345 | class HInvokeInterface : public HInvoke { |
| 3346 | public: |
| 3347 | HInvokeInterface(ArenaAllocator* arena, |
| 3348 | uint32_t number_of_arguments, |
| 3349 | Primitive::Type return_type, |
| 3350 | uint32_t dex_pc, |
| 3351 | uint32_t dex_method_index, |
| 3352 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3353 | : 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] | 3354 | imt_index_(imt_index) {} |
| 3355 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3356 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3357 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3358 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3359 | } |
| 3360 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3361 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3362 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3363 | |
| 3364 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3365 | |
| 3366 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3367 | const uint32_t imt_index_; |
| 3368 | |
| 3369 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3370 | }; |
| 3371 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3372 | class HNewInstance : public HExpression<1> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3373 | public: |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3374 | HNewInstance(HCurrentMethod* current_method, |
| 3375 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3376 | uint16_t type_index, |
| 3377 | const DexFile& dex_file, |
| 3378 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3379 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3380 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3381 | dex_file_(dex_file), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3382 | entrypoint_(entrypoint) { |
| 3383 | SetRawInputAt(0, current_method); |
| 3384 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3385 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3386 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3387 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3388 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3389 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3390 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3391 | // It may throw when called on: |
| 3392 | // - interfaces |
| 3393 | // - abstract/innaccessible/unknown classes |
| 3394 | // TODO: optimize when possible. |
| 3395 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3396 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3397 | bool CanBeNull() const OVERRIDE { return false; } |
| 3398 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3399 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3400 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3401 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3402 | |
| 3403 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3404 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3405 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3406 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3407 | |
| 3408 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3409 | }; |
| 3410 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3411 | class HNeg : public HUnaryOperation { |
| 3412 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3413 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3414 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3415 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3416 | template <typename T> T Compute(T x) const { return -x; } |
| 3417 | |
| 3418 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3419 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3420 | } |
| 3421 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3422 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3423 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3424 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3425 | DECLARE_INSTRUCTION(Neg); |
| 3426 | |
| 3427 | private: |
| 3428 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3429 | }; |
| 3430 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3431 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3432 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3433 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3434 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3435 | uint32_t dex_pc, |
| 3436 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3437 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3438 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3439 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3440 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3441 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3442 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3443 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3444 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3445 | } |
| 3446 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3447 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3448 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3449 | |
| 3450 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3451 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3452 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3453 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3454 | bool CanThrow() const OVERRIDE { return true; } |
| 3455 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3456 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3457 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3458 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3459 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3460 | DECLARE_INSTRUCTION(NewArray); |
| 3461 | |
| 3462 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3463 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3464 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3465 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3466 | |
| 3467 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3468 | }; |
| 3469 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3470 | class HAdd : public HBinaryOperation { |
| 3471 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3472 | HAdd(Primitive::Type result_type, |
| 3473 | HInstruction* left, |
| 3474 | HInstruction* right, |
| 3475 | uint32_t dex_pc = kNoDexPc) |
| 3476 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3477 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3478 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3479 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3480 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3481 | |
| 3482 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3483 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3484 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3485 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3486 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3487 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3488 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3489 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3490 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3491 | DECLARE_INSTRUCTION(Add); |
| 3492 | |
| 3493 | private: |
| 3494 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3495 | }; |
| 3496 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3497 | class HSub : public HBinaryOperation { |
| 3498 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3499 | HSub(Primitive::Type result_type, |
| 3500 | HInstruction* left, |
| 3501 | HInstruction* right, |
| 3502 | uint32_t dex_pc = kNoDexPc) |
| 3503 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3504 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3505 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3506 | |
| 3507 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3508 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3509 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3510 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3511 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3512 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3513 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3514 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3515 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3516 | DECLARE_INSTRUCTION(Sub); |
| 3517 | |
| 3518 | private: |
| 3519 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3520 | }; |
| 3521 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3522 | class HMul : public HBinaryOperation { |
| 3523 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3524 | HMul(Primitive::Type result_type, |
| 3525 | HInstruction* left, |
| 3526 | HInstruction* right, |
| 3527 | uint32_t dex_pc = kNoDexPc) |
| 3528 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3529 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3530 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3531 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3532 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3533 | |
| 3534 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3535 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3536 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3537 | } |
| 3538 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3539 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3540 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3541 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3542 | |
| 3543 | DECLARE_INSTRUCTION(Mul); |
| 3544 | |
| 3545 | private: |
| 3546 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3547 | }; |
| 3548 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3549 | class HDiv : public HBinaryOperation { |
| 3550 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3551 | HDiv(Primitive::Type result_type, |
| 3552 | HInstruction* left, |
| 3553 | HInstruction* right, |
| 3554 | uint32_t dex_pc) |
| 3555 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3556 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3557 | template <typename T> |
| 3558 | T Compute(T x, T y) const { |
| 3559 | // Our graph structure ensures we never have 0 for `y` during |
| 3560 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3561 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3562 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3563 | return (y == -1) ? -x : x / y; |
| 3564 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3565 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3566 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3567 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3568 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3569 | } |
| 3570 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3571 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3572 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3573 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3574 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3575 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3576 | // The generated code can use a runtime call. |
| 3577 | return SideEffects::CanTriggerGC(); |
| 3578 | } |
| 3579 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3580 | DECLARE_INSTRUCTION(Div); |
| 3581 | |
| 3582 | private: |
| 3583 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3584 | }; |
| 3585 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3586 | class HRem : public HBinaryOperation { |
| 3587 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3588 | HRem(Primitive::Type result_type, |
| 3589 | HInstruction* left, |
| 3590 | HInstruction* right, |
| 3591 | uint32_t dex_pc) |
| 3592 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3593 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3594 | template <typename T> |
| 3595 | T Compute(T x, T y) const { |
| 3596 | // Our graph structure ensures we never have 0 for `y` during |
| 3597 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3598 | DCHECK_NE(y, 0); |
| 3599 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3600 | return (y == -1) ? 0 : x % y; |
| 3601 | } |
| 3602 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3603 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3604 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3605 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3606 | } |
| 3607 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3608 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3609 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3610 | } |
| 3611 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3612 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3613 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3614 | return SideEffects::CanTriggerGC(); |
| 3615 | } |
| 3616 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3617 | DECLARE_INSTRUCTION(Rem); |
| 3618 | |
| 3619 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3620 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3621 | }; |
| 3622 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3623 | class HDivZeroCheck : public HExpression<1> { |
| 3624 | public: |
| 3625 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3626 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3627 | SetRawInputAt(0, value); |
| 3628 | } |
| 3629 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3630 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3631 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3632 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3633 | |
| 3634 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3635 | UNUSED(other); |
| 3636 | return true; |
| 3637 | } |
| 3638 | |
| 3639 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3640 | bool CanThrow() const OVERRIDE { return true; } |
| 3641 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3642 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3643 | |
| 3644 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3645 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3646 | }; |
| 3647 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3648 | class HShl : public HBinaryOperation { |
| 3649 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3650 | HShl(Primitive::Type result_type, |
| 3651 | HInstruction* left, |
| 3652 | HInstruction* right, |
| 3653 | uint32_t dex_pc = kNoDexPc) |
| 3654 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3655 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3656 | template <typename T, typename U, typename V> |
| 3657 | T Compute(T x, U y, V max_shift_value) const { |
| 3658 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3659 | "V is not the unsigned integer type corresponding to T"); |
| 3660 | return x << (y & max_shift_value); |
| 3661 | } |
| 3662 | |
| 3663 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3664 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3665 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3666 | } |
| 3667 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3668 | // case is handled as `x << static_cast<int>(y)`. |
| 3669 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3670 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3671 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3672 | } |
| 3673 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3674 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3675 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3676 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3677 | |
| 3678 | DECLARE_INSTRUCTION(Shl); |
| 3679 | |
| 3680 | private: |
| 3681 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 3682 | }; |
| 3683 | |
| 3684 | class HShr : public HBinaryOperation { |
| 3685 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3686 | HShr(Primitive::Type result_type, |
| 3687 | HInstruction* left, |
| 3688 | HInstruction* right, |
| 3689 | uint32_t dex_pc = kNoDexPc) |
| 3690 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3691 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3692 | template <typename T, typename U, typename V> |
| 3693 | T Compute(T x, U y, V max_shift_value) const { |
| 3694 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3695 | "V is not the unsigned integer type corresponding to T"); |
| 3696 | return x >> (y & max_shift_value); |
| 3697 | } |
| 3698 | |
| 3699 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3700 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3701 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3702 | } |
| 3703 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3704 | // case is handled as `x >> static_cast<int>(y)`. |
| 3705 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3706 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3707 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3708 | } |
| 3709 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3710 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3711 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3712 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3713 | |
| 3714 | DECLARE_INSTRUCTION(Shr); |
| 3715 | |
| 3716 | private: |
| 3717 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 3718 | }; |
| 3719 | |
| 3720 | class HUShr : public HBinaryOperation { |
| 3721 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3722 | HUShr(Primitive::Type result_type, |
| 3723 | HInstruction* left, |
| 3724 | HInstruction* right, |
| 3725 | uint32_t dex_pc = kNoDexPc) |
| 3726 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3727 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3728 | template <typename T, typename U, typename V> |
| 3729 | T Compute(T x, U y, V max_shift_value) const { |
| 3730 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3731 | "V is not the unsigned integer type corresponding to T"); |
| 3732 | V ux = static_cast<V>(x); |
| 3733 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3734 | } |
| 3735 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3736 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3737 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3738 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3739 | } |
| 3740 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3741 | // case is handled as `x >>> static_cast<int>(y)`. |
| 3742 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3743 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3744 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3745 | } |
| 3746 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3747 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3748 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | DECLARE_INSTRUCTION(UShr); |
| 3752 | |
| 3753 | private: |
| 3754 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 3755 | }; |
| 3756 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3757 | class HAnd : public HBinaryOperation { |
| 3758 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3759 | HAnd(Primitive::Type result_type, |
| 3760 | HInstruction* left, |
| 3761 | HInstruction* right, |
| 3762 | uint32_t dex_pc = kNoDexPc) |
| 3763 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3764 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3765 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3766 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3767 | template <typename T, typename U> |
| 3768 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 3769 | |
| 3770 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3771 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3772 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3773 | } |
| 3774 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3775 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3776 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3777 | } |
| 3778 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3779 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3780 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3781 | } |
| 3782 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3783 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3784 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3785 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3786 | |
| 3787 | DECLARE_INSTRUCTION(And); |
| 3788 | |
| 3789 | private: |
| 3790 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 3791 | }; |
| 3792 | |
| 3793 | class HOr : public HBinaryOperation { |
| 3794 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3795 | HOr(Primitive::Type result_type, |
| 3796 | HInstruction* left, |
| 3797 | HInstruction* right, |
| 3798 | uint32_t dex_pc = kNoDexPc) |
| 3799 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3800 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3801 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3802 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3803 | template <typename T, typename U> |
| 3804 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 3805 | |
| 3806 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3807 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3808 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3809 | } |
| 3810 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3811 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3812 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3813 | } |
| 3814 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3815 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3816 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3817 | } |
| 3818 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3819 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3820 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3821 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3822 | |
| 3823 | DECLARE_INSTRUCTION(Or); |
| 3824 | |
| 3825 | private: |
| 3826 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 3827 | }; |
| 3828 | |
| 3829 | class HXor : public HBinaryOperation { |
| 3830 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3831 | HXor(Primitive::Type result_type, |
| 3832 | HInstruction* left, |
| 3833 | HInstruction* right, |
| 3834 | uint32_t dex_pc = kNoDexPc) |
| 3835 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3836 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3837 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3838 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3839 | template <typename T, typename U> |
| 3840 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 3841 | |
| 3842 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3843 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3844 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3845 | } |
| 3846 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3847 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3848 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3849 | } |
| 3850 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3851 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3852 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3853 | } |
| 3854 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3855 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3856 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3857 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3858 | |
| 3859 | DECLARE_INSTRUCTION(Xor); |
| 3860 | |
| 3861 | private: |
| 3862 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 3863 | }; |
| 3864 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3865 | // The value of a parameter in this method. Its location depends on |
| 3866 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3867 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3868 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3869 | HParameterValue(uint8_t index, |
| 3870 | Primitive::Type parameter_type, |
| 3871 | bool is_this = false) |
| 3872 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3873 | index_(index), |
| 3874 | is_this_(is_this), |
| 3875 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3876 | |
| 3877 | uint8_t GetIndex() const { return index_; } |
| 3878 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3879 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 3880 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3881 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 3882 | bool IsThis() const { return is_this_; } |
| 3883 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3884 | DECLARE_INSTRUCTION(ParameterValue); |
| 3885 | |
| 3886 | private: |
| 3887 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3888 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3889 | const uint8_t index_; |
| 3890 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3891 | // Whether or not the parameter value corresponds to 'this' argument. |
| 3892 | const bool is_this_; |
| 3893 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3894 | bool can_be_null_; |
| 3895 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3896 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 3897 | }; |
| 3898 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3899 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3900 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3901 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3902 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3903 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3904 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3905 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3906 | UNUSED(other); |
| 3907 | return true; |
| 3908 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3909 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3910 | template <typename T> T Compute(T x) const { return ~x; } |
| 3911 | |
| 3912 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3913 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3914 | } |
| 3915 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3916 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3917 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3918 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3919 | DECLARE_INSTRUCTION(Not); |
| 3920 | |
| 3921 | private: |
| 3922 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 3923 | }; |
| 3924 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3925 | class HBooleanNot : public HUnaryOperation { |
| 3926 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3927 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3928 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3929 | |
| 3930 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3931 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3932 | UNUSED(other); |
| 3933 | return true; |
| 3934 | } |
| 3935 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3936 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3937 | DCHECK(IsUint<1>(x)); |
| 3938 | return !x; |
| 3939 | } |
| 3940 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3941 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3942 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3943 | } |
| 3944 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3945 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3946 | UNREACHABLE(); |
| 3947 | } |
| 3948 | |
| 3949 | DECLARE_INSTRUCTION(BooleanNot); |
| 3950 | |
| 3951 | private: |
| 3952 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 3953 | }; |
| 3954 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3955 | class HTypeConversion : public HExpression<1> { |
| 3956 | public: |
| 3957 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3958 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3959 | : HExpression(result_type, |
| 3960 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 3961 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3962 | SetRawInputAt(0, input); |
| 3963 | DCHECK_NE(input->GetType(), result_type); |
| 3964 | } |
| 3965 | |
| 3966 | HInstruction* GetInput() const { return InputAt(0); } |
| 3967 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 3968 | Primitive::Type GetResultType() const { return GetType(); } |
| 3969 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3970 | // Required by the x86 and ARM code generators when producing calls |
| 3971 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3972 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3973 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 3974 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3975 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 3976 | // Try to statically evaluate the conversion and return a HConstant |
| 3977 | // containing the result. If the input cannot be converted, return nullptr. |
| 3978 | HConstant* TryStaticEvaluation() const; |
| 3979 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3980 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 3981 | Primitive::Type result_type) { |
| 3982 | // Some architectures may not require the 'GC' side effects, but at this point |
| 3983 | // in the compilation process we do not know what architecture we will |
| 3984 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 3985 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 3986 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3987 | return SideEffects::CanTriggerGC(); |
| 3988 | } |
| 3989 | return SideEffects::None(); |
| 3990 | } |
| 3991 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3992 | DECLARE_INSTRUCTION(TypeConversion); |
| 3993 | |
| 3994 | private: |
| 3995 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 3996 | }; |
| 3997 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 3998 | static constexpr uint32_t kNoRegNumber = -1; |
| 3999 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4000 | class HPhi : public HInstruction { |
| 4001 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4002 | HPhi(ArenaAllocator* arena, |
| 4003 | uint32_t reg_number, |
| 4004 | size_t number_of_inputs, |
| 4005 | Primitive::Type type, |
| 4006 | uint32_t dex_pc = kNoDexPc) |
| 4007 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4008 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4009 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4010 | type_(type), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4011 | is_live_(false), |
| 4012 | can_be_null_(true) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4013 | } |
| 4014 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4015 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4016 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4017 | switch (type) { |
| 4018 | case Primitive::kPrimBoolean: |
| 4019 | case Primitive::kPrimByte: |
| 4020 | case Primitive::kPrimShort: |
| 4021 | case Primitive::kPrimChar: |
| 4022 | return Primitive::kPrimInt; |
| 4023 | default: |
| 4024 | return type; |
| 4025 | } |
| 4026 | } |
| 4027 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4028 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4029 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4030 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4031 | |
| 4032 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4033 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4034 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4035 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4036 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4037 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4038 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4039 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4040 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4041 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4042 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4043 | void SetDead() { is_live_ = false; } |
| 4044 | void SetLive() { is_live_ = true; } |
| 4045 | bool IsDead() const { return !is_live_; } |
| 4046 | bool IsLive() const { return is_live_; } |
| 4047 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4048 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4049 | return other != nullptr |
| 4050 | && other->IsPhi() |
| 4051 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4052 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4053 | } |
| 4054 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4055 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4056 | // An equivalent phi is a phi having the same dex register and type. |
| 4057 | // It assumes that phis with the same dex register are adjacent. |
| 4058 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4059 | HInstruction* next = GetNext(); |
| 4060 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4061 | if (next->GetType() == GetType()) { |
| 4062 | return next->AsPhi(); |
| 4063 | } |
| 4064 | next = next->GetNext(); |
| 4065 | } |
| 4066 | return nullptr; |
| 4067 | } |
| 4068 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4069 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4070 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4071 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4072 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 4073 | DCHECK_LE(index, InputCount()); |
| 4074 | return inputs_[index]; |
| 4075 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4076 | |
| 4077 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4078 | DCHECK_LE(index, InputCount()); |
| 4079 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4080 | } |
| 4081 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4082 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4083 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4084 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4085 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4086 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4087 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4088 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4089 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4090 | }; |
| 4091 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4092 | class HNullCheck : public HExpression<1> { |
| 4093 | public: |
| 4094 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4095 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4096 | SetRawInputAt(0, value); |
| 4097 | } |
| 4098 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4099 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4100 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4101 | UNUSED(other); |
| 4102 | return true; |
| 4103 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4104 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4105 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4106 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4107 | bool CanThrow() const OVERRIDE { return true; } |
| 4108 | |
| 4109 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4110 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4111 | |
| 4112 | DECLARE_INSTRUCTION(NullCheck); |
| 4113 | |
| 4114 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4115 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4116 | }; |
| 4117 | |
| 4118 | class FieldInfo : public ValueObject { |
| 4119 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4120 | FieldInfo(MemberOffset field_offset, |
| 4121 | Primitive::Type field_type, |
| 4122 | bool is_volatile, |
| 4123 | uint32_t index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4124 | const DexFile& dex_file, |
| 4125 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4126 | : field_offset_(field_offset), |
| 4127 | field_type_(field_type), |
| 4128 | is_volatile_(is_volatile), |
| 4129 | index_(index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4130 | dex_file_(dex_file), |
| 4131 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4132 | |
| 4133 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4134 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4135 | uint32_t GetFieldIndex() const { return index_; } |
| 4136 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4137 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4138 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4139 | |
| 4140 | private: |
| 4141 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4142 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4143 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4144 | const uint32_t index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4145 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4146 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4147 | }; |
| 4148 | |
| 4149 | class HInstanceFieldGet : public HExpression<1> { |
| 4150 | public: |
| 4151 | HInstanceFieldGet(HInstruction* value, |
| 4152 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4153 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4154 | bool is_volatile, |
| 4155 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4156 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4157 | Handle<mirror::DexCache> dex_cache, |
| 4158 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4159 | : HExpression( |
| 4160 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4161 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4162 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4163 | SetRawInputAt(0, value); |
| 4164 | } |
| 4165 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4166 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4167 | |
| 4168 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4169 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4170 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4171 | } |
| 4172 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4173 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4174 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4178 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4179 | } |
| 4180 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4181 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4182 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4183 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4184 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4185 | |
| 4186 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4187 | |
| 4188 | private: |
| 4189 | const FieldInfo field_info_; |
| 4190 | |
| 4191 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4192 | }; |
| 4193 | |
| 4194 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4195 | public: |
| 4196 | HInstanceFieldSet(HInstruction* object, |
| 4197 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4198 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4199 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4200 | bool is_volatile, |
| 4201 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4202 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4203 | Handle<mirror::DexCache> dex_cache, |
| 4204 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4205 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4206 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4207 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4208 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4209 | SetRawInputAt(0, object); |
| 4210 | SetRawInputAt(1, value); |
| 4211 | } |
| 4212 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4213 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4214 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4215 | } |
| 4216 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4217 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4218 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4219 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4220 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4221 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4222 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4223 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4224 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4225 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4226 | |
| 4227 | private: |
| 4228 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4229 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4230 | |
| 4231 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4232 | }; |
| 4233 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4234 | class HArrayGet : public HExpression<2> { |
| 4235 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4236 | HArrayGet(HInstruction* array, |
| 4237 | HInstruction* index, |
| 4238 | Primitive::Type type, |
| 4239 | uint32_t dex_pc = kNoDexPc) |
| 4240 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4241 | SetRawInputAt(0, array); |
| 4242 | SetRawInputAt(1, index); |
| 4243 | } |
| 4244 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4245 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4246 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4247 | UNUSED(other); |
| 4248 | return true; |
| 4249 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4250 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4251 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4252 | // TODO: We can be smarter here. |
| 4253 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4254 | // which generates the implicit null check. There are cases when these can be removed |
| 4255 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4256 | // implicit check here (as long as the address falls in the first page). |
| 4257 | return false; |
| 4258 | } |
| 4259 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4260 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4261 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4262 | HInstruction* GetArray() const { return InputAt(0); } |
| 4263 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4264 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4265 | DECLARE_INSTRUCTION(ArrayGet); |
| 4266 | |
| 4267 | private: |
| 4268 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4269 | }; |
| 4270 | |
| 4271 | class HArraySet : public HTemplateInstruction<3> { |
| 4272 | public: |
| 4273 | HArraySet(HInstruction* array, |
| 4274 | HInstruction* index, |
| 4275 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4276 | Primitive::Type expected_component_type, |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4277 | uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4278 | : HTemplateInstruction( |
| 4279 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4280 | SideEffectsForArchRuntimeCalls(value->GetType())), dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4281 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4282 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
| 4283 | value_can_be_null_(true) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4284 | SetRawInputAt(0, array); |
| 4285 | SetRawInputAt(1, index); |
| 4286 | SetRawInputAt(2, value); |
| 4287 | } |
| 4288 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4289 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4290 | // We currently always call a runtime method to catch array store |
| 4291 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4292 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4293 | } |
| 4294 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4295 | // Can throw ArrayStoreException. |
| 4296 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4297 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4298 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4299 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4300 | // TODO: Same as for ArrayGet. |
| 4301 | return false; |
| 4302 | } |
| 4303 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4304 | void ClearNeedsTypeCheck() { |
| 4305 | needs_type_check_ = false; |
| 4306 | } |
| 4307 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4308 | void ClearValueCanBeNull() { |
| 4309 | value_can_be_null_ = false; |
| 4310 | } |
| 4311 | |
| 4312 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4313 | bool NeedsTypeCheck() const { return needs_type_check_; } |
| 4314 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4315 | HInstruction* GetArray() const { return InputAt(0); } |
| 4316 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4317 | HInstruction* GetValue() const { return InputAt(2); } |
| 4318 | |
| 4319 | Primitive::Type GetComponentType() const { |
| 4320 | // The Dex format does not type floating point index operations. Since the |
| 4321 | // `expected_component_type_` is set during building and can therefore not |
| 4322 | // be correct, we also check what is the value type. If it is a floating |
| 4323 | // point type, we must use that type. |
| 4324 | Primitive::Type value_type = GetValue()->GetType(); |
| 4325 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4326 | ? value_type |
| 4327 | : expected_component_type_; |
| 4328 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4329 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4330 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4331 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4332 | } |
| 4333 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4334 | DECLARE_INSTRUCTION(ArraySet); |
| 4335 | |
| 4336 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4337 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4338 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4339 | bool value_can_be_null_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4340 | |
| 4341 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4342 | }; |
| 4343 | |
| 4344 | class HArrayLength : public HExpression<1> { |
| 4345 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4346 | explicit HArrayLength(HInstruction* array, uint32_t dex_pc = kNoDexPc) |
| 4347 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4348 | // Note that arrays do not change length, so the instruction does not |
| 4349 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4350 | SetRawInputAt(0, array); |
| 4351 | } |
| 4352 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4353 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4354 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4355 | UNUSED(other); |
| 4356 | return true; |
| 4357 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4358 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4359 | return obj == InputAt(0); |
| 4360 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4361 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4362 | DECLARE_INSTRUCTION(ArrayLength); |
| 4363 | |
| 4364 | private: |
| 4365 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4366 | }; |
| 4367 | |
| 4368 | class HBoundsCheck : public HExpression<2> { |
| 4369 | public: |
| 4370 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4371 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4372 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4373 | SetRawInputAt(0, index); |
| 4374 | SetRawInputAt(1, length); |
| 4375 | } |
| 4376 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4377 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4378 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4379 | UNUSED(other); |
| 4380 | return true; |
| 4381 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4382 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4383 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4384 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4385 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4386 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4387 | |
| 4388 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4389 | |
| 4390 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4391 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4392 | }; |
| 4393 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4394 | /** |
| 4395 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4396 | * to stay live until the last HInstruction. This class |
| 4397 | * 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] | 4398 | * HInstruction stays live. `index` represents the stack location index of the |
| 4399 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4400 | */ |
| 4401 | class HTemporary : public HTemplateInstruction<0> { |
| 4402 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4403 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4404 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4405 | |
| 4406 | size_t GetIndex() const { return index_; } |
| 4407 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4408 | Primitive::Type GetType() const OVERRIDE { |
| 4409 | // The previous instruction is the one that will be stored in the temporary location. |
| 4410 | DCHECK(GetPrevious() != nullptr); |
| 4411 | return GetPrevious()->GetType(); |
| 4412 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4413 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4414 | DECLARE_INSTRUCTION(Temporary); |
| 4415 | |
| 4416 | private: |
| 4417 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4418 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4419 | }; |
| 4420 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4421 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4422 | public: |
| 4423 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4424 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4425 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4426 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4427 | return true; |
| 4428 | } |
| 4429 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4430 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4431 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4432 | |
| 4433 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4434 | |
| 4435 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4436 | // Only used for code generation, in order to share the same slow path between back edges |
| 4437 | // of a same loop. |
| 4438 | SlowPathCode* slow_path_; |
| 4439 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4440 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4441 | }; |
| 4442 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4443 | /** |
| 4444 | * Instruction to load a Class object. |
| 4445 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4446 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4447 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4448 | HLoadClass(HCurrentMethod* current_method, |
| 4449 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4450 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4451 | bool is_referrers_class, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4452 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4453 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4454 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4455 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4456 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4457 | generate_clinit_check_(false), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4458 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4459 | SetRawInputAt(0, current_method); |
| 4460 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4461 | |
| 4462 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4463 | |
| 4464 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4465 | return other->AsLoadClass()->type_index_ == type_index_; |
| 4466 | } |
| 4467 | |
| 4468 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4469 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4470 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4471 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4472 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4473 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4474 | bool NeedsEnvironment() const OVERRIDE { |
| 4475 | // Will call runtime and load the class if the class is not loaded yet. |
| 4476 | // TODO: finer grain decision. |
| 4477 | return !is_referrers_class_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4478 | } |
| 4479 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4480 | bool MustGenerateClinitCheck() const { |
| 4481 | return generate_clinit_check_; |
| 4482 | } |
| 4483 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4484 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
| 4485 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4486 | } |
| 4487 | |
| 4488 | bool CanCallRuntime() const { |
| 4489 | return MustGenerateClinitCheck() || !is_referrers_class_; |
| 4490 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4491 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4492 | bool CanThrow() const OVERRIDE { |
| 4493 | // May call runtime and and therefore can throw. |
| 4494 | // TODO: finer grain decision. |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4495 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4496 | } |
| 4497 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4498 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4499 | return loaded_class_rti_; |
| 4500 | } |
| 4501 | |
| 4502 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4503 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4504 | DCHECK(rti.IsExact()); |
| 4505 | loaded_class_rti_ = rti; |
| 4506 | } |
| 4507 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4508 | const DexFile& GetDexFile() { return dex_file_; } |
| 4509 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4510 | bool NeedsDexCache() const OVERRIDE { return !is_referrers_class_; } |
| 4511 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4512 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4513 | return SideEffects::CanTriggerGC(); |
| 4514 | } |
| 4515 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4516 | DECLARE_INSTRUCTION(LoadClass); |
| 4517 | |
| 4518 | private: |
| 4519 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4520 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4521 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4522 | // Whether this instruction must generate the initialization check. |
| 4523 | // Used for code generation. |
| 4524 | bool generate_clinit_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4525 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4526 | ReferenceTypeInfo loaded_class_rti_; |
| 4527 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4528 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4529 | }; |
| 4530 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4531 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4532 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4533 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4534 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4535 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4536 | SetRawInputAt(0, current_method); |
| 4537 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4538 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4539 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4540 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4541 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4542 | return other->AsLoadString()->string_index_ == string_index_; |
| 4543 | } |
| 4544 | |
| 4545 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4546 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4547 | uint32_t GetStringIndex() const { return string_index_; } |
| 4548 | |
| 4549 | // TODO: Can we deopt or debug when we resolve a string? |
| 4550 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4551 | bool NeedsDexCache() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4552 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4553 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4554 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4555 | return SideEffects::CanTriggerGC(); |
| 4556 | } |
| 4557 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4558 | DECLARE_INSTRUCTION(LoadString); |
| 4559 | |
| 4560 | private: |
| 4561 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4562 | |
| 4563 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4564 | }; |
| 4565 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4566 | /** |
| 4567 | * Performs an initialization check on its Class object input. |
| 4568 | */ |
| 4569 | class HClinitCheck : public HExpression<1> { |
| 4570 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4571 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4572 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4573 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4574 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4575 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4576 | SetRawInputAt(0, constant); |
| 4577 | } |
| 4578 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4579 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4580 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4581 | UNUSED(other); |
| 4582 | return true; |
| 4583 | } |
| 4584 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4585 | bool NeedsEnvironment() const OVERRIDE { |
| 4586 | // May call runtime to initialize the class. |
| 4587 | return true; |
| 4588 | } |
| 4589 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4590 | |
| 4591 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4592 | |
| 4593 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4594 | |
| 4595 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4596 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4597 | }; |
| 4598 | |
| 4599 | class HStaticFieldGet : public HExpression<1> { |
| 4600 | public: |
| 4601 | HStaticFieldGet(HInstruction* cls, |
| 4602 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4603 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4604 | bool is_volatile, |
| 4605 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4606 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4607 | Handle<mirror::DexCache> dex_cache, |
| 4608 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4609 | : HExpression( |
| 4610 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4611 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4612 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4613 | SetRawInputAt(0, cls); |
| 4614 | } |
| 4615 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4616 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4617 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4618 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4619 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4620 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 4621 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | size_t ComputeHashCode() const OVERRIDE { |
| 4625 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4626 | } |
| 4627 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4628 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4629 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4630 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4631 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4632 | |
| 4633 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 4634 | |
| 4635 | private: |
| 4636 | const FieldInfo field_info_; |
| 4637 | |
| 4638 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 4639 | }; |
| 4640 | |
| 4641 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 4642 | public: |
| 4643 | HStaticFieldSet(HInstruction* cls, |
| 4644 | HInstruction* value, |
| 4645 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4647 | bool is_volatile, |
| 4648 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4649 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4650 | Handle<mirror::DexCache> dex_cache, |
| 4651 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4652 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4653 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4654 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4655 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4656 | SetRawInputAt(0, cls); |
| 4657 | SetRawInputAt(1, value); |
| 4658 | } |
| 4659 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4660 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4661 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4662 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4663 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4664 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4665 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4666 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4667 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4668 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4669 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 4670 | |
| 4671 | private: |
| 4672 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4673 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4674 | |
| 4675 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 4676 | }; |
| 4677 | |
Calin Juravle | 23a8e35 | 2015-09-08 19:56:31 +0100 | [diff] [blame] | 4678 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 4679 | public: |
| 4680 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 4681 | Primitive::Type field_type, |
| 4682 | uint32_t field_index, |
| 4683 | uint32_t dex_pc) |
| 4684 | : HExpression(field_type, SideEffects::AllExceptGCDependency()), |
| 4685 | field_index_(field_index), |
| 4686 | dex_pc_(dex_pc) { |
| 4687 | SetRawInputAt(0, obj); |
| 4688 | } |
| 4689 | |
| 4690 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4691 | bool CanThrow() const OVERRIDE { return true; } |
| 4692 | |
| 4693 | Primitive::Type GetFieldType() const { return GetType(); } |
| 4694 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4695 | uint32_t GetDexPc() const { return dex_pc_; } |
| 4696 | |
| 4697 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 4698 | |
| 4699 | private: |
| 4700 | const uint32_t field_index_; |
| 4701 | const uint32_t dex_pc_; |
| 4702 | |
| 4703 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 4704 | }; |
| 4705 | |
| 4706 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 4707 | public: |
| 4708 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 4709 | HInstruction* value, |
| 4710 | Primitive::Type field_type, |
| 4711 | uint32_t field_index, |
| 4712 | uint32_t dex_pc) |
| 4713 | : HTemplateInstruction(SideEffects::AllExceptGCDependency()), |
| 4714 | field_type_(field_type), |
| 4715 | field_index_(field_index), |
| 4716 | dex_pc_(dex_pc) { |
| 4717 | DCHECK_EQ(field_type, value->GetType()); |
| 4718 | SetRawInputAt(0, obj); |
| 4719 | SetRawInputAt(1, value); |
| 4720 | } |
| 4721 | |
| 4722 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4723 | bool CanThrow() const OVERRIDE { return true; } |
| 4724 | |
| 4725 | Primitive::Type GetFieldType() const { return field_type_; } |
| 4726 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4727 | uint32_t GetDexPc() const { return dex_pc_; } |
| 4728 | |
| 4729 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 4730 | |
| 4731 | private: |
| 4732 | const Primitive::Type field_type_; |
| 4733 | const uint32_t field_index_; |
| 4734 | const uint32_t dex_pc_; |
| 4735 | |
| 4736 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 4737 | }; |
| 4738 | |
| 4739 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 4740 | public: |
| 4741 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 4742 | uint32_t field_index, |
| 4743 | uint32_t dex_pc) |
| 4744 | : HExpression(field_type, SideEffects::AllExceptGCDependency()), |
| 4745 | field_index_(field_index), |
| 4746 | dex_pc_(dex_pc) { |
| 4747 | } |
| 4748 | |
| 4749 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4750 | bool CanThrow() const OVERRIDE { return true; } |
| 4751 | |
| 4752 | Primitive::Type GetFieldType() const { return GetType(); } |
| 4753 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4754 | uint32_t GetDexPc() const { return dex_pc_; } |
| 4755 | |
| 4756 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 4757 | |
| 4758 | private: |
| 4759 | const uint32_t field_index_; |
| 4760 | const uint32_t dex_pc_; |
| 4761 | |
| 4762 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 4763 | }; |
| 4764 | |
| 4765 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 4766 | public: |
| 4767 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 4768 | Primitive::Type field_type, |
| 4769 | uint32_t field_index, |
| 4770 | uint32_t dex_pc) |
| 4771 | : HTemplateInstruction(SideEffects::AllExceptGCDependency()), |
| 4772 | field_type_(field_type), |
| 4773 | field_index_(field_index), |
| 4774 | dex_pc_(dex_pc) { |
| 4775 | DCHECK_EQ(field_type, value->GetType()); |
| 4776 | SetRawInputAt(0, value); |
| 4777 | } |
| 4778 | |
| 4779 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4780 | bool CanThrow() const OVERRIDE { return true; } |
| 4781 | |
| 4782 | Primitive::Type GetFieldType() const { return field_type_; } |
| 4783 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4784 | uint32_t GetDexPc() const { return dex_pc_; } |
| 4785 | |
| 4786 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 4787 | |
| 4788 | private: |
| 4789 | const Primitive::Type field_type_; |
| 4790 | const uint32_t field_index_; |
| 4791 | const uint32_t dex_pc_; |
| 4792 | |
| 4793 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 4794 | }; |
| 4795 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4796 | // Implement the move-exception DEX instruction. |
| 4797 | class HLoadException : public HExpression<0> { |
| 4798 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4799 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 4800 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4801 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 4802 | bool CanBeNull() const OVERRIDE { return false; } |
| 4803 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4804 | DECLARE_INSTRUCTION(LoadException); |
| 4805 | |
| 4806 | private: |
| 4807 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 4808 | }; |
| 4809 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4810 | // Implicit part of move-exception which clears thread-local exception storage. |
| 4811 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 4812 | class HClearException : public HTemplateInstruction<0> { |
| 4813 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4814 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 4815 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4816 | |
| 4817 | DECLARE_INSTRUCTION(ClearException); |
| 4818 | |
| 4819 | private: |
| 4820 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 4821 | }; |
| 4822 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4823 | class HThrow : public HTemplateInstruction<1> { |
| 4824 | public: |
| 4825 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4826 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4827 | SetRawInputAt(0, exception); |
| 4828 | } |
| 4829 | |
| 4830 | bool IsControlFlow() const OVERRIDE { return true; } |
| 4831 | |
| 4832 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4833 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4834 | bool CanThrow() const OVERRIDE { return true; } |
| 4835 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4836 | |
| 4837 | DECLARE_INSTRUCTION(Throw); |
| 4838 | |
| 4839 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4840 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 4841 | }; |
| 4842 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4843 | /** |
| 4844 | * Implementation strategies for the code generator of a HInstanceOf |
| 4845 | * or `HCheckCast`. |
| 4846 | */ |
| 4847 | enum class TypeCheckKind { |
| 4848 | kExactCheck, // Can do a single class compare. |
| 4849 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 4850 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 4851 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 4852 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 4853 | kArrayCheck // No optimization yet when checking against a generic array. |
| 4854 | }; |
| 4855 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4856 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4857 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4858 | HInstanceOf(HInstruction* object, |
| 4859 | HLoadClass* constant, |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4860 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4861 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4862 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4863 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4864 | dex_pc), |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4865 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4866 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4867 | SetRawInputAt(0, object); |
| 4868 | SetRawInputAt(1, constant); |
| 4869 | } |
| 4870 | |
| 4871 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4872 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4873 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4874 | return true; |
| 4875 | } |
| 4876 | |
| 4877 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4878 | return false; |
| 4879 | } |
| 4880 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4881 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 4882 | |
| 4883 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4884 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4885 | // Used only in code generation. |
| 4886 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4887 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 4888 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4889 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 4890 | return (check_kind == TypeCheckKind::kExactCheck) |
| 4891 | ? SideEffects::None() |
| 4892 | // Mips currently does runtime calls for any other checks. |
| 4893 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4894 | } |
| 4895 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4896 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4897 | |
| 4898 | private: |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4899 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4900 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4901 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4902 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 4903 | }; |
| 4904 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4905 | class HBoundType : public HExpression<1> { |
| 4906 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4907 | // Constructs an HBoundType with the given upper_bound. |
| 4908 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4909 | HBoundType(HInstruction* input, |
| 4910 | ReferenceTypeInfo upper_bound, |
| 4911 | bool upper_can_be_null, |
| 4912 | uint32_t dex_pc = kNoDexPc) |
| 4913 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4914 | upper_bound_(upper_bound), |
| 4915 | upper_can_be_null_(upper_can_be_null), |
| 4916 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 4917 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4918 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4919 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4920 | } |
| 4921 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4922 | // GetUpper* should only be used in reference type propagation. |
| 4923 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 4924 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4925 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4926 | void SetCanBeNull(bool can_be_null) { |
| 4927 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 4928 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4929 | } |
| 4930 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4931 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4932 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4933 | DECLARE_INSTRUCTION(BoundType); |
| 4934 | |
| 4935 | private: |
| 4936 | // Encodes the most upper class that this instruction can have. In other words |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4937 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 4938 | // It is used to bound the type in cases like: |
| 4939 | // if (x instanceof ClassX) { |
| 4940 | // // uper_bound_ will be ClassX |
| 4941 | // } |
| 4942 | const ReferenceTypeInfo upper_bound_; |
| 4943 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 4944 | // is false then can_be_null_ cannot be true). |
| 4945 | const bool upper_can_be_null_; |
| 4946 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4947 | |
| 4948 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 4949 | }; |
| 4950 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4951 | class HCheckCast : public HTemplateInstruction<2> { |
| 4952 | public: |
| 4953 | HCheckCast(HInstruction* object, |
| 4954 | HLoadClass* constant, |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4955 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4956 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4957 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4958 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4959 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4960 | SetRawInputAt(0, object); |
| 4961 | SetRawInputAt(1, constant); |
| 4962 | } |
| 4963 | |
| 4964 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4965 | |
| 4966 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4967 | return true; |
| 4968 | } |
| 4969 | |
| 4970 | bool NeedsEnvironment() const OVERRIDE { |
| 4971 | // Instruction may throw a CheckCastError. |
| 4972 | return true; |
| 4973 | } |
| 4974 | |
| 4975 | bool CanThrow() const OVERRIDE { return true; } |
| 4976 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4977 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4978 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4979 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4980 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4981 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4982 | |
| 4983 | DECLARE_INSTRUCTION(CheckCast); |
| 4984 | |
| 4985 | private: |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame^] | 4986 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4987 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4988 | |
| 4989 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4990 | }; |
| 4991 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4992 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 4993 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4994 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4995 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4996 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4997 | barrier_kind_(barrier_kind) {} |
| 4998 | |
| 4999 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5000 | |
| 5001 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5002 | |
| 5003 | private: |
| 5004 | const MemBarrierKind barrier_kind_; |
| 5005 | |
| 5006 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5007 | }; |
| 5008 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5009 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5010 | public: |
| 5011 | enum OperationKind { |
| 5012 | kEnter, |
| 5013 | kExit, |
| 5014 | }; |
| 5015 | |
| 5016 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5017 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5018 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5019 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5020 | SetRawInputAt(0, object); |
| 5021 | } |
| 5022 | |
| 5023 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5024 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5025 | |
| 5026 | bool CanThrow() const OVERRIDE { |
| 5027 | // Verifier guarantees that monitor-exit cannot throw. |
| 5028 | // This is important because it allows the HGraphBuilder to remove |
| 5029 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5030 | return IsEnter(); |
| 5031 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5032 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5033 | |
| 5034 | bool IsEnter() const { return kind_ == kEnter; } |
| 5035 | |
| 5036 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5037 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5038 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5039 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5040 | |
| 5041 | private: |
| 5042 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5043 | }; |
| 5044 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5045 | /** |
| 5046 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5047 | * of a String to a call to a StringFactory. Only baseline will see |
| 5048 | * the node at code generation, where it will be be treated as null. |
| 5049 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5050 | * in the instruction simplifier. |
| 5051 | */ |
| 5052 | class HFakeString : public HTemplateInstruction<0> { |
| 5053 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5054 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5055 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5056 | |
| 5057 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5058 | |
| 5059 | DECLARE_INSTRUCTION(FakeString); |
| 5060 | |
| 5061 | private: |
| 5062 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5063 | }; |
| 5064 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5065 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5066 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5067 | MoveOperands(Location source, |
| 5068 | Location destination, |
| 5069 | Primitive::Type type, |
| 5070 | HInstruction* instruction) |
| 5071 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5072 | |
| 5073 | Location GetSource() const { return source_; } |
| 5074 | Location GetDestination() const { return destination_; } |
| 5075 | |
| 5076 | void SetSource(Location value) { source_ = value; } |
| 5077 | void SetDestination(Location value) { destination_ = value; } |
| 5078 | |
| 5079 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5080 | // destination (but not the source). |
| 5081 | Location MarkPending() { |
| 5082 | DCHECK(!IsPending()); |
| 5083 | Location dest = destination_; |
| 5084 | destination_ = Location::NoLocation(); |
| 5085 | return dest; |
| 5086 | } |
| 5087 | |
| 5088 | void ClearPending(Location dest) { |
| 5089 | DCHECK(IsPending()); |
| 5090 | destination_ = dest; |
| 5091 | } |
| 5092 | |
| 5093 | bool IsPending() const { |
| 5094 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5095 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5096 | } |
| 5097 | |
| 5098 | // True if this blocks a move from the given location. |
| 5099 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5100 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | // A move is redundant if it's been eliminated, if its source and |
| 5104 | // destination are the same, or if its destination is unneeded. |
| 5105 | bool IsRedundant() const { |
| 5106 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5107 | } |
| 5108 | |
| 5109 | // We clear both operands to indicate move that's been eliminated. |
| 5110 | void Eliminate() { |
| 5111 | source_ = destination_ = Location::NoLocation(); |
| 5112 | } |
| 5113 | |
| 5114 | bool IsEliminated() const { |
| 5115 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5116 | return source_.IsInvalid(); |
| 5117 | } |
| 5118 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5119 | Primitive::Type GetType() const { return type_; } |
| 5120 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5121 | bool Is64BitMove() const { |
| 5122 | return Primitive::Is64BitType(type_); |
| 5123 | } |
| 5124 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5125 | HInstruction* GetInstruction() const { return instruction_; } |
| 5126 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5127 | private: |
| 5128 | Location source_; |
| 5129 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5130 | // The type this move is for. |
| 5131 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5132 | // The instruction this move is assocatied with. Null when this move is |
| 5133 | // for moving an input in the expected locations of user (including a phi user). |
| 5134 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5135 | // in the same parallel move. |
| 5136 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5137 | }; |
| 5138 | |
| 5139 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5140 | |
| 5141 | class HParallelMove : public HTemplateInstruction<0> { |
| 5142 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5143 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
| 5144 | : HTemplateInstruction(SideEffects::None(), dex_pc), moves_(arena, kDefaultNumberOfMoves) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5145 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5146 | void AddMove(Location source, |
| 5147 | Location destination, |
| 5148 | Primitive::Type type, |
| 5149 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5150 | DCHECK(source.IsValid()); |
| 5151 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5152 | if (kIsDebugBuild) { |
| 5153 | if (instruction != nullptr) { |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5154 | for (size_t i = 0, e = moves_.Size(); i < e; ++i) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5155 | if (moves_.Get(i).GetInstruction() == instruction) { |
| 5156 | // Special case the situation where the move is for the spill slot |
| 5157 | // of the instruction. |
| 5158 | if ((GetPrevious() == instruction) |
| 5159 | || ((GetPrevious() == nullptr) |
| 5160 | && instruction->IsPhi() |
| 5161 | && instruction->GetBlock() == GetBlock())) { |
| 5162 | DCHECK_NE(destination.GetKind(), moves_.Get(i).GetDestination().GetKind()) |
| 5163 | << "Doing parallel moves for the same instruction."; |
| 5164 | } else { |
| 5165 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5166 | } |
| 5167 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5168 | } |
| 5169 | } |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5170 | for (size_t i = 0, e = moves_.Size(); i < e; ++i) { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5171 | DCHECK(!destination.OverlapsWith(moves_.Get(i).GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5172 | << "Overlapped destination for two moves in a parallel move: " |
| 5173 | << moves_.Get(i).GetSource() << " ==> " << moves_.Get(i).GetDestination() << " and " |
| 5174 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5175 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5176 | } |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5177 | moves_.Add(MoveOperands(source, destination, type, instruction)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | MoveOperands* MoveOperandsAt(size_t index) const { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5181 | return moves_.GetRawStorage() + index; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | size_t NumMoves() const { return moves_.Size(); } |
| 5185 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5186 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5187 | |
| 5188 | private: |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5189 | GrowableArray<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5190 | |
| 5191 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5192 | }; |
| 5193 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5194 | } // namespace art |
| 5195 | |
| 5196 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5197 | #include "nodes_x86.h" |
| 5198 | #endif |
| 5199 | |
| 5200 | namespace art { |
| 5201 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5202 | class HGraphVisitor : public ValueObject { |
| 5203 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5204 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5205 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5206 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5207 | virtual void VisitInstruction(HInstruction* instruction) { UNUSED(instruction); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5208 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5209 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5210 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5211 | void VisitInsertionOrder(); |
| 5212 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5213 | // Visit the graph following dominator tree reverse post-order. |
| 5214 | void VisitReversePostOrder(); |
| 5215 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5216 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5217 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5218 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5219 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5220 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5221 | |
| 5222 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5223 | |
| 5224 | #undef DECLARE_VISIT_INSTRUCTION |
| 5225 | |
| 5226 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5227 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5228 | |
| 5229 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5230 | }; |
| 5231 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5232 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5233 | public: |
| 5234 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5235 | virtual ~HGraphDelegateVisitor() {} |
| 5236 | |
| 5237 | // Visit functions that delegate to to super class. |
| 5238 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5239 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5240 | |
| 5241 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5242 | |
| 5243 | #undef DECLARE_VISIT_INSTRUCTION |
| 5244 | |
| 5245 | private: |
| 5246 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5247 | }; |
| 5248 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5249 | class HInsertionOrderIterator : public ValueObject { |
| 5250 | public: |
| 5251 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5252 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5253 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
| 5254 | HBasicBlock* Current() const { return graph_.GetBlock(index_); } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5255 | void Advance() { ++index_; } |
| 5256 | |
| 5257 | private: |
| 5258 | const HGraph& graph_; |
| 5259 | size_t index_; |
| 5260 | |
| 5261 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5262 | }; |
| 5263 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5264 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5265 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5266 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5267 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5268 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5269 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5270 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5271 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5272 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5273 | void Advance() { ++index_; } |
| 5274 | |
| 5275 | private: |
| 5276 | const HGraph& graph_; |
| 5277 | size_t index_; |
| 5278 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5279 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5280 | }; |
| 5281 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5282 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5283 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5284 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5285 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5286 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5287 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5288 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5289 | |
| 5290 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5291 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5292 | void Advance() { --index_; } |
| 5293 | |
| 5294 | private: |
| 5295 | const HGraph& graph_; |
| 5296 | size_t index_; |
| 5297 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5298 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5299 | }; |
| 5300 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5301 | class HLinearPostOrderIterator : public ValueObject { |
| 5302 | public: |
| 5303 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5304 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5305 | |
| 5306 | bool Done() const { return index_ == 0; } |
| 5307 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5308 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5309 | |
| 5310 | void Advance() { |
| 5311 | --index_; |
| 5312 | DCHECK_GE(index_, 0U); |
| 5313 | } |
| 5314 | |
| 5315 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5316 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5317 | size_t index_; |
| 5318 | |
| 5319 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5320 | }; |
| 5321 | |
| 5322 | class HLinearOrderIterator : public ValueObject { |
| 5323 | public: |
| 5324 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5325 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5326 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5327 | bool Done() const { return index_ == order_.size(); } |
| 5328 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5329 | void Advance() { ++index_; } |
| 5330 | |
| 5331 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5332 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5333 | size_t index_; |
| 5334 | |
| 5335 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5336 | }; |
| 5337 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5338 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5339 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5340 | // block id. |
| 5341 | class HBlocksInLoopIterator : public ValueObject { |
| 5342 | public: |
| 5343 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5344 | : blocks_in_loop_(info.GetBlocks()), |
| 5345 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5346 | index_(0) { |
| 5347 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5348 | Advance(); |
| 5349 | } |
| 5350 | } |
| 5351 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5352 | bool Done() const { return index_ == blocks_.size(); } |
| 5353 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5354 | void Advance() { |
| 5355 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5356 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5357 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5358 | break; |
| 5359 | } |
| 5360 | } |
| 5361 | } |
| 5362 | |
| 5363 | private: |
| 5364 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5365 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5366 | size_t index_; |
| 5367 | |
| 5368 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5369 | }; |
| 5370 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5371 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5372 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5373 | // post order. |
| 5374 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5375 | public: |
| 5376 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5377 | : blocks_in_loop_(info.GetBlocks()), |
| 5378 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5379 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5380 | DCHECK(!blocks_.empty()); |
| 5381 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5382 | Advance(); |
| 5383 | } |
| 5384 | } |
| 5385 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5386 | bool Done() const { return index_ == blocks_.size(); } |
| 5387 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5388 | void Advance() { |
| 5389 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5390 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5391 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5392 | break; |
| 5393 | } |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | private: |
| 5398 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5399 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5400 | size_t index_; |
| 5401 | |
| 5402 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5403 | }; |
| 5404 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5405 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5406 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5407 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5408 | : constant->AsLongConstant()->GetValue(); |
| 5409 | } |
| 5410 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5411 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5412 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5413 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5414 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5415 | // times and provide different class resolution but no two class loaders should ever |
| 5416 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5417 | // all sorts of weird failures. |
| 5418 | return &lhs == &rhs; |
| 5419 | } |
| 5420 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5421 | } // namespace art |
| 5422 | |
| 5423 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |