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