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 | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 373 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 374 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 375 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 376 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 377 | template <class InstructionType, typename ValueType> |
| 378 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 379 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 380 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 381 | // Try to find an existing constant of the given value. |
| 382 | InstructionType* constant = nullptr; |
| 383 | auto cached_constant = cache->find(value); |
| 384 | if (cached_constant != cache->end()) { |
| 385 | constant = cached_constant->second; |
| 386 | } |
| 387 | |
| 388 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 389 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 390 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 391 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 392 | cache->Overwrite(value, constant); |
| 393 | InsertConstant(constant); |
| 394 | } |
| 395 | return constant; |
| 396 | } |
| 397 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 398 | void InsertConstant(HConstant* instruction); |
| 399 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 400 | // Cache a float constant into the graph. This method should only be |
| 401 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 402 | void CacheFloatConstant(HFloatConstant* constant); |
| 403 | |
| 404 | // See CacheFloatConstant comment. |
| 405 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 406 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 407 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 408 | |
| 409 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 410 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 411 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 412 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 413 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 414 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 415 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 416 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 417 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 418 | HBasicBlock* entry_block_; |
| 419 | HBasicBlock* exit_block_; |
| 420 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 421 | // 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] | 422 | uint16_t maximum_number_of_out_vregs_; |
| 423 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 424 | // The number of virtual registers in this method. Contains the parameters. |
| 425 | uint16_t number_of_vregs_; |
| 426 | |
| 427 | // The number of virtual registers used by parameters of this method. |
| 428 | uint16_t number_of_in_vregs_; |
| 429 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 430 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 431 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 432 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 433 | // Has bounds checks. We can totally skip BCE if it's false. |
| 434 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 435 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 436 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 437 | // try/catch-related passes if false. |
| 438 | bool has_try_catch_; |
| 439 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 440 | // Indicates whether the graph should be compiled in a way that |
| 441 | // ensures full debuggability. If false, we can apply more |
| 442 | // aggressive optimizations that may limit the level of debugging. |
| 443 | const bool debuggable_; |
| 444 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 445 | // 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] | 446 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 447 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 448 | // The dex file from which the method is from. |
| 449 | const DexFile& dex_file_; |
| 450 | |
| 451 | // The method index in the dex file. |
| 452 | const uint32_t method_idx_; |
| 453 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 454 | // If inlined, this encodes how the callee is being invoked. |
| 455 | const InvokeType invoke_type_; |
| 456 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 457 | // Whether the graph has been transformed to SSA form. Only used |
| 458 | // in debug mode to ensure we are not using properties only valid |
| 459 | // for non-SSA form (like the number of temporaries). |
| 460 | bool in_ssa_form_; |
| 461 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 462 | const bool should_generate_constructor_barrier_; |
| 463 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 464 | const InstructionSet instruction_set_; |
| 465 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 466 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 467 | HNullConstant* cached_null_constant_; |
| 468 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 469 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 470 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 471 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 472 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 473 | HCurrentMethod* cached_current_method_; |
| 474 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 475 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 476 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 477 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 478 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 479 | }; |
| 480 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 481 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 482 | public: |
| 483 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 484 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 485 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 486 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 487 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 488 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 489 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 490 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 491 | |
| 492 | HBasicBlock* GetHeader() const { |
| 493 | return header_; |
| 494 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 495 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 496 | void SetHeader(HBasicBlock* block) { |
| 497 | header_ = block; |
| 498 | } |
| 499 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 500 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 501 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 502 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 503 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 504 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 505 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 508 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 509 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 510 | } |
| 511 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 512 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 513 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 514 | } |
| 515 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 516 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 517 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 520 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 521 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 522 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 523 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 524 | } |
| 525 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 526 | // Returns the lifetime position of the back edge that has the |
| 527 | // greatest lifetime position. |
| 528 | size_t GetLifetimeEnd() const; |
| 529 | |
| 530 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 531 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 534 | // 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] | 535 | // that is the header dominates the back edge. |
| 536 | bool Populate(); |
| 537 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 538 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 539 | // Populate(). If there are no back edges left, the loop info is completely |
| 540 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 541 | // inner loops first. |
| 542 | void Update(); |
| 543 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 544 | // Returns whether this loop information contains `block`. |
| 545 | // Note that this loop information *must* be populated before entering this function. |
| 546 | bool Contains(const HBasicBlock& block) const; |
| 547 | |
| 548 | // Returns whether this loop information is an inner loop of `other`. |
| 549 | // Note that `other` *must* be populated before entering this function. |
| 550 | bool IsIn(const HLoopInformation& other) const; |
| 551 | |
| 552 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 553 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 554 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 555 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 556 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 557 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 558 | // Internal recursive implementation of `Populate`. |
| 559 | void PopulateRecursive(HBasicBlock* block); |
| 560 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 561 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 562 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 563 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 564 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 565 | |
| 566 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 567 | }; |
| 568 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 569 | // Stores try/catch information for basic blocks. |
| 570 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 571 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 572 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 573 | public: |
| 574 | // Try block information constructor. |
| 575 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 576 | : try_entry_(&try_entry), |
| 577 | catch_dex_file_(nullptr), |
| 578 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 579 | DCHECK(try_entry_ != nullptr); |
| 580 | } |
| 581 | |
| 582 | // Catch block information constructor. |
| 583 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 584 | : try_entry_(nullptr), |
| 585 | catch_dex_file_(&dex_file), |
| 586 | catch_type_index_(catch_type_index) {} |
| 587 | |
| 588 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 589 | |
| 590 | const HTryBoundary& GetTryEntry() const { |
| 591 | DCHECK(IsTryBlock()); |
| 592 | return *try_entry_; |
| 593 | } |
| 594 | |
| 595 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 596 | |
| 597 | bool IsCatchAllTypeIndex() const { |
| 598 | DCHECK(IsCatchBlock()); |
| 599 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 600 | } |
| 601 | |
| 602 | uint16_t GetCatchTypeIndex() const { |
| 603 | DCHECK(IsCatchBlock()); |
| 604 | return catch_type_index_; |
| 605 | } |
| 606 | |
| 607 | const DexFile& GetCatchDexFile() const { |
| 608 | DCHECK(IsCatchBlock()); |
| 609 | return *catch_dex_file_; |
| 610 | } |
| 611 | |
| 612 | private: |
| 613 | // One of possibly several TryBoundary instructions entering the block's try. |
| 614 | // Only set for try blocks. |
| 615 | const HTryBoundary* try_entry_; |
| 616 | |
| 617 | // Exception type information. Only set for catch blocks. |
| 618 | const DexFile* catch_dex_file_; |
| 619 | const uint16_t catch_type_index_; |
| 620 | }; |
| 621 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 622 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 623 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 624 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 625 | // A block in a method. Contains the list of instructions represented |
| 626 | // as a double linked list. Each block knows its predecessors and |
| 627 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 628 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 629 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 630 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 631 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 632 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 633 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 634 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 635 | loop_information_(nullptr), |
| 636 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 637 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 638 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 639 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 640 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 641 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 642 | try_catch_information_(nullptr) { |
| 643 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 644 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 645 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 646 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 647 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 648 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 649 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 652 | HBasicBlock* GetPredecessor(size_t pred_idx) const { |
| 653 | DCHECK_LT(pred_idx, predecessors_.size()); |
| 654 | return predecessors_[pred_idx]; |
| 655 | } |
| 656 | |
| 657 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 658 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 661 | HBasicBlock* GetSuccessor(size_t succ_idx) const { |
| 662 | DCHECK_LT(succ_idx, successors_.size()); |
| 663 | return successors_[succ_idx]; |
| 664 | } |
| 665 | |
| 666 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 667 | return ContainsElement(successors_, block, start_from); |
| 668 | } |
| 669 | |
| 670 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 671 | return dominated_blocks_; |
| 672 | } |
| 673 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 674 | bool IsEntryBlock() const { |
| 675 | return graph_->GetEntryBlock() == this; |
| 676 | } |
| 677 | |
| 678 | bool IsExitBlock() const { |
| 679 | return graph_->GetExitBlock() == this; |
| 680 | } |
| 681 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 682 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 683 | bool IsSingleTryBoundary() const; |
| 684 | |
| 685 | // Returns true if this block emits nothing but a jump. |
| 686 | bool IsSingleJump() const { |
| 687 | HLoopInformation* loop_info = GetLoopInformation(); |
| 688 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 689 | // Back edges generate a suspend check. |
| 690 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 691 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 692 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 693 | void AddBackEdge(HBasicBlock* back_edge) { |
| 694 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 695 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 696 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 697 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 698 | loop_information_->AddBackEdge(back_edge); |
| 699 | } |
| 700 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 701 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 702 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 703 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 704 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 705 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 706 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 707 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 708 | HBasicBlock* GetDominator() const { return dominator_; } |
| 709 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 710 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 711 | |
| 712 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 713 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 714 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 715 | |
| 716 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 717 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 718 | } |
| 719 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 720 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 721 | |
| 722 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 723 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 726 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 727 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 728 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 729 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 730 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 731 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 732 | |
| 733 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 734 | successors_.push_back(block); |
| 735 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 736 | } |
| 737 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 738 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 739 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 740 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 741 | new_block->predecessors_.push_back(this); |
| 742 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 745 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 746 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 747 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 748 | new_block->successors_.push_back(this); |
| 749 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 752 | // Insert `this` between `predecessor` and `successor. This method |
| 753 | // preserves the indicies, and will update the first edge found between |
| 754 | // `predecessor` and `successor`. |
| 755 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 756 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 757 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 758 | successor->predecessors_[predecessor_index] = this; |
| 759 | predecessor->successors_[successor_index] = this; |
| 760 | successors_.push_back(successor); |
| 761 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 762 | } |
| 763 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 764 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 765 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 766 | } |
| 767 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 768 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 769 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 770 | } |
| 771 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 772 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 773 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 777 | predecessors_.push_back(block); |
| 778 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 781 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 782 | DCHECK_EQ(predecessors_.size(), 2u); |
| 783 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 784 | } |
| 785 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 786 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 787 | DCHECK_EQ(successors_.size(), 2u); |
| 788 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 789 | } |
| 790 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 791 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 792 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 793 | } |
| 794 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 795 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 796 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 797 | } |
| 798 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 799 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 800 | DCHECK_EQ(GetPredecessors().size(), 1u); |
| 801 | return GetPredecessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 805 | DCHECK_EQ(GetSuccessors().size(), 1u); |
| 806 | return GetSuccessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | // Returns whether the first occurrence of `predecessor` in the list of |
| 810 | // predecessors is at index `idx`. |
| 811 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 812 | DCHECK_EQ(GetPredecessor(idx), predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 813 | return GetPredecessorIndexOf(predecessor) == idx; |
| 814 | } |
| 815 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 816 | // Returns the number of non-exceptional successors. SsaChecker ensures that |
| 817 | // these are stored at the beginning of the successor list. |
| 818 | size_t NumberOfNormalSuccessors() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 819 | return EndsWithTryBoundary() ? 1 : GetSuccessors().size(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 820 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 821 | |
| 822 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 823 | // created, latter block. Note that this method will add the block to the |
| 824 | // graph, create a Goto at the end of the former block and will create an edge |
| 825 | // between the blocks. It will not, however, update the reverse post order or |
| 826 | // loop information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 827 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 828 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 829 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 830 | // created block. Note that this method just updates raw block information, |
| 831 | // like predecessors, successors, dominators, and instruction list. It does not |
| 832 | // update the graph, reverse post order, loop information, nor make sure the |
| 833 | // blocks are consistent (for example ending with a control flow instruction). |
| 834 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 835 | |
| 836 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 837 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 838 | // that this method does not update the graph, reverse post order, loop |
| 839 | // information, nor make sure the blocks are consistent (for example ending |
| 840 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 841 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 842 | |
| 843 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 844 | // of `this` are moved to `other`. |
| 845 | // Note that this method does not update the graph, reverse post order, loop |
| 846 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 847 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 848 | void ReplaceWith(HBasicBlock* other); |
| 849 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 850 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 851 | // order, links to predecessors, successors, dominators and deletes the block |
| 852 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 853 | // predecessor of `other` and vice versa. |
| 854 | void MergeWith(HBasicBlock* other); |
| 855 | |
| 856 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 857 | // removes it from all loops it is included in and eventually from the graph. |
| 858 | // The block must not dominate any other block. Predecessors and successors |
| 859 | // are safely updated. |
| 860 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 861 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 862 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 863 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 864 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 865 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 866 | // Replace instruction `initial` with `replacement` within this block. |
| 867 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 868 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 869 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 870 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 871 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 872 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 873 | // instruction is not in use and removes it from the use lists of its inputs. |
| 874 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 875 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 876 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 877 | |
| 878 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 879 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 880 | } |
| 881 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 882 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 883 | DCHECK(IsLoopHeader()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 884 | return GetPredecessor(0) == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 885 | } |
| 886 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 887 | HLoopInformation* GetLoopInformation() const { |
| 888 | return loop_information_; |
| 889 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 890 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 891 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 892 | // 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] | 893 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 894 | void SetInLoop(HLoopInformation* info) { |
| 895 | if (IsLoopHeader()) { |
| 896 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 897 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 898 | loop_information_ = info; |
| 899 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 900 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 901 | // Note that a non loop header having a loop information means this loop information |
| 902 | // has already been populated |
| 903 | loop_information_ = info; |
| 904 | } else { |
| 905 | // Block is part of an inner loop. Do not update the loop information. |
| 906 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 907 | // at this point, because this method is being called while populating `info`. |
| 908 | } |
| 909 | } |
| 910 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 911 | // Raw update of the loop information. |
| 912 | void SetLoopInformation(HLoopInformation* info) { |
| 913 | loop_information_ = info; |
| 914 | } |
| 915 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 916 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 917 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 918 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 919 | |
| 920 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 921 | try_catch_information_ = try_catch_information; |
| 922 | } |
| 923 | |
| 924 | bool IsTryBlock() const { |
| 925 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 926 | } |
| 927 | |
| 928 | bool IsCatchBlock() const { |
| 929 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 930 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 931 | |
| 932 | // Returns the try entry that this block's successors should have. They will |
| 933 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 934 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 935 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 936 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 937 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 938 | bool Dominates(HBasicBlock* block) const; |
| 939 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 940 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 941 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 942 | |
| 943 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 944 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 945 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 946 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 947 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 948 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 949 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 950 | bool HasSinglePhi() const; |
| 951 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 952 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 953 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 954 | ArenaVector<HBasicBlock*> predecessors_; |
| 955 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 956 | HInstructionList instructions_; |
| 957 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 958 | HLoopInformation* loop_information_; |
| 959 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 960 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 961 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 962 | // The dex program counter of the first instruction of this block. |
| 963 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 964 | size_t lifetime_start_; |
| 965 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 966 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 967 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 968 | friend class HGraph; |
| 969 | friend class HInstruction; |
| 970 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 971 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 972 | }; |
| 973 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 974 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 975 | // from the innermost to the outermost. |
| 976 | class HLoopInformationOutwardIterator : public ValueObject { |
| 977 | public: |
| 978 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 979 | : current_(block.GetLoopInformation()) {} |
| 980 | |
| 981 | bool Done() const { return current_ == nullptr; } |
| 982 | |
| 983 | void Advance() { |
| 984 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 985 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | HLoopInformation* Current() const { |
| 989 | DCHECK(!Done()); |
| 990 | return current_; |
| 991 | } |
| 992 | |
| 993 | private: |
| 994 | HLoopInformation* current_; |
| 995 | |
| 996 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 997 | }; |
| 998 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 999 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1000 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1001 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1002 | M(ArrayGet, Instruction) \ |
| 1003 | M(ArrayLength, Instruction) \ |
| 1004 | M(ArraySet, Instruction) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1005 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1006 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1007 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1008 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1009 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1010 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1011 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1012 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1013 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1014 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1015 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1016 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1017 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1018 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1019 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1020 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1021 | M(FloatConstant, Constant) \ |
| 1022 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1023 | M(GreaterThan, Condition) \ |
| 1024 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1025 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1026 | M(InstanceFieldGet, Instruction) \ |
| 1027 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1028 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1029 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1030 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1031 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1032 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1033 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1034 | M(LessThan, Condition) \ |
| 1035 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1036 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1037 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1038 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1039 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1040 | M(Local, Instruction) \ |
| 1041 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1042 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1043 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1044 | M(Mul, BinaryOperation) \ |
| 1045 | M(Neg, UnaryOperation) \ |
| 1046 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1047 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1048 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1049 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1050 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1051 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1052 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1053 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1054 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1055 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1056 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1057 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1058 | M(Return, Instruction) \ |
| 1059 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1060 | M(Shl, BinaryOperation) \ |
| 1061 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1062 | M(StaticFieldGet, Instruction) \ |
| 1063 | M(StaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1064 | M(StoreLocal, Instruction) \ |
| 1065 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1066 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1067 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1068 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1069 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1070 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1071 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1072 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1073 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1074 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1075 | |
| 1076 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1077 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1078 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1079 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1080 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1081 | M(X86ComputeBaseMethodAddress, Instruction) \ |
| 1082 | M(X86LoadFromConstantTable, Instruction) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1083 | |
| 1084 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1085 | |
| 1086 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1087 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1088 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1089 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1090 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1091 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1092 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1093 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1094 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1095 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1096 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1097 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1098 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1099 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1100 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1101 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1102 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1103 | #undef FORWARD_DECLARATION |
| 1104 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1105 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1106 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1107 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1108 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1109 | H##type* As##type() OVERRIDE { return this; } \ |
| 1110 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1111 | return other->Is##type(); \ |
| 1112 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1113 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1114 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1115 | template <typename T> class HUseList; |
| 1116 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1117 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1118 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1119 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1120 | HUseListNode* GetPrevious() const { return prev_; } |
| 1121 | HUseListNode* GetNext() const { return next_; } |
| 1122 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1123 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1124 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1125 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1126 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1127 | HUseListNode(T user, size_t index) |
| 1128 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1129 | |
| 1130 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1131 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1132 | HUseListNode<T>* prev_; |
| 1133 | HUseListNode<T>* next_; |
| 1134 | |
| 1135 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1136 | |
| 1137 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1138 | }; |
| 1139 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1140 | template <typename T> |
| 1141 | class HUseList : public ValueObject { |
| 1142 | public: |
| 1143 | HUseList() : first_(nullptr) {} |
| 1144 | |
| 1145 | void Clear() { |
| 1146 | first_ = nullptr; |
| 1147 | } |
| 1148 | |
| 1149 | // Adds a new entry at the beginning of the use list and returns |
| 1150 | // the newly created node. |
| 1151 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1152 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1153 | if (IsEmpty()) { |
| 1154 | first_ = new_node; |
| 1155 | } else { |
| 1156 | first_->prev_ = new_node; |
| 1157 | new_node->next_ = first_; |
| 1158 | first_ = new_node; |
| 1159 | } |
| 1160 | return new_node; |
| 1161 | } |
| 1162 | |
| 1163 | HUseListNode<T>* GetFirst() const { |
| 1164 | return first_; |
| 1165 | } |
| 1166 | |
| 1167 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1168 | DCHECK(node != nullptr); |
| 1169 | DCHECK(Contains(node)); |
| 1170 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1171 | if (node->prev_ != nullptr) { |
| 1172 | node->prev_->next_ = node->next_; |
| 1173 | } |
| 1174 | if (node->next_ != nullptr) { |
| 1175 | node->next_->prev_ = node->prev_; |
| 1176 | } |
| 1177 | if (node == first_) { |
| 1178 | first_ = node->next_; |
| 1179 | } |
| 1180 | } |
| 1181 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1182 | bool Contains(const HUseListNode<T>* node) const { |
| 1183 | if (node == nullptr) { |
| 1184 | return false; |
| 1185 | } |
| 1186 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1187 | if (current == node) { |
| 1188 | return true; |
| 1189 | } |
| 1190 | } |
| 1191 | return false; |
| 1192 | } |
| 1193 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1194 | bool IsEmpty() const { |
| 1195 | return first_ == nullptr; |
| 1196 | } |
| 1197 | |
| 1198 | bool HasOnlyOneUse() const { |
| 1199 | return first_ != nullptr && first_->next_ == nullptr; |
| 1200 | } |
| 1201 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1202 | size_t SizeSlow() const { |
| 1203 | size_t count = 0; |
| 1204 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1205 | ++count; |
| 1206 | } |
| 1207 | return count; |
| 1208 | } |
| 1209 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1210 | private: |
| 1211 | HUseListNode<T>* first_; |
| 1212 | }; |
| 1213 | |
| 1214 | template<typename T> |
| 1215 | class HUseIterator : public ValueObject { |
| 1216 | public: |
| 1217 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1218 | |
| 1219 | bool Done() const { return current_ == nullptr; } |
| 1220 | |
| 1221 | void Advance() { |
| 1222 | DCHECK(!Done()); |
| 1223 | current_ = current_->GetNext(); |
| 1224 | } |
| 1225 | |
| 1226 | HUseListNode<T>* Current() const { |
| 1227 | DCHECK(!Done()); |
| 1228 | return current_; |
| 1229 | } |
| 1230 | |
| 1231 | private: |
| 1232 | HUseListNode<T>* current_; |
| 1233 | |
| 1234 | friend class HValue; |
| 1235 | }; |
| 1236 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1237 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1238 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1239 | // by the used instructions. |
| 1240 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1241 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1242 | public: |
| 1243 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1244 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1245 | |
| 1246 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1247 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1248 | DCHECK(instruction_ != nullptr); |
| 1249 | DCHECK(use_node_ != nullptr); |
| 1250 | DCHECK(old_record.use_node_ == nullptr); |
| 1251 | } |
| 1252 | |
| 1253 | HInstruction* GetInstruction() const { return instruction_; } |
| 1254 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1255 | |
| 1256 | private: |
| 1257 | // Instruction used by the user. |
| 1258 | HInstruction* instruction_; |
| 1259 | |
| 1260 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1261 | HUseListNode<T>* use_node_; |
| 1262 | }; |
| 1263 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1264 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1265 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1266 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1267 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1268 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1269 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1270 | * modify the value of a reference field read [although it may modify the |
| 1271 | * reference fetch prior to reading the field, which is represented by its own |
| 1272 | * write/read dependence]). The analysis makes conservative points-to |
| 1273 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1274 | * the same, and any reference read depends on any reference read without |
| 1275 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1276 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1277 | * The internal representation uses 38-bit and is described in the table below. |
| 1278 | * The first line indicates the side effect, and for field/array accesses the |
| 1279 | * second line indicates the type of the access (in the order of the |
| 1280 | * Primitive::Type enum). |
| 1281 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1282 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1283 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1284 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1285 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1286 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1287 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1288 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1289 | * |
| 1290 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1291 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1292 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1293 | class SideEffects : public ValueObject { |
| 1294 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1295 | SideEffects() : flags_(0) {} |
| 1296 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1297 | static SideEffects None() { |
| 1298 | return SideEffects(0); |
| 1299 | } |
| 1300 | |
| 1301 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1302 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1303 | } |
| 1304 | |
| 1305 | static SideEffects AllChanges() { |
| 1306 | return SideEffects(kAllChangeBits); |
| 1307 | } |
| 1308 | |
| 1309 | static SideEffects AllDependencies() { |
| 1310 | return SideEffects(kAllDependOnBits); |
| 1311 | } |
| 1312 | |
| 1313 | static SideEffects AllExceptGCDependency() { |
| 1314 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1315 | } |
| 1316 | |
| 1317 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1318 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1319 | } |
| 1320 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1321 | static SideEffects AllWrites() { |
| 1322 | return SideEffects(kAllWrites); |
| 1323 | } |
| 1324 | |
| 1325 | static SideEffects AllReads() { |
| 1326 | return SideEffects(kAllReads); |
| 1327 | } |
| 1328 | |
| 1329 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1330 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1331 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1332 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1333 | } |
| 1334 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1335 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1336 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1337 | } |
| 1338 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1339 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1340 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1341 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1342 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1346 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1347 | } |
| 1348 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1349 | static SideEffects CanTriggerGC() { |
| 1350 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1351 | } |
| 1352 | |
| 1353 | static SideEffects DependsOnGC() { |
| 1354 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1355 | } |
| 1356 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1357 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1358 | SideEffects Union(SideEffects other) const { |
| 1359 | return SideEffects(flags_ | other.flags_); |
| 1360 | } |
| 1361 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1362 | SideEffects Exclusion(SideEffects other) const { |
| 1363 | return SideEffects(flags_ & ~other.flags_); |
| 1364 | } |
| 1365 | |
| 1366 | bool Includes(SideEffects other) const { |
| 1367 | return (other.flags_ & flags_) == other.flags_; |
| 1368 | } |
| 1369 | |
| 1370 | bool HasSideEffects() const { |
| 1371 | return (flags_ & kAllChangeBits); |
| 1372 | } |
| 1373 | |
| 1374 | bool HasDependencies() const { |
| 1375 | return (flags_ & kAllDependOnBits); |
| 1376 | } |
| 1377 | |
| 1378 | // Returns true if there are no side effects or dependencies. |
| 1379 | bool DoesNothing() const { |
| 1380 | return flags_ == 0; |
| 1381 | } |
| 1382 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1383 | // Returns true if something is written. |
| 1384 | bool DoesAnyWrite() const { |
| 1385 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1386 | } |
| 1387 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1388 | // Returns true if something is read. |
| 1389 | bool DoesAnyRead() const { |
| 1390 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1393 | // Returns true if potentially everything is written and read |
| 1394 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1395 | bool DoesAllReadWrite() const { |
| 1396 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1397 | } |
| 1398 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1399 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1400 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | // Returns true if this may read something written by other. |
| 1404 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1405 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1406 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1410 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1411 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1412 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1413 | for (int s = kLastBit; s >= 0; s--) { |
| 1414 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1415 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1416 | // This is a bit for the GC side effect. |
| 1417 | if (current_bit_is_set) { |
| 1418 | flags += "GC"; |
| 1419 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1420 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1421 | } else { |
| 1422 | // This is a bit for the array/field analysis. |
| 1423 | // The underscore character stands for the 'can trigger GC' bit. |
| 1424 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1425 | if (current_bit_is_set) { |
| 1426 | flags += kDebug[s]; |
| 1427 | } |
| 1428 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1429 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1430 | flags += "|"; |
| 1431 | } |
| 1432 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1433 | } |
| 1434 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1435 | } |
| 1436 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1437 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1438 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1439 | private: |
| 1440 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1441 | |
| 1442 | static constexpr int kFieldWriteOffset = 0; |
| 1443 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1444 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1445 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1446 | |
| 1447 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1448 | |
| 1449 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1450 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1451 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1452 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1453 | |
| 1454 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1455 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1456 | |
| 1457 | // Aliases. |
| 1458 | |
| 1459 | static_assert(kChangeBits == kDependOnBits, |
| 1460 | "the 'change' bits should match the 'depend on' bits."); |
| 1461 | |
| 1462 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1463 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1464 | static constexpr uint64_t kAllWrites = |
| 1465 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1466 | static constexpr uint64_t kAllReads = |
| 1467 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1468 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1469 | // Work around the fact that HIR aliases I/F and J/D. |
| 1470 | // TODO: remove this interceptor once HIR types are clean |
| 1471 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1472 | switch (type) { |
| 1473 | case Primitive::kPrimInt: |
| 1474 | case Primitive::kPrimFloat: |
| 1475 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1476 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1477 | case Primitive::kPrimLong: |
| 1478 | case Primitive::kPrimDouble: |
| 1479 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1480 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1481 | default: |
| 1482 | return TypeFlag(type, offset); |
| 1483 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1484 | } |
| 1485 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1486 | // Translates type to bit flag. |
| 1487 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1488 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1489 | const uint64_t one = 1; |
| 1490 | const int shift = type; // 0-based consecutive enum |
| 1491 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1492 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1493 | return one << (type + offset); |
| 1494 | } |
| 1495 | |
| 1496 | // Private constructor on direct flags value. |
| 1497 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1498 | |
| 1499 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1500 | }; |
| 1501 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1502 | // 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] | 1503 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1504 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1505 | HEnvironment(ArenaAllocator* arena, |
| 1506 | size_t number_of_vregs, |
| 1507 | const DexFile& dex_file, |
| 1508 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1509 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1510 | InvokeType invoke_type, |
| 1511 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1512 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1513 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1514 | parent_(nullptr), |
| 1515 | dex_file_(dex_file), |
| 1516 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1517 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1518 | invoke_type_(invoke_type), |
| 1519 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1520 | } |
| 1521 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1522 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1523 | : HEnvironment(arena, |
| 1524 | to_copy.Size(), |
| 1525 | to_copy.GetDexFile(), |
| 1526 | to_copy.GetMethodIdx(), |
| 1527 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1528 | to_copy.GetInvokeType(), |
| 1529 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1530 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1531 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1532 | if (parent_ != nullptr) { |
| 1533 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1534 | } else { |
| 1535 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1536 | parent_->CopyFrom(parent); |
| 1537 | if (parent->GetParent() != nullptr) { |
| 1538 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1539 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1540 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1541 | } |
| 1542 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1543 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1544 | void CopyFrom(HEnvironment* environment); |
| 1545 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1546 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1547 | // input to the loop phi instead. This is for inserting instructions that |
| 1548 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1549 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1550 | |
| 1551 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1552 | DCHECK_LT(index, Size()); |
| 1553 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1557 | DCHECK_LT(index, Size()); |
| 1558 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1561 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1562 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1563 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1564 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1565 | HEnvironment* GetParent() const { return parent_; } |
| 1566 | |
| 1567 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1568 | DCHECK_LT(index, Size()); |
| 1569 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1573 | DCHECK_LT(index, Size()); |
| 1574 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | uint32_t GetDexPc() const { |
| 1578 | return dex_pc_; |
| 1579 | } |
| 1580 | |
| 1581 | uint32_t GetMethodIdx() const { |
| 1582 | return method_idx_; |
| 1583 | } |
| 1584 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1585 | InvokeType GetInvokeType() const { |
| 1586 | return invoke_type_; |
| 1587 | } |
| 1588 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1589 | const DexFile& GetDexFile() const { |
| 1590 | return dex_file_; |
| 1591 | } |
| 1592 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1593 | HInstruction* GetHolder() const { |
| 1594 | return holder_; |
| 1595 | } |
| 1596 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1597 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1598 | // Record instructions' use entries of this environment for constant-time removal. |
| 1599 | // It should only be called by HInstruction when a new environment use is added. |
| 1600 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1601 | DCHECK(env_use->GetUser() == this); |
| 1602 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1603 | DCHECK_LT(index, Size()); |
| 1604 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1605 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1606 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1607 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1608 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1609 | HEnvironment* parent_; |
| 1610 | const DexFile& dex_file_; |
| 1611 | const uint32_t method_idx_; |
| 1612 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1613 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1614 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1615 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1616 | HInstruction* const holder_; |
| 1617 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1618 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1619 | |
| 1620 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1621 | }; |
| 1622 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1623 | class ReferenceTypeInfo : ValueObject { |
| 1624 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1625 | typedef Handle<mirror::Class> TypeHandle; |
| 1626 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1627 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1628 | // The constructor will check that the type_handle is valid. |
| 1629 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1632 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1633 | |
| 1634 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1635 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1638 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1639 | return IsValidHandle(type_handle_); |
| 1640 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1641 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1642 | |
| 1643 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1644 | DCHECK(IsValid()); |
| 1645 | return GetTypeHandle()->IsObjectClass(); |
| 1646 | } |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1647 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1648 | DCHECK(IsValid()); |
| 1649 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1650 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1651 | |
| 1652 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1653 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1654 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1655 | DCHECK(IsValid()); |
| 1656 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1657 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1658 | } |
| 1659 | |
| 1660 | // Returns true if the type information provide the same amount of details. |
| 1661 | // 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] | 1662 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1663 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1664 | if (!IsValid() && !rti.IsValid()) { |
| 1665 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1666 | return true; |
| 1667 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1668 | if (!IsValid() || !rti.IsValid()) { |
| 1669 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1670 | return false; |
| 1671 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1672 | return IsExact() == rti.IsExact() |
| 1673 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1677 | ReferenceTypeInfo(); |
| 1678 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1679 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1680 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1681 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1682 | // 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] | 1683 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1684 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1685 | }; |
| 1686 | |
| 1687 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1688 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1689 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1690 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1691 | HInstruction(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1692 | : previous_(nullptr), |
| 1693 | next_(nullptr), |
| 1694 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1695 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1696 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1697 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1698 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1699 | locations_(nullptr), |
| 1700 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1701 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1702 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1703 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1704 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1705 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1706 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1707 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1708 | enum InstructionKind { |
| 1709 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1710 | }; |
| 1711 | #undef DECLARE_KIND |
| 1712 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1713 | HInstruction* GetNext() const { return next_; } |
| 1714 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1715 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1716 | HInstruction* GetNextDisregardingMoves() const; |
| 1717 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1718 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1719 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1720 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1721 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1722 | bool IsInBlock() const { return block_ != nullptr; } |
| 1723 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1724 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1725 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1726 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1727 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1728 | |
| 1729 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1730 | virtual const char* DebugName() const = 0; |
| 1731 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1732 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1733 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1734 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1735 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1736 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1737 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1738 | |
| 1739 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1740 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1741 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1742 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1743 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1744 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1745 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1746 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1747 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1748 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1749 | // Does not apply for all instructions, but having this at top level greatly |
| 1750 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1751 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1752 | virtual bool CanBeNull() const { |
| 1753 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1754 | return true; |
| 1755 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1756 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1757 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj) const { |
| 1758 | UNUSED(obj); |
| 1759 | return false; |
| 1760 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1761 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1762 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1763 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1764 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1765 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1766 | return reference_type_info_; |
| 1767 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1768 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1769 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1770 | DCHECK(user != nullptr); |
| 1771 | HUseListNode<HInstruction*>* use = |
| 1772 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1773 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1776 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1777 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1778 | HUseListNode<HEnvironment*>* env_use = |
| 1779 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1780 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1781 | } |
| 1782 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1783 | void RemoveAsUserOfInput(size_t input) { |
| 1784 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1785 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1786 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1787 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1788 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1789 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1790 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1791 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1792 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1793 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1794 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1795 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1796 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1797 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1798 | // Does this instruction strictly dominate `other_instruction`? |
| 1799 | // Returns false if this instruction and `other_instruction` are the same. |
| 1800 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1801 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1802 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1803 | int GetId() const { return id_; } |
| 1804 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1805 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1806 | int GetSsaIndex() const { return ssa_index_; } |
| 1807 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1808 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1809 | |
| 1810 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1811 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1812 | // Set the `environment_` field. Raw because this method does not |
| 1813 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1814 | void SetRawEnvironment(HEnvironment* environment) { |
| 1815 | DCHECK(environment_ == nullptr); |
| 1816 | DCHECK_EQ(environment->GetHolder(), this); |
| 1817 | environment_ = environment; |
| 1818 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1819 | |
| 1820 | // Set the environment of this instruction, copying it from `environment`. While |
| 1821 | // copying, the uses lists are being updated. |
| 1822 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1823 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1824 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1825 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1826 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1827 | if (environment->GetParent() != nullptr) { |
| 1828 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1829 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1830 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1831 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1832 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1833 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1834 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1835 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1836 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1837 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1838 | if (environment->GetParent() != nullptr) { |
| 1839 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1840 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1843 | // Returns the number of entries in the environment. Typically, that is the |
| 1844 | // number of dex registers in a method. It could be more in case of inlining. |
| 1845 | size_t EnvironmentSize() const; |
| 1846 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1847 | LocationSummary* GetLocations() const { return locations_; } |
| 1848 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1849 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1850 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1851 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1852 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1853 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1854 | // uses of this instruction by `other` are *not* updated. |
| 1855 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1856 | ReplaceWith(other); |
| 1857 | other->ReplaceInput(this, use_index); |
| 1858 | } |
| 1859 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1860 | // Move `this` instruction before `cursor`. |
| 1861 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1862 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1863 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1864 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1865 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1866 | virtual H##type* As##type() { return nullptr; } |
| 1867 | |
| 1868 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1869 | #undef INSTRUCTION_TYPE_CHECK |
| 1870 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1871 | // Returns whether the instruction can be moved within the graph. |
| 1872 | virtual bool CanBeMoved() const { return false; } |
| 1873 | |
| 1874 | // Returns whether the two instructions are of the same kind. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1875 | virtual bool InstructionTypeEquals(HInstruction* other) const { |
| 1876 | UNUSED(other); |
| 1877 | return false; |
| 1878 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1879 | |
| 1880 | // Returns whether any data encoded in the two instructions is equal. |
| 1881 | // This method does not look at the inputs. Both instructions must be |
| 1882 | // of the same type, otherwise the method has undefined behavior. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1883 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1884 | UNUSED(other); |
| 1885 | return false; |
| 1886 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1887 | |
| 1888 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1889 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1890 | // 2) Their inputs are identical. |
| 1891 | bool Equals(HInstruction* other) const; |
| 1892 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1893 | virtual InstructionKind GetKind() const = 0; |
| 1894 | |
| 1895 | virtual size_t ComputeHashCode() const { |
| 1896 | size_t result = GetKind(); |
| 1897 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1898 | result = (result * 31) + InputAt(i)->GetId(); |
| 1899 | } |
| 1900 | return result; |
| 1901 | } |
| 1902 | |
| 1903 | SideEffects GetSideEffects() const { return side_effects_; } |
| 1904 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1905 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1906 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1907 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 1908 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 1909 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 1910 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1911 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 1912 | |
| 1913 | // Returns whether the code generation of the instruction will require to have access |
| 1914 | // to the current method. Such instructions are: |
| 1915 | // (1): Instructions that require an environment, as calling the runtime requires |
| 1916 | // to walk the stack and have the current method stored at a specific stack address. |
| 1917 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 1918 | // fields of the current method. |
| 1919 | bool NeedsCurrentMethod() const { |
| 1920 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 1921 | } |
| 1922 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1923 | virtual bool NeedsDexCache() const { return false; } |
| 1924 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1925 | // Does this instruction have any use in an environment before |
| 1926 | // control flow hits 'other'? |
| 1927 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 1928 | |
| 1929 | // Remove all references to environment uses of this instruction. |
| 1930 | // The caller must ensure that this is safe to do. |
| 1931 | void RemoveEnvironmentUsers(); |
| 1932 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1933 | protected: |
| 1934 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 1935 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 1936 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1937 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1938 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 1939 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1940 | HInstruction* previous_; |
| 1941 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1942 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1943 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1944 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1945 | // An instruction gets an id when it is added to the graph. |
| 1946 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1947 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1948 | int id_; |
| 1949 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1950 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 1951 | int ssa_index_; |
| 1952 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1953 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1954 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1955 | |
| 1956 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1957 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1958 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1959 | // The environment associated with this instruction. Not null if the instruction |
| 1960 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1961 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1962 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1963 | // Set by the code generator. |
| 1964 | LocationSummary* locations_; |
| 1965 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1966 | // Set by the liveness analysis. |
| 1967 | LiveInterval* live_interval_; |
| 1968 | |
| 1969 | // Set by the liveness analysis, this is the position in a linear |
| 1970 | // order of blocks where this instruction's live interval start. |
| 1971 | size_t lifetime_position_; |
| 1972 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1973 | const SideEffects side_effects_; |
| 1974 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1975 | // TODO: for primitive types this should be marked as invalid. |
| 1976 | ReferenceTypeInfo reference_type_info_; |
| 1977 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1978 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1979 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1980 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1981 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1982 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1983 | |
| 1984 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 1985 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1986 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1987 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1988 | class HInputIterator : public ValueObject { |
| 1989 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1990 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1991 | |
| 1992 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 1993 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 1994 | void Advance() { index_++; } |
| 1995 | |
| 1996 | private: |
| 1997 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1998 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1999 | |
| 2000 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2001 | }; |
| 2002 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2003 | class HInstructionIterator : public ValueObject { |
| 2004 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2005 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2006 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2007 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2008 | } |
| 2009 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2010 | bool Done() const { return instruction_ == nullptr; } |
| 2011 | HInstruction* Current() const { return instruction_; } |
| 2012 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2013 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2014 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | private: |
| 2018 | HInstruction* instruction_; |
| 2019 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2020 | |
| 2021 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2022 | }; |
| 2023 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2024 | class HBackwardInstructionIterator : public ValueObject { |
| 2025 | public: |
| 2026 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2027 | : instruction_(instructions.last_instruction_) { |
| 2028 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2029 | } |
| 2030 | |
| 2031 | bool Done() const { return instruction_ == nullptr; } |
| 2032 | HInstruction* Current() const { return instruction_; } |
| 2033 | void Advance() { |
| 2034 | instruction_ = next_; |
| 2035 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2036 | } |
| 2037 | |
| 2038 | private: |
| 2039 | HInstruction* instruction_; |
| 2040 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2041 | |
| 2042 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2043 | }; |
| 2044 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2045 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2046 | class HTemplateInstruction: public HInstruction { |
| 2047 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2048 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2049 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2050 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2051 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2052 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2053 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2054 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2055 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2056 | DCHECK_LT(i, N); |
| 2057 | return inputs_[i]; |
| 2058 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2059 | |
| 2060 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2061 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2062 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2065 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2066 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2067 | |
| 2068 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2069 | }; |
| 2070 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2071 | // HTemplateInstruction specialization for N=0. |
| 2072 | template<> |
| 2073 | class HTemplateInstruction<0>: public HInstruction { |
| 2074 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2075 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2076 | : HInstruction(side_effects, dex_pc) {} |
| 2077 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2078 | virtual ~HTemplateInstruction() {} |
| 2079 | |
| 2080 | size_t InputCount() const OVERRIDE { return 0; } |
| 2081 | |
| 2082 | protected: |
| 2083 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2084 | LOG(FATAL) << "Unreachable"; |
| 2085 | UNREACHABLE(); |
| 2086 | } |
| 2087 | |
| 2088 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2089 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2090 | LOG(FATAL) << "Unreachable"; |
| 2091 | UNREACHABLE(); |
| 2092 | } |
| 2093 | |
| 2094 | private: |
| 2095 | friend class SsaBuilder; |
| 2096 | }; |
| 2097 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2098 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2099 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2100 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2101 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2102 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2103 | virtual ~HExpression() {} |
| 2104 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2105 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2106 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2107 | protected: |
| 2108 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2109 | }; |
| 2110 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2111 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2112 | // instruction that branches to the exit block. |
| 2113 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2114 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2115 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2116 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2117 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2118 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2119 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2120 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2121 | |
| 2122 | private: |
| 2123 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2124 | }; |
| 2125 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2126 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2127 | // instruction that branches to the exit block. |
| 2128 | class HReturn : public HTemplateInstruction<1> { |
| 2129 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2130 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2131 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2132 | SetRawInputAt(0, value); |
| 2133 | } |
| 2134 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2135 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2136 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2137 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2138 | |
| 2139 | private: |
| 2140 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2141 | }; |
| 2142 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2143 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2144 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2145 | // exit block. |
| 2146 | class HExit : public HTemplateInstruction<0> { |
| 2147 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2148 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2149 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2150 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2151 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2152 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2153 | |
| 2154 | private: |
| 2155 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2156 | }; |
| 2157 | |
| 2158 | // Jumps from one block to another. |
| 2159 | class HGoto : public HTemplateInstruction<0> { |
| 2160 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2161 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2162 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2163 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2164 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2165 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2166 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2167 | } |
| 2168 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2169 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2170 | |
| 2171 | private: |
| 2172 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2173 | }; |
| 2174 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2175 | class HConstant : public HExpression<0> { |
| 2176 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2177 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2178 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2179 | |
| 2180 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2181 | |
| 2182 | virtual bool IsMinusOne() const { return false; } |
| 2183 | virtual bool IsZero() const { return false; } |
| 2184 | virtual bool IsOne() const { return false; } |
| 2185 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2186 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2187 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2188 | DECLARE_INSTRUCTION(Constant); |
| 2189 | |
| 2190 | private: |
| 2191 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2192 | }; |
| 2193 | |
| 2194 | class HNullConstant : public HConstant { |
| 2195 | public: |
| 2196 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2197 | return true; |
| 2198 | } |
| 2199 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2200 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2201 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2202 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2203 | |
| 2204 | DECLARE_INSTRUCTION(NullConstant); |
| 2205 | |
| 2206 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2207 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2208 | |
| 2209 | friend class HGraph; |
| 2210 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2211 | }; |
| 2212 | |
| 2213 | // Constants of the type int. Those can be from Dex instructions, or |
| 2214 | // synthesized (for example with the if-eqz instruction). |
| 2215 | class HIntConstant : public HConstant { |
| 2216 | public: |
| 2217 | int32_t GetValue() const { return value_; } |
| 2218 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2219 | uint64_t GetValueAsUint64() const OVERRIDE { return static_cast<uint64_t>(value_); } |
| 2220 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2221 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2222 | DCHECK(other->IsIntConstant()); |
| 2223 | return other->AsIntConstant()->value_ == value_; |
| 2224 | } |
| 2225 | |
| 2226 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2227 | |
| 2228 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2229 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2230 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2231 | |
| 2232 | DECLARE_INSTRUCTION(IntConstant); |
| 2233 | |
| 2234 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2235 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2236 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2237 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2238 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2239 | |
| 2240 | const int32_t value_; |
| 2241 | |
| 2242 | friend class HGraph; |
| 2243 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2244 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2245 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2246 | }; |
| 2247 | |
| 2248 | class HLongConstant : public HConstant { |
| 2249 | public: |
| 2250 | int64_t GetValue() const { return value_; } |
| 2251 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2252 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2253 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2254 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2255 | DCHECK(other->IsLongConstant()); |
| 2256 | return other->AsLongConstant()->value_ == value_; |
| 2257 | } |
| 2258 | |
| 2259 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2260 | |
| 2261 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2262 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2263 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2264 | |
| 2265 | DECLARE_INSTRUCTION(LongConstant); |
| 2266 | |
| 2267 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2268 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2269 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2270 | |
| 2271 | const int64_t value_; |
| 2272 | |
| 2273 | friend class HGraph; |
| 2274 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2275 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2276 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2277 | // Conditional branch. A block ending with an HIf instruction must have |
| 2278 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2279 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2280 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2281 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2282 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2283 | SetRawInputAt(0, input); |
| 2284 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2285 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2286 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2287 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2288 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2289 | return GetBlock()->GetSuccessor(0); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
| 2292 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2293 | return GetBlock()->GetSuccessor(1); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2294 | } |
| 2295 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2296 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2297 | |
| 2298 | private: |
| 2299 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2300 | }; |
| 2301 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2302 | |
| 2303 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2304 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2305 | // non-exceptional control flow. |
| 2306 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2307 | // higher indices in no particular order. |
| 2308 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2309 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2310 | enum BoundaryKind { |
| 2311 | kEntry, |
| 2312 | kExit, |
| 2313 | }; |
| 2314 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2315 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2316 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2317 | |
| 2318 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2319 | |
| 2320 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2321 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessor(0); } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2322 | |
| 2323 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2324 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2325 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2326 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2327 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2328 | } |
| 2329 | |
| 2330 | // If not present already, adds `handler` to its block's list of exception |
| 2331 | // handlers. |
| 2332 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2333 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2334 | GetBlock()->AddSuccessor(handler); |
| 2335 | } |
| 2336 | } |
| 2337 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2338 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2339 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2340 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2341 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2342 | DECLARE_INSTRUCTION(TryBoundary); |
| 2343 | |
| 2344 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2345 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2346 | |
| 2347 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2348 | }; |
| 2349 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2350 | // Iterator over exception handlers of a given HTryBoundary, i.e. over |
| 2351 | // exceptional successors of its basic block. |
| 2352 | class HExceptionHandlerIterator : public ValueObject { |
| 2353 | public: |
| 2354 | explicit HExceptionHandlerIterator(const HTryBoundary& try_boundary) |
| 2355 | : block_(*try_boundary.GetBlock()), index_(block_.NumberOfNormalSuccessors()) {} |
| 2356 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2357 | bool Done() const { return index_ == block_.GetSuccessors().size(); } |
| 2358 | HBasicBlock* Current() const { return block_.GetSuccessor(index_); } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2359 | size_t CurrentSuccessorIndex() const { return index_; } |
| 2360 | void Advance() { ++index_; } |
| 2361 | |
| 2362 | private: |
| 2363 | const HBasicBlock& block_; |
| 2364 | size_t index_; |
| 2365 | |
| 2366 | DISALLOW_COPY_AND_ASSIGN(HExceptionHandlerIterator); |
| 2367 | }; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2368 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2369 | // Deoptimize to interpreter, upon checking a condition. |
| 2370 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2371 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2372 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2373 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2374 | SetRawInputAt(0, cond); |
| 2375 | } |
| 2376 | |
| 2377 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2378 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2379 | |
| 2380 | DECLARE_INSTRUCTION(Deoptimize); |
| 2381 | |
| 2382 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2383 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2384 | }; |
| 2385 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2386 | // Represents the ArtMethod that was passed as a first argument to |
| 2387 | // the method. It is used by instructions that depend on it, like |
| 2388 | // instructions that work with the dex cache. |
| 2389 | class HCurrentMethod : public HExpression<0> { |
| 2390 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2391 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2392 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2393 | |
| 2394 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2395 | |
| 2396 | private: |
| 2397 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2398 | }; |
| 2399 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2400 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2401 | // have one successor for each entry in the switch table, and the final successor |
| 2402 | // will be the block containing the next Dex opcode. |
| 2403 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2404 | public: |
| 2405 | HPackedSwitch(int32_t start_value, int32_t num_entries, HInstruction* input, |
| 2406 | uint32_t dex_pc = kNoDexPc) |
| 2407 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2408 | start_value_(start_value), |
| 2409 | num_entries_(num_entries) { |
| 2410 | SetRawInputAt(0, input); |
| 2411 | } |
| 2412 | |
| 2413 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2414 | |
| 2415 | int32_t GetStartValue() const { return start_value_; } |
| 2416 | |
| 2417 | int32_t GetNumEntries() const { return num_entries_; } |
| 2418 | |
| 2419 | HBasicBlock* GetDefaultBlock() const { |
| 2420 | // Last entry is the default block. |
| 2421 | return GetBlock()->GetSuccessor(num_entries_); |
| 2422 | } |
| 2423 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2424 | |
| 2425 | private: |
| 2426 | int32_t start_value_; |
| 2427 | int32_t num_entries_; |
| 2428 | |
| 2429 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2430 | }; |
| 2431 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2432 | class HUnaryOperation : public HExpression<1> { |
| 2433 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2434 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2435 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2436 | SetRawInputAt(0, input); |
| 2437 | } |
| 2438 | |
| 2439 | HInstruction* GetInput() const { return InputAt(0); } |
| 2440 | Primitive::Type GetResultType() const { return GetType(); } |
| 2441 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2442 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2443 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2444 | UNUSED(other); |
| 2445 | return true; |
| 2446 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2447 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2448 | // Try to statically evaluate `operation` and return a HConstant |
| 2449 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2450 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2451 | HConstant* TryStaticEvaluation() const; |
| 2452 | |
| 2453 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2454 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2455 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2456 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2457 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2458 | |
| 2459 | private: |
| 2460 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2461 | }; |
| 2462 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2463 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2464 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2465 | HBinaryOperation(Primitive::Type result_type, |
| 2466 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2467 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2468 | SideEffects side_effects = SideEffects::None(), |
| 2469 | uint32_t dex_pc = kNoDexPc) |
| 2470 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2471 | SetRawInputAt(0, left); |
| 2472 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2475 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2476 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2477 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2478 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2479 | virtual bool IsCommutative() const { return false; } |
| 2480 | |
| 2481 | // Put constant on the right. |
| 2482 | // Returns whether order is changed. |
| 2483 | bool OrderInputsWithConstantOnTheRight() { |
| 2484 | HInstruction* left = InputAt(0); |
| 2485 | HInstruction* right = InputAt(1); |
| 2486 | if (left->IsConstant() && !right->IsConstant()) { |
| 2487 | ReplaceInput(right, 0); |
| 2488 | ReplaceInput(left, 1); |
| 2489 | return true; |
| 2490 | } |
| 2491 | return false; |
| 2492 | } |
| 2493 | |
| 2494 | // Order inputs by instruction id, but favor constant on the right side. |
| 2495 | // This helps GVN for commutative ops. |
| 2496 | void OrderInputs() { |
| 2497 | DCHECK(IsCommutative()); |
| 2498 | HInstruction* left = InputAt(0); |
| 2499 | HInstruction* right = InputAt(1); |
| 2500 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2501 | return; |
| 2502 | } |
| 2503 | if (OrderInputsWithConstantOnTheRight()) { |
| 2504 | return; |
| 2505 | } |
| 2506 | // Order according to instruction id. |
| 2507 | if (left->GetId() > right->GetId()) { |
| 2508 | ReplaceInput(right, 0); |
| 2509 | ReplaceInput(left, 1); |
| 2510 | } |
| 2511 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2512 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2513 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2514 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2515 | UNUSED(other); |
| 2516 | return true; |
| 2517 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2518 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2519 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2520 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2521 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2522 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2523 | |
| 2524 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2525 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2526 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2527 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2528 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2529 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2530 | return nullptr; |
| 2531 | } |
| 2532 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2533 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2534 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2535 | return nullptr; |
| 2536 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2537 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2538 | // 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] | 2539 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2540 | HConstant* GetConstantRight() const; |
| 2541 | |
| 2542 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2543 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2544 | HInstruction* GetLeastConstantLeft() const; |
| 2545 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2546 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2547 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2548 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2549 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2550 | }; |
| 2551 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2552 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2553 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2554 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2555 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2556 | kGtBias, // return 1 for NaN comparisons |
| 2557 | kLtBias, // return -1 for NaN comparisons |
| 2558 | }; |
| 2559 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2560 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2561 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2562 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2563 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2564 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2565 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2566 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2567 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2568 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2569 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2570 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2571 | // `instruction`, and disregard moves in between. |
| 2572 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2573 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2574 | DECLARE_INSTRUCTION(Condition); |
| 2575 | |
| 2576 | virtual IfCondition GetCondition() const = 0; |
| 2577 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2578 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2579 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2580 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2581 | |
| 2582 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2583 | |
| 2584 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2585 | return bias_ == other->AsCondition()->bias_; |
| 2586 | } |
| 2587 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2588 | bool IsFPConditionTrueIfNaN() const { |
| 2589 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2590 | IfCondition if_cond = GetCondition(); |
| 2591 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2592 | } |
| 2593 | |
| 2594 | bool IsFPConditionFalseIfNaN() const { |
| 2595 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2596 | IfCondition if_cond = GetCondition(); |
| 2597 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2598 | } |
| 2599 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2600 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2601 | // For register allocation purposes, returns whether this instruction needs to be |
| 2602 | // materialized (that is, not just be in the processor flags). |
| 2603 | bool needs_materialization_; |
| 2604 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2605 | // Needed if we merge a HCompare into a HCondition. |
| 2606 | ComparisonBias bias_; |
| 2607 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2608 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2609 | }; |
| 2610 | |
| 2611 | // Instruction to check if two inputs are equal to each other. |
| 2612 | class HEqual : public HCondition { |
| 2613 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2614 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2615 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2616 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2617 | bool IsCommutative() const OVERRIDE { return true; } |
| 2618 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2619 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2620 | |
| 2621 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2622 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2623 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2624 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2625 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2626 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2627 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2628 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2629 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2630 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2631 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2632 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2633 | return kCondEQ; |
| 2634 | } |
| 2635 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2636 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2637 | return kCondNE; |
| 2638 | } |
| 2639 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2640 | private: |
| 2641 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2642 | }; |
| 2643 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2644 | class HNotEqual : public HCondition { |
| 2645 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2646 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2647 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2648 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2649 | bool IsCommutative() const OVERRIDE { return true; } |
| 2650 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2651 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2652 | |
| 2653 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2654 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2655 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2656 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2657 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2658 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2659 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2660 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2661 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2662 | DECLARE_INSTRUCTION(NotEqual); |
| 2663 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2664 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2665 | return kCondNE; |
| 2666 | } |
| 2667 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2668 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2669 | return kCondEQ; |
| 2670 | } |
| 2671 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2672 | private: |
| 2673 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2674 | }; |
| 2675 | |
| 2676 | class HLessThan : public HCondition { |
| 2677 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2678 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2679 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2680 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2681 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2682 | |
| 2683 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2684 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2685 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2686 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2687 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2688 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2689 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2690 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2691 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2692 | DECLARE_INSTRUCTION(LessThan); |
| 2693 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2694 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2695 | return kCondLT; |
| 2696 | } |
| 2697 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2698 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2699 | return kCondGE; |
| 2700 | } |
| 2701 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2702 | private: |
| 2703 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2704 | }; |
| 2705 | |
| 2706 | class HLessThanOrEqual : public HCondition { |
| 2707 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2708 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2709 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2710 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2711 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2712 | |
| 2713 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2714 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2715 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2716 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2717 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2718 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2719 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2720 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2721 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2722 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2723 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2724 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2725 | return kCondLE; |
| 2726 | } |
| 2727 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2728 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2729 | return kCondGT; |
| 2730 | } |
| 2731 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2732 | private: |
| 2733 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2734 | }; |
| 2735 | |
| 2736 | class HGreaterThan : public HCondition { |
| 2737 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2738 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2739 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2740 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2741 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2742 | |
| 2743 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2744 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2745 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2746 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2747 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2748 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2749 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2750 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2751 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2752 | DECLARE_INSTRUCTION(GreaterThan); |
| 2753 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2754 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2755 | return kCondGT; |
| 2756 | } |
| 2757 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2758 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2759 | return kCondLE; |
| 2760 | } |
| 2761 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2762 | private: |
| 2763 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2764 | }; |
| 2765 | |
| 2766 | class HGreaterThanOrEqual : public HCondition { |
| 2767 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2768 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2769 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2770 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2771 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2772 | |
| 2773 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2774 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2775 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2776 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2777 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2778 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2779 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2780 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2781 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2782 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2783 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2784 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2785 | return kCondGE; |
| 2786 | } |
| 2787 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2788 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2789 | return kCondLT; |
| 2790 | } |
| 2791 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2792 | private: |
| 2793 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2794 | }; |
| 2795 | |
| 2796 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2797 | // Instruction to check how two inputs compare to each other. |
| 2798 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 2799 | class HCompare : public HBinaryOperation { |
| 2800 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2801 | HCompare(Primitive::Type type, |
| 2802 | HInstruction* first, |
| 2803 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2804 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2805 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2806 | : HBinaryOperation(Primitive::kPrimInt, |
| 2807 | first, |
| 2808 | second, |
| 2809 | SideEffectsForArchRuntimeCalls(type), |
| 2810 | dex_pc), |
| 2811 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2812 | DCHECK_EQ(type, first->GetType()); |
| 2813 | DCHECK_EQ(type, second->GetType()); |
| 2814 | } |
| 2815 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2816 | template <typename T> |
| 2817 | 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] | 2818 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2819 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2820 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2821 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2822 | } |
| 2823 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2824 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2825 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2826 | } |
| 2827 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2828 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2829 | return bias_ == other->AsCompare()->bias_; |
| 2830 | } |
| 2831 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2832 | ComparisonBias GetBias() const { return bias_; } |
| 2833 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2834 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2835 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2836 | |
| 2837 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 2838 | // MIPS64 uses a runtime call for FP comparisons. |
| 2839 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 2840 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2841 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2842 | DECLARE_INSTRUCTION(Compare); |
| 2843 | |
| 2844 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2845 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2846 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2847 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 2848 | }; |
| 2849 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2850 | // A local in the graph. Corresponds to a Dex register. |
| 2851 | class HLocal : public HTemplateInstruction<0> { |
| 2852 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2853 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2854 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2855 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2856 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2857 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2858 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2859 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2860 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2861 | // The Dex register number. |
| 2862 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2863 | |
| 2864 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 2865 | }; |
| 2866 | |
| 2867 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2868 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2869 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2870 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2871 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2872 | SetRawInputAt(0, local); |
| 2873 | } |
| 2874 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2875 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2876 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2877 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2878 | |
| 2879 | private: |
| 2880 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 2881 | }; |
| 2882 | |
| 2883 | // Store a value in a given local. This instruction has two inputs: the value |
| 2884 | // and the local. |
| 2885 | class HStoreLocal : public HTemplateInstruction<2> { |
| 2886 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2887 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2888 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2889 | SetRawInputAt(0, local); |
| 2890 | SetRawInputAt(1, value); |
| 2891 | } |
| 2892 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2893 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2894 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2895 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2896 | |
| 2897 | private: |
| 2898 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 2899 | }; |
| 2900 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2901 | class HFloatConstant : public HConstant { |
| 2902 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2903 | float GetValue() const { return value_; } |
| 2904 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2905 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2906 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2907 | } |
| 2908 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2909 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2910 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2911 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2912 | } |
| 2913 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2914 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2915 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2916 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2917 | 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] | 2918 | } |
| 2919 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2920 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2921 | } |
| 2922 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2923 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2924 | } |
| 2925 | bool IsNaN() const { |
| 2926 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2927 | } |
| 2928 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2929 | DECLARE_INSTRUCTION(FloatConstant); |
| 2930 | |
| 2931 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2932 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2933 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2934 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2935 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2936 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2937 | const float value_; |
| 2938 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2939 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2940 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2941 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2942 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2943 | }; |
| 2944 | |
| 2945 | class HDoubleConstant : public HConstant { |
| 2946 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2947 | double GetValue() const { return value_; } |
| 2948 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2949 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2950 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2951 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2952 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2953 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2954 | } |
| 2955 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2956 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2957 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2958 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2959 | 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] | 2960 | } |
| 2961 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2962 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2963 | } |
| 2964 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2965 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2966 | } |
| 2967 | bool IsNaN() const { |
| 2968 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2969 | } |
| 2970 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2971 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2972 | |
| 2973 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2974 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2975 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2976 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2977 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2978 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2979 | const double value_; |
| 2980 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2981 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2982 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2983 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2984 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2985 | }; |
| 2986 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2987 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2988 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2989 | #include "intrinsics_list.h" |
| 2990 | kNone, |
| 2991 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 2992 | #undef INTRINSICS_LIST |
| 2993 | #undef OPTIMIZING_INTRINSICS |
| 2994 | }; |
| 2995 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 2996 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2997 | enum IntrinsicNeedsEnvironmentOrCache { |
| 2998 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 2999 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3000 | }; |
| 3001 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3002 | class HInvoke : public HInstruction { |
| 3003 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3004 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3005 | |
| 3006 | // Runtime needs to walk the stack, so Dex -> Dex calls need to |
| 3007 | // know their environment. |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3008 | bool NeedsEnvironment() const OVERRIDE { |
| 3009 | return needs_environment_or_cache_ == kNeedsEnvironmentOrCache; |
| 3010 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3011 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3012 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3013 | SetRawInputAt(index, argument); |
| 3014 | } |
| 3015 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3016 | // Return the number of arguments. This number can be lower than |
| 3017 | // the number of inputs returned by InputCount(), as some invoke |
| 3018 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3019 | // inputs at the end of their list of inputs. |
| 3020 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3021 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3022 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3023 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3024 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3025 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3026 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3027 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3028 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3029 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3030 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3031 | return intrinsic_; |
| 3032 | } |
| 3033 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3034 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3035 | intrinsic_ = intrinsic; |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3036 | needs_environment_or_cache_ = needs_env_or_cache; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3037 | } |
| 3038 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3039 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3040 | return GetEnvironment()->GetParent() != nullptr; |
| 3041 | } |
| 3042 | |
| 3043 | bool CanThrow() const OVERRIDE { return true; } |
| 3044 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3045 | DECLARE_INSTRUCTION(Invoke); |
| 3046 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3047 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3048 | HInvoke(ArenaAllocator* arena, |
| 3049 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3050 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3051 | Primitive::Type return_type, |
| 3052 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3053 | uint32_t dex_method_index, |
| 3054 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3055 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3056 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3057 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3058 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3059 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3060 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3061 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3062 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3063 | intrinsic_(Intrinsics::kNone), |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3064 | needs_environment_or_cache_(kNeedsEnvironmentOrCache) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3065 | } |
| 3066 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3067 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 3068 | DCHECK_LT(index, InputCount()); |
| 3069 | return inputs_[index]; |
| 3070 | } |
| 3071 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3072 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3073 | DCHECK_LT(index, InputCount()); |
| 3074 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3075 | } |
| 3076 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3077 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3078 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3079 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3080 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3081 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3082 | Intrinsics intrinsic_; |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3083 | IntrinsicNeedsEnvironmentOrCache needs_environment_or_cache_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3084 | |
| 3085 | private: |
| 3086 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3087 | }; |
| 3088 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3089 | class HInvokeUnresolved : public HInvoke { |
| 3090 | public: |
| 3091 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3092 | uint32_t number_of_arguments, |
| 3093 | Primitive::Type return_type, |
| 3094 | uint32_t dex_pc, |
| 3095 | uint32_t dex_method_index, |
| 3096 | InvokeType invoke_type) |
| 3097 | : HInvoke(arena, |
| 3098 | number_of_arguments, |
| 3099 | 0u /* number_of_other_inputs */, |
| 3100 | return_type, |
| 3101 | dex_pc, |
| 3102 | dex_method_index, |
| 3103 | invoke_type) { |
| 3104 | } |
| 3105 | |
| 3106 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3107 | |
| 3108 | private: |
| 3109 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3110 | }; |
| 3111 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3112 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3113 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3114 | // Requirements of this method call regarding the class |
| 3115 | // initialization (clinit) check of its declaring class. |
| 3116 | enum class ClinitCheckRequirement { |
| 3117 | kNone, // Class already initialized. |
| 3118 | kExplicit, // Static call having explicit clinit check as last input. |
| 3119 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3120 | }; |
| 3121 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3122 | // Determines how to load the target ArtMethod*. |
| 3123 | enum class MethodLoadKind { |
| 3124 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3125 | kStringInit, |
| 3126 | |
| 3127 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3128 | kRecursive, |
| 3129 | |
| 3130 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3131 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3132 | kDirectAddress, |
| 3133 | |
| 3134 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3135 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3136 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3137 | // the image relocatable or not. |
| 3138 | kDirectAddressWithFixup, |
| 3139 | |
| 3140 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3141 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3142 | // may cause class initialization (the entry may point to a resolution method), |
| 3143 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3144 | kDexCachePcRelative, |
| 3145 | |
| 3146 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3147 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3148 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3149 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3150 | kDexCacheViaMethod, |
| 3151 | }; |
| 3152 | |
| 3153 | // Determines the location of the code pointer. |
| 3154 | enum class CodePtrLocation { |
| 3155 | // Recursive call, use local PC-relative call instruction. |
| 3156 | kCallSelf, |
| 3157 | |
| 3158 | // Use PC-relative call instruction patched at link time. |
| 3159 | // Used for calls within an oat file, boot->boot or app->app. |
| 3160 | kCallPCRelative, |
| 3161 | |
| 3162 | // Call to a known target address, embed the direct address in code. |
| 3163 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3164 | kCallDirect, |
| 3165 | |
| 3166 | // Call to a target address that will be known at link time, embed the direct |
| 3167 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3168 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3169 | // the image relocatable or not. |
| 3170 | kCallDirectWithFixup, |
| 3171 | |
| 3172 | // Use code pointer from the ArtMethod*. |
| 3173 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3174 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3175 | kCallArtMethod, |
| 3176 | }; |
| 3177 | |
| 3178 | struct DispatchInfo { |
| 3179 | const MethodLoadKind method_load_kind; |
| 3180 | const CodePtrLocation code_ptr_location; |
| 3181 | // The method load data holds |
| 3182 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3183 | // Note that there are multiple string init methods, each having its own offset. |
| 3184 | // - the method address for kDirectAddress |
| 3185 | // - the dex cache arrays offset for kDexCachePcRel. |
| 3186 | const uint64_t method_load_data; |
| 3187 | const uint64_t direct_code_ptr; |
| 3188 | }; |
| 3189 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3190 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3191 | uint32_t number_of_arguments, |
| 3192 | Primitive::Type return_type, |
| 3193 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3194 | uint32_t method_index, |
| 3195 | MethodReference target_method, |
| 3196 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3197 | InvokeType original_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3198 | InvokeType invoke_type, |
| 3199 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3200 | : HInvoke(arena, |
| 3201 | number_of_arguments, |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3202 | // There is one extra argument for the HCurrentMethod node, and |
| 3203 | // potentially one other if the clinit check is explicit, and one other |
| 3204 | // if the method is a string factory. |
| 3205 | 1u + (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3206 | + (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3207 | return_type, |
| 3208 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3209 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3210 | original_invoke_type), |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3211 | invoke_type_(invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3212 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3213 | target_method_(target_method), |
| 3214 | dispatch_info_(dispatch_info) {} |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3215 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3216 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 3217 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3218 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3219 | // TODO: for intrinsics we can generate implicit null checks. |
| 3220 | return false; |
| 3221 | } |
| 3222 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3223 | bool CanBeNull() const OVERRIDE { |
| 3224 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3225 | } |
| 3226 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3227 | InvokeType GetInvokeType() const { return invoke_type_; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3228 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3229 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3230 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3231 | bool NeedsDexCache() const OVERRIDE { |
| 3232 | if (intrinsic_ != Intrinsics::kNone) { return needs_environment_or_cache_; } |
| 3233 | return !IsRecursive() && !IsStringInit(); |
| 3234 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3235 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3236 | uint32_t GetCurrentMethodInputIndex() const { return GetNumberOfArguments(); } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3237 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
| 3238 | bool HasPcRelDexCache() const { return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; } |
| 3239 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3240 | MethodReference GetTargetMethod() const { return target_method_; } |
| 3241 | |
| 3242 | int32_t GetStringInitOffset() const { |
| 3243 | DCHECK(IsStringInit()); |
| 3244 | return dispatch_info_.method_load_data; |
| 3245 | } |
| 3246 | |
| 3247 | uint64_t GetMethodAddress() const { |
| 3248 | DCHECK(HasMethodAddress()); |
| 3249 | return dispatch_info_.method_load_data; |
| 3250 | } |
| 3251 | |
| 3252 | uint32_t GetDexCacheArrayOffset() const { |
| 3253 | DCHECK(HasPcRelDexCache()); |
| 3254 | return dispatch_info_.method_load_data; |
| 3255 | } |
| 3256 | |
| 3257 | uint64_t GetDirectCodePtr() const { |
| 3258 | DCHECK(HasDirectCodePtr()); |
| 3259 | return dispatch_info_.direct_code_ptr; |
| 3260 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3261 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3262 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3263 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3264 | // Is this instruction a call to a static method? |
| 3265 | bool IsStatic() const { |
| 3266 | return GetInvokeType() == kStatic; |
| 3267 | } |
| 3268 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3269 | // Remove the art::HLoadClass instruction set as last input by |
| 3270 | // art::PrepareForRegisterAllocation::VisitClinitCheck in lieu of |
| 3271 | // the initial art::HClinitCheck instruction (only relevant for |
| 3272 | // static calls with explicit clinit check). |
| 3273 | void RemoveLoadClassAsLastInput() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3274 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3275 | size_t last_input_index = InputCount() - 1; |
| 3276 | HInstruction* last_input = InputAt(last_input_index); |
| 3277 | DCHECK(last_input != nullptr); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3278 | DCHECK(last_input->IsLoadClass()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3279 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3280 | inputs_.pop_back(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3281 | clinit_check_requirement_ = ClinitCheckRequirement::kImplicit; |
| 3282 | DCHECK(IsStaticWithImplicitClinitCheck()); |
| 3283 | } |
| 3284 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3285 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3286 | if (!IsStringInit()) return false; |
| 3287 | // +1 for the current method. |
| 3288 | if (InputCount() == (number_of_arguments_ + 1)) return false; |
| 3289 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3290 | } |
| 3291 | |
| 3292 | void RemoveFakeStringArgumentAsLastInput() { |
| 3293 | DCHECK(IsStringInit()); |
| 3294 | size_t last_input_index = InputCount() - 1; |
| 3295 | HInstruction* last_input = InputAt(last_input_index); |
| 3296 | DCHECK(last_input != nullptr); |
| 3297 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3298 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3299 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3300 | } |
| 3301 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3302 | // Is this a call to a static method whose declaring class has an |
| 3303 | // explicit intialization check in the graph? |
| 3304 | bool IsStaticWithExplicitClinitCheck() const { |
| 3305 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3306 | } |
| 3307 | |
| 3308 | // Is this a call to a static method whose declaring class has an |
| 3309 | // implicit intialization check requirement? |
| 3310 | bool IsStaticWithImplicitClinitCheck() const { |
| 3311 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3312 | } |
| 3313 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3314 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3315 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3316 | protected: |
| 3317 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3318 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3319 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3320 | HInstruction* input = input_record.GetInstruction(); |
| 3321 | // `input` is the last input of a static invoke marked as having |
| 3322 | // an explicit clinit check. It must either be: |
| 3323 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3324 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3325 | DCHECK(input != nullptr); |
| 3326 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3327 | } |
| 3328 | return input_record; |
| 3329 | } |
| 3330 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3331 | private: |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3332 | const InvokeType invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3333 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3334 | // The target method may refer to different dex file or method index than the original |
| 3335 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3336 | // in derived class to increase visibility. |
| 3337 | MethodReference target_method_; |
| 3338 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3339 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3340 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3341 | }; |
| 3342 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3343 | class HInvokeVirtual : public HInvoke { |
| 3344 | public: |
| 3345 | HInvokeVirtual(ArenaAllocator* arena, |
| 3346 | uint32_t number_of_arguments, |
| 3347 | Primitive::Type return_type, |
| 3348 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3349 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3350 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3351 | : 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] | 3352 | vtable_index_(vtable_index) {} |
| 3353 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3354 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3355 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3356 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3357 | } |
| 3358 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3359 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3360 | |
| 3361 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3362 | |
| 3363 | private: |
| 3364 | const uint32_t vtable_index_; |
| 3365 | |
| 3366 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3367 | }; |
| 3368 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3369 | class HInvokeInterface : public HInvoke { |
| 3370 | public: |
| 3371 | HInvokeInterface(ArenaAllocator* arena, |
| 3372 | uint32_t number_of_arguments, |
| 3373 | Primitive::Type return_type, |
| 3374 | uint32_t dex_pc, |
| 3375 | uint32_t dex_method_index, |
| 3376 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3377 | : 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] | 3378 | imt_index_(imt_index) {} |
| 3379 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3380 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3381 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3382 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3383 | } |
| 3384 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3385 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3386 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3387 | |
| 3388 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3389 | |
| 3390 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3391 | const uint32_t imt_index_; |
| 3392 | |
| 3393 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3394 | }; |
| 3395 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3396 | class HNewInstance : public HExpression<1> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3397 | public: |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3398 | HNewInstance(HCurrentMethod* current_method, |
| 3399 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3400 | uint16_t type_index, |
| 3401 | const DexFile& dex_file, |
| 3402 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3403 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3404 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3405 | dex_file_(dex_file), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3406 | entrypoint_(entrypoint) { |
| 3407 | SetRawInputAt(0, current_method); |
| 3408 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3409 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3410 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3411 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3412 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3413 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3414 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3415 | // It may throw when called on: |
| 3416 | // - interfaces |
| 3417 | // - abstract/innaccessible/unknown classes |
| 3418 | // TODO: optimize when possible. |
| 3419 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3420 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3421 | bool CanBeNull() const OVERRIDE { return false; } |
| 3422 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3423 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3424 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3425 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3426 | |
| 3427 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3428 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3429 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3430 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3431 | |
| 3432 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3433 | }; |
| 3434 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3435 | class HNeg : public HUnaryOperation { |
| 3436 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3437 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3438 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3439 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3440 | template <typename T> T Compute(T x) const { return -x; } |
| 3441 | |
| 3442 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3443 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3444 | } |
| 3445 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3446 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3447 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3448 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3449 | DECLARE_INSTRUCTION(Neg); |
| 3450 | |
| 3451 | private: |
| 3452 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3453 | }; |
| 3454 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3455 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3456 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3457 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3458 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3459 | uint32_t dex_pc, |
| 3460 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3461 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3462 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3463 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3464 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3465 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3466 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3467 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3468 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3469 | } |
| 3470 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3471 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3472 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3473 | |
| 3474 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3475 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3476 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3477 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3478 | bool CanThrow() const OVERRIDE { return true; } |
| 3479 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3480 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3481 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3482 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3483 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3484 | DECLARE_INSTRUCTION(NewArray); |
| 3485 | |
| 3486 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3487 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3488 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3489 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3490 | |
| 3491 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3492 | }; |
| 3493 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3494 | class HAdd : public HBinaryOperation { |
| 3495 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3496 | HAdd(Primitive::Type result_type, |
| 3497 | HInstruction* left, |
| 3498 | HInstruction* right, |
| 3499 | uint32_t dex_pc = kNoDexPc) |
| 3500 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3501 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3502 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3503 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3504 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3505 | |
| 3506 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3507 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3508 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3509 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3510 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3511 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3512 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3513 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3514 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3515 | DECLARE_INSTRUCTION(Add); |
| 3516 | |
| 3517 | private: |
| 3518 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3519 | }; |
| 3520 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3521 | class HSub : public HBinaryOperation { |
| 3522 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3523 | HSub(Primitive::Type result_type, |
| 3524 | HInstruction* left, |
| 3525 | HInstruction* right, |
| 3526 | uint32_t dex_pc = kNoDexPc) |
| 3527 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3528 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3529 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3530 | |
| 3531 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3532 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3533 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3534 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3535 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3536 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3537 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3538 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3539 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3540 | DECLARE_INSTRUCTION(Sub); |
| 3541 | |
| 3542 | private: |
| 3543 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3544 | }; |
| 3545 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3546 | class HMul : public HBinaryOperation { |
| 3547 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3548 | HMul(Primitive::Type result_type, |
| 3549 | HInstruction* left, |
| 3550 | HInstruction* right, |
| 3551 | uint32_t dex_pc = kNoDexPc) |
| 3552 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3553 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3554 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3555 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3556 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3557 | |
| 3558 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3559 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3560 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3561 | } |
| 3562 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3563 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3564 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3565 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3566 | |
| 3567 | DECLARE_INSTRUCTION(Mul); |
| 3568 | |
| 3569 | private: |
| 3570 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3571 | }; |
| 3572 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3573 | class HDiv : public HBinaryOperation { |
| 3574 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3575 | HDiv(Primitive::Type result_type, |
| 3576 | HInstruction* left, |
| 3577 | HInstruction* right, |
| 3578 | uint32_t dex_pc) |
| 3579 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3580 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3581 | template <typename T> |
| 3582 | T Compute(T x, T y) const { |
| 3583 | // Our graph structure ensures we never have 0 for `y` during |
| 3584 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3585 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3586 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3587 | return (y == -1) ? -x : x / y; |
| 3588 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3589 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3590 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3591 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3592 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3593 | } |
| 3594 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3595 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3596 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3597 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3598 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3599 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3600 | // The generated code can use a runtime call. |
| 3601 | return SideEffects::CanTriggerGC(); |
| 3602 | } |
| 3603 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3604 | DECLARE_INSTRUCTION(Div); |
| 3605 | |
| 3606 | private: |
| 3607 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3608 | }; |
| 3609 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3610 | class HRem : public HBinaryOperation { |
| 3611 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3612 | HRem(Primitive::Type result_type, |
| 3613 | HInstruction* left, |
| 3614 | HInstruction* right, |
| 3615 | uint32_t dex_pc) |
| 3616 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3617 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3618 | template <typename T> |
| 3619 | T Compute(T x, T y) const { |
| 3620 | // Our graph structure ensures we never have 0 for `y` during |
| 3621 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3622 | DCHECK_NE(y, 0); |
| 3623 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3624 | return (y == -1) ? 0 : x % y; |
| 3625 | } |
| 3626 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3627 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3628 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3629 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3630 | } |
| 3631 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3632 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3633 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3634 | } |
| 3635 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3636 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3637 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3638 | return SideEffects::CanTriggerGC(); |
| 3639 | } |
| 3640 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3641 | DECLARE_INSTRUCTION(Rem); |
| 3642 | |
| 3643 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3644 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3645 | }; |
| 3646 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3647 | class HDivZeroCheck : public HExpression<1> { |
| 3648 | public: |
| 3649 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3650 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3651 | SetRawInputAt(0, value); |
| 3652 | } |
| 3653 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3654 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3655 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3656 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3657 | |
| 3658 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3659 | UNUSED(other); |
| 3660 | return true; |
| 3661 | } |
| 3662 | |
| 3663 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3664 | bool CanThrow() const OVERRIDE { return true; } |
| 3665 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3666 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3667 | |
| 3668 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3669 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3670 | }; |
| 3671 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3672 | class HShl : public HBinaryOperation { |
| 3673 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3674 | HShl(Primitive::Type result_type, |
| 3675 | HInstruction* left, |
| 3676 | HInstruction* right, |
| 3677 | uint32_t dex_pc = kNoDexPc) |
| 3678 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3679 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3680 | template <typename T, typename U, typename V> |
| 3681 | T Compute(T x, U y, V max_shift_value) const { |
| 3682 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3683 | "V is not the unsigned integer type corresponding to T"); |
| 3684 | return x << (y & max_shift_value); |
| 3685 | } |
| 3686 | |
| 3687 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3688 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3689 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3690 | } |
| 3691 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3692 | // case is handled as `x << static_cast<int>(y)`. |
| 3693 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3694 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3695 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3696 | } |
| 3697 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3698 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3699 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3700 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3701 | |
| 3702 | DECLARE_INSTRUCTION(Shl); |
| 3703 | |
| 3704 | private: |
| 3705 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 3706 | }; |
| 3707 | |
| 3708 | class HShr : public HBinaryOperation { |
| 3709 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3710 | HShr(Primitive::Type result_type, |
| 3711 | HInstruction* left, |
| 3712 | HInstruction* right, |
| 3713 | uint32_t dex_pc = kNoDexPc) |
| 3714 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3715 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3716 | template <typename T, typename U, typename V> |
| 3717 | T Compute(T x, U y, V max_shift_value) const { |
| 3718 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3719 | "V is not the unsigned integer type corresponding to T"); |
| 3720 | return x >> (y & max_shift_value); |
| 3721 | } |
| 3722 | |
| 3723 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3724 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3725 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3726 | } |
| 3727 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3728 | // case is handled as `x >> static_cast<int>(y)`. |
| 3729 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3730 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3731 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3732 | } |
| 3733 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3734 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3735 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3736 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3737 | |
| 3738 | DECLARE_INSTRUCTION(Shr); |
| 3739 | |
| 3740 | private: |
| 3741 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 3742 | }; |
| 3743 | |
| 3744 | class HUShr : public HBinaryOperation { |
| 3745 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3746 | HUShr(Primitive::Type result_type, |
| 3747 | HInstruction* left, |
| 3748 | HInstruction* right, |
| 3749 | uint32_t dex_pc = kNoDexPc) |
| 3750 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3751 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3752 | template <typename T, typename U, typename V> |
| 3753 | T Compute(T x, U y, V max_shift_value) const { |
| 3754 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3755 | "V is not the unsigned integer type corresponding to T"); |
| 3756 | V ux = static_cast<V>(x); |
| 3757 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3758 | } |
| 3759 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3760 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3761 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3762 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3763 | } |
| 3764 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3765 | // case is handled as `x >>> static_cast<int>(y)`. |
| 3766 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3767 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3768 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3769 | } |
| 3770 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3771 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3772 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | DECLARE_INSTRUCTION(UShr); |
| 3776 | |
| 3777 | private: |
| 3778 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 3779 | }; |
| 3780 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3781 | class HAnd : public HBinaryOperation { |
| 3782 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3783 | HAnd(Primitive::Type result_type, |
| 3784 | HInstruction* left, |
| 3785 | HInstruction* right, |
| 3786 | uint32_t dex_pc = kNoDexPc) |
| 3787 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3788 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3789 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3790 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3791 | template <typename T, typename U> |
| 3792 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 3793 | |
| 3794 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3795 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3796 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3797 | } |
| 3798 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3799 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3800 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3801 | } |
| 3802 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3803 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3804 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3805 | } |
| 3806 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3807 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3808 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3809 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3810 | |
| 3811 | DECLARE_INSTRUCTION(And); |
| 3812 | |
| 3813 | private: |
| 3814 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 3815 | }; |
| 3816 | |
| 3817 | class HOr : public HBinaryOperation { |
| 3818 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3819 | HOr(Primitive::Type result_type, |
| 3820 | HInstruction* left, |
| 3821 | HInstruction* right, |
| 3822 | uint32_t dex_pc = kNoDexPc) |
| 3823 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3824 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3825 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3826 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3827 | template <typename T, typename U> |
| 3828 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 3829 | |
| 3830 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3831 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3832 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3833 | } |
| 3834 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3835 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3836 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3837 | } |
| 3838 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3839 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3840 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3841 | } |
| 3842 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3843 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3844 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3845 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3846 | |
| 3847 | DECLARE_INSTRUCTION(Or); |
| 3848 | |
| 3849 | private: |
| 3850 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 3851 | }; |
| 3852 | |
| 3853 | class HXor : public HBinaryOperation { |
| 3854 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3855 | HXor(Primitive::Type result_type, |
| 3856 | HInstruction* left, |
| 3857 | HInstruction* right, |
| 3858 | uint32_t dex_pc = kNoDexPc) |
| 3859 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3860 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3861 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3862 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3863 | template <typename T, typename U> |
| 3864 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 3865 | |
| 3866 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3867 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3868 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3869 | } |
| 3870 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3871 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3872 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3873 | } |
| 3874 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3875 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3876 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3877 | } |
| 3878 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3879 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3880 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3881 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3882 | |
| 3883 | DECLARE_INSTRUCTION(Xor); |
| 3884 | |
| 3885 | private: |
| 3886 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 3887 | }; |
| 3888 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3889 | // The value of a parameter in this method. Its location depends on |
| 3890 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3891 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3892 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3893 | HParameterValue(uint8_t index, |
| 3894 | Primitive::Type parameter_type, |
| 3895 | bool is_this = false) |
| 3896 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3897 | index_(index), |
| 3898 | is_this_(is_this), |
| 3899 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3900 | |
| 3901 | uint8_t GetIndex() const { return index_; } |
| 3902 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3903 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 3904 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3905 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 3906 | bool IsThis() const { return is_this_; } |
| 3907 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3908 | DECLARE_INSTRUCTION(ParameterValue); |
| 3909 | |
| 3910 | private: |
| 3911 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3912 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3913 | const uint8_t index_; |
| 3914 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3915 | // Whether or not the parameter value corresponds to 'this' argument. |
| 3916 | const bool is_this_; |
| 3917 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3918 | bool can_be_null_; |
| 3919 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3920 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 3921 | }; |
| 3922 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3923 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3924 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3925 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3926 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3927 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3928 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3929 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3930 | UNUSED(other); |
| 3931 | return true; |
| 3932 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3933 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3934 | template <typename T> T Compute(T x) const { return ~x; } |
| 3935 | |
| 3936 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3937 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3938 | } |
| 3939 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3940 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3941 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3942 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3943 | DECLARE_INSTRUCTION(Not); |
| 3944 | |
| 3945 | private: |
| 3946 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 3947 | }; |
| 3948 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3949 | class HBooleanNot : public HUnaryOperation { |
| 3950 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3951 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3952 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3953 | |
| 3954 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3955 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3956 | UNUSED(other); |
| 3957 | return true; |
| 3958 | } |
| 3959 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3960 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3961 | DCHECK(IsUint<1>(x)); |
| 3962 | return !x; |
| 3963 | } |
| 3964 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3965 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3966 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3967 | } |
| 3968 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3969 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3970 | UNREACHABLE(); |
| 3971 | } |
| 3972 | |
| 3973 | DECLARE_INSTRUCTION(BooleanNot); |
| 3974 | |
| 3975 | private: |
| 3976 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 3977 | }; |
| 3978 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3979 | class HTypeConversion : public HExpression<1> { |
| 3980 | public: |
| 3981 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3982 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3983 | : HExpression(result_type, |
| 3984 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 3985 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3986 | SetRawInputAt(0, input); |
| 3987 | DCHECK_NE(input->GetType(), result_type); |
| 3988 | } |
| 3989 | |
| 3990 | HInstruction* GetInput() const { return InputAt(0); } |
| 3991 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 3992 | Primitive::Type GetResultType() const { return GetType(); } |
| 3993 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3994 | // Required by the x86 and ARM code generators when producing calls |
| 3995 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3996 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3997 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 3998 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3999 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4000 | // Try to statically evaluate the conversion and return a HConstant |
| 4001 | // containing the result. If the input cannot be converted, return nullptr. |
| 4002 | HConstant* TryStaticEvaluation() const; |
| 4003 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4004 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4005 | Primitive::Type result_type) { |
| 4006 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4007 | // in the compilation process we do not know what architecture we will |
| 4008 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4009 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4010 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4011 | return SideEffects::CanTriggerGC(); |
| 4012 | } |
| 4013 | return SideEffects::None(); |
| 4014 | } |
| 4015 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4016 | DECLARE_INSTRUCTION(TypeConversion); |
| 4017 | |
| 4018 | private: |
| 4019 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4020 | }; |
| 4021 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4022 | static constexpr uint32_t kNoRegNumber = -1; |
| 4023 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4024 | class HPhi : public HInstruction { |
| 4025 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4026 | HPhi(ArenaAllocator* arena, |
| 4027 | uint32_t reg_number, |
| 4028 | size_t number_of_inputs, |
| 4029 | Primitive::Type type, |
| 4030 | uint32_t dex_pc = kNoDexPc) |
| 4031 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4032 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4033 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4034 | type_(type), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4035 | is_live_(false), |
| 4036 | can_be_null_(true) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4037 | } |
| 4038 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4039 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4040 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4041 | switch (type) { |
| 4042 | case Primitive::kPrimBoolean: |
| 4043 | case Primitive::kPrimByte: |
| 4044 | case Primitive::kPrimShort: |
| 4045 | case Primitive::kPrimChar: |
| 4046 | return Primitive::kPrimInt; |
| 4047 | default: |
| 4048 | return type; |
| 4049 | } |
| 4050 | } |
| 4051 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4052 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4053 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4054 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4055 | |
| 4056 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4057 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4058 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4059 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4060 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4061 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4062 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4063 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4064 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4065 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4066 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4067 | void SetDead() { is_live_ = false; } |
| 4068 | void SetLive() { is_live_ = true; } |
| 4069 | bool IsDead() const { return !is_live_; } |
| 4070 | bool IsLive() const { return is_live_; } |
| 4071 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4072 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4073 | return other != nullptr |
| 4074 | && other->IsPhi() |
| 4075 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4076 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4077 | } |
| 4078 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4079 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4080 | // An equivalent phi is a phi having the same dex register and type. |
| 4081 | // It assumes that phis with the same dex register are adjacent. |
| 4082 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4083 | HInstruction* next = GetNext(); |
| 4084 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4085 | if (next->GetType() == GetType()) { |
| 4086 | return next->AsPhi(); |
| 4087 | } |
| 4088 | next = next->GetNext(); |
| 4089 | } |
| 4090 | return nullptr; |
| 4091 | } |
| 4092 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4093 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4094 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4095 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4096 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 4097 | DCHECK_LE(index, InputCount()); |
| 4098 | return inputs_[index]; |
| 4099 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4100 | |
| 4101 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4102 | DCHECK_LE(index, InputCount()); |
| 4103 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4104 | } |
| 4105 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4106 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4107 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4108 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4109 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4110 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4111 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4112 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4113 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4114 | }; |
| 4115 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4116 | class HNullCheck : public HExpression<1> { |
| 4117 | public: |
| 4118 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4119 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4120 | SetRawInputAt(0, value); |
| 4121 | } |
| 4122 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4123 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4124 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4125 | UNUSED(other); |
| 4126 | return true; |
| 4127 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4128 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4129 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4130 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4131 | bool CanThrow() const OVERRIDE { return true; } |
| 4132 | |
| 4133 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4134 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4135 | |
| 4136 | DECLARE_INSTRUCTION(NullCheck); |
| 4137 | |
| 4138 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4139 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4140 | }; |
| 4141 | |
| 4142 | class FieldInfo : public ValueObject { |
| 4143 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4144 | FieldInfo(MemberOffset field_offset, |
| 4145 | Primitive::Type field_type, |
| 4146 | bool is_volatile, |
| 4147 | uint32_t index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4148 | const DexFile& dex_file, |
| 4149 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4150 | : field_offset_(field_offset), |
| 4151 | field_type_(field_type), |
| 4152 | is_volatile_(is_volatile), |
| 4153 | index_(index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4154 | dex_file_(dex_file), |
| 4155 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4156 | |
| 4157 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4158 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4159 | uint32_t GetFieldIndex() const { return index_; } |
| 4160 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4161 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4162 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4163 | |
| 4164 | private: |
| 4165 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4166 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4167 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4168 | const uint32_t index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4169 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4170 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4171 | }; |
| 4172 | |
| 4173 | class HInstanceFieldGet : public HExpression<1> { |
| 4174 | public: |
| 4175 | HInstanceFieldGet(HInstruction* value, |
| 4176 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4177 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4178 | bool is_volatile, |
| 4179 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4180 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4181 | Handle<mirror::DexCache> dex_cache, |
| 4182 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4183 | : HExpression( |
| 4184 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4185 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4186 | 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] | 4187 | SetRawInputAt(0, value); |
| 4188 | } |
| 4189 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4190 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4191 | |
| 4192 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4193 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4194 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4195 | } |
| 4196 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4197 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4198 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4202 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4203 | } |
| 4204 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4205 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4206 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4207 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4208 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4209 | |
| 4210 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4211 | |
| 4212 | private: |
| 4213 | const FieldInfo field_info_; |
| 4214 | |
| 4215 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4216 | }; |
| 4217 | |
| 4218 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4219 | public: |
| 4220 | HInstanceFieldSet(HInstruction* object, |
| 4221 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4222 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4223 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4224 | bool is_volatile, |
| 4225 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4226 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4227 | Handle<mirror::DexCache> dex_cache, |
| 4228 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4229 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4230 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4231 | 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] | 4232 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4233 | SetRawInputAt(0, object); |
| 4234 | SetRawInputAt(1, value); |
| 4235 | } |
| 4236 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4237 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4238 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4241 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4242 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4243 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4244 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4245 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4246 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4247 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4248 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4249 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4250 | |
| 4251 | private: |
| 4252 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4253 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4254 | |
| 4255 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4256 | }; |
| 4257 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4258 | class HArrayGet : public HExpression<2> { |
| 4259 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4260 | HArrayGet(HInstruction* array, |
| 4261 | HInstruction* index, |
| 4262 | Primitive::Type type, |
| 4263 | uint32_t dex_pc = kNoDexPc) |
| 4264 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4265 | SetRawInputAt(0, array); |
| 4266 | SetRawInputAt(1, index); |
| 4267 | } |
| 4268 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4269 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4270 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4271 | UNUSED(other); |
| 4272 | return true; |
| 4273 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4274 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4275 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4276 | // TODO: We can be smarter here. |
| 4277 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4278 | // which generates the implicit null check. There are cases when these can be removed |
| 4279 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4280 | // implicit check here (as long as the address falls in the first page). |
| 4281 | return false; |
| 4282 | } |
| 4283 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4284 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4285 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4286 | HInstruction* GetArray() const { return InputAt(0); } |
| 4287 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4288 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4289 | DECLARE_INSTRUCTION(ArrayGet); |
| 4290 | |
| 4291 | private: |
| 4292 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4293 | }; |
| 4294 | |
| 4295 | class HArraySet : public HTemplateInstruction<3> { |
| 4296 | public: |
| 4297 | HArraySet(HInstruction* array, |
| 4298 | HInstruction* index, |
| 4299 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4300 | Primitive::Type expected_component_type, |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4301 | uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4302 | : HTemplateInstruction( |
| 4303 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4304 | SideEffectsForArchRuntimeCalls(value->GetType())), dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4305 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4306 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
| 4307 | value_can_be_null_(true) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4308 | SetRawInputAt(0, array); |
| 4309 | SetRawInputAt(1, index); |
| 4310 | SetRawInputAt(2, value); |
| 4311 | } |
| 4312 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4313 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4314 | // We currently always call a runtime method to catch array store |
| 4315 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4316 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4317 | } |
| 4318 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4319 | // Can throw ArrayStoreException. |
| 4320 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4321 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4322 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4323 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4324 | // TODO: Same as for ArrayGet. |
| 4325 | return false; |
| 4326 | } |
| 4327 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4328 | void ClearNeedsTypeCheck() { |
| 4329 | needs_type_check_ = false; |
| 4330 | } |
| 4331 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4332 | void ClearValueCanBeNull() { |
| 4333 | value_can_be_null_ = false; |
| 4334 | } |
| 4335 | |
| 4336 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4337 | bool NeedsTypeCheck() const { return needs_type_check_; } |
| 4338 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4339 | HInstruction* GetArray() const { return InputAt(0); } |
| 4340 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4341 | HInstruction* GetValue() const { return InputAt(2); } |
| 4342 | |
| 4343 | Primitive::Type GetComponentType() const { |
| 4344 | // The Dex format does not type floating point index operations. Since the |
| 4345 | // `expected_component_type_` is set during building and can therefore not |
| 4346 | // be correct, we also check what is the value type. If it is a floating |
| 4347 | // point type, we must use that type. |
| 4348 | Primitive::Type value_type = GetValue()->GetType(); |
| 4349 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4350 | ? value_type |
| 4351 | : expected_component_type_; |
| 4352 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4353 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4354 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4355 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4356 | } |
| 4357 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4358 | DECLARE_INSTRUCTION(ArraySet); |
| 4359 | |
| 4360 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4361 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4362 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4363 | bool value_can_be_null_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4364 | |
| 4365 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4366 | }; |
| 4367 | |
| 4368 | class HArrayLength : public HExpression<1> { |
| 4369 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4370 | explicit HArrayLength(HInstruction* array, uint32_t dex_pc = kNoDexPc) |
| 4371 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4372 | // Note that arrays do not change length, so the instruction does not |
| 4373 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4374 | SetRawInputAt(0, array); |
| 4375 | } |
| 4376 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +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 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4382 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4383 | return obj == InputAt(0); |
| 4384 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4385 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4386 | DECLARE_INSTRUCTION(ArrayLength); |
| 4387 | |
| 4388 | private: |
| 4389 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4390 | }; |
| 4391 | |
| 4392 | class HBoundsCheck : public HExpression<2> { |
| 4393 | public: |
| 4394 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4395 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4396 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4397 | SetRawInputAt(0, index); |
| 4398 | SetRawInputAt(1, length); |
| 4399 | } |
| 4400 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4401 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4402 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4403 | UNUSED(other); |
| 4404 | return true; |
| 4405 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4406 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4407 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4408 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4409 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4410 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4411 | |
| 4412 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4413 | |
| 4414 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4415 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4416 | }; |
| 4417 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4418 | /** |
| 4419 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4420 | * to stay live until the last HInstruction. This class |
| 4421 | * 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] | 4422 | * HInstruction stays live. `index` represents the stack location index of the |
| 4423 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4424 | */ |
| 4425 | class HTemporary : public HTemplateInstruction<0> { |
| 4426 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4427 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4428 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4429 | |
| 4430 | size_t GetIndex() const { return index_; } |
| 4431 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4432 | Primitive::Type GetType() const OVERRIDE { |
| 4433 | // The previous instruction is the one that will be stored in the temporary location. |
| 4434 | DCHECK(GetPrevious() != nullptr); |
| 4435 | return GetPrevious()->GetType(); |
| 4436 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4437 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4438 | DECLARE_INSTRUCTION(Temporary); |
| 4439 | |
| 4440 | private: |
| 4441 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4442 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4443 | }; |
| 4444 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4445 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4446 | public: |
| 4447 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4448 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4449 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4450 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4451 | return true; |
| 4452 | } |
| 4453 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4454 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4455 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4456 | |
| 4457 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4458 | |
| 4459 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4460 | // Only used for code generation, in order to share the same slow path between back edges |
| 4461 | // of a same loop. |
| 4462 | SlowPathCode* slow_path_; |
| 4463 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4464 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4465 | }; |
| 4466 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4467 | /** |
| 4468 | * Instruction to load a Class object. |
| 4469 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4470 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4471 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4472 | HLoadClass(HCurrentMethod* current_method, |
| 4473 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4474 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4475 | bool is_referrers_class, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4476 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4477 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4478 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4479 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4480 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4481 | generate_clinit_check_(false), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4482 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4483 | SetRawInputAt(0, current_method); |
| 4484 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4485 | |
| 4486 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4487 | |
| 4488 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4489 | return other->AsLoadClass()->type_index_ == type_index_; |
| 4490 | } |
| 4491 | |
| 4492 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4493 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4494 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4495 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4496 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4497 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4498 | bool NeedsEnvironment() const OVERRIDE { |
| 4499 | // Will call runtime and load the class if the class is not loaded yet. |
| 4500 | // TODO: finer grain decision. |
| 4501 | return !is_referrers_class_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4502 | } |
| 4503 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4504 | bool MustGenerateClinitCheck() const { |
| 4505 | return generate_clinit_check_; |
| 4506 | } |
| 4507 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4508 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
| 4509 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4510 | } |
| 4511 | |
| 4512 | bool CanCallRuntime() const { |
| 4513 | return MustGenerateClinitCheck() || !is_referrers_class_; |
| 4514 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4515 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4516 | bool CanThrow() const OVERRIDE { |
| 4517 | // May call runtime and and therefore can throw. |
| 4518 | // TODO: finer grain decision. |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4519 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4520 | } |
| 4521 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4522 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4523 | return loaded_class_rti_; |
| 4524 | } |
| 4525 | |
| 4526 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4527 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4528 | DCHECK(rti.IsExact()); |
| 4529 | loaded_class_rti_ = rti; |
| 4530 | } |
| 4531 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4532 | const DexFile& GetDexFile() { return dex_file_; } |
| 4533 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4534 | bool NeedsDexCache() const OVERRIDE { return !is_referrers_class_; } |
| 4535 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4536 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4537 | return SideEffects::CanTriggerGC(); |
| 4538 | } |
| 4539 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4540 | DECLARE_INSTRUCTION(LoadClass); |
| 4541 | |
| 4542 | private: |
| 4543 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4544 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4545 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4546 | // Whether this instruction must generate the initialization check. |
| 4547 | // Used for code generation. |
| 4548 | bool generate_clinit_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4549 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4550 | ReferenceTypeInfo loaded_class_rti_; |
| 4551 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4552 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4553 | }; |
| 4554 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4555 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4556 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4557 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4558 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4559 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4560 | SetRawInputAt(0, current_method); |
| 4561 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4562 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4563 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4564 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4565 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4566 | return other->AsLoadString()->string_index_ == string_index_; |
| 4567 | } |
| 4568 | |
| 4569 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4570 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4571 | uint32_t GetStringIndex() const { return string_index_; } |
| 4572 | |
| 4573 | // TODO: Can we deopt or debug when we resolve a string? |
| 4574 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4575 | bool NeedsDexCache() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4576 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4577 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4578 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4579 | return SideEffects::CanTriggerGC(); |
| 4580 | } |
| 4581 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4582 | DECLARE_INSTRUCTION(LoadString); |
| 4583 | |
| 4584 | private: |
| 4585 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4586 | |
| 4587 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4588 | }; |
| 4589 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4590 | /** |
| 4591 | * Performs an initialization check on its Class object input. |
| 4592 | */ |
| 4593 | class HClinitCheck : public HExpression<1> { |
| 4594 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4595 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4596 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4597 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4598 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4599 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4600 | SetRawInputAt(0, constant); |
| 4601 | } |
| 4602 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4603 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4604 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4605 | UNUSED(other); |
| 4606 | return true; |
| 4607 | } |
| 4608 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4609 | bool NeedsEnvironment() const OVERRIDE { |
| 4610 | // May call runtime to initialize the class. |
| 4611 | return true; |
| 4612 | } |
| 4613 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4614 | |
| 4615 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4616 | |
| 4617 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4618 | |
| 4619 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4620 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4621 | }; |
| 4622 | |
| 4623 | class HStaticFieldGet : public HExpression<1> { |
| 4624 | public: |
| 4625 | HStaticFieldGet(HInstruction* cls, |
| 4626 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4627 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4628 | bool is_volatile, |
| 4629 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4630 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4631 | Handle<mirror::DexCache> dex_cache, |
| 4632 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4633 | : HExpression( |
| 4634 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4635 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4636 | 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] | 4637 | SetRawInputAt(0, cls); |
| 4638 | } |
| 4639 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4640 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4641 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4642 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4643 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4644 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 4645 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | size_t ComputeHashCode() const OVERRIDE { |
| 4649 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4650 | } |
| 4651 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4652 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4653 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4654 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4655 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4656 | |
| 4657 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 4658 | |
| 4659 | private: |
| 4660 | const FieldInfo field_info_; |
| 4661 | |
| 4662 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 4663 | }; |
| 4664 | |
| 4665 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 4666 | public: |
| 4667 | HStaticFieldSet(HInstruction* cls, |
| 4668 | HInstruction* value, |
| 4669 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4670 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4671 | bool is_volatile, |
| 4672 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4673 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4674 | Handle<mirror::DexCache> dex_cache, |
| 4675 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4676 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4677 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4678 | 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] | 4679 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4680 | SetRawInputAt(0, cls); |
| 4681 | SetRawInputAt(1, value); |
| 4682 | } |
| 4683 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4684 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4685 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4686 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4687 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4688 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4689 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4690 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4691 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4692 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4693 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 4694 | |
| 4695 | private: |
| 4696 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4697 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4698 | |
| 4699 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 4700 | }; |
| 4701 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4702 | // Implement the move-exception DEX instruction. |
| 4703 | class HLoadException : public HExpression<0> { |
| 4704 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4705 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 4706 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4707 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 4708 | bool CanBeNull() const OVERRIDE { return false; } |
| 4709 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4710 | DECLARE_INSTRUCTION(LoadException); |
| 4711 | |
| 4712 | private: |
| 4713 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 4714 | }; |
| 4715 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4716 | // Implicit part of move-exception which clears thread-local exception storage. |
| 4717 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 4718 | class HClearException : public HTemplateInstruction<0> { |
| 4719 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4720 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 4721 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4722 | |
| 4723 | DECLARE_INSTRUCTION(ClearException); |
| 4724 | |
| 4725 | private: |
| 4726 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 4727 | }; |
| 4728 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4729 | class HThrow : public HTemplateInstruction<1> { |
| 4730 | public: |
| 4731 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4732 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4733 | SetRawInputAt(0, exception); |
| 4734 | } |
| 4735 | |
| 4736 | bool IsControlFlow() const OVERRIDE { return true; } |
| 4737 | |
| 4738 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4739 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4740 | bool CanThrow() const OVERRIDE { return true; } |
| 4741 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4742 | |
| 4743 | DECLARE_INSTRUCTION(Throw); |
| 4744 | |
| 4745 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4746 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 4747 | }; |
| 4748 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4749 | /** |
| 4750 | * Implementation strategies for the code generator of a HInstanceOf |
| 4751 | * or `HCheckCast`. |
| 4752 | */ |
| 4753 | enum class TypeCheckKind { |
| 4754 | kExactCheck, // Can do a single class compare. |
| 4755 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 4756 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 4757 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 4758 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 4759 | kArrayCheck // No optimization yet when checking against a generic array. |
| 4760 | }; |
| 4761 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4762 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4763 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4764 | HInstanceOf(HInstruction* object, |
| 4765 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4766 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4767 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4768 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4769 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4770 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4771 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4772 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4773 | SetRawInputAt(0, object); |
| 4774 | SetRawInputAt(1, constant); |
| 4775 | } |
| 4776 | |
| 4777 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4778 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4779 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4780 | return true; |
| 4781 | } |
| 4782 | |
| 4783 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4784 | return false; |
| 4785 | } |
| 4786 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4787 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 4788 | |
| 4789 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4790 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4791 | // Used only in code generation. |
| 4792 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4793 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 4794 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4795 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 4796 | return (check_kind == TypeCheckKind::kExactCheck) |
| 4797 | ? SideEffects::None() |
| 4798 | // Mips currently does runtime calls for any other checks. |
| 4799 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4800 | } |
| 4801 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4802 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4803 | |
| 4804 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4805 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4806 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4807 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4808 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 4809 | }; |
| 4810 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4811 | class HBoundType : public HExpression<1> { |
| 4812 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4813 | // Constructs an HBoundType with the given upper_bound. |
| 4814 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4815 | HBoundType(HInstruction* input, |
| 4816 | ReferenceTypeInfo upper_bound, |
| 4817 | bool upper_can_be_null, |
| 4818 | uint32_t dex_pc = kNoDexPc) |
| 4819 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4820 | upper_bound_(upper_bound), |
| 4821 | upper_can_be_null_(upper_can_be_null), |
| 4822 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 4823 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4824 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4825 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4826 | } |
| 4827 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4828 | // GetUpper* should only be used in reference type propagation. |
| 4829 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 4830 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4831 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4832 | void SetCanBeNull(bool can_be_null) { |
| 4833 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 4834 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4837 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4838 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4839 | DECLARE_INSTRUCTION(BoundType); |
| 4840 | |
| 4841 | private: |
| 4842 | // 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] | 4843 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 4844 | // It is used to bound the type in cases like: |
| 4845 | // if (x instanceof ClassX) { |
| 4846 | // // uper_bound_ will be ClassX |
| 4847 | // } |
| 4848 | const ReferenceTypeInfo upper_bound_; |
| 4849 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 4850 | // is false then can_be_null_ cannot be true). |
| 4851 | const bool upper_can_be_null_; |
| 4852 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4853 | |
| 4854 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 4855 | }; |
| 4856 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4857 | class HCheckCast : public HTemplateInstruction<2> { |
| 4858 | public: |
| 4859 | HCheckCast(HInstruction* object, |
| 4860 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4861 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4862 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4863 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4864 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4865 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4866 | SetRawInputAt(0, object); |
| 4867 | SetRawInputAt(1, constant); |
| 4868 | } |
| 4869 | |
| 4870 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4871 | |
| 4872 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4873 | return true; |
| 4874 | } |
| 4875 | |
| 4876 | bool NeedsEnvironment() const OVERRIDE { |
| 4877 | // Instruction may throw a CheckCastError. |
| 4878 | return true; |
| 4879 | } |
| 4880 | |
| 4881 | bool CanThrow() const OVERRIDE { return true; } |
| 4882 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4883 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4884 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4885 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4886 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4887 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4888 | |
| 4889 | DECLARE_INSTRUCTION(CheckCast); |
| 4890 | |
| 4891 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4892 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4893 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4894 | |
| 4895 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4896 | }; |
| 4897 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4898 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 4899 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4900 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4901 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4902 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4903 | barrier_kind_(barrier_kind) {} |
| 4904 | |
| 4905 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 4906 | |
| 4907 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 4908 | |
| 4909 | private: |
| 4910 | const MemBarrierKind barrier_kind_; |
| 4911 | |
| 4912 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 4913 | }; |
| 4914 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4915 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 4916 | public: |
| 4917 | enum OperationKind { |
| 4918 | kEnter, |
| 4919 | kExit, |
| 4920 | }; |
| 4921 | |
| 4922 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4923 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4924 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 4925 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4926 | SetRawInputAt(0, object); |
| 4927 | } |
| 4928 | |
| 4929 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 4930 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 4931 | |
| 4932 | bool CanThrow() const OVERRIDE { |
| 4933 | // Verifier guarantees that monitor-exit cannot throw. |
| 4934 | // This is important because it allows the HGraphBuilder to remove |
| 4935 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 4936 | return IsEnter(); |
| 4937 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4938 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4939 | |
| 4940 | bool IsEnter() const { return kind_ == kEnter; } |
| 4941 | |
| 4942 | DECLARE_INSTRUCTION(MonitorOperation); |
| 4943 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4944 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4945 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4946 | |
| 4947 | private: |
| 4948 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 4949 | }; |
| 4950 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4951 | /** |
| 4952 | * A HInstruction used as a marker for the replacement of new + <init> |
| 4953 | * of a String to a call to a StringFactory. Only baseline will see |
| 4954 | * the node at code generation, where it will be be treated as null. |
| 4955 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 4956 | * in the instruction simplifier. |
| 4957 | */ |
| 4958 | class HFakeString : public HTemplateInstruction<0> { |
| 4959 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4960 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 4961 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4962 | |
| 4963 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 4964 | |
| 4965 | DECLARE_INSTRUCTION(FakeString); |
| 4966 | |
| 4967 | private: |
| 4968 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 4969 | }; |
| 4970 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 4971 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4972 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 4973 | MoveOperands(Location source, |
| 4974 | Location destination, |
| 4975 | Primitive::Type type, |
| 4976 | HInstruction* instruction) |
| 4977 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4978 | |
| 4979 | Location GetSource() const { return source_; } |
| 4980 | Location GetDestination() const { return destination_; } |
| 4981 | |
| 4982 | void SetSource(Location value) { source_ = value; } |
| 4983 | void SetDestination(Location value) { destination_ = value; } |
| 4984 | |
| 4985 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 4986 | // destination (but not the source). |
| 4987 | Location MarkPending() { |
| 4988 | DCHECK(!IsPending()); |
| 4989 | Location dest = destination_; |
| 4990 | destination_ = Location::NoLocation(); |
| 4991 | return dest; |
| 4992 | } |
| 4993 | |
| 4994 | void ClearPending(Location dest) { |
| 4995 | DCHECK(IsPending()); |
| 4996 | destination_ = dest; |
| 4997 | } |
| 4998 | |
| 4999 | bool IsPending() const { |
| 5000 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5001 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5002 | } |
| 5003 | |
| 5004 | // True if this blocks a move from the given location. |
| 5005 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5006 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | // A move is redundant if it's been eliminated, if its source and |
| 5010 | // destination are the same, or if its destination is unneeded. |
| 5011 | bool IsRedundant() const { |
| 5012 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5013 | } |
| 5014 | |
| 5015 | // We clear both operands to indicate move that's been eliminated. |
| 5016 | void Eliminate() { |
| 5017 | source_ = destination_ = Location::NoLocation(); |
| 5018 | } |
| 5019 | |
| 5020 | bool IsEliminated() const { |
| 5021 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5022 | return source_.IsInvalid(); |
| 5023 | } |
| 5024 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5025 | Primitive::Type GetType() const { return type_; } |
| 5026 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5027 | bool Is64BitMove() const { |
| 5028 | return Primitive::Is64BitType(type_); |
| 5029 | } |
| 5030 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5031 | HInstruction* GetInstruction() const { return instruction_; } |
| 5032 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5033 | private: |
| 5034 | Location source_; |
| 5035 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5036 | // The type this move is for. |
| 5037 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5038 | // The instruction this move is assocatied with. Null when this move is |
| 5039 | // for moving an input in the expected locations of user (including a phi user). |
| 5040 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5041 | // in the same parallel move. |
| 5042 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5043 | }; |
| 5044 | |
| 5045 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5046 | |
| 5047 | class HParallelMove : public HTemplateInstruction<0> { |
| 5048 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5049 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
| 5050 | : HTemplateInstruction(SideEffects::None(), dex_pc), moves_(arena, kDefaultNumberOfMoves) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5051 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5052 | void AddMove(Location source, |
| 5053 | Location destination, |
| 5054 | Primitive::Type type, |
| 5055 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5056 | DCHECK(source.IsValid()); |
| 5057 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5058 | if (kIsDebugBuild) { |
| 5059 | if (instruction != nullptr) { |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5060 | for (size_t i = 0, e = moves_.Size(); i < e; ++i) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5061 | if (moves_.Get(i).GetInstruction() == instruction) { |
| 5062 | // Special case the situation where the move is for the spill slot |
| 5063 | // of the instruction. |
| 5064 | if ((GetPrevious() == instruction) |
| 5065 | || ((GetPrevious() == nullptr) |
| 5066 | && instruction->IsPhi() |
| 5067 | && instruction->GetBlock() == GetBlock())) { |
| 5068 | DCHECK_NE(destination.GetKind(), moves_.Get(i).GetDestination().GetKind()) |
| 5069 | << "Doing parallel moves for the same instruction."; |
| 5070 | } else { |
| 5071 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5072 | } |
| 5073 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5074 | } |
| 5075 | } |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5076 | for (size_t i = 0, e = moves_.Size(); i < e; ++i) { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5077 | DCHECK(!destination.OverlapsWith(moves_.Get(i).GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5078 | << "Overlapped destination for two moves in a parallel move: " |
| 5079 | << moves_.Get(i).GetSource() << " ==> " << moves_.Get(i).GetDestination() << " and " |
| 5080 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5081 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5082 | } |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5083 | moves_.Add(MoveOperands(source, destination, type, instruction)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | MoveOperands* MoveOperandsAt(size_t index) const { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5087 | return moves_.GetRawStorage() + index; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | size_t NumMoves() const { return moves_.Size(); } |
| 5091 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5092 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5093 | |
| 5094 | private: |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5095 | GrowableArray<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5096 | |
| 5097 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5098 | }; |
| 5099 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5100 | } // namespace art |
| 5101 | |
| 5102 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5103 | #include "nodes_x86.h" |
| 5104 | #endif |
| 5105 | |
| 5106 | namespace art { |
| 5107 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5108 | class HGraphVisitor : public ValueObject { |
| 5109 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5110 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5111 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5112 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5113 | virtual void VisitInstruction(HInstruction* instruction) { UNUSED(instruction); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5114 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5115 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5116 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5117 | void VisitInsertionOrder(); |
| 5118 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5119 | // Visit the graph following dominator tree reverse post-order. |
| 5120 | void VisitReversePostOrder(); |
| 5121 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5122 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5123 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5124 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5125 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5126 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5127 | |
| 5128 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5129 | |
| 5130 | #undef DECLARE_VISIT_INSTRUCTION |
| 5131 | |
| 5132 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5133 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5134 | |
| 5135 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5136 | }; |
| 5137 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5138 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5139 | public: |
| 5140 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5141 | virtual ~HGraphDelegateVisitor() {} |
| 5142 | |
| 5143 | // Visit functions that delegate to to super class. |
| 5144 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5145 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5146 | |
| 5147 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5148 | |
| 5149 | #undef DECLARE_VISIT_INSTRUCTION |
| 5150 | |
| 5151 | private: |
| 5152 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5153 | }; |
| 5154 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5155 | class HInsertionOrderIterator : public ValueObject { |
| 5156 | public: |
| 5157 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5158 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5159 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
| 5160 | HBasicBlock* Current() const { return graph_.GetBlock(index_); } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5161 | void Advance() { ++index_; } |
| 5162 | |
| 5163 | private: |
| 5164 | const HGraph& graph_; |
| 5165 | size_t index_; |
| 5166 | |
| 5167 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5168 | }; |
| 5169 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5170 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5171 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5172 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5173 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5174 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5175 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5176 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5177 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5178 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5179 | void Advance() { ++index_; } |
| 5180 | |
| 5181 | private: |
| 5182 | const HGraph& graph_; |
| 5183 | size_t index_; |
| 5184 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5185 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5186 | }; |
| 5187 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5188 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5189 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5190 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5191 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5192 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5193 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5194 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5195 | |
| 5196 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5197 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5198 | void Advance() { --index_; } |
| 5199 | |
| 5200 | private: |
| 5201 | const HGraph& graph_; |
| 5202 | size_t index_; |
| 5203 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5204 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5205 | }; |
| 5206 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5207 | class HLinearPostOrderIterator : public ValueObject { |
| 5208 | public: |
| 5209 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5210 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5211 | |
| 5212 | bool Done() const { return index_ == 0; } |
| 5213 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5214 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5215 | |
| 5216 | void Advance() { |
| 5217 | --index_; |
| 5218 | DCHECK_GE(index_, 0U); |
| 5219 | } |
| 5220 | |
| 5221 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5222 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5223 | size_t index_; |
| 5224 | |
| 5225 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5226 | }; |
| 5227 | |
| 5228 | class HLinearOrderIterator : public ValueObject { |
| 5229 | public: |
| 5230 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5231 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5232 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5233 | bool Done() const { return index_ == order_.size(); } |
| 5234 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5235 | void Advance() { ++index_; } |
| 5236 | |
| 5237 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5238 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5239 | size_t index_; |
| 5240 | |
| 5241 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5242 | }; |
| 5243 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5244 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5245 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5246 | // block id. |
| 5247 | class HBlocksInLoopIterator : public ValueObject { |
| 5248 | public: |
| 5249 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5250 | : blocks_in_loop_(info.GetBlocks()), |
| 5251 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5252 | index_(0) { |
| 5253 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5254 | Advance(); |
| 5255 | } |
| 5256 | } |
| 5257 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5258 | bool Done() const { return index_ == blocks_.size(); } |
| 5259 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5260 | void Advance() { |
| 5261 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5262 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5263 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5264 | break; |
| 5265 | } |
| 5266 | } |
| 5267 | } |
| 5268 | |
| 5269 | private: |
| 5270 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5271 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5272 | size_t index_; |
| 5273 | |
| 5274 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5275 | }; |
| 5276 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5277 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5278 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5279 | // post order. |
| 5280 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5281 | public: |
| 5282 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5283 | : blocks_in_loop_(info.GetBlocks()), |
| 5284 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5285 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5286 | DCHECK(!blocks_.empty()); |
| 5287 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5288 | Advance(); |
| 5289 | } |
| 5290 | } |
| 5291 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5292 | bool Done() const { return index_ == blocks_.size(); } |
| 5293 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5294 | void Advance() { |
| 5295 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5296 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5297 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5298 | break; |
| 5299 | } |
| 5300 | } |
| 5301 | } |
| 5302 | |
| 5303 | private: |
| 5304 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5305 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5306 | size_t index_; |
| 5307 | |
| 5308 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5309 | }; |
| 5310 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5311 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5312 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5313 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5314 | : constant->AsLongConstant()->GetValue(); |
| 5315 | } |
| 5316 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5317 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5318 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5319 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5320 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5321 | // times and provide different class resolution but no two class loaders should ever |
| 5322 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5323 | // all sorts of weird failures. |
| 5324 | return &lhs == &rhs; |
| 5325 | } |
| 5326 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5327 | } // namespace art |
| 5328 | |
| 5329 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |