Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_NODES_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_H_ |
| 19 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 24 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 26 | #include "base/arena_object.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 28 | #include "dex/compiler_enums.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 30 | #include "handle.h" |
| 31 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 32 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 33 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 34 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 35 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 36 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 37 | #include "primitive.h" |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 38 | #include "utils/array_ref.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 39 | |
| 40 | namespace art { |
| 41 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 42 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 43 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 45 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 46 | class HEnvironment; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 47 | class HFakeString; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 48 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 49 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 51 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 52 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 53 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 55 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 56 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 57 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 58 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 59 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 60 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 61 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 62 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 63 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 64 | namespace mirror { |
| 65 | class DexCache; |
| 66 | } // namespace mirror |
| 67 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 68 | static const int kDefaultNumberOfBlocks = 8; |
| 69 | static const int kDefaultNumberOfSuccessors = 2; |
| 70 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 72 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 73 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 74 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 75 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 76 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 77 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 78 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 79 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 80 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 81 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 82 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 83 | static constexpr uint32_t kNoDexPc = -1; |
| 84 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 85 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 86 | // All types. |
| 87 | kCondEQ, // == |
| 88 | kCondNE, // != |
| 89 | // Signed integers and floating-point numbers. |
| 90 | kCondLT, // < |
| 91 | kCondLE, // <= |
| 92 | kCondGT, // > |
| 93 | kCondGE, // >= |
| 94 | // Unsigned integers. |
| 95 | kCondB, // < |
| 96 | kCondBE, // <= |
| 97 | kCondA, // > |
| 98 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 101 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 102 | public: |
| 103 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 104 | |
| 105 | void AddInstruction(HInstruction* instruction); |
| 106 | void RemoveInstruction(HInstruction* instruction); |
| 107 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 108 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 109 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 110 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 111 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 112 | // Return true if this list contains `instruction`. |
| 113 | bool Contains(HInstruction* instruction) const; |
| 114 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 115 | // Return true if `instruction1` is found before `instruction2` in |
| 116 | // this instruction list and false otherwise. Abort if none |
| 117 | // of these instructions is found. |
| 118 | bool FoundBefore(const HInstruction* instruction1, |
| 119 | const HInstruction* instruction2) const; |
| 120 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 121 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 122 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 123 | |
| 124 | // Update the block of all instructions to be `block`. |
| 125 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 126 | |
| 127 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 128 | void Add(const HInstructionList& instruction_list); |
| 129 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 130 | // Return the number of instructions in the list. This is an expensive operation. |
| 131 | size_t CountSize() const; |
| 132 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 133 | private: |
| 134 | HInstruction* first_instruction_; |
| 135 | HInstruction* last_instruction_; |
| 136 | |
| 137 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 138 | friend class HGraph; |
| 139 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 140 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 141 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 142 | |
| 143 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 144 | }; |
| 145 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 146 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 147 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 148 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 149 | HGraph(ArenaAllocator* arena, |
| 150 | const DexFile& dex_file, |
| 151 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 152 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 153 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 154 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 155 | bool debuggable = false, |
| 156 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 157 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 158 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 159 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 160 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 161 | entry_block_(nullptr), |
| 162 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 163 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 164 | number_of_vregs_(0), |
| 165 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 166 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 167 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 168 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 169 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 170 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 171 | dex_file_(dex_file), |
| 172 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 173 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 174 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 175 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 176 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 177 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 178 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 179 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 180 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 181 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 182 | cached_current_method_(nullptr) { |
| 183 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 184 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 185 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 186 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 187 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 188 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 189 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 190 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 191 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 192 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 193 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 194 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 195 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 196 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 197 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 198 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 199 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 200 | // Try building the SSA form of this graph, with dominance computation and loop |
| 201 | // recognition. Returns whether it was successful in doing all these steps. |
| 202 | bool TryBuildingSsa() { |
| 203 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 204 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 205 | // elimination phase checks the consistency of the graph when doing a post-order |
| 206 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 207 | // users remaining when being visited. |
| 208 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 209 | // Precompute per-block try membership before entering the SSA builder, |
| 210 | // which needs the information to build catch block phis from values of |
| 211 | // locals at throwing instructions inside try blocks. |
| 212 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 213 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 214 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 215 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 218 | void ComputeDominanceInformation(); |
| 219 | void ClearDominanceInformation(); |
| 220 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 221 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 222 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 223 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 224 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 225 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 226 | // Analyze all natural loops in this graph. Returns false if one |
| 227 | // loop is not natural, that is the header does not dominate the |
| 228 | // back edge. |
| 229 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 230 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 231 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 232 | // order and loop information. |
| 233 | void ComputeTryBlockInformation(); |
| 234 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 235 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 236 | // Returns the instruction used to replace the invoke expression or null if the |
| 237 | // invoke is for a void method. |
| 238 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 239 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 240 | // Need to add a couple of blocks to test if the loop body is entered and |
| 241 | // put deoptimization instructions, etc. |
| 242 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 243 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 244 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 245 | // other blocks and has no instructions or phis. |
| 246 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 247 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 248 | // Splits the edge between `block` and `successor` while preserving the |
| 249 | // indices in the predecessor/successor lists. If there are multiple edges |
| 250 | // between the blocks, the lowest indices are used. |
| 251 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 252 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 253 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 254 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 255 | void SimplifyLoop(HBasicBlock* header); |
| 256 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 257 | int32_t GetNextInstructionId() { |
| 258 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 259 | return current_instruction_id_++; |
| 260 | } |
| 261 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 262 | int32_t GetCurrentInstructionId() const { |
| 263 | return current_instruction_id_; |
| 264 | } |
| 265 | |
| 266 | void SetCurrentInstructionId(int32_t id) { |
| 267 | current_instruction_id_ = id; |
| 268 | } |
| 269 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 270 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 271 | return maximum_number_of_out_vregs_; |
| 272 | } |
| 273 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 274 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 275 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 276 | } |
| 277 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 278 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 279 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 280 | } |
| 281 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 282 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 283 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 286 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 287 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 288 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 291 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 292 | number_of_vregs_ = number_of_vregs; |
| 293 | } |
| 294 | |
| 295 | uint16_t GetNumberOfVRegs() const { |
| 296 | return number_of_vregs_; |
| 297 | } |
| 298 | |
| 299 | void SetNumberOfInVRegs(uint16_t value) { |
| 300 | number_of_in_vregs_ = value; |
| 301 | } |
| 302 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 303 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 304 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 305 | return number_of_vregs_ - number_of_in_vregs_; |
| 306 | } |
| 307 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 308 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 309 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 310 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 311 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 312 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 313 | return linear_order_; |
| 314 | } |
| 315 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 316 | bool HasBoundsChecks() const { |
| 317 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 320 | void SetHasBoundsChecks(bool value) { |
| 321 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 324 | bool ShouldGenerateConstructorBarrier() const { |
| 325 | return should_generate_constructor_barrier_; |
| 326 | } |
| 327 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 328 | bool IsDebuggable() const { return debuggable_; } |
| 329 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 330 | // Returns a constant of the given type and value. If it does not exist |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 331 | // already, it is created and inserted into the graph. This method is only for |
| 332 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 333 | HConstant* GetConstant(Primitive::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 334 | |
| 335 | // TODO: This is problematic for the consistency of reference type propagation |
| 336 | // because it can be created anytime after the pass and thus it will be left |
| 337 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 338 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 339 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 340 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 341 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 342 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 343 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 344 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 345 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 346 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 347 | return CreateConstant(bit_cast<int32_t, float>(value), &cached_float_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 348 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 349 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 350 | return CreateConstant(bit_cast<int64_t, double>(value), &cached_double_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 351 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 352 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 353 | HCurrentMethod* GetCurrentMethod(); |
| 354 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 355 | const DexFile& GetDexFile() const { |
| 356 | return dex_file_; |
| 357 | } |
| 358 | |
| 359 | uint32_t GetMethodIdx() const { |
| 360 | return method_idx_; |
| 361 | } |
| 362 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 363 | InvokeType GetInvokeType() const { |
| 364 | return invoke_type_; |
| 365 | } |
| 366 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 367 | InstructionSet GetInstructionSet() const { |
| 368 | return instruction_set_; |
| 369 | } |
| 370 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 371 | bool HasTryCatch() const { return has_try_catch_; } |
| 372 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 373 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 374 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 375 | // The instruction has been inserted into the graph, either as a constant, or |
| 376 | // before cursor. |
| 377 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 378 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 379 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 380 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 381 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 382 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 383 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 384 | template <class InstructionType, typename ValueType> |
| 385 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 386 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 387 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 388 | // Try to find an existing constant of the given value. |
| 389 | InstructionType* constant = nullptr; |
| 390 | auto cached_constant = cache->find(value); |
| 391 | if (cached_constant != cache->end()) { |
| 392 | constant = cached_constant->second; |
| 393 | } |
| 394 | |
| 395 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 396 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 397 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 398 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 399 | cache->Overwrite(value, constant); |
| 400 | InsertConstant(constant); |
| 401 | } |
| 402 | return constant; |
| 403 | } |
| 404 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 405 | void InsertConstant(HConstant* instruction); |
| 406 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 407 | // Cache a float constant into the graph. This method should only be |
| 408 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 409 | void CacheFloatConstant(HFloatConstant* constant); |
| 410 | |
| 411 | // See CacheFloatConstant comment. |
| 412 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 413 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 414 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 415 | |
| 416 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 417 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 418 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 419 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 420 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 421 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 422 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 423 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 424 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 425 | HBasicBlock* entry_block_; |
| 426 | HBasicBlock* exit_block_; |
| 427 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 428 | // The maximum number of virtual registers arguments passed to a HInvoke in this graph. |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 429 | uint16_t maximum_number_of_out_vregs_; |
| 430 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 431 | // The number of virtual registers in this method. Contains the parameters. |
| 432 | uint16_t number_of_vregs_; |
| 433 | |
| 434 | // The number of virtual registers used by parameters of this method. |
| 435 | uint16_t number_of_in_vregs_; |
| 436 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 437 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 438 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 439 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 440 | // Has bounds checks. We can totally skip BCE if it's false. |
| 441 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 442 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 443 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 444 | // try/catch-related passes if false. |
| 445 | bool has_try_catch_; |
| 446 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 447 | // Indicates whether the graph should be compiled in a way that |
| 448 | // ensures full debuggability. If false, we can apply more |
| 449 | // aggressive optimizations that may limit the level of debugging. |
| 450 | const bool debuggable_; |
| 451 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 452 | // The current id to assign to a newly added instruction. See HInstruction.id_. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 453 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 454 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 455 | // The dex file from which the method is from. |
| 456 | const DexFile& dex_file_; |
| 457 | |
| 458 | // The method index in the dex file. |
| 459 | const uint32_t method_idx_; |
| 460 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 461 | // If inlined, this encodes how the callee is being invoked. |
| 462 | const InvokeType invoke_type_; |
| 463 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 464 | // Whether the graph has been transformed to SSA form. Only used |
| 465 | // in debug mode to ensure we are not using properties only valid |
| 466 | // for non-SSA form (like the number of temporaries). |
| 467 | bool in_ssa_form_; |
| 468 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 469 | const bool should_generate_constructor_barrier_; |
| 470 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 471 | const InstructionSet instruction_set_; |
| 472 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 473 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 474 | HNullConstant* cached_null_constant_; |
| 475 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 476 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 477 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 478 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 479 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 480 | HCurrentMethod* cached_current_method_; |
| 481 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 482 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 483 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 484 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 485 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 486 | }; |
| 487 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 488 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 489 | public: |
| 490 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 491 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 492 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 493 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 494 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 495 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 496 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 497 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 498 | |
| 499 | HBasicBlock* GetHeader() const { |
| 500 | return header_; |
| 501 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 502 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 503 | void SetHeader(HBasicBlock* block) { |
| 504 | header_ = block; |
| 505 | } |
| 506 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 507 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 508 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 509 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 510 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 511 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 512 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 515 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 516 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 517 | } |
| 518 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 519 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 520 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 521 | } |
| 522 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 523 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 524 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 525 | } |
| 526 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 527 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 528 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 529 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 530 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 533 | // Returns the lifetime position of the back edge that has the |
| 534 | // greatest lifetime position. |
| 535 | size_t GetLifetimeEnd() const; |
| 536 | |
| 537 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 538 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 539 | } |
| 540 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 541 | // Finds blocks that are part of this loop. Returns whether the loop is a natural loop, |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 542 | // that is the header dominates the back edge. |
| 543 | bool Populate(); |
| 544 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 545 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 546 | // Populate(). If there are no back edges left, the loop info is completely |
| 547 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 548 | // inner loops first. |
| 549 | void Update(); |
| 550 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 551 | // Returns whether this loop information contains `block`. |
| 552 | // Note that this loop information *must* be populated before entering this function. |
| 553 | bool Contains(const HBasicBlock& block) const; |
| 554 | |
| 555 | // Returns whether this loop information is an inner loop of `other`. |
| 556 | // Note that `other` *must* be populated before entering this function. |
| 557 | bool IsIn(const HLoopInformation& other) const; |
| 558 | |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 559 | // Returns true if instruction is not defined within this loop or any loop nested inside |
| 560 | // this loop. If must_dominate is set, only definitions that actually dominate the loop |
| 561 | // header can be invariant. Otherwise, any definition outside the loop, including |
| 562 | // definitions that appear after the loop, is invariant. |
| 563 | bool IsLoopInvariant(HInstruction* instruction, bool must_dominate) const; |
| 564 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 565 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 566 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 567 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 568 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 569 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 570 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 571 | // Internal recursive implementation of `Populate`. |
| 572 | void PopulateRecursive(HBasicBlock* block); |
| 573 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 574 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 575 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 576 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 577 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 578 | |
| 579 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 580 | }; |
| 581 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 582 | // Stores try/catch information for basic blocks. |
| 583 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 584 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 585 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 586 | public: |
| 587 | // Try block information constructor. |
| 588 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 589 | : try_entry_(&try_entry), |
| 590 | catch_dex_file_(nullptr), |
| 591 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 592 | DCHECK(try_entry_ != nullptr); |
| 593 | } |
| 594 | |
| 595 | // Catch block information constructor. |
| 596 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 597 | : try_entry_(nullptr), |
| 598 | catch_dex_file_(&dex_file), |
| 599 | catch_type_index_(catch_type_index) {} |
| 600 | |
| 601 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 602 | |
| 603 | const HTryBoundary& GetTryEntry() const { |
| 604 | DCHECK(IsTryBlock()); |
| 605 | return *try_entry_; |
| 606 | } |
| 607 | |
| 608 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 609 | |
| 610 | bool IsCatchAllTypeIndex() const { |
| 611 | DCHECK(IsCatchBlock()); |
| 612 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 613 | } |
| 614 | |
| 615 | uint16_t GetCatchTypeIndex() const { |
| 616 | DCHECK(IsCatchBlock()); |
| 617 | return catch_type_index_; |
| 618 | } |
| 619 | |
| 620 | const DexFile& GetCatchDexFile() const { |
| 621 | DCHECK(IsCatchBlock()); |
| 622 | return *catch_dex_file_; |
| 623 | } |
| 624 | |
| 625 | private: |
| 626 | // One of possibly several TryBoundary instructions entering the block's try. |
| 627 | // Only set for try blocks. |
| 628 | const HTryBoundary* try_entry_; |
| 629 | |
| 630 | // Exception type information. Only set for catch blocks. |
| 631 | const DexFile* catch_dex_file_; |
| 632 | const uint16_t catch_type_index_; |
| 633 | }; |
| 634 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 635 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 636 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 637 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 638 | // A block in a method. Contains the list of instructions represented |
| 639 | // as a double linked list. Each block knows its predecessors and |
| 640 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 641 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 642 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 643 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 644 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 645 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 646 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 647 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 648 | loop_information_(nullptr), |
| 649 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 650 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 651 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 652 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 653 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 654 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 655 | try_catch_information_(nullptr) { |
| 656 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 657 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 658 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 659 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 660 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 661 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 662 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 663 | } |
| 664 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 665 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 666 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 667 | } |
| 668 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 669 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 670 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 671 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 672 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 673 | return ContainsElement(successors_, block, start_from); |
| 674 | } |
| 675 | |
| 676 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 677 | return dominated_blocks_; |
| 678 | } |
| 679 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 680 | bool IsEntryBlock() const { |
| 681 | return graph_->GetEntryBlock() == this; |
| 682 | } |
| 683 | |
| 684 | bool IsExitBlock() const { |
| 685 | return graph_->GetExitBlock() == this; |
| 686 | } |
| 687 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 688 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 689 | bool IsSingleTryBoundary() const; |
| 690 | |
| 691 | // Returns true if this block emits nothing but a jump. |
| 692 | bool IsSingleJump() const { |
| 693 | HLoopInformation* loop_info = GetLoopInformation(); |
| 694 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 695 | // Back edges generate a suspend check. |
| 696 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 697 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 698 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 699 | void AddBackEdge(HBasicBlock* back_edge) { |
| 700 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 701 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 702 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 703 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 704 | loop_information_->AddBackEdge(back_edge); |
| 705 | } |
| 706 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 707 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 708 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 709 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 710 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 711 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 712 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 713 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 714 | HBasicBlock* GetDominator() const { return dominator_; } |
| 715 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 716 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 717 | |
| 718 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 719 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 720 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 721 | |
| 722 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 723 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 724 | } |
| 725 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 726 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 727 | |
| 728 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 729 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 732 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 733 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 734 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 735 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 736 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 737 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 738 | |
| 739 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 740 | successors_.push_back(block); |
| 741 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 744 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 745 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 746 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 747 | new_block->predecessors_.push_back(this); |
| 748 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 751 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 752 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 753 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 754 | new_block->successors_.push_back(this); |
| 755 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 758 | // Insert `this` between `predecessor` and `successor. This method |
| 759 | // preserves the indicies, and will update the first edge found between |
| 760 | // `predecessor` and `successor`. |
| 761 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 762 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 763 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 764 | successor->predecessors_[predecessor_index] = this; |
| 765 | predecessor->successors_[successor_index] = this; |
| 766 | successors_.push_back(successor); |
| 767 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 768 | } |
| 769 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 770 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 771 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 772 | } |
| 773 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 774 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 775 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 778 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 779 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 783 | predecessors_.push_back(block); |
| 784 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 785 | } |
| 786 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 787 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 788 | DCHECK_EQ(predecessors_.size(), 2u); |
| 789 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 790 | } |
| 791 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 792 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 793 | DCHECK_EQ(successors_.size(), 2u); |
| 794 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 795 | } |
| 796 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 797 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 798 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 799 | } |
| 800 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 801 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 802 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 803 | } |
| 804 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 805 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 806 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 807 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 812 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Returns whether the first occurrence of `predecessor` in the list of |
| 816 | // predecessors is at index `idx`. |
| 817 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 818 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 819 | return GetPredecessorIndexOf(predecessor) == idx; |
| 820 | } |
| 821 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 822 | // Create a new block between this block and its predecessors. The new block |
| 823 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 824 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 825 | // loop and try/catch information are not updated. |
| 826 | HBasicBlock* CreateImmediateDominator(); |
| 827 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 828 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 829 | // created, latter block. Note that this method will add the block to the |
| 830 | // graph, create a Goto at the end of the former block and will create an edge |
| 831 | // between the blocks. It will not, however, update the reverse post order or |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 832 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 833 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 834 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 835 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 836 | // created block. Note that this method just updates raw block information, |
| 837 | // like predecessors, successors, dominators, and instruction list. It does not |
| 838 | // update the graph, reverse post order, loop information, nor make sure the |
| 839 | // blocks are consistent (for example ending with a control flow instruction). |
| 840 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 841 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 842 | // Split catch block into two blocks after the original move-exception bytecode |
| 843 | // instruction, or at the beginning if not present. Returns the newly created, |
| 844 | // latter block, or nullptr if such block could not be created (must be dead |
| 845 | // in that case). Note that this method just updates raw block information, |
| 846 | // like predecessors, successors, dominators, and instruction list. It does not |
| 847 | // update the graph, reverse post order, loop information, nor make sure the |
| 848 | // blocks are consistent (for example ending with a control flow instruction). |
| 849 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 850 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 851 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 852 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 853 | // that this method does not update the graph, reverse post order, loop |
| 854 | // information, nor make sure the blocks are consistent (for example ending |
| 855 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 856 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 857 | |
| 858 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 859 | // of `this` are moved to `other`. |
| 860 | // Note that this method does not update the graph, reverse post order, loop |
| 861 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 862 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 863 | void ReplaceWith(HBasicBlock* other); |
| 864 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 865 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 866 | // order, links to predecessors, successors, dominators and deletes the block |
| 867 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 868 | // predecessor of `other` and vice versa. |
| 869 | void MergeWith(HBasicBlock* other); |
| 870 | |
| 871 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 872 | // removes it from all loops it is included in and eventually from the graph. |
| 873 | // The block must not dominate any other block. Predecessors and successors |
| 874 | // are safely updated. |
| 875 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 876 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 877 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 878 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 879 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 880 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 881 | // Replace instruction `initial` with `replacement` within this block. |
| 882 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 883 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 884 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 885 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 886 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 887 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 888 | // instruction is not in use and removes it from the use lists of its inputs. |
| 889 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 890 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 891 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 892 | |
| 893 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 894 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 895 | } |
| 896 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 897 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 898 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 899 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 902 | HLoopInformation* GetLoopInformation() const { |
| 903 | return loop_information_; |
| 904 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 905 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 906 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 907 | // loop_information if it is an outer loop of the passed loop information. |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 908 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 909 | void SetInLoop(HLoopInformation* info) { |
| 910 | if (IsLoopHeader()) { |
| 911 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 912 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 913 | loop_information_ = info; |
| 914 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 915 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 916 | // Note that a non loop header having a loop information means this loop information |
| 917 | // has already been populated |
| 918 | loop_information_ = info; |
| 919 | } else { |
| 920 | // Block is part of an inner loop. Do not update the loop information. |
| 921 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 922 | // at this point, because this method is being called while populating `info`. |
| 923 | } |
| 924 | } |
| 925 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 926 | // Raw update of the loop information. |
| 927 | void SetLoopInformation(HLoopInformation* info) { |
| 928 | loop_information_ = info; |
| 929 | } |
| 930 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 931 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 932 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 933 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 934 | |
| 935 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 936 | try_catch_information_ = try_catch_information; |
| 937 | } |
| 938 | |
| 939 | bool IsTryBlock() const { |
| 940 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 941 | } |
| 942 | |
| 943 | bool IsCatchBlock() const { |
| 944 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 945 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 946 | |
| 947 | // Returns the try entry that this block's successors should have. They will |
| 948 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 949 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 950 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 951 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 952 | bool HasThrowingInstructions() const; |
| 953 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 954 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 955 | bool Dominates(HBasicBlock* block) const; |
| 956 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 957 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 958 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 959 | |
| 960 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 961 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 962 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 963 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 964 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 965 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 966 | bool HasSinglePhi() const; |
| 967 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 968 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 969 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 970 | ArenaVector<HBasicBlock*> predecessors_; |
| 971 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 972 | HInstructionList instructions_; |
| 973 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 974 | HLoopInformation* loop_information_; |
| 975 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 976 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 977 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 978 | // The dex program counter of the first instruction of this block. |
| 979 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 980 | size_t lifetime_start_; |
| 981 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 982 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 983 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 984 | friend class HGraph; |
| 985 | friend class HInstruction; |
| 986 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 987 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 988 | }; |
| 989 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 990 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 991 | // from the innermost to the outermost. |
| 992 | class HLoopInformationOutwardIterator : public ValueObject { |
| 993 | public: |
| 994 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 995 | : current_(block.GetLoopInformation()) {} |
| 996 | |
| 997 | bool Done() const { return current_ == nullptr; } |
| 998 | |
| 999 | void Advance() { |
| 1000 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1001 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | HLoopInformation* Current() const { |
| 1005 | DCHECK(!Done()); |
| 1006 | return current_; |
| 1007 | } |
| 1008 | |
| 1009 | private: |
| 1010 | HLoopInformation* current_; |
| 1011 | |
| 1012 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1013 | }; |
| 1014 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1015 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1016 | M(Above, Condition) \ |
| 1017 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1018 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1019 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1020 | M(ArrayGet, Instruction) \ |
| 1021 | M(ArrayLength, Instruction) \ |
| 1022 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1023 | M(Below, Condition) \ |
| 1024 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1025 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1026 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1027 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1028 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1029 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1030 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1031 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1032 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1033 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1034 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1035 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1036 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1037 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1038 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1039 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1040 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1041 | M(FloatConstant, Constant) \ |
| 1042 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1043 | M(GreaterThan, Condition) \ |
| 1044 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1045 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1046 | M(InstanceFieldGet, Instruction) \ |
| 1047 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1048 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1049 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1050 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1051 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1052 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1053 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1054 | M(LessThan, Condition) \ |
| 1055 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1056 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1057 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1058 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1059 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1060 | M(Local, Instruction) \ |
| 1061 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1062 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1063 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1064 | M(Mul, BinaryOperation) \ |
| 1065 | M(Neg, UnaryOperation) \ |
| 1066 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1067 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1068 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1069 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1070 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1071 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1072 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1073 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1074 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1075 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1076 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1077 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1078 | M(Return, Instruction) \ |
| 1079 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1080 | M(Shl, BinaryOperation) \ |
| 1081 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1082 | M(StaticFieldGet, Instruction) \ |
| 1083 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1084 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1085 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1086 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1087 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1088 | M(StoreLocal, Instruction) \ |
| 1089 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1090 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1091 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1092 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1093 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1094 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1095 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1096 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1097 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1098 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1099 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1100 | #else |
| 1101 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1102 | M(ArmDexCacheArraysBase, Instruction) |
| 1103 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1104 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1105 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1106 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1107 | #else |
| 1108 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1109 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1110 | M(Arm64IntermediateAddress, Instruction) \ |
| 1111 | M(Arm64MultiplyAccumulate, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1112 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1113 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1114 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1115 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1116 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1117 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1118 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1119 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1120 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1121 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1122 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1123 | M(X86LoadFromConstantTable, Instruction) \ |
| 1124 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1125 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1126 | |
| 1127 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1128 | |
| 1129 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1130 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1131 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1132 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1133 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1134 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1135 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1136 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1137 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1138 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1139 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1140 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1141 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1142 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1143 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1144 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1145 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1146 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1147 | #undef FORWARD_DECLARATION |
| 1148 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1149 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1150 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1151 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1152 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1153 | H##type* As##type() OVERRIDE { return this; } \ |
| 1154 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1155 | return other->Is##type(); \ |
| 1156 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1157 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1158 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1159 | template <typename T> class HUseList; |
| 1160 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1161 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1162 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1163 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1164 | HUseListNode* GetPrevious() const { return prev_; } |
| 1165 | HUseListNode* GetNext() const { return next_; } |
| 1166 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1167 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1168 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1169 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1170 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1171 | HUseListNode(T user, size_t index) |
| 1172 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1173 | |
| 1174 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1175 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1176 | HUseListNode<T>* prev_; |
| 1177 | HUseListNode<T>* next_; |
| 1178 | |
| 1179 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1180 | |
| 1181 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1182 | }; |
| 1183 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1184 | template <typename T> |
| 1185 | class HUseList : public ValueObject { |
| 1186 | public: |
| 1187 | HUseList() : first_(nullptr) {} |
| 1188 | |
| 1189 | void Clear() { |
| 1190 | first_ = nullptr; |
| 1191 | } |
| 1192 | |
| 1193 | // Adds a new entry at the beginning of the use list and returns |
| 1194 | // the newly created node. |
| 1195 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1196 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1197 | if (IsEmpty()) { |
| 1198 | first_ = new_node; |
| 1199 | } else { |
| 1200 | first_->prev_ = new_node; |
| 1201 | new_node->next_ = first_; |
| 1202 | first_ = new_node; |
| 1203 | } |
| 1204 | return new_node; |
| 1205 | } |
| 1206 | |
| 1207 | HUseListNode<T>* GetFirst() const { |
| 1208 | return first_; |
| 1209 | } |
| 1210 | |
| 1211 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1212 | DCHECK(node != nullptr); |
| 1213 | DCHECK(Contains(node)); |
| 1214 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1215 | if (node->prev_ != nullptr) { |
| 1216 | node->prev_->next_ = node->next_; |
| 1217 | } |
| 1218 | if (node->next_ != nullptr) { |
| 1219 | node->next_->prev_ = node->prev_; |
| 1220 | } |
| 1221 | if (node == first_) { |
| 1222 | first_ = node->next_; |
| 1223 | } |
| 1224 | } |
| 1225 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1226 | bool Contains(const HUseListNode<T>* node) const { |
| 1227 | if (node == nullptr) { |
| 1228 | return false; |
| 1229 | } |
| 1230 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1231 | if (current == node) { |
| 1232 | return true; |
| 1233 | } |
| 1234 | } |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1238 | bool IsEmpty() const { |
| 1239 | return first_ == nullptr; |
| 1240 | } |
| 1241 | |
| 1242 | bool HasOnlyOneUse() const { |
| 1243 | return first_ != nullptr && first_->next_ == nullptr; |
| 1244 | } |
| 1245 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1246 | size_t SizeSlow() const { |
| 1247 | size_t count = 0; |
| 1248 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1249 | ++count; |
| 1250 | } |
| 1251 | return count; |
| 1252 | } |
| 1253 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1254 | private: |
| 1255 | HUseListNode<T>* first_; |
| 1256 | }; |
| 1257 | |
| 1258 | template<typename T> |
| 1259 | class HUseIterator : public ValueObject { |
| 1260 | public: |
| 1261 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1262 | |
| 1263 | bool Done() const { return current_ == nullptr; } |
| 1264 | |
| 1265 | void Advance() { |
| 1266 | DCHECK(!Done()); |
| 1267 | current_ = current_->GetNext(); |
| 1268 | } |
| 1269 | |
| 1270 | HUseListNode<T>* Current() const { |
| 1271 | DCHECK(!Done()); |
| 1272 | return current_; |
| 1273 | } |
| 1274 | |
| 1275 | private: |
| 1276 | HUseListNode<T>* current_; |
| 1277 | |
| 1278 | friend class HValue; |
| 1279 | }; |
| 1280 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1281 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1282 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1283 | // by the used instructions. |
| 1284 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1285 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1286 | public: |
| 1287 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1288 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1289 | |
| 1290 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1291 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1292 | DCHECK(instruction_ != nullptr); |
| 1293 | DCHECK(use_node_ != nullptr); |
| 1294 | DCHECK(old_record.use_node_ == nullptr); |
| 1295 | } |
| 1296 | |
| 1297 | HInstruction* GetInstruction() const { return instruction_; } |
| 1298 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1299 | |
| 1300 | private: |
| 1301 | // Instruction used by the user. |
| 1302 | HInstruction* instruction_; |
| 1303 | |
| 1304 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1305 | HUseListNode<T>* use_node_; |
| 1306 | }; |
| 1307 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1308 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1309 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1310 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1311 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1312 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1313 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1314 | * modify the value of a reference field read [although it may modify the |
| 1315 | * reference fetch prior to reading the field, which is represented by its own |
| 1316 | * write/read dependence]). The analysis makes conservative points-to |
| 1317 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1318 | * the same, and any reference read depends on any reference read without |
| 1319 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1320 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1321 | * The internal representation uses 38-bit and is described in the table below. |
| 1322 | * The first line indicates the side effect, and for field/array accesses the |
| 1323 | * second line indicates the type of the access (in the order of the |
| 1324 | * Primitive::Type enum). |
| 1325 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1326 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1327 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1328 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1329 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1330 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1331 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1332 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1333 | * |
| 1334 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1335 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1336 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1337 | class SideEffects : public ValueObject { |
| 1338 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1339 | SideEffects() : flags_(0) {} |
| 1340 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1341 | static SideEffects None() { |
| 1342 | return SideEffects(0); |
| 1343 | } |
| 1344 | |
| 1345 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1346 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1347 | } |
| 1348 | |
| 1349 | static SideEffects AllChanges() { |
| 1350 | return SideEffects(kAllChangeBits); |
| 1351 | } |
| 1352 | |
| 1353 | static SideEffects AllDependencies() { |
| 1354 | return SideEffects(kAllDependOnBits); |
| 1355 | } |
| 1356 | |
| 1357 | static SideEffects AllExceptGCDependency() { |
| 1358 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1359 | } |
| 1360 | |
| 1361 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1362 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1363 | } |
| 1364 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1365 | static SideEffects AllWrites() { |
| 1366 | return SideEffects(kAllWrites); |
| 1367 | } |
| 1368 | |
| 1369 | static SideEffects AllReads() { |
| 1370 | return SideEffects(kAllReads); |
| 1371 | } |
| 1372 | |
| 1373 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1374 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1375 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1376 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1377 | } |
| 1378 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1379 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1380 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1381 | } |
| 1382 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1383 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1384 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1385 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1386 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1390 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1391 | } |
| 1392 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1393 | static SideEffects CanTriggerGC() { |
| 1394 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1395 | } |
| 1396 | |
| 1397 | static SideEffects DependsOnGC() { |
| 1398 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1399 | } |
| 1400 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1401 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1402 | SideEffects Union(SideEffects other) const { |
| 1403 | return SideEffects(flags_ | other.flags_); |
| 1404 | } |
| 1405 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1406 | SideEffects Exclusion(SideEffects other) const { |
| 1407 | return SideEffects(flags_ & ~other.flags_); |
| 1408 | } |
| 1409 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1410 | void Add(SideEffects other) { |
| 1411 | flags_ |= other.flags_; |
| 1412 | } |
| 1413 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1414 | bool Includes(SideEffects other) const { |
| 1415 | return (other.flags_ & flags_) == other.flags_; |
| 1416 | } |
| 1417 | |
| 1418 | bool HasSideEffects() const { |
| 1419 | return (flags_ & kAllChangeBits); |
| 1420 | } |
| 1421 | |
| 1422 | bool HasDependencies() const { |
| 1423 | return (flags_ & kAllDependOnBits); |
| 1424 | } |
| 1425 | |
| 1426 | // Returns true if there are no side effects or dependencies. |
| 1427 | bool DoesNothing() const { |
| 1428 | return flags_ == 0; |
| 1429 | } |
| 1430 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1431 | // Returns true if something is written. |
| 1432 | bool DoesAnyWrite() const { |
| 1433 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1434 | } |
| 1435 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1436 | // Returns true if something is read. |
| 1437 | bool DoesAnyRead() const { |
| 1438 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1441 | // Returns true if potentially everything is written and read |
| 1442 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1443 | bool DoesAllReadWrite() const { |
| 1444 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1445 | } |
| 1446 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1447 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1448 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1451 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1452 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1453 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1454 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1458 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1459 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1460 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1461 | for (int s = kLastBit; s >= 0; s--) { |
| 1462 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1463 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1464 | // This is a bit for the GC side effect. |
| 1465 | if (current_bit_is_set) { |
| 1466 | flags += "GC"; |
| 1467 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1468 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1469 | } else { |
| 1470 | // This is a bit for the array/field analysis. |
| 1471 | // The underscore character stands for the 'can trigger GC' bit. |
| 1472 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1473 | if (current_bit_is_set) { |
| 1474 | flags += kDebug[s]; |
| 1475 | } |
| 1476 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1477 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1478 | flags += "|"; |
| 1479 | } |
| 1480 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1481 | } |
| 1482 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1485 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1486 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1487 | private: |
| 1488 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1489 | |
| 1490 | static constexpr int kFieldWriteOffset = 0; |
| 1491 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1492 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1493 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1494 | |
| 1495 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1496 | |
| 1497 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1498 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1499 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1500 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1501 | |
| 1502 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1503 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1504 | |
| 1505 | // Aliases. |
| 1506 | |
| 1507 | static_assert(kChangeBits == kDependOnBits, |
| 1508 | "the 'change' bits should match the 'depend on' bits."); |
| 1509 | |
| 1510 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1511 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1512 | static constexpr uint64_t kAllWrites = |
| 1513 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1514 | static constexpr uint64_t kAllReads = |
| 1515 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1516 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1517 | // Work around the fact that HIR aliases I/F and J/D. |
| 1518 | // TODO: remove this interceptor once HIR types are clean |
| 1519 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1520 | switch (type) { |
| 1521 | case Primitive::kPrimInt: |
| 1522 | case Primitive::kPrimFloat: |
| 1523 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1524 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1525 | case Primitive::kPrimLong: |
| 1526 | case Primitive::kPrimDouble: |
| 1527 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1528 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1529 | default: |
| 1530 | return TypeFlag(type, offset); |
| 1531 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1532 | } |
| 1533 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1534 | // Translates type to bit flag. |
| 1535 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1536 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1537 | const uint64_t one = 1; |
| 1538 | const int shift = type; // 0-based consecutive enum |
| 1539 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1540 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1541 | return one << (type + offset); |
| 1542 | } |
| 1543 | |
| 1544 | // Private constructor on direct flags value. |
| 1545 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1546 | |
| 1547 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1548 | }; |
| 1549 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1550 | // 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] | 1551 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1552 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1553 | HEnvironment(ArenaAllocator* arena, |
| 1554 | size_t number_of_vregs, |
| 1555 | const DexFile& dex_file, |
| 1556 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1557 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1558 | InvokeType invoke_type, |
| 1559 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1560 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1561 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1562 | parent_(nullptr), |
| 1563 | dex_file_(dex_file), |
| 1564 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1565 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1566 | invoke_type_(invoke_type), |
| 1567 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1568 | } |
| 1569 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1570 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1571 | : HEnvironment(arena, |
| 1572 | to_copy.Size(), |
| 1573 | to_copy.GetDexFile(), |
| 1574 | to_copy.GetMethodIdx(), |
| 1575 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1576 | to_copy.GetInvokeType(), |
| 1577 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1578 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1579 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1580 | if (parent_ != nullptr) { |
| 1581 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1582 | } else { |
| 1583 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1584 | parent_->CopyFrom(parent); |
| 1585 | if (parent->GetParent() != nullptr) { |
| 1586 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1587 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1588 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1591 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1592 | void CopyFrom(HEnvironment* environment); |
| 1593 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1594 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1595 | // input to the loop phi instead. This is for inserting instructions that |
| 1596 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1597 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1598 | |
| 1599 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1600 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1604 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1607 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1608 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1609 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1610 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1611 | HEnvironment* GetParent() const { return parent_; } |
| 1612 | |
| 1613 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1614 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1618 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | uint32_t GetDexPc() const { |
| 1622 | return dex_pc_; |
| 1623 | } |
| 1624 | |
| 1625 | uint32_t GetMethodIdx() const { |
| 1626 | return method_idx_; |
| 1627 | } |
| 1628 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1629 | InvokeType GetInvokeType() const { |
| 1630 | return invoke_type_; |
| 1631 | } |
| 1632 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1633 | const DexFile& GetDexFile() const { |
| 1634 | return dex_file_; |
| 1635 | } |
| 1636 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1637 | HInstruction* GetHolder() const { |
| 1638 | return holder_; |
| 1639 | } |
| 1640 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1641 | |
| 1642 | bool IsFromInlinedInvoke() const { |
| 1643 | return GetParent() != nullptr; |
| 1644 | } |
| 1645 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1646 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1647 | // Record instructions' use entries of this environment for constant-time removal. |
| 1648 | // It should only be called by HInstruction when a new environment use is added. |
| 1649 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1650 | DCHECK(env_use->GetUser() == this); |
| 1651 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1652 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1653 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1654 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1655 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1656 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1657 | HEnvironment* parent_; |
| 1658 | const DexFile& dex_file_; |
| 1659 | const uint32_t method_idx_; |
| 1660 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1661 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1662 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1663 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1664 | HInstruction* const holder_; |
| 1665 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1666 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1667 | |
| 1668 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1669 | }; |
| 1670 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1671 | class ReferenceTypeInfo : ValueObject { |
| 1672 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1673 | typedef Handle<mirror::Class> TypeHandle; |
| 1674 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1675 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1676 | // The constructor will check that the type_handle is valid. |
| 1677 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1680 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1681 | |
| 1682 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1683 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1686 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1687 | return IsValidHandle(type_handle_); |
| 1688 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1689 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1690 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1691 | |
| 1692 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1693 | DCHECK(IsValid()); |
| 1694 | return GetTypeHandle()->IsObjectClass(); |
| 1695 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1696 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1697 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1698 | DCHECK(IsValid()); |
| 1699 | return GetTypeHandle()->IsStringClass(); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1700 | } |
| 1701 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1702 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1703 | DCHECK(IsValid()); |
| 1704 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 1705 | } |
| 1706 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1707 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1708 | DCHECK(IsValid()); |
| 1709 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1710 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1711 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1712 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1713 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1714 | return GetTypeHandle()->IsArrayClass(); |
| 1715 | } |
| 1716 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1717 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1718 | DCHECK(IsValid()); |
| 1719 | return GetTypeHandle()->IsPrimitiveArray(); |
| 1720 | } |
| 1721 | |
| 1722 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1723 | DCHECK(IsValid()); |
| 1724 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 1725 | } |
| 1726 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1727 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1728 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1729 | if (!IsExact()) return false; |
| 1730 | if (!IsArrayClass()) return false; |
| 1731 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1732 | } |
| 1733 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1734 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1735 | DCHECK(IsValid()); |
| 1736 | if (!IsExact()) return false; |
| 1737 | if (!IsArrayClass()) return false; |
| 1738 | if (!rti.IsArrayClass()) return false; |
| 1739 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 1740 | rti.GetTypeHandle()->GetComponentType()); |
| 1741 | } |
| 1742 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1743 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1744 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1745 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1746 | DCHECK(IsValid()); |
| 1747 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1748 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1749 | } |
| 1750 | |
Calin Juravle | cdfed3d | 2015-10-26 14:05:01 +0000 | [diff] [blame] | 1751 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1752 | DCHECK(IsValid()); |
| 1753 | DCHECK(rti.IsValid()); |
| 1754 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 1755 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1756 | } |
| 1757 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1758 | // Returns true if the type information provide the same amount of details. |
| 1759 | // 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] | 1760 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1761 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1762 | if (!IsValid() && !rti.IsValid()) { |
| 1763 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1764 | return true; |
| 1765 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1766 | if (!IsValid() || !rti.IsValid()) { |
| 1767 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1768 | return false; |
| 1769 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1770 | return IsExact() == rti.IsExact() |
| 1771 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1772 | } |
| 1773 | |
| 1774 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1775 | ReferenceTypeInfo(); |
| 1776 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1777 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1778 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1779 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1780 | // 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] | 1781 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1782 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1783 | }; |
| 1784 | |
| 1785 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1786 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1787 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1788 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1789 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1790 | : previous_(nullptr), |
| 1791 | next_(nullptr), |
| 1792 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1793 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1794 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1795 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1796 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1797 | locations_(nullptr), |
| 1798 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1799 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1800 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1801 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1802 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1803 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1804 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1805 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1806 | enum InstructionKind { |
| 1807 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1808 | }; |
| 1809 | #undef DECLARE_KIND |
| 1810 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1811 | HInstruction* GetNext() const { return next_; } |
| 1812 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1813 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1814 | HInstruction* GetNextDisregardingMoves() const; |
| 1815 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1816 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1817 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1818 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1819 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1820 | bool IsInBlock() const { return block_ != nullptr; } |
| 1821 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1822 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1823 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1824 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1825 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1826 | |
| 1827 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1828 | virtual const char* DebugName() const = 0; |
| 1829 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1830 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1831 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1832 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1833 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1834 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1835 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1836 | |
| 1837 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1838 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1839 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1840 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1841 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1842 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1843 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1844 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1845 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1846 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1847 | // Does not apply for all instructions, but having this at top level greatly |
| 1848 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1849 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1850 | virtual bool CanBeNull() const { |
| 1851 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1852 | return true; |
| 1853 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1854 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1855 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1856 | return false; |
| 1857 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1858 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1859 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1860 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1861 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1862 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1863 | return reference_type_info_; |
| 1864 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1865 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1866 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1867 | DCHECK(user != nullptr); |
| 1868 | HUseListNode<HInstruction*>* use = |
| 1869 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1870 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1873 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1874 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1875 | HUseListNode<HEnvironment*>* env_use = |
| 1876 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1877 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1878 | } |
| 1879 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1880 | void RemoveAsUserOfInput(size_t input) { |
| 1881 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1882 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1883 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1884 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1885 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1886 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1887 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1888 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1889 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1890 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1891 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1892 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1893 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1894 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1895 | // Does this instruction strictly dominate `other_instruction`? |
| 1896 | // Returns false if this instruction and `other_instruction` are the same. |
| 1897 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1898 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1899 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1900 | int GetId() const { return id_; } |
| 1901 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1902 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1903 | int GetSsaIndex() const { return ssa_index_; } |
| 1904 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1905 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1906 | |
| 1907 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1908 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1909 | // Set the `environment_` field. Raw because this method does not |
| 1910 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1911 | void SetRawEnvironment(HEnvironment* environment) { |
| 1912 | DCHECK(environment_ == nullptr); |
| 1913 | DCHECK_EQ(environment->GetHolder(), this); |
| 1914 | environment_ = environment; |
| 1915 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1916 | |
| 1917 | // Set the environment of this instruction, copying it from `environment`. While |
| 1918 | // copying, the uses lists are being updated. |
| 1919 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1920 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1921 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1922 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1923 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1924 | if (environment->GetParent() != nullptr) { |
| 1925 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1926 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1927 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1928 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1929 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1930 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1931 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1932 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1933 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1934 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1935 | if (environment->GetParent() != nullptr) { |
| 1936 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1937 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1940 | // Returns the number of entries in the environment. Typically, that is the |
| 1941 | // number of dex registers in a method. It could be more in case of inlining. |
| 1942 | size_t EnvironmentSize() const; |
| 1943 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1944 | LocationSummary* GetLocations() const { return locations_; } |
| 1945 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1946 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1947 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1948 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1949 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1950 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1951 | // uses of this instruction by `other` are *not* updated. |
| 1952 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1953 | ReplaceWith(other); |
| 1954 | other->ReplaceInput(this, use_index); |
| 1955 | } |
| 1956 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1957 | // Move `this` instruction before `cursor`. |
| 1958 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1959 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 1960 | // Move `this` before its first user and out of any loops. If there is no |
| 1961 | // out-of-loop user that dominates all other users, move the instruction |
| 1962 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 1963 | // |
| 1964 | // This can be used only on non-throwing instructions with no side effects that |
| 1965 | // have at least one use but no environment uses. |
| 1966 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 1967 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1968 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1969 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1970 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1971 | virtual H##type* As##type() { return nullptr; } |
| 1972 | |
| 1973 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1974 | #undef INSTRUCTION_TYPE_CHECK |
| 1975 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1976 | // Returns whether the instruction can be moved within the graph. |
| 1977 | virtual bool CanBeMoved() const { return false; } |
| 1978 | |
| 1979 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1980 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1981 | return false; |
| 1982 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1983 | |
| 1984 | // Returns whether any data encoded in the two instructions is equal. |
| 1985 | // This method does not look at the inputs. Both instructions must be |
| 1986 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1987 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1988 | return false; |
| 1989 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1990 | |
| 1991 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1992 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1993 | // 2) Their inputs are identical. |
| 1994 | bool Equals(HInstruction* other) const; |
| 1995 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1996 | virtual InstructionKind GetKind() const = 0; |
| 1997 | |
| 1998 | virtual size_t ComputeHashCode() const { |
| 1999 | size_t result = GetKind(); |
| 2000 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2001 | result = (result * 31) + InputAt(i)->GetId(); |
| 2002 | } |
| 2003 | return result; |
| 2004 | } |
| 2005 | |
| 2006 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2007 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2008 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2009 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2010 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2011 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2012 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2013 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2014 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2015 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2016 | |
| 2017 | // Returns whether the code generation of the instruction will require to have access |
| 2018 | // to the current method. Such instructions are: |
| 2019 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2020 | // to walk the stack and have the current method stored at a specific stack address. |
| 2021 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2022 | // fields of the current method. |
| 2023 | bool NeedsCurrentMethod() const { |
| 2024 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2025 | } |
| 2026 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2027 | // Returns whether the code generation of the instruction will require to have access |
| 2028 | // to the dex cache of the current method's declaring class via the current method. |
| 2029 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2030 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2031 | // Does this instruction have any use in an environment before |
| 2032 | // control flow hits 'other'? |
| 2033 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2034 | |
| 2035 | // Remove all references to environment uses of this instruction. |
| 2036 | // The caller must ensure that this is safe to do. |
| 2037 | void RemoveEnvironmentUsers(); |
| 2038 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2039 | protected: |
| 2040 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2041 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2042 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2043 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2044 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2045 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2046 | HInstruction* previous_; |
| 2047 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2048 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2049 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2050 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2051 | // An instruction gets an id when it is added to the graph. |
| 2052 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2053 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2054 | int id_; |
| 2055 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2056 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2057 | int ssa_index_; |
| 2058 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2059 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2060 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2061 | |
| 2062 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2063 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2064 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2065 | // The environment associated with this instruction. Not null if the instruction |
| 2066 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2067 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2068 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2069 | // Set by the code generator. |
| 2070 | LocationSummary* locations_; |
| 2071 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2072 | // Set by the liveness analysis. |
| 2073 | LiveInterval* live_interval_; |
| 2074 | |
| 2075 | // Set by the liveness analysis, this is the position in a linear |
| 2076 | // order of blocks where this instruction's live interval start. |
| 2077 | size_t lifetime_position_; |
| 2078 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2079 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2080 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2081 | // TODO: for primitive types this should be marked as invalid. |
| 2082 | ReferenceTypeInfo reference_type_info_; |
| 2083 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2084 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2085 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2086 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2087 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2088 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2089 | |
| 2090 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2091 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2092 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2093 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2094 | class HInputIterator : public ValueObject { |
| 2095 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2096 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2097 | |
| 2098 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2099 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2100 | void Advance() { index_++; } |
| 2101 | |
| 2102 | private: |
| 2103 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2104 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2105 | |
| 2106 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2107 | }; |
| 2108 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2109 | class HInstructionIterator : public ValueObject { |
| 2110 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2111 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2112 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2113 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2116 | bool Done() const { return instruction_ == nullptr; } |
| 2117 | HInstruction* Current() const { return instruction_; } |
| 2118 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2119 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2120 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | private: |
| 2124 | HInstruction* instruction_; |
| 2125 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2126 | |
| 2127 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2128 | }; |
| 2129 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2130 | class HBackwardInstructionIterator : public ValueObject { |
| 2131 | public: |
| 2132 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2133 | : instruction_(instructions.last_instruction_) { |
| 2134 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2135 | } |
| 2136 | |
| 2137 | bool Done() const { return instruction_ == nullptr; } |
| 2138 | HInstruction* Current() const { return instruction_; } |
| 2139 | void Advance() { |
| 2140 | instruction_ = next_; |
| 2141 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2142 | } |
| 2143 | |
| 2144 | private: |
| 2145 | HInstruction* instruction_; |
| 2146 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2147 | |
| 2148 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2149 | }; |
| 2150 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2151 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2152 | class HTemplateInstruction: public HInstruction { |
| 2153 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2154 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2155 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2156 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2157 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2158 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2159 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2160 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2161 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2162 | DCHECK_LT(i, N); |
| 2163 | return inputs_[i]; |
| 2164 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2165 | |
| 2166 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2167 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2168 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2169 | } |
| 2170 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2171 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2172 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2173 | |
| 2174 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2175 | }; |
| 2176 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2177 | // HTemplateInstruction specialization for N=0. |
| 2178 | template<> |
| 2179 | class HTemplateInstruction<0>: public HInstruction { |
| 2180 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2181 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2182 | : HInstruction(side_effects, dex_pc) {} |
| 2183 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2184 | virtual ~HTemplateInstruction() {} |
| 2185 | |
| 2186 | size_t InputCount() const OVERRIDE { return 0; } |
| 2187 | |
| 2188 | protected: |
| 2189 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2190 | LOG(FATAL) << "Unreachable"; |
| 2191 | UNREACHABLE(); |
| 2192 | } |
| 2193 | |
| 2194 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2195 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2196 | LOG(FATAL) << "Unreachable"; |
| 2197 | UNREACHABLE(); |
| 2198 | } |
| 2199 | |
| 2200 | private: |
| 2201 | friend class SsaBuilder; |
| 2202 | }; |
| 2203 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2204 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2205 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2206 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2207 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2208 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2209 | virtual ~HExpression() {} |
| 2210 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2211 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2212 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2213 | protected: |
| 2214 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2215 | }; |
| 2216 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2217 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2218 | // instruction that branches to the exit block. |
| 2219 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2220 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2221 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2222 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2223 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2224 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2225 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2226 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2227 | |
| 2228 | private: |
| 2229 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2230 | }; |
| 2231 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2232 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2233 | // instruction that branches to the exit block. |
| 2234 | class HReturn : public HTemplateInstruction<1> { |
| 2235 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2236 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2237 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2238 | SetRawInputAt(0, value); |
| 2239 | } |
| 2240 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2241 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2242 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2243 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2244 | |
| 2245 | private: |
| 2246 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2247 | }; |
| 2248 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2249 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2250 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2251 | // exit block. |
| 2252 | class HExit : public HTemplateInstruction<0> { |
| 2253 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2254 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2255 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2256 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2257 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2258 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2259 | |
| 2260 | private: |
| 2261 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2262 | }; |
| 2263 | |
| 2264 | // Jumps from one block to another. |
| 2265 | class HGoto : public HTemplateInstruction<0> { |
| 2266 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2267 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2268 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2269 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2270 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2271 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2272 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2273 | } |
| 2274 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2275 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2276 | |
| 2277 | private: |
| 2278 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2279 | }; |
| 2280 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2281 | class HConstant : public HExpression<0> { |
| 2282 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2283 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2284 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2285 | |
| 2286 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2287 | |
| 2288 | virtual bool IsMinusOne() const { return false; } |
| 2289 | virtual bool IsZero() const { return false; } |
| 2290 | virtual bool IsOne() const { return false; } |
| 2291 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2292 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2293 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2294 | DECLARE_INSTRUCTION(Constant); |
| 2295 | |
| 2296 | private: |
| 2297 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2298 | }; |
| 2299 | |
| 2300 | class HNullConstant : public HConstant { |
| 2301 | public: |
| 2302 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2303 | return true; |
| 2304 | } |
| 2305 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2306 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2307 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2308 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2309 | |
| 2310 | DECLARE_INSTRUCTION(NullConstant); |
| 2311 | |
| 2312 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2313 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2314 | |
| 2315 | friend class HGraph; |
| 2316 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2317 | }; |
| 2318 | |
| 2319 | // Constants of the type int. Those can be from Dex instructions, or |
| 2320 | // synthesized (for example with the if-eqz instruction). |
| 2321 | class HIntConstant : public HConstant { |
| 2322 | public: |
| 2323 | int32_t GetValue() const { return value_; } |
| 2324 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2325 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2326 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2327 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2328 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2329 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2330 | DCHECK(other->IsIntConstant()); |
| 2331 | return other->AsIntConstant()->value_ == value_; |
| 2332 | } |
| 2333 | |
| 2334 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2335 | |
| 2336 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2337 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2338 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2339 | |
| 2340 | DECLARE_INSTRUCTION(IntConstant); |
| 2341 | |
| 2342 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2343 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2344 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2345 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2346 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2347 | |
| 2348 | const int32_t value_; |
| 2349 | |
| 2350 | friend class HGraph; |
| 2351 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2352 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2353 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2354 | }; |
| 2355 | |
| 2356 | class HLongConstant : public HConstant { |
| 2357 | public: |
| 2358 | int64_t GetValue() const { return value_; } |
| 2359 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2360 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2361 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2362 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2363 | DCHECK(other->IsLongConstant()); |
| 2364 | return other->AsLongConstant()->value_ == value_; |
| 2365 | } |
| 2366 | |
| 2367 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2368 | |
| 2369 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2370 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2371 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2372 | |
| 2373 | DECLARE_INSTRUCTION(LongConstant); |
| 2374 | |
| 2375 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2376 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2377 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2378 | |
| 2379 | const int64_t value_; |
| 2380 | |
| 2381 | friend class HGraph; |
| 2382 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2383 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2384 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2385 | // Conditional branch. A block ending with an HIf instruction must have |
| 2386 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2387 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2388 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2389 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2390 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2391 | SetRawInputAt(0, input); |
| 2392 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2393 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2394 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2395 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2396 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2397 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2398 | } |
| 2399 | |
| 2400 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2401 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2402 | } |
| 2403 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2404 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2405 | |
| 2406 | private: |
| 2407 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2408 | }; |
| 2409 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2410 | |
| 2411 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2412 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2413 | // non-exceptional control flow. |
| 2414 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2415 | // higher indices in no particular order. |
| 2416 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2417 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2418 | enum BoundaryKind { |
| 2419 | kEntry, |
| 2420 | kExit, |
| 2421 | }; |
| 2422 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2423 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2424 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2425 | |
| 2426 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2427 | |
| 2428 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2429 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2430 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2431 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2432 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2433 | } |
| 2434 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2435 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2436 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2437 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2438 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2439 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | // If not present already, adds `handler` to its block's list of exception |
| 2443 | // handlers. |
| 2444 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2445 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2446 | GetBlock()->AddSuccessor(handler); |
| 2447 | } |
| 2448 | } |
| 2449 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2450 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2451 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2452 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2453 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2454 | DECLARE_INSTRUCTION(TryBoundary); |
| 2455 | |
| 2456 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2457 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2458 | |
| 2459 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2460 | }; |
| 2461 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2462 | // Deoptimize to interpreter, upon checking a condition. |
| 2463 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2464 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2465 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2466 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2467 | SetRawInputAt(0, cond); |
| 2468 | } |
| 2469 | |
| 2470 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2471 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2472 | |
| 2473 | DECLARE_INSTRUCTION(Deoptimize); |
| 2474 | |
| 2475 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2476 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2477 | }; |
| 2478 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2479 | // Represents the ArtMethod that was passed as a first argument to |
| 2480 | // the method. It is used by instructions that depend on it, like |
| 2481 | // instructions that work with the dex cache. |
| 2482 | class HCurrentMethod : public HExpression<0> { |
| 2483 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2484 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2485 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2486 | |
| 2487 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2488 | |
| 2489 | private: |
| 2490 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2491 | }; |
| 2492 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2493 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2494 | // have one successor for each entry in the switch table, and the final successor |
| 2495 | // will be the block containing the next Dex opcode. |
| 2496 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2497 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2498 | HPackedSwitch(int32_t start_value, |
| 2499 | uint32_t num_entries, |
| 2500 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2501 | uint32_t dex_pc = kNoDexPc) |
| 2502 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2503 | start_value_(start_value), |
| 2504 | num_entries_(num_entries) { |
| 2505 | SetRawInputAt(0, input); |
| 2506 | } |
| 2507 | |
| 2508 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2509 | |
| 2510 | int32_t GetStartValue() const { return start_value_; } |
| 2511 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2512 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2513 | |
| 2514 | HBasicBlock* GetDefaultBlock() const { |
| 2515 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2516 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2517 | } |
| 2518 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2519 | |
| 2520 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2521 | const int32_t start_value_; |
| 2522 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2523 | |
| 2524 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2525 | }; |
| 2526 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2527 | class HUnaryOperation : public HExpression<1> { |
| 2528 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2529 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2530 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2531 | SetRawInputAt(0, input); |
| 2532 | } |
| 2533 | |
| 2534 | HInstruction* GetInput() const { return InputAt(0); } |
| 2535 | Primitive::Type GetResultType() const { return GetType(); } |
| 2536 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2537 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2538 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2539 | return true; |
| 2540 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2541 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2542 | // Try to statically evaluate `operation` and return a HConstant |
| 2543 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2544 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2545 | HConstant* TryStaticEvaluation() const; |
| 2546 | |
| 2547 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2548 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2549 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2550 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2551 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2552 | |
| 2553 | private: |
| 2554 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2555 | }; |
| 2556 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2557 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2558 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2559 | HBinaryOperation(Primitive::Type result_type, |
| 2560 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2561 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2562 | SideEffects side_effects = SideEffects::None(), |
| 2563 | uint32_t dex_pc = kNoDexPc) |
| 2564 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2565 | SetRawInputAt(0, left); |
| 2566 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2569 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2570 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2571 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2572 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2573 | virtual bool IsCommutative() const { return false; } |
| 2574 | |
| 2575 | // Put constant on the right. |
| 2576 | // Returns whether order is changed. |
| 2577 | bool OrderInputsWithConstantOnTheRight() { |
| 2578 | HInstruction* left = InputAt(0); |
| 2579 | HInstruction* right = InputAt(1); |
| 2580 | if (left->IsConstant() && !right->IsConstant()) { |
| 2581 | ReplaceInput(right, 0); |
| 2582 | ReplaceInput(left, 1); |
| 2583 | return true; |
| 2584 | } |
| 2585 | return false; |
| 2586 | } |
| 2587 | |
| 2588 | // Order inputs by instruction id, but favor constant on the right side. |
| 2589 | // This helps GVN for commutative ops. |
| 2590 | void OrderInputs() { |
| 2591 | DCHECK(IsCommutative()); |
| 2592 | HInstruction* left = InputAt(0); |
| 2593 | HInstruction* right = InputAt(1); |
| 2594 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2595 | return; |
| 2596 | } |
| 2597 | if (OrderInputsWithConstantOnTheRight()) { |
| 2598 | return; |
| 2599 | } |
| 2600 | // Order according to instruction id. |
| 2601 | if (left->GetId() > right->GetId()) { |
| 2602 | ReplaceInput(right, 0); |
| 2603 | ReplaceInput(left, 1); |
| 2604 | } |
| 2605 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2606 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2607 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2608 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2609 | return true; |
| 2610 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2611 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2612 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2613 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2614 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2615 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2616 | |
| 2617 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2618 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2619 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2620 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2621 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2622 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2623 | return nullptr; |
| 2624 | } |
| 2625 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2626 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2627 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2628 | return nullptr; |
| 2629 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2630 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2631 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| 2632 | VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; |
| 2633 | return nullptr; |
| 2634 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2635 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2636 | // 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] | 2637 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2638 | HConstant* GetConstantRight() const; |
| 2639 | |
| 2640 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2641 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2642 | HInstruction* GetLeastConstantLeft() const; |
| 2643 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2644 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2645 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2646 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2647 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2648 | }; |
| 2649 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2650 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2651 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2652 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2653 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2654 | kGtBias, // return 1 for NaN comparisons |
| 2655 | kLtBias, // return -1 for NaN comparisons |
| 2656 | }; |
| 2657 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2658 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2659 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2660 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2661 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2662 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2663 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2664 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2665 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2666 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2667 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2668 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2669 | // `instruction`, and disregard moves in between. |
| 2670 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2671 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2672 | DECLARE_INSTRUCTION(Condition); |
| 2673 | |
| 2674 | virtual IfCondition GetCondition() const = 0; |
| 2675 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2676 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2677 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2678 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2679 | |
| 2680 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2681 | |
| 2682 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2683 | return bias_ == other->AsCondition()->bias_; |
| 2684 | } |
| 2685 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2686 | bool IsFPConditionTrueIfNaN() const { |
| 2687 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2688 | IfCondition if_cond = GetCondition(); |
| 2689 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2690 | } |
| 2691 | |
| 2692 | bool IsFPConditionFalseIfNaN() const { |
| 2693 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2694 | IfCondition if_cond = GetCondition(); |
| 2695 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2696 | } |
| 2697 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2698 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2699 | // For register allocation purposes, returns whether this instruction needs to be |
| 2700 | // materialized (that is, not just be in the processor flags). |
| 2701 | bool needs_materialization_; |
| 2702 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2703 | // Needed if we merge a HCompare into a HCondition. |
| 2704 | ComparisonBias bias_; |
| 2705 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2706 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2707 | }; |
| 2708 | |
| 2709 | // Instruction to check if two inputs are equal to each other. |
| 2710 | class HEqual : public HCondition { |
| 2711 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2712 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2713 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2714 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2715 | bool IsCommutative() const OVERRIDE { return true; } |
| 2716 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2717 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2718 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2719 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2720 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2721 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2722 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2723 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2724 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2725 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2726 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2727 | return GetBlock()->GetGraph()->GetIntConstant(1); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2728 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2729 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2730 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2731 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2732 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2733 | return kCondEQ; |
| 2734 | } |
| 2735 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2736 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2737 | return kCondNE; |
| 2738 | } |
| 2739 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2740 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2741 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2742 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2743 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2744 | }; |
| 2745 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2746 | class HNotEqual : public HCondition { |
| 2747 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2748 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2749 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2750 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2751 | bool IsCommutative() const OVERRIDE { return true; } |
| 2752 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2753 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2754 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2755 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2756 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2757 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2758 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2759 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2760 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2761 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2762 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2763 | return GetBlock()->GetGraph()->GetIntConstant(0); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2764 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2765 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2766 | DECLARE_INSTRUCTION(NotEqual); |
| 2767 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2768 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2769 | return kCondNE; |
| 2770 | } |
| 2771 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2772 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2773 | return kCondEQ; |
| 2774 | } |
| 2775 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2776 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2777 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2778 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2779 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2780 | }; |
| 2781 | |
| 2782 | class HLessThan : public HCondition { |
| 2783 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2784 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2785 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2786 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2787 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2788 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2789 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2790 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2791 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2792 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2793 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2794 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2795 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2796 | DECLARE_INSTRUCTION(LessThan); |
| 2797 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2798 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2799 | return kCondLT; |
| 2800 | } |
| 2801 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2802 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2803 | return kCondGE; |
| 2804 | } |
| 2805 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2806 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2807 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2808 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2809 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2810 | }; |
| 2811 | |
| 2812 | class HLessThanOrEqual : public HCondition { |
| 2813 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2814 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2815 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2816 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2817 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2818 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2819 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2820 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2821 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2822 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2823 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2824 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2825 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2826 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2827 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2828 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2829 | return kCondLE; |
| 2830 | } |
| 2831 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2832 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2833 | return kCondGT; |
| 2834 | } |
| 2835 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2836 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2837 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2838 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2839 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2840 | }; |
| 2841 | |
| 2842 | class HGreaterThan : public HCondition { |
| 2843 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2844 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2845 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2846 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2847 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2848 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2849 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2850 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2851 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2852 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2853 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2854 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2855 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2856 | DECLARE_INSTRUCTION(GreaterThan); |
| 2857 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2858 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2859 | return kCondGT; |
| 2860 | } |
| 2861 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2862 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2863 | return kCondLE; |
| 2864 | } |
| 2865 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2866 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2867 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2868 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2869 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2870 | }; |
| 2871 | |
| 2872 | class HGreaterThanOrEqual : public HCondition { |
| 2873 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2874 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2875 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2876 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2877 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2878 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2879 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2880 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2881 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2882 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2883 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2884 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2885 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2886 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2887 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2888 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2889 | return kCondGE; |
| 2890 | } |
| 2891 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2892 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2893 | return kCondLT; |
| 2894 | } |
| 2895 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2896 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2897 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2898 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2899 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2900 | }; |
| 2901 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2902 | class HBelow : public HCondition { |
| 2903 | public: |
| 2904 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2905 | : HCondition(first, second, dex_pc) {} |
| 2906 | |
| 2907 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2908 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2909 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2910 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2911 | } |
| 2912 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2913 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2914 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2915 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2916 | } |
| 2917 | |
| 2918 | DECLARE_INSTRUCTION(Below); |
| 2919 | |
| 2920 | IfCondition GetCondition() const OVERRIDE { |
| 2921 | return kCondB; |
| 2922 | } |
| 2923 | |
| 2924 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2925 | return kCondAE; |
| 2926 | } |
| 2927 | |
| 2928 | private: |
| 2929 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2930 | |
| 2931 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 2932 | }; |
| 2933 | |
| 2934 | class HBelowOrEqual : public HCondition { |
| 2935 | public: |
| 2936 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2937 | : HCondition(first, second, dex_pc) {} |
| 2938 | |
| 2939 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2940 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2941 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2942 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2943 | } |
| 2944 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2945 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2946 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2947 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2948 | } |
| 2949 | |
| 2950 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 2951 | |
| 2952 | IfCondition GetCondition() const OVERRIDE { |
| 2953 | return kCondBE; |
| 2954 | } |
| 2955 | |
| 2956 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2957 | return kCondA; |
| 2958 | } |
| 2959 | |
| 2960 | private: |
| 2961 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2962 | |
| 2963 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 2964 | }; |
| 2965 | |
| 2966 | class HAbove : public HCondition { |
| 2967 | public: |
| 2968 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2969 | : HCondition(first, second, dex_pc) {} |
| 2970 | |
| 2971 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2972 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2973 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2974 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2975 | } |
| 2976 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2977 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2978 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2979 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2980 | } |
| 2981 | |
| 2982 | DECLARE_INSTRUCTION(Above); |
| 2983 | |
| 2984 | IfCondition GetCondition() const OVERRIDE { |
| 2985 | return kCondA; |
| 2986 | } |
| 2987 | |
| 2988 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2989 | return kCondBE; |
| 2990 | } |
| 2991 | |
| 2992 | private: |
| 2993 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2994 | |
| 2995 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 2996 | }; |
| 2997 | |
| 2998 | class HAboveOrEqual : public HCondition { |
| 2999 | public: |
| 3000 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3001 | : HCondition(first, second, dex_pc) {} |
| 3002 | |
| 3003 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3004 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3005 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3006 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3007 | } |
| 3008 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3009 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3010 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3011 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3012 | } |
| 3013 | |
| 3014 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3015 | |
| 3016 | IfCondition GetCondition() const OVERRIDE { |
| 3017 | return kCondAE; |
| 3018 | } |
| 3019 | |
| 3020 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3021 | return kCondB; |
| 3022 | } |
| 3023 | |
| 3024 | private: |
| 3025 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3026 | |
| 3027 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3028 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3029 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3030 | // Instruction to check how two inputs compare to each other. |
| 3031 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3032 | class HCompare : public HBinaryOperation { |
| 3033 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3034 | HCompare(Primitive::Type type, |
| 3035 | HInstruction* first, |
| 3036 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3037 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3038 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3039 | : HBinaryOperation(Primitive::kPrimInt, |
| 3040 | first, |
| 3041 | second, |
| 3042 | SideEffectsForArchRuntimeCalls(type), |
| 3043 | dex_pc), |
| 3044 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3045 | DCHECK_EQ(type, first->GetType()); |
| 3046 | DCHECK_EQ(type, second->GetType()); |
| 3047 | } |
| 3048 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3049 | template <typename T> |
| 3050 | 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] | 3051 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3052 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3053 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3054 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3055 | } |
| 3056 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3057 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3058 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3059 | } |
| 3060 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3061 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3062 | return bias_ == other->AsCompare()->bias_; |
| 3063 | } |
| 3064 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3065 | ComparisonBias GetBias() const { return bias_; } |
| 3066 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3067 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3068 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3069 | |
| 3070 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3071 | // MIPS64 uses a runtime call for FP comparisons. |
| 3072 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3073 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3074 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3075 | DECLARE_INSTRUCTION(Compare); |
| 3076 | |
| 3077 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3078 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3079 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3080 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3081 | }; |
| 3082 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3083 | // A local in the graph. Corresponds to a Dex register. |
| 3084 | class HLocal : public HTemplateInstruction<0> { |
| 3085 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3086 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3087 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3088 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3089 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3090 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3091 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3092 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3093 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3094 | // The Dex register number. |
| 3095 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3096 | |
| 3097 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3098 | }; |
| 3099 | |
| 3100 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3101 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3102 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3103 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3104 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3105 | SetRawInputAt(0, local); |
| 3106 | } |
| 3107 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3108 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3109 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3110 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3111 | |
| 3112 | private: |
| 3113 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3114 | }; |
| 3115 | |
| 3116 | // Store a value in a given local. This instruction has two inputs: the value |
| 3117 | // and the local. |
| 3118 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3119 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3120 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3121 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3122 | SetRawInputAt(0, local); |
| 3123 | SetRawInputAt(1, value); |
| 3124 | } |
| 3125 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3126 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3127 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3128 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3129 | |
| 3130 | private: |
| 3131 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3132 | }; |
| 3133 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3134 | class HFloatConstant : public HConstant { |
| 3135 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3136 | float GetValue() const { return value_; } |
| 3137 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3138 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3139 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3140 | } |
| 3141 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3142 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3143 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3144 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3147 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3148 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3149 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3150 | 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] | 3151 | } |
| 3152 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3153 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3154 | } |
| 3155 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3156 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3157 | } |
| 3158 | bool IsNaN() const { |
| 3159 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3162 | DECLARE_INSTRUCTION(FloatConstant); |
| 3163 | |
| 3164 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3165 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3166 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3167 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3168 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3169 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3170 | const float value_; |
| 3171 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3172 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3173 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3174 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3175 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3176 | }; |
| 3177 | |
| 3178 | class HDoubleConstant : public HConstant { |
| 3179 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3180 | double GetValue() const { return value_; } |
| 3181 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3182 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3183 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3184 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3185 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3186 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3187 | } |
| 3188 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3189 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3190 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3191 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3192 | 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] | 3193 | } |
| 3194 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3195 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3196 | } |
| 3197 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3198 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3199 | } |
| 3200 | bool IsNaN() const { |
| 3201 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3202 | } |
| 3203 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3204 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3205 | |
| 3206 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3207 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3208 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3209 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3210 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3211 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3212 | const double value_; |
| 3213 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3214 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3215 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3216 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3217 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3218 | }; |
| 3219 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3220 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3221 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3222 | #include "intrinsics_list.h" |
| 3223 | kNone, |
| 3224 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3225 | #undef INTRINSICS_LIST |
| 3226 | #undef OPTIMIZING_INTRINSICS |
| 3227 | }; |
| 3228 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3229 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3230 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3231 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3232 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3233 | }; |
| 3234 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3235 | class HInvoke : public HInstruction { |
| 3236 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3237 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3238 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3239 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3240 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3241 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3242 | SetRawInputAt(index, argument); |
| 3243 | } |
| 3244 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3245 | // Return the number of arguments. This number can be lower than |
| 3246 | // the number of inputs returned by InputCount(), as some invoke |
| 3247 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3248 | // inputs at the end of their list of inputs. |
| 3249 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3250 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3251 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3252 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3253 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3254 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3255 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3256 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3257 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3258 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3259 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3260 | return intrinsic_; |
| 3261 | } |
| 3262 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3263 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3264 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3265 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3266 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3267 | } |
| 3268 | |
| 3269 | bool CanThrow() const OVERRIDE { return true; } |
| 3270 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3271 | uint32_t* GetIntrinsicOptimizations() { |
| 3272 | return &intrinsic_optimizations_; |
| 3273 | } |
| 3274 | |
| 3275 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3276 | return &intrinsic_optimizations_; |
| 3277 | } |
| 3278 | |
| 3279 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3280 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3281 | DECLARE_INSTRUCTION(Invoke); |
| 3282 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3283 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3284 | HInvoke(ArenaAllocator* arena, |
| 3285 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3286 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3287 | Primitive::Type return_type, |
| 3288 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3289 | uint32_t dex_method_index, |
| 3290 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3291 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3292 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3293 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3294 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3295 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3296 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3297 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3298 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3299 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3300 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3301 | } |
| 3302 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3303 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3304 | return inputs_[index]; |
| 3305 | } |
| 3306 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3307 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3308 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3311 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3312 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3313 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3314 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3315 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3316 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3317 | |
| 3318 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3319 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3320 | |
| 3321 | private: |
| 3322 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3323 | }; |
| 3324 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3325 | class HInvokeUnresolved : public HInvoke { |
| 3326 | public: |
| 3327 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3328 | uint32_t number_of_arguments, |
| 3329 | Primitive::Type return_type, |
| 3330 | uint32_t dex_pc, |
| 3331 | uint32_t dex_method_index, |
| 3332 | InvokeType invoke_type) |
| 3333 | : HInvoke(arena, |
| 3334 | number_of_arguments, |
| 3335 | 0u /* number_of_other_inputs */, |
| 3336 | return_type, |
| 3337 | dex_pc, |
| 3338 | dex_method_index, |
| 3339 | invoke_type) { |
| 3340 | } |
| 3341 | |
| 3342 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3343 | |
| 3344 | private: |
| 3345 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3346 | }; |
| 3347 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3348 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3349 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3350 | // Requirements of this method call regarding the class |
| 3351 | // initialization (clinit) check of its declaring class. |
| 3352 | enum class ClinitCheckRequirement { |
| 3353 | kNone, // Class already initialized. |
| 3354 | kExplicit, // Static call having explicit clinit check as last input. |
| 3355 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3356 | }; |
| 3357 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3358 | // Determines how to load the target ArtMethod*. |
| 3359 | enum class MethodLoadKind { |
| 3360 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3361 | kStringInit, |
| 3362 | |
| 3363 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3364 | kRecursive, |
| 3365 | |
| 3366 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3367 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3368 | kDirectAddress, |
| 3369 | |
| 3370 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3371 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3372 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3373 | // the image relocatable or not. |
| 3374 | kDirectAddressWithFixup, |
| 3375 | |
| 3376 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3377 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3378 | // may cause class initialization (the entry may point to a resolution method), |
| 3379 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3380 | kDexCachePcRelative, |
| 3381 | |
| 3382 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3383 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3384 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3385 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3386 | kDexCacheViaMethod, |
| 3387 | }; |
| 3388 | |
| 3389 | // Determines the location of the code pointer. |
| 3390 | enum class CodePtrLocation { |
| 3391 | // Recursive call, use local PC-relative call instruction. |
| 3392 | kCallSelf, |
| 3393 | |
| 3394 | // Use PC-relative call instruction patched at link time. |
| 3395 | // Used for calls within an oat file, boot->boot or app->app. |
| 3396 | kCallPCRelative, |
| 3397 | |
| 3398 | // Call to a known target address, embed the direct address in code. |
| 3399 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3400 | kCallDirect, |
| 3401 | |
| 3402 | // Call to a target address that will be known at link time, embed the direct |
| 3403 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3404 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3405 | // the image relocatable or not. |
| 3406 | kCallDirectWithFixup, |
| 3407 | |
| 3408 | // Use code pointer from the ArtMethod*. |
| 3409 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3410 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3411 | kCallArtMethod, |
| 3412 | }; |
| 3413 | |
| 3414 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3415 | MethodLoadKind method_load_kind; |
| 3416 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3417 | // The method load data holds |
| 3418 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3419 | // Note that there are multiple string init methods, each having its own offset. |
| 3420 | // - the method address for kDirectAddress |
| 3421 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3422 | uint64_t method_load_data; |
| 3423 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3424 | }; |
| 3425 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3426 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3427 | uint32_t number_of_arguments, |
| 3428 | Primitive::Type return_type, |
| 3429 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3430 | uint32_t method_index, |
| 3431 | MethodReference target_method, |
| 3432 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3433 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3434 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3435 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3436 | : HInvoke(arena, |
| 3437 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3438 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3439 | // potentially one other if the clinit check is explicit, and potentially |
| 3440 | // one other if the method is a string factory. |
| 3441 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3442 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3443 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3444 | return_type, |
| 3445 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3446 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3447 | original_invoke_type), |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3448 | optimized_invoke_type_(optimized_invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3449 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3450 | target_method_(target_method), |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3451 | dispatch_info_(dispatch_info) { } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3452 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3453 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3454 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3455 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3456 | |
| 3457 | // Using the current method is the default and once we find a better |
| 3458 | // method load kind, we should not go back to using the current method. |
| 3459 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3460 | |
| 3461 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3462 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3463 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3464 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3465 | dispatch_info_ = dispatch_info; |
| 3466 | } |
| 3467 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3468 | void AddSpecialInput(HInstruction* input) { |
| 3469 | // We allow only one special input. |
| 3470 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3471 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3472 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3473 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3474 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3475 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3476 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3477 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3478 | // TODO: for intrinsics we can generate implicit null checks. |
| 3479 | return false; |
| 3480 | } |
| 3481 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3482 | bool CanBeNull() const OVERRIDE { |
| 3483 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3484 | } |
| 3485 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3486 | // Get the index of the special input, if any. |
| 3487 | // |
| 3488 | // If the invoke IsStringInit(), it initially has a HFakeString special argument |
| 3489 | // which is removed by the instruction simplifier; if the invoke HasCurrentMethodInput(), |
| 3490 | // the "special input" is the current method pointer; otherwise there may be one |
| 3491 | // platform-specific special input, such as PC-relative addressing base. |
| 3492 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
| 3493 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3494 | InvokeType GetOptimizedInvokeType() const { return optimized_invoke_type_; } |
| 3495 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
| 3496 | optimized_invoke_type_ = invoke_type; |
| 3497 | } |
| 3498 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3499 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3500 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3501 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3502 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3503 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3504 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3505 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3506 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3507 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3508 | bool HasCurrentMethodInput() const { |
| 3509 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3510 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3511 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3512 | return true; |
| 3513 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3514 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3515 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3516 | return false; |
| 3517 | } |
| 3518 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3519 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3520 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3521 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3522 | |
| 3523 | int32_t GetStringInitOffset() const { |
| 3524 | DCHECK(IsStringInit()); |
| 3525 | return dispatch_info_.method_load_data; |
| 3526 | } |
| 3527 | |
| 3528 | uint64_t GetMethodAddress() const { |
| 3529 | DCHECK(HasMethodAddress()); |
| 3530 | return dispatch_info_.method_load_data; |
| 3531 | } |
| 3532 | |
| 3533 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3534 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3535 | return dispatch_info_.method_load_data; |
| 3536 | } |
| 3537 | |
| 3538 | uint64_t GetDirectCodePtr() const { |
| 3539 | DCHECK(HasDirectCodePtr()); |
| 3540 | return dispatch_info_.direct_code_ptr; |
| 3541 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3542 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3543 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3544 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3545 | // Is this instruction a call to a static method? |
| 3546 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3547 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3548 | } |
| 3549 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3550 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3551 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3552 | // instruction; only relevant for static calls with explicit clinit check. |
| 3553 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3554 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3555 | size_t last_input_index = InputCount() - 1; |
| 3556 | HInstruction* last_input = InputAt(last_input_index); |
| 3557 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3558 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3559 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3560 | inputs_.pop_back(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3561 | clinit_check_requirement_ = new_requirement; |
| 3562 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3563 | } |
| 3564 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3565 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3566 | if (!IsStringInit()) return false; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3567 | DCHECK(!HasCurrentMethodInput()); |
| 3568 | if (InputCount() == (number_of_arguments_)) return false; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3569 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3570 | } |
| 3571 | |
| 3572 | void RemoveFakeStringArgumentAsLastInput() { |
| 3573 | DCHECK(IsStringInit()); |
| 3574 | size_t last_input_index = InputCount() - 1; |
| 3575 | HInstruction* last_input = InputAt(last_input_index); |
| 3576 | DCHECK(last_input != nullptr); |
| 3577 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3578 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3579 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3580 | } |
| 3581 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3582 | // 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] | 3583 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3584 | bool IsStaticWithExplicitClinitCheck() const { |
| 3585 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3586 | } |
| 3587 | |
| 3588 | // Is this a call to a static method whose declaring class has an |
| 3589 | // implicit intialization check requirement? |
| 3590 | bool IsStaticWithImplicitClinitCheck() const { |
| 3591 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3592 | } |
| 3593 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3594 | // Does this method load kind need the current method as an input? |
| 3595 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 3596 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 3597 | } |
| 3598 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3599 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3600 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3601 | protected: |
| 3602 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3603 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3604 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3605 | HInstruction* input = input_record.GetInstruction(); |
| 3606 | // `input` is the last input of a static invoke marked as having |
| 3607 | // an explicit clinit check. It must either be: |
| 3608 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3609 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3610 | DCHECK(input != nullptr); |
| 3611 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3612 | } |
| 3613 | return input_record; |
| 3614 | } |
| 3615 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3616 | void InsertInputAt(size_t index, HInstruction* input); |
| 3617 | void RemoveInputAt(size_t index); |
| 3618 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3619 | private: |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3620 | InvokeType optimized_invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3621 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3622 | // The target method may refer to different dex file or method index than the original |
| 3623 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3624 | // in derived class to increase visibility. |
| 3625 | MethodReference target_method_; |
| 3626 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3627 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3628 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3629 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 3630 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3631 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3632 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3633 | class HInvokeVirtual : public HInvoke { |
| 3634 | public: |
| 3635 | HInvokeVirtual(ArenaAllocator* arena, |
| 3636 | uint32_t number_of_arguments, |
| 3637 | Primitive::Type return_type, |
| 3638 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3639 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3640 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3641 | : HInvoke(arena, number_of_arguments, 0u, return_type, dex_pc, dex_method_index, kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3642 | vtable_index_(vtable_index) {} |
| 3643 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3644 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3645 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3646 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3647 | } |
| 3648 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3649 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3650 | |
| 3651 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3652 | |
| 3653 | private: |
| 3654 | const uint32_t vtable_index_; |
| 3655 | |
| 3656 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3657 | }; |
| 3658 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3659 | class HInvokeInterface : public HInvoke { |
| 3660 | public: |
| 3661 | HInvokeInterface(ArenaAllocator* arena, |
| 3662 | uint32_t number_of_arguments, |
| 3663 | Primitive::Type return_type, |
| 3664 | uint32_t dex_pc, |
| 3665 | uint32_t dex_method_index, |
| 3666 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3667 | : 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] | 3668 | imt_index_(imt_index) {} |
| 3669 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3670 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3671 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3672 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3673 | } |
| 3674 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3675 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3676 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3677 | |
| 3678 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3679 | |
| 3680 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3681 | const uint32_t imt_index_; |
| 3682 | |
| 3683 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3684 | }; |
| 3685 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3686 | class HNewInstance : public HExpression<2> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3687 | public: |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3688 | HNewInstance(HInstruction* cls, |
| 3689 | HCurrentMethod* current_method, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3690 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3691 | uint16_t type_index, |
| 3692 | const DexFile& dex_file, |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3693 | bool can_throw, |
| 3694 | bool finalizable, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3695 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3696 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3697 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3698 | dex_file_(dex_file), |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3699 | can_throw_(can_throw), |
| 3700 | finalizable_(finalizable), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3701 | entrypoint_(entrypoint) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3702 | SetRawInputAt(0, cls); |
| 3703 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3704 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3705 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3706 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3707 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3708 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3709 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3710 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3711 | |
| 3712 | // It may throw when called on type that's not instantiable/accessible. |
| 3713 | // It can throw OOME. |
| 3714 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
| 3715 | bool CanThrow() const OVERRIDE { return can_throw_ || true; } |
| 3716 | |
| 3717 | bool IsFinalizable() const { return finalizable_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3718 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3719 | bool CanBeNull() const OVERRIDE { return false; } |
| 3720 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3721 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3722 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3723 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3724 | entrypoint_ = entrypoint; |
| 3725 | } |
| 3726 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3727 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3728 | |
| 3729 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3730 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3731 | const DexFile& dex_file_; |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3732 | const bool can_throw_; |
| 3733 | const bool finalizable_; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3734 | QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3735 | |
| 3736 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3737 | }; |
| 3738 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3739 | class HNeg : public HUnaryOperation { |
| 3740 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3741 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3742 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3743 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3744 | template <typename T> T Compute(T x) const { return -x; } |
| 3745 | |
| 3746 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3747 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3748 | } |
| 3749 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3750 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3751 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3752 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3753 | DECLARE_INSTRUCTION(Neg); |
| 3754 | |
| 3755 | private: |
| 3756 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3757 | }; |
| 3758 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3759 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3760 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3761 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3762 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3763 | uint32_t dex_pc, |
| 3764 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3765 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3766 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3767 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3768 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3769 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3770 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3771 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3772 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3773 | } |
| 3774 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3775 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3776 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3777 | |
| 3778 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3779 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3780 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3781 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3782 | bool CanThrow() const OVERRIDE { return true; } |
| 3783 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3784 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3785 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3786 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3787 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3788 | DECLARE_INSTRUCTION(NewArray); |
| 3789 | |
| 3790 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3791 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3792 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3793 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3794 | |
| 3795 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3796 | }; |
| 3797 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3798 | class HAdd : public HBinaryOperation { |
| 3799 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3800 | HAdd(Primitive::Type result_type, |
| 3801 | HInstruction* left, |
| 3802 | HInstruction* right, |
| 3803 | uint32_t dex_pc = kNoDexPc) |
| 3804 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3805 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3806 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3807 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3808 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3809 | |
| 3810 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3811 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3812 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3813 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3814 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3815 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3816 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3817 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3818 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3819 | DECLARE_INSTRUCTION(Add); |
| 3820 | |
| 3821 | private: |
| 3822 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3823 | }; |
| 3824 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3825 | class HSub : public HBinaryOperation { |
| 3826 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3827 | HSub(Primitive::Type result_type, |
| 3828 | HInstruction* left, |
| 3829 | HInstruction* right, |
| 3830 | uint32_t dex_pc = kNoDexPc) |
| 3831 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3832 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3833 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3834 | |
| 3835 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3836 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3837 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3838 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3839 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3840 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3841 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3842 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3843 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3844 | DECLARE_INSTRUCTION(Sub); |
| 3845 | |
| 3846 | private: |
| 3847 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3848 | }; |
| 3849 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3850 | class HMul : public HBinaryOperation { |
| 3851 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3852 | HMul(Primitive::Type result_type, |
| 3853 | HInstruction* left, |
| 3854 | HInstruction* right, |
| 3855 | uint32_t dex_pc = kNoDexPc) |
| 3856 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3857 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3858 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3859 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3860 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3861 | |
| 3862 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3863 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3864 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3865 | } |
| 3866 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3867 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3868 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3869 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3870 | |
| 3871 | DECLARE_INSTRUCTION(Mul); |
| 3872 | |
| 3873 | private: |
| 3874 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3875 | }; |
| 3876 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3877 | class HDiv : public HBinaryOperation { |
| 3878 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3879 | HDiv(Primitive::Type result_type, |
| 3880 | HInstruction* left, |
| 3881 | HInstruction* right, |
| 3882 | uint32_t dex_pc) |
| 3883 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3884 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3885 | template <typename T> |
| 3886 | T Compute(T x, T y) const { |
| 3887 | // Our graph structure ensures we never have 0 for `y` during |
| 3888 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3889 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3890 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3891 | return (y == -1) ? -x : x / y; |
| 3892 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3893 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3894 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3895 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3896 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3897 | } |
| 3898 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3899 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3900 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3901 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3902 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3903 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3904 | // The generated code can use a runtime call. |
| 3905 | return SideEffects::CanTriggerGC(); |
| 3906 | } |
| 3907 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3908 | DECLARE_INSTRUCTION(Div); |
| 3909 | |
| 3910 | private: |
| 3911 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3912 | }; |
| 3913 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3914 | class HRem : public HBinaryOperation { |
| 3915 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3916 | HRem(Primitive::Type result_type, |
| 3917 | HInstruction* left, |
| 3918 | HInstruction* right, |
| 3919 | uint32_t dex_pc) |
| 3920 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3921 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3922 | template <typename T> |
| 3923 | T Compute(T x, T y) const { |
| 3924 | // Our graph structure ensures we never have 0 for `y` during |
| 3925 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3926 | DCHECK_NE(y, 0); |
| 3927 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3928 | return (y == -1) ? 0 : x % y; |
| 3929 | } |
| 3930 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3931 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3932 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3933 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3934 | } |
| 3935 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3936 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3937 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3938 | } |
| 3939 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3940 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3941 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3942 | return SideEffects::CanTriggerGC(); |
| 3943 | } |
| 3944 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3945 | DECLARE_INSTRUCTION(Rem); |
| 3946 | |
| 3947 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3948 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3949 | }; |
| 3950 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3951 | class HDivZeroCheck : public HExpression<1> { |
| 3952 | public: |
| 3953 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3954 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3955 | SetRawInputAt(0, value); |
| 3956 | } |
| 3957 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3958 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3959 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3960 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3961 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3962 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3963 | return true; |
| 3964 | } |
| 3965 | |
| 3966 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3967 | bool CanThrow() const OVERRIDE { return true; } |
| 3968 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3969 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3970 | |
| 3971 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3972 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3973 | }; |
| 3974 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3975 | class HShl : public HBinaryOperation { |
| 3976 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3977 | HShl(Primitive::Type result_type, |
| 3978 | HInstruction* left, |
| 3979 | HInstruction* right, |
| 3980 | uint32_t dex_pc = kNoDexPc) |
| 3981 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3982 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3983 | template <typename T, typename U, typename V> |
| 3984 | T Compute(T x, U y, V max_shift_value) const { |
| 3985 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3986 | "V is not the unsigned integer type corresponding to T"); |
| 3987 | return x << (y & max_shift_value); |
| 3988 | } |
| 3989 | |
| 3990 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3991 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3992 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3993 | } |
| 3994 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3995 | // case is handled as `x << static_cast<int>(y)`. |
| 3996 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3997 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3998 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3999 | } |
| 4000 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4001 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4002 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4003 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4004 | |
| 4005 | DECLARE_INSTRUCTION(Shl); |
| 4006 | |
| 4007 | private: |
| 4008 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4009 | }; |
| 4010 | |
| 4011 | class HShr : public HBinaryOperation { |
| 4012 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4013 | HShr(Primitive::Type result_type, |
| 4014 | HInstruction* left, |
| 4015 | HInstruction* right, |
| 4016 | uint32_t dex_pc = kNoDexPc) |
| 4017 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4018 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4019 | template <typename T, typename U, typename V> |
| 4020 | T Compute(T x, U y, V max_shift_value) const { |
| 4021 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4022 | "V is not the unsigned integer type corresponding to T"); |
| 4023 | return x >> (y & max_shift_value); |
| 4024 | } |
| 4025 | |
| 4026 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4027 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4028 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4029 | } |
| 4030 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4031 | // case is handled as `x >> static_cast<int>(y)`. |
| 4032 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4033 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4034 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4035 | } |
| 4036 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4037 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4038 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4039 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4040 | |
| 4041 | DECLARE_INSTRUCTION(Shr); |
| 4042 | |
| 4043 | private: |
| 4044 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4045 | }; |
| 4046 | |
| 4047 | class HUShr : public HBinaryOperation { |
| 4048 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4049 | HUShr(Primitive::Type result_type, |
| 4050 | HInstruction* left, |
| 4051 | HInstruction* right, |
| 4052 | uint32_t dex_pc = kNoDexPc) |
| 4053 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4054 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4055 | template <typename T, typename U, typename V> |
| 4056 | T Compute(T x, U y, V max_shift_value) const { |
| 4057 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4058 | "V is not the unsigned integer type corresponding to T"); |
| 4059 | V ux = static_cast<V>(x); |
| 4060 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4063 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4064 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4065 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4066 | } |
| 4067 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4068 | // case is handled as `x >>> static_cast<int>(y)`. |
| 4069 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4070 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4071 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4072 | } |
| 4073 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4074 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4075 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | DECLARE_INSTRUCTION(UShr); |
| 4079 | |
| 4080 | private: |
| 4081 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4082 | }; |
| 4083 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4084 | class HAnd : public HBinaryOperation { |
| 4085 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4086 | HAnd(Primitive::Type result_type, |
| 4087 | HInstruction* left, |
| 4088 | HInstruction* right, |
| 4089 | uint32_t dex_pc = kNoDexPc) |
| 4090 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4091 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4092 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4093 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4094 | template <typename T, typename U> |
| 4095 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 4096 | |
| 4097 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4098 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4099 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4100 | } |
| 4101 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4102 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4103 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4104 | } |
| 4105 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4106 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4107 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4108 | } |
| 4109 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4110 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4111 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4112 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4113 | |
| 4114 | DECLARE_INSTRUCTION(And); |
| 4115 | |
| 4116 | private: |
| 4117 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4118 | }; |
| 4119 | |
| 4120 | class HOr : public HBinaryOperation { |
| 4121 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4122 | HOr(Primitive::Type result_type, |
| 4123 | HInstruction* left, |
| 4124 | HInstruction* right, |
| 4125 | uint32_t dex_pc = kNoDexPc) |
| 4126 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4127 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4128 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4129 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4130 | template <typename T, typename U> |
| 4131 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4132 | |
| 4133 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4134 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4135 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4136 | } |
| 4137 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4138 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4139 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4140 | } |
| 4141 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4142 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4143 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4144 | } |
| 4145 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4146 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4147 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4148 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4149 | |
| 4150 | DECLARE_INSTRUCTION(Or); |
| 4151 | |
| 4152 | private: |
| 4153 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4154 | }; |
| 4155 | |
| 4156 | class HXor : public HBinaryOperation { |
| 4157 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4158 | HXor(Primitive::Type result_type, |
| 4159 | HInstruction* left, |
| 4160 | HInstruction* right, |
| 4161 | uint32_t dex_pc = kNoDexPc) |
| 4162 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4163 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4164 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4165 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4166 | template <typename T, typename U> |
| 4167 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4168 | |
| 4169 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4170 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4171 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4172 | } |
| 4173 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4174 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4175 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4176 | } |
| 4177 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4178 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4179 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4180 | } |
| 4181 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4182 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4183 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4184 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4185 | |
| 4186 | DECLARE_INSTRUCTION(Xor); |
| 4187 | |
| 4188 | private: |
| 4189 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4190 | }; |
| 4191 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4192 | // The value of a parameter in this method. Its location depends on |
| 4193 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4194 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4195 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4196 | HParameterValue(const DexFile& dex_file, |
| 4197 | uint16_t type_index, |
| 4198 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4199 | Primitive::Type parameter_type, |
| 4200 | bool is_this = false) |
| 4201 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4202 | dex_file_(dex_file), |
| 4203 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4204 | index_(index), |
| 4205 | is_this_(is_this), |
| 4206 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4207 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4208 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4209 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4210 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4211 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4212 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4213 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4214 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4215 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4216 | DECLARE_INSTRUCTION(ParameterValue); |
| 4217 | |
| 4218 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4219 | const DexFile& dex_file_; |
| 4220 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4221 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4222 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4223 | const uint8_t index_; |
| 4224 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4225 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4226 | const bool is_this_; |
| 4227 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4228 | bool can_be_null_; |
| 4229 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4230 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4231 | }; |
| 4232 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4233 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4234 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4235 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4236 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4237 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4238 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4239 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4240 | return true; |
| 4241 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4242 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4243 | template <typename T> T Compute(T x) const { return ~x; } |
| 4244 | |
| 4245 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4246 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4247 | } |
| 4248 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4249 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4250 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4251 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4252 | DECLARE_INSTRUCTION(Not); |
| 4253 | |
| 4254 | private: |
| 4255 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4256 | }; |
| 4257 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4258 | class HBooleanNot : public HUnaryOperation { |
| 4259 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4260 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4261 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4262 | |
| 4263 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4264 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4265 | return true; |
| 4266 | } |
| 4267 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4268 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4269 | DCHECK(IsUint<1>(x)); |
| 4270 | return !x; |
| 4271 | } |
| 4272 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4273 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4274 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4275 | } |
| 4276 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4277 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4278 | UNREACHABLE(); |
| 4279 | } |
| 4280 | |
| 4281 | DECLARE_INSTRUCTION(BooleanNot); |
| 4282 | |
| 4283 | private: |
| 4284 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4285 | }; |
| 4286 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4287 | class HTypeConversion : public HExpression<1> { |
| 4288 | public: |
| 4289 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4290 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4291 | : HExpression(result_type, |
| 4292 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4293 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4294 | SetRawInputAt(0, input); |
| 4295 | DCHECK_NE(input->GetType(), result_type); |
| 4296 | } |
| 4297 | |
| 4298 | HInstruction* GetInput() const { return InputAt(0); } |
| 4299 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4300 | Primitive::Type GetResultType() const { return GetType(); } |
| 4301 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4302 | // 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] | 4303 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4304 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4305 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4306 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4307 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4308 | // Try to statically evaluate the conversion and return a HConstant |
| 4309 | // containing the result. If the input cannot be converted, return nullptr. |
| 4310 | HConstant* TryStaticEvaluation() const; |
| 4311 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4312 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4313 | Primitive::Type result_type) { |
| 4314 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4315 | // in the compilation process we do not know what architecture we will |
| 4316 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4317 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4318 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4319 | return SideEffects::CanTriggerGC(); |
| 4320 | } |
| 4321 | return SideEffects::None(); |
| 4322 | } |
| 4323 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4324 | DECLARE_INSTRUCTION(TypeConversion); |
| 4325 | |
| 4326 | private: |
| 4327 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4328 | }; |
| 4329 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4330 | static constexpr uint32_t kNoRegNumber = -1; |
| 4331 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4332 | class HPhi : public HInstruction { |
| 4333 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4334 | HPhi(ArenaAllocator* arena, |
| 4335 | uint32_t reg_number, |
| 4336 | size_t number_of_inputs, |
| 4337 | Primitive::Type type, |
| 4338 | uint32_t dex_pc = kNoDexPc) |
| 4339 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4340 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4341 | reg_number_(reg_number), |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4342 | type_(ToPhiType(type)), |
| 4343 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4344 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4345 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4346 | is_live_(true), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4347 | can_be_null_(true) { |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4348 | DCHECK_NE(type_, Primitive::kPrimVoid); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4349 | } |
| 4350 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4351 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4352 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4353 | switch (type) { |
| 4354 | case Primitive::kPrimBoolean: |
| 4355 | case Primitive::kPrimByte: |
| 4356 | case Primitive::kPrimShort: |
| 4357 | case Primitive::kPrimChar: |
| 4358 | return Primitive::kPrimInt; |
| 4359 | default: |
| 4360 | return type; |
| 4361 | } |
| 4362 | } |
| 4363 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4364 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4365 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4366 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4367 | |
| 4368 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4369 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4370 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4371 | Primitive::Type GetType() const OVERRIDE { return type_; } |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4372 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4373 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4374 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4375 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4376 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4377 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4378 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4379 | void SetDead() { is_live_ = false; } |
| 4380 | void SetLive() { is_live_ = true; } |
| 4381 | bool IsDead() const { return !is_live_; } |
| 4382 | bool IsLive() const { return is_live_; } |
| 4383 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4384 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4385 | return other != nullptr |
| 4386 | && other->IsPhi() |
| 4387 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4388 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4389 | } |
| 4390 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4391 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4392 | // An equivalent phi is a phi having the same dex register and type. |
| 4393 | // It assumes that phis with the same dex register are adjacent. |
| 4394 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4395 | HInstruction* next = GetNext(); |
| 4396 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4397 | if (next->GetType() == GetType()) { |
| 4398 | return next->AsPhi(); |
| 4399 | } |
| 4400 | next = next->GetNext(); |
| 4401 | } |
| 4402 | return nullptr; |
| 4403 | } |
| 4404 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4405 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4406 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4407 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4408 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4409 | return inputs_[index]; |
| 4410 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4411 | |
| 4412 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4413 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4414 | } |
| 4415 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4416 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4417 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4418 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4419 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4420 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4421 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4422 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4423 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4424 | }; |
| 4425 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4426 | class HNullCheck : public HExpression<1> { |
| 4427 | public: |
| 4428 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4429 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4430 | SetRawInputAt(0, value); |
| 4431 | } |
| 4432 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4433 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4434 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4435 | return true; |
| 4436 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4437 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4438 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4439 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4440 | bool CanThrow() const OVERRIDE { return true; } |
| 4441 | |
| 4442 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4443 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4444 | |
| 4445 | DECLARE_INSTRUCTION(NullCheck); |
| 4446 | |
| 4447 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4448 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4449 | }; |
| 4450 | |
| 4451 | class FieldInfo : public ValueObject { |
| 4452 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4453 | FieldInfo(MemberOffset field_offset, |
| 4454 | Primitive::Type field_type, |
| 4455 | bool is_volatile, |
| 4456 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4457 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4458 | const DexFile& dex_file, |
| 4459 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4460 | : field_offset_(field_offset), |
| 4461 | field_type_(field_type), |
| 4462 | is_volatile_(is_volatile), |
| 4463 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4464 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4465 | dex_file_(dex_file), |
| 4466 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4467 | |
| 4468 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4469 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4470 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4471 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4472 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4473 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4474 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4475 | |
| 4476 | private: |
| 4477 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4478 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4479 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4480 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4481 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4482 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4483 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4484 | }; |
| 4485 | |
| 4486 | class HInstanceFieldGet : public HExpression<1> { |
| 4487 | public: |
| 4488 | HInstanceFieldGet(HInstruction* value, |
| 4489 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4490 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4491 | bool is_volatile, |
| 4492 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4493 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4494 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4495 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4496 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4497 | : HExpression(field_type, |
| 4498 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4499 | dex_pc), |
| 4500 | field_info_(field_offset, |
| 4501 | field_type, |
| 4502 | is_volatile, |
| 4503 | field_idx, |
| 4504 | declaring_class_def_index, |
| 4505 | dex_file, |
| 4506 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4507 | SetRawInputAt(0, value); |
| 4508 | } |
| 4509 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4510 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4511 | |
| 4512 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4513 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4514 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4515 | } |
| 4516 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4517 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4518 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4519 | } |
| 4520 | |
| 4521 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4522 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4523 | } |
| 4524 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4525 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4526 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4527 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4528 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4529 | |
| 4530 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4531 | |
| 4532 | private: |
| 4533 | const FieldInfo field_info_; |
| 4534 | |
| 4535 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4536 | }; |
| 4537 | |
| 4538 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4539 | public: |
| 4540 | HInstanceFieldSet(HInstruction* object, |
| 4541 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4542 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4543 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4544 | bool is_volatile, |
| 4545 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4546 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4547 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4548 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4549 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4550 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4551 | dex_pc), |
| 4552 | field_info_(field_offset, |
| 4553 | field_type, |
| 4554 | is_volatile, |
| 4555 | field_idx, |
| 4556 | declaring_class_def_index, |
| 4557 | dex_file, |
| 4558 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4559 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4560 | SetRawInputAt(0, object); |
| 4561 | SetRawInputAt(1, value); |
| 4562 | } |
| 4563 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4564 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4565 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4566 | } |
| 4567 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4568 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4569 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4570 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4571 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4572 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4573 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4574 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4575 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4576 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4577 | |
| 4578 | private: |
| 4579 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4580 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4581 | |
| 4582 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4583 | }; |
| 4584 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4585 | class HArrayGet : public HExpression<2> { |
| 4586 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4587 | HArrayGet(HInstruction* array, |
| 4588 | HInstruction* index, |
| 4589 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4590 | uint32_t dex_pc, |
| 4591 | SideEffects additional_side_effects = SideEffects::None()) |
| 4592 | : HExpression(type, |
| 4593 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4594 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4595 | SetRawInputAt(0, array); |
| 4596 | SetRawInputAt(1, index); |
| 4597 | } |
| 4598 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4599 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4600 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4601 | return true; |
| 4602 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4603 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4604 | // TODO: We can be smarter here. |
| 4605 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4606 | // which generates the implicit null check. There are cases when these can be removed |
| 4607 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4608 | // implicit check here (as long as the address falls in the first page). |
| 4609 | return false; |
| 4610 | } |
| 4611 | |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4612 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4613 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4614 | HInstruction* GetArray() const { return InputAt(0); } |
| 4615 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4616 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4617 | DECLARE_INSTRUCTION(ArrayGet); |
| 4618 | |
| 4619 | private: |
| 4620 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4621 | }; |
| 4622 | |
| 4623 | class HArraySet : public HTemplateInstruction<3> { |
| 4624 | public: |
| 4625 | HArraySet(HInstruction* array, |
| 4626 | HInstruction* index, |
| 4627 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4628 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4629 | uint32_t dex_pc, |
| 4630 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4631 | : HTemplateInstruction( |
| 4632 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4633 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4634 | additional_side_effects), |
| 4635 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4636 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4637 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4638 | value_can_be_null_(true), |
| 4639 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4640 | SetRawInputAt(0, array); |
| 4641 | SetRawInputAt(1, index); |
| 4642 | SetRawInputAt(2, value); |
| 4643 | } |
| 4644 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4645 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4646 | // We currently always call a runtime method to catch array store |
| 4647 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4648 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4649 | } |
| 4650 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4651 | // Can throw ArrayStoreException. |
| 4652 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4653 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4654 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4655 | // TODO: Same as for ArrayGet. |
| 4656 | return false; |
| 4657 | } |
| 4658 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4659 | void ClearNeedsTypeCheck() { |
| 4660 | needs_type_check_ = false; |
| 4661 | } |
| 4662 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4663 | void ClearValueCanBeNull() { |
| 4664 | value_can_be_null_ = false; |
| 4665 | } |
| 4666 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4667 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4668 | static_type_of_array_is_object_array_ = true; |
| 4669 | } |
| 4670 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4671 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4672 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4673 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4674 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4675 | HInstruction* GetArray() const { return InputAt(0); } |
| 4676 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4677 | HInstruction* GetValue() const { return InputAt(2); } |
| 4678 | |
| 4679 | Primitive::Type GetComponentType() const { |
| 4680 | // The Dex format does not type floating point index operations. Since the |
| 4681 | // `expected_component_type_` is set during building and can therefore not |
| 4682 | // be correct, we also check what is the value type. If it is a floating |
| 4683 | // point type, we must use that type. |
| 4684 | Primitive::Type value_type = GetValue()->GetType(); |
| 4685 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4686 | ? value_type |
| 4687 | : expected_component_type_; |
| 4688 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4689 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4690 | Primitive::Type GetRawExpectedComponentType() const { |
| 4691 | return expected_component_type_; |
| 4692 | } |
| 4693 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4694 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4695 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4696 | } |
| 4697 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4698 | DECLARE_INSTRUCTION(ArraySet); |
| 4699 | |
| 4700 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4701 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4702 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4703 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4704 | // Cached information for the reference_type_info_ so that codegen |
| 4705 | // does not need to inspect the static type. |
| 4706 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4707 | |
| 4708 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4709 | }; |
| 4710 | |
| 4711 | class HArrayLength : public HExpression<1> { |
| 4712 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4713 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4714 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4715 | // Note that arrays do not change length, so the instruction does not |
| 4716 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4717 | SetRawInputAt(0, array); |
| 4718 | } |
| 4719 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4720 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4721 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4722 | return true; |
| 4723 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4724 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4725 | return obj == InputAt(0); |
| 4726 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4727 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4728 | DECLARE_INSTRUCTION(ArrayLength); |
| 4729 | |
| 4730 | private: |
| 4731 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4732 | }; |
| 4733 | |
| 4734 | class HBoundsCheck : public HExpression<2> { |
| 4735 | public: |
| 4736 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4737 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4738 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4739 | SetRawInputAt(0, index); |
| 4740 | SetRawInputAt(1, length); |
| 4741 | } |
| 4742 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4743 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4744 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4745 | return true; |
| 4746 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4747 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4748 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4749 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4750 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4751 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4752 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4753 | |
| 4754 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4755 | |
| 4756 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4757 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4758 | }; |
| 4759 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4760 | /** |
| 4761 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4762 | * to stay live until the last HInstruction. This class |
| 4763 | * 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] | 4764 | * HInstruction stays live. `index` represents the stack location index of the |
| 4765 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4766 | */ |
| 4767 | class HTemporary : public HTemplateInstruction<0> { |
| 4768 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4769 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4770 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4771 | |
| 4772 | size_t GetIndex() const { return index_; } |
| 4773 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4774 | Primitive::Type GetType() const OVERRIDE { |
| 4775 | // The previous instruction is the one that will be stored in the temporary location. |
| 4776 | DCHECK(GetPrevious() != nullptr); |
| 4777 | return GetPrevious()->GetType(); |
| 4778 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4779 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4780 | DECLARE_INSTRUCTION(Temporary); |
| 4781 | |
| 4782 | private: |
| 4783 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4784 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4785 | }; |
| 4786 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4787 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4788 | public: |
| 4789 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4790 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4791 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4792 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4793 | return true; |
| 4794 | } |
| 4795 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4796 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4797 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4798 | |
| 4799 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4800 | |
| 4801 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4802 | // Only used for code generation, in order to share the same slow path between back edges |
| 4803 | // of a same loop. |
| 4804 | SlowPathCode* slow_path_; |
| 4805 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4806 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4807 | }; |
| 4808 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4809 | /** |
| 4810 | * Instruction to load a Class object. |
| 4811 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4812 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4813 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4814 | HLoadClass(HCurrentMethod* current_method, |
| 4815 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4816 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4817 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4818 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4819 | bool needs_access_check, |
| 4820 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4821 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4822 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4823 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4824 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4825 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4826 | needs_access_check_(needs_access_check), |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4827 | is_in_dex_cache_(is_in_dex_cache), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4828 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4829 | // Referrers class should not need access check. We never inline unverified |
| 4830 | // methods so we can't possibly end up in this situation. |
| 4831 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4832 | SetRawInputAt(0, current_method); |
| 4833 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4834 | |
| 4835 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4836 | |
| 4837 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 4838 | // Note that we don't need to test for generate_clinit_check_. |
| 4839 | // Whether or not we need to generate the clinit check is processed in |
| 4840 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4841 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 4842 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4846 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4847 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4848 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4849 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4850 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4851 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4852 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4853 | } |
| 4854 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4855 | bool MustGenerateClinitCheck() const { |
| 4856 | return generate_clinit_check_; |
| 4857 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4858 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4859 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 4860 | // The entrypoint the code generator is going to call does not do |
| 4861 | // clinit of the class. |
| 4862 | DCHECK(!NeedsAccessCheck()); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4863 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4867 | return MustGenerateClinitCheck() || |
| 4868 | (!is_referrers_class_ && !is_in_dex_cache_) || |
| 4869 | needs_access_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4870 | } |
| 4871 | |
| 4872 | bool NeedsAccessCheck() const { |
| 4873 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4874 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4875 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4876 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4877 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4878 | } |
| 4879 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4880 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4881 | return loaded_class_rti_; |
| 4882 | } |
| 4883 | |
| 4884 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4885 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4886 | DCHECK(rti.IsExact()); |
| 4887 | loaded_class_rti_ = rti; |
| 4888 | } |
| 4889 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4890 | const DexFile& GetDexFile() { return dex_file_; } |
| 4891 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4892 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4893 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4894 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4895 | return SideEffects::CanTriggerGC(); |
| 4896 | } |
| 4897 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4898 | bool IsInDexCache() const { return is_in_dex_cache_; } |
| 4899 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4900 | DECLARE_INSTRUCTION(LoadClass); |
| 4901 | |
| 4902 | private: |
| 4903 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4904 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4905 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4906 | // Whether this instruction must generate the initialization check. |
| 4907 | // Used for code generation. |
| 4908 | bool generate_clinit_check_; |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4909 | const bool needs_access_check_; |
| 4910 | const bool is_in_dex_cache_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4911 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4912 | ReferenceTypeInfo loaded_class_rti_; |
| 4913 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4914 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4915 | }; |
| 4916 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4917 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4918 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4919 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4920 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4921 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4922 | SetRawInputAt(0, current_method); |
| 4923 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4924 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4925 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4926 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4927 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4928 | return other->AsLoadString()->string_index_ == string_index_; |
| 4929 | } |
| 4930 | |
| 4931 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4932 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4933 | uint32_t GetStringIndex() const { return string_index_; } |
| 4934 | |
| 4935 | // TODO: Can we deopt or debug when we resolve a string? |
| 4936 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4937 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4938 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4939 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4940 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4941 | return SideEffects::CanTriggerGC(); |
| 4942 | } |
| 4943 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4944 | DECLARE_INSTRUCTION(LoadString); |
| 4945 | |
| 4946 | private: |
| 4947 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4948 | |
| 4949 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4950 | }; |
| 4951 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4952 | /** |
| 4953 | * Performs an initialization check on its Class object input. |
| 4954 | */ |
| 4955 | class HClinitCheck : public HExpression<1> { |
| 4956 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4957 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4958 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4959 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4960 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4961 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4962 | SetRawInputAt(0, constant); |
| 4963 | } |
| 4964 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4965 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4966 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4967 | return true; |
| 4968 | } |
| 4969 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4970 | bool NeedsEnvironment() const OVERRIDE { |
| 4971 | // May call runtime to initialize the class. |
| 4972 | return true; |
| 4973 | } |
| 4974 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 4975 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4976 | |
| 4977 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4978 | |
| 4979 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4980 | |
| 4981 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4982 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4983 | }; |
| 4984 | |
| 4985 | class HStaticFieldGet : public HExpression<1> { |
| 4986 | public: |
| 4987 | HStaticFieldGet(HInstruction* cls, |
| 4988 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4989 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4990 | bool is_volatile, |
| 4991 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4992 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4993 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4994 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4995 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4996 | : HExpression(field_type, |
| 4997 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4998 | dex_pc), |
| 4999 | field_info_(field_offset, |
| 5000 | field_type, |
| 5001 | is_volatile, |
| 5002 | field_idx, |
| 5003 | declaring_class_def_index, |
| 5004 | dex_file, |
| 5005 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5006 | SetRawInputAt(0, cls); |
| 5007 | } |
| 5008 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5009 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5010 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5011 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5012 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5013 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5014 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5015 | } |
| 5016 | |
| 5017 | size_t ComputeHashCode() const OVERRIDE { |
| 5018 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5019 | } |
| 5020 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5021 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5022 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5023 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5024 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5025 | |
| 5026 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5027 | |
| 5028 | private: |
| 5029 | const FieldInfo field_info_; |
| 5030 | |
| 5031 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5032 | }; |
| 5033 | |
| 5034 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5035 | public: |
| 5036 | HStaticFieldSet(HInstruction* cls, |
| 5037 | HInstruction* value, |
| 5038 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5039 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5040 | bool is_volatile, |
| 5041 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5042 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5043 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5044 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5045 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5046 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5047 | dex_pc), |
| 5048 | field_info_(field_offset, |
| 5049 | field_type, |
| 5050 | is_volatile, |
| 5051 | field_idx, |
| 5052 | declaring_class_def_index, |
| 5053 | dex_file, |
| 5054 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5055 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5056 | SetRawInputAt(0, cls); |
| 5057 | SetRawInputAt(1, value); |
| 5058 | } |
| 5059 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5060 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5061 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5062 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5063 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5064 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5065 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5066 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 5067 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5068 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5069 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5070 | |
| 5071 | private: |
| 5072 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5073 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5074 | |
| 5075 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5076 | }; |
| 5077 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5078 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5079 | public: |
| 5080 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5081 | Primitive::Type field_type, |
| 5082 | uint32_t field_index, |
| 5083 | uint32_t dex_pc) |
| 5084 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5085 | field_index_(field_index) { |
| 5086 | SetRawInputAt(0, obj); |
| 5087 | } |
| 5088 | |
| 5089 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5090 | bool CanThrow() const OVERRIDE { return true; } |
| 5091 | |
| 5092 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5093 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5094 | |
| 5095 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5096 | |
| 5097 | private: |
| 5098 | const uint32_t field_index_; |
| 5099 | |
| 5100 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5101 | }; |
| 5102 | |
| 5103 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5104 | public: |
| 5105 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5106 | HInstruction* value, |
| 5107 | Primitive::Type field_type, |
| 5108 | uint32_t field_index, |
| 5109 | uint32_t dex_pc) |
| 5110 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5111 | field_type_(field_type), |
| 5112 | field_index_(field_index) { |
| 5113 | DCHECK_EQ(field_type, value->GetType()); |
| 5114 | SetRawInputAt(0, obj); |
| 5115 | SetRawInputAt(1, value); |
| 5116 | } |
| 5117 | |
| 5118 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5119 | bool CanThrow() const OVERRIDE { return true; } |
| 5120 | |
| 5121 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5122 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5123 | |
| 5124 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5125 | |
| 5126 | private: |
| 5127 | const Primitive::Type field_type_; |
| 5128 | const uint32_t field_index_; |
| 5129 | |
| 5130 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5131 | }; |
| 5132 | |
| 5133 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5134 | public: |
| 5135 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5136 | uint32_t field_index, |
| 5137 | uint32_t dex_pc) |
| 5138 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5139 | field_index_(field_index) { |
| 5140 | } |
| 5141 | |
| 5142 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5143 | bool CanThrow() const OVERRIDE { return true; } |
| 5144 | |
| 5145 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5146 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5147 | |
| 5148 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5149 | |
| 5150 | private: |
| 5151 | const uint32_t field_index_; |
| 5152 | |
| 5153 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5154 | }; |
| 5155 | |
| 5156 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5157 | public: |
| 5158 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5159 | Primitive::Type field_type, |
| 5160 | uint32_t field_index, |
| 5161 | uint32_t dex_pc) |
| 5162 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5163 | field_type_(field_type), |
| 5164 | field_index_(field_index) { |
| 5165 | DCHECK_EQ(field_type, value->GetType()); |
| 5166 | SetRawInputAt(0, value); |
| 5167 | } |
| 5168 | |
| 5169 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5170 | bool CanThrow() const OVERRIDE { return true; } |
| 5171 | |
| 5172 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5173 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5174 | |
| 5175 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5176 | |
| 5177 | private: |
| 5178 | const Primitive::Type field_type_; |
| 5179 | const uint32_t field_index_; |
| 5180 | |
| 5181 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5182 | }; |
| 5183 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5184 | // Implement the move-exception DEX instruction. |
| 5185 | class HLoadException : public HExpression<0> { |
| 5186 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5187 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5188 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5189 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5190 | bool CanBeNull() const OVERRIDE { return false; } |
| 5191 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5192 | DECLARE_INSTRUCTION(LoadException); |
| 5193 | |
| 5194 | private: |
| 5195 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5196 | }; |
| 5197 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5198 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5199 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5200 | class HClearException : public HTemplateInstruction<0> { |
| 5201 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5202 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5203 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5204 | |
| 5205 | DECLARE_INSTRUCTION(ClearException); |
| 5206 | |
| 5207 | private: |
| 5208 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5209 | }; |
| 5210 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5211 | class HThrow : public HTemplateInstruction<1> { |
| 5212 | public: |
| 5213 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5214 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5215 | SetRawInputAt(0, exception); |
| 5216 | } |
| 5217 | |
| 5218 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5219 | |
| 5220 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5221 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5222 | bool CanThrow() const OVERRIDE { return true; } |
| 5223 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5224 | |
| 5225 | DECLARE_INSTRUCTION(Throw); |
| 5226 | |
| 5227 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5228 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5229 | }; |
| 5230 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5231 | /** |
| 5232 | * Implementation strategies for the code generator of a HInstanceOf |
| 5233 | * or `HCheckCast`. |
| 5234 | */ |
| 5235 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5236 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5237 | kExactCheck, // Can do a single class compare. |
| 5238 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5239 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5240 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5241 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5242 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5243 | }; |
| 5244 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5245 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5246 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5247 | HInstanceOf(HInstruction* object, |
| 5248 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5249 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5250 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5251 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5252 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5253 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5254 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5255 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5256 | SetRawInputAt(0, object); |
| 5257 | SetRawInputAt(1, constant); |
| 5258 | } |
| 5259 | |
| 5260 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5261 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5262 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5263 | return true; |
| 5264 | } |
| 5265 | |
| 5266 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5267 | return false; |
| 5268 | } |
| 5269 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5270 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5271 | |
| 5272 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5273 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5274 | // Used only in code generation. |
| 5275 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5276 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5277 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5278 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 5279 | return (check_kind == TypeCheckKind::kExactCheck) |
| 5280 | ? SideEffects::None() |
| 5281 | // Mips currently does runtime calls for any other checks. |
| 5282 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5283 | } |
| 5284 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5285 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5286 | |
| 5287 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5288 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5289 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5290 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5291 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5292 | }; |
| 5293 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5294 | class HBoundType : public HExpression<1> { |
| 5295 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5296 | // Constructs an HBoundType with the given upper_bound. |
| 5297 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5298 | HBoundType(HInstruction* input, |
| 5299 | ReferenceTypeInfo upper_bound, |
| 5300 | bool upper_can_be_null, |
| 5301 | uint32_t dex_pc = kNoDexPc) |
| 5302 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5303 | upper_bound_(upper_bound), |
| 5304 | upper_can_be_null_(upper_can_be_null), |
| 5305 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5306 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5307 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5308 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5309 | } |
| 5310 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5311 | // GetUpper* should only be used in reference type propagation. |
| 5312 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5313 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5314 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5315 | void SetCanBeNull(bool can_be_null) { |
| 5316 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5317 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5318 | } |
| 5319 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5320 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5321 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5322 | DECLARE_INSTRUCTION(BoundType); |
| 5323 | |
| 5324 | private: |
| 5325 | // 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] | 5326 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5327 | // It is used to bound the type in cases like: |
| 5328 | // if (x instanceof ClassX) { |
| 5329 | // // uper_bound_ will be ClassX |
| 5330 | // } |
| 5331 | const ReferenceTypeInfo upper_bound_; |
| 5332 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5333 | // is false then can_be_null_ cannot be true). |
| 5334 | const bool upper_can_be_null_; |
| 5335 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5336 | |
| 5337 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5338 | }; |
| 5339 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5340 | class HCheckCast : public HTemplateInstruction<2> { |
| 5341 | public: |
| 5342 | HCheckCast(HInstruction* object, |
| 5343 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5344 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5345 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5346 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5347 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5348 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5349 | SetRawInputAt(0, object); |
| 5350 | SetRawInputAt(1, constant); |
| 5351 | } |
| 5352 | |
| 5353 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5354 | |
| 5355 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5356 | return true; |
| 5357 | } |
| 5358 | |
| 5359 | bool NeedsEnvironment() const OVERRIDE { |
| 5360 | // Instruction may throw a CheckCastError. |
| 5361 | return true; |
| 5362 | } |
| 5363 | |
| 5364 | bool CanThrow() const OVERRIDE { return true; } |
| 5365 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5366 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5367 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5368 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5369 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5370 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5371 | |
| 5372 | DECLARE_INSTRUCTION(CheckCast); |
| 5373 | |
| 5374 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5375 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5376 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5377 | |
| 5378 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5379 | }; |
| 5380 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5381 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5382 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5383 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5384 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5385 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5386 | barrier_kind_(barrier_kind) {} |
| 5387 | |
| 5388 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5389 | |
| 5390 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5391 | |
| 5392 | private: |
| 5393 | const MemBarrierKind barrier_kind_; |
| 5394 | |
| 5395 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5396 | }; |
| 5397 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5398 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5399 | public: |
| 5400 | enum OperationKind { |
| 5401 | kEnter, |
| 5402 | kExit, |
| 5403 | }; |
| 5404 | |
| 5405 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5406 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5407 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5408 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5409 | SetRawInputAt(0, object); |
| 5410 | } |
| 5411 | |
| 5412 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5413 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5414 | |
| 5415 | bool CanThrow() const OVERRIDE { |
| 5416 | // Verifier guarantees that monitor-exit cannot throw. |
| 5417 | // This is important because it allows the HGraphBuilder to remove |
| 5418 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5419 | return IsEnter(); |
| 5420 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5421 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5422 | |
| 5423 | bool IsEnter() const { return kind_ == kEnter; } |
| 5424 | |
| 5425 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5426 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5427 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5428 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5429 | |
| 5430 | private: |
| 5431 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5432 | }; |
| 5433 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5434 | /** |
| 5435 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5436 | * of a String to a call to a StringFactory. Only baseline will see |
| 5437 | * the node at code generation, where it will be be treated as null. |
| 5438 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5439 | * in the instruction simplifier. |
| 5440 | */ |
| 5441 | class HFakeString : public HTemplateInstruction<0> { |
| 5442 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5443 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5444 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5445 | |
| 5446 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5447 | |
| 5448 | DECLARE_INSTRUCTION(FakeString); |
| 5449 | |
| 5450 | private: |
| 5451 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5452 | }; |
| 5453 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5454 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5455 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5456 | MoveOperands(Location source, |
| 5457 | Location destination, |
| 5458 | Primitive::Type type, |
| 5459 | HInstruction* instruction) |
| 5460 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5461 | |
| 5462 | Location GetSource() const { return source_; } |
| 5463 | Location GetDestination() const { return destination_; } |
| 5464 | |
| 5465 | void SetSource(Location value) { source_ = value; } |
| 5466 | void SetDestination(Location value) { destination_ = value; } |
| 5467 | |
| 5468 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5469 | // destination (but not the source). |
| 5470 | Location MarkPending() { |
| 5471 | DCHECK(!IsPending()); |
| 5472 | Location dest = destination_; |
| 5473 | destination_ = Location::NoLocation(); |
| 5474 | return dest; |
| 5475 | } |
| 5476 | |
| 5477 | void ClearPending(Location dest) { |
| 5478 | DCHECK(IsPending()); |
| 5479 | destination_ = dest; |
| 5480 | } |
| 5481 | |
| 5482 | bool IsPending() const { |
| 5483 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5484 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5485 | } |
| 5486 | |
| 5487 | // True if this blocks a move from the given location. |
| 5488 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5489 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | // A move is redundant if it's been eliminated, if its source and |
| 5493 | // destination are the same, or if its destination is unneeded. |
| 5494 | bool IsRedundant() const { |
| 5495 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5496 | } |
| 5497 | |
| 5498 | // We clear both operands to indicate move that's been eliminated. |
| 5499 | void Eliminate() { |
| 5500 | source_ = destination_ = Location::NoLocation(); |
| 5501 | } |
| 5502 | |
| 5503 | bool IsEliminated() const { |
| 5504 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5505 | return source_.IsInvalid(); |
| 5506 | } |
| 5507 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5508 | Primitive::Type GetType() const { return type_; } |
| 5509 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5510 | bool Is64BitMove() const { |
| 5511 | return Primitive::Is64BitType(type_); |
| 5512 | } |
| 5513 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5514 | HInstruction* GetInstruction() const { return instruction_; } |
| 5515 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5516 | private: |
| 5517 | Location source_; |
| 5518 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5519 | // The type this move is for. |
| 5520 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5521 | // The instruction this move is assocatied with. Null when this move is |
| 5522 | // for moving an input in the expected locations of user (including a phi user). |
| 5523 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5524 | // in the same parallel move. |
| 5525 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5526 | }; |
| 5527 | |
| 5528 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5529 | |
| 5530 | class HParallelMove : public HTemplateInstruction<0> { |
| 5531 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5532 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5533 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5534 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5535 | moves_.reserve(kDefaultNumberOfMoves); |
| 5536 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5537 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5538 | void AddMove(Location source, |
| 5539 | Location destination, |
| 5540 | Primitive::Type type, |
| 5541 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5542 | DCHECK(source.IsValid()); |
| 5543 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5544 | if (kIsDebugBuild) { |
| 5545 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5546 | for (const MoveOperands& move : moves_) { |
| 5547 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5548 | // Special case the situation where the move is for the spill slot |
| 5549 | // of the instruction. |
| 5550 | if ((GetPrevious() == instruction) |
| 5551 | || ((GetPrevious() == nullptr) |
| 5552 | && instruction->IsPhi() |
| 5553 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5554 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5555 | << "Doing parallel moves for the same instruction."; |
| 5556 | } else { |
| 5557 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5558 | } |
| 5559 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5560 | } |
| 5561 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5562 | for (const MoveOperands& move : moves_) { |
| 5563 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5564 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5565 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5566 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5567 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5568 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5569 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5570 | } |
| 5571 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5572 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5573 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5574 | } |
| 5575 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5576 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5577 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5578 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5579 | |
| 5580 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5581 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5582 | |
| 5583 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5584 | }; |
| 5585 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5586 | } // namespace art |
| 5587 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 5588 | #ifdef ART_ENABLE_CODEGEN_arm |
| 5589 | #include "nodes_arm.h" |
| 5590 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5591 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5592 | #include "nodes_arm64.h" |
| 5593 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5594 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5595 | #include "nodes_x86.h" |
| 5596 | #endif |
| 5597 | |
| 5598 | namespace art { |
| 5599 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5600 | class HGraphVisitor : public ValueObject { |
| 5601 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5602 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5603 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5604 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5605 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5606 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5607 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5608 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5609 | void VisitInsertionOrder(); |
| 5610 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5611 | // Visit the graph following dominator tree reverse post-order. |
| 5612 | void VisitReversePostOrder(); |
| 5613 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5614 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5615 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5616 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5617 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5618 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5619 | |
| 5620 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5621 | |
| 5622 | #undef DECLARE_VISIT_INSTRUCTION |
| 5623 | |
| 5624 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5625 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5626 | |
| 5627 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5628 | }; |
| 5629 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5630 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5631 | public: |
| 5632 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5633 | virtual ~HGraphDelegateVisitor() {} |
| 5634 | |
| 5635 | // Visit functions that delegate to to super class. |
| 5636 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5637 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5638 | |
| 5639 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5640 | |
| 5641 | #undef DECLARE_VISIT_INSTRUCTION |
| 5642 | |
| 5643 | private: |
| 5644 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5645 | }; |
| 5646 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5647 | class HInsertionOrderIterator : public ValueObject { |
| 5648 | public: |
| 5649 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5650 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5651 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5652 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5653 | void Advance() { ++index_; } |
| 5654 | |
| 5655 | private: |
| 5656 | const HGraph& graph_; |
| 5657 | size_t index_; |
| 5658 | |
| 5659 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5660 | }; |
| 5661 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5662 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5663 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5664 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5665 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5666 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5667 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5668 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5669 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5670 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5671 | void Advance() { ++index_; } |
| 5672 | |
| 5673 | private: |
| 5674 | const HGraph& graph_; |
| 5675 | size_t index_; |
| 5676 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5677 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5678 | }; |
| 5679 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5680 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5681 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5682 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5683 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5684 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5685 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5686 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5687 | |
| 5688 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5689 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5690 | void Advance() { --index_; } |
| 5691 | |
| 5692 | private: |
| 5693 | const HGraph& graph_; |
| 5694 | size_t index_; |
| 5695 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5696 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5697 | }; |
| 5698 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5699 | class HLinearPostOrderIterator : public ValueObject { |
| 5700 | public: |
| 5701 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5702 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5703 | |
| 5704 | bool Done() const { return index_ == 0; } |
| 5705 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5706 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5707 | |
| 5708 | void Advance() { |
| 5709 | --index_; |
| 5710 | DCHECK_GE(index_, 0U); |
| 5711 | } |
| 5712 | |
| 5713 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5714 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5715 | size_t index_; |
| 5716 | |
| 5717 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5718 | }; |
| 5719 | |
| 5720 | class HLinearOrderIterator : public ValueObject { |
| 5721 | public: |
| 5722 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5723 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5724 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5725 | bool Done() const { return index_ == order_.size(); } |
| 5726 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5727 | void Advance() { ++index_; } |
| 5728 | |
| 5729 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5730 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5731 | size_t index_; |
| 5732 | |
| 5733 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5734 | }; |
| 5735 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5736 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5737 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5738 | // block id. |
| 5739 | class HBlocksInLoopIterator : public ValueObject { |
| 5740 | public: |
| 5741 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5742 | : blocks_in_loop_(info.GetBlocks()), |
| 5743 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5744 | index_(0) { |
| 5745 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5746 | Advance(); |
| 5747 | } |
| 5748 | } |
| 5749 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5750 | bool Done() const { return index_ == blocks_.size(); } |
| 5751 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5752 | void Advance() { |
| 5753 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5754 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5755 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5756 | break; |
| 5757 | } |
| 5758 | } |
| 5759 | } |
| 5760 | |
| 5761 | private: |
| 5762 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5763 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5764 | size_t index_; |
| 5765 | |
| 5766 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5767 | }; |
| 5768 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5769 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5770 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5771 | // post order. |
| 5772 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5773 | public: |
| 5774 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5775 | : blocks_in_loop_(info.GetBlocks()), |
| 5776 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5777 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5778 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5779 | Advance(); |
| 5780 | } |
| 5781 | } |
| 5782 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5783 | bool Done() const { return index_ == blocks_.size(); } |
| 5784 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5785 | void Advance() { |
| 5786 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5787 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5788 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5789 | break; |
| 5790 | } |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | private: |
| 5795 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5796 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5797 | size_t index_; |
| 5798 | |
| 5799 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5800 | }; |
| 5801 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5802 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5803 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5804 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5805 | : constant->AsLongConstant()->GetValue(); |
| 5806 | } |
| 5807 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5808 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5809 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5810 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5811 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5812 | // times and provide different class resolution but no two class loaders should ever |
| 5813 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5814 | // all sorts of weird failures. |
| 5815 | return &lhs == &rhs; |
| 5816 | } |
| 5817 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5818 | } // namespace art |
| 5819 | |
| 5820 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |