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 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame^] | 374 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 375 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 376 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 377 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 378 | // The instruction has been inserted into the graph, either as a constant, or |
| 379 | // before cursor. |
| 380 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 381 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 382 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 383 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 384 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 385 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 386 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 387 | template <class InstructionType, typename ValueType> |
| 388 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 389 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 390 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 391 | // Try to find an existing constant of the given value. |
| 392 | InstructionType* constant = nullptr; |
| 393 | auto cached_constant = cache->find(value); |
| 394 | if (cached_constant != cache->end()) { |
| 395 | constant = cached_constant->second; |
| 396 | } |
| 397 | |
| 398 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 399 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 400 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 401 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 402 | cache->Overwrite(value, constant); |
| 403 | InsertConstant(constant); |
| 404 | } |
| 405 | return constant; |
| 406 | } |
| 407 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 408 | void InsertConstant(HConstant* instruction); |
| 409 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 410 | // Cache a float constant into the graph. This method should only be |
| 411 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 412 | void CacheFloatConstant(HFloatConstant* constant); |
| 413 | |
| 414 | // See CacheFloatConstant comment. |
| 415 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 416 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 417 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 418 | |
| 419 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 420 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 421 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 422 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 423 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 424 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 425 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 426 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 427 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 428 | HBasicBlock* entry_block_; |
| 429 | HBasicBlock* exit_block_; |
| 430 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 431 | // 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] | 432 | uint16_t maximum_number_of_out_vregs_; |
| 433 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 434 | // The number of virtual registers in this method. Contains the parameters. |
| 435 | uint16_t number_of_vregs_; |
| 436 | |
| 437 | // The number of virtual registers used by parameters of this method. |
| 438 | uint16_t number_of_in_vregs_; |
| 439 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 440 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 441 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 442 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 443 | // Has bounds checks. We can totally skip BCE if it's false. |
| 444 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 445 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 446 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 447 | // try/catch-related passes if false. |
| 448 | bool has_try_catch_; |
| 449 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 450 | // Indicates whether the graph should be compiled in a way that |
| 451 | // ensures full debuggability. If false, we can apply more |
| 452 | // aggressive optimizations that may limit the level of debugging. |
| 453 | const bool debuggable_; |
| 454 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 455 | // 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] | 456 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 457 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 458 | // The dex file from which the method is from. |
| 459 | const DexFile& dex_file_; |
| 460 | |
| 461 | // The method index in the dex file. |
| 462 | const uint32_t method_idx_; |
| 463 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 464 | // If inlined, this encodes how the callee is being invoked. |
| 465 | const InvokeType invoke_type_; |
| 466 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 467 | // Whether the graph has been transformed to SSA form. Only used |
| 468 | // in debug mode to ensure we are not using properties only valid |
| 469 | // for non-SSA form (like the number of temporaries). |
| 470 | bool in_ssa_form_; |
| 471 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 472 | const bool should_generate_constructor_barrier_; |
| 473 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 474 | const InstructionSet instruction_set_; |
| 475 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 476 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 477 | HNullConstant* cached_null_constant_; |
| 478 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 479 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 480 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 481 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 482 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 483 | HCurrentMethod* cached_current_method_; |
| 484 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame^] | 485 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 486 | // for example for methods whose declaring class could not be resolved |
| 487 | // (such as when the superclass could not be found). |
| 488 | ArtMethod* art_method_; |
| 489 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 490 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 491 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 492 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 493 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 494 | }; |
| 495 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 496 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 497 | public: |
| 498 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 499 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 500 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 501 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 502 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 503 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 504 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 505 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 506 | |
| 507 | HBasicBlock* GetHeader() const { |
| 508 | return header_; |
| 509 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 510 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 511 | void SetHeader(HBasicBlock* block) { |
| 512 | header_ = block; |
| 513 | } |
| 514 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 515 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 516 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 517 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 518 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 519 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 520 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 523 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 524 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 525 | } |
| 526 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 527 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 528 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 531 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 532 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 535 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 536 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 537 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 538 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 539 | } |
| 540 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 541 | // Returns the lifetime position of the back edge that has the |
| 542 | // greatest lifetime position. |
| 543 | size_t GetLifetimeEnd() const; |
| 544 | |
| 545 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 546 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 547 | } |
| 548 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 549 | // 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] | 550 | // that is the header dominates the back edge. |
| 551 | bool Populate(); |
| 552 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 553 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 554 | // Populate(). If there are no back edges left, the loop info is completely |
| 555 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 556 | // inner loops first. |
| 557 | void Update(); |
| 558 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 559 | // Returns whether this loop information contains `block`. |
| 560 | // Note that this loop information *must* be populated before entering this function. |
| 561 | bool Contains(const HBasicBlock& block) const; |
| 562 | |
| 563 | // Returns whether this loop information is an inner loop of `other`. |
| 564 | // Note that `other` *must* be populated before entering this function. |
| 565 | bool IsIn(const HLoopInformation& other) const; |
| 566 | |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 567 | // Returns true if instruction is not defined within this loop or any loop nested inside |
| 568 | // this loop. If must_dominate is set, only definitions that actually dominate the loop |
| 569 | // header can be invariant. Otherwise, any definition outside the loop, including |
| 570 | // definitions that appear after the loop, is invariant. |
| 571 | bool IsLoopInvariant(HInstruction* instruction, bool must_dominate) const; |
| 572 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 573 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 574 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 575 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 576 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 577 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 578 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 579 | // Internal recursive implementation of `Populate`. |
| 580 | void PopulateRecursive(HBasicBlock* block); |
| 581 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 582 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 583 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 584 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 585 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 586 | |
| 587 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 588 | }; |
| 589 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 590 | // Stores try/catch information for basic blocks. |
| 591 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 592 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 593 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 594 | public: |
| 595 | // Try block information constructor. |
| 596 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 597 | : try_entry_(&try_entry), |
| 598 | catch_dex_file_(nullptr), |
| 599 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 600 | DCHECK(try_entry_ != nullptr); |
| 601 | } |
| 602 | |
| 603 | // Catch block information constructor. |
| 604 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 605 | : try_entry_(nullptr), |
| 606 | catch_dex_file_(&dex_file), |
| 607 | catch_type_index_(catch_type_index) {} |
| 608 | |
| 609 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 610 | |
| 611 | const HTryBoundary& GetTryEntry() const { |
| 612 | DCHECK(IsTryBlock()); |
| 613 | return *try_entry_; |
| 614 | } |
| 615 | |
| 616 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 617 | |
| 618 | bool IsCatchAllTypeIndex() const { |
| 619 | DCHECK(IsCatchBlock()); |
| 620 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 621 | } |
| 622 | |
| 623 | uint16_t GetCatchTypeIndex() const { |
| 624 | DCHECK(IsCatchBlock()); |
| 625 | return catch_type_index_; |
| 626 | } |
| 627 | |
| 628 | const DexFile& GetCatchDexFile() const { |
| 629 | DCHECK(IsCatchBlock()); |
| 630 | return *catch_dex_file_; |
| 631 | } |
| 632 | |
| 633 | private: |
| 634 | // One of possibly several TryBoundary instructions entering the block's try. |
| 635 | // Only set for try blocks. |
| 636 | const HTryBoundary* try_entry_; |
| 637 | |
| 638 | // Exception type information. Only set for catch blocks. |
| 639 | const DexFile* catch_dex_file_; |
| 640 | const uint16_t catch_type_index_; |
| 641 | }; |
| 642 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 643 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 644 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 645 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 646 | // A block in a method. Contains the list of instructions represented |
| 647 | // as a double linked list. Each block knows its predecessors and |
| 648 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 649 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 650 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 651 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 652 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 653 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 654 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 655 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 656 | loop_information_(nullptr), |
| 657 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 658 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 659 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 660 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 661 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 662 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 663 | try_catch_information_(nullptr) { |
| 664 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 665 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 666 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 667 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 668 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 669 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 670 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 673 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 674 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 675 | } |
| 676 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 677 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 678 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 679 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 680 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 681 | return ContainsElement(successors_, block, start_from); |
| 682 | } |
| 683 | |
| 684 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 685 | return dominated_blocks_; |
| 686 | } |
| 687 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 688 | bool IsEntryBlock() const { |
| 689 | return graph_->GetEntryBlock() == this; |
| 690 | } |
| 691 | |
| 692 | bool IsExitBlock() const { |
| 693 | return graph_->GetExitBlock() == this; |
| 694 | } |
| 695 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 696 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 697 | bool IsSingleTryBoundary() const; |
| 698 | |
| 699 | // Returns true if this block emits nothing but a jump. |
| 700 | bool IsSingleJump() const { |
| 701 | HLoopInformation* loop_info = GetLoopInformation(); |
| 702 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 703 | // Back edges generate a suspend check. |
| 704 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 705 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 706 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 707 | void AddBackEdge(HBasicBlock* back_edge) { |
| 708 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 709 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 710 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 711 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 712 | loop_information_->AddBackEdge(back_edge); |
| 713 | } |
| 714 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 715 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 716 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 717 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 718 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 719 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 720 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 721 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 722 | HBasicBlock* GetDominator() const { return dominator_; } |
| 723 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 724 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 725 | |
| 726 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 727 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 728 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 729 | |
| 730 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 731 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 732 | } |
| 733 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 734 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 735 | |
| 736 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 737 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 738 | } |
| 739 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 740 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 741 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 742 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 743 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 744 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 745 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 746 | |
| 747 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 748 | successors_.push_back(block); |
| 749 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 752 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 753 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 754 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 755 | new_block->predecessors_.push_back(this); |
| 756 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 757 | } |
| 758 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 759 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 760 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 761 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 762 | new_block->successors_.push_back(this); |
| 763 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 766 | // Insert `this` between `predecessor` and `successor. This method |
| 767 | // preserves the indicies, and will update the first edge found between |
| 768 | // `predecessor` and `successor`. |
| 769 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 770 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 771 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 772 | successor->predecessors_[predecessor_index] = this; |
| 773 | predecessor->successors_[successor_index] = this; |
| 774 | successors_.push_back(successor); |
| 775 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 776 | } |
| 777 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 778 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 779 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 780 | } |
| 781 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 782 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 783 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 786 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 787 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 791 | predecessors_.push_back(block); |
| 792 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 793 | } |
| 794 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 795 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 796 | DCHECK_EQ(predecessors_.size(), 2u); |
| 797 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 798 | } |
| 799 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 800 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 801 | DCHECK_EQ(successors_.size(), 2u); |
| 802 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 803 | } |
| 804 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 805 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 806 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 807 | } |
| 808 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 809 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 810 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 811 | } |
| 812 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 813 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 814 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 815 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 819 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 820 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | // Returns whether the first occurrence of `predecessor` in the list of |
| 824 | // predecessors is at index `idx`. |
| 825 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 826 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 827 | return GetPredecessorIndexOf(predecessor) == idx; |
| 828 | } |
| 829 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 830 | // Create a new block between this block and its predecessors. The new block |
| 831 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 832 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 833 | // loop and try/catch information are not updated. |
| 834 | HBasicBlock* CreateImmediateDominator(); |
| 835 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 836 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 837 | // created, latter block. Note that this method will add the block to the |
| 838 | // graph, create a Goto at the end of the former block and will create an edge |
| 839 | // 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] | 840 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 841 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 842 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 843 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 844 | // created block. Note that this method just updates raw block information, |
| 845 | // like predecessors, successors, dominators, and instruction list. It does not |
| 846 | // update the graph, reverse post order, loop information, nor make sure the |
| 847 | // blocks are consistent (for example ending with a control flow instruction). |
| 848 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 849 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 850 | // Split catch block into two blocks after the original move-exception bytecode |
| 851 | // instruction, or at the beginning if not present. Returns the newly created, |
| 852 | // latter block, or nullptr if such block could not be created (must be dead |
| 853 | // in that case). Note that this method just updates raw block information, |
| 854 | // like predecessors, successors, dominators, and instruction list. It does not |
| 855 | // update the graph, reverse post order, loop information, nor make sure the |
| 856 | // blocks are consistent (for example ending with a control flow instruction). |
| 857 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 858 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 859 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 860 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 861 | // that this method does not update the graph, reverse post order, loop |
| 862 | // information, nor make sure the blocks are consistent (for example ending |
| 863 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 864 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 865 | |
| 866 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 867 | // of `this` are moved to `other`. |
| 868 | // Note that this method does not update the graph, reverse post order, loop |
| 869 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 870 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 871 | void ReplaceWith(HBasicBlock* other); |
| 872 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 873 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 874 | // order, links to predecessors, successors, dominators and deletes the block |
| 875 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 876 | // predecessor of `other` and vice versa. |
| 877 | void MergeWith(HBasicBlock* other); |
| 878 | |
| 879 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 880 | // removes it from all loops it is included in and eventually from the graph. |
| 881 | // The block must not dominate any other block. Predecessors and successors |
| 882 | // are safely updated. |
| 883 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 884 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 885 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 886 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 887 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 888 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 889 | // Replace instruction `initial` with `replacement` within this block. |
| 890 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 891 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 892 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 893 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 894 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 895 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 896 | // instruction is not in use and removes it from the use lists of its inputs. |
| 897 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 898 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 899 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 900 | |
| 901 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 902 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 903 | } |
| 904 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 905 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 906 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 907 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 908 | } |
| 909 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 910 | HLoopInformation* GetLoopInformation() const { |
| 911 | return loop_information_; |
| 912 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 913 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 914 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 915 | // 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] | 916 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 917 | void SetInLoop(HLoopInformation* info) { |
| 918 | if (IsLoopHeader()) { |
| 919 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 920 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 921 | loop_information_ = info; |
| 922 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 923 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 924 | // Note that a non loop header having a loop information means this loop information |
| 925 | // has already been populated |
| 926 | loop_information_ = info; |
| 927 | } else { |
| 928 | // Block is part of an inner loop. Do not update the loop information. |
| 929 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 930 | // at this point, because this method is being called while populating `info`. |
| 931 | } |
| 932 | } |
| 933 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 934 | // Raw update of the loop information. |
| 935 | void SetLoopInformation(HLoopInformation* info) { |
| 936 | loop_information_ = info; |
| 937 | } |
| 938 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 939 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 940 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 941 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 942 | |
| 943 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 944 | try_catch_information_ = try_catch_information; |
| 945 | } |
| 946 | |
| 947 | bool IsTryBlock() const { |
| 948 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 949 | } |
| 950 | |
| 951 | bool IsCatchBlock() const { |
| 952 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 953 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 954 | |
| 955 | // Returns the try entry that this block's successors should have. They will |
| 956 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 957 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 958 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 959 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 960 | bool HasThrowingInstructions() const; |
| 961 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 962 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 963 | bool Dominates(HBasicBlock* block) const; |
| 964 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 965 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 966 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 967 | |
| 968 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 969 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 970 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 971 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 972 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 973 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 974 | bool HasSinglePhi() const; |
| 975 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 976 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 977 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 978 | ArenaVector<HBasicBlock*> predecessors_; |
| 979 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 980 | HInstructionList instructions_; |
| 981 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 982 | HLoopInformation* loop_information_; |
| 983 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 984 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 985 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 986 | // The dex program counter of the first instruction of this block. |
| 987 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 988 | size_t lifetime_start_; |
| 989 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 990 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 991 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 992 | friend class HGraph; |
| 993 | friend class HInstruction; |
| 994 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 995 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 996 | }; |
| 997 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 998 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 999 | // from the innermost to the outermost. |
| 1000 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1001 | public: |
| 1002 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1003 | : current_(block.GetLoopInformation()) {} |
| 1004 | |
| 1005 | bool Done() const { return current_ == nullptr; } |
| 1006 | |
| 1007 | void Advance() { |
| 1008 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1009 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | HLoopInformation* Current() const { |
| 1013 | DCHECK(!Done()); |
| 1014 | return current_; |
| 1015 | } |
| 1016 | |
| 1017 | private: |
| 1018 | HLoopInformation* current_; |
| 1019 | |
| 1020 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1021 | }; |
| 1022 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1023 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1024 | M(Above, Condition) \ |
| 1025 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1026 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1027 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1028 | M(ArrayGet, Instruction) \ |
| 1029 | M(ArrayLength, Instruction) \ |
| 1030 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1031 | M(Below, Condition) \ |
| 1032 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1033 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1034 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1035 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1036 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1037 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1038 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1039 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1040 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1041 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1042 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1043 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1044 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1045 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1046 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1047 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1048 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1049 | M(FloatConstant, Constant) \ |
| 1050 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1051 | M(GreaterThan, Condition) \ |
| 1052 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1053 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1054 | M(InstanceFieldGet, Instruction) \ |
| 1055 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1056 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1057 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1058 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1059 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1060 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1061 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1062 | M(LessThan, Condition) \ |
| 1063 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1064 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1065 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1066 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1067 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1068 | M(Local, Instruction) \ |
| 1069 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1070 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1071 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1072 | M(Mul, BinaryOperation) \ |
| 1073 | M(Neg, UnaryOperation) \ |
| 1074 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1075 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1076 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1077 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1078 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1079 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1080 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1081 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1082 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1083 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1084 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1085 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1086 | M(Return, Instruction) \ |
| 1087 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1088 | M(Shl, BinaryOperation) \ |
| 1089 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1090 | M(StaticFieldGet, Instruction) \ |
| 1091 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1092 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1093 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1094 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1095 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1096 | M(StoreLocal, Instruction) \ |
| 1097 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1098 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1099 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1100 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1101 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1102 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1103 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1104 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1105 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1106 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1107 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1108 | #else |
| 1109 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1110 | M(ArmDexCacheArraysBase, Instruction) |
| 1111 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1112 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1113 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1114 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1115 | #else |
| 1116 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1117 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1118 | M(Arm64IntermediateAddress, Instruction) \ |
| 1119 | M(Arm64MultiplyAccumulate, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1120 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1121 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1122 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1123 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1124 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1125 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1126 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1127 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1128 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1129 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1130 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1131 | M(X86LoadFromConstantTable, Instruction) \ |
| 1132 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1133 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1134 | |
| 1135 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1136 | |
| 1137 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1138 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1139 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1140 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1141 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1142 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1143 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1144 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1145 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1146 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1147 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1148 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1149 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1150 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1151 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1152 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1153 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1154 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1155 | #undef FORWARD_DECLARATION |
| 1156 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1157 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1158 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1159 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1160 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1161 | H##type* As##type() OVERRIDE { return this; } \ |
| 1162 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1163 | return other->Is##type(); \ |
| 1164 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1165 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1166 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1167 | template <typename T> class HUseList; |
| 1168 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1169 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1170 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1171 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1172 | HUseListNode* GetPrevious() const { return prev_; } |
| 1173 | HUseListNode* GetNext() const { return next_; } |
| 1174 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1175 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1176 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1177 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1178 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1179 | HUseListNode(T user, size_t index) |
| 1180 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1181 | |
| 1182 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1183 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1184 | HUseListNode<T>* prev_; |
| 1185 | HUseListNode<T>* next_; |
| 1186 | |
| 1187 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1188 | |
| 1189 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1190 | }; |
| 1191 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1192 | template <typename T> |
| 1193 | class HUseList : public ValueObject { |
| 1194 | public: |
| 1195 | HUseList() : first_(nullptr) {} |
| 1196 | |
| 1197 | void Clear() { |
| 1198 | first_ = nullptr; |
| 1199 | } |
| 1200 | |
| 1201 | // Adds a new entry at the beginning of the use list and returns |
| 1202 | // the newly created node. |
| 1203 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1204 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1205 | if (IsEmpty()) { |
| 1206 | first_ = new_node; |
| 1207 | } else { |
| 1208 | first_->prev_ = new_node; |
| 1209 | new_node->next_ = first_; |
| 1210 | first_ = new_node; |
| 1211 | } |
| 1212 | return new_node; |
| 1213 | } |
| 1214 | |
| 1215 | HUseListNode<T>* GetFirst() const { |
| 1216 | return first_; |
| 1217 | } |
| 1218 | |
| 1219 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1220 | DCHECK(node != nullptr); |
| 1221 | DCHECK(Contains(node)); |
| 1222 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1223 | if (node->prev_ != nullptr) { |
| 1224 | node->prev_->next_ = node->next_; |
| 1225 | } |
| 1226 | if (node->next_ != nullptr) { |
| 1227 | node->next_->prev_ = node->prev_; |
| 1228 | } |
| 1229 | if (node == first_) { |
| 1230 | first_ = node->next_; |
| 1231 | } |
| 1232 | } |
| 1233 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1234 | bool Contains(const HUseListNode<T>* node) const { |
| 1235 | if (node == nullptr) { |
| 1236 | return false; |
| 1237 | } |
| 1238 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1239 | if (current == node) { |
| 1240 | return true; |
| 1241 | } |
| 1242 | } |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1246 | bool IsEmpty() const { |
| 1247 | return first_ == nullptr; |
| 1248 | } |
| 1249 | |
| 1250 | bool HasOnlyOneUse() const { |
| 1251 | return first_ != nullptr && first_->next_ == nullptr; |
| 1252 | } |
| 1253 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1254 | size_t SizeSlow() const { |
| 1255 | size_t count = 0; |
| 1256 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1257 | ++count; |
| 1258 | } |
| 1259 | return count; |
| 1260 | } |
| 1261 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1262 | private: |
| 1263 | HUseListNode<T>* first_; |
| 1264 | }; |
| 1265 | |
| 1266 | template<typename T> |
| 1267 | class HUseIterator : public ValueObject { |
| 1268 | public: |
| 1269 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1270 | |
| 1271 | bool Done() const { return current_ == nullptr; } |
| 1272 | |
| 1273 | void Advance() { |
| 1274 | DCHECK(!Done()); |
| 1275 | current_ = current_->GetNext(); |
| 1276 | } |
| 1277 | |
| 1278 | HUseListNode<T>* Current() const { |
| 1279 | DCHECK(!Done()); |
| 1280 | return current_; |
| 1281 | } |
| 1282 | |
| 1283 | private: |
| 1284 | HUseListNode<T>* current_; |
| 1285 | |
| 1286 | friend class HValue; |
| 1287 | }; |
| 1288 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1289 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1290 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1291 | // by the used instructions. |
| 1292 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1293 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1294 | public: |
| 1295 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1296 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1297 | |
| 1298 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1299 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1300 | DCHECK(instruction_ != nullptr); |
| 1301 | DCHECK(use_node_ != nullptr); |
| 1302 | DCHECK(old_record.use_node_ == nullptr); |
| 1303 | } |
| 1304 | |
| 1305 | HInstruction* GetInstruction() const { return instruction_; } |
| 1306 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1307 | |
| 1308 | private: |
| 1309 | // Instruction used by the user. |
| 1310 | HInstruction* instruction_; |
| 1311 | |
| 1312 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1313 | HUseListNode<T>* use_node_; |
| 1314 | }; |
| 1315 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1316 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1317 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1318 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1319 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1320 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1321 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1322 | * modify the value of a reference field read [although it may modify the |
| 1323 | * reference fetch prior to reading the field, which is represented by its own |
| 1324 | * write/read dependence]). The analysis makes conservative points-to |
| 1325 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1326 | * the same, and any reference read depends on any reference read without |
| 1327 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1328 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1329 | * The internal representation uses 38-bit and is described in the table below. |
| 1330 | * The first line indicates the side effect, and for field/array accesses the |
| 1331 | * second line indicates the type of the access (in the order of the |
| 1332 | * Primitive::Type enum). |
| 1333 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1334 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1335 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1336 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1337 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1338 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1339 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1340 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1341 | * |
| 1342 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1343 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1344 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1345 | class SideEffects : public ValueObject { |
| 1346 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1347 | SideEffects() : flags_(0) {} |
| 1348 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1349 | static SideEffects None() { |
| 1350 | return SideEffects(0); |
| 1351 | } |
| 1352 | |
| 1353 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1354 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1355 | } |
| 1356 | |
| 1357 | static SideEffects AllChanges() { |
| 1358 | return SideEffects(kAllChangeBits); |
| 1359 | } |
| 1360 | |
| 1361 | static SideEffects AllDependencies() { |
| 1362 | return SideEffects(kAllDependOnBits); |
| 1363 | } |
| 1364 | |
| 1365 | static SideEffects AllExceptGCDependency() { |
| 1366 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1367 | } |
| 1368 | |
| 1369 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1370 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1371 | } |
| 1372 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1373 | static SideEffects AllWrites() { |
| 1374 | return SideEffects(kAllWrites); |
| 1375 | } |
| 1376 | |
| 1377 | static SideEffects AllReads() { |
| 1378 | return SideEffects(kAllReads); |
| 1379 | } |
| 1380 | |
| 1381 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1382 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1383 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1384 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1387 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1388 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1389 | } |
| 1390 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1391 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1392 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1393 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1394 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1398 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1399 | } |
| 1400 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1401 | static SideEffects CanTriggerGC() { |
| 1402 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1403 | } |
| 1404 | |
| 1405 | static SideEffects DependsOnGC() { |
| 1406 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1407 | } |
| 1408 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1409 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1410 | SideEffects Union(SideEffects other) const { |
| 1411 | return SideEffects(flags_ | other.flags_); |
| 1412 | } |
| 1413 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1414 | SideEffects Exclusion(SideEffects other) const { |
| 1415 | return SideEffects(flags_ & ~other.flags_); |
| 1416 | } |
| 1417 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1418 | void Add(SideEffects other) { |
| 1419 | flags_ |= other.flags_; |
| 1420 | } |
| 1421 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1422 | bool Includes(SideEffects other) const { |
| 1423 | return (other.flags_ & flags_) == other.flags_; |
| 1424 | } |
| 1425 | |
| 1426 | bool HasSideEffects() const { |
| 1427 | return (flags_ & kAllChangeBits); |
| 1428 | } |
| 1429 | |
| 1430 | bool HasDependencies() const { |
| 1431 | return (flags_ & kAllDependOnBits); |
| 1432 | } |
| 1433 | |
| 1434 | // Returns true if there are no side effects or dependencies. |
| 1435 | bool DoesNothing() const { |
| 1436 | return flags_ == 0; |
| 1437 | } |
| 1438 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1439 | // Returns true if something is written. |
| 1440 | bool DoesAnyWrite() const { |
| 1441 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1442 | } |
| 1443 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1444 | // Returns true if something is read. |
| 1445 | bool DoesAnyRead() const { |
| 1446 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1447 | } |
| 1448 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1449 | // Returns true if potentially everything is written and read |
| 1450 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1451 | bool DoesAllReadWrite() const { |
| 1452 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1453 | } |
| 1454 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1455 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1456 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1459 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1460 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1461 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1462 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1466 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1467 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1468 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1469 | for (int s = kLastBit; s >= 0; s--) { |
| 1470 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1471 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1472 | // This is a bit for the GC side effect. |
| 1473 | if (current_bit_is_set) { |
| 1474 | flags += "GC"; |
| 1475 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1476 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1477 | } else { |
| 1478 | // This is a bit for the array/field analysis. |
| 1479 | // The underscore character stands for the 'can trigger GC' bit. |
| 1480 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1481 | if (current_bit_is_set) { |
| 1482 | flags += kDebug[s]; |
| 1483 | } |
| 1484 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1485 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1486 | flags += "|"; |
| 1487 | } |
| 1488 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1489 | } |
| 1490 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1491 | } |
| 1492 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1493 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1494 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1495 | private: |
| 1496 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1497 | |
| 1498 | static constexpr int kFieldWriteOffset = 0; |
| 1499 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1500 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1501 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1502 | |
| 1503 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1504 | |
| 1505 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1506 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1507 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1508 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1509 | |
| 1510 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1511 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1512 | |
| 1513 | // Aliases. |
| 1514 | |
| 1515 | static_assert(kChangeBits == kDependOnBits, |
| 1516 | "the 'change' bits should match the 'depend on' bits."); |
| 1517 | |
| 1518 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1519 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1520 | static constexpr uint64_t kAllWrites = |
| 1521 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1522 | static constexpr uint64_t kAllReads = |
| 1523 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1524 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1525 | // Work around the fact that HIR aliases I/F and J/D. |
| 1526 | // TODO: remove this interceptor once HIR types are clean |
| 1527 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1528 | switch (type) { |
| 1529 | case Primitive::kPrimInt: |
| 1530 | case Primitive::kPrimFloat: |
| 1531 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1532 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1533 | case Primitive::kPrimLong: |
| 1534 | case Primitive::kPrimDouble: |
| 1535 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1536 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1537 | default: |
| 1538 | return TypeFlag(type, offset); |
| 1539 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1542 | // Translates type to bit flag. |
| 1543 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1544 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1545 | const uint64_t one = 1; |
| 1546 | const int shift = type; // 0-based consecutive enum |
| 1547 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1548 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1549 | return one << (type + offset); |
| 1550 | } |
| 1551 | |
| 1552 | // Private constructor on direct flags value. |
| 1553 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1554 | |
| 1555 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1556 | }; |
| 1557 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1558 | // 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] | 1559 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1560 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1561 | HEnvironment(ArenaAllocator* arena, |
| 1562 | size_t number_of_vregs, |
| 1563 | const DexFile& dex_file, |
| 1564 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1565 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1566 | InvokeType invoke_type, |
| 1567 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1568 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1569 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1570 | parent_(nullptr), |
| 1571 | dex_file_(dex_file), |
| 1572 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1573 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1574 | invoke_type_(invoke_type), |
| 1575 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1578 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1579 | : HEnvironment(arena, |
| 1580 | to_copy.Size(), |
| 1581 | to_copy.GetDexFile(), |
| 1582 | to_copy.GetMethodIdx(), |
| 1583 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1584 | to_copy.GetInvokeType(), |
| 1585 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1586 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1587 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1588 | if (parent_ != nullptr) { |
| 1589 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1590 | } else { |
| 1591 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1592 | parent_->CopyFrom(parent); |
| 1593 | if (parent->GetParent() != nullptr) { |
| 1594 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1595 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1596 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1599 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1600 | void CopyFrom(HEnvironment* environment); |
| 1601 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1602 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1603 | // input to the loop phi instead. This is for inserting instructions that |
| 1604 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1605 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1606 | |
| 1607 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1608 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1612 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1615 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1616 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1617 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1618 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1619 | HEnvironment* GetParent() const { return parent_; } |
| 1620 | |
| 1621 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1622 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1626 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | uint32_t GetDexPc() const { |
| 1630 | return dex_pc_; |
| 1631 | } |
| 1632 | |
| 1633 | uint32_t GetMethodIdx() const { |
| 1634 | return method_idx_; |
| 1635 | } |
| 1636 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1637 | InvokeType GetInvokeType() const { |
| 1638 | return invoke_type_; |
| 1639 | } |
| 1640 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1641 | const DexFile& GetDexFile() const { |
| 1642 | return dex_file_; |
| 1643 | } |
| 1644 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1645 | HInstruction* GetHolder() const { |
| 1646 | return holder_; |
| 1647 | } |
| 1648 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1649 | |
| 1650 | bool IsFromInlinedInvoke() const { |
| 1651 | return GetParent() != nullptr; |
| 1652 | } |
| 1653 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1654 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1655 | // Record instructions' use entries of this environment for constant-time removal. |
| 1656 | // It should only be called by HInstruction when a new environment use is added. |
| 1657 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1658 | DCHECK(env_use->GetUser() == this); |
| 1659 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1660 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1661 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1662 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1663 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1664 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1665 | HEnvironment* parent_; |
| 1666 | const DexFile& dex_file_; |
| 1667 | const uint32_t method_idx_; |
| 1668 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1669 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1670 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1671 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1672 | HInstruction* const holder_; |
| 1673 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1674 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1675 | |
| 1676 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1677 | }; |
| 1678 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1679 | class ReferenceTypeInfo : ValueObject { |
| 1680 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1681 | typedef Handle<mirror::Class> TypeHandle; |
| 1682 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1683 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1684 | // The constructor will check that the type_handle is valid. |
| 1685 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1688 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1689 | |
| 1690 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1691 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1694 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1695 | return IsValidHandle(type_handle_); |
| 1696 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1697 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1698 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1699 | |
| 1700 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1701 | DCHECK(IsValid()); |
| 1702 | return GetTypeHandle()->IsObjectClass(); |
| 1703 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1704 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1705 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1706 | DCHECK(IsValid()); |
| 1707 | return GetTypeHandle()->IsStringClass(); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1710 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1711 | DCHECK(IsValid()); |
| 1712 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 1713 | } |
| 1714 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1715 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1716 | DCHECK(IsValid()); |
| 1717 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1718 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1719 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1720 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1721 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1722 | return GetTypeHandle()->IsArrayClass(); |
| 1723 | } |
| 1724 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1725 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1726 | DCHECK(IsValid()); |
| 1727 | return GetTypeHandle()->IsPrimitiveArray(); |
| 1728 | } |
| 1729 | |
| 1730 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1731 | DCHECK(IsValid()); |
| 1732 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 1733 | } |
| 1734 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1735 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1736 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1737 | if (!IsExact()) return false; |
| 1738 | if (!IsArrayClass()) return false; |
| 1739 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1740 | } |
| 1741 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1742 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1743 | DCHECK(IsValid()); |
| 1744 | if (!IsExact()) return false; |
| 1745 | if (!IsArrayClass()) return false; |
| 1746 | if (!rti.IsArrayClass()) return false; |
| 1747 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 1748 | rti.GetTypeHandle()->GetComponentType()); |
| 1749 | } |
| 1750 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1751 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1752 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1753 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1754 | DCHECK(IsValid()); |
| 1755 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1756 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1757 | } |
| 1758 | |
Calin Juravle | cdfed3d | 2015-10-26 14:05:01 +0000 | [diff] [blame] | 1759 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1760 | DCHECK(IsValid()); |
| 1761 | DCHECK(rti.IsValid()); |
| 1762 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 1763 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1764 | } |
| 1765 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1766 | // Returns true if the type information provide the same amount of details. |
| 1767 | // 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] | 1768 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1769 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1770 | if (!IsValid() && !rti.IsValid()) { |
| 1771 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1772 | return true; |
| 1773 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1774 | if (!IsValid() || !rti.IsValid()) { |
| 1775 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1776 | return false; |
| 1777 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1778 | return IsExact() == rti.IsExact() |
| 1779 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1783 | ReferenceTypeInfo(); |
| 1784 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1785 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1786 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1787 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1788 | // 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] | 1789 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1790 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1791 | }; |
| 1792 | |
| 1793 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1794 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1795 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1796 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1797 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1798 | : previous_(nullptr), |
| 1799 | next_(nullptr), |
| 1800 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1801 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1802 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1803 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1804 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1805 | locations_(nullptr), |
| 1806 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1807 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1808 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1809 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1810 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1811 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1812 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1813 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1814 | enum InstructionKind { |
| 1815 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1816 | }; |
| 1817 | #undef DECLARE_KIND |
| 1818 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1819 | HInstruction* GetNext() const { return next_; } |
| 1820 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1821 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1822 | HInstruction* GetNextDisregardingMoves() const; |
| 1823 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1824 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1825 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1826 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1827 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1828 | bool IsInBlock() const { return block_ != nullptr; } |
| 1829 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1830 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1831 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1832 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1833 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1834 | |
| 1835 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1836 | virtual const char* DebugName() const = 0; |
| 1837 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1838 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1839 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1840 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1841 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1842 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1843 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1844 | |
| 1845 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1846 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1847 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1848 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1849 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1850 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1851 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1852 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1853 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1854 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1855 | // Does not apply for all instructions, but having this at top level greatly |
| 1856 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1857 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1858 | virtual bool CanBeNull() const { |
| 1859 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1860 | return true; |
| 1861 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1862 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1863 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1864 | return false; |
| 1865 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1866 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1867 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1868 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1869 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1870 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1871 | return reference_type_info_; |
| 1872 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1873 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1874 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1875 | DCHECK(user != nullptr); |
| 1876 | HUseListNode<HInstruction*>* use = |
| 1877 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1878 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1881 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1882 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1883 | HUseListNode<HEnvironment*>* env_use = |
| 1884 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1885 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1886 | } |
| 1887 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1888 | void RemoveAsUserOfInput(size_t input) { |
| 1889 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1890 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1891 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1892 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1893 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1894 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1895 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1896 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1897 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1898 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1899 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1900 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1901 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1902 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1903 | // Does this instruction strictly dominate `other_instruction`? |
| 1904 | // Returns false if this instruction and `other_instruction` are the same. |
| 1905 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1906 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1907 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1908 | int GetId() const { return id_; } |
| 1909 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1910 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1911 | int GetSsaIndex() const { return ssa_index_; } |
| 1912 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1913 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1914 | |
| 1915 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1916 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1917 | // Set the `environment_` field. Raw because this method does not |
| 1918 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1919 | void SetRawEnvironment(HEnvironment* environment) { |
| 1920 | DCHECK(environment_ == nullptr); |
| 1921 | DCHECK_EQ(environment->GetHolder(), this); |
| 1922 | environment_ = environment; |
| 1923 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1924 | |
| 1925 | // Set the environment of this instruction, copying it from `environment`. While |
| 1926 | // copying, the uses lists are being updated. |
| 1927 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1928 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1929 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1930 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1931 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1932 | if (environment->GetParent() != nullptr) { |
| 1933 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1934 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1935 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1936 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1937 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1938 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1939 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1940 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1941 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1942 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1943 | if (environment->GetParent() != nullptr) { |
| 1944 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1945 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1946 | } |
| 1947 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1948 | // Returns the number of entries in the environment. Typically, that is the |
| 1949 | // number of dex registers in a method. It could be more in case of inlining. |
| 1950 | size_t EnvironmentSize() const; |
| 1951 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1952 | LocationSummary* GetLocations() const { return locations_; } |
| 1953 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1954 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1955 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1956 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1957 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1958 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1959 | // uses of this instruction by `other` are *not* updated. |
| 1960 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1961 | ReplaceWith(other); |
| 1962 | other->ReplaceInput(this, use_index); |
| 1963 | } |
| 1964 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1965 | // Move `this` instruction before `cursor`. |
| 1966 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1967 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 1968 | // Move `this` before its first user and out of any loops. If there is no |
| 1969 | // out-of-loop user that dominates all other users, move the instruction |
| 1970 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 1971 | // |
| 1972 | // This can be used only on non-throwing instructions with no side effects that |
| 1973 | // have at least one use but no environment uses. |
| 1974 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 1975 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1976 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1977 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1978 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1979 | virtual H##type* As##type() { return nullptr; } |
| 1980 | |
| 1981 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1982 | #undef INSTRUCTION_TYPE_CHECK |
| 1983 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1984 | // Returns whether the instruction can be moved within the graph. |
| 1985 | virtual bool CanBeMoved() const { return false; } |
| 1986 | |
| 1987 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1988 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1989 | return false; |
| 1990 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1991 | |
| 1992 | // Returns whether any data encoded in the two instructions is equal. |
| 1993 | // This method does not look at the inputs. Both instructions must be |
| 1994 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1995 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1996 | return false; |
| 1997 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1998 | |
| 1999 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2000 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2001 | // 2) Their inputs are identical. |
| 2002 | bool Equals(HInstruction* other) const; |
| 2003 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2004 | virtual InstructionKind GetKind() const = 0; |
| 2005 | |
| 2006 | virtual size_t ComputeHashCode() const { |
| 2007 | size_t result = GetKind(); |
| 2008 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2009 | result = (result * 31) + InputAt(i)->GetId(); |
| 2010 | } |
| 2011 | return result; |
| 2012 | } |
| 2013 | |
| 2014 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2015 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2016 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2017 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2018 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2019 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2020 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2021 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2022 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2023 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2024 | |
| 2025 | // Returns whether the code generation of the instruction will require to have access |
| 2026 | // to the current method. Such instructions are: |
| 2027 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2028 | // to walk the stack and have the current method stored at a specific stack address. |
| 2029 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2030 | // fields of the current method. |
| 2031 | bool NeedsCurrentMethod() const { |
| 2032 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2033 | } |
| 2034 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2035 | // Returns whether the code generation of the instruction will require to have access |
| 2036 | // to the dex cache of the current method's declaring class via the current method. |
| 2037 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2038 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2039 | // Does this instruction have any use in an environment before |
| 2040 | // control flow hits 'other'? |
| 2041 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2042 | |
| 2043 | // Remove all references to environment uses of this instruction. |
| 2044 | // The caller must ensure that this is safe to do. |
| 2045 | void RemoveEnvironmentUsers(); |
| 2046 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2047 | protected: |
| 2048 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2049 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2050 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2051 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2052 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2053 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2054 | HInstruction* previous_; |
| 2055 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2056 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2057 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2058 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2059 | // An instruction gets an id when it is added to the graph. |
| 2060 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2061 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2062 | int id_; |
| 2063 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2064 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2065 | int ssa_index_; |
| 2066 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2067 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2068 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2069 | |
| 2070 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2071 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2072 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2073 | // The environment associated with this instruction. Not null if the instruction |
| 2074 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2075 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2076 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2077 | // Set by the code generator. |
| 2078 | LocationSummary* locations_; |
| 2079 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2080 | // Set by the liveness analysis. |
| 2081 | LiveInterval* live_interval_; |
| 2082 | |
| 2083 | // Set by the liveness analysis, this is the position in a linear |
| 2084 | // order of blocks where this instruction's live interval start. |
| 2085 | size_t lifetime_position_; |
| 2086 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2087 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2088 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2089 | // TODO: for primitive types this should be marked as invalid. |
| 2090 | ReferenceTypeInfo reference_type_info_; |
| 2091 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2092 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2093 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2094 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2095 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2096 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2097 | |
| 2098 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2099 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2100 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2101 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2102 | class HInputIterator : public ValueObject { |
| 2103 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2104 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2105 | |
| 2106 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2107 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2108 | void Advance() { index_++; } |
| 2109 | |
| 2110 | private: |
| 2111 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2112 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2113 | |
| 2114 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2115 | }; |
| 2116 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2117 | class HInstructionIterator : public ValueObject { |
| 2118 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2119 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2120 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2121 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2122 | } |
| 2123 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2124 | bool Done() const { return instruction_ == nullptr; } |
| 2125 | HInstruction* Current() const { return instruction_; } |
| 2126 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2127 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2128 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | private: |
| 2132 | HInstruction* instruction_; |
| 2133 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2134 | |
| 2135 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2136 | }; |
| 2137 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2138 | class HBackwardInstructionIterator : public ValueObject { |
| 2139 | public: |
| 2140 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2141 | : instruction_(instructions.last_instruction_) { |
| 2142 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2143 | } |
| 2144 | |
| 2145 | bool Done() const { return instruction_ == nullptr; } |
| 2146 | HInstruction* Current() const { return instruction_; } |
| 2147 | void Advance() { |
| 2148 | instruction_ = next_; |
| 2149 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2150 | } |
| 2151 | |
| 2152 | private: |
| 2153 | HInstruction* instruction_; |
| 2154 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2155 | |
| 2156 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2157 | }; |
| 2158 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2159 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2160 | class HTemplateInstruction: public HInstruction { |
| 2161 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2162 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2163 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2164 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2165 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2166 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2167 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2168 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2169 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2170 | DCHECK_LT(i, N); |
| 2171 | return inputs_[i]; |
| 2172 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2173 | |
| 2174 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2175 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2176 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2177 | } |
| 2178 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2179 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2180 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2181 | |
| 2182 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2183 | }; |
| 2184 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2185 | // HTemplateInstruction specialization for N=0. |
| 2186 | template<> |
| 2187 | class HTemplateInstruction<0>: public HInstruction { |
| 2188 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2189 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2190 | : HInstruction(side_effects, dex_pc) {} |
| 2191 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2192 | virtual ~HTemplateInstruction() {} |
| 2193 | |
| 2194 | size_t InputCount() const OVERRIDE { return 0; } |
| 2195 | |
| 2196 | protected: |
| 2197 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2198 | LOG(FATAL) << "Unreachable"; |
| 2199 | UNREACHABLE(); |
| 2200 | } |
| 2201 | |
| 2202 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2203 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2204 | LOG(FATAL) << "Unreachable"; |
| 2205 | UNREACHABLE(); |
| 2206 | } |
| 2207 | |
| 2208 | private: |
| 2209 | friend class SsaBuilder; |
| 2210 | }; |
| 2211 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2212 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2213 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2214 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2215 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2216 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2217 | virtual ~HExpression() {} |
| 2218 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2219 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2220 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2221 | protected: |
| 2222 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2223 | }; |
| 2224 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2225 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2226 | // instruction that branches to the exit block. |
| 2227 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2228 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2229 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2230 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2231 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2232 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2233 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2234 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2235 | |
| 2236 | private: |
| 2237 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2238 | }; |
| 2239 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2240 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2241 | // instruction that branches to the exit block. |
| 2242 | class HReturn : public HTemplateInstruction<1> { |
| 2243 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2244 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2245 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2246 | SetRawInputAt(0, value); |
| 2247 | } |
| 2248 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2249 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2250 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2251 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2252 | |
| 2253 | private: |
| 2254 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2255 | }; |
| 2256 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2257 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2258 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2259 | // exit block. |
| 2260 | class HExit : public HTemplateInstruction<0> { |
| 2261 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2262 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2263 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2264 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2265 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2266 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2267 | |
| 2268 | private: |
| 2269 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2270 | }; |
| 2271 | |
| 2272 | // Jumps from one block to another. |
| 2273 | class HGoto : public HTemplateInstruction<0> { |
| 2274 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2275 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2276 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2277 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2278 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2279 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2280 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2283 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2284 | |
| 2285 | private: |
| 2286 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2287 | }; |
| 2288 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2289 | class HConstant : public HExpression<0> { |
| 2290 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2291 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2292 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2293 | |
| 2294 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2295 | |
| 2296 | virtual bool IsMinusOne() const { return false; } |
| 2297 | virtual bool IsZero() const { return false; } |
| 2298 | virtual bool IsOne() const { return false; } |
| 2299 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2300 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2301 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2302 | DECLARE_INSTRUCTION(Constant); |
| 2303 | |
| 2304 | private: |
| 2305 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2306 | }; |
| 2307 | |
| 2308 | class HNullConstant : public HConstant { |
| 2309 | public: |
| 2310 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2311 | return true; |
| 2312 | } |
| 2313 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2314 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2315 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2316 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2317 | |
| 2318 | DECLARE_INSTRUCTION(NullConstant); |
| 2319 | |
| 2320 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2321 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2322 | |
| 2323 | friend class HGraph; |
| 2324 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2325 | }; |
| 2326 | |
| 2327 | // Constants of the type int. Those can be from Dex instructions, or |
| 2328 | // synthesized (for example with the if-eqz instruction). |
| 2329 | class HIntConstant : public HConstant { |
| 2330 | public: |
| 2331 | int32_t GetValue() const { return value_; } |
| 2332 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2333 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2334 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2335 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2336 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2337 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2338 | DCHECK(other->IsIntConstant()); |
| 2339 | return other->AsIntConstant()->value_ == value_; |
| 2340 | } |
| 2341 | |
| 2342 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2343 | |
| 2344 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2345 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2346 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2347 | |
| 2348 | DECLARE_INSTRUCTION(IntConstant); |
| 2349 | |
| 2350 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2351 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2352 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2353 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2354 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2355 | |
| 2356 | const int32_t value_; |
| 2357 | |
| 2358 | friend class HGraph; |
| 2359 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2360 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2361 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2362 | }; |
| 2363 | |
| 2364 | class HLongConstant : public HConstant { |
| 2365 | public: |
| 2366 | int64_t GetValue() const { return value_; } |
| 2367 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2368 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2369 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2370 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2371 | DCHECK(other->IsLongConstant()); |
| 2372 | return other->AsLongConstant()->value_ == value_; |
| 2373 | } |
| 2374 | |
| 2375 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2376 | |
| 2377 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2378 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2379 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2380 | |
| 2381 | DECLARE_INSTRUCTION(LongConstant); |
| 2382 | |
| 2383 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2384 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2385 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2386 | |
| 2387 | const int64_t value_; |
| 2388 | |
| 2389 | friend class HGraph; |
| 2390 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2391 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2392 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2393 | // Conditional branch. A block ending with an HIf instruction must have |
| 2394 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2395 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2396 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2397 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2398 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2399 | SetRawInputAt(0, input); |
| 2400 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2401 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2402 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2403 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2404 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2405 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2409 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2410 | } |
| 2411 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2412 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2413 | |
| 2414 | private: |
| 2415 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2416 | }; |
| 2417 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2418 | |
| 2419 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2420 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2421 | // non-exceptional control flow. |
| 2422 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2423 | // higher indices in no particular order. |
| 2424 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2425 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2426 | enum BoundaryKind { |
| 2427 | kEntry, |
| 2428 | kExit, |
| 2429 | }; |
| 2430 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2431 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2432 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2433 | |
| 2434 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2435 | |
| 2436 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2437 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2438 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2439 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2440 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2441 | } |
| 2442 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2443 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2444 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2445 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2446 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2447 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | // If not present already, adds `handler` to its block's list of exception |
| 2451 | // handlers. |
| 2452 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2453 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2454 | GetBlock()->AddSuccessor(handler); |
| 2455 | } |
| 2456 | } |
| 2457 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2458 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2459 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2460 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2461 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2462 | DECLARE_INSTRUCTION(TryBoundary); |
| 2463 | |
| 2464 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2465 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2466 | |
| 2467 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2468 | }; |
| 2469 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2470 | // Deoptimize to interpreter, upon checking a condition. |
| 2471 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2472 | public: |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame^] | 2473 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2474 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2475 | SetRawInputAt(0, cond); |
| 2476 | } |
| 2477 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame^] | 2478 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2479 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2480 | return true; |
| 2481 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2482 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2483 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2484 | |
| 2485 | DECLARE_INSTRUCTION(Deoptimize); |
| 2486 | |
| 2487 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2488 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2489 | }; |
| 2490 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2491 | // Represents the ArtMethod that was passed as a first argument to |
| 2492 | // the method. It is used by instructions that depend on it, like |
| 2493 | // instructions that work with the dex cache. |
| 2494 | class HCurrentMethod : public HExpression<0> { |
| 2495 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2496 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2497 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2498 | |
| 2499 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2500 | |
| 2501 | private: |
| 2502 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2503 | }; |
| 2504 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2505 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2506 | // have one successor for each entry in the switch table, and the final successor |
| 2507 | // will be the block containing the next Dex opcode. |
| 2508 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2509 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2510 | HPackedSwitch(int32_t start_value, |
| 2511 | uint32_t num_entries, |
| 2512 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2513 | uint32_t dex_pc = kNoDexPc) |
| 2514 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2515 | start_value_(start_value), |
| 2516 | num_entries_(num_entries) { |
| 2517 | SetRawInputAt(0, input); |
| 2518 | } |
| 2519 | |
| 2520 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2521 | |
| 2522 | int32_t GetStartValue() const { return start_value_; } |
| 2523 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2524 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2525 | |
| 2526 | HBasicBlock* GetDefaultBlock() const { |
| 2527 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2528 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2529 | } |
| 2530 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2531 | |
| 2532 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2533 | const int32_t start_value_; |
| 2534 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2535 | |
| 2536 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2537 | }; |
| 2538 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2539 | class HUnaryOperation : public HExpression<1> { |
| 2540 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2541 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2542 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2543 | SetRawInputAt(0, input); |
| 2544 | } |
| 2545 | |
| 2546 | HInstruction* GetInput() const { return InputAt(0); } |
| 2547 | Primitive::Type GetResultType() const { return GetType(); } |
| 2548 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2549 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2550 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2551 | return true; |
| 2552 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2553 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2554 | // Try to statically evaluate `operation` and return a HConstant |
| 2555 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2556 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2557 | HConstant* TryStaticEvaluation() const; |
| 2558 | |
| 2559 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2560 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2561 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2562 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2563 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2564 | |
| 2565 | private: |
| 2566 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2567 | }; |
| 2568 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2569 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2570 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2571 | HBinaryOperation(Primitive::Type result_type, |
| 2572 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2573 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2574 | SideEffects side_effects = SideEffects::None(), |
| 2575 | uint32_t dex_pc = kNoDexPc) |
| 2576 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2577 | SetRawInputAt(0, left); |
| 2578 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2579 | } |
| 2580 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2581 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2582 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2583 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2584 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2585 | virtual bool IsCommutative() const { return false; } |
| 2586 | |
| 2587 | // Put constant on the right. |
| 2588 | // Returns whether order is changed. |
| 2589 | bool OrderInputsWithConstantOnTheRight() { |
| 2590 | HInstruction* left = InputAt(0); |
| 2591 | HInstruction* right = InputAt(1); |
| 2592 | if (left->IsConstant() && !right->IsConstant()) { |
| 2593 | ReplaceInput(right, 0); |
| 2594 | ReplaceInput(left, 1); |
| 2595 | return true; |
| 2596 | } |
| 2597 | return false; |
| 2598 | } |
| 2599 | |
| 2600 | // Order inputs by instruction id, but favor constant on the right side. |
| 2601 | // This helps GVN for commutative ops. |
| 2602 | void OrderInputs() { |
| 2603 | DCHECK(IsCommutative()); |
| 2604 | HInstruction* left = InputAt(0); |
| 2605 | HInstruction* right = InputAt(1); |
| 2606 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2607 | return; |
| 2608 | } |
| 2609 | if (OrderInputsWithConstantOnTheRight()) { |
| 2610 | return; |
| 2611 | } |
| 2612 | // Order according to instruction id. |
| 2613 | if (left->GetId() > right->GetId()) { |
| 2614 | ReplaceInput(right, 0); |
| 2615 | ReplaceInput(left, 1); |
| 2616 | } |
| 2617 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2618 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2619 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2620 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2621 | return true; |
| 2622 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2623 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2624 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2625 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2626 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2627 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2628 | |
| 2629 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2630 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2631 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2632 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2633 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2634 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2635 | return nullptr; |
| 2636 | } |
| 2637 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2638 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2639 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2640 | return nullptr; |
| 2641 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2642 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2643 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| 2644 | VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; |
| 2645 | return nullptr; |
| 2646 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2647 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2648 | // 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] | 2649 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2650 | HConstant* GetConstantRight() const; |
| 2651 | |
| 2652 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2653 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2654 | HInstruction* GetLeastConstantLeft() const; |
| 2655 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2656 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2657 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2658 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2659 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2660 | }; |
| 2661 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2662 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2663 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2664 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2665 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2666 | kGtBias, // return 1 for NaN comparisons |
| 2667 | kLtBias, // return -1 for NaN comparisons |
| 2668 | }; |
| 2669 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2670 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2671 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2672 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2673 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2674 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2675 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2676 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2677 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2678 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2679 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2680 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2681 | // `instruction`, and disregard moves in between. |
| 2682 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2683 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2684 | DECLARE_INSTRUCTION(Condition); |
| 2685 | |
| 2686 | virtual IfCondition GetCondition() const = 0; |
| 2687 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2688 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2689 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2690 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2691 | |
| 2692 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2693 | |
| 2694 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2695 | return bias_ == other->AsCondition()->bias_; |
| 2696 | } |
| 2697 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2698 | bool IsFPConditionTrueIfNaN() const { |
| 2699 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2700 | IfCondition if_cond = GetCondition(); |
| 2701 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2702 | } |
| 2703 | |
| 2704 | bool IsFPConditionFalseIfNaN() const { |
| 2705 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2706 | IfCondition if_cond = GetCondition(); |
| 2707 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2708 | } |
| 2709 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2710 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2711 | // For register allocation purposes, returns whether this instruction needs to be |
| 2712 | // materialized (that is, not just be in the processor flags). |
| 2713 | bool needs_materialization_; |
| 2714 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2715 | // Needed if we merge a HCompare into a HCondition. |
| 2716 | ComparisonBias bias_; |
| 2717 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2718 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2719 | }; |
| 2720 | |
| 2721 | // Instruction to check if two inputs are equal to each other. |
| 2722 | class HEqual : public HCondition { |
| 2723 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2724 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2725 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2726 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2727 | bool IsCommutative() const OVERRIDE { return true; } |
| 2728 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2729 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2730 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2731 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2732 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2733 | HConstant* Evaluate(HLongConstant* x, HLongConstant* 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 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2737 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2738 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2739 | return GetBlock()->GetGraph()->GetIntConstant(1); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2740 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2741 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2742 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2743 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2744 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2745 | return kCondEQ; |
| 2746 | } |
| 2747 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2748 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2749 | return kCondNE; |
| 2750 | } |
| 2751 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2752 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2753 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2754 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2755 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2756 | }; |
| 2757 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2758 | class HNotEqual : public HCondition { |
| 2759 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2760 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2761 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2762 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2763 | bool IsCommutative() const OVERRIDE { return true; } |
| 2764 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2765 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2766 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2767 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2768 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2769 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2770 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2771 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2772 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2773 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2774 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2775 | return GetBlock()->GetGraph()->GetIntConstant(0); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2776 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2777 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2778 | DECLARE_INSTRUCTION(NotEqual); |
| 2779 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2780 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2781 | return kCondNE; |
| 2782 | } |
| 2783 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2784 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2785 | return kCondEQ; |
| 2786 | } |
| 2787 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2788 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2789 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2790 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2791 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2792 | }; |
| 2793 | |
| 2794 | class HLessThan : public HCondition { |
| 2795 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2796 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2797 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2798 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2799 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2800 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2801 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2802 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2803 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2804 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2805 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2806 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2807 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2808 | DECLARE_INSTRUCTION(LessThan); |
| 2809 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2810 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2811 | return kCondLT; |
| 2812 | } |
| 2813 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2814 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2815 | return kCondGE; |
| 2816 | } |
| 2817 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2818 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2819 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2820 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2821 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2822 | }; |
| 2823 | |
| 2824 | class HLessThanOrEqual : public HCondition { |
| 2825 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2826 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2827 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2828 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2829 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2830 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2831 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2832 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2833 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2834 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2835 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2836 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2837 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2838 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2839 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2840 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2841 | return kCondLE; |
| 2842 | } |
| 2843 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2844 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2845 | return kCondGT; |
| 2846 | } |
| 2847 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2848 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2849 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2850 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2851 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2852 | }; |
| 2853 | |
| 2854 | class HGreaterThan : public HCondition { |
| 2855 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2856 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2857 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2858 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2859 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2860 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2861 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2862 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2863 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2864 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2865 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2866 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2867 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2868 | DECLARE_INSTRUCTION(GreaterThan); |
| 2869 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2870 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2871 | return kCondGT; |
| 2872 | } |
| 2873 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2874 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2875 | return kCondLE; |
| 2876 | } |
| 2877 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2878 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2879 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2880 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2881 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2882 | }; |
| 2883 | |
| 2884 | class HGreaterThanOrEqual : public HCondition { |
| 2885 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2886 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2887 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2888 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2889 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2890 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2891 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2892 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2893 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2894 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2895 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2896 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2897 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2898 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2899 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2900 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2901 | return kCondGE; |
| 2902 | } |
| 2903 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2904 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2905 | return kCondLT; |
| 2906 | } |
| 2907 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2908 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2909 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2910 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2911 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2912 | }; |
| 2913 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2914 | class HBelow : public HCondition { |
| 2915 | public: |
| 2916 | HBelow(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(Below); |
| 2931 | |
| 2932 | IfCondition GetCondition() const OVERRIDE { |
| 2933 | return kCondB; |
| 2934 | } |
| 2935 | |
| 2936 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2937 | return kCondAE; |
| 2938 | } |
| 2939 | |
| 2940 | private: |
| 2941 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2942 | |
| 2943 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 2944 | }; |
| 2945 | |
| 2946 | class HBelowOrEqual : public HCondition { |
| 2947 | public: |
| 2948 | HBelowOrEqual(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(BelowOrEqual); |
| 2963 | |
| 2964 | IfCondition GetCondition() const OVERRIDE { |
| 2965 | return kCondBE; |
| 2966 | } |
| 2967 | |
| 2968 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2969 | return kCondA; |
| 2970 | } |
| 2971 | |
| 2972 | private: |
| 2973 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2974 | |
| 2975 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 2976 | }; |
| 2977 | |
| 2978 | class HAbove : public HCondition { |
| 2979 | public: |
| 2980 | HAbove(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(Above); |
| 2995 | |
| 2996 | IfCondition GetCondition() const OVERRIDE { |
| 2997 | return kCondA; |
| 2998 | } |
| 2999 | |
| 3000 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3001 | return kCondBE; |
| 3002 | } |
| 3003 | |
| 3004 | private: |
| 3005 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3006 | |
| 3007 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3008 | }; |
| 3009 | |
| 3010 | class HAboveOrEqual : public HCondition { |
| 3011 | public: |
| 3012 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3013 | : HCondition(first, second, dex_pc) {} |
| 3014 | |
| 3015 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3016 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3017 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3018 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3019 | } |
| 3020 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3021 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3022 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3023 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3024 | } |
| 3025 | |
| 3026 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3027 | |
| 3028 | IfCondition GetCondition() const OVERRIDE { |
| 3029 | return kCondAE; |
| 3030 | } |
| 3031 | |
| 3032 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3033 | return kCondB; |
| 3034 | } |
| 3035 | |
| 3036 | private: |
| 3037 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3038 | |
| 3039 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3040 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3041 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3042 | // Instruction to check how two inputs compare to each other. |
| 3043 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3044 | class HCompare : public HBinaryOperation { |
| 3045 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3046 | HCompare(Primitive::Type type, |
| 3047 | HInstruction* first, |
| 3048 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3049 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3050 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3051 | : HBinaryOperation(Primitive::kPrimInt, |
| 3052 | first, |
| 3053 | second, |
| 3054 | SideEffectsForArchRuntimeCalls(type), |
| 3055 | dex_pc), |
| 3056 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3057 | DCHECK_EQ(type, first->GetType()); |
| 3058 | DCHECK_EQ(type, second->GetType()); |
| 3059 | } |
| 3060 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3061 | template <typename T> |
| 3062 | 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] | 3063 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3064 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3065 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3066 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3067 | } |
| 3068 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3069 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3070 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3071 | } |
| 3072 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3073 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3074 | return bias_ == other->AsCompare()->bias_; |
| 3075 | } |
| 3076 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3077 | ComparisonBias GetBias() const { return bias_; } |
| 3078 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3079 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3080 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3081 | |
| 3082 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3083 | // MIPS64 uses a runtime call for FP comparisons. |
| 3084 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3085 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3086 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3087 | DECLARE_INSTRUCTION(Compare); |
| 3088 | |
| 3089 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3090 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3091 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3092 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3093 | }; |
| 3094 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3095 | // A local in the graph. Corresponds to a Dex register. |
| 3096 | class HLocal : public HTemplateInstruction<0> { |
| 3097 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3098 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3099 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3100 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3101 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3102 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3103 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3104 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3105 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3106 | // The Dex register number. |
| 3107 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3108 | |
| 3109 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3110 | }; |
| 3111 | |
| 3112 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3113 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3114 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3115 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3116 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3117 | SetRawInputAt(0, local); |
| 3118 | } |
| 3119 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3120 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3121 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3122 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3123 | |
| 3124 | private: |
| 3125 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3126 | }; |
| 3127 | |
| 3128 | // Store a value in a given local. This instruction has two inputs: the value |
| 3129 | // and the local. |
| 3130 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3131 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3132 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3133 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3134 | SetRawInputAt(0, local); |
| 3135 | SetRawInputAt(1, value); |
| 3136 | } |
| 3137 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3138 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3139 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3140 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3141 | |
| 3142 | private: |
| 3143 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3144 | }; |
| 3145 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3146 | class HFloatConstant : public HConstant { |
| 3147 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3148 | float GetValue() const { return value_; } |
| 3149 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3150 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3151 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3152 | } |
| 3153 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3154 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3155 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3156 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3157 | } |
| 3158 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3159 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3160 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3161 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3162 | 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] | 3163 | } |
| 3164 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3165 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3166 | } |
| 3167 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3168 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3169 | } |
| 3170 | bool IsNaN() const { |
| 3171 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3174 | DECLARE_INSTRUCTION(FloatConstant); |
| 3175 | |
| 3176 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3177 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3178 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3179 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3180 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3181 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3182 | const float value_; |
| 3183 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3184 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3185 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3186 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3187 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3188 | }; |
| 3189 | |
| 3190 | class HDoubleConstant : public HConstant { |
| 3191 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3192 | double GetValue() const { return value_; } |
| 3193 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3194 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3195 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3196 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3197 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3198 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3199 | } |
| 3200 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3201 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3202 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3203 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3204 | 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] | 3205 | } |
| 3206 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3207 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3208 | } |
| 3209 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3210 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3211 | } |
| 3212 | bool IsNaN() const { |
| 3213 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3216 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3217 | |
| 3218 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3219 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3220 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3221 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3222 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3223 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3224 | const double value_; |
| 3225 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3226 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3227 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3228 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3229 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3230 | }; |
| 3231 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3232 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3233 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3234 | #include "intrinsics_list.h" |
| 3235 | kNone, |
| 3236 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3237 | #undef INTRINSICS_LIST |
| 3238 | #undef OPTIMIZING_INTRINSICS |
| 3239 | }; |
| 3240 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3241 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3242 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3243 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3244 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3245 | }; |
| 3246 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3247 | class HInvoke : public HInstruction { |
| 3248 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3249 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3250 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3251 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3252 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3253 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3254 | SetRawInputAt(index, argument); |
| 3255 | } |
| 3256 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3257 | // Return the number of arguments. This number can be lower than |
| 3258 | // the number of inputs returned by InputCount(), as some invoke |
| 3259 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3260 | // inputs at the end of their list of inputs. |
| 3261 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3262 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3263 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3264 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3265 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3266 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3267 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3268 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3269 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3270 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3271 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3272 | return intrinsic_; |
| 3273 | } |
| 3274 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3275 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3276 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3277 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3278 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | bool CanThrow() const OVERRIDE { return true; } |
| 3282 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3283 | uint32_t* GetIntrinsicOptimizations() { |
| 3284 | return &intrinsic_optimizations_; |
| 3285 | } |
| 3286 | |
| 3287 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3288 | return &intrinsic_optimizations_; |
| 3289 | } |
| 3290 | |
| 3291 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3292 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3293 | DECLARE_INSTRUCTION(Invoke); |
| 3294 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3295 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3296 | HInvoke(ArenaAllocator* arena, |
| 3297 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3298 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3299 | Primitive::Type return_type, |
| 3300 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3301 | uint32_t dex_method_index, |
| 3302 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3303 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3304 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3305 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3306 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3307 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3308 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3309 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3310 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3311 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3312 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3313 | } |
| 3314 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3315 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3316 | return inputs_[index]; |
| 3317 | } |
| 3318 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3319 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3320 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3321 | } |
| 3322 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3323 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3324 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3325 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3326 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3327 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3328 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3329 | |
| 3330 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3331 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3332 | |
| 3333 | private: |
| 3334 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3335 | }; |
| 3336 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3337 | class HInvokeUnresolved : public HInvoke { |
| 3338 | public: |
| 3339 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3340 | uint32_t number_of_arguments, |
| 3341 | Primitive::Type return_type, |
| 3342 | uint32_t dex_pc, |
| 3343 | uint32_t dex_method_index, |
| 3344 | InvokeType invoke_type) |
| 3345 | : HInvoke(arena, |
| 3346 | number_of_arguments, |
| 3347 | 0u /* number_of_other_inputs */, |
| 3348 | return_type, |
| 3349 | dex_pc, |
| 3350 | dex_method_index, |
| 3351 | invoke_type) { |
| 3352 | } |
| 3353 | |
| 3354 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3355 | |
| 3356 | private: |
| 3357 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3358 | }; |
| 3359 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3360 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3361 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3362 | // Requirements of this method call regarding the class |
| 3363 | // initialization (clinit) check of its declaring class. |
| 3364 | enum class ClinitCheckRequirement { |
| 3365 | kNone, // Class already initialized. |
| 3366 | kExplicit, // Static call having explicit clinit check as last input. |
| 3367 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3368 | }; |
| 3369 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3370 | // Determines how to load the target ArtMethod*. |
| 3371 | enum class MethodLoadKind { |
| 3372 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3373 | kStringInit, |
| 3374 | |
| 3375 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3376 | kRecursive, |
| 3377 | |
| 3378 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3379 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3380 | kDirectAddress, |
| 3381 | |
| 3382 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3383 | // address in the 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 | kDirectAddressWithFixup, |
| 3387 | |
| 3388 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3389 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3390 | // may cause class initialization (the entry may point to a resolution method), |
| 3391 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3392 | kDexCachePcRelative, |
| 3393 | |
| 3394 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3395 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3396 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3397 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3398 | kDexCacheViaMethod, |
| 3399 | }; |
| 3400 | |
| 3401 | // Determines the location of the code pointer. |
| 3402 | enum class CodePtrLocation { |
| 3403 | // Recursive call, use local PC-relative call instruction. |
| 3404 | kCallSelf, |
| 3405 | |
| 3406 | // Use PC-relative call instruction patched at link time. |
| 3407 | // Used for calls within an oat file, boot->boot or app->app. |
| 3408 | kCallPCRelative, |
| 3409 | |
| 3410 | // Call to a known target address, embed the direct address in code. |
| 3411 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3412 | kCallDirect, |
| 3413 | |
| 3414 | // Call to a target address that will be known at link time, embed the direct |
| 3415 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3416 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3417 | // the image relocatable or not. |
| 3418 | kCallDirectWithFixup, |
| 3419 | |
| 3420 | // Use code pointer from the ArtMethod*. |
| 3421 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3422 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3423 | kCallArtMethod, |
| 3424 | }; |
| 3425 | |
| 3426 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3427 | MethodLoadKind method_load_kind; |
| 3428 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3429 | // The method load data holds |
| 3430 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3431 | // Note that there are multiple string init methods, each having its own offset. |
| 3432 | // - the method address for kDirectAddress |
| 3433 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3434 | uint64_t method_load_data; |
| 3435 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3436 | }; |
| 3437 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3438 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3439 | uint32_t number_of_arguments, |
| 3440 | Primitive::Type return_type, |
| 3441 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3442 | uint32_t method_index, |
| 3443 | MethodReference target_method, |
| 3444 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3445 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3446 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3447 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3448 | : HInvoke(arena, |
| 3449 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3450 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3451 | // potentially one other if the clinit check is explicit, and potentially |
| 3452 | // one other if the method is a string factory. |
| 3453 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3454 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3455 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3456 | return_type, |
| 3457 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3458 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3459 | original_invoke_type), |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3460 | optimized_invoke_type_(optimized_invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3461 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3462 | target_method_(target_method), |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3463 | dispatch_info_(dispatch_info) { } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3464 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3465 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3466 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3467 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3468 | |
| 3469 | // Using the current method is the default and once we find a better |
| 3470 | // method load kind, we should not go back to using the current method. |
| 3471 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3472 | |
| 3473 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3474 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3475 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3476 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3477 | dispatch_info_ = dispatch_info; |
| 3478 | } |
| 3479 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3480 | void AddSpecialInput(HInstruction* input) { |
| 3481 | // We allow only one special input. |
| 3482 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3483 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3484 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3485 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3486 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3487 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3488 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3489 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3490 | // TODO: for intrinsics we can generate implicit null checks. |
| 3491 | return false; |
| 3492 | } |
| 3493 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3494 | bool CanBeNull() const OVERRIDE { |
| 3495 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3496 | } |
| 3497 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3498 | // Get the index of the special input, if any. |
| 3499 | // |
| 3500 | // If the invoke IsStringInit(), it initially has a HFakeString special argument |
| 3501 | // which is removed by the instruction simplifier; if the invoke HasCurrentMethodInput(), |
| 3502 | // the "special input" is the current method pointer; otherwise there may be one |
| 3503 | // platform-specific special input, such as PC-relative addressing base. |
| 3504 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
| 3505 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3506 | InvokeType GetOptimizedInvokeType() const { return optimized_invoke_type_; } |
| 3507 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
| 3508 | optimized_invoke_type_ = invoke_type; |
| 3509 | } |
| 3510 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3511 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3512 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3513 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3514 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3515 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3516 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3517 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3518 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3519 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3520 | bool HasCurrentMethodInput() const { |
| 3521 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3522 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3523 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3524 | return true; |
| 3525 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3526 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3527 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3528 | return false; |
| 3529 | } |
| 3530 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3531 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3532 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3533 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3534 | |
| 3535 | int32_t GetStringInitOffset() const { |
| 3536 | DCHECK(IsStringInit()); |
| 3537 | return dispatch_info_.method_load_data; |
| 3538 | } |
| 3539 | |
| 3540 | uint64_t GetMethodAddress() const { |
| 3541 | DCHECK(HasMethodAddress()); |
| 3542 | return dispatch_info_.method_load_data; |
| 3543 | } |
| 3544 | |
| 3545 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3546 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3547 | return dispatch_info_.method_load_data; |
| 3548 | } |
| 3549 | |
| 3550 | uint64_t GetDirectCodePtr() const { |
| 3551 | DCHECK(HasDirectCodePtr()); |
| 3552 | return dispatch_info_.direct_code_ptr; |
| 3553 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3554 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3555 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3556 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3557 | // Is this instruction a call to a static method? |
| 3558 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3559 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3560 | } |
| 3561 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3562 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3563 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3564 | // instruction; only relevant for static calls with explicit clinit check. |
| 3565 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3566 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3567 | size_t last_input_index = InputCount() - 1; |
| 3568 | HInstruction* last_input = InputAt(last_input_index); |
| 3569 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3570 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3571 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3572 | inputs_.pop_back(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3573 | clinit_check_requirement_ = new_requirement; |
| 3574 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3575 | } |
| 3576 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3577 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3578 | if (!IsStringInit()) return false; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3579 | DCHECK(!HasCurrentMethodInput()); |
| 3580 | if (InputCount() == (number_of_arguments_)) return false; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3581 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3582 | } |
| 3583 | |
| 3584 | void RemoveFakeStringArgumentAsLastInput() { |
| 3585 | DCHECK(IsStringInit()); |
| 3586 | size_t last_input_index = InputCount() - 1; |
| 3587 | HInstruction* last_input = InputAt(last_input_index); |
| 3588 | DCHECK(last_input != nullptr); |
| 3589 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3590 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3591 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3592 | } |
| 3593 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3594 | // 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] | 3595 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3596 | bool IsStaticWithExplicitClinitCheck() const { |
| 3597 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3598 | } |
| 3599 | |
| 3600 | // Is this a call to a static method whose declaring class has an |
| 3601 | // implicit intialization check requirement? |
| 3602 | bool IsStaticWithImplicitClinitCheck() const { |
| 3603 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3604 | } |
| 3605 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3606 | // Does this method load kind need the current method as an input? |
| 3607 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 3608 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 3609 | } |
| 3610 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3611 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3612 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3613 | protected: |
| 3614 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3615 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3616 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3617 | HInstruction* input = input_record.GetInstruction(); |
| 3618 | // `input` is the last input of a static invoke marked as having |
| 3619 | // an explicit clinit check. It must either be: |
| 3620 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3621 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3622 | DCHECK(input != nullptr); |
| 3623 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3624 | } |
| 3625 | return input_record; |
| 3626 | } |
| 3627 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3628 | void InsertInputAt(size_t index, HInstruction* input); |
| 3629 | void RemoveInputAt(size_t index); |
| 3630 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3631 | private: |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3632 | InvokeType optimized_invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3633 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3634 | // The target method may refer to different dex file or method index than the original |
| 3635 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3636 | // in derived class to increase visibility. |
| 3637 | MethodReference target_method_; |
| 3638 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3639 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3640 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3641 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 3642 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3643 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3644 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3645 | class HInvokeVirtual : public HInvoke { |
| 3646 | public: |
| 3647 | HInvokeVirtual(ArenaAllocator* arena, |
| 3648 | uint32_t number_of_arguments, |
| 3649 | Primitive::Type return_type, |
| 3650 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3651 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3652 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3653 | : 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] | 3654 | vtable_index_(vtable_index) {} |
| 3655 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3656 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3657 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3658 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3659 | } |
| 3660 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3661 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3662 | |
| 3663 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3664 | |
| 3665 | private: |
| 3666 | const uint32_t vtable_index_; |
| 3667 | |
| 3668 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3669 | }; |
| 3670 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3671 | class HInvokeInterface : public HInvoke { |
| 3672 | public: |
| 3673 | HInvokeInterface(ArenaAllocator* arena, |
| 3674 | uint32_t number_of_arguments, |
| 3675 | Primitive::Type return_type, |
| 3676 | uint32_t dex_pc, |
| 3677 | uint32_t dex_method_index, |
| 3678 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3679 | : 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] | 3680 | imt_index_(imt_index) {} |
| 3681 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3682 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3683 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3684 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3685 | } |
| 3686 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3687 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3688 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3689 | |
| 3690 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3691 | |
| 3692 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3693 | const uint32_t imt_index_; |
| 3694 | |
| 3695 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3696 | }; |
| 3697 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3698 | class HNewInstance : public HExpression<2> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3699 | public: |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3700 | HNewInstance(HInstruction* cls, |
| 3701 | HCurrentMethod* current_method, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3702 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3703 | uint16_t type_index, |
| 3704 | const DexFile& dex_file, |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3705 | bool can_throw, |
| 3706 | bool finalizable, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3707 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3708 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3709 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3710 | dex_file_(dex_file), |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3711 | can_throw_(can_throw), |
| 3712 | finalizable_(finalizable), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3713 | entrypoint_(entrypoint) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3714 | SetRawInputAt(0, cls); |
| 3715 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3716 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3717 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3718 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3719 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3720 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3721 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3722 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3723 | |
| 3724 | // It may throw when called on type that's not instantiable/accessible. |
| 3725 | // It can throw OOME. |
| 3726 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
| 3727 | bool CanThrow() const OVERRIDE { return can_throw_ || true; } |
| 3728 | |
| 3729 | bool IsFinalizable() const { return finalizable_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3730 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3731 | bool CanBeNull() const OVERRIDE { return false; } |
| 3732 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3733 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3734 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3735 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3736 | entrypoint_ = entrypoint; |
| 3737 | } |
| 3738 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3739 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3740 | |
| 3741 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3742 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3743 | const DexFile& dex_file_; |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3744 | const bool can_throw_; |
| 3745 | const bool finalizable_; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3746 | QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3747 | |
| 3748 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3749 | }; |
| 3750 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3751 | class HNeg : public HUnaryOperation { |
| 3752 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3753 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3754 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3755 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3756 | template <typename T> T Compute(T x) const { return -x; } |
| 3757 | |
| 3758 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3759 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3760 | } |
| 3761 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3762 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3763 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3764 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3765 | DECLARE_INSTRUCTION(Neg); |
| 3766 | |
| 3767 | private: |
| 3768 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3769 | }; |
| 3770 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3771 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3772 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3773 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3774 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3775 | uint32_t dex_pc, |
| 3776 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3777 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3778 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3779 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3780 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3781 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3782 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3783 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3784 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3785 | } |
| 3786 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3787 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3788 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3789 | |
| 3790 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3791 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3792 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3793 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3794 | bool CanThrow() const OVERRIDE { return true; } |
| 3795 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3796 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3797 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3798 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3799 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3800 | DECLARE_INSTRUCTION(NewArray); |
| 3801 | |
| 3802 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3803 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3804 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3805 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3806 | |
| 3807 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3808 | }; |
| 3809 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3810 | class HAdd : public HBinaryOperation { |
| 3811 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3812 | HAdd(Primitive::Type result_type, |
| 3813 | HInstruction* left, |
| 3814 | HInstruction* right, |
| 3815 | uint32_t dex_pc = kNoDexPc) |
| 3816 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3817 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3818 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3819 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3820 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3821 | |
| 3822 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3823 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3824 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3825 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3826 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3827 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3828 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3829 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3830 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3831 | DECLARE_INSTRUCTION(Add); |
| 3832 | |
| 3833 | private: |
| 3834 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3835 | }; |
| 3836 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3837 | class HSub : public HBinaryOperation { |
| 3838 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3839 | HSub(Primitive::Type result_type, |
| 3840 | HInstruction* left, |
| 3841 | HInstruction* right, |
| 3842 | uint32_t dex_pc = kNoDexPc) |
| 3843 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3844 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3845 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3846 | |
| 3847 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3848 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3849 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3850 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3851 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3852 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3853 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3854 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3855 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3856 | DECLARE_INSTRUCTION(Sub); |
| 3857 | |
| 3858 | private: |
| 3859 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3860 | }; |
| 3861 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3862 | class HMul : public HBinaryOperation { |
| 3863 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3864 | HMul(Primitive::Type result_type, |
| 3865 | HInstruction* left, |
| 3866 | HInstruction* right, |
| 3867 | uint32_t dex_pc = kNoDexPc) |
| 3868 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3869 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3870 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3871 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3872 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3873 | |
| 3874 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3875 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3876 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3877 | } |
| 3878 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3879 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3880 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3881 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3882 | |
| 3883 | DECLARE_INSTRUCTION(Mul); |
| 3884 | |
| 3885 | private: |
| 3886 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3887 | }; |
| 3888 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3889 | class HDiv : public HBinaryOperation { |
| 3890 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3891 | HDiv(Primitive::Type result_type, |
| 3892 | HInstruction* left, |
| 3893 | HInstruction* right, |
| 3894 | uint32_t dex_pc) |
| 3895 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3896 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3897 | template <typename T> |
| 3898 | T Compute(T x, T y) const { |
| 3899 | // Our graph structure ensures we never have 0 for `y` during |
| 3900 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3901 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3902 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3903 | return (y == -1) ? -x : x / y; |
| 3904 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3905 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3906 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3907 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3908 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3909 | } |
| 3910 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3911 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3912 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3913 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3914 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3915 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3916 | // The generated code can use a runtime call. |
| 3917 | return SideEffects::CanTriggerGC(); |
| 3918 | } |
| 3919 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3920 | DECLARE_INSTRUCTION(Div); |
| 3921 | |
| 3922 | private: |
| 3923 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3924 | }; |
| 3925 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3926 | class HRem : public HBinaryOperation { |
| 3927 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3928 | HRem(Primitive::Type result_type, |
| 3929 | HInstruction* left, |
| 3930 | HInstruction* right, |
| 3931 | uint32_t dex_pc) |
| 3932 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3933 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3934 | template <typename T> |
| 3935 | T Compute(T x, T y) const { |
| 3936 | // Our graph structure ensures we never have 0 for `y` during |
| 3937 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3938 | DCHECK_NE(y, 0); |
| 3939 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3940 | return (y == -1) ? 0 : x % y; |
| 3941 | } |
| 3942 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3943 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3944 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3945 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3946 | } |
| 3947 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3948 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3949 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3950 | } |
| 3951 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3952 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3953 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3954 | return SideEffects::CanTriggerGC(); |
| 3955 | } |
| 3956 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3957 | DECLARE_INSTRUCTION(Rem); |
| 3958 | |
| 3959 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3960 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3961 | }; |
| 3962 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3963 | class HDivZeroCheck : public HExpression<1> { |
| 3964 | public: |
| 3965 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3966 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3967 | SetRawInputAt(0, value); |
| 3968 | } |
| 3969 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3970 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3971 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3972 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3973 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3974 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3975 | return true; |
| 3976 | } |
| 3977 | |
| 3978 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3979 | bool CanThrow() const OVERRIDE { return true; } |
| 3980 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3981 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3982 | |
| 3983 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3984 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3985 | }; |
| 3986 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3987 | class HShl : public HBinaryOperation { |
| 3988 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3989 | HShl(Primitive::Type result_type, |
| 3990 | HInstruction* left, |
| 3991 | HInstruction* right, |
| 3992 | uint32_t dex_pc = kNoDexPc) |
| 3993 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3994 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3995 | template <typename T, typename U, typename V> |
| 3996 | T Compute(T x, U y, V max_shift_value) const { |
| 3997 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3998 | "V is not the unsigned integer type corresponding to T"); |
| 3999 | return x << (y & max_shift_value); |
| 4000 | } |
| 4001 | |
| 4002 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4003 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4004 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4005 | } |
| 4006 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4007 | // case is handled as `x << static_cast<int>(y)`. |
| 4008 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4009 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4010 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4011 | } |
| 4012 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4013 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4014 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4015 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4016 | |
| 4017 | DECLARE_INSTRUCTION(Shl); |
| 4018 | |
| 4019 | private: |
| 4020 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4021 | }; |
| 4022 | |
| 4023 | class HShr : public HBinaryOperation { |
| 4024 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4025 | HShr(Primitive::Type result_type, |
| 4026 | HInstruction* left, |
| 4027 | HInstruction* right, |
| 4028 | uint32_t dex_pc = kNoDexPc) |
| 4029 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4030 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4031 | template <typename T, typename U, typename V> |
| 4032 | T Compute(T x, U y, V max_shift_value) const { |
| 4033 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4034 | "V is not the unsigned integer type corresponding to T"); |
| 4035 | return x >> (y & max_shift_value); |
| 4036 | } |
| 4037 | |
| 4038 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4039 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4040 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4041 | } |
| 4042 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4043 | // case is handled as `x >> static_cast<int>(y)`. |
| 4044 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4045 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4046 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4047 | } |
| 4048 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4049 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4050 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4051 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4052 | |
| 4053 | DECLARE_INSTRUCTION(Shr); |
| 4054 | |
| 4055 | private: |
| 4056 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4057 | }; |
| 4058 | |
| 4059 | class HUShr : public HBinaryOperation { |
| 4060 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4061 | HUShr(Primitive::Type result_type, |
| 4062 | HInstruction* left, |
| 4063 | HInstruction* right, |
| 4064 | uint32_t dex_pc = kNoDexPc) |
| 4065 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4066 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4067 | template <typename T, typename U, typename V> |
| 4068 | T Compute(T x, U y, V max_shift_value) const { |
| 4069 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4070 | "V is not the unsigned integer type corresponding to T"); |
| 4071 | V ux = static_cast<V>(x); |
| 4072 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4073 | } |
| 4074 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4075 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4076 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4077 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4078 | } |
| 4079 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4080 | // case is handled as `x >>> static_cast<int>(y)`. |
| 4081 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4082 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4083 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4084 | } |
| 4085 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4086 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4087 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | DECLARE_INSTRUCTION(UShr); |
| 4091 | |
| 4092 | private: |
| 4093 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4094 | }; |
| 4095 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4096 | class HAnd : public HBinaryOperation { |
| 4097 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4098 | HAnd(Primitive::Type result_type, |
| 4099 | HInstruction* left, |
| 4100 | HInstruction* right, |
| 4101 | uint32_t dex_pc = kNoDexPc) |
| 4102 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4103 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4104 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4105 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4106 | template <typename T, typename U> |
| 4107 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 4108 | |
| 4109 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4110 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4111 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4112 | } |
| 4113 | HConstant* Evaluate(HIntConstant* 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 | } |
| 4117 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4118 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4119 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4120 | } |
| 4121 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4122 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4123 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4124 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4125 | |
| 4126 | DECLARE_INSTRUCTION(And); |
| 4127 | |
| 4128 | private: |
| 4129 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4130 | }; |
| 4131 | |
| 4132 | class HOr : public HBinaryOperation { |
| 4133 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4134 | HOr(Primitive::Type result_type, |
| 4135 | HInstruction* left, |
| 4136 | HInstruction* right, |
| 4137 | uint32_t dex_pc = kNoDexPc) |
| 4138 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4139 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4140 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4141 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4142 | template <typename T, typename U> |
| 4143 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4144 | |
| 4145 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4146 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4147 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4148 | } |
| 4149 | HConstant* Evaluate(HIntConstant* 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 | } |
| 4153 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4154 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4155 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4156 | } |
| 4157 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4158 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4159 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4160 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4161 | |
| 4162 | DECLARE_INSTRUCTION(Or); |
| 4163 | |
| 4164 | private: |
| 4165 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4166 | }; |
| 4167 | |
| 4168 | class HXor : public HBinaryOperation { |
| 4169 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4170 | HXor(Primitive::Type result_type, |
| 4171 | HInstruction* left, |
| 4172 | HInstruction* right, |
| 4173 | uint32_t dex_pc = kNoDexPc) |
| 4174 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4175 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4176 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4177 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4178 | template <typename T, typename U> |
| 4179 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4180 | |
| 4181 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4182 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4183 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4184 | } |
| 4185 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4186 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4187 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4188 | } |
| 4189 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4190 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4191 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4192 | } |
| 4193 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4194 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4195 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4196 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4197 | |
| 4198 | DECLARE_INSTRUCTION(Xor); |
| 4199 | |
| 4200 | private: |
| 4201 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4202 | }; |
| 4203 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4204 | // The value of a parameter in this method. Its location depends on |
| 4205 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4206 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4207 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4208 | HParameterValue(const DexFile& dex_file, |
| 4209 | uint16_t type_index, |
| 4210 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4211 | Primitive::Type parameter_type, |
| 4212 | bool is_this = false) |
| 4213 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4214 | dex_file_(dex_file), |
| 4215 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4216 | index_(index), |
| 4217 | is_this_(is_this), |
| 4218 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4219 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4220 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4221 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4222 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4223 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4224 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4225 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4226 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4227 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4228 | DECLARE_INSTRUCTION(ParameterValue); |
| 4229 | |
| 4230 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4231 | const DexFile& dex_file_; |
| 4232 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4233 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4234 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4235 | const uint8_t index_; |
| 4236 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4237 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4238 | const bool is_this_; |
| 4239 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4240 | bool can_be_null_; |
| 4241 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4242 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4243 | }; |
| 4244 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4245 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4246 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4247 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4248 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4249 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4250 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4251 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4252 | return true; |
| 4253 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4254 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4255 | template <typename T> T Compute(T x) const { return ~x; } |
| 4256 | |
| 4257 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4258 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4259 | } |
| 4260 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4261 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4262 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4263 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4264 | DECLARE_INSTRUCTION(Not); |
| 4265 | |
| 4266 | private: |
| 4267 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4268 | }; |
| 4269 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4270 | class HBooleanNot : public HUnaryOperation { |
| 4271 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4272 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4273 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4274 | |
| 4275 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4276 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4277 | return true; |
| 4278 | } |
| 4279 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4280 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4281 | DCHECK(IsUint<1>(x)); |
| 4282 | return !x; |
| 4283 | } |
| 4284 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4285 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4286 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4287 | } |
| 4288 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4289 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4290 | UNREACHABLE(); |
| 4291 | } |
| 4292 | |
| 4293 | DECLARE_INSTRUCTION(BooleanNot); |
| 4294 | |
| 4295 | private: |
| 4296 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4297 | }; |
| 4298 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4299 | class HTypeConversion : public HExpression<1> { |
| 4300 | public: |
| 4301 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4302 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4303 | : HExpression(result_type, |
| 4304 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4305 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4306 | SetRawInputAt(0, input); |
| 4307 | DCHECK_NE(input->GetType(), result_type); |
| 4308 | } |
| 4309 | |
| 4310 | HInstruction* GetInput() const { return InputAt(0); } |
| 4311 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4312 | Primitive::Type GetResultType() const { return GetType(); } |
| 4313 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4314 | // 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] | 4315 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4316 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4317 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4318 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4319 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4320 | // Try to statically evaluate the conversion and return a HConstant |
| 4321 | // containing the result. If the input cannot be converted, return nullptr. |
| 4322 | HConstant* TryStaticEvaluation() const; |
| 4323 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4324 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4325 | Primitive::Type result_type) { |
| 4326 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4327 | // in the compilation process we do not know what architecture we will |
| 4328 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4329 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4330 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4331 | return SideEffects::CanTriggerGC(); |
| 4332 | } |
| 4333 | return SideEffects::None(); |
| 4334 | } |
| 4335 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4336 | DECLARE_INSTRUCTION(TypeConversion); |
| 4337 | |
| 4338 | private: |
| 4339 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4340 | }; |
| 4341 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4342 | static constexpr uint32_t kNoRegNumber = -1; |
| 4343 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4344 | class HPhi : public HInstruction { |
| 4345 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4346 | HPhi(ArenaAllocator* arena, |
| 4347 | uint32_t reg_number, |
| 4348 | size_t number_of_inputs, |
| 4349 | Primitive::Type type, |
| 4350 | uint32_t dex_pc = kNoDexPc) |
| 4351 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4352 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4353 | reg_number_(reg_number), |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4354 | type_(ToPhiType(type)), |
| 4355 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4356 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4357 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4358 | is_live_(true), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4359 | can_be_null_(true) { |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4360 | DCHECK_NE(type_, Primitive::kPrimVoid); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4361 | } |
| 4362 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4363 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4364 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4365 | switch (type) { |
| 4366 | case Primitive::kPrimBoolean: |
| 4367 | case Primitive::kPrimByte: |
| 4368 | case Primitive::kPrimShort: |
| 4369 | case Primitive::kPrimChar: |
| 4370 | return Primitive::kPrimInt; |
| 4371 | default: |
| 4372 | return type; |
| 4373 | } |
| 4374 | } |
| 4375 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4376 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4377 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4378 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4379 | |
| 4380 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4381 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4382 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4383 | Primitive::Type GetType() const OVERRIDE { return type_; } |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4384 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4385 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4386 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4387 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4388 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4389 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4390 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4391 | void SetDead() { is_live_ = false; } |
| 4392 | void SetLive() { is_live_ = true; } |
| 4393 | bool IsDead() const { return !is_live_; } |
| 4394 | bool IsLive() const { return is_live_; } |
| 4395 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4396 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4397 | return other != nullptr |
| 4398 | && other->IsPhi() |
| 4399 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4400 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4401 | } |
| 4402 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4403 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4404 | // An equivalent phi is a phi having the same dex register and type. |
| 4405 | // It assumes that phis with the same dex register are adjacent. |
| 4406 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4407 | HInstruction* next = GetNext(); |
| 4408 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4409 | if (next->GetType() == GetType()) { |
| 4410 | return next->AsPhi(); |
| 4411 | } |
| 4412 | next = next->GetNext(); |
| 4413 | } |
| 4414 | return nullptr; |
| 4415 | } |
| 4416 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4417 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4418 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4419 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4420 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4421 | return inputs_[index]; |
| 4422 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4423 | |
| 4424 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4425 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4428 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4429 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4430 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4431 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4432 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4433 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4434 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4435 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4436 | }; |
| 4437 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4438 | class HNullCheck : public HExpression<1> { |
| 4439 | public: |
| 4440 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4441 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4442 | SetRawInputAt(0, value); |
| 4443 | } |
| 4444 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4445 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4446 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4447 | return true; |
| 4448 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4449 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4450 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4451 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4452 | bool CanThrow() const OVERRIDE { return true; } |
| 4453 | |
| 4454 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4455 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4456 | |
| 4457 | DECLARE_INSTRUCTION(NullCheck); |
| 4458 | |
| 4459 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4460 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4461 | }; |
| 4462 | |
| 4463 | class FieldInfo : public ValueObject { |
| 4464 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4465 | FieldInfo(MemberOffset field_offset, |
| 4466 | Primitive::Type field_type, |
| 4467 | bool is_volatile, |
| 4468 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4469 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4470 | const DexFile& dex_file, |
| 4471 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4472 | : field_offset_(field_offset), |
| 4473 | field_type_(field_type), |
| 4474 | is_volatile_(is_volatile), |
| 4475 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4476 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4477 | dex_file_(dex_file), |
| 4478 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4479 | |
| 4480 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4481 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4482 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4483 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4484 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4485 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4486 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4487 | |
| 4488 | private: |
| 4489 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4490 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4491 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4492 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4493 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4494 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4495 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4496 | }; |
| 4497 | |
| 4498 | class HInstanceFieldGet : public HExpression<1> { |
| 4499 | public: |
| 4500 | HInstanceFieldGet(HInstruction* value, |
| 4501 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4502 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4503 | bool is_volatile, |
| 4504 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4505 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4506 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4507 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4508 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4509 | : HExpression(field_type, |
| 4510 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4511 | dex_pc), |
| 4512 | field_info_(field_offset, |
| 4513 | field_type, |
| 4514 | is_volatile, |
| 4515 | field_idx, |
| 4516 | declaring_class_def_index, |
| 4517 | dex_file, |
| 4518 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4519 | SetRawInputAt(0, value); |
| 4520 | } |
| 4521 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4522 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4523 | |
| 4524 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4525 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4526 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4527 | } |
| 4528 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4529 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4530 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4534 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4535 | } |
| 4536 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4537 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4538 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4539 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4540 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4541 | |
| 4542 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4543 | |
| 4544 | private: |
| 4545 | const FieldInfo field_info_; |
| 4546 | |
| 4547 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4548 | }; |
| 4549 | |
| 4550 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4551 | public: |
| 4552 | HInstanceFieldSet(HInstruction* object, |
| 4553 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4554 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4555 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4556 | bool is_volatile, |
| 4557 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4558 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4559 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4560 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4561 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4562 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4563 | dex_pc), |
| 4564 | field_info_(field_offset, |
| 4565 | field_type, |
| 4566 | is_volatile, |
| 4567 | field_idx, |
| 4568 | declaring_class_def_index, |
| 4569 | dex_file, |
| 4570 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4571 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4572 | SetRawInputAt(0, object); |
| 4573 | SetRawInputAt(1, value); |
| 4574 | } |
| 4575 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4576 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4577 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4580 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4581 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4582 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4583 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4584 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4585 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4586 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4587 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4588 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4589 | |
| 4590 | private: |
| 4591 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4592 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4593 | |
| 4594 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4595 | }; |
| 4596 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4597 | class HArrayGet : public HExpression<2> { |
| 4598 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4599 | HArrayGet(HInstruction* array, |
| 4600 | HInstruction* index, |
| 4601 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4602 | uint32_t dex_pc, |
| 4603 | SideEffects additional_side_effects = SideEffects::None()) |
| 4604 | : HExpression(type, |
| 4605 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4606 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4607 | SetRawInputAt(0, array); |
| 4608 | SetRawInputAt(1, index); |
| 4609 | } |
| 4610 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4611 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4612 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4613 | return true; |
| 4614 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4615 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4616 | // TODO: We can be smarter here. |
| 4617 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4618 | // which generates the implicit null check. There are cases when these can be removed |
| 4619 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4620 | // implicit check here (as long as the address falls in the first page). |
| 4621 | return false; |
| 4622 | } |
| 4623 | |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4624 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4625 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4626 | HInstruction* GetArray() const { return InputAt(0); } |
| 4627 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4628 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4629 | DECLARE_INSTRUCTION(ArrayGet); |
| 4630 | |
| 4631 | private: |
| 4632 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4633 | }; |
| 4634 | |
| 4635 | class HArraySet : public HTemplateInstruction<3> { |
| 4636 | public: |
| 4637 | HArraySet(HInstruction* array, |
| 4638 | HInstruction* index, |
| 4639 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4640 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4641 | uint32_t dex_pc, |
| 4642 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4643 | : HTemplateInstruction( |
| 4644 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4645 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4646 | additional_side_effects), |
| 4647 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4648 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4649 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4650 | value_can_be_null_(true), |
| 4651 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4652 | SetRawInputAt(0, array); |
| 4653 | SetRawInputAt(1, index); |
| 4654 | SetRawInputAt(2, value); |
| 4655 | } |
| 4656 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4657 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4658 | // We currently always call a runtime method to catch array store |
| 4659 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4660 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4661 | } |
| 4662 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4663 | // Can throw ArrayStoreException. |
| 4664 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4665 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4666 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4667 | // TODO: Same as for ArrayGet. |
| 4668 | return false; |
| 4669 | } |
| 4670 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4671 | void ClearNeedsTypeCheck() { |
| 4672 | needs_type_check_ = false; |
| 4673 | } |
| 4674 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4675 | void ClearValueCanBeNull() { |
| 4676 | value_can_be_null_ = false; |
| 4677 | } |
| 4678 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4679 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4680 | static_type_of_array_is_object_array_ = true; |
| 4681 | } |
| 4682 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4683 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4684 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4685 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4686 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4687 | HInstruction* GetArray() const { return InputAt(0); } |
| 4688 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4689 | HInstruction* GetValue() const { return InputAt(2); } |
| 4690 | |
| 4691 | Primitive::Type GetComponentType() const { |
| 4692 | // The Dex format does not type floating point index operations. Since the |
| 4693 | // `expected_component_type_` is set during building and can therefore not |
| 4694 | // be correct, we also check what is the value type. If it is a floating |
| 4695 | // point type, we must use that type. |
| 4696 | Primitive::Type value_type = GetValue()->GetType(); |
| 4697 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4698 | ? value_type |
| 4699 | : expected_component_type_; |
| 4700 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4701 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4702 | Primitive::Type GetRawExpectedComponentType() const { |
| 4703 | return expected_component_type_; |
| 4704 | } |
| 4705 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4706 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4707 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4708 | } |
| 4709 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4710 | DECLARE_INSTRUCTION(ArraySet); |
| 4711 | |
| 4712 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4713 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4714 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4715 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4716 | // Cached information for the reference_type_info_ so that codegen |
| 4717 | // does not need to inspect the static type. |
| 4718 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4719 | |
| 4720 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4721 | }; |
| 4722 | |
| 4723 | class HArrayLength : public HExpression<1> { |
| 4724 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4725 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4726 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4727 | // Note that arrays do not change length, so the instruction does not |
| 4728 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4729 | SetRawInputAt(0, array); |
| 4730 | } |
| 4731 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4732 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4733 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4734 | return true; |
| 4735 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4736 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4737 | return obj == InputAt(0); |
| 4738 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4739 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4740 | DECLARE_INSTRUCTION(ArrayLength); |
| 4741 | |
| 4742 | private: |
| 4743 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4744 | }; |
| 4745 | |
| 4746 | class HBoundsCheck : public HExpression<2> { |
| 4747 | public: |
| 4748 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4749 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4750 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4751 | SetRawInputAt(0, index); |
| 4752 | SetRawInputAt(1, length); |
| 4753 | } |
| 4754 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4755 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4756 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4757 | return true; |
| 4758 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4759 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4760 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4761 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4762 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4763 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4764 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4765 | |
| 4766 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4767 | |
| 4768 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4769 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4770 | }; |
| 4771 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4772 | /** |
| 4773 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4774 | * to stay live until the last HInstruction. This class |
| 4775 | * 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] | 4776 | * HInstruction stays live. `index` represents the stack location index of the |
| 4777 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4778 | */ |
| 4779 | class HTemporary : public HTemplateInstruction<0> { |
| 4780 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4781 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4782 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4783 | |
| 4784 | size_t GetIndex() const { return index_; } |
| 4785 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4786 | Primitive::Type GetType() const OVERRIDE { |
| 4787 | // The previous instruction is the one that will be stored in the temporary location. |
| 4788 | DCHECK(GetPrevious() != nullptr); |
| 4789 | return GetPrevious()->GetType(); |
| 4790 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4791 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4792 | DECLARE_INSTRUCTION(Temporary); |
| 4793 | |
| 4794 | private: |
| 4795 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4796 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4797 | }; |
| 4798 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4799 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4800 | public: |
| 4801 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4802 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4803 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4804 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4805 | return true; |
| 4806 | } |
| 4807 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4808 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4809 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4810 | |
| 4811 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4812 | |
| 4813 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4814 | // Only used for code generation, in order to share the same slow path between back edges |
| 4815 | // of a same loop. |
| 4816 | SlowPathCode* slow_path_; |
| 4817 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4818 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4819 | }; |
| 4820 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4821 | /** |
| 4822 | * Instruction to load a Class object. |
| 4823 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4824 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4825 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4826 | HLoadClass(HCurrentMethod* current_method, |
| 4827 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4828 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4829 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4830 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4831 | bool needs_access_check, |
| 4832 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4833 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4834 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4835 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4836 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4837 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4838 | needs_access_check_(needs_access_check), |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4839 | is_in_dex_cache_(is_in_dex_cache), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4840 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4841 | // Referrers class should not need access check. We never inline unverified |
| 4842 | // methods so we can't possibly end up in this situation. |
| 4843 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4844 | SetRawInputAt(0, current_method); |
| 4845 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4846 | |
| 4847 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4848 | |
| 4849 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 4850 | // Note that we don't need to test for generate_clinit_check_. |
| 4851 | // Whether or not we need to generate the clinit check is processed in |
| 4852 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4853 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 4854 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4855 | } |
| 4856 | |
| 4857 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4858 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4859 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4860 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4861 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4862 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4863 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4864 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4865 | } |
| 4866 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4867 | bool MustGenerateClinitCheck() const { |
| 4868 | return generate_clinit_check_; |
| 4869 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4870 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4871 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 4872 | // The entrypoint the code generator is going to call does not do |
| 4873 | // clinit of the class. |
| 4874 | DCHECK(!NeedsAccessCheck()); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4875 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4876 | } |
| 4877 | |
| 4878 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4879 | return MustGenerateClinitCheck() || |
| 4880 | (!is_referrers_class_ && !is_in_dex_cache_) || |
| 4881 | needs_access_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | bool NeedsAccessCheck() const { |
| 4885 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4886 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4887 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4888 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4889 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4890 | } |
| 4891 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4892 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4893 | return loaded_class_rti_; |
| 4894 | } |
| 4895 | |
| 4896 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4897 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4898 | DCHECK(rti.IsExact()); |
| 4899 | loaded_class_rti_ = rti; |
| 4900 | } |
| 4901 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4902 | const DexFile& GetDexFile() { return dex_file_; } |
| 4903 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4904 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4905 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4906 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4907 | return SideEffects::CanTriggerGC(); |
| 4908 | } |
| 4909 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4910 | bool IsInDexCache() const { return is_in_dex_cache_; } |
| 4911 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4912 | DECLARE_INSTRUCTION(LoadClass); |
| 4913 | |
| 4914 | private: |
| 4915 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4916 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4917 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4918 | // Whether this instruction must generate the initialization check. |
| 4919 | // Used for code generation. |
| 4920 | bool generate_clinit_check_; |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4921 | const bool needs_access_check_; |
| 4922 | const bool is_in_dex_cache_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4923 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4924 | ReferenceTypeInfo loaded_class_rti_; |
| 4925 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4926 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4927 | }; |
| 4928 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4929 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4930 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4931 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4932 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4933 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4934 | SetRawInputAt(0, current_method); |
| 4935 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4936 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4937 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4938 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4939 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4940 | return other->AsLoadString()->string_index_ == string_index_; |
| 4941 | } |
| 4942 | |
| 4943 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4944 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4945 | uint32_t GetStringIndex() const { return string_index_; } |
| 4946 | |
| 4947 | // TODO: Can we deopt or debug when we resolve a string? |
| 4948 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4949 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4950 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4951 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4952 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4953 | return SideEffects::CanTriggerGC(); |
| 4954 | } |
| 4955 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4956 | DECLARE_INSTRUCTION(LoadString); |
| 4957 | |
| 4958 | private: |
| 4959 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4960 | |
| 4961 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4962 | }; |
| 4963 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4964 | /** |
| 4965 | * Performs an initialization check on its Class object input. |
| 4966 | */ |
| 4967 | class HClinitCheck : public HExpression<1> { |
| 4968 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4969 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4970 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4971 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4972 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4973 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4974 | SetRawInputAt(0, constant); |
| 4975 | } |
| 4976 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4977 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4978 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4979 | return true; |
| 4980 | } |
| 4981 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4982 | bool NeedsEnvironment() const OVERRIDE { |
| 4983 | // May call runtime to initialize the class. |
| 4984 | return true; |
| 4985 | } |
| 4986 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 4987 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4988 | |
| 4989 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4990 | |
| 4991 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4992 | |
| 4993 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4994 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4995 | }; |
| 4996 | |
| 4997 | class HStaticFieldGet : public HExpression<1> { |
| 4998 | public: |
| 4999 | HStaticFieldGet(HInstruction* cls, |
| 5000 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5001 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5002 | bool is_volatile, |
| 5003 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5004 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5005 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5006 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5007 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5008 | : HExpression(field_type, |
| 5009 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5010 | dex_pc), |
| 5011 | field_info_(field_offset, |
| 5012 | field_type, |
| 5013 | is_volatile, |
| 5014 | field_idx, |
| 5015 | declaring_class_def_index, |
| 5016 | dex_file, |
| 5017 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5018 | SetRawInputAt(0, cls); |
| 5019 | } |
| 5020 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5021 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5022 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5023 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5024 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5025 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5026 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5027 | } |
| 5028 | |
| 5029 | size_t ComputeHashCode() const OVERRIDE { |
| 5030 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5031 | } |
| 5032 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5033 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5034 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5035 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5036 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5037 | |
| 5038 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5039 | |
| 5040 | private: |
| 5041 | const FieldInfo field_info_; |
| 5042 | |
| 5043 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5044 | }; |
| 5045 | |
| 5046 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5047 | public: |
| 5048 | HStaticFieldSet(HInstruction* cls, |
| 5049 | HInstruction* value, |
| 5050 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5051 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5052 | bool is_volatile, |
| 5053 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5054 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5055 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5056 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5057 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5058 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5059 | dex_pc), |
| 5060 | field_info_(field_offset, |
| 5061 | field_type, |
| 5062 | is_volatile, |
| 5063 | field_idx, |
| 5064 | declaring_class_def_index, |
| 5065 | dex_file, |
| 5066 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5067 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5068 | SetRawInputAt(0, cls); |
| 5069 | SetRawInputAt(1, value); |
| 5070 | } |
| 5071 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5072 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5073 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5074 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5075 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5076 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5077 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5078 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 5079 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5080 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5081 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5082 | |
| 5083 | private: |
| 5084 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5085 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5086 | |
| 5087 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5088 | }; |
| 5089 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5090 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5091 | public: |
| 5092 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5093 | Primitive::Type field_type, |
| 5094 | uint32_t field_index, |
| 5095 | uint32_t dex_pc) |
| 5096 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5097 | field_index_(field_index) { |
| 5098 | SetRawInputAt(0, obj); |
| 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(UnresolvedInstanceFieldGet); |
| 5108 | |
| 5109 | private: |
| 5110 | const uint32_t field_index_; |
| 5111 | |
| 5112 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5113 | }; |
| 5114 | |
| 5115 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5116 | public: |
| 5117 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5118 | HInstruction* value, |
| 5119 | Primitive::Type field_type, |
| 5120 | uint32_t field_index, |
| 5121 | uint32_t dex_pc) |
| 5122 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5123 | field_type_(field_type), |
| 5124 | field_index_(field_index) { |
| 5125 | DCHECK_EQ(field_type, value->GetType()); |
| 5126 | SetRawInputAt(0, obj); |
| 5127 | SetRawInputAt(1, value); |
| 5128 | } |
| 5129 | |
| 5130 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5131 | bool CanThrow() const OVERRIDE { return true; } |
| 5132 | |
| 5133 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5134 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5135 | |
| 5136 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5137 | |
| 5138 | private: |
| 5139 | const Primitive::Type field_type_; |
| 5140 | const uint32_t field_index_; |
| 5141 | |
| 5142 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5143 | }; |
| 5144 | |
| 5145 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5146 | public: |
| 5147 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5148 | uint32_t field_index, |
| 5149 | uint32_t dex_pc) |
| 5150 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5151 | field_index_(field_index) { |
| 5152 | } |
| 5153 | |
| 5154 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5155 | bool CanThrow() const OVERRIDE { return true; } |
| 5156 | |
| 5157 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5158 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5159 | |
| 5160 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5161 | |
| 5162 | private: |
| 5163 | const uint32_t field_index_; |
| 5164 | |
| 5165 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5166 | }; |
| 5167 | |
| 5168 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5169 | public: |
| 5170 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5171 | Primitive::Type field_type, |
| 5172 | uint32_t field_index, |
| 5173 | uint32_t dex_pc) |
| 5174 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5175 | field_type_(field_type), |
| 5176 | field_index_(field_index) { |
| 5177 | DCHECK_EQ(field_type, value->GetType()); |
| 5178 | SetRawInputAt(0, value); |
| 5179 | } |
| 5180 | |
| 5181 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5182 | bool CanThrow() const OVERRIDE { return true; } |
| 5183 | |
| 5184 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5185 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5186 | |
| 5187 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5188 | |
| 5189 | private: |
| 5190 | const Primitive::Type field_type_; |
| 5191 | const uint32_t field_index_; |
| 5192 | |
| 5193 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5194 | }; |
| 5195 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5196 | // Implement the move-exception DEX instruction. |
| 5197 | class HLoadException : public HExpression<0> { |
| 5198 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5199 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5200 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5201 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5202 | bool CanBeNull() const OVERRIDE { return false; } |
| 5203 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5204 | DECLARE_INSTRUCTION(LoadException); |
| 5205 | |
| 5206 | private: |
| 5207 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5208 | }; |
| 5209 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5210 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5211 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5212 | class HClearException : public HTemplateInstruction<0> { |
| 5213 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5214 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5215 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5216 | |
| 5217 | DECLARE_INSTRUCTION(ClearException); |
| 5218 | |
| 5219 | private: |
| 5220 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5221 | }; |
| 5222 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5223 | class HThrow : public HTemplateInstruction<1> { |
| 5224 | public: |
| 5225 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5226 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5227 | SetRawInputAt(0, exception); |
| 5228 | } |
| 5229 | |
| 5230 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5231 | |
| 5232 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5233 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5234 | bool CanThrow() const OVERRIDE { return true; } |
| 5235 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5236 | |
| 5237 | DECLARE_INSTRUCTION(Throw); |
| 5238 | |
| 5239 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5240 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5241 | }; |
| 5242 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5243 | /** |
| 5244 | * Implementation strategies for the code generator of a HInstanceOf |
| 5245 | * or `HCheckCast`. |
| 5246 | */ |
| 5247 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5248 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5249 | kExactCheck, // Can do a single class compare. |
| 5250 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5251 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5252 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5253 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5254 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5255 | }; |
| 5256 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5257 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5258 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5259 | HInstanceOf(HInstruction* object, |
| 5260 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5261 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5262 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5263 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5264 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5265 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5266 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5267 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5268 | SetRawInputAt(0, object); |
| 5269 | SetRawInputAt(1, constant); |
| 5270 | } |
| 5271 | |
| 5272 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5273 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5274 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5275 | return true; |
| 5276 | } |
| 5277 | |
| 5278 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5279 | return false; |
| 5280 | } |
| 5281 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5282 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5283 | |
| 5284 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5285 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5286 | // Used only in code generation. |
| 5287 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5288 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5289 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5290 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 5291 | return (check_kind == TypeCheckKind::kExactCheck) |
| 5292 | ? SideEffects::None() |
| 5293 | // Mips currently does runtime calls for any other checks. |
| 5294 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5295 | } |
| 5296 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5297 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5298 | |
| 5299 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5300 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5301 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5302 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5303 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5304 | }; |
| 5305 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5306 | class HBoundType : public HExpression<1> { |
| 5307 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5308 | // Constructs an HBoundType with the given upper_bound. |
| 5309 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5310 | HBoundType(HInstruction* input, |
| 5311 | ReferenceTypeInfo upper_bound, |
| 5312 | bool upper_can_be_null, |
| 5313 | uint32_t dex_pc = kNoDexPc) |
| 5314 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5315 | upper_bound_(upper_bound), |
| 5316 | upper_can_be_null_(upper_can_be_null), |
| 5317 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5318 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5319 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5320 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5323 | // GetUpper* should only be used in reference type propagation. |
| 5324 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5325 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5326 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5327 | void SetCanBeNull(bool can_be_null) { |
| 5328 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5329 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5332 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5333 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5334 | DECLARE_INSTRUCTION(BoundType); |
| 5335 | |
| 5336 | private: |
| 5337 | // 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] | 5338 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5339 | // It is used to bound the type in cases like: |
| 5340 | // if (x instanceof ClassX) { |
| 5341 | // // uper_bound_ will be ClassX |
| 5342 | // } |
| 5343 | const ReferenceTypeInfo upper_bound_; |
| 5344 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5345 | // is false then can_be_null_ cannot be true). |
| 5346 | const bool upper_can_be_null_; |
| 5347 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5348 | |
| 5349 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5350 | }; |
| 5351 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5352 | class HCheckCast : public HTemplateInstruction<2> { |
| 5353 | public: |
| 5354 | HCheckCast(HInstruction* object, |
| 5355 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5356 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5357 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5358 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5359 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5360 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5361 | SetRawInputAt(0, object); |
| 5362 | SetRawInputAt(1, constant); |
| 5363 | } |
| 5364 | |
| 5365 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5366 | |
| 5367 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5368 | return true; |
| 5369 | } |
| 5370 | |
| 5371 | bool NeedsEnvironment() const OVERRIDE { |
| 5372 | // Instruction may throw a CheckCastError. |
| 5373 | return true; |
| 5374 | } |
| 5375 | |
| 5376 | bool CanThrow() const OVERRIDE { return true; } |
| 5377 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5378 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5379 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5380 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5381 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5382 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5383 | |
| 5384 | DECLARE_INSTRUCTION(CheckCast); |
| 5385 | |
| 5386 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5387 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5388 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5389 | |
| 5390 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5391 | }; |
| 5392 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5393 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5394 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5395 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5396 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5397 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5398 | barrier_kind_(barrier_kind) {} |
| 5399 | |
| 5400 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5401 | |
| 5402 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5403 | |
| 5404 | private: |
| 5405 | const MemBarrierKind barrier_kind_; |
| 5406 | |
| 5407 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5408 | }; |
| 5409 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5410 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5411 | public: |
| 5412 | enum OperationKind { |
| 5413 | kEnter, |
| 5414 | kExit, |
| 5415 | }; |
| 5416 | |
| 5417 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5418 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5419 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5420 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5421 | SetRawInputAt(0, object); |
| 5422 | } |
| 5423 | |
| 5424 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5425 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5426 | |
| 5427 | bool CanThrow() const OVERRIDE { |
| 5428 | // Verifier guarantees that monitor-exit cannot throw. |
| 5429 | // This is important because it allows the HGraphBuilder to remove |
| 5430 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5431 | return IsEnter(); |
| 5432 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5433 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5434 | |
| 5435 | bool IsEnter() const { return kind_ == kEnter; } |
| 5436 | |
| 5437 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5438 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5439 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5440 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5441 | |
| 5442 | private: |
| 5443 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5444 | }; |
| 5445 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5446 | /** |
| 5447 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5448 | * of a String to a call to a StringFactory. Only baseline will see |
| 5449 | * the node at code generation, where it will be be treated as null. |
| 5450 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5451 | * in the instruction simplifier. |
| 5452 | */ |
| 5453 | class HFakeString : public HTemplateInstruction<0> { |
| 5454 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5455 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5456 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5457 | |
| 5458 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5459 | |
| 5460 | DECLARE_INSTRUCTION(FakeString); |
| 5461 | |
| 5462 | private: |
| 5463 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5464 | }; |
| 5465 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5466 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5467 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5468 | MoveOperands(Location source, |
| 5469 | Location destination, |
| 5470 | Primitive::Type type, |
| 5471 | HInstruction* instruction) |
| 5472 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5473 | |
| 5474 | Location GetSource() const { return source_; } |
| 5475 | Location GetDestination() const { return destination_; } |
| 5476 | |
| 5477 | void SetSource(Location value) { source_ = value; } |
| 5478 | void SetDestination(Location value) { destination_ = value; } |
| 5479 | |
| 5480 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5481 | // destination (but not the source). |
| 5482 | Location MarkPending() { |
| 5483 | DCHECK(!IsPending()); |
| 5484 | Location dest = destination_; |
| 5485 | destination_ = Location::NoLocation(); |
| 5486 | return dest; |
| 5487 | } |
| 5488 | |
| 5489 | void ClearPending(Location dest) { |
| 5490 | DCHECK(IsPending()); |
| 5491 | destination_ = dest; |
| 5492 | } |
| 5493 | |
| 5494 | bool IsPending() const { |
| 5495 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5496 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5497 | } |
| 5498 | |
| 5499 | // True if this blocks a move from the given location. |
| 5500 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5501 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | // A move is redundant if it's been eliminated, if its source and |
| 5505 | // destination are the same, or if its destination is unneeded. |
| 5506 | bool IsRedundant() const { |
| 5507 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5508 | } |
| 5509 | |
| 5510 | // We clear both operands to indicate move that's been eliminated. |
| 5511 | void Eliminate() { |
| 5512 | source_ = destination_ = Location::NoLocation(); |
| 5513 | } |
| 5514 | |
| 5515 | bool IsEliminated() const { |
| 5516 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5517 | return source_.IsInvalid(); |
| 5518 | } |
| 5519 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5520 | Primitive::Type GetType() const { return type_; } |
| 5521 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5522 | bool Is64BitMove() const { |
| 5523 | return Primitive::Is64BitType(type_); |
| 5524 | } |
| 5525 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5526 | HInstruction* GetInstruction() const { return instruction_; } |
| 5527 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5528 | private: |
| 5529 | Location source_; |
| 5530 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5531 | // The type this move is for. |
| 5532 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5533 | // The instruction this move is assocatied with. Null when this move is |
| 5534 | // for moving an input in the expected locations of user (including a phi user). |
| 5535 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5536 | // in the same parallel move. |
| 5537 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5538 | }; |
| 5539 | |
| 5540 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5541 | |
| 5542 | class HParallelMove : public HTemplateInstruction<0> { |
| 5543 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5544 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5545 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5546 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5547 | moves_.reserve(kDefaultNumberOfMoves); |
| 5548 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5549 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5550 | void AddMove(Location source, |
| 5551 | Location destination, |
| 5552 | Primitive::Type type, |
| 5553 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5554 | DCHECK(source.IsValid()); |
| 5555 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5556 | if (kIsDebugBuild) { |
| 5557 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5558 | for (const MoveOperands& move : moves_) { |
| 5559 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5560 | // Special case the situation where the move is for the spill slot |
| 5561 | // of the instruction. |
| 5562 | if ((GetPrevious() == instruction) |
| 5563 | || ((GetPrevious() == nullptr) |
| 5564 | && instruction->IsPhi() |
| 5565 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5566 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5567 | << "Doing parallel moves for the same instruction."; |
| 5568 | } else { |
| 5569 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5570 | } |
| 5571 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5572 | } |
| 5573 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5574 | for (const MoveOperands& move : moves_) { |
| 5575 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5576 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5577 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5578 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5579 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5580 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5581 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5582 | } |
| 5583 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5584 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5585 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5586 | } |
| 5587 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5588 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5589 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5590 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5591 | |
| 5592 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5593 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5594 | |
| 5595 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5596 | }; |
| 5597 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5598 | } // namespace art |
| 5599 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 5600 | #ifdef ART_ENABLE_CODEGEN_arm |
| 5601 | #include "nodes_arm.h" |
| 5602 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5603 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5604 | #include "nodes_arm64.h" |
| 5605 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5606 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5607 | #include "nodes_x86.h" |
| 5608 | #endif |
| 5609 | |
| 5610 | namespace art { |
| 5611 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5612 | class HGraphVisitor : public ValueObject { |
| 5613 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5614 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5615 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5616 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5617 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5618 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5619 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5620 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5621 | void VisitInsertionOrder(); |
| 5622 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5623 | // Visit the graph following dominator tree reverse post-order. |
| 5624 | void VisitReversePostOrder(); |
| 5625 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5626 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5627 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5628 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5629 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5630 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5631 | |
| 5632 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5633 | |
| 5634 | #undef DECLARE_VISIT_INSTRUCTION |
| 5635 | |
| 5636 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5637 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5638 | |
| 5639 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5640 | }; |
| 5641 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5642 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5643 | public: |
| 5644 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5645 | virtual ~HGraphDelegateVisitor() {} |
| 5646 | |
| 5647 | // Visit functions that delegate to to super class. |
| 5648 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5649 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5650 | |
| 5651 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5652 | |
| 5653 | #undef DECLARE_VISIT_INSTRUCTION |
| 5654 | |
| 5655 | private: |
| 5656 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5657 | }; |
| 5658 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5659 | class HInsertionOrderIterator : public ValueObject { |
| 5660 | public: |
| 5661 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5662 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5663 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5664 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5665 | void Advance() { ++index_; } |
| 5666 | |
| 5667 | private: |
| 5668 | const HGraph& graph_; |
| 5669 | size_t index_; |
| 5670 | |
| 5671 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5672 | }; |
| 5673 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5674 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5675 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5676 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5677 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5678 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5679 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5680 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5681 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5682 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5683 | void Advance() { ++index_; } |
| 5684 | |
| 5685 | private: |
| 5686 | const HGraph& graph_; |
| 5687 | size_t index_; |
| 5688 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5689 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5690 | }; |
| 5691 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5692 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5693 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5694 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5695 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5696 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5697 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5698 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5699 | |
| 5700 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5701 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5702 | void Advance() { --index_; } |
| 5703 | |
| 5704 | private: |
| 5705 | const HGraph& graph_; |
| 5706 | size_t index_; |
| 5707 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5708 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5709 | }; |
| 5710 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5711 | class HLinearPostOrderIterator : public ValueObject { |
| 5712 | public: |
| 5713 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5714 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5715 | |
| 5716 | bool Done() const { return index_ == 0; } |
| 5717 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5718 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5719 | |
| 5720 | void Advance() { |
| 5721 | --index_; |
| 5722 | DCHECK_GE(index_, 0U); |
| 5723 | } |
| 5724 | |
| 5725 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5726 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5727 | size_t index_; |
| 5728 | |
| 5729 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5730 | }; |
| 5731 | |
| 5732 | class HLinearOrderIterator : public ValueObject { |
| 5733 | public: |
| 5734 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5735 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5736 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5737 | bool Done() const { return index_ == order_.size(); } |
| 5738 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5739 | void Advance() { ++index_; } |
| 5740 | |
| 5741 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5742 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5743 | size_t index_; |
| 5744 | |
| 5745 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5746 | }; |
| 5747 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5748 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5749 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5750 | // block id. |
| 5751 | class HBlocksInLoopIterator : public ValueObject { |
| 5752 | public: |
| 5753 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5754 | : blocks_in_loop_(info.GetBlocks()), |
| 5755 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5756 | index_(0) { |
| 5757 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5758 | Advance(); |
| 5759 | } |
| 5760 | } |
| 5761 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5762 | bool Done() const { return index_ == blocks_.size(); } |
| 5763 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5764 | void Advance() { |
| 5765 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5766 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5767 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5768 | break; |
| 5769 | } |
| 5770 | } |
| 5771 | } |
| 5772 | |
| 5773 | private: |
| 5774 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5775 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5776 | size_t index_; |
| 5777 | |
| 5778 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5779 | }; |
| 5780 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5781 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5782 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5783 | // post order. |
| 5784 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5785 | public: |
| 5786 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5787 | : blocks_in_loop_(info.GetBlocks()), |
| 5788 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5789 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5790 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5791 | Advance(); |
| 5792 | } |
| 5793 | } |
| 5794 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5795 | bool Done() const { return index_ == blocks_.size(); } |
| 5796 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5797 | void Advance() { |
| 5798 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5799 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5800 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5801 | break; |
| 5802 | } |
| 5803 | } |
| 5804 | } |
| 5805 | |
| 5806 | private: |
| 5807 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5808 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5809 | size_t index_; |
| 5810 | |
| 5811 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5812 | }; |
| 5813 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5814 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5815 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5816 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5817 | : constant->AsLongConstant()->GetValue(); |
| 5818 | } |
| 5819 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5820 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5821 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5822 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5823 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5824 | // times and provide different class resolution but no two class loaders should ever |
| 5825 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5826 | // all sorts of weird failures. |
| 5827 | return &lhs == &rhs; |
| 5828 | } |
| 5829 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5830 | } // namespace art |
| 5831 | |
| 5832 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |