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 | |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 24 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 26 | #include "base/arena_object.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 28 | #include "dex/compiler_enums.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 30 | #include "handle.h" |
| 31 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 32 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 33 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 34 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 35 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 36 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 37 | #include "primitive.h" |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 38 | #include "utils/array_ref.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 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); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 79 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 80 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 81 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 82 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 83 | static constexpr uint32_t kNoDexPc = -1; |
| 84 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 85 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 86 | // All types. |
| 87 | kCondEQ, // == |
| 88 | kCondNE, // != |
| 89 | // Signed integers and floating-point numbers. |
| 90 | kCondLT, // < |
| 91 | kCondLE, // <= |
| 92 | kCondGT, // > |
| 93 | kCondGE, // >= |
| 94 | // Unsigned integers. |
| 95 | kCondB, // < |
| 96 | kCondBE, // <= |
| 97 | kCondA, // > |
| 98 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 101 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 102 | public: |
| 103 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 104 | |
| 105 | void AddInstruction(HInstruction* instruction); |
| 106 | void RemoveInstruction(HInstruction* instruction); |
| 107 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 108 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 109 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 110 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 111 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 112 | // Return true if this list contains `instruction`. |
| 113 | bool Contains(HInstruction* instruction) const; |
| 114 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 115 | // Return true if `instruction1` is found before `instruction2` in |
| 116 | // this instruction list and false otherwise. Abort if none |
| 117 | // of these instructions is found. |
| 118 | bool FoundBefore(const HInstruction* instruction1, |
| 119 | const HInstruction* instruction2) const; |
| 120 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 121 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 122 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 123 | |
| 124 | // Update the block of all instructions to be `block`. |
| 125 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 126 | |
| 127 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 128 | void Add(const HInstructionList& instruction_list); |
| 129 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 130 | // Return the number of instructions in the list. This is an expensive operation. |
| 131 | size_t CountSize() const; |
| 132 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 133 | private: |
| 134 | HInstruction* first_instruction_; |
| 135 | HInstruction* last_instruction_; |
| 136 | |
| 137 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 138 | friend class HGraph; |
| 139 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 140 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 141 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 142 | |
| 143 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 144 | }; |
| 145 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 146 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 147 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 148 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 149 | HGraph(ArenaAllocator* arena, |
| 150 | const DexFile& dex_file, |
| 151 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 152 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 153 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 154 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 155 | bool debuggable = false, |
| 156 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 157 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 158 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 159 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 160 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 161 | entry_block_(nullptr), |
| 162 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 163 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 164 | number_of_vregs_(0), |
| 165 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 166 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 167 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 168 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 169 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 170 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 171 | dex_file_(dex_file), |
| 172 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 173 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 174 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 175 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 176 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 177 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 178 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 179 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 180 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 181 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 182 | cached_current_method_(nullptr) { |
| 183 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 184 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 185 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 186 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 187 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 188 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 189 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 190 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 191 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 192 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 193 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 194 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 195 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 196 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 197 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 198 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 199 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 200 | // Try building the SSA form of this graph, with dominance computation and loop |
| 201 | // recognition. Returns whether it was successful in doing all these steps. |
| 202 | bool TryBuildingSsa() { |
| 203 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 204 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 205 | // elimination phase checks the consistency of the graph when doing a post-order |
| 206 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 207 | // users remaining when being visited. |
| 208 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 209 | // Precompute per-block try membership before entering the SSA builder, |
| 210 | // which needs the information to build catch block phis from values of |
| 211 | // locals at throwing instructions inside try blocks. |
| 212 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 213 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 214 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 215 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 218 | void ComputeDominanceInformation(); |
| 219 | void ClearDominanceInformation(); |
| 220 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 221 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 222 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 223 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 224 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 225 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 226 | // Analyze all natural loops in this graph. Returns false if one |
| 227 | // loop is not natural, that is the header does not dominate the |
| 228 | // back edge. |
| 229 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 230 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 231 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 232 | // order and loop information. |
| 233 | void ComputeTryBlockInformation(); |
| 234 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 235 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 236 | // Returns the instruction used to replace the invoke expression or null if the |
| 237 | // invoke is for a void method. |
| 238 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 239 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 240 | // Need to add a couple of blocks to test if the loop body is entered and |
| 241 | // put deoptimization instructions, etc. |
| 242 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 243 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 244 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 245 | // other blocks and has no instructions or phis. |
| 246 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 247 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 248 | // Splits the edge between `block` and `successor` while preserving the |
| 249 | // indices in the predecessor/successor lists. If there are multiple edges |
| 250 | // between the blocks, the lowest indices are used. |
| 251 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 252 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 253 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 254 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 255 | void SimplifyLoop(HBasicBlock* header); |
| 256 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 257 | int32_t GetNextInstructionId() { |
| 258 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 259 | return current_instruction_id_++; |
| 260 | } |
| 261 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 262 | int32_t GetCurrentInstructionId() const { |
| 263 | return current_instruction_id_; |
| 264 | } |
| 265 | |
| 266 | void SetCurrentInstructionId(int32_t id) { |
| 267 | current_instruction_id_ = id; |
| 268 | } |
| 269 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 270 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 271 | return maximum_number_of_out_vregs_; |
| 272 | } |
| 273 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 274 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 275 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 276 | } |
| 277 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 278 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 279 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 280 | } |
| 281 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 282 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 283 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 286 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 287 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 288 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 291 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 292 | number_of_vregs_ = number_of_vregs; |
| 293 | } |
| 294 | |
| 295 | uint16_t GetNumberOfVRegs() const { |
| 296 | return number_of_vregs_; |
| 297 | } |
| 298 | |
| 299 | void SetNumberOfInVRegs(uint16_t value) { |
| 300 | number_of_in_vregs_ = value; |
| 301 | } |
| 302 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 303 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 304 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 305 | return number_of_vregs_ - number_of_in_vregs_; |
| 306 | } |
| 307 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 308 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 309 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 310 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 311 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 312 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 313 | return linear_order_; |
| 314 | } |
| 315 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 316 | bool HasBoundsChecks() const { |
| 317 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 320 | void SetHasBoundsChecks(bool value) { |
| 321 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 324 | bool ShouldGenerateConstructorBarrier() const { |
| 325 | return should_generate_constructor_barrier_; |
| 326 | } |
| 327 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 328 | bool IsDebuggable() const { return debuggable_; } |
| 329 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 330 | // 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] | 331 | // already, it is created and inserted into the graph. This method is only for |
| 332 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 333 | 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] | 334 | |
| 335 | // TODO: This is problematic for the consistency of reference type propagation |
| 336 | // because it can be created anytime after the pass and thus it will be left |
| 337 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 338 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 339 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 340 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 341 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 342 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 343 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 344 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 345 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 346 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 347 | 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] | 348 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 349 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 350 | 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] | 351 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 352 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 353 | HCurrentMethod* GetCurrentMethod(); |
| 354 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 355 | const DexFile& GetDexFile() const { |
| 356 | return dex_file_; |
| 357 | } |
| 358 | |
| 359 | uint32_t GetMethodIdx() const { |
| 360 | return method_idx_; |
| 361 | } |
| 362 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 363 | InvokeType GetInvokeType() const { |
| 364 | return invoke_type_; |
| 365 | } |
| 366 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 367 | InstructionSet GetInstructionSet() const { |
| 368 | return instruction_set_; |
| 369 | } |
| 370 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 371 | bool HasTryCatch() const { return has_try_catch_; } |
| 372 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 373 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame^] | 374 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 375 | // The instruction has been inserted into the graph, either as a constant, or |
| 376 | // before cursor. |
| 377 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 378 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 379 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 380 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 381 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 382 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 383 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 384 | template <class InstructionType, typename ValueType> |
| 385 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 386 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 387 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 388 | // Try to find an existing constant of the given value. |
| 389 | InstructionType* constant = nullptr; |
| 390 | auto cached_constant = cache->find(value); |
| 391 | if (cached_constant != cache->end()) { |
| 392 | constant = cached_constant->second; |
| 393 | } |
| 394 | |
| 395 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 396 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 397 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 398 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 399 | cache->Overwrite(value, constant); |
| 400 | InsertConstant(constant); |
| 401 | } |
| 402 | return constant; |
| 403 | } |
| 404 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 405 | void InsertConstant(HConstant* instruction); |
| 406 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 407 | // Cache a float constant into the graph. This method should only be |
| 408 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 409 | void CacheFloatConstant(HFloatConstant* constant); |
| 410 | |
| 411 | // See CacheFloatConstant comment. |
| 412 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 413 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 414 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 415 | |
| 416 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 417 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 418 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 419 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 420 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 421 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 422 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 423 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 424 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 425 | HBasicBlock* entry_block_; |
| 426 | HBasicBlock* exit_block_; |
| 427 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 428 | // 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] | 429 | uint16_t maximum_number_of_out_vregs_; |
| 430 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 431 | // The number of virtual registers in this method. Contains the parameters. |
| 432 | uint16_t number_of_vregs_; |
| 433 | |
| 434 | // The number of virtual registers used by parameters of this method. |
| 435 | uint16_t number_of_in_vregs_; |
| 436 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 437 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 438 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 439 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 440 | // Has bounds checks. We can totally skip BCE if it's false. |
| 441 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 442 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 443 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 444 | // try/catch-related passes if false. |
| 445 | bool has_try_catch_; |
| 446 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 447 | // Indicates whether the graph should be compiled in a way that |
| 448 | // ensures full debuggability. If false, we can apply more |
| 449 | // aggressive optimizations that may limit the level of debugging. |
| 450 | const bool debuggable_; |
| 451 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 452 | // 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] | 453 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 454 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 455 | // The dex file from which the method is from. |
| 456 | const DexFile& dex_file_; |
| 457 | |
| 458 | // The method index in the dex file. |
| 459 | const uint32_t method_idx_; |
| 460 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 461 | // If inlined, this encodes how the callee is being invoked. |
| 462 | const InvokeType invoke_type_; |
| 463 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 464 | // Whether the graph has been transformed to SSA form. Only used |
| 465 | // in debug mode to ensure we are not using properties only valid |
| 466 | // for non-SSA form (like the number of temporaries). |
| 467 | bool in_ssa_form_; |
| 468 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 469 | const bool should_generate_constructor_barrier_; |
| 470 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 471 | const InstructionSet instruction_set_; |
| 472 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 473 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 474 | HNullConstant* cached_null_constant_; |
| 475 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 476 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 477 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 478 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 479 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 480 | HCurrentMethod* cached_current_method_; |
| 481 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 482 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 483 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 484 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 485 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 486 | }; |
| 487 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 488 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 489 | public: |
| 490 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 491 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 492 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 493 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 494 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 495 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 496 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 497 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 498 | |
| 499 | HBasicBlock* GetHeader() const { |
| 500 | return header_; |
| 501 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 502 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 503 | void SetHeader(HBasicBlock* block) { |
| 504 | header_ = block; |
| 505 | } |
| 506 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 507 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 508 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 509 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 510 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 511 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 512 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 515 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 516 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 517 | } |
| 518 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 519 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 520 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 521 | } |
| 522 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 523 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 524 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 527 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 528 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 529 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 530 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 533 | // Returns the lifetime position of the back edge that has the |
| 534 | // greatest lifetime position. |
| 535 | size_t GetLifetimeEnd() const; |
| 536 | |
| 537 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 538 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 539 | } |
| 540 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 541 | // 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] | 542 | // that is the header dominates the back edge. |
| 543 | bool Populate(); |
| 544 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 545 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 546 | // Populate(). If there are no back edges left, the loop info is completely |
| 547 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 548 | // inner loops first. |
| 549 | void Update(); |
| 550 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 551 | // Returns whether this loop information contains `block`. |
| 552 | // Note that this loop information *must* be populated before entering this function. |
| 553 | bool Contains(const HBasicBlock& block) const; |
| 554 | |
| 555 | // Returns whether this loop information is an inner loop of `other`. |
| 556 | // Note that `other` *must* be populated before entering this function. |
| 557 | bool IsIn(const HLoopInformation& other) const; |
| 558 | |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 559 | // Returns true if instruction is not defined within this loop or any loop nested inside |
| 560 | // this loop. If must_dominate is set, only definitions that actually dominate the loop |
| 561 | // header can be invariant. Otherwise, any definition outside the loop, including |
| 562 | // definitions that appear after the loop, is invariant. |
| 563 | bool IsLoopInvariant(HInstruction* instruction, bool must_dominate) const; |
| 564 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 565 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 566 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 567 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 568 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 569 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 570 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 571 | // Internal recursive implementation of `Populate`. |
| 572 | void PopulateRecursive(HBasicBlock* block); |
| 573 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 574 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 575 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 576 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 577 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 578 | |
| 579 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 580 | }; |
| 581 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 582 | // Stores try/catch information for basic blocks. |
| 583 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 584 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 585 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 586 | public: |
| 587 | // Try block information constructor. |
| 588 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 589 | : try_entry_(&try_entry), |
| 590 | catch_dex_file_(nullptr), |
| 591 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 592 | DCHECK(try_entry_ != nullptr); |
| 593 | } |
| 594 | |
| 595 | // Catch block information constructor. |
| 596 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 597 | : try_entry_(nullptr), |
| 598 | catch_dex_file_(&dex_file), |
| 599 | catch_type_index_(catch_type_index) {} |
| 600 | |
| 601 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 602 | |
| 603 | const HTryBoundary& GetTryEntry() const { |
| 604 | DCHECK(IsTryBlock()); |
| 605 | return *try_entry_; |
| 606 | } |
| 607 | |
| 608 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 609 | |
| 610 | bool IsCatchAllTypeIndex() const { |
| 611 | DCHECK(IsCatchBlock()); |
| 612 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 613 | } |
| 614 | |
| 615 | uint16_t GetCatchTypeIndex() const { |
| 616 | DCHECK(IsCatchBlock()); |
| 617 | return catch_type_index_; |
| 618 | } |
| 619 | |
| 620 | const DexFile& GetCatchDexFile() const { |
| 621 | DCHECK(IsCatchBlock()); |
| 622 | return *catch_dex_file_; |
| 623 | } |
| 624 | |
| 625 | private: |
| 626 | // One of possibly several TryBoundary instructions entering the block's try. |
| 627 | // Only set for try blocks. |
| 628 | const HTryBoundary* try_entry_; |
| 629 | |
| 630 | // Exception type information. Only set for catch blocks. |
| 631 | const DexFile* catch_dex_file_; |
| 632 | const uint16_t catch_type_index_; |
| 633 | }; |
| 634 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 635 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 636 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 637 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 638 | // A block in a method. Contains the list of instructions represented |
| 639 | // as a double linked list. Each block knows its predecessors and |
| 640 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 641 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 642 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 643 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 644 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 645 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 646 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 647 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 648 | loop_information_(nullptr), |
| 649 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 650 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 651 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 652 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 653 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 654 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 655 | try_catch_information_(nullptr) { |
| 656 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 657 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 658 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 659 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 660 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 661 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 662 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 665 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 666 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 667 | } |
| 668 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 669 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 670 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 671 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 672 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 673 | return ContainsElement(successors_, block, start_from); |
| 674 | } |
| 675 | |
| 676 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 677 | return dominated_blocks_; |
| 678 | } |
| 679 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 680 | bool IsEntryBlock() const { |
| 681 | return graph_->GetEntryBlock() == this; |
| 682 | } |
| 683 | |
| 684 | bool IsExitBlock() const { |
| 685 | return graph_->GetExitBlock() == this; |
| 686 | } |
| 687 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 688 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 689 | bool IsSingleTryBoundary() const; |
| 690 | |
| 691 | // Returns true if this block emits nothing but a jump. |
| 692 | bool IsSingleJump() const { |
| 693 | HLoopInformation* loop_info = GetLoopInformation(); |
| 694 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 695 | // Back edges generate a suspend check. |
| 696 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 697 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 698 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 699 | void AddBackEdge(HBasicBlock* back_edge) { |
| 700 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 701 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 702 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 703 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 704 | loop_information_->AddBackEdge(back_edge); |
| 705 | } |
| 706 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 707 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 708 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 709 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 710 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 711 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 712 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 713 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 714 | HBasicBlock* GetDominator() const { return dominator_; } |
| 715 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 716 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 717 | |
| 718 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 719 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 720 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 721 | |
| 722 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 723 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 724 | } |
| 725 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 726 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 727 | |
| 728 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 729 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 732 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 733 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 734 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 735 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 736 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 737 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 738 | |
| 739 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 740 | successors_.push_back(block); |
| 741 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 744 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 745 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 746 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 747 | new_block->predecessors_.push_back(this); |
| 748 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 751 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 752 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 753 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 754 | new_block->successors_.push_back(this); |
| 755 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 758 | // Insert `this` between `predecessor` and `successor. This method |
| 759 | // preserves the indicies, and will update the first edge found between |
| 760 | // `predecessor` and `successor`. |
| 761 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 762 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 763 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 764 | successor->predecessors_[predecessor_index] = this; |
| 765 | predecessor->successors_[successor_index] = this; |
| 766 | successors_.push_back(successor); |
| 767 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 768 | } |
| 769 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 770 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 771 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 772 | } |
| 773 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 774 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 775 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 778 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 779 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 783 | predecessors_.push_back(block); |
| 784 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 785 | } |
| 786 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 787 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 788 | DCHECK_EQ(predecessors_.size(), 2u); |
| 789 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 790 | } |
| 791 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 792 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 793 | DCHECK_EQ(successors_.size(), 2u); |
| 794 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 795 | } |
| 796 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 797 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 798 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 799 | } |
| 800 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 801 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 802 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 803 | } |
| 804 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 805 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 806 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 807 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 812 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Returns whether the first occurrence of `predecessor` in the list of |
| 816 | // predecessors is at index `idx`. |
| 817 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 818 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 819 | return GetPredecessorIndexOf(predecessor) == idx; |
| 820 | } |
| 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 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 842 | // Split catch block into two blocks after the original move-exception bytecode |
| 843 | // instruction, or at the beginning if not present. Returns the newly created, |
| 844 | // latter block, or nullptr if such block could not be created (must be dead |
| 845 | // in that case). Note that this method just updates raw block information, |
| 846 | // like predecessors, successors, dominators, and instruction list. It does not |
| 847 | // update the graph, reverse post order, loop information, nor make sure the |
| 848 | // blocks are consistent (for example ending with a control flow instruction). |
| 849 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 850 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 851 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 852 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 853 | // that this method does not update the graph, reverse post order, loop |
| 854 | // information, nor make sure the blocks are consistent (for example ending |
| 855 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 856 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 857 | |
| 858 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 859 | // of `this` are moved to `other`. |
| 860 | // Note that this method does not update the graph, reverse post order, loop |
| 861 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 862 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 863 | void ReplaceWith(HBasicBlock* other); |
| 864 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 865 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 866 | // order, links to predecessors, successors, dominators and deletes the block |
| 867 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 868 | // predecessor of `other` and vice versa. |
| 869 | void MergeWith(HBasicBlock* other); |
| 870 | |
| 871 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 872 | // removes it from all loops it is included in and eventually from the graph. |
| 873 | // The block must not dominate any other block. Predecessors and successors |
| 874 | // are safely updated. |
| 875 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 876 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 877 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 878 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 879 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 880 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 881 | // Replace instruction `initial` with `replacement` within this block. |
| 882 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 883 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 884 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 885 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 886 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 887 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 888 | // instruction is not in use and removes it from the use lists of its inputs. |
| 889 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 890 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 891 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 892 | |
| 893 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 894 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 895 | } |
| 896 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 897 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 898 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 899 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 902 | HLoopInformation* GetLoopInformation() const { |
| 903 | return loop_information_; |
| 904 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 905 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 906 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 907 | // 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] | 908 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 909 | void SetInLoop(HLoopInformation* info) { |
| 910 | if (IsLoopHeader()) { |
| 911 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 912 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 913 | loop_information_ = info; |
| 914 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 915 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 916 | // Note that a non loop header having a loop information means this loop information |
| 917 | // has already been populated |
| 918 | loop_information_ = info; |
| 919 | } else { |
| 920 | // Block is part of an inner loop. Do not update the loop information. |
| 921 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 922 | // at this point, because this method is being called while populating `info`. |
| 923 | } |
| 924 | } |
| 925 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 926 | // Raw update of the loop information. |
| 927 | void SetLoopInformation(HLoopInformation* info) { |
| 928 | loop_information_ = info; |
| 929 | } |
| 930 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 931 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 932 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 933 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 934 | |
| 935 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 936 | try_catch_information_ = try_catch_information; |
| 937 | } |
| 938 | |
| 939 | bool IsTryBlock() const { |
| 940 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 941 | } |
| 942 | |
| 943 | bool IsCatchBlock() const { |
| 944 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 945 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 946 | |
| 947 | // Returns the try entry that this block's successors should have. They will |
| 948 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 949 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 950 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 951 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 952 | bool HasThrowingInstructions() const; |
| 953 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 954 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 955 | bool Dominates(HBasicBlock* block) const; |
| 956 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 957 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 958 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 959 | |
| 960 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 961 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 962 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 963 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 964 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 965 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 966 | bool HasSinglePhi() const; |
| 967 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 968 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 969 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 970 | ArenaVector<HBasicBlock*> predecessors_; |
| 971 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 972 | HInstructionList instructions_; |
| 973 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 974 | HLoopInformation* loop_information_; |
| 975 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 976 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 977 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 978 | // The dex program counter of the first instruction of this block. |
| 979 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 980 | size_t lifetime_start_; |
| 981 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 982 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 983 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 984 | friend class HGraph; |
| 985 | friend class HInstruction; |
| 986 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 987 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 988 | }; |
| 989 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 990 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 991 | // from the innermost to the outermost. |
| 992 | class HLoopInformationOutwardIterator : public ValueObject { |
| 993 | public: |
| 994 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 995 | : current_(block.GetLoopInformation()) {} |
| 996 | |
| 997 | bool Done() const { return current_ == nullptr; } |
| 998 | |
| 999 | void Advance() { |
| 1000 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1001 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | HLoopInformation* Current() const { |
| 1005 | DCHECK(!Done()); |
| 1006 | return current_; |
| 1007 | } |
| 1008 | |
| 1009 | private: |
| 1010 | HLoopInformation* current_; |
| 1011 | |
| 1012 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1013 | }; |
| 1014 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1015 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1016 | M(Above, Condition) \ |
| 1017 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1018 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1019 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1020 | M(ArrayGet, Instruction) \ |
| 1021 | M(ArrayLength, Instruction) \ |
| 1022 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1023 | M(Below, Condition) \ |
| 1024 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1025 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1026 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1027 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1028 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1029 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1030 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1031 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1032 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1033 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1034 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1035 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1036 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1037 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1038 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1039 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1040 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1041 | M(FloatConstant, Constant) \ |
| 1042 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1043 | M(GreaterThan, Condition) \ |
| 1044 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1045 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1046 | M(InstanceFieldGet, Instruction) \ |
| 1047 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1048 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1049 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1050 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1051 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1052 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1053 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1054 | M(LessThan, Condition) \ |
| 1055 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1056 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1057 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1058 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1059 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1060 | M(Local, Instruction) \ |
| 1061 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1062 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1063 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1064 | M(Mul, BinaryOperation) \ |
| 1065 | M(Neg, UnaryOperation) \ |
| 1066 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1067 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1068 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1069 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1070 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1071 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1072 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1073 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1074 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1075 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1076 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1077 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1078 | M(Return, Instruction) \ |
| 1079 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1080 | M(Shl, BinaryOperation) \ |
| 1081 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1082 | M(StaticFieldGet, Instruction) \ |
| 1083 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1084 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1085 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1086 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1087 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1088 | M(StoreLocal, Instruction) \ |
| 1089 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1090 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1091 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1092 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1093 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1094 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1095 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1096 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1097 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1098 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1099 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1100 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1101 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1102 | #else |
| 1103 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
| 1104 | M(Arm64IntermediateAddress, Instruction) |
| 1105 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1106 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1107 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1108 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1109 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1110 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1111 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1112 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1113 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1114 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1115 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1116 | M(X86LoadFromConstantTable, Instruction) \ |
| 1117 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1118 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1119 | |
| 1120 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1121 | |
| 1122 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1123 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1124 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1125 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1126 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1127 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1128 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1129 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1130 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1131 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1132 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1133 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1134 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1135 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1136 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1137 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1138 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1139 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1140 | #undef FORWARD_DECLARATION |
| 1141 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1142 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1143 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1144 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1145 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1146 | H##type* As##type() OVERRIDE { return this; } \ |
| 1147 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1148 | return other->Is##type(); \ |
| 1149 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1150 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1151 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1152 | template <typename T> class HUseList; |
| 1153 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1154 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1155 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1156 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1157 | HUseListNode* GetPrevious() const { return prev_; } |
| 1158 | HUseListNode* GetNext() const { return next_; } |
| 1159 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1160 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1161 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1162 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1163 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1164 | HUseListNode(T user, size_t index) |
| 1165 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1166 | |
| 1167 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1168 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1169 | HUseListNode<T>* prev_; |
| 1170 | HUseListNode<T>* next_; |
| 1171 | |
| 1172 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1173 | |
| 1174 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1175 | }; |
| 1176 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1177 | template <typename T> |
| 1178 | class HUseList : public ValueObject { |
| 1179 | public: |
| 1180 | HUseList() : first_(nullptr) {} |
| 1181 | |
| 1182 | void Clear() { |
| 1183 | first_ = nullptr; |
| 1184 | } |
| 1185 | |
| 1186 | // Adds a new entry at the beginning of the use list and returns |
| 1187 | // the newly created node. |
| 1188 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1189 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1190 | if (IsEmpty()) { |
| 1191 | first_ = new_node; |
| 1192 | } else { |
| 1193 | first_->prev_ = new_node; |
| 1194 | new_node->next_ = first_; |
| 1195 | first_ = new_node; |
| 1196 | } |
| 1197 | return new_node; |
| 1198 | } |
| 1199 | |
| 1200 | HUseListNode<T>* GetFirst() const { |
| 1201 | return first_; |
| 1202 | } |
| 1203 | |
| 1204 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1205 | DCHECK(node != nullptr); |
| 1206 | DCHECK(Contains(node)); |
| 1207 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1208 | if (node->prev_ != nullptr) { |
| 1209 | node->prev_->next_ = node->next_; |
| 1210 | } |
| 1211 | if (node->next_ != nullptr) { |
| 1212 | node->next_->prev_ = node->prev_; |
| 1213 | } |
| 1214 | if (node == first_) { |
| 1215 | first_ = node->next_; |
| 1216 | } |
| 1217 | } |
| 1218 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1219 | bool Contains(const HUseListNode<T>* node) const { |
| 1220 | if (node == nullptr) { |
| 1221 | return false; |
| 1222 | } |
| 1223 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1224 | if (current == node) { |
| 1225 | return true; |
| 1226 | } |
| 1227 | } |
| 1228 | return false; |
| 1229 | } |
| 1230 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1231 | bool IsEmpty() const { |
| 1232 | return first_ == nullptr; |
| 1233 | } |
| 1234 | |
| 1235 | bool HasOnlyOneUse() const { |
| 1236 | return first_ != nullptr && first_->next_ == nullptr; |
| 1237 | } |
| 1238 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1239 | size_t SizeSlow() const { |
| 1240 | size_t count = 0; |
| 1241 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1242 | ++count; |
| 1243 | } |
| 1244 | return count; |
| 1245 | } |
| 1246 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1247 | private: |
| 1248 | HUseListNode<T>* first_; |
| 1249 | }; |
| 1250 | |
| 1251 | template<typename T> |
| 1252 | class HUseIterator : public ValueObject { |
| 1253 | public: |
| 1254 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1255 | |
| 1256 | bool Done() const { return current_ == nullptr; } |
| 1257 | |
| 1258 | void Advance() { |
| 1259 | DCHECK(!Done()); |
| 1260 | current_ = current_->GetNext(); |
| 1261 | } |
| 1262 | |
| 1263 | HUseListNode<T>* Current() const { |
| 1264 | DCHECK(!Done()); |
| 1265 | return current_; |
| 1266 | } |
| 1267 | |
| 1268 | private: |
| 1269 | HUseListNode<T>* current_; |
| 1270 | |
| 1271 | friend class HValue; |
| 1272 | }; |
| 1273 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1274 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1275 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1276 | // by the used instructions. |
| 1277 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1278 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1279 | public: |
| 1280 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1281 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1282 | |
| 1283 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1284 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1285 | DCHECK(instruction_ != nullptr); |
| 1286 | DCHECK(use_node_ != nullptr); |
| 1287 | DCHECK(old_record.use_node_ == nullptr); |
| 1288 | } |
| 1289 | |
| 1290 | HInstruction* GetInstruction() const { return instruction_; } |
| 1291 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1292 | |
| 1293 | private: |
| 1294 | // Instruction used by the user. |
| 1295 | HInstruction* instruction_; |
| 1296 | |
| 1297 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1298 | HUseListNode<T>* use_node_; |
| 1299 | }; |
| 1300 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1301 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1302 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1303 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1304 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1305 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1306 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1307 | * modify the value of a reference field read [although it may modify the |
| 1308 | * reference fetch prior to reading the field, which is represented by its own |
| 1309 | * write/read dependence]). The analysis makes conservative points-to |
| 1310 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1311 | * the same, and any reference read depends on any reference read without |
| 1312 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1313 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1314 | * The internal representation uses 38-bit and is described in the table below. |
| 1315 | * The first line indicates the side effect, and for field/array accesses the |
| 1316 | * second line indicates the type of the access (in the order of the |
| 1317 | * Primitive::Type enum). |
| 1318 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1319 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1320 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1321 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1322 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1323 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1324 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1325 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1326 | * |
| 1327 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1328 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1329 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1330 | class SideEffects : public ValueObject { |
| 1331 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1332 | SideEffects() : flags_(0) {} |
| 1333 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1334 | static SideEffects None() { |
| 1335 | return SideEffects(0); |
| 1336 | } |
| 1337 | |
| 1338 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1339 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1340 | } |
| 1341 | |
| 1342 | static SideEffects AllChanges() { |
| 1343 | return SideEffects(kAllChangeBits); |
| 1344 | } |
| 1345 | |
| 1346 | static SideEffects AllDependencies() { |
| 1347 | return SideEffects(kAllDependOnBits); |
| 1348 | } |
| 1349 | |
| 1350 | static SideEffects AllExceptGCDependency() { |
| 1351 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1352 | } |
| 1353 | |
| 1354 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1355 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1356 | } |
| 1357 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1358 | static SideEffects AllWrites() { |
| 1359 | return SideEffects(kAllWrites); |
| 1360 | } |
| 1361 | |
| 1362 | static SideEffects AllReads() { |
| 1363 | return SideEffects(kAllReads); |
| 1364 | } |
| 1365 | |
| 1366 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1367 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1368 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1369 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1372 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1373 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1374 | } |
| 1375 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1376 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1377 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1378 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1379 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1383 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1384 | } |
| 1385 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1386 | static SideEffects CanTriggerGC() { |
| 1387 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1388 | } |
| 1389 | |
| 1390 | static SideEffects DependsOnGC() { |
| 1391 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1392 | } |
| 1393 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1394 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1395 | SideEffects Union(SideEffects other) const { |
| 1396 | return SideEffects(flags_ | other.flags_); |
| 1397 | } |
| 1398 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1399 | SideEffects Exclusion(SideEffects other) const { |
| 1400 | return SideEffects(flags_ & ~other.flags_); |
| 1401 | } |
| 1402 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1403 | void Add(SideEffects other) { |
| 1404 | flags_ |= other.flags_; |
| 1405 | } |
| 1406 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1407 | bool Includes(SideEffects other) const { |
| 1408 | return (other.flags_ & flags_) == other.flags_; |
| 1409 | } |
| 1410 | |
| 1411 | bool HasSideEffects() const { |
| 1412 | return (flags_ & kAllChangeBits); |
| 1413 | } |
| 1414 | |
| 1415 | bool HasDependencies() const { |
| 1416 | return (flags_ & kAllDependOnBits); |
| 1417 | } |
| 1418 | |
| 1419 | // Returns true if there are no side effects or dependencies. |
| 1420 | bool DoesNothing() const { |
| 1421 | return flags_ == 0; |
| 1422 | } |
| 1423 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1424 | // Returns true if something is written. |
| 1425 | bool DoesAnyWrite() const { |
| 1426 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1427 | } |
| 1428 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1429 | // Returns true if something is read. |
| 1430 | bool DoesAnyRead() const { |
| 1431 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1432 | } |
| 1433 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1434 | // Returns true if potentially everything is written and read |
| 1435 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1436 | bool DoesAllReadWrite() const { |
| 1437 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1438 | } |
| 1439 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1440 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1441 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1444 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1445 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1446 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1447 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1451 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1452 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1453 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1454 | for (int s = kLastBit; s >= 0; s--) { |
| 1455 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1456 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1457 | // This is a bit for the GC side effect. |
| 1458 | if (current_bit_is_set) { |
| 1459 | flags += "GC"; |
| 1460 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1461 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1462 | } else { |
| 1463 | // This is a bit for the array/field analysis. |
| 1464 | // The underscore character stands for the 'can trigger GC' bit. |
| 1465 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1466 | if (current_bit_is_set) { |
| 1467 | flags += kDebug[s]; |
| 1468 | } |
| 1469 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1470 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1471 | flags += "|"; |
| 1472 | } |
| 1473 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1474 | } |
| 1475 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1476 | } |
| 1477 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1478 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1479 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1480 | private: |
| 1481 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1482 | |
| 1483 | static constexpr int kFieldWriteOffset = 0; |
| 1484 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1485 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1486 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1487 | |
| 1488 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1489 | |
| 1490 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1491 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1492 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1493 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1494 | |
| 1495 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1496 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1497 | |
| 1498 | // Aliases. |
| 1499 | |
| 1500 | static_assert(kChangeBits == kDependOnBits, |
| 1501 | "the 'change' bits should match the 'depend on' bits."); |
| 1502 | |
| 1503 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1504 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1505 | static constexpr uint64_t kAllWrites = |
| 1506 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1507 | static constexpr uint64_t kAllReads = |
| 1508 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1509 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1510 | // Work around the fact that HIR aliases I/F and J/D. |
| 1511 | // TODO: remove this interceptor once HIR types are clean |
| 1512 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1513 | switch (type) { |
| 1514 | case Primitive::kPrimInt: |
| 1515 | case Primitive::kPrimFloat: |
| 1516 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1517 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1518 | case Primitive::kPrimLong: |
| 1519 | case Primitive::kPrimDouble: |
| 1520 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1521 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1522 | default: |
| 1523 | return TypeFlag(type, offset); |
| 1524 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1525 | } |
| 1526 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1527 | // Translates type to bit flag. |
| 1528 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1529 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1530 | const uint64_t one = 1; |
| 1531 | const int shift = type; // 0-based consecutive enum |
| 1532 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1533 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1534 | return one << (type + offset); |
| 1535 | } |
| 1536 | |
| 1537 | // Private constructor on direct flags value. |
| 1538 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1539 | |
| 1540 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1541 | }; |
| 1542 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1543 | // 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] | 1544 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1545 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1546 | HEnvironment(ArenaAllocator* arena, |
| 1547 | size_t number_of_vregs, |
| 1548 | const DexFile& dex_file, |
| 1549 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1550 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1551 | InvokeType invoke_type, |
| 1552 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1553 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1554 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1555 | parent_(nullptr), |
| 1556 | dex_file_(dex_file), |
| 1557 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1558 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1559 | invoke_type_(invoke_type), |
| 1560 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1561 | } |
| 1562 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1563 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1564 | : HEnvironment(arena, |
| 1565 | to_copy.Size(), |
| 1566 | to_copy.GetDexFile(), |
| 1567 | to_copy.GetMethodIdx(), |
| 1568 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1569 | to_copy.GetInvokeType(), |
| 1570 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1571 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1572 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1573 | if (parent_ != nullptr) { |
| 1574 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1575 | } else { |
| 1576 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1577 | parent_->CopyFrom(parent); |
| 1578 | if (parent->GetParent() != nullptr) { |
| 1579 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1580 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1581 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1584 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1585 | void CopyFrom(HEnvironment* environment); |
| 1586 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1587 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1588 | // input to the loop phi instead. This is for inserting instructions that |
| 1589 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1590 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1591 | |
| 1592 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1593 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1597 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1598 | } |
| 1599 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1600 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1601 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1602 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1603 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1604 | HEnvironment* GetParent() const { return parent_; } |
| 1605 | |
| 1606 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1607 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1608 | } |
| 1609 | |
| 1610 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1611 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | uint32_t GetDexPc() const { |
| 1615 | return dex_pc_; |
| 1616 | } |
| 1617 | |
| 1618 | uint32_t GetMethodIdx() const { |
| 1619 | return method_idx_; |
| 1620 | } |
| 1621 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1622 | InvokeType GetInvokeType() const { |
| 1623 | return invoke_type_; |
| 1624 | } |
| 1625 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1626 | const DexFile& GetDexFile() const { |
| 1627 | return dex_file_; |
| 1628 | } |
| 1629 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1630 | HInstruction* GetHolder() const { |
| 1631 | return holder_; |
| 1632 | } |
| 1633 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1634 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1635 | // Record instructions' use entries of this environment for constant-time removal. |
| 1636 | // It should only be called by HInstruction when a new environment use is added. |
| 1637 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1638 | DCHECK(env_use->GetUser() == this); |
| 1639 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1640 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1641 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1642 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1643 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1644 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1645 | HEnvironment* parent_; |
| 1646 | const DexFile& dex_file_; |
| 1647 | const uint32_t method_idx_; |
| 1648 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1649 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1650 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1651 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1652 | HInstruction* const holder_; |
| 1653 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1654 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1655 | |
| 1656 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1657 | }; |
| 1658 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1659 | class ReferenceTypeInfo : ValueObject { |
| 1660 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1661 | typedef Handle<mirror::Class> TypeHandle; |
| 1662 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1663 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1664 | // The constructor will check that the type_handle is valid. |
| 1665 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1668 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1669 | |
| 1670 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1671 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1674 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1675 | return IsValidHandle(type_handle_); |
| 1676 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1677 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1678 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1679 | |
| 1680 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1681 | DCHECK(IsValid()); |
| 1682 | return GetTypeHandle()->IsObjectClass(); |
| 1683 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1684 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1685 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1686 | DCHECK(IsValid()); |
| 1687 | return GetTypeHandle()->IsStringClass(); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1688 | } |
| 1689 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1690 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1691 | DCHECK(IsValid()); |
| 1692 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 1693 | } |
| 1694 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1695 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1696 | DCHECK(IsValid()); |
| 1697 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1698 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1699 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1700 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1701 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1702 | return GetTypeHandle()->IsArrayClass(); |
| 1703 | } |
| 1704 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1705 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1706 | DCHECK(IsValid()); |
| 1707 | return GetTypeHandle()->IsPrimitiveArray(); |
| 1708 | } |
| 1709 | |
| 1710 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1711 | DCHECK(IsValid()); |
| 1712 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 1713 | } |
| 1714 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1715 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1716 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1717 | if (!IsExact()) return false; |
| 1718 | if (!IsArrayClass()) return false; |
| 1719 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1720 | } |
| 1721 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1722 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1723 | DCHECK(IsValid()); |
| 1724 | if (!IsExact()) return false; |
| 1725 | if (!IsArrayClass()) return false; |
| 1726 | if (!rti.IsArrayClass()) return false; |
| 1727 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 1728 | rti.GetTypeHandle()->GetComponentType()); |
| 1729 | } |
| 1730 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1731 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1732 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1733 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1734 | DCHECK(IsValid()); |
| 1735 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1736 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1737 | } |
| 1738 | |
Calin Juravle | cdfed3d | 2015-10-26 14:05:01 +0000 | [diff] [blame] | 1739 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1740 | DCHECK(IsValid()); |
| 1741 | DCHECK(rti.IsValid()); |
| 1742 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 1743 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1744 | } |
| 1745 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1746 | // Returns true if the type information provide the same amount of details. |
| 1747 | // 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] | 1748 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1749 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1750 | if (!IsValid() && !rti.IsValid()) { |
| 1751 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1752 | return true; |
| 1753 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1754 | if (!IsValid() || !rti.IsValid()) { |
| 1755 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1756 | return false; |
| 1757 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1758 | return IsExact() == rti.IsExact() |
| 1759 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
| 1762 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1763 | ReferenceTypeInfo(); |
| 1764 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1765 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1766 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1767 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1768 | // 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] | 1769 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1770 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1771 | }; |
| 1772 | |
| 1773 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1774 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1775 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1776 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1777 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1778 | : previous_(nullptr), |
| 1779 | next_(nullptr), |
| 1780 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1781 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1782 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1783 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1784 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1785 | locations_(nullptr), |
| 1786 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1787 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1788 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1789 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1790 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1791 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1792 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1793 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1794 | enum InstructionKind { |
| 1795 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1796 | }; |
| 1797 | #undef DECLARE_KIND |
| 1798 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1799 | HInstruction* GetNext() const { return next_; } |
| 1800 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1801 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1802 | HInstruction* GetNextDisregardingMoves() const; |
| 1803 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1804 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1805 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1806 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1807 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1808 | bool IsInBlock() const { return block_ != nullptr; } |
| 1809 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1810 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1811 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1812 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1813 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1814 | |
| 1815 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1816 | virtual const char* DebugName() const = 0; |
| 1817 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1818 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1819 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1820 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1821 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1822 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1823 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1824 | |
| 1825 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1826 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1827 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1828 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1829 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1830 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1831 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1832 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1833 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1834 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1835 | // Does not apply for all instructions, but having this at top level greatly |
| 1836 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1837 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1838 | virtual bool CanBeNull() const { |
| 1839 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1840 | return true; |
| 1841 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1842 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1843 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1844 | return false; |
| 1845 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1846 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1847 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1848 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1849 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1850 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1851 | return reference_type_info_; |
| 1852 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1853 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1854 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1855 | DCHECK(user != nullptr); |
| 1856 | HUseListNode<HInstruction*>* use = |
| 1857 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1858 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1861 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1862 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1863 | HUseListNode<HEnvironment*>* env_use = |
| 1864 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1865 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1866 | } |
| 1867 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1868 | void RemoveAsUserOfInput(size_t input) { |
| 1869 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1870 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1871 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1872 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1873 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1874 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1875 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1876 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1877 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1878 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1879 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1880 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1881 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1882 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1883 | // Does this instruction strictly dominate `other_instruction`? |
| 1884 | // Returns false if this instruction and `other_instruction` are the same. |
| 1885 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1886 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1887 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1888 | int GetId() const { return id_; } |
| 1889 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1890 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1891 | int GetSsaIndex() const { return ssa_index_; } |
| 1892 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1893 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1894 | |
| 1895 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1896 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1897 | // Set the `environment_` field. Raw because this method does not |
| 1898 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1899 | void SetRawEnvironment(HEnvironment* environment) { |
| 1900 | DCHECK(environment_ == nullptr); |
| 1901 | DCHECK_EQ(environment->GetHolder(), this); |
| 1902 | environment_ = environment; |
| 1903 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1904 | |
| 1905 | // Set the environment of this instruction, copying it from `environment`. While |
| 1906 | // copying, the uses lists are being updated. |
| 1907 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1908 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1909 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1910 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1911 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1912 | if (environment->GetParent() != nullptr) { |
| 1913 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1914 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1915 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1916 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1917 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1918 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1919 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1920 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1921 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1922 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1923 | if (environment->GetParent() != nullptr) { |
| 1924 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1925 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1928 | // Returns the number of entries in the environment. Typically, that is the |
| 1929 | // number of dex registers in a method. It could be more in case of inlining. |
| 1930 | size_t EnvironmentSize() const; |
| 1931 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1932 | LocationSummary* GetLocations() const { return locations_; } |
| 1933 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1934 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1935 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1936 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1937 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1938 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1939 | // uses of this instruction by `other` are *not* updated. |
| 1940 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1941 | ReplaceWith(other); |
| 1942 | other->ReplaceInput(this, use_index); |
| 1943 | } |
| 1944 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1945 | // Move `this` instruction before `cursor`. |
| 1946 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1947 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1948 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1949 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1950 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1951 | virtual H##type* As##type() { return nullptr; } |
| 1952 | |
| 1953 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1954 | #undef INSTRUCTION_TYPE_CHECK |
| 1955 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1956 | // Returns whether the instruction can be moved within the graph. |
| 1957 | virtual bool CanBeMoved() const { return false; } |
| 1958 | |
| 1959 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1960 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1961 | return false; |
| 1962 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1963 | |
| 1964 | // Returns whether any data encoded in the two instructions is equal. |
| 1965 | // This method does not look at the inputs. Both instructions must be |
| 1966 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1967 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1968 | return false; |
| 1969 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1970 | |
| 1971 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1972 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1973 | // 2) Their inputs are identical. |
| 1974 | bool Equals(HInstruction* other) const; |
| 1975 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1976 | virtual InstructionKind GetKind() const = 0; |
| 1977 | |
| 1978 | virtual size_t ComputeHashCode() const { |
| 1979 | size_t result = GetKind(); |
| 1980 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1981 | result = (result * 31) + InputAt(i)->GetId(); |
| 1982 | } |
| 1983 | return result; |
| 1984 | } |
| 1985 | |
| 1986 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1987 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1988 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1989 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1990 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1991 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 1992 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 1993 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 1994 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1995 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 1996 | |
| 1997 | // Returns whether the code generation of the instruction will require to have access |
| 1998 | // to the current method. Such instructions are: |
| 1999 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2000 | // to walk the stack and have the current method stored at a specific stack address. |
| 2001 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2002 | // fields of the current method. |
| 2003 | bool NeedsCurrentMethod() const { |
| 2004 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2005 | } |
| 2006 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2007 | // Returns whether the code generation of the instruction will require to have access |
| 2008 | // to the dex cache of the current method's declaring class via the current method. |
| 2009 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2010 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2011 | // Does this instruction have any use in an environment before |
| 2012 | // control flow hits 'other'? |
| 2013 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2014 | |
| 2015 | // Remove all references to environment uses of this instruction. |
| 2016 | // The caller must ensure that this is safe to do. |
| 2017 | void RemoveEnvironmentUsers(); |
| 2018 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2019 | protected: |
| 2020 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2021 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2022 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2023 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2024 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2025 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2026 | HInstruction* previous_; |
| 2027 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2028 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2029 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2030 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2031 | // An instruction gets an id when it is added to the graph. |
| 2032 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2033 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2034 | int id_; |
| 2035 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2036 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2037 | int ssa_index_; |
| 2038 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2039 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2040 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2041 | |
| 2042 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2043 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2044 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2045 | // The environment associated with this instruction. Not null if the instruction |
| 2046 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2047 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2048 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2049 | // Set by the code generator. |
| 2050 | LocationSummary* locations_; |
| 2051 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2052 | // Set by the liveness analysis. |
| 2053 | LiveInterval* live_interval_; |
| 2054 | |
| 2055 | // Set by the liveness analysis, this is the position in a linear |
| 2056 | // order of blocks where this instruction's live interval start. |
| 2057 | size_t lifetime_position_; |
| 2058 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2059 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2060 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2061 | // TODO: for primitive types this should be marked as invalid. |
| 2062 | ReferenceTypeInfo reference_type_info_; |
| 2063 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2064 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2065 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2066 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2067 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2068 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2069 | |
| 2070 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2071 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2072 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2073 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2074 | class HInputIterator : public ValueObject { |
| 2075 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2076 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2077 | |
| 2078 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2079 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2080 | void Advance() { index_++; } |
| 2081 | |
| 2082 | private: |
| 2083 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2084 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2085 | |
| 2086 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2087 | }; |
| 2088 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2089 | class HInstructionIterator : public ValueObject { |
| 2090 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2091 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2092 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2093 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2096 | bool Done() const { return instruction_ == nullptr; } |
| 2097 | HInstruction* Current() const { return instruction_; } |
| 2098 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2099 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2100 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | private: |
| 2104 | HInstruction* instruction_; |
| 2105 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2106 | |
| 2107 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2108 | }; |
| 2109 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2110 | class HBackwardInstructionIterator : public ValueObject { |
| 2111 | public: |
| 2112 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2113 | : instruction_(instructions.last_instruction_) { |
| 2114 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2115 | } |
| 2116 | |
| 2117 | bool Done() const { return instruction_ == nullptr; } |
| 2118 | HInstruction* Current() const { return instruction_; } |
| 2119 | void Advance() { |
| 2120 | instruction_ = next_; |
| 2121 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2122 | } |
| 2123 | |
| 2124 | private: |
| 2125 | HInstruction* instruction_; |
| 2126 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2127 | |
| 2128 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2129 | }; |
| 2130 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2131 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2132 | class HTemplateInstruction: public HInstruction { |
| 2133 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2134 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2135 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2136 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2137 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2138 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2139 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2140 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2141 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2142 | DCHECK_LT(i, N); |
| 2143 | return inputs_[i]; |
| 2144 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2145 | |
| 2146 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2147 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2148 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2149 | } |
| 2150 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2151 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2152 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2153 | |
| 2154 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2155 | }; |
| 2156 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2157 | // HTemplateInstruction specialization for N=0. |
| 2158 | template<> |
| 2159 | class HTemplateInstruction<0>: public HInstruction { |
| 2160 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2161 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2162 | : HInstruction(side_effects, dex_pc) {} |
| 2163 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2164 | virtual ~HTemplateInstruction() {} |
| 2165 | |
| 2166 | size_t InputCount() const OVERRIDE { return 0; } |
| 2167 | |
| 2168 | protected: |
| 2169 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2170 | LOG(FATAL) << "Unreachable"; |
| 2171 | UNREACHABLE(); |
| 2172 | } |
| 2173 | |
| 2174 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2175 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2176 | LOG(FATAL) << "Unreachable"; |
| 2177 | UNREACHABLE(); |
| 2178 | } |
| 2179 | |
| 2180 | private: |
| 2181 | friend class SsaBuilder; |
| 2182 | }; |
| 2183 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2184 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2185 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2186 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2187 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2188 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2189 | virtual ~HExpression() {} |
| 2190 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2191 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2192 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2193 | protected: |
| 2194 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2195 | }; |
| 2196 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2197 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2198 | // instruction that branches to the exit block. |
| 2199 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2200 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2201 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2202 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2203 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2204 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2205 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2206 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2207 | |
| 2208 | private: |
| 2209 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2210 | }; |
| 2211 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2212 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2213 | // instruction that branches to the exit block. |
| 2214 | class HReturn : public HTemplateInstruction<1> { |
| 2215 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2216 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2217 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2218 | SetRawInputAt(0, value); |
| 2219 | } |
| 2220 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2221 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2222 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2223 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2224 | |
| 2225 | private: |
| 2226 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2227 | }; |
| 2228 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2229 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2230 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2231 | // exit block. |
| 2232 | class HExit : public HTemplateInstruction<0> { |
| 2233 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2234 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2235 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2236 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2237 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2238 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2239 | |
| 2240 | private: |
| 2241 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2242 | }; |
| 2243 | |
| 2244 | // Jumps from one block to another. |
| 2245 | class HGoto : public HTemplateInstruction<0> { |
| 2246 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2247 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2248 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2249 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2250 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2251 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2252 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2253 | } |
| 2254 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2255 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2256 | |
| 2257 | private: |
| 2258 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2259 | }; |
| 2260 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2261 | class HConstant : public HExpression<0> { |
| 2262 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2263 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2264 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2265 | |
| 2266 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2267 | |
| 2268 | virtual bool IsMinusOne() const { return false; } |
| 2269 | virtual bool IsZero() const { return false; } |
| 2270 | virtual bool IsOne() const { return false; } |
| 2271 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2272 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2273 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2274 | DECLARE_INSTRUCTION(Constant); |
| 2275 | |
| 2276 | private: |
| 2277 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2278 | }; |
| 2279 | |
| 2280 | class HNullConstant : public HConstant { |
| 2281 | public: |
| 2282 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2283 | return true; |
| 2284 | } |
| 2285 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2286 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2287 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2288 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2289 | |
| 2290 | DECLARE_INSTRUCTION(NullConstant); |
| 2291 | |
| 2292 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2293 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2294 | |
| 2295 | friend class HGraph; |
| 2296 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2297 | }; |
| 2298 | |
| 2299 | // Constants of the type int. Those can be from Dex instructions, or |
| 2300 | // synthesized (for example with the if-eqz instruction). |
| 2301 | class HIntConstant : public HConstant { |
| 2302 | public: |
| 2303 | int32_t GetValue() const { return value_; } |
| 2304 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2305 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2306 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2307 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2308 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2309 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2310 | DCHECK(other->IsIntConstant()); |
| 2311 | return other->AsIntConstant()->value_ == value_; |
| 2312 | } |
| 2313 | |
| 2314 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2315 | |
| 2316 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2317 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2318 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2319 | |
| 2320 | DECLARE_INSTRUCTION(IntConstant); |
| 2321 | |
| 2322 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2323 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2324 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2325 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2326 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2327 | |
| 2328 | const int32_t value_; |
| 2329 | |
| 2330 | friend class HGraph; |
| 2331 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2332 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2333 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2334 | }; |
| 2335 | |
| 2336 | class HLongConstant : public HConstant { |
| 2337 | public: |
| 2338 | int64_t GetValue() const { return value_; } |
| 2339 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2340 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2341 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2342 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2343 | DCHECK(other->IsLongConstant()); |
| 2344 | return other->AsLongConstant()->value_ == value_; |
| 2345 | } |
| 2346 | |
| 2347 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2348 | |
| 2349 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2350 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2351 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2352 | |
| 2353 | DECLARE_INSTRUCTION(LongConstant); |
| 2354 | |
| 2355 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2356 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2357 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2358 | |
| 2359 | const int64_t value_; |
| 2360 | |
| 2361 | friend class HGraph; |
| 2362 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2363 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2364 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2365 | // Conditional branch. A block ending with an HIf instruction must have |
| 2366 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2367 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2368 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2369 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2370 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2371 | SetRawInputAt(0, input); |
| 2372 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2373 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2374 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2375 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2376 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2377 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2381 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2382 | } |
| 2383 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2384 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2385 | |
| 2386 | private: |
| 2387 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2388 | }; |
| 2389 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2390 | |
| 2391 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2392 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2393 | // non-exceptional control flow. |
| 2394 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2395 | // higher indices in no particular order. |
| 2396 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2397 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2398 | enum BoundaryKind { |
| 2399 | kEntry, |
| 2400 | kExit, |
| 2401 | }; |
| 2402 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2403 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2404 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2405 | |
| 2406 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2407 | |
| 2408 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2409 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2410 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2411 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2412 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2413 | } |
| 2414 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2415 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2416 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2417 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2418 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2419 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2420 | } |
| 2421 | |
| 2422 | // If not present already, adds `handler` to its block's list of exception |
| 2423 | // handlers. |
| 2424 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2425 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2426 | GetBlock()->AddSuccessor(handler); |
| 2427 | } |
| 2428 | } |
| 2429 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2430 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2431 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2432 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2433 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2434 | DECLARE_INSTRUCTION(TryBoundary); |
| 2435 | |
| 2436 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2437 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2438 | |
| 2439 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2440 | }; |
| 2441 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2442 | // Deoptimize to interpreter, upon checking a condition. |
| 2443 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2444 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2445 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2446 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2447 | SetRawInputAt(0, cond); |
| 2448 | } |
| 2449 | |
| 2450 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2451 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2452 | |
| 2453 | DECLARE_INSTRUCTION(Deoptimize); |
| 2454 | |
| 2455 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2456 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2457 | }; |
| 2458 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2459 | // Represents the ArtMethod that was passed as a first argument to |
| 2460 | // the method. It is used by instructions that depend on it, like |
| 2461 | // instructions that work with the dex cache. |
| 2462 | class HCurrentMethod : public HExpression<0> { |
| 2463 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2464 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2465 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2466 | |
| 2467 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2468 | |
| 2469 | private: |
| 2470 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2471 | }; |
| 2472 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2473 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2474 | // have one successor for each entry in the switch table, and the final successor |
| 2475 | // will be the block containing the next Dex opcode. |
| 2476 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2477 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2478 | HPackedSwitch(int32_t start_value, |
| 2479 | uint32_t num_entries, |
| 2480 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2481 | uint32_t dex_pc = kNoDexPc) |
| 2482 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2483 | start_value_(start_value), |
| 2484 | num_entries_(num_entries) { |
| 2485 | SetRawInputAt(0, input); |
| 2486 | } |
| 2487 | |
| 2488 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2489 | |
| 2490 | int32_t GetStartValue() const { return start_value_; } |
| 2491 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2492 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2493 | |
| 2494 | HBasicBlock* GetDefaultBlock() const { |
| 2495 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2496 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2497 | } |
| 2498 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2499 | |
| 2500 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2501 | const int32_t start_value_; |
| 2502 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2503 | |
| 2504 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2505 | }; |
| 2506 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2507 | class HUnaryOperation : public HExpression<1> { |
| 2508 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2509 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2510 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2511 | SetRawInputAt(0, input); |
| 2512 | } |
| 2513 | |
| 2514 | HInstruction* GetInput() const { return InputAt(0); } |
| 2515 | Primitive::Type GetResultType() const { return GetType(); } |
| 2516 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2517 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2518 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2519 | return true; |
| 2520 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2521 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2522 | // Try to statically evaluate `operation` and return a HConstant |
| 2523 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2524 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2525 | HConstant* TryStaticEvaluation() const; |
| 2526 | |
| 2527 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2528 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2529 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2530 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2531 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2532 | |
| 2533 | private: |
| 2534 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2535 | }; |
| 2536 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2537 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2538 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2539 | HBinaryOperation(Primitive::Type result_type, |
| 2540 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2541 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2542 | SideEffects side_effects = SideEffects::None(), |
| 2543 | uint32_t dex_pc = kNoDexPc) |
| 2544 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2545 | SetRawInputAt(0, left); |
| 2546 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2549 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2550 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2551 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2552 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2553 | virtual bool IsCommutative() const { return false; } |
| 2554 | |
| 2555 | // Put constant on the right. |
| 2556 | // Returns whether order is changed. |
| 2557 | bool OrderInputsWithConstantOnTheRight() { |
| 2558 | HInstruction* left = InputAt(0); |
| 2559 | HInstruction* right = InputAt(1); |
| 2560 | if (left->IsConstant() && !right->IsConstant()) { |
| 2561 | ReplaceInput(right, 0); |
| 2562 | ReplaceInput(left, 1); |
| 2563 | return true; |
| 2564 | } |
| 2565 | return false; |
| 2566 | } |
| 2567 | |
| 2568 | // Order inputs by instruction id, but favor constant on the right side. |
| 2569 | // This helps GVN for commutative ops. |
| 2570 | void OrderInputs() { |
| 2571 | DCHECK(IsCommutative()); |
| 2572 | HInstruction* left = InputAt(0); |
| 2573 | HInstruction* right = InputAt(1); |
| 2574 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2575 | return; |
| 2576 | } |
| 2577 | if (OrderInputsWithConstantOnTheRight()) { |
| 2578 | return; |
| 2579 | } |
| 2580 | // Order according to instruction id. |
| 2581 | if (left->GetId() > right->GetId()) { |
| 2582 | ReplaceInput(right, 0); |
| 2583 | ReplaceInput(left, 1); |
| 2584 | } |
| 2585 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2586 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2587 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2588 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2589 | return true; |
| 2590 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2591 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2592 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2593 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2594 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2595 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2596 | |
| 2597 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2598 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2599 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2600 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2601 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2602 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2603 | return nullptr; |
| 2604 | } |
| 2605 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2606 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2607 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2608 | return nullptr; |
| 2609 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2610 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2611 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| 2612 | VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; |
| 2613 | return nullptr; |
| 2614 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2615 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2616 | // 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] | 2617 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2618 | HConstant* GetConstantRight() const; |
| 2619 | |
| 2620 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2621 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2622 | HInstruction* GetLeastConstantLeft() const; |
| 2623 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2624 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2625 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2626 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2627 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2628 | }; |
| 2629 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2630 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2631 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2632 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2633 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2634 | kGtBias, // return 1 for NaN comparisons |
| 2635 | kLtBias, // return -1 for NaN comparisons |
| 2636 | }; |
| 2637 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2638 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2639 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2640 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2641 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2642 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2643 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2644 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2645 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2646 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2647 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2648 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2649 | // `instruction`, and disregard moves in between. |
| 2650 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2651 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2652 | DECLARE_INSTRUCTION(Condition); |
| 2653 | |
| 2654 | virtual IfCondition GetCondition() const = 0; |
| 2655 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2656 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2657 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2658 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2659 | |
| 2660 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2661 | |
| 2662 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2663 | return bias_ == other->AsCondition()->bias_; |
| 2664 | } |
| 2665 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2666 | bool IsFPConditionTrueIfNaN() const { |
| 2667 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2668 | IfCondition if_cond = GetCondition(); |
| 2669 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2670 | } |
| 2671 | |
| 2672 | bool IsFPConditionFalseIfNaN() const { |
| 2673 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2674 | IfCondition if_cond = GetCondition(); |
| 2675 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2676 | } |
| 2677 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2678 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2679 | // For register allocation purposes, returns whether this instruction needs to be |
| 2680 | // materialized (that is, not just be in the processor flags). |
| 2681 | bool needs_materialization_; |
| 2682 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2683 | // Needed if we merge a HCompare into a HCondition. |
| 2684 | ComparisonBias bias_; |
| 2685 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2686 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2687 | }; |
| 2688 | |
| 2689 | // Instruction to check if two inputs are equal to each other. |
| 2690 | class HEqual : public HCondition { |
| 2691 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2692 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2693 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2694 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2695 | bool IsCommutative() const OVERRIDE { return true; } |
| 2696 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2697 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2698 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2699 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2700 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2701 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2702 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2703 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2704 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2705 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2706 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2707 | return GetBlock()->GetGraph()->GetIntConstant(1); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2708 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2709 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2710 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2711 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2712 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2713 | return kCondEQ; |
| 2714 | } |
| 2715 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2716 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2717 | return kCondNE; |
| 2718 | } |
| 2719 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2720 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2721 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2722 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2723 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2724 | }; |
| 2725 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2726 | class HNotEqual : public HCondition { |
| 2727 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2728 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2729 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2730 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2731 | bool IsCommutative() const OVERRIDE { return true; } |
| 2732 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2733 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2734 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2735 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2736 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2737 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2738 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2739 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2740 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2741 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2742 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2743 | return GetBlock()->GetGraph()->GetIntConstant(0); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2744 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2745 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2746 | DECLARE_INSTRUCTION(NotEqual); |
| 2747 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2748 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2749 | return kCondNE; |
| 2750 | } |
| 2751 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2752 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2753 | return kCondEQ; |
| 2754 | } |
| 2755 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2756 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2757 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2758 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2759 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2760 | }; |
| 2761 | |
| 2762 | class HLessThan : public HCondition { |
| 2763 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2764 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2765 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2766 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2767 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2768 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2769 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2770 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2771 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2772 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2773 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2774 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2775 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2776 | DECLARE_INSTRUCTION(LessThan); |
| 2777 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2778 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2779 | return kCondLT; |
| 2780 | } |
| 2781 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2782 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2783 | return kCondGE; |
| 2784 | } |
| 2785 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2786 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2787 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2788 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2789 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2790 | }; |
| 2791 | |
| 2792 | class HLessThanOrEqual : public HCondition { |
| 2793 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2794 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2795 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2796 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2797 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2798 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2799 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2800 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2801 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2802 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2803 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2804 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2805 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2806 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2807 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2808 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2809 | return kCondLE; |
| 2810 | } |
| 2811 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2812 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2813 | return kCondGT; |
| 2814 | } |
| 2815 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2816 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2817 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2818 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2819 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2820 | }; |
| 2821 | |
| 2822 | class HGreaterThan : public HCondition { |
| 2823 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2824 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2825 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2826 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2827 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2828 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2829 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2830 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2831 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2832 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2833 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2834 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2835 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2836 | DECLARE_INSTRUCTION(GreaterThan); |
| 2837 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2838 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2839 | return kCondGT; |
| 2840 | } |
| 2841 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2842 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2843 | return kCondLE; |
| 2844 | } |
| 2845 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2846 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2847 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2848 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2849 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2850 | }; |
| 2851 | |
| 2852 | class HGreaterThanOrEqual : public HCondition { |
| 2853 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2854 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2855 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2856 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2857 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2858 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2859 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2860 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2861 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2862 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2863 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2864 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2865 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2866 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2867 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2868 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2869 | return kCondGE; |
| 2870 | } |
| 2871 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2872 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2873 | return kCondLT; |
| 2874 | } |
| 2875 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2876 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2877 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2878 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2879 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2880 | }; |
| 2881 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2882 | class HBelow : public HCondition { |
| 2883 | public: |
| 2884 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2885 | : HCondition(first, second, dex_pc) {} |
| 2886 | |
| 2887 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2888 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2889 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2890 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2891 | } |
| 2892 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2893 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2894 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2895 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2896 | } |
| 2897 | |
| 2898 | DECLARE_INSTRUCTION(Below); |
| 2899 | |
| 2900 | IfCondition GetCondition() const OVERRIDE { |
| 2901 | return kCondB; |
| 2902 | } |
| 2903 | |
| 2904 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2905 | return kCondAE; |
| 2906 | } |
| 2907 | |
| 2908 | private: |
| 2909 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2910 | |
| 2911 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 2912 | }; |
| 2913 | |
| 2914 | class HBelowOrEqual : public HCondition { |
| 2915 | public: |
| 2916 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2917 | : HCondition(first, second, dex_pc) {} |
| 2918 | |
| 2919 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2920 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2921 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2922 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2923 | } |
| 2924 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2925 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2926 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2927 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2928 | } |
| 2929 | |
| 2930 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 2931 | |
| 2932 | IfCondition GetCondition() const OVERRIDE { |
| 2933 | return kCondBE; |
| 2934 | } |
| 2935 | |
| 2936 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2937 | return kCondA; |
| 2938 | } |
| 2939 | |
| 2940 | private: |
| 2941 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2942 | |
| 2943 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 2944 | }; |
| 2945 | |
| 2946 | class HAbove : public HCondition { |
| 2947 | public: |
| 2948 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2949 | : HCondition(first, second, dex_pc) {} |
| 2950 | |
| 2951 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2952 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2953 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2954 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2955 | } |
| 2956 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2957 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2958 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2959 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2960 | } |
| 2961 | |
| 2962 | DECLARE_INSTRUCTION(Above); |
| 2963 | |
| 2964 | IfCondition GetCondition() const OVERRIDE { |
| 2965 | return kCondA; |
| 2966 | } |
| 2967 | |
| 2968 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2969 | return kCondBE; |
| 2970 | } |
| 2971 | |
| 2972 | private: |
| 2973 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2974 | |
| 2975 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 2976 | }; |
| 2977 | |
| 2978 | class HAboveOrEqual : public HCondition { |
| 2979 | public: |
| 2980 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2981 | : HCondition(first, second, dex_pc) {} |
| 2982 | |
| 2983 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2984 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2985 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2986 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2987 | } |
| 2988 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2989 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2990 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2991 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2992 | } |
| 2993 | |
| 2994 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 2995 | |
| 2996 | IfCondition GetCondition() const OVERRIDE { |
| 2997 | return kCondAE; |
| 2998 | } |
| 2999 | |
| 3000 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3001 | return kCondB; |
| 3002 | } |
| 3003 | |
| 3004 | private: |
| 3005 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3006 | |
| 3007 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3008 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3009 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3010 | // Instruction to check how two inputs compare to each other. |
| 3011 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3012 | class HCompare : public HBinaryOperation { |
| 3013 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3014 | HCompare(Primitive::Type type, |
| 3015 | HInstruction* first, |
| 3016 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3017 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3018 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3019 | : HBinaryOperation(Primitive::kPrimInt, |
| 3020 | first, |
| 3021 | second, |
| 3022 | SideEffectsForArchRuntimeCalls(type), |
| 3023 | dex_pc), |
| 3024 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3025 | DCHECK_EQ(type, first->GetType()); |
| 3026 | DCHECK_EQ(type, second->GetType()); |
| 3027 | } |
| 3028 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3029 | template <typename T> |
| 3030 | 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] | 3031 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3032 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3033 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3034 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3035 | } |
| 3036 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3037 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3038 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3039 | } |
| 3040 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3041 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3042 | return bias_ == other->AsCompare()->bias_; |
| 3043 | } |
| 3044 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3045 | ComparisonBias GetBias() const { return bias_; } |
| 3046 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3047 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3048 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3049 | |
| 3050 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3051 | // MIPS64 uses a runtime call for FP comparisons. |
| 3052 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3053 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3054 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3055 | DECLARE_INSTRUCTION(Compare); |
| 3056 | |
| 3057 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3058 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3059 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3060 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3061 | }; |
| 3062 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3063 | // A local in the graph. Corresponds to a Dex register. |
| 3064 | class HLocal : public HTemplateInstruction<0> { |
| 3065 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3066 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3067 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3068 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3069 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3070 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3071 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3072 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3073 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3074 | // The Dex register number. |
| 3075 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3076 | |
| 3077 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3078 | }; |
| 3079 | |
| 3080 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3081 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3082 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3083 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3084 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3085 | SetRawInputAt(0, local); |
| 3086 | } |
| 3087 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3088 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3089 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3090 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3091 | |
| 3092 | private: |
| 3093 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3094 | }; |
| 3095 | |
| 3096 | // Store a value in a given local. This instruction has two inputs: the value |
| 3097 | // and the local. |
| 3098 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3099 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3100 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3101 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3102 | SetRawInputAt(0, local); |
| 3103 | SetRawInputAt(1, value); |
| 3104 | } |
| 3105 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3106 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3107 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3108 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3109 | |
| 3110 | private: |
| 3111 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3112 | }; |
| 3113 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3114 | class HFloatConstant : public HConstant { |
| 3115 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3116 | float GetValue() const { return value_; } |
| 3117 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3118 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3119 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3120 | } |
| 3121 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3122 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3123 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3124 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3125 | } |
| 3126 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3127 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3128 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3129 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3130 | 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] | 3131 | } |
| 3132 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3133 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3134 | } |
| 3135 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3136 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3137 | } |
| 3138 | bool IsNaN() const { |
| 3139 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3142 | DECLARE_INSTRUCTION(FloatConstant); |
| 3143 | |
| 3144 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3145 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3146 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3147 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3148 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3149 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3150 | const float value_; |
| 3151 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3152 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3153 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3154 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3155 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3156 | }; |
| 3157 | |
| 3158 | class HDoubleConstant : public HConstant { |
| 3159 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3160 | double GetValue() const { return value_; } |
| 3161 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3162 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3163 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3164 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3165 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3166 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3167 | } |
| 3168 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3169 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3170 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3171 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3172 | 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] | 3173 | } |
| 3174 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3175 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3176 | } |
| 3177 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3178 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3179 | } |
| 3180 | bool IsNaN() const { |
| 3181 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3182 | } |
| 3183 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3184 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3185 | |
| 3186 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3187 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3188 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3189 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3190 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3191 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3192 | const double value_; |
| 3193 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3194 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3195 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3196 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3197 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3198 | }; |
| 3199 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3200 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3201 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3202 | #include "intrinsics_list.h" |
| 3203 | kNone, |
| 3204 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3205 | #undef INTRINSICS_LIST |
| 3206 | #undef OPTIMIZING_INTRINSICS |
| 3207 | }; |
| 3208 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3209 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3210 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3211 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3212 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3213 | }; |
| 3214 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3215 | class HInvoke : public HInstruction { |
| 3216 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3217 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3218 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3219 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3220 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3221 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3222 | SetRawInputAt(index, argument); |
| 3223 | } |
| 3224 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3225 | // Return the number of arguments. This number can be lower than |
| 3226 | // the number of inputs returned by InputCount(), as some invoke |
| 3227 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3228 | // inputs at the end of their list of inputs. |
| 3229 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3230 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3231 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3232 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3233 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3234 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3235 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3236 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3237 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3238 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3239 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3240 | return intrinsic_; |
| 3241 | } |
| 3242 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3243 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3244 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3245 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3246 | return GetEnvironment()->GetParent() != nullptr; |
| 3247 | } |
| 3248 | |
| 3249 | bool CanThrow() const OVERRIDE { return true; } |
| 3250 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3251 | uint32_t* GetIntrinsicOptimizations() { |
| 3252 | return &intrinsic_optimizations_; |
| 3253 | } |
| 3254 | |
| 3255 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3256 | return &intrinsic_optimizations_; |
| 3257 | } |
| 3258 | |
| 3259 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3260 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3261 | DECLARE_INSTRUCTION(Invoke); |
| 3262 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3263 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3264 | HInvoke(ArenaAllocator* arena, |
| 3265 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3266 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3267 | Primitive::Type return_type, |
| 3268 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3269 | uint32_t dex_method_index, |
| 3270 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3271 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3272 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3273 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3274 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3275 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3276 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3277 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3278 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3279 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3280 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3281 | } |
| 3282 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3283 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3284 | return inputs_[index]; |
| 3285 | } |
| 3286 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3287 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3288 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3289 | } |
| 3290 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3291 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3292 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3293 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3294 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3295 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3296 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3297 | |
| 3298 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3299 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3300 | |
| 3301 | private: |
| 3302 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3303 | }; |
| 3304 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3305 | class HInvokeUnresolved : public HInvoke { |
| 3306 | public: |
| 3307 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3308 | uint32_t number_of_arguments, |
| 3309 | Primitive::Type return_type, |
| 3310 | uint32_t dex_pc, |
| 3311 | uint32_t dex_method_index, |
| 3312 | InvokeType invoke_type) |
| 3313 | : HInvoke(arena, |
| 3314 | number_of_arguments, |
| 3315 | 0u /* number_of_other_inputs */, |
| 3316 | return_type, |
| 3317 | dex_pc, |
| 3318 | dex_method_index, |
| 3319 | invoke_type) { |
| 3320 | } |
| 3321 | |
| 3322 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3323 | |
| 3324 | private: |
| 3325 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3326 | }; |
| 3327 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3328 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3329 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3330 | // Requirements of this method call regarding the class |
| 3331 | // initialization (clinit) check of its declaring class. |
| 3332 | enum class ClinitCheckRequirement { |
| 3333 | kNone, // Class already initialized. |
| 3334 | kExplicit, // Static call having explicit clinit check as last input. |
| 3335 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3336 | }; |
| 3337 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3338 | // Determines how to load the target ArtMethod*. |
| 3339 | enum class MethodLoadKind { |
| 3340 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3341 | kStringInit, |
| 3342 | |
| 3343 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3344 | kRecursive, |
| 3345 | |
| 3346 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3347 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3348 | kDirectAddress, |
| 3349 | |
| 3350 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3351 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3352 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3353 | // the image relocatable or not. |
| 3354 | kDirectAddressWithFixup, |
| 3355 | |
| 3356 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3357 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3358 | // may cause class initialization (the entry may point to a resolution method), |
| 3359 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3360 | kDexCachePcRelative, |
| 3361 | |
| 3362 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3363 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3364 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3365 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3366 | kDexCacheViaMethod, |
| 3367 | }; |
| 3368 | |
| 3369 | // Determines the location of the code pointer. |
| 3370 | enum class CodePtrLocation { |
| 3371 | // Recursive call, use local PC-relative call instruction. |
| 3372 | kCallSelf, |
| 3373 | |
| 3374 | // Use PC-relative call instruction patched at link time. |
| 3375 | // Used for calls within an oat file, boot->boot or app->app. |
| 3376 | kCallPCRelative, |
| 3377 | |
| 3378 | // Call to a known target address, embed the direct address in code. |
| 3379 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3380 | kCallDirect, |
| 3381 | |
| 3382 | // Call to a target address that will be known at link time, embed the direct |
| 3383 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3384 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3385 | // the image relocatable or not. |
| 3386 | kCallDirectWithFixup, |
| 3387 | |
| 3388 | // Use code pointer from the ArtMethod*. |
| 3389 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3390 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3391 | kCallArtMethod, |
| 3392 | }; |
| 3393 | |
| 3394 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3395 | MethodLoadKind method_load_kind; |
| 3396 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3397 | // The method load data holds |
| 3398 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3399 | // Note that there are multiple string init methods, each having its own offset. |
| 3400 | // - the method address for kDirectAddress |
| 3401 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3402 | uint64_t method_load_data; |
| 3403 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3404 | }; |
| 3405 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3406 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3407 | uint32_t number_of_arguments, |
| 3408 | Primitive::Type return_type, |
| 3409 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3410 | uint32_t method_index, |
| 3411 | MethodReference target_method, |
| 3412 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3413 | InvokeType original_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3414 | InvokeType invoke_type, |
| 3415 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3416 | : HInvoke(arena, |
| 3417 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3418 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3419 | // potentially one other if the clinit check is explicit, and potentially |
| 3420 | // one other if the method is a string factory. |
| 3421 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3422 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3423 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3424 | return_type, |
| 3425 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3426 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3427 | original_invoke_type), |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3428 | invoke_type_(invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3429 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3430 | target_method_(target_method), |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3431 | dispatch_info_(dispatch_info) { } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3432 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3433 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3434 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3435 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3436 | |
| 3437 | // Using the current method is the default and once we find a better |
| 3438 | // method load kind, we should not go back to using the current method. |
| 3439 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3440 | |
| 3441 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3442 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3443 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3444 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3445 | dispatch_info_ = dispatch_info; |
| 3446 | } |
| 3447 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3448 | void AddSpecialInput(HInstruction* input) { |
| 3449 | // We allow only one special input. |
| 3450 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3451 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3452 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3453 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3454 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3455 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3456 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3457 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3458 | // TODO: for intrinsics we can generate implicit null checks. |
| 3459 | return false; |
| 3460 | } |
| 3461 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3462 | bool CanBeNull() const OVERRIDE { |
| 3463 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3464 | } |
| 3465 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3466 | // Get the index of the special input, if any. |
| 3467 | // |
| 3468 | // If the invoke IsStringInit(), it initially has a HFakeString special argument |
| 3469 | // which is removed by the instruction simplifier; if the invoke HasCurrentMethodInput(), |
| 3470 | // the "special input" is the current method pointer; otherwise there may be one |
| 3471 | // platform-specific special input, such as PC-relative addressing base. |
| 3472 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
| 3473 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3474 | InvokeType GetInvokeType() const { return invoke_type_; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3475 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3476 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3477 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3478 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3479 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3480 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3481 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3482 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3483 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3484 | bool HasCurrentMethodInput() const { |
| 3485 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3486 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3487 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3488 | return true; |
| 3489 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3490 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3491 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3492 | return false; |
| 3493 | } |
| 3494 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3495 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3496 | MethodReference GetTargetMethod() const { return target_method_; } |
| 3497 | |
| 3498 | int32_t GetStringInitOffset() const { |
| 3499 | DCHECK(IsStringInit()); |
| 3500 | return dispatch_info_.method_load_data; |
| 3501 | } |
| 3502 | |
| 3503 | uint64_t GetMethodAddress() const { |
| 3504 | DCHECK(HasMethodAddress()); |
| 3505 | return dispatch_info_.method_load_data; |
| 3506 | } |
| 3507 | |
| 3508 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3509 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3510 | return dispatch_info_.method_load_data; |
| 3511 | } |
| 3512 | |
| 3513 | uint64_t GetDirectCodePtr() const { |
| 3514 | DCHECK(HasDirectCodePtr()); |
| 3515 | return dispatch_info_.direct_code_ptr; |
| 3516 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3517 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3518 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3519 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3520 | // Is this instruction a call to a static method? |
| 3521 | bool IsStatic() const { |
| 3522 | return GetInvokeType() == kStatic; |
| 3523 | } |
| 3524 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3525 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3526 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3527 | // instruction; only relevant for static calls with explicit clinit check. |
| 3528 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3529 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3530 | size_t last_input_index = InputCount() - 1; |
| 3531 | HInstruction* last_input = InputAt(last_input_index); |
| 3532 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3533 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3534 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3535 | inputs_.pop_back(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3536 | clinit_check_requirement_ = new_requirement; |
| 3537 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3538 | } |
| 3539 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3540 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3541 | if (!IsStringInit()) return false; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3542 | DCHECK(!HasCurrentMethodInput()); |
| 3543 | if (InputCount() == (number_of_arguments_)) return false; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3544 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3545 | } |
| 3546 | |
| 3547 | void RemoveFakeStringArgumentAsLastInput() { |
| 3548 | DCHECK(IsStringInit()); |
| 3549 | size_t last_input_index = InputCount() - 1; |
| 3550 | HInstruction* last_input = InputAt(last_input_index); |
| 3551 | DCHECK(last_input != nullptr); |
| 3552 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3553 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3554 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3555 | } |
| 3556 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3557 | // Is this a call to a static method whose declaring class has an |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3558 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3559 | bool IsStaticWithExplicitClinitCheck() const { |
| 3560 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3561 | } |
| 3562 | |
| 3563 | // Is this a call to a static method whose declaring class has an |
| 3564 | // implicit intialization check requirement? |
| 3565 | bool IsStaticWithImplicitClinitCheck() const { |
| 3566 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3567 | } |
| 3568 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3569 | // Does this method load kind need the current method as an input? |
| 3570 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 3571 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 3572 | } |
| 3573 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3574 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3575 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3576 | protected: |
| 3577 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3578 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3579 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3580 | HInstruction* input = input_record.GetInstruction(); |
| 3581 | // `input` is the last input of a static invoke marked as having |
| 3582 | // an explicit clinit check. It must either be: |
| 3583 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3584 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3585 | DCHECK(input != nullptr); |
| 3586 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3587 | } |
| 3588 | return input_record; |
| 3589 | } |
| 3590 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3591 | void InsertInputAt(size_t index, HInstruction* input); |
| 3592 | void RemoveInputAt(size_t index); |
| 3593 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3594 | private: |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3595 | const InvokeType invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3596 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3597 | // The target method may refer to different dex file or method index than the original |
| 3598 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3599 | // in derived class to increase visibility. |
| 3600 | MethodReference target_method_; |
| 3601 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3602 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3603 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3604 | }; |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3605 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3606 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3607 | class HInvokeVirtual : public HInvoke { |
| 3608 | public: |
| 3609 | HInvokeVirtual(ArenaAllocator* arena, |
| 3610 | uint32_t number_of_arguments, |
| 3611 | Primitive::Type return_type, |
| 3612 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3613 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3614 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3615 | : 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] | 3616 | vtable_index_(vtable_index) {} |
| 3617 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3618 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3619 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3620 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3621 | } |
| 3622 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3623 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3624 | |
| 3625 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3626 | |
| 3627 | private: |
| 3628 | const uint32_t vtable_index_; |
| 3629 | |
| 3630 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3631 | }; |
| 3632 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3633 | class HInvokeInterface : public HInvoke { |
| 3634 | public: |
| 3635 | HInvokeInterface(ArenaAllocator* arena, |
| 3636 | uint32_t number_of_arguments, |
| 3637 | Primitive::Type return_type, |
| 3638 | uint32_t dex_pc, |
| 3639 | uint32_t dex_method_index, |
| 3640 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3641 | : 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] | 3642 | imt_index_(imt_index) {} |
| 3643 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3644 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3645 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3646 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3647 | } |
| 3648 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3649 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3650 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3651 | |
| 3652 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3653 | |
| 3654 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3655 | const uint32_t imt_index_; |
| 3656 | |
| 3657 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3658 | }; |
| 3659 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3660 | class HNewInstance : public HExpression<1> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3661 | public: |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3662 | HNewInstance(HCurrentMethod* current_method, |
| 3663 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3664 | uint16_t type_index, |
| 3665 | const DexFile& dex_file, |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3666 | bool can_throw, |
| 3667 | bool finalizable, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3668 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3669 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3670 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3671 | dex_file_(dex_file), |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3672 | can_throw_(can_throw), |
| 3673 | finalizable_(finalizable), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3674 | entrypoint_(entrypoint) { |
| 3675 | SetRawInputAt(0, current_method); |
| 3676 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3677 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3678 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3679 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3680 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3681 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3682 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3683 | |
| 3684 | // It may throw when called on type that's not instantiable/accessible. |
| 3685 | // It can throw OOME. |
| 3686 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
| 3687 | bool CanThrow() const OVERRIDE { return can_throw_ || true; } |
| 3688 | |
| 3689 | bool IsFinalizable() const { return finalizable_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3690 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3691 | bool CanBeNull() const OVERRIDE { return false; } |
| 3692 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3693 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3694 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3695 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3696 | |
| 3697 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3698 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3699 | const DexFile& dex_file_; |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3700 | const bool can_throw_; |
| 3701 | const bool finalizable_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3702 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3703 | |
| 3704 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3705 | }; |
| 3706 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3707 | class HNeg : public HUnaryOperation { |
| 3708 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3709 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3710 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3711 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3712 | template <typename T> T Compute(T x) const { return -x; } |
| 3713 | |
| 3714 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3715 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3716 | } |
| 3717 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3718 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3719 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3720 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3721 | DECLARE_INSTRUCTION(Neg); |
| 3722 | |
| 3723 | private: |
| 3724 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3725 | }; |
| 3726 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3727 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3728 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3729 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3730 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3731 | uint32_t dex_pc, |
| 3732 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3733 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3734 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3735 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3736 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3737 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3738 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3739 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3740 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3741 | } |
| 3742 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3743 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3744 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3745 | |
| 3746 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3747 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3748 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3749 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3750 | bool CanThrow() const OVERRIDE { return true; } |
| 3751 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3752 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3753 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3754 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3755 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3756 | DECLARE_INSTRUCTION(NewArray); |
| 3757 | |
| 3758 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3759 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3760 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3761 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3762 | |
| 3763 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3764 | }; |
| 3765 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3766 | class HAdd : public HBinaryOperation { |
| 3767 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3768 | HAdd(Primitive::Type result_type, |
| 3769 | HInstruction* left, |
| 3770 | HInstruction* right, |
| 3771 | uint32_t dex_pc = kNoDexPc) |
| 3772 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3773 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3774 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3775 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3776 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3777 | |
| 3778 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3779 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3780 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3781 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3782 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3783 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3784 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3785 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3786 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3787 | DECLARE_INSTRUCTION(Add); |
| 3788 | |
| 3789 | private: |
| 3790 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3791 | }; |
| 3792 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3793 | class HSub : public HBinaryOperation { |
| 3794 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3795 | HSub(Primitive::Type result_type, |
| 3796 | HInstruction* left, |
| 3797 | HInstruction* right, |
| 3798 | uint32_t dex_pc = kNoDexPc) |
| 3799 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3800 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3801 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3802 | |
| 3803 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3804 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3805 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3806 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3807 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3808 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3809 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3810 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3811 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3812 | DECLARE_INSTRUCTION(Sub); |
| 3813 | |
| 3814 | private: |
| 3815 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3816 | }; |
| 3817 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3818 | class HMul : public HBinaryOperation { |
| 3819 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3820 | HMul(Primitive::Type result_type, |
| 3821 | HInstruction* left, |
| 3822 | HInstruction* right, |
| 3823 | uint32_t dex_pc = kNoDexPc) |
| 3824 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3825 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3826 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3827 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3828 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3829 | |
| 3830 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3831 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3832 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3833 | } |
| 3834 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3835 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3836 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3837 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3838 | |
| 3839 | DECLARE_INSTRUCTION(Mul); |
| 3840 | |
| 3841 | private: |
| 3842 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3843 | }; |
| 3844 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3845 | class HDiv : public HBinaryOperation { |
| 3846 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3847 | HDiv(Primitive::Type result_type, |
| 3848 | HInstruction* left, |
| 3849 | HInstruction* right, |
| 3850 | uint32_t dex_pc) |
| 3851 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3852 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3853 | template <typename T> |
| 3854 | T Compute(T x, T y) const { |
| 3855 | // Our graph structure ensures we never have 0 for `y` during |
| 3856 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3857 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3858 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3859 | return (y == -1) ? -x : x / y; |
| 3860 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3861 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3862 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3863 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3864 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3865 | } |
| 3866 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3867 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3868 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3869 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3870 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3871 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3872 | // The generated code can use a runtime call. |
| 3873 | return SideEffects::CanTriggerGC(); |
| 3874 | } |
| 3875 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3876 | DECLARE_INSTRUCTION(Div); |
| 3877 | |
| 3878 | private: |
| 3879 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3880 | }; |
| 3881 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3882 | class HRem : public HBinaryOperation { |
| 3883 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3884 | HRem(Primitive::Type result_type, |
| 3885 | HInstruction* left, |
| 3886 | HInstruction* right, |
| 3887 | uint32_t dex_pc) |
| 3888 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3889 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3890 | template <typename T> |
| 3891 | T Compute(T x, T y) const { |
| 3892 | // Our graph structure ensures we never have 0 for `y` during |
| 3893 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3894 | DCHECK_NE(y, 0); |
| 3895 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3896 | return (y == -1) ? 0 : x % y; |
| 3897 | } |
| 3898 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3899 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3900 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3901 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3902 | } |
| 3903 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3904 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3905 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3906 | } |
| 3907 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3908 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3909 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3910 | return SideEffects::CanTriggerGC(); |
| 3911 | } |
| 3912 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3913 | DECLARE_INSTRUCTION(Rem); |
| 3914 | |
| 3915 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3916 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3917 | }; |
| 3918 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3919 | class HDivZeroCheck : public HExpression<1> { |
| 3920 | public: |
| 3921 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3922 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3923 | SetRawInputAt(0, value); |
| 3924 | } |
| 3925 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3926 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3927 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3928 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3929 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3930 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3931 | return true; |
| 3932 | } |
| 3933 | |
| 3934 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3935 | bool CanThrow() const OVERRIDE { return true; } |
| 3936 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3937 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3938 | |
| 3939 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3940 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3941 | }; |
| 3942 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3943 | class HShl : public HBinaryOperation { |
| 3944 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3945 | HShl(Primitive::Type result_type, |
| 3946 | HInstruction* left, |
| 3947 | HInstruction* right, |
| 3948 | uint32_t dex_pc = kNoDexPc) |
| 3949 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3950 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3951 | template <typename T, typename U, typename V> |
| 3952 | T Compute(T x, U y, V max_shift_value) const { |
| 3953 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3954 | "V is not the unsigned integer type corresponding to T"); |
| 3955 | return x << (y & max_shift_value); |
| 3956 | } |
| 3957 | |
| 3958 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3959 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3960 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3961 | } |
| 3962 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3963 | // case is handled as `x << static_cast<int>(y)`. |
| 3964 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3965 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3966 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3967 | } |
| 3968 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3969 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3970 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3971 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3972 | |
| 3973 | DECLARE_INSTRUCTION(Shl); |
| 3974 | |
| 3975 | private: |
| 3976 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 3977 | }; |
| 3978 | |
| 3979 | class HShr : public HBinaryOperation { |
| 3980 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3981 | HShr(Primitive::Type result_type, |
| 3982 | HInstruction* left, |
| 3983 | HInstruction* right, |
| 3984 | uint32_t dex_pc = kNoDexPc) |
| 3985 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3986 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3987 | template <typename T, typename U, typename V> |
| 3988 | T Compute(T x, U y, V max_shift_value) const { |
| 3989 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3990 | "V is not the unsigned integer type corresponding to T"); |
| 3991 | return x >> (y & max_shift_value); |
| 3992 | } |
| 3993 | |
| 3994 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3995 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3996 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3997 | } |
| 3998 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3999 | // case is handled as `x >> static_cast<int>(y)`. |
| 4000 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4001 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4002 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4003 | } |
| 4004 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4005 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4006 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4007 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4008 | |
| 4009 | DECLARE_INSTRUCTION(Shr); |
| 4010 | |
| 4011 | private: |
| 4012 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4013 | }; |
| 4014 | |
| 4015 | class HUShr : public HBinaryOperation { |
| 4016 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4017 | HUShr(Primitive::Type result_type, |
| 4018 | HInstruction* left, |
| 4019 | HInstruction* right, |
| 4020 | uint32_t dex_pc = kNoDexPc) |
| 4021 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4022 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4023 | template <typename T, typename U, typename V> |
| 4024 | T Compute(T x, U y, V max_shift_value) const { |
| 4025 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4026 | "V is not the unsigned integer type corresponding to T"); |
| 4027 | V ux = static_cast<V>(x); |
| 4028 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4031 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4032 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4033 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4034 | } |
| 4035 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4036 | // case is handled as `x >>> static_cast<int>(y)`. |
| 4037 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4038 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4039 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4040 | } |
| 4041 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4042 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4043 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | DECLARE_INSTRUCTION(UShr); |
| 4047 | |
| 4048 | private: |
| 4049 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4050 | }; |
| 4051 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4052 | class HAnd : public HBinaryOperation { |
| 4053 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4054 | HAnd(Primitive::Type result_type, |
| 4055 | HInstruction* left, |
| 4056 | HInstruction* right, |
| 4057 | uint32_t dex_pc = kNoDexPc) |
| 4058 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4059 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4060 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4061 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4062 | template <typename T, typename U> |
| 4063 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 4064 | |
| 4065 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4066 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4067 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4068 | } |
| 4069 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4070 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4071 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4072 | } |
| 4073 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4074 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4075 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4076 | } |
| 4077 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4078 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4079 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4080 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4081 | |
| 4082 | DECLARE_INSTRUCTION(And); |
| 4083 | |
| 4084 | private: |
| 4085 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4086 | }; |
| 4087 | |
| 4088 | class HOr : public HBinaryOperation { |
| 4089 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4090 | HOr(Primitive::Type result_type, |
| 4091 | HInstruction* left, |
| 4092 | HInstruction* right, |
| 4093 | uint32_t dex_pc = kNoDexPc) |
| 4094 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4095 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4096 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4097 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4098 | template <typename T, typename U> |
| 4099 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4100 | |
| 4101 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4102 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4103 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4104 | } |
| 4105 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4106 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4107 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4108 | } |
| 4109 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4110 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4111 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4112 | } |
| 4113 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4114 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4115 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4116 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4117 | |
| 4118 | DECLARE_INSTRUCTION(Or); |
| 4119 | |
| 4120 | private: |
| 4121 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4122 | }; |
| 4123 | |
| 4124 | class HXor : public HBinaryOperation { |
| 4125 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4126 | HXor(Primitive::Type result_type, |
| 4127 | HInstruction* left, |
| 4128 | HInstruction* right, |
| 4129 | uint32_t dex_pc = kNoDexPc) |
| 4130 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4131 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4132 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4133 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4134 | template <typename T, typename U> |
| 4135 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4136 | |
| 4137 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4138 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4139 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4140 | } |
| 4141 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4142 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4143 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4144 | } |
| 4145 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4146 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4147 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4148 | } |
| 4149 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4150 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4151 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4152 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4153 | |
| 4154 | DECLARE_INSTRUCTION(Xor); |
| 4155 | |
| 4156 | private: |
| 4157 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4158 | }; |
| 4159 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4160 | // The value of a parameter in this method. Its location depends on |
| 4161 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4162 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4163 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4164 | HParameterValue(const DexFile& dex_file, |
| 4165 | uint16_t type_index, |
| 4166 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4167 | Primitive::Type parameter_type, |
| 4168 | bool is_this = false) |
| 4169 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4170 | dex_file_(dex_file), |
| 4171 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4172 | index_(index), |
| 4173 | is_this_(is_this), |
| 4174 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4175 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4176 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4177 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4178 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4179 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4180 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4181 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4182 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4183 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4184 | DECLARE_INSTRUCTION(ParameterValue); |
| 4185 | |
| 4186 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4187 | const DexFile& dex_file_; |
| 4188 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4189 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4190 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4191 | const uint8_t index_; |
| 4192 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4193 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4194 | const bool is_this_; |
| 4195 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4196 | bool can_be_null_; |
| 4197 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4198 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4199 | }; |
| 4200 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4201 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4202 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4203 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4204 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4205 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4206 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4207 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4208 | return true; |
| 4209 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4210 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4211 | template <typename T> T Compute(T x) const { return ~x; } |
| 4212 | |
| 4213 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4214 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4215 | } |
| 4216 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4217 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4218 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4219 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4220 | DECLARE_INSTRUCTION(Not); |
| 4221 | |
| 4222 | private: |
| 4223 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4224 | }; |
| 4225 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4226 | class HBooleanNot : public HUnaryOperation { |
| 4227 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4228 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4229 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4230 | |
| 4231 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4232 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4233 | return true; |
| 4234 | } |
| 4235 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4236 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4237 | DCHECK(IsUint<1>(x)); |
| 4238 | return !x; |
| 4239 | } |
| 4240 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4241 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4242 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4243 | } |
| 4244 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4245 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4246 | UNREACHABLE(); |
| 4247 | } |
| 4248 | |
| 4249 | DECLARE_INSTRUCTION(BooleanNot); |
| 4250 | |
| 4251 | private: |
| 4252 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4253 | }; |
| 4254 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4255 | class HTypeConversion : public HExpression<1> { |
| 4256 | public: |
| 4257 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4258 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4259 | : HExpression(result_type, |
| 4260 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4261 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4262 | SetRawInputAt(0, input); |
| 4263 | DCHECK_NE(input->GetType(), result_type); |
| 4264 | } |
| 4265 | |
| 4266 | HInstruction* GetInput() const { return InputAt(0); } |
| 4267 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4268 | Primitive::Type GetResultType() const { return GetType(); } |
| 4269 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4270 | // Required by the x86, ARM, MIPS and MIPS64 code generators when producing calls |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4271 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4272 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4273 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4274 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4275 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4276 | // Try to statically evaluate the conversion and return a HConstant |
| 4277 | // containing the result. If the input cannot be converted, return nullptr. |
| 4278 | HConstant* TryStaticEvaluation() const; |
| 4279 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4280 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4281 | Primitive::Type result_type) { |
| 4282 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4283 | // in the compilation process we do not know what architecture we will |
| 4284 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4285 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4286 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4287 | return SideEffects::CanTriggerGC(); |
| 4288 | } |
| 4289 | return SideEffects::None(); |
| 4290 | } |
| 4291 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4292 | DECLARE_INSTRUCTION(TypeConversion); |
| 4293 | |
| 4294 | private: |
| 4295 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4296 | }; |
| 4297 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4298 | static constexpr uint32_t kNoRegNumber = -1; |
| 4299 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4300 | class HPhi : public HInstruction { |
| 4301 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4302 | HPhi(ArenaAllocator* arena, |
| 4303 | uint32_t reg_number, |
| 4304 | size_t number_of_inputs, |
| 4305 | Primitive::Type type, |
| 4306 | uint32_t dex_pc = kNoDexPc) |
| 4307 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4308 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4309 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4310 | type_(type), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4311 | is_live_(false), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4312 | can_be_null_(true) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4313 | } |
| 4314 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4315 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4316 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4317 | switch (type) { |
| 4318 | case Primitive::kPrimBoolean: |
| 4319 | case Primitive::kPrimByte: |
| 4320 | case Primitive::kPrimShort: |
| 4321 | case Primitive::kPrimChar: |
| 4322 | return Primitive::kPrimInt; |
| 4323 | default: |
| 4324 | return type; |
| 4325 | } |
| 4326 | } |
| 4327 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4328 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4329 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4330 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4331 | |
| 4332 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4333 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4334 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4335 | Primitive::Type GetType() const OVERRIDE { return type_; } |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4336 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4337 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4338 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4339 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4340 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4341 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4342 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4343 | void SetDead() { is_live_ = false; } |
| 4344 | void SetLive() { is_live_ = true; } |
| 4345 | bool IsDead() const { return !is_live_; } |
| 4346 | bool IsLive() const { return is_live_; } |
| 4347 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4348 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4349 | return other != nullptr |
| 4350 | && other->IsPhi() |
| 4351 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4352 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4353 | } |
| 4354 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4355 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4356 | // An equivalent phi is a phi having the same dex register and type. |
| 4357 | // It assumes that phis with the same dex register are adjacent. |
| 4358 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4359 | HInstruction* next = GetNext(); |
| 4360 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4361 | if (next->GetType() == GetType()) { |
| 4362 | return next->AsPhi(); |
| 4363 | } |
| 4364 | next = next->GetNext(); |
| 4365 | } |
| 4366 | return nullptr; |
| 4367 | } |
| 4368 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4369 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4370 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4371 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4372 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4373 | return inputs_[index]; |
| 4374 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4375 | |
| 4376 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4377 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4380 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4381 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4382 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4383 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4384 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4385 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4386 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4387 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4388 | }; |
| 4389 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4390 | class HNullCheck : public HExpression<1> { |
| 4391 | public: |
| 4392 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4393 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4394 | SetRawInputAt(0, value); |
| 4395 | } |
| 4396 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4397 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4398 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4399 | return true; |
| 4400 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4401 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4402 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4403 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4404 | bool CanThrow() const OVERRIDE { return true; } |
| 4405 | |
| 4406 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4407 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4408 | |
| 4409 | DECLARE_INSTRUCTION(NullCheck); |
| 4410 | |
| 4411 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4412 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4413 | }; |
| 4414 | |
| 4415 | class FieldInfo : public ValueObject { |
| 4416 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4417 | FieldInfo(MemberOffset field_offset, |
| 4418 | Primitive::Type field_type, |
| 4419 | bool is_volatile, |
| 4420 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4421 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4422 | const DexFile& dex_file, |
| 4423 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4424 | : field_offset_(field_offset), |
| 4425 | field_type_(field_type), |
| 4426 | is_volatile_(is_volatile), |
| 4427 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4428 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4429 | dex_file_(dex_file), |
| 4430 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4431 | |
| 4432 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4433 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4434 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4435 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4436 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4437 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4438 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4439 | |
| 4440 | private: |
| 4441 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4442 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4443 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4444 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4445 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4446 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4447 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4448 | }; |
| 4449 | |
| 4450 | class HInstanceFieldGet : public HExpression<1> { |
| 4451 | public: |
| 4452 | HInstanceFieldGet(HInstruction* value, |
| 4453 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4454 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4455 | bool is_volatile, |
| 4456 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4457 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4458 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4459 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4460 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4461 | : HExpression(field_type, |
| 4462 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4463 | dex_pc), |
| 4464 | field_info_(field_offset, |
| 4465 | field_type, |
| 4466 | is_volatile, |
| 4467 | field_idx, |
| 4468 | declaring_class_def_index, |
| 4469 | dex_file, |
| 4470 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4471 | SetRawInputAt(0, value); |
| 4472 | } |
| 4473 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4474 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4475 | |
| 4476 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4477 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4478 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4479 | } |
| 4480 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4481 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4482 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4483 | } |
| 4484 | |
| 4485 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4486 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4487 | } |
| 4488 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4489 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4490 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4491 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4492 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4493 | |
| 4494 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4495 | |
| 4496 | private: |
| 4497 | const FieldInfo field_info_; |
| 4498 | |
| 4499 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4500 | }; |
| 4501 | |
| 4502 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4503 | public: |
| 4504 | HInstanceFieldSet(HInstruction* object, |
| 4505 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4506 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4507 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4508 | bool is_volatile, |
| 4509 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4510 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4511 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4512 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4513 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4514 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4515 | dex_pc), |
| 4516 | field_info_(field_offset, |
| 4517 | field_type, |
| 4518 | is_volatile, |
| 4519 | field_idx, |
| 4520 | declaring_class_def_index, |
| 4521 | dex_file, |
| 4522 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4523 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4524 | SetRawInputAt(0, object); |
| 4525 | SetRawInputAt(1, value); |
| 4526 | } |
| 4527 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4528 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4529 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4532 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4533 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4534 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4535 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4536 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4537 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4538 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4539 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4540 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4541 | |
| 4542 | private: |
| 4543 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4544 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4545 | |
| 4546 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4547 | }; |
| 4548 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4549 | class HArrayGet : public HExpression<2> { |
| 4550 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4551 | HArrayGet(HInstruction* array, |
| 4552 | HInstruction* index, |
| 4553 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4554 | uint32_t dex_pc, |
| 4555 | SideEffects additional_side_effects = SideEffects::None()) |
| 4556 | : HExpression(type, |
| 4557 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4558 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4559 | SetRawInputAt(0, array); |
| 4560 | SetRawInputAt(1, index); |
| 4561 | } |
| 4562 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4563 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4564 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4565 | return true; |
| 4566 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4567 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4568 | // TODO: We can be smarter here. |
| 4569 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4570 | // which generates the implicit null check. There are cases when these can be removed |
| 4571 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4572 | // implicit check here (as long as the address falls in the first page). |
| 4573 | return false; |
| 4574 | } |
| 4575 | |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4576 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4577 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4578 | HInstruction* GetArray() const { return InputAt(0); } |
| 4579 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4580 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4581 | DECLARE_INSTRUCTION(ArrayGet); |
| 4582 | |
| 4583 | private: |
| 4584 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4585 | }; |
| 4586 | |
| 4587 | class HArraySet : public HTemplateInstruction<3> { |
| 4588 | public: |
| 4589 | HArraySet(HInstruction* array, |
| 4590 | HInstruction* index, |
| 4591 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4592 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4593 | uint32_t dex_pc, |
| 4594 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4595 | : HTemplateInstruction( |
| 4596 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4597 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4598 | additional_side_effects), |
| 4599 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4600 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4601 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4602 | value_can_be_null_(true), |
| 4603 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4604 | SetRawInputAt(0, array); |
| 4605 | SetRawInputAt(1, index); |
| 4606 | SetRawInputAt(2, value); |
| 4607 | } |
| 4608 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4609 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4610 | // We currently always call a runtime method to catch array store |
| 4611 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4612 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4613 | } |
| 4614 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4615 | // Can throw ArrayStoreException. |
| 4616 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4617 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4618 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4619 | // TODO: Same as for ArrayGet. |
| 4620 | return false; |
| 4621 | } |
| 4622 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4623 | void ClearNeedsTypeCheck() { |
| 4624 | needs_type_check_ = false; |
| 4625 | } |
| 4626 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4627 | void ClearValueCanBeNull() { |
| 4628 | value_can_be_null_ = false; |
| 4629 | } |
| 4630 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4631 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4632 | static_type_of_array_is_object_array_ = true; |
| 4633 | } |
| 4634 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4635 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4636 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4637 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4638 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4639 | HInstruction* GetArray() const { return InputAt(0); } |
| 4640 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4641 | HInstruction* GetValue() const { return InputAt(2); } |
| 4642 | |
| 4643 | Primitive::Type GetComponentType() const { |
| 4644 | // The Dex format does not type floating point index operations. Since the |
| 4645 | // `expected_component_type_` is set during building and can therefore not |
| 4646 | // be correct, we also check what is the value type. If it is a floating |
| 4647 | // point type, we must use that type. |
| 4648 | Primitive::Type value_type = GetValue()->GetType(); |
| 4649 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4650 | ? value_type |
| 4651 | : expected_component_type_; |
| 4652 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4653 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4654 | Primitive::Type GetRawExpectedComponentType() const { |
| 4655 | return expected_component_type_; |
| 4656 | } |
| 4657 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4658 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4659 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4660 | } |
| 4661 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4662 | DECLARE_INSTRUCTION(ArraySet); |
| 4663 | |
| 4664 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4665 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4666 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4667 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4668 | // Cached information for the reference_type_info_ so that codegen |
| 4669 | // does not need to inspect the static type. |
| 4670 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4671 | |
| 4672 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4673 | }; |
| 4674 | |
| 4675 | class HArrayLength : public HExpression<1> { |
| 4676 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4677 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4678 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4679 | // Note that arrays do not change length, so the instruction does not |
| 4680 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4681 | SetRawInputAt(0, array); |
| 4682 | } |
| 4683 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4684 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4685 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4686 | return true; |
| 4687 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4688 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4689 | return obj == InputAt(0); |
| 4690 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4691 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4692 | DECLARE_INSTRUCTION(ArrayLength); |
| 4693 | |
| 4694 | private: |
| 4695 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4696 | }; |
| 4697 | |
| 4698 | class HBoundsCheck : public HExpression<2> { |
| 4699 | public: |
| 4700 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4701 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4702 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4703 | SetRawInputAt(0, index); |
| 4704 | SetRawInputAt(1, length); |
| 4705 | } |
| 4706 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4707 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4708 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4709 | return true; |
| 4710 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4711 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4712 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4713 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4714 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4715 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4716 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4717 | |
| 4718 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4719 | |
| 4720 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4721 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4722 | }; |
| 4723 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4724 | /** |
| 4725 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4726 | * to stay live until the last HInstruction. This class |
| 4727 | * 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] | 4728 | * HInstruction stays live. `index` represents the stack location index of the |
| 4729 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4730 | */ |
| 4731 | class HTemporary : public HTemplateInstruction<0> { |
| 4732 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4733 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4734 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4735 | |
| 4736 | size_t GetIndex() const { return index_; } |
| 4737 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4738 | Primitive::Type GetType() const OVERRIDE { |
| 4739 | // The previous instruction is the one that will be stored in the temporary location. |
| 4740 | DCHECK(GetPrevious() != nullptr); |
| 4741 | return GetPrevious()->GetType(); |
| 4742 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4743 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4744 | DECLARE_INSTRUCTION(Temporary); |
| 4745 | |
| 4746 | private: |
| 4747 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4748 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4749 | }; |
| 4750 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4751 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4752 | public: |
| 4753 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4754 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4755 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4756 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4757 | return true; |
| 4758 | } |
| 4759 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4760 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4761 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4762 | |
| 4763 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4764 | |
| 4765 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4766 | // Only used for code generation, in order to share the same slow path between back edges |
| 4767 | // of a same loop. |
| 4768 | SlowPathCode* slow_path_; |
| 4769 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4770 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4771 | }; |
| 4772 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4773 | /** |
| 4774 | * Instruction to load a Class object. |
| 4775 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4776 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4777 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4778 | HLoadClass(HCurrentMethod* current_method, |
| 4779 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4780 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4781 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4782 | uint32_t dex_pc, |
| 4783 | bool needs_access_check) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4784 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4785 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4786 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4787 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4788 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4789 | needs_access_check_(needs_access_check), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4790 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4791 | // Referrers class should not need access check. We never inline unverified |
| 4792 | // methods so we can't possibly end up in this situation. |
| 4793 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4794 | SetRawInputAt(0, current_method); |
| 4795 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4796 | |
| 4797 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4798 | |
| 4799 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 4800 | // Note that we don't need to test for generate_clinit_check_. |
| 4801 | // Whether or not we need to generate the clinit check is processed in |
| 4802 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4803 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 4804 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4808 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4809 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4810 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4811 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4812 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4813 | bool NeedsEnvironment() const OVERRIDE { |
| 4814 | // Will call runtime and load the class if the class is not loaded yet. |
| 4815 | // TODO: finer grain decision. |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4816 | return !is_referrers_class_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4817 | } |
| 4818 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4819 | bool MustGenerateClinitCheck() const { |
| 4820 | return generate_clinit_check_; |
| 4821 | } |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4822 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 4823 | // The entrypoint the code generator is going to call does not do |
| 4824 | // clinit of the class. |
| 4825 | DCHECK(!NeedsAccessCheck()); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4826 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
| 4829 | bool CanCallRuntime() const { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4830 | return MustGenerateClinitCheck() || !is_referrers_class_ || needs_access_check_; |
| 4831 | } |
| 4832 | |
| 4833 | bool NeedsAccessCheck() const { |
| 4834 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4835 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4836 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4837 | bool CanThrow() const OVERRIDE { |
| 4838 | // May call runtime and and therefore can throw. |
| 4839 | // TODO: finer grain decision. |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4840 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4843 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4844 | return loaded_class_rti_; |
| 4845 | } |
| 4846 | |
| 4847 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4848 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4849 | DCHECK(rti.IsExact()); |
| 4850 | loaded_class_rti_ = rti; |
| 4851 | } |
| 4852 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4853 | const DexFile& GetDexFile() { return dex_file_; } |
| 4854 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4855 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4856 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4857 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4858 | return SideEffects::CanTriggerGC(); |
| 4859 | } |
| 4860 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4861 | DECLARE_INSTRUCTION(LoadClass); |
| 4862 | |
| 4863 | private: |
| 4864 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4865 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4866 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4867 | // Whether this instruction must generate the initialization check. |
| 4868 | // Used for code generation. |
| 4869 | bool generate_clinit_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4870 | bool needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4871 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4872 | ReferenceTypeInfo loaded_class_rti_; |
| 4873 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4874 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4875 | }; |
| 4876 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4877 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4878 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4879 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4880 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4881 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4882 | SetRawInputAt(0, current_method); |
| 4883 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4884 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4885 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4886 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4887 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4888 | return other->AsLoadString()->string_index_ == string_index_; |
| 4889 | } |
| 4890 | |
| 4891 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4892 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4893 | uint32_t GetStringIndex() const { return string_index_; } |
| 4894 | |
| 4895 | // TODO: Can we deopt or debug when we resolve a string? |
| 4896 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4897 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4898 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4899 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4900 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4901 | return SideEffects::CanTriggerGC(); |
| 4902 | } |
| 4903 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4904 | DECLARE_INSTRUCTION(LoadString); |
| 4905 | |
| 4906 | private: |
| 4907 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4908 | |
| 4909 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4910 | }; |
| 4911 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4912 | /** |
| 4913 | * Performs an initialization check on its Class object input. |
| 4914 | */ |
| 4915 | class HClinitCheck : public HExpression<1> { |
| 4916 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4917 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4918 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4919 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4920 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4921 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4922 | SetRawInputAt(0, constant); |
| 4923 | } |
| 4924 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4925 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4926 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4927 | return true; |
| 4928 | } |
| 4929 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4930 | bool NeedsEnvironment() const OVERRIDE { |
| 4931 | // May call runtime to initialize the class. |
| 4932 | return true; |
| 4933 | } |
| 4934 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4935 | |
| 4936 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4937 | |
| 4938 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4939 | |
| 4940 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4941 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4942 | }; |
| 4943 | |
| 4944 | class HStaticFieldGet : public HExpression<1> { |
| 4945 | public: |
| 4946 | HStaticFieldGet(HInstruction* cls, |
| 4947 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4948 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4949 | bool is_volatile, |
| 4950 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4951 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4952 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4953 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4954 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4955 | : HExpression(field_type, |
| 4956 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4957 | dex_pc), |
| 4958 | field_info_(field_offset, |
| 4959 | field_type, |
| 4960 | is_volatile, |
| 4961 | field_idx, |
| 4962 | declaring_class_def_index, |
| 4963 | dex_file, |
| 4964 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4965 | SetRawInputAt(0, cls); |
| 4966 | } |
| 4967 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4968 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4969 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4970 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4971 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4972 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 4973 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | size_t ComputeHashCode() const OVERRIDE { |
| 4977 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4978 | } |
| 4979 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4980 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4981 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4982 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4983 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4984 | |
| 4985 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 4986 | |
| 4987 | private: |
| 4988 | const FieldInfo field_info_; |
| 4989 | |
| 4990 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 4991 | }; |
| 4992 | |
| 4993 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 4994 | public: |
| 4995 | HStaticFieldSet(HInstruction* cls, |
| 4996 | HInstruction* value, |
| 4997 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4998 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4999 | bool is_volatile, |
| 5000 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5001 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5002 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5003 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5004 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5005 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5006 | dex_pc), |
| 5007 | field_info_(field_offset, |
| 5008 | field_type, |
| 5009 | is_volatile, |
| 5010 | field_idx, |
| 5011 | declaring_class_def_index, |
| 5012 | dex_file, |
| 5013 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5014 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5015 | SetRawInputAt(0, cls); |
| 5016 | SetRawInputAt(1, value); |
| 5017 | } |
| 5018 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5019 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5020 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5021 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5022 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5023 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5024 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5025 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 5026 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5027 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5028 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5029 | |
| 5030 | private: |
| 5031 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5032 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5033 | |
| 5034 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5035 | }; |
| 5036 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5037 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5038 | public: |
| 5039 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5040 | Primitive::Type field_type, |
| 5041 | uint32_t field_index, |
| 5042 | uint32_t dex_pc) |
| 5043 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5044 | field_index_(field_index) { |
| 5045 | SetRawInputAt(0, obj); |
| 5046 | } |
| 5047 | |
| 5048 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5049 | bool CanThrow() const OVERRIDE { return true; } |
| 5050 | |
| 5051 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5052 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5053 | |
| 5054 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5055 | |
| 5056 | private: |
| 5057 | const uint32_t field_index_; |
| 5058 | |
| 5059 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5060 | }; |
| 5061 | |
| 5062 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5063 | public: |
| 5064 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5065 | HInstruction* value, |
| 5066 | Primitive::Type field_type, |
| 5067 | uint32_t field_index, |
| 5068 | uint32_t dex_pc) |
| 5069 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5070 | field_type_(field_type), |
| 5071 | field_index_(field_index) { |
| 5072 | DCHECK_EQ(field_type, value->GetType()); |
| 5073 | SetRawInputAt(0, obj); |
| 5074 | SetRawInputAt(1, value); |
| 5075 | } |
| 5076 | |
| 5077 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5078 | bool CanThrow() const OVERRIDE { return true; } |
| 5079 | |
| 5080 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5081 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5082 | |
| 5083 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5084 | |
| 5085 | private: |
| 5086 | const Primitive::Type field_type_; |
| 5087 | const uint32_t field_index_; |
| 5088 | |
| 5089 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5090 | }; |
| 5091 | |
| 5092 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5093 | public: |
| 5094 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5095 | uint32_t field_index, |
| 5096 | uint32_t dex_pc) |
| 5097 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5098 | field_index_(field_index) { |
| 5099 | } |
| 5100 | |
| 5101 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5102 | bool CanThrow() const OVERRIDE { return true; } |
| 5103 | |
| 5104 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5105 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5106 | |
| 5107 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5108 | |
| 5109 | private: |
| 5110 | const uint32_t field_index_; |
| 5111 | |
| 5112 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5113 | }; |
| 5114 | |
| 5115 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5116 | public: |
| 5117 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5118 | Primitive::Type field_type, |
| 5119 | uint32_t field_index, |
| 5120 | uint32_t dex_pc) |
| 5121 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5122 | field_type_(field_type), |
| 5123 | field_index_(field_index) { |
| 5124 | DCHECK_EQ(field_type, value->GetType()); |
| 5125 | SetRawInputAt(0, value); |
| 5126 | } |
| 5127 | |
| 5128 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5129 | bool CanThrow() const OVERRIDE { return true; } |
| 5130 | |
| 5131 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5132 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5133 | |
| 5134 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5135 | |
| 5136 | private: |
| 5137 | const Primitive::Type field_type_; |
| 5138 | const uint32_t field_index_; |
| 5139 | |
| 5140 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5141 | }; |
| 5142 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5143 | // Implement the move-exception DEX instruction. |
| 5144 | class HLoadException : public HExpression<0> { |
| 5145 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5146 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5147 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5148 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5149 | bool CanBeNull() const OVERRIDE { return false; } |
| 5150 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5151 | DECLARE_INSTRUCTION(LoadException); |
| 5152 | |
| 5153 | private: |
| 5154 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5155 | }; |
| 5156 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5157 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5158 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5159 | class HClearException : public HTemplateInstruction<0> { |
| 5160 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5161 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5162 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5163 | |
| 5164 | DECLARE_INSTRUCTION(ClearException); |
| 5165 | |
| 5166 | private: |
| 5167 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5168 | }; |
| 5169 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5170 | class HThrow : public HTemplateInstruction<1> { |
| 5171 | public: |
| 5172 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5173 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5174 | SetRawInputAt(0, exception); |
| 5175 | } |
| 5176 | |
| 5177 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5178 | |
| 5179 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5180 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5181 | bool CanThrow() const OVERRIDE { return true; } |
| 5182 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5183 | |
| 5184 | DECLARE_INSTRUCTION(Throw); |
| 5185 | |
| 5186 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5187 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5188 | }; |
| 5189 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5190 | /** |
| 5191 | * Implementation strategies for the code generator of a HInstanceOf |
| 5192 | * or `HCheckCast`. |
| 5193 | */ |
| 5194 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5195 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5196 | kExactCheck, // Can do a single class compare. |
| 5197 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5198 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5199 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5200 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5201 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5202 | }; |
| 5203 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5204 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5205 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5206 | HInstanceOf(HInstruction* object, |
| 5207 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5208 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5209 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5210 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5211 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5212 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5213 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5214 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5215 | SetRawInputAt(0, object); |
| 5216 | SetRawInputAt(1, constant); |
| 5217 | } |
| 5218 | |
| 5219 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5220 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5221 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5222 | return true; |
| 5223 | } |
| 5224 | |
| 5225 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5226 | return false; |
| 5227 | } |
| 5228 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5229 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5230 | |
| 5231 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5232 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5233 | // Used only in code generation. |
| 5234 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5235 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5236 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5237 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 5238 | return (check_kind == TypeCheckKind::kExactCheck) |
| 5239 | ? SideEffects::None() |
| 5240 | // Mips currently does runtime calls for any other checks. |
| 5241 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5242 | } |
| 5243 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5244 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5245 | |
| 5246 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5247 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5248 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5249 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5250 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5251 | }; |
| 5252 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5253 | class HBoundType : public HExpression<1> { |
| 5254 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5255 | // Constructs an HBoundType with the given upper_bound. |
| 5256 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5257 | HBoundType(HInstruction* input, |
| 5258 | ReferenceTypeInfo upper_bound, |
| 5259 | bool upper_can_be_null, |
| 5260 | uint32_t dex_pc = kNoDexPc) |
| 5261 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5262 | upper_bound_(upper_bound), |
| 5263 | upper_can_be_null_(upper_can_be_null), |
| 5264 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5265 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5266 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5267 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5268 | } |
| 5269 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5270 | // GetUpper* should only be used in reference type propagation. |
| 5271 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5272 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5273 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5274 | void SetCanBeNull(bool can_be_null) { |
| 5275 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5276 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5277 | } |
| 5278 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5279 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5280 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5281 | DECLARE_INSTRUCTION(BoundType); |
| 5282 | |
| 5283 | private: |
| 5284 | // 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] | 5285 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5286 | // It is used to bound the type in cases like: |
| 5287 | // if (x instanceof ClassX) { |
| 5288 | // // uper_bound_ will be ClassX |
| 5289 | // } |
| 5290 | const ReferenceTypeInfo upper_bound_; |
| 5291 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5292 | // is false then can_be_null_ cannot be true). |
| 5293 | const bool upper_can_be_null_; |
| 5294 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5295 | |
| 5296 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5297 | }; |
| 5298 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5299 | class HCheckCast : public HTemplateInstruction<2> { |
| 5300 | public: |
| 5301 | HCheckCast(HInstruction* object, |
| 5302 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5303 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5304 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5305 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5306 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5307 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5308 | SetRawInputAt(0, object); |
| 5309 | SetRawInputAt(1, constant); |
| 5310 | } |
| 5311 | |
| 5312 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5313 | |
| 5314 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5315 | return true; |
| 5316 | } |
| 5317 | |
| 5318 | bool NeedsEnvironment() const OVERRIDE { |
| 5319 | // Instruction may throw a CheckCastError. |
| 5320 | return true; |
| 5321 | } |
| 5322 | |
| 5323 | bool CanThrow() const OVERRIDE { return true; } |
| 5324 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5325 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5326 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5327 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5328 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5329 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5330 | |
| 5331 | DECLARE_INSTRUCTION(CheckCast); |
| 5332 | |
| 5333 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5334 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5335 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5336 | |
| 5337 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5338 | }; |
| 5339 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5340 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5341 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5342 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5343 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5344 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5345 | barrier_kind_(barrier_kind) {} |
| 5346 | |
| 5347 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5348 | |
| 5349 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5350 | |
| 5351 | private: |
| 5352 | const MemBarrierKind barrier_kind_; |
| 5353 | |
| 5354 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5355 | }; |
| 5356 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5357 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5358 | public: |
| 5359 | enum OperationKind { |
| 5360 | kEnter, |
| 5361 | kExit, |
| 5362 | }; |
| 5363 | |
| 5364 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5365 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5366 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5367 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5368 | SetRawInputAt(0, object); |
| 5369 | } |
| 5370 | |
| 5371 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5372 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5373 | |
| 5374 | bool CanThrow() const OVERRIDE { |
| 5375 | // Verifier guarantees that monitor-exit cannot throw. |
| 5376 | // This is important because it allows the HGraphBuilder to remove |
| 5377 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5378 | return IsEnter(); |
| 5379 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5380 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5381 | |
| 5382 | bool IsEnter() const { return kind_ == kEnter; } |
| 5383 | |
| 5384 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5385 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5386 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5387 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5388 | |
| 5389 | private: |
| 5390 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5391 | }; |
| 5392 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5393 | /** |
| 5394 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5395 | * of a String to a call to a StringFactory. Only baseline will see |
| 5396 | * the node at code generation, where it will be be treated as null. |
| 5397 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5398 | * in the instruction simplifier. |
| 5399 | */ |
| 5400 | class HFakeString : public HTemplateInstruction<0> { |
| 5401 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5402 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5403 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5404 | |
| 5405 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5406 | |
| 5407 | DECLARE_INSTRUCTION(FakeString); |
| 5408 | |
| 5409 | private: |
| 5410 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5411 | }; |
| 5412 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5413 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5414 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5415 | MoveOperands(Location source, |
| 5416 | Location destination, |
| 5417 | Primitive::Type type, |
| 5418 | HInstruction* instruction) |
| 5419 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5420 | |
| 5421 | Location GetSource() const { return source_; } |
| 5422 | Location GetDestination() const { return destination_; } |
| 5423 | |
| 5424 | void SetSource(Location value) { source_ = value; } |
| 5425 | void SetDestination(Location value) { destination_ = value; } |
| 5426 | |
| 5427 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5428 | // destination (but not the source). |
| 5429 | Location MarkPending() { |
| 5430 | DCHECK(!IsPending()); |
| 5431 | Location dest = destination_; |
| 5432 | destination_ = Location::NoLocation(); |
| 5433 | return dest; |
| 5434 | } |
| 5435 | |
| 5436 | void ClearPending(Location dest) { |
| 5437 | DCHECK(IsPending()); |
| 5438 | destination_ = dest; |
| 5439 | } |
| 5440 | |
| 5441 | bool IsPending() const { |
| 5442 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5443 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5444 | } |
| 5445 | |
| 5446 | // True if this blocks a move from the given location. |
| 5447 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5448 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5449 | } |
| 5450 | |
| 5451 | // A move is redundant if it's been eliminated, if its source and |
| 5452 | // destination are the same, or if its destination is unneeded. |
| 5453 | bool IsRedundant() const { |
| 5454 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5455 | } |
| 5456 | |
| 5457 | // We clear both operands to indicate move that's been eliminated. |
| 5458 | void Eliminate() { |
| 5459 | source_ = destination_ = Location::NoLocation(); |
| 5460 | } |
| 5461 | |
| 5462 | bool IsEliminated() const { |
| 5463 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5464 | return source_.IsInvalid(); |
| 5465 | } |
| 5466 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5467 | Primitive::Type GetType() const { return type_; } |
| 5468 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5469 | bool Is64BitMove() const { |
| 5470 | return Primitive::Is64BitType(type_); |
| 5471 | } |
| 5472 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5473 | HInstruction* GetInstruction() const { return instruction_; } |
| 5474 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5475 | private: |
| 5476 | Location source_; |
| 5477 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5478 | // The type this move is for. |
| 5479 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5480 | // The instruction this move is assocatied with. Null when this move is |
| 5481 | // for moving an input in the expected locations of user (including a phi user). |
| 5482 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5483 | // in the same parallel move. |
| 5484 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5485 | }; |
| 5486 | |
| 5487 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5488 | |
| 5489 | class HParallelMove : public HTemplateInstruction<0> { |
| 5490 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5491 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5492 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5493 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5494 | moves_.reserve(kDefaultNumberOfMoves); |
| 5495 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5496 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5497 | void AddMove(Location source, |
| 5498 | Location destination, |
| 5499 | Primitive::Type type, |
| 5500 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5501 | DCHECK(source.IsValid()); |
| 5502 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5503 | if (kIsDebugBuild) { |
| 5504 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5505 | for (const MoveOperands& move : moves_) { |
| 5506 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5507 | // Special case the situation where the move is for the spill slot |
| 5508 | // of the instruction. |
| 5509 | if ((GetPrevious() == instruction) |
| 5510 | || ((GetPrevious() == nullptr) |
| 5511 | && instruction->IsPhi() |
| 5512 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5513 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5514 | << "Doing parallel moves for the same instruction."; |
| 5515 | } else { |
| 5516 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5517 | } |
| 5518 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5519 | } |
| 5520 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5521 | for (const MoveOperands& move : moves_) { |
| 5522 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5523 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5524 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5525 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5526 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5527 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5528 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5529 | } |
| 5530 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5531 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5532 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5533 | } |
| 5534 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5535 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5536 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5537 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5538 | |
| 5539 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5540 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5541 | |
| 5542 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5543 | }; |
| 5544 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5545 | } // namespace art |
| 5546 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5547 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5548 | #include "nodes_arm64.h" |
| 5549 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5550 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5551 | #include "nodes_x86.h" |
| 5552 | #endif |
| 5553 | |
| 5554 | namespace art { |
| 5555 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5556 | class HGraphVisitor : public ValueObject { |
| 5557 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5558 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5559 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5560 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5561 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5562 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5563 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5564 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5565 | void VisitInsertionOrder(); |
| 5566 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5567 | // Visit the graph following dominator tree reverse post-order. |
| 5568 | void VisitReversePostOrder(); |
| 5569 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5570 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5571 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5572 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5573 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5574 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5575 | |
| 5576 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5577 | |
| 5578 | #undef DECLARE_VISIT_INSTRUCTION |
| 5579 | |
| 5580 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5581 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5582 | |
| 5583 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5584 | }; |
| 5585 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5586 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5587 | public: |
| 5588 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5589 | virtual ~HGraphDelegateVisitor() {} |
| 5590 | |
| 5591 | // Visit functions that delegate to to super class. |
| 5592 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5593 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5594 | |
| 5595 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5596 | |
| 5597 | #undef DECLARE_VISIT_INSTRUCTION |
| 5598 | |
| 5599 | private: |
| 5600 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5601 | }; |
| 5602 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5603 | class HInsertionOrderIterator : public ValueObject { |
| 5604 | public: |
| 5605 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5606 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5607 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5608 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5609 | void Advance() { ++index_; } |
| 5610 | |
| 5611 | private: |
| 5612 | const HGraph& graph_; |
| 5613 | size_t index_; |
| 5614 | |
| 5615 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5616 | }; |
| 5617 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5618 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5619 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5620 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5621 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5622 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5623 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5624 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5625 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5626 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5627 | void Advance() { ++index_; } |
| 5628 | |
| 5629 | private: |
| 5630 | const HGraph& graph_; |
| 5631 | size_t index_; |
| 5632 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5633 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5634 | }; |
| 5635 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5636 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5637 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5638 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5639 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5640 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5641 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5642 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5643 | |
| 5644 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5645 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5646 | void Advance() { --index_; } |
| 5647 | |
| 5648 | private: |
| 5649 | const HGraph& graph_; |
| 5650 | size_t index_; |
| 5651 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5652 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5653 | }; |
| 5654 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5655 | class HLinearPostOrderIterator : public ValueObject { |
| 5656 | public: |
| 5657 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5658 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5659 | |
| 5660 | bool Done() const { return index_ == 0; } |
| 5661 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5662 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5663 | |
| 5664 | void Advance() { |
| 5665 | --index_; |
| 5666 | DCHECK_GE(index_, 0U); |
| 5667 | } |
| 5668 | |
| 5669 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5670 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5671 | size_t index_; |
| 5672 | |
| 5673 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5674 | }; |
| 5675 | |
| 5676 | class HLinearOrderIterator : public ValueObject { |
| 5677 | public: |
| 5678 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5679 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5680 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5681 | bool Done() const { return index_ == order_.size(); } |
| 5682 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5683 | void Advance() { ++index_; } |
| 5684 | |
| 5685 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5686 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5687 | size_t index_; |
| 5688 | |
| 5689 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5690 | }; |
| 5691 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5692 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5693 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5694 | // block id. |
| 5695 | class HBlocksInLoopIterator : public ValueObject { |
| 5696 | public: |
| 5697 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5698 | : blocks_in_loop_(info.GetBlocks()), |
| 5699 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5700 | index_(0) { |
| 5701 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5702 | Advance(); |
| 5703 | } |
| 5704 | } |
| 5705 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5706 | bool Done() const { return index_ == blocks_.size(); } |
| 5707 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5708 | void Advance() { |
| 5709 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5710 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5711 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5712 | break; |
| 5713 | } |
| 5714 | } |
| 5715 | } |
| 5716 | |
| 5717 | private: |
| 5718 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5719 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5720 | size_t index_; |
| 5721 | |
| 5722 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5723 | }; |
| 5724 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5725 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5726 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5727 | // post order. |
| 5728 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5729 | public: |
| 5730 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5731 | : blocks_in_loop_(info.GetBlocks()), |
| 5732 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5733 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5734 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5735 | Advance(); |
| 5736 | } |
| 5737 | } |
| 5738 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5739 | bool Done() const { return index_ == blocks_.size(); } |
| 5740 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5741 | void Advance() { |
| 5742 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5743 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5744 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5745 | break; |
| 5746 | } |
| 5747 | } |
| 5748 | } |
| 5749 | |
| 5750 | private: |
| 5751 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5752 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5753 | size_t index_; |
| 5754 | |
| 5755 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5756 | }; |
| 5757 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5758 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5759 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5760 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5761 | : constant->AsLongConstant()->GetValue(); |
| 5762 | } |
| 5763 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5764 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5765 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5766 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5767 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5768 | // times and provide different class resolution but no two class loaders should ever |
| 5769 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5770 | // all sorts of weird failures. |
| 5771 | return &lhs == &rhs; |
| 5772 | } |
| 5773 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5774 | } // namespace art |
| 5775 | |
| 5776 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |