Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_NODES_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_H_ |
| 19 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 24 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 26 | #include "base/arena_object.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 28 | #include "dex/compiler_enums.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 30 | #include "handle.h" |
| 31 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 32 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 33 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 34 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 35 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 36 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 37 | #include "primitive.h" |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 38 | #include "utils/array_ref.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 39 | |
| 40 | namespace art { |
| 41 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 42 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 43 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 45 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 46 | class HEnvironment; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 47 | class HFakeString; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 48 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 49 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 51 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 52 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 53 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 55 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 56 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 57 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 58 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 59 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 60 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 61 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 62 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 63 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 64 | namespace mirror { |
| 65 | class DexCache; |
| 66 | } // namespace mirror |
| 67 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 68 | static const int kDefaultNumberOfBlocks = 8; |
| 69 | static const int kDefaultNumberOfSuccessors = 2; |
| 70 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 72 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 73 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 74 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 75 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 76 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 77 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 78 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 79 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 80 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 81 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 82 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 83 | static constexpr uint32_t kNoDexPc = -1; |
| 84 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 85 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 86 | // All types. |
| 87 | kCondEQ, // == |
| 88 | kCondNE, // != |
| 89 | // Signed integers and floating-point numbers. |
| 90 | kCondLT, // < |
| 91 | kCondLE, // <= |
| 92 | kCondGT, // > |
| 93 | kCondGE, // >= |
| 94 | // Unsigned integers. |
| 95 | kCondB, // < |
| 96 | kCondBE, // <= |
| 97 | kCondA, // > |
| 98 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 101 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 102 | public: |
| 103 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 104 | |
| 105 | void AddInstruction(HInstruction* instruction); |
| 106 | void RemoveInstruction(HInstruction* instruction); |
| 107 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 108 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 109 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 110 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 111 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 112 | // Return true if this list contains `instruction`. |
| 113 | bool Contains(HInstruction* instruction) const; |
| 114 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 115 | // Return true if `instruction1` is found before `instruction2` in |
| 116 | // this instruction list and false otherwise. Abort if none |
| 117 | // of these instructions is found. |
| 118 | bool FoundBefore(const HInstruction* instruction1, |
| 119 | const HInstruction* instruction2) const; |
| 120 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 121 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 122 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 123 | |
| 124 | // Update the block of all instructions to be `block`. |
| 125 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 126 | |
| 127 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 128 | void Add(const HInstructionList& instruction_list); |
| 129 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 130 | // Return the number of instructions in the list. This is an expensive operation. |
| 131 | size_t CountSize() const; |
| 132 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 133 | private: |
| 134 | HInstruction* first_instruction_; |
| 135 | HInstruction* last_instruction_; |
| 136 | |
| 137 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 138 | friend class HGraph; |
| 139 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 140 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 141 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 142 | |
| 143 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 144 | }; |
| 145 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 146 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 147 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 148 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 149 | HGraph(ArenaAllocator* arena, |
| 150 | const DexFile& dex_file, |
| 151 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 152 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 153 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 154 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 155 | bool debuggable = false, |
| 156 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 157 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 158 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 159 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 160 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 161 | entry_block_(nullptr), |
| 162 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 163 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 164 | number_of_vregs_(0), |
| 165 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 166 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 167 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 168 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 169 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 170 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 171 | dex_file_(dex_file), |
| 172 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 173 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 174 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 175 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 176 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 177 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 178 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 179 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 180 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 181 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 182 | cached_current_method_(nullptr) { |
| 183 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 184 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 185 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 186 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 187 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 188 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 189 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 190 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 191 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 192 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 193 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 194 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 195 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 196 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 197 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 198 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 199 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 200 | // Try building the SSA form of this graph, with dominance computation and loop |
| 201 | // recognition. Returns whether it was successful in doing all these steps. |
| 202 | bool TryBuildingSsa() { |
| 203 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 204 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 205 | // elimination phase checks the consistency of the graph when doing a post-order |
| 206 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 207 | // users remaining when being visited. |
| 208 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 209 | // Precompute per-block try membership before entering the SSA builder, |
| 210 | // which needs the information to build catch block phis from values of |
| 211 | // locals at throwing instructions inside try blocks. |
| 212 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 213 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 214 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 215 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 218 | void ComputeDominanceInformation(); |
| 219 | void ClearDominanceInformation(); |
| 220 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 221 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 222 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 223 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 224 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 225 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 226 | // Analyze all natural loops in this graph. Returns false if one |
| 227 | // loop is not natural, that is the header does not dominate the |
| 228 | // back edge. |
| 229 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 230 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 231 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 232 | // order and loop information. |
| 233 | void ComputeTryBlockInformation(); |
| 234 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 235 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 236 | // Returns the instruction used to replace the invoke expression or null if the |
| 237 | // invoke is for a void method. |
| 238 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 239 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 240 | // Need to add a couple of blocks to test if the loop body is entered and |
| 241 | // put deoptimization instructions, etc. |
| 242 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 243 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 244 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 245 | // other blocks and has no instructions or phis. |
| 246 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 247 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 248 | // Splits the edge between `block` and `successor` while preserving the |
| 249 | // indices in the predecessor/successor lists. If there are multiple edges |
| 250 | // between the blocks, the lowest indices are used. |
| 251 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 252 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 253 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 254 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 255 | void SimplifyLoop(HBasicBlock* header); |
| 256 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 257 | int32_t GetNextInstructionId() { |
| 258 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 259 | return current_instruction_id_++; |
| 260 | } |
| 261 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 262 | int32_t GetCurrentInstructionId() const { |
| 263 | return current_instruction_id_; |
| 264 | } |
| 265 | |
| 266 | void SetCurrentInstructionId(int32_t id) { |
| 267 | current_instruction_id_ = id; |
| 268 | } |
| 269 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 270 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 271 | return maximum_number_of_out_vregs_; |
| 272 | } |
| 273 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 274 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 275 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 276 | } |
| 277 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 278 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 279 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 280 | } |
| 281 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 282 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 283 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 286 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 287 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 288 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 291 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 292 | number_of_vregs_ = number_of_vregs; |
| 293 | } |
| 294 | |
| 295 | uint16_t GetNumberOfVRegs() const { |
| 296 | return number_of_vregs_; |
| 297 | } |
| 298 | |
| 299 | void SetNumberOfInVRegs(uint16_t value) { |
| 300 | number_of_in_vregs_ = value; |
| 301 | } |
| 302 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 303 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 304 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 305 | return number_of_vregs_ - number_of_in_vregs_; |
| 306 | } |
| 307 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 308 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 309 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 310 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 311 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 312 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 313 | return linear_order_; |
| 314 | } |
| 315 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 316 | bool HasBoundsChecks() const { |
| 317 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 320 | void SetHasBoundsChecks(bool value) { |
| 321 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 324 | bool ShouldGenerateConstructorBarrier() const { |
| 325 | return should_generate_constructor_barrier_; |
| 326 | } |
| 327 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 328 | bool IsDebuggable() const { return debuggable_; } |
| 329 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 330 | // Returns a constant of the given type and value. If it does not exist |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 331 | // already, it is created and inserted into the graph. This method is only for |
| 332 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 333 | HConstant* GetConstant(Primitive::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 334 | |
| 335 | // TODO: This is problematic for the consistency of reference type propagation |
| 336 | // because it can be created anytime after the pass and thus it will be left |
| 337 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 338 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 339 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 340 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 341 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 342 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 343 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 344 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 345 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 346 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 347 | return CreateConstant(bit_cast<int32_t, float>(value), &cached_float_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 348 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 349 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 350 | return CreateConstant(bit_cast<int64_t, double>(value), &cached_double_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 351 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 352 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 353 | HCurrentMethod* GetCurrentMethod(); |
| 354 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 355 | const DexFile& GetDexFile() const { |
| 356 | return dex_file_; |
| 357 | } |
| 358 | |
| 359 | uint32_t GetMethodIdx() const { |
| 360 | return method_idx_; |
| 361 | } |
| 362 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 363 | InvokeType GetInvokeType() const { |
| 364 | return invoke_type_; |
| 365 | } |
| 366 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 367 | InstructionSet GetInstructionSet() const { |
| 368 | return instruction_set_; |
| 369 | } |
| 370 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 371 | bool HasTryCatch() const { return has_try_catch_; } |
| 372 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 373 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 374 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 375 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 376 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 377 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 378 | // The instruction has been inserted into the graph, either as a constant, or |
| 379 | // before cursor. |
| 380 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 381 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 382 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 383 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 384 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 385 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 386 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 387 | template <class InstructionType, typename ValueType> |
| 388 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 389 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 390 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 391 | // Try to find an existing constant of the given value. |
| 392 | InstructionType* constant = nullptr; |
| 393 | auto cached_constant = cache->find(value); |
| 394 | if (cached_constant != cache->end()) { |
| 395 | constant = cached_constant->second; |
| 396 | } |
| 397 | |
| 398 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 399 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 400 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 401 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 402 | cache->Overwrite(value, constant); |
| 403 | InsertConstant(constant); |
| 404 | } |
| 405 | return constant; |
| 406 | } |
| 407 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 408 | void InsertConstant(HConstant* instruction); |
| 409 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 410 | // Cache a float constant into the graph. This method should only be |
| 411 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 412 | void CacheFloatConstant(HFloatConstant* constant); |
| 413 | |
| 414 | // See CacheFloatConstant comment. |
| 415 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 416 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 417 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 418 | |
| 419 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 420 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 421 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 422 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 423 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 424 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 425 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 426 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 427 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 428 | HBasicBlock* entry_block_; |
| 429 | HBasicBlock* exit_block_; |
| 430 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 431 | // The maximum number of virtual registers arguments passed to a HInvoke in this graph. |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 432 | uint16_t maximum_number_of_out_vregs_; |
| 433 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 434 | // The number of virtual registers in this method. Contains the parameters. |
| 435 | uint16_t number_of_vregs_; |
| 436 | |
| 437 | // The number of virtual registers used by parameters of this method. |
| 438 | uint16_t number_of_in_vregs_; |
| 439 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 440 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 441 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 442 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 443 | // Has bounds checks. We can totally skip BCE if it's false. |
| 444 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 445 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 446 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 447 | // try/catch-related passes if false. |
| 448 | bool has_try_catch_; |
| 449 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 450 | // Indicates whether the graph should be compiled in a way that |
| 451 | // ensures full debuggability. If false, we can apply more |
| 452 | // aggressive optimizations that may limit the level of debugging. |
| 453 | const bool debuggable_; |
| 454 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 455 | // The current id to assign to a newly added instruction. See HInstruction.id_. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 456 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 457 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 458 | // The dex file from which the method is from. |
| 459 | const DexFile& dex_file_; |
| 460 | |
| 461 | // The method index in the dex file. |
| 462 | const uint32_t method_idx_; |
| 463 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 464 | // If inlined, this encodes how the callee is being invoked. |
| 465 | const InvokeType invoke_type_; |
| 466 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 467 | // Whether the graph has been transformed to SSA form. Only used |
| 468 | // in debug mode to ensure we are not using properties only valid |
| 469 | // for non-SSA form (like the number of temporaries). |
| 470 | bool in_ssa_form_; |
| 471 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 472 | const bool should_generate_constructor_barrier_; |
| 473 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 474 | const InstructionSet instruction_set_; |
| 475 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 476 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 477 | HNullConstant* cached_null_constant_; |
| 478 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 479 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 480 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 481 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 482 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 483 | HCurrentMethod* cached_current_method_; |
| 484 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 485 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 486 | // for example for methods whose declaring class could not be resolved |
| 487 | // (such as when the superclass could not be found). |
| 488 | ArtMethod* art_method_; |
| 489 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 490 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 491 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 492 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 493 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 494 | }; |
| 495 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 496 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 497 | public: |
| 498 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 499 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 500 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 501 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 502 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 503 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 504 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 505 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 506 | |
| 507 | HBasicBlock* GetHeader() const { |
| 508 | return header_; |
| 509 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 510 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 511 | void SetHeader(HBasicBlock* block) { |
| 512 | header_ = block; |
| 513 | } |
| 514 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 515 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 516 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 517 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 518 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 519 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 520 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 523 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 524 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 525 | } |
| 526 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 527 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 528 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 531 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 532 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 535 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 536 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 537 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 538 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 539 | } |
| 540 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 541 | // Returns the lifetime position of the back edge that has the |
| 542 | // greatest lifetime position. |
| 543 | size_t GetLifetimeEnd() const; |
| 544 | |
| 545 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 546 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 547 | } |
| 548 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 549 | // Finds blocks that are part of this loop. Returns whether the loop is a natural loop, |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 550 | // that is the header dominates the back edge. |
| 551 | bool Populate(); |
| 552 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 553 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 554 | // Populate(). If there are no back edges left, the loop info is completely |
| 555 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 556 | // inner loops first. |
| 557 | void Update(); |
| 558 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 559 | // Returns whether this loop information contains `block`. |
| 560 | // Note that this loop information *must* be populated before entering this function. |
| 561 | bool Contains(const HBasicBlock& block) const; |
| 562 | |
| 563 | // Returns whether this loop information is an inner loop of `other`. |
| 564 | // Note that `other` *must* be populated before entering this function. |
| 565 | bool IsIn(const HLoopInformation& other) const; |
| 566 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 567 | // Returns true if instruction is not defined within this loop. |
| 568 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 569 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 570 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 571 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 572 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 573 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 574 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 575 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 576 | // Internal recursive implementation of `Populate`. |
| 577 | void PopulateRecursive(HBasicBlock* block); |
| 578 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 579 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 580 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 581 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 582 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 583 | |
| 584 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 585 | }; |
| 586 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 587 | // Stores try/catch information for basic blocks. |
| 588 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 589 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 590 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 591 | public: |
| 592 | // Try block information constructor. |
| 593 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 594 | : try_entry_(&try_entry), |
| 595 | catch_dex_file_(nullptr), |
| 596 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 597 | DCHECK(try_entry_ != nullptr); |
| 598 | } |
| 599 | |
| 600 | // Catch block information constructor. |
| 601 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 602 | : try_entry_(nullptr), |
| 603 | catch_dex_file_(&dex_file), |
| 604 | catch_type_index_(catch_type_index) {} |
| 605 | |
| 606 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 607 | |
| 608 | const HTryBoundary& GetTryEntry() const { |
| 609 | DCHECK(IsTryBlock()); |
| 610 | return *try_entry_; |
| 611 | } |
| 612 | |
| 613 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 614 | |
| 615 | bool IsCatchAllTypeIndex() const { |
| 616 | DCHECK(IsCatchBlock()); |
| 617 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 618 | } |
| 619 | |
| 620 | uint16_t GetCatchTypeIndex() const { |
| 621 | DCHECK(IsCatchBlock()); |
| 622 | return catch_type_index_; |
| 623 | } |
| 624 | |
| 625 | const DexFile& GetCatchDexFile() const { |
| 626 | DCHECK(IsCatchBlock()); |
| 627 | return *catch_dex_file_; |
| 628 | } |
| 629 | |
| 630 | private: |
| 631 | // One of possibly several TryBoundary instructions entering the block's try. |
| 632 | // Only set for try blocks. |
| 633 | const HTryBoundary* try_entry_; |
| 634 | |
| 635 | // Exception type information. Only set for catch blocks. |
| 636 | const DexFile* catch_dex_file_; |
| 637 | const uint16_t catch_type_index_; |
| 638 | }; |
| 639 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 640 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 641 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 642 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 643 | // A block in a method. Contains the list of instructions represented |
| 644 | // as a double linked list. Each block knows its predecessors and |
| 645 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 646 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 647 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 648 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 649 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 650 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 651 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 652 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 653 | loop_information_(nullptr), |
| 654 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 655 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 656 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 657 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 658 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 659 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 660 | try_catch_information_(nullptr) { |
| 661 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 662 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 663 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 664 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 665 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 666 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 667 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 670 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 671 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 672 | } |
| 673 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 674 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 675 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 676 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 677 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 678 | return ContainsElement(successors_, block, start_from); |
| 679 | } |
| 680 | |
| 681 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 682 | return dominated_blocks_; |
| 683 | } |
| 684 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 685 | bool IsEntryBlock() const { |
| 686 | return graph_->GetEntryBlock() == this; |
| 687 | } |
| 688 | |
| 689 | bool IsExitBlock() const { |
| 690 | return graph_->GetExitBlock() == this; |
| 691 | } |
| 692 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 693 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 694 | bool IsSingleTryBoundary() const; |
| 695 | |
| 696 | // Returns true if this block emits nothing but a jump. |
| 697 | bool IsSingleJump() const { |
| 698 | HLoopInformation* loop_info = GetLoopInformation(); |
| 699 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 700 | // Back edges generate a suspend check. |
| 701 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 702 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 703 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 704 | void AddBackEdge(HBasicBlock* back_edge) { |
| 705 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 706 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 707 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 708 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 709 | loop_information_->AddBackEdge(back_edge); |
| 710 | } |
| 711 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 712 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 713 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 714 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 715 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 716 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 717 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 718 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 719 | HBasicBlock* GetDominator() const { return dominator_; } |
| 720 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 721 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 722 | |
| 723 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 724 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 725 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 726 | |
| 727 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 728 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 729 | } |
| 730 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 731 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 732 | |
| 733 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 734 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 737 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 738 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 739 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 740 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 741 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 742 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 743 | |
| 744 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 745 | successors_.push_back(block); |
| 746 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 747 | } |
| 748 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 749 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 750 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 751 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 752 | new_block->predecessors_.push_back(this); |
| 753 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 756 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 757 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 758 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 759 | new_block->successors_.push_back(this); |
| 760 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 763 | // Insert `this` between `predecessor` and `successor. This method |
| 764 | // preserves the indicies, and will update the first edge found between |
| 765 | // `predecessor` and `successor`. |
| 766 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 767 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 768 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 769 | successor->predecessors_[predecessor_index] = this; |
| 770 | predecessor->successors_[successor_index] = this; |
| 771 | successors_.push_back(successor); |
| 772 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 773 | } |
| 774 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 775 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 776 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 777 | } |
| 778 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 779 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 780 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 783 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 784 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 788 | predecessors_.push_back(block); |
| 789 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 790 | } |
| 791 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 792 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 793 | DCHECK_EQ(predecessors_.size(), 2u); |
| 794 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 795 | } |
| 796 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 797 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 798 | DCHECK_EQ(successors_.size(), 2u); |
| 799 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 800 | } |
| 801 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 802 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 803 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 804 | } |
| 805 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 806 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 807 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 808 | } |
| 809 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 810 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 812 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 816 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 817 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | // Returns whether the first occurrence of `predecessor` in the list of |
| 821 | // predecessors is at index `idx`. |
| 822 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 823 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 824 | return GetPredecessorIndexOf(predecessor) == idx; |
| 825 | } |
| 826 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 827 | // Create a new block between this block and its predecessors. The new block |
| 828 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 829 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 830 | // loop and try/catch information are not updated. |
| 831 | HBasicBlock* CreateImmediateDominator(); |
| 832 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 833 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 834 | // created, latter block. Note that this method will add the block to the |
| 835 | // graph, create a Goto at the end of the former block and will create an edge |
| 836 | // 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] | 837 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 838 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 839 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 840 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 841 | // created block. Note that this method just updates raw block information, |
| 842 | // like predecessors, successors, dominators, and instruction list. It does not |
| 843 | // update the graph, reverse post order, loop information, nor make sure the |
| 844 | // blocks are consistent (for example ending with a control flow instruction). |
| 845 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 846 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 847 | // Split catch block into two blocks after the original move-exception bytecode |
| 848 | // instruction, or at the beginning if not present. Returns the newly created, |
| 849 | // latter block, or nullptr if such block could not be created (must be dead |
| 850 | // in that case). Note that this method just updates raw block information, |
| 851 | // like predecessors, successors, dominators, and instruction list. It does not |
| 852 | // update the graph, reverse post order, loop information, nor make sure the |
| 853 | // blocks are consistent (for example ending with a control flow instruction). |
| 854 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 855 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 856 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 857 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 858 | // that this method does not update the graph, reverse post order, loop |
| 859 | // information, nor make sure the blocks are consistent (for example ending |
| 860 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 861 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 862 | |
| 863 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 864 | // of `this` are moved to `other`. |
| 865 | // Note that this method does not update the graph, reverse post order, loop |
| 866 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 867 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 868 | void ReplaceWith(HBasicBlock* other); |
| 869 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 870 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 871 | // order, links to predecessors, successors, dominators and deletes the block |
| 872 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 873 | // predecessor of `other` and vice versa. |
| 874 | void MergeWith(HBasicBlock* other); |
| 875 | |
| 876 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 877 | // removes it from all loops it is included in and eventually from the graph. |
| 878 | // The block must not dominate any other block. Predecessors and successors |
| 879 | // are safely updated. |
| 880 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 881 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 882 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 883 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 884 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 885 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 886 | // Replace instruction `initial` with `replacement` within this block. |
| 887 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 888 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 889 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 890 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 891 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 892 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 893 | // instruction is not in use and removes it from the use lists of its inputs. |
| 894 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 895 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 896 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 897 | |
| 898 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 899 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 900 | } |
| 901 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 902 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 903 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 904 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 907 | HLoopInformation* GetLoopInformation() const { |
| 908 | return loop_information_; |
| 909 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 910 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 911 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 912 | // 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] | 913 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 914 | void SetInLoop(HLoopInformation* info) { |
| 915 | if (IsLoopHeader()) { |
| 916 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 917 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 918 | loop_information_ = info; |
| 919 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 920 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 921 | // Note that a non loop header having a loop information means this loop information |
| 922 | // has already been populated |
| 923 | loop_information_ = info; |
| 924 | } else { |
| 925 | // Block is part of an inner loop. Do not update the loop information. |
| 926 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 927 | // at this point, because this method is being called while populating `info`. |
| 928 | } |
| 929 | } |
| 930 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 931 | // Raw update of the loop information. |
| 932 | void SetLoopInformation(HLoopInformation* info) { |
| 933 | loop_information_ = info; |
| 934 | } |
| 935 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 936 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 937 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 938 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 939 | |
| 940 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 941 | try_catch_information_ = try_catch_information; |
| 942 | } |
| 943 | |
| 944 | bool IsTryBlock() const { |
| 945 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 946 | } |
| 947 | |
| 948 | bool IsCatchBlock() const { |
| 949 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 950 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 951 | |
| 952 | // Returns the try entry that this block's successors should have. They will |
| 953 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 954 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 955 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 956 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 957 | bool HasThrowingInstructions() const; |
| 958 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 959 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 960 | bool Dominates(HBasicBlock* block) const; |
| 961 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 962 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 963 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 964 | |
| 965 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 966 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 967 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 968 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 969 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 970 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 971 | bool HasSinglePhi() const; |
| 972 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 973 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 974 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 975 | ArenaVector<HBasicBlock*> predecessors_; |
| 976 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 977 | HInstructionList instructions_; |
| 978 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 979 | HLoopInformation* loop_information_; |
| 980 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 981 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 982 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 983 | // The dex program counter of the first instruction of this block. |
| 984 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 985 | size_t lifetime_start_; |
| 986 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 987 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 988 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 989 | friend class HGraph; |
| 990 | friend class HInstruction; |
| 991 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 992 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 993 | }; |
| 994 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 995 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 996 | // from the innermost to the outermost. |
| 997 | class HLoopInformationOutwardIterator : public ValueObject { |
| 998 | public: |
| 999 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1000 | : current_(block.GetLoopInformation()) {} |
| 1001 | |
| 1002 | bool Done() const { return current_ == nullptr; } |
| 1003 | |
| 1004 | void Advance() { |
| 1005 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1006 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | HLoopInformation* Current() const { |
| 1010 | DCHECK(!Done()); |
| 1011 | return current_; |
| 1012 | } |
| 1013 | |
| 1014 | private: |
| 1015 | HLoopInformation* current_; |
| 1016 | |
| 1017 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1018 | }; |
| 1019 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1020 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1021 | M(Above, Condition) \ |
| 1022 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1023 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1024 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1025 | M(ArrayGet, Instruction) \ |
| 1026 | M(ArrayLength, Instruction) \ |
| 1027 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1028 | M(Below, Condition) \ |
| 1029 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1030 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1031 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1032 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1033 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1034 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1035 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1036 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1037 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1038 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1039 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1040 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1041 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1042 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1043 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1044 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1045 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1046 | M(FloatConstant, Constant) \ |
| 1047 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1048 | M(GreaterThan, Condition) \ |
| 1049 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1050 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1051 | M(InstanceFieldGet, Instruction) \ |
| 1052 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1053 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1054 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1055 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1056 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1057 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1058 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1059 | M(LessThan, Condition) \ |
| 1060 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1061 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1062 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1063 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1064 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1065 | M(Local, Instruction) \ |
| 1066 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1067 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1068 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1069 | M(Mul, BinaryOperation) \ |
| 1070 | M(Neg, UnaryOperation) \ |
| 1071 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1072 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1073 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1074 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1075 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1076 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1077 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1078 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1079 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1080 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1081 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1082 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1083 | M(Return, Instruction) \ |
| 1084 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1085 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1086 | M(Shl, BinaryOperation) \ |
| 1087 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1088 | M(StaticFieldGet, Instruction) \ |
| 1089 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1090 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1091 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1092 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1093 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1094 | M(StoreLocal, Instruction) \ |
| 1095 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1096 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1097 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1098 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1099 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1100 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1101 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1102 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1103 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1104 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1105 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1106 | #else |
| 1107 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1108 | M(ArmDexCacheArraysBase, Instruction) |
| 1109 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1110 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1111 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1112 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1113 | #else |
| 1114 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1115 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1116 | M(Arm64IntermediateAddress, Instruction) \ |
| 1117 | M(Arm64MultiplyAccumulate, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1118 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1119 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1120 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1121 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1122 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1123 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1124 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1125 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1126 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1127 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1128 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1129 | M(X86LoadFromConstantTable, Instruction) \ |
| 1130 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1131 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1132 | |
| 1133 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1134 | |
| 1135 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1136 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1137 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1138 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1139 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1140 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1141 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1142 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1143 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1144 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1145 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1146 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1147 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1148 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1149 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1150 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1151 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1152 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1153 | #undef FORWARD_DECLARATION |
| 1154 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1155 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1156 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1157 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1158 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1159 | H##type* As##type() OVERRIDE { return this; } \ |
| 1160 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1161 | return other->Is##type(); \ |
| 1162 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1163 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1164 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1165 | template <typename T> class HUseList; |
| 1166 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1167 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1168 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1169 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1170 | HUseListNode* GetPrevious() const { return prev_; } |
| 1171 | HUseListNode* GetNext() const { return next_; } |
| 1172 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1173 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1174 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1175 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1176 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1177 | HUseListNode(T user, size_t index) |
| 1178 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1179 | |
| 1180 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1181 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1182 | HUseListNode<T>* prev_; |
| 1183 | HUseListNode<T>* next_; |
| 1184 | |
| 1185 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1186 | |
| 1187 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1188 | }; |
| 1189 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1190 | template <typename T> |
| 1191 | class HUseList : public ValueObject { |
| 1192 | public: |
| 1193 | HUseList() : first_(nullptr) {} |
| 1194 | |
| 1195 | void Clear() { |
| 1196 | first_ = nullptr; |
| 1197 | } |
| 1198 | |
| 1199 | // Adds a new entry at the beginning of the use list and returns |
| 1200 | // the newly created node. |
| 1201 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1202 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1203 | if (IsEmpty()) { |
| 1204 | first_ = new_node; |
| 1205 | } else { |
| 1206 | first_->prev_ = new_node; |
| 1207 | new_node->next_ = first_; |
| 1208 | first_ = new_node; |
| 1209 | } |
| 1210 | return new_node; |
| 1211 | } |
| 1212 | |
| 1213 | HUseListNode<T>* GetFirst() const { |
| 1214 | return first_; |
| 1215 | } |
| 1216 | |
| 1217 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1218 | DCHECK(node != nullptr); |
| 1219 | DCHECK(Contains(node)); |
| 1220 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1221 | if (node->prev_ != nullptr) { |
| 1222 | node->prev_->next_ = node->next_; |
| 1223 | } |
| 1224 | if (node->next_ != nullptr) { |
| 1225 | node->next_->prev_ = node->prev_; |
| 1226 | } |
| 1227 | if (node == first_) { |
| 1228 | first_ = node->next_; |
| 1229 | } |
| 1230 | } |
| 1231 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1232 | bool Contains(const HUseListNode<T>* node) const { |
| 1233 | if (node == nullptr) { |
| 1234 | return false; |
| 1235 | } |
| 1236 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1237 | if (current == node) { |
| 1238 | return true; |
| 1239 | } |
| 1240 | } |
| 1241 | return false; |
| 1242 | } |
| 1243 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1244 | bool IsEmpty() const { |
| 1245 | return first_ == nullptr; |
| 1246 | } |
| 1247 | |
| 1248 | bool HasOnlyOneUse() const { |
| 1249 | return first_ != nullptr && first_->next_ == nullptr; |
| 1250 | } |
| 1251 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1252 | size_t SizeSlow() const { |
| 1253 | size_t count = 0; |
| 1254 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1255 | ++count; |
| 1256 | } |
| 1257 | return count; |
| 1258 | } |
| 1259 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1260 | private: |
| 1261 | HUseListNode<T>* first_; |
| 1262 | }; |
| 1263 | |
| 1264 | template<typename T> |
| 1265 | class HUseIterator : public ValueObject { |
| 1266 | public: |
| 1267 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1268 | |
| 1269 | bool Done() const { return current_ == nullptr; } |
| 1270 | |
| 1271 | void Advance() { |
| 1272 | DCHECK(!Done()); |
| 1273 | current_ = current_->GetNext(); |
| 1274 | } |
| 1275 | |
| 1276 | HUseListNode<T>* Current() const { |
| 1277 | DCHECK(!Done()); |
| 1278 | return current_; |
| 1279 | } |
| 1280 | |
| 1281 | private: |
| 1282 | HUseListNode<T>* current_; |
| 1283 | |
| 1284 | friend class HValue; |
| 1285 | }; |
| 1286 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1287 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1288 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1289 | // by the used instructions. |
| 1290 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1291 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1292 | public: |
| 1293 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1294 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1295 | |
| 1296 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1297 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1298 | DCHECK(instruction_ != nullptr); |
| 1299 | DCHECK(use_node_ != nullptr); |
| 1300 | DCHECK(old_record.use_node_ == nullptr); |
| 1301 | } |
| 1302 | |
| 1303 | HInstruction* GetInstruction() const { return instruction_; } |
| 1304 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1305 | |
| 1306 | private: |
| 1307 | // Instruction used by the user. |
| 1308 | HInstruction* instruction_; |
| 1309 | |
| 1310 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1311 | HUseListNode<T>* use_node_; |
| 1312 | }; |
| 1313 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1314 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1315 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1316 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1317 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1318 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1319 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1320 | * modify the value of a reference field read [although it may modify the |
| 1321 | * reference fetch prior to reading the field, which is represented by its own |
| 1322 | * write/read dependence]). The analysis makes conservative points-to |
| 1323 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1324 | * the same, and any reference read depends on any reference read without |
| 1325 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1326 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1327 | * The internal representation uses 38-bit and is described in the table below. |
| 1328 | * The first line indicates the side effect, and for field/array accesses the |
| 1329 | * second line indicates the type of the access (in the order of the |
| 1330 | * Primitive::Type enum). |
| 1331 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1332 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1333 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1334 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1335 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1336 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1337 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1338 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1339 | * |
| 1340 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1341 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1342 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1343 | class SideEffects : public ValueObject { |
| 1344 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1345 | SideEffects() : flags_(0) {} |
| 1346 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1347 | static SideEffects None() { |
| 1348 | return SideEffects(0); |
| 1349 | } |
| 1350 | |
| 1351 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1352 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1353 | } |
| 1354 | |
| 1355 | static SideEffects AllChanges() { |
| 1356 | return SideEffects(kAllChangeBits); |
| 1357 | } |
| 1358 | |
| 1359 | static SideEffects AllDependencies() { |
| 1360 | return SideEffects(kAllDependOnBits); |
| 1361 | } |
| 1362 | |
| 1363 | static SideEffects AllExceptGCDependency() { |
| 1364 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1365 | } |
| 1366 | |
| 1367 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1368 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1369 | } |
| 1370 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1371 | static SideEffects AllWrites() { |
| 1372 | return SideEffects(kAllWrites); |
| 1373 | } |
| 1374 | |
| 1375 | static SideEffects AllReads() { |
| 1376 | return SideEffects(kAllReads); |
| 1377 | } |
| 1378 | |
| 1379 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1380 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1381 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1382 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1383 | } |
| 1384 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1385 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1386 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1387 | } |
| 1388 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1389 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1390 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1391 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1392 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1396 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1397 | } |
| 1398 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1399 | static SideEffects CanTriggerGC() { |
| 1400 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1401 | } |
| 1402 | |
| 1403 | static SideEffects DependsOnGC() { |
| 1404 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1405 | } |
| 1406 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1407 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1408 | SideEffects Union(SideEffects other) const { |
| 1409 | return SideEffects(flags_ | other.flags_); |
| 1410 | } |
| 1411 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1412 | SideEffects Exclusion(SideEffects other) const { |
| 1413 | return SideEffects(flags_ & ~other.flags_); |
| 1414 | } |
| 1415 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1416 | void Add(SideEffects other) { |
| 1417 | flags_ |= other.flags_; |
| 1418 | } |
| 1419 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1420 | bool Includes(SideEffects other) const { |
| 1421 | return (other.flags_ & flags_) == other.flags_; |
| 1422 | } |
| 1423 | |
| 1424 | bool HasSideEffects() const { |
| 1425 | return (flags_ & kAllChangeBits); |
| 1426 | } |
| 1427 | |
| 1428 | bool HasDependencies() const { |
| 1429 | return (flags_ & kAllDependOnBits); |
| 1430 | } |
| 1431 | |
| 1432 | // Returns true if there are no side effects or dependencies. |
| 1433 | bool DoesNothing() const { |
| 1434 | return flags_ == 0; |
| 1435 | } |
| 1436 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1437 | // Returns true if something is written. |
| 1438 | bool DoesAnyWrite() const { |
| 1439 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1440 | } |
| 1441 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1442 | // Returns true if something is read. |
| 1443 | bool DoesAnyRead() const { |
| 1444 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1447 | // Returns true if potentially everything is written and read |
| 1448 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1449 | bool DoesAllReadWrite() const { |
| 1450 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1451 | } |
| 1452 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1453 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1454 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1457 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1458 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1459 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1460 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1464 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1465 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1466 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1467 | for (int s = kLastBit; s >= 0; s--) { |
| 1468 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1469 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1470 | // This is a bit for the GC side effect. |
| 1471 | if (current_bit_is_set) { |
| 1472 | flags += "GC"; |
| 1473 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1474 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1475 | } else { |
| 1476 | // This is a bit for the array/field analysis. |
| 1477 | // The underscore character stands for the 'can trigger GC' bit. |
| 1478 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1479 | if (current_bit_is_set) { |
| 1480 | flags += kDebug[s]; |
| 1481 | } |
| 1482 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1483 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1484 | flags += "|"; |
| 1485 | } |
| 1486 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1487 | } |
| 1488 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1489 | } |
| 1490 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1491 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1492 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1493 | private: |
| 1494 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1495 | |
| 1496 | static constexpr int kFieldWriteOffset = 0; |
| 1497 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1498 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1499 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1500 | |
| 1501 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1502 | |
| 1503 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1504 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1505 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1506 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1507 | |
| 1508 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1509 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1510 | |
| 1511 | // Aliases. |
| 1512 | |
| 1513 | static_assert(kChangeBits == kDependOnBits, |
| 1514 | "the 'change' bits should match the 'depend on' bits."); |
| 1515 | |
| 1516 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1517 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1518 | static constexpr uint64_t kAllWrites = |
| 1519 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1520 | static constexpr uint64_t kAllReads = |
| 1521 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1522 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1523 | // Work around the fact that HIR aliases I/F and J/D. |
| 1524 | // TODO: remove this interceptor once HIR types are clean |
| 1525 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1526 | switch (type) { |
| 1527 | case Primitive::kPrimInt: |
| 1528 | case Primitive::kPrimFloat: |
| 1529 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1530 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1531 | case Primitive::kPrimLong: |
| 1532 | case Primitive::kPrimDouble: |
| 1533 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1534 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1535 | default: |
| 1536 | return TypeFlag(type, offset); |
| 1537 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1538 | } |
| 1539 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1540 | // Translates type to bit flag. |
| 1541 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1542 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1543 | const uint64_t one = 1; |
| 1544 | const int shift = type; // 0-based consecutive enum |
| 1545 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1546 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1547 | return one << (type + offset); |
| 1548 | } |
| 1549 | |
| 1550 | // Private constructor on direct flags value. |
| 1551 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1552 | |
| 1553 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1554 | }; |
| 1555 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1556 | // 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] | 1557 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1558 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1559 | HEnvironment(ArenaAllocator* arena, |
| 1560 | size_t number_of_vregs, |
| 1561 | const DexFile& dex_file, |
| 1562 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1563 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1564 | InvokeType invoke_type, |
| 1565 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1566 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1567 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1568 | parent_(nullptr), |
| 1569 | dex_file_(dex_file), |
| 1570 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1571 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1572 | invoke_type_(invoke_type), |
| 1573 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1574 | } |
| 1575 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1576 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1577 | : HEnvironment(arena, |
| 1578 | to_copy.Size(), |
| 1579 | to_copy.GetDexFile(), |
| 1580 | to_copy.GetMethodIdx(), |
| 1581 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1582 | to_copy.GetInvokeType(), |
| 1583 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1584 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1585 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1586 | if (parent_ != nullptr) { |
| 1587 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1588 | } else { |
| 1589 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1590 | parent_->CopyFrom(parent); |
| 1591 | if (parent->GetParent() != nullptr) { |
| 1592 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1593 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1594 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1595 | } |
| 1596 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1597 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1598 | void CopyFrom(HEnvironment* environment); |
| 1599 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1600 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1601 | // input to the loop phi instead. This is for inserting instructions that |
| 1602 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1603 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1604 | |
| 1605 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1606 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
| 1609 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1610 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1613 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1614 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1615 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1616 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1617 | HEnvironment* GetParent() const { return parent_; } |
| 1618 | |
| 1619 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1620 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1624 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | uint32_t GetDexPc() const { |
| 1628 | return dex_pc_; |
| 1629 | } |
| 1630 | |
| 1631 | uint32_t GetMethodIdx() const { |
| 1632 | return method_idx_; |
| 1633 | } |
| 1634 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1635 | InvokeType GetInvokeType() const { |
| 1636 | return invoke_type_; |
| 1637 | } |
| 1638 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1639 | const DexFile& GetDexFile() const { |
| 1640 | return dex_file_; |
| 1641 | } |
| 1642 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1643 | HInstruction* GetHolder() const { |
| 1644 | return holder_; |
| 1645 | } |
| 1646 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1647 | |
| 1648 | bool IsFromInlinedInvoke() const { |
| 1649 | return GetParent() != nullptr; |
| 1650 | } |
| 1651 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1652 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1653 | // Record instructions' use entries of this environment for constant-time removal. |
| 1654 | // It should only be called by HInstruction when a new environment use is added. |
| 1655 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1656 | DCHECK(env_use->GetUser() == this); |
| 1657 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1658 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1659 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1660 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1661 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1662 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1663 | HEnvironment* parent_; |
| 1664 | const DexFile& dex_file_; |
| 1665 | const uint32_t method_idx_; |
| 1666 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1667 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1668 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1669 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1670 | HInstruction* const holder_; |
| 1671 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1672 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1673 | |
| 1674 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1675 | }; |
| 1676 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1677 | class ReferenceTypeInfo : ValueObject { |
| 1678 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1679 | typedef Handle<mirror::Class> TypeHandle; |
| 1680 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1681 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1682 | // The constructor will check that the type_handle is valid. |
| 1683 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1686 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1687 | |
| 1688 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1689 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1690 | } |
| 1691 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1692 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1693 | return IsValidHandle(type_handle_); |
| 1694 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1695 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1696 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1697 | |
| 1698 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1699 | DCHECK(IsValid()); |
| 1700 | return GetTypeHandle()->IsObjectClass(); |
| 1701 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1702 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1703 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1704 | DCHECK(IsValid()); |
| 1705 | return GetTypeHandle()->IsStringClass(); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1706 | } |
| 1707 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1708 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1709 | DCHECK(IsValid()); |
| 1710 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 1711 | } |
| 1712 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1713 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1714 | DCHECK(IsValid()); |
| 1715 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1716 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1717 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1718 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1719 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1720 | return GetTypeHandle()->IsArrayClass(); |
| 1721 | } |
| 1722 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1723 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1724 | DCHECK(IsValid()); |
| 1725 | return GetTypeHandle()->IsPrimitiveArray(); |
| 1726 | } |
| 1727 | |
| 1728 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1729 | DCHECK(IsValid()); |
| 1730 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 1731 | } |
| 1732 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1733 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1734 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1735 | if (!IsExact()) return false; |
| 1736 | if (!IsArrayClass()) return false; |
| 1737 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1738 | } |
| 1739 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1740 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1741 | DCHECK(IsValid()); |
| 1742 | if (!IsExact()) return false; |
| 1743 | if (!IsArrayClass()) return false; |
| 1744 | if (!rti.IsArrayClass()) return false; |
| 1745 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 1746 | rti.GetTypeHandle()->GetComponentType()); |
| 1747 | } |
| 1748 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1749 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1750 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1751 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1752 | DCHECK(IsValid()); |
| 1753 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1754 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1755 | } |
| 1756 | |
Calin Juravle | cdfed3d | 2015-10-26 14:05:01 +0000 | [diff] [blame] | 1757 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1758 | DCHECK(IsValid()); |
| 1759 | DCHECK(rti.IsValid()); |
| 1760 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 1761 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1762 | } |
| 1763 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1764 | // Returns true if the type information provide the same amount of details. |
| 1765 | // 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] | 1766 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1767 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1768 | if (!IsValid() && !rti.IsValid()) { |
| 1769 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1770 | return true; |
| 1771 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1772 | if (!IsValid() || !rti.IsValid()) { |
| 1773 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1774 | return false; |
| 1775 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1776 | return IsExact() == rti.IsExact() |
| 1777 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1781 | ReferenceTypeInfo(); |
| 1782 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1783 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1784 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1785 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1786 | // 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] | 1787 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1788 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1789 | }; |
| 1790 | |
| 1791 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1792 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1793 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1794 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1795 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1796 | : previous_(nullptr), |
| 1797 | next_(nullptr), |
| 1798 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1799 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1800 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1801 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1802 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1803 | locations_(nullptr), |
| 1804 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1805 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1806 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1807 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1808 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1809 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1810 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1811 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1812 | enum InstructionKind { |
| 1813 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1814 | }; |
| 1815 | #undef DECLARE_KIND |
| 1816 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1817 | HInstruction* GetNext() const { return next_; } |
| 1818 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1819 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1820 | HInstruction* GetNextDisregardingMoves() const; |
| 1821 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1822 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1823 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1824 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1825 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1826 | bool IsInBlock() const { return block_ != nullptr; } |
| 1827 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1828 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1829 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1830 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1831 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1832 | |
| 1833 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1834 | virtual const char* DebugName() const = 0; |
| 1835 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1836 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1837 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1838 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1839 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1840 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1841 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1842 | |
| 1843 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1844 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1845 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1846 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1847 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1848 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1849 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1850 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1851 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1852 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1853 | // Does not apply for all instructions, but having this at top level greatly |
| 1854 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1855 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1856 | virtual bool CanBeNull() const { |
| 1857 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1858 | return true; |
| 1859 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1860 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1861 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1862 | return false; |
| 1863 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1864 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1865 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1866 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1867 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1868 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1869 | return reference_type_info_; |
| 1870 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1871 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1872 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1873 | DCHECK(user != nullptr); |
| 1874 | HUseListNode<HInstruction*>* use = |
| 1875 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1876 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1877 | } |
| 1878 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1879 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1880 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1881 | HUseListNode<HEnvironment*>* env_use = |
| 1882 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1883 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1886 | void RemoveAsUserOfInput(size_t input) { |
| 1887 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1888 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1889 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1890 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1891 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1892 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1893 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1894 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1895 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1896 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1897 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1898 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1899 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1900 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1901 | // Does this instruction strictly dominate `other_instruction`? |
| 1902 | // Returns false if this instruction and `other_instruction` are the same. |
| 1903 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1904 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1905 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1906 | int GetId() const { return id_; } |
| 1907 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1908 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1909 | int GetSsaIndex() const { return ssa_index_; } |
| 1910 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1911 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1912 | |
| 1913 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1914 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1915 | // Set the `environment_` field. Raw because this method does not |
| 1916 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1917 | void SetRawEnvironment(HEnvironment* environment) { |
| 1918 | DCHECK(environment_ == nullptr); |
| 1919 | DCHECK_EQ(environment->GetHolder(), this); |
| 1920 | environment_ = environment; |
| 1921 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1922 | |
| 1923 | // Set the environment of this instruction, copying it from `environment`. While |
| 1924 | // copying, the uses lists are being updated. |
| 1925 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1926 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1927 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1928 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1929 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1930 | if (environment->GetParent() != nullptr) { |
| 1931 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1932 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1933 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1934 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1935 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1936 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1937 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1938 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1939 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1940 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1941 | if (environment->GetParent() != nullptr) { |
| 1942 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1943 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1946 | // Returns the number of entries in the environment. Typically, that is the |
| 1947 | // number of dex registers in a method. It could be more in case of inlining. |
| 1948 | size_t EnvironmentSize() const; |
| 1949 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1950 | LocationSummary* GetLocations() const { return locations_; } |
| 1951 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1952 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1953 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1954 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1955 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1956 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1957 | // uses of this instruction by `other` are *not* updated. |
| 1958 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1959 | ReplaceWith(other); |
| 1960 | other->ReplaceInput(this, use_index); |
| 1961 | } |
| 1962 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1963 | // Move `this` instruction before `cursor`. |
| 1964 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1965 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 1966 | // Move `this` before its first user and out of any loops. If there is no |
| 1967 | // out-of-loop user that dominates all other users, move the instruction |
| 1968 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 1969 | // |
| 1970 | // This can be used only on non-throwing instructions with no side effects that |
| 1971 | // have at least one use but no environment uses. |
| 1972 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 1973 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1974 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1975 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1976 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1977 | virtual H##type* As##type() { return nullptr; } |
| 1978 | |
| 1979 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1980 | #undef INSTRUCTION_TYPE_CHECK |
| 1981 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1982 | // Returns whether the instruction can be moved within the graph. |
| 1983 | virtual bool CanBeMoved() const { return false; } |
| 1984 | |
| 1985 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1986 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1987 | return false; |
| 1988 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1989 | |
| 1990 | // Returns whether any data encoded in the two instructions is equal. |
| 1991 | // This method does not look at the inputs. Both instructions must be |
| 1992 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1993 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1994 | return false; |
| 1995 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1996 | |
| 1997 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1998 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1999 | // 2) Their inputs are identical. |
| 2000 | bool Equals(HInstruction* other) const; |
| 2001 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2002 | virtual InstructionKind GetKind() const = 0; |
| 2003 | |
| 2004 | virtual size_t ComputeHashCode() const { |
| 2005 | size_t result = GetKind(); |
| 2006 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2007 | result = (result * 31) + InputAt(i)->GetId(); |
| 2008 | } |
| 2009 | return result; |
| 2010 | } |
| 2011 | |
| 2012 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2013 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2014 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2015 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2016 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2017 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2018 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2019 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2020 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2021 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2022 | |
| 2023 | // Returns whether the code generation of the instruction will require to have access |
| 2024 | // to the current method. Such instructions are: |
| 2025 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2026 | // to walk the stack and have the current method stored at a specific stack address. |
| 2027 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2028 | // fields of the current method. |
| 2029 | bool NeedsCurrentMethod() const { |
| 2030 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2031 | } |
| 2032 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2033 | // Returns whether the code generation of the instruction will require to have access |
| 2034 | // to the dex cache of the current method's declaring class via the current method. |
| 2035 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2036 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2037 | // Does this instruction have any use in an environment before |
| 2038 | // control flow hits 'other'? |
| 2039 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2040 | |
| 2041 | // Remove all references to environment uses of this instruction. |
| 2042 | // The caller must ensure that this is safe to do. |
| 2043 | void RemoveEnvironmentUsers(); |
| 2044 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2045 | protected: |
| 2046 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2047 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2048 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2049 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2050 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2051 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2052 | HInstruction* previous_; |
| 2053 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2054 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2055 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2056 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2057 | // An instruction gets an id when it is added to the graph. |
| 2058 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2059 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2060 | int id_; |
| 2061 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2062 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2063 | int ssa_index_; |
| 2064 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2065 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2066 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2067 | |
| 2068 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2069 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2070 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2071 | // The environment associated with this instruction. Not null if the instruction |
| 2072 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2073 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2074 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2075 | // Set by the code generator. |
| 2076 | LocationSummary* locations_; |
| 2077 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2078 | // Set by the liveness analysis. |
| 2079 | LiveInterval* live_interval_; |
| 2080 | |
| 2081 | // Set by the liveness analysis, this is the position in a linear |
| 2082 | // order of blocks where this instruction's live interval start. |
| 2083 | size_t lifetime_position_; |
| 2084 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2085 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2086 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2087 | // TODO: for primitive types this should be marked as invalid. |
| 2088 | ReferenceTypeInfo reference_type_info_; |
| 2089 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2090 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2091 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2092 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2093 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2094 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2095 | |
| 2096 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2097 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2098 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2099 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2100 | class HInputIterator : public ValueObject { |
| 2101 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2102 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2103 | |
| 2104 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2105 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2106 | void Advance() { index_++; } |
| 2107 | |
| 2108 | private: |
| 2109 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2110 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2111 | |
| 2112 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2113 | }; |
| 2114 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2115 | class HInstructionIterator : public ValueObject { |
| 2116 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2117 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2118 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2119 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2122 | bool Done() const { return instruction_ == nullptr; } |
| 2123 | HInstruction* Current() const { return instruction_; } |
| 2124 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2125 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2126 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | private: |
| 2130 | HInstruction* instruction_; |
| 2131 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2132 | |
| 2133 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2134 | }; |
| 2135 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2136 | class HBackwardInstructionIterator : public ValueObject { |
| 2137 | public: |
| 2138 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2139 | : instruction_(instructions.last_instruction_) { |
| 2140 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2141 | } |
| 2142 | |
| 2143 | bool Done() const { return instruction_ == nullptr; } |
| 2144 | HInstruction* Current() const { return instruction_; } |
| 2145 | void Advance() { |
| 2146 | instruction_ = next_; |
| 2147 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2148 | } |
| 2149 | |
| 2150 | private: |
| 2151 | HInstruction* instruction_; |
| 2152 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2153 | |
| 2154 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2155 | }; |
| 2156 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2157 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2158 | class HTemplateInstruction: public HInstruction { |
| 2159 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2160 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2161 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2162 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2163 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2164 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2165 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2166 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2167 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2168 | DCHECK_LT(i, N); |
| 2169 | return inputs_[i]; |
| 2170 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2171 | |
| 2172 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2173 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2174 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2175 | } |
| 2176 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2177 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2178 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2179 | |
| 2180 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2181 | }; |
| 2182 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2183 | // HTemplateInstruction specialization for N=0. |
| 2184 | template<> |
| 2185 | class HTemplateInstruction<0>: public HInstruction { |
| 2186 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2187 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2188 | : HInstruction(side_effects, dex_pc) {} |
| 2189 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2190 | virtual ~HTemplateInstruction() {} |
| 2191 | |
| 2192 | size_t InputCount() const OVERRIDE { return 0; } |
| 2193 | |
| 2194 | protected: |
| 2195 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2196 | LOG(FATAL) << "Unreachable"; |
| 2197 | UNREACHABLE(); |
| 2198 | } |
| 2199 | |
| 2200 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2201 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2202 | LOG(FATAL) << "Unreachable"; |
| 2203 | UNREACHABLE(); |
| 2204 | } |
| 2205 | |
| 2206 | private: |
| 2207 | friend class SsaBuilder; |
| 2208 | }; |
| 2209 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2210 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2211 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2212 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2213 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2214 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2215 | virtual ~HExpression() {} |
| 2216 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2217 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2218 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2219 | protected: |
| 2220 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2221 | }; |
| 2222 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2223 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2224 | // instruction that branches to the exit block. |
| 2225 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2226 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2227 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2228 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2229 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2230 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2231 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2232 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2233 | |
| 2234 | private: |
| 2235 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2236 | }; |
| 2237 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2238 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2239 | // instruction that branches to the exit block. |
| 2240 | class HReturn : public HTemplateInstruction<1> { |
| 2241 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2242 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2243 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2244 | SetRawInputAt(0, value); |
| 2245 | } |
| 2246 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2247 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2248 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2249 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2250 | |
| 2251 | private: |
| 2252 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2253 | }; |
| 2254 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2255 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2256 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2257 | // exit block. |
| 2258 | class HExit : public HTemplateInstruction<0> { |
| 2259 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2260 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2261 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2262 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2263 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2264 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2265 | |
| 2266 | private: |
| 2267 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2268 | }; |
| 2269 | |
| 2270 | // Jumps from one block to another. |
| 2271 | class HGoto : public HTemplateInstruction<0> { |
| 2272 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2273 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2274 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2275 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2276 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2277 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2278 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2281 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2282 | |
| 2283 | private: |
| 2284 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2285 | }; |
| 2286 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2287 | class HConstant : public HExpression<0> { |
| 2288 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2289 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2290 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2291 | |
| 2292 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2293 | |
| 2294 | virtual bool IsMinusOne() const { return false; } |
| 2295 | virtual bool IsZero() const { return false; } |
| 2296 | virtual bool IsOne() const { return false; } |
| 2297 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2298 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2299 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2300 | DECLARE_INSTRUCTION(Constant); |
| 2301 | |
| 2302 | private: |
| 2303 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2304 | }; |
| 2305 | |
| 2306 | class HNullConstant : public HConstant { |
| 2307 | public: |
| 2308 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2309 | return true; |
| 2310 | } |
| 2311 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2312 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2313 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2314 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2315 | |
| 2316 | DECLARE_INSTRUCTION(NullConstant); |
| 2317 | |
| 2318 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2319 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2320 | |
| 2321 | friend class HGraph; |
| 2322 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2323 | }; |
| 2324 | |
| 2325 | // Constants of the type int. Those can be from Dex instructions, or |
| 2326 | // synthesized (for example with the if-eqz instruction). |
| 2327 | class HIntConstant : public HConstant { |
| 2328 | public: |
| 2329 | int32_t GetValue() const { return value_; } |
| 2330 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2331 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2332 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2333 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2334 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2335 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2336 | DCHECK(other->IsIntConstant()); |
| 2337 | return other->AsIntConstant()->value_ == value_; |
| 2338 | } |
| 2339 | |
| 2340 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2341 | |
| 2342 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2343 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2344 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2345 | |
| 2346 | DECLARE_INSTRUCTION(IntConstant); |
| 2347 | |
| 2348 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2349 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2350 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2351 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2352 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2353 | |
| 2354 | const int32_t value_; |
| 2355 | |
| 2356 | friend class HGraph; |
| 2357 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2358 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2359 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2360 | }; |
| 2361 | |
| 2362 | class HLongConstant : public HConstant { |
| 2363 | public: |
| 2364 | int64_t GetValue() const { return value_; } |
| 2365 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2366 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2367 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2368 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2369 | DCHECK(other->IsLongConstant()); |
| 2370 | return other->AsLongConstant()->value_ == value_; |
| 2371 | } |
| 2372 | |
| 2373 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2374 | |
| 2375 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2376 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2377 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2378 | |
| 2379 | DECLARE_INSTRUCTION(LongConstant); |
| 2380 | |
| 2381 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2382 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2383 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2384 | |
| 2385 | const int64_t value_; |
| 2386 | |
| 2387 | friend class HGraph; |
| 2388 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2389 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2390 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2391 | // Conditional branch. A block ending with an HIf instruction must have |
| 2392 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2393 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2394 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2395 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2396 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2397 | SetRawInputAt(0, input); |
| 2398 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2399 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2400 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2401 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2402 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2403 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2407 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2410 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2411 | |
| 2412 | private: |
| 2413 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2414 | }; |
| 2415 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2416 | |
| 2417 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2418 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2419 | // non-exceptional control flow. |
| 2420 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2421 | // higher indices in no particular order. |
| 2422 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2423 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2424 | enum BoundaryKind { |
| 2425 | kEntry, |
| 2426 | kExit, |
| 2427 | }; |
| 2428 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2429 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2430 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2431 | |
| 2432 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2433 | |
| 2434 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2435 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2436 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2437 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2438 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2439 | } |
| 2440 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2441 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2442 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2443 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2444 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2445 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
| 2448 | // If not present already, adds `handler` to its block's list of exception |
| 2449 | // handlers. |
| 2450 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2451 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2452 | GetBlock()->AddSuccessor(handler); |
| 2453 | } |
| 2454 | } |
| 2455 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2456 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2457 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2458 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2459 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2460 | DECLARE_INSTRUCTION(TryBoundary); |
| 2461 | |
| 2462 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2463 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2464 | |
| 2465 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2466 | }; |
| 2467 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2468 | // Deoptimize to interpreter, upon checking a condition. |
| 2469 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2470 | public: |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2471 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2472 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2473 | SetRawInputAt(0, cond); |
| 2474 | } |
| 2475 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2476 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2477 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2478 | return true; |
| 2479 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2480 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2481 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2482 | |
| 2483 | DECLARE_INSTRUCTION(Deoptimize); |
| 2484 | |
| 2485 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2486 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2487 | }; |
| 2488 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2489 | // Represents the ArtMethod that was passed as a first argument to |
| 2490 | // the method. It is used by instructions that depend on it, like |
| 2491 | // instructions that work with the dex cache. |
| 2492 | class HCurrentMethod : public HExpression<0> { |
| 2493 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2494 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2495 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2496 | |
| 2497 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2498 | |
| 2499 | private: |
| 2500 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2501 | }; |
| 2502 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2503 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2504 | // have one successor for each entry in the switch table, and the final successor |
| 2505 | // will be the block containing the next Dex opcode. |
| 2506 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2507 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2508 | HPackedSwitch(int32_t start_value, |
| 2509 | uint32_t num_entries, |
| 2510 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2511 | uint32_t dex_pc = kNoDexPc) |
| 2512 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2513 | start_value_(start_value), |
| 2514 | num_entries_(num_entries) { |
| 2515 | SetRawInputAt(0, input); |
| 2516 | } |
| 2517 | |
| 2518 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2519 | |
| 2520 | int32_t GetStartValue() const { return start_value_; } |
| 2521 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2522 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2523 | |
| 2524 | HBasicBlock* GetDefaultBlock() const { |
| 2525 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2526 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2527 | } |
| 2528 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2529 | |
| 2530 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2531 | const int32_t start_value_; |
| 2532 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2533 | |
| 2534 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2535 | }; |
| 2536 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2537 | class HUnaryOperation : public HExpression<1> { |
| 2538 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2539 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2540 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2541 | SetRawInputAt(0, input); |
| 2542 | } |
| 2543 | |
| 2544 | HInstruction* GetInput() const { return InputAt(0); } |
| 2545 | Primitive::Type GetResultType() const { return GetType(); } |
| 2546 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2547 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2548 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2549 | return true; |
| 2550 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2551 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2552 | // Try to statically evaluate `operation` and return a HConstant |
| 2553 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2554 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2555 | HConstant* TryStaticEvaluation() const; |
| 2556 | |
| 2557 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2558 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2559 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2560 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2561 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2562 | |
| 2563 | private: |
| 2564 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2565 | }; |
| 2566 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2567 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2568 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2569 | HBinaryOperation(Primitive::Type result_type, |
| 2570 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2571 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2572 | SideEffects side_effects = SideEffects::None(), |
| 2573 | uint32_t dex_pc = kNoDexPc) |
| 2574 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2575 | SetRawInputAt(0, left); |
| 2576 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2577 | } |
| 2578 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2579 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2580 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2581 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2582 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2583 | virtual bool IsCommutative() const { return false; } |
| 2584 | |
| 2585 | // Put constant on the right. |
| 2586 | // Returns whether order is changed. |
| 2587 | bool OrderInputsWithConstantOnTheRight() { |
| 2588 | HInstruction* left = InputAt(0); |
| 2589 | HInstruction* right = InputAt(1); |
| 2590 | if (left->IsConstant() && !right->IsConstant()) { |
| 2591 | ReplaceInput(right, 0); |
| 2592 | ReplaceInput(left, 1); |
| 2593 | return true; |
| 2594 | } |
| 2595 | return false; |
| 2596 | } |
| 2597 | |
| 2598 | // Order inputs by instruction id, but favor constant on the right side. |
| 2599 | // This helps GVN for commutative ops. |
| 2600 | void OrderInputs() { |
| 2601 | DCHECK(IsCommutative()); |
| 2602 | HInstruction* left = InputAt(0); |
| 2603 | HInstruction* right = InputAt(1); |
| 2604 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2605 | return; |
| 2606 | } |
| 2607 | if (OrderInputsWithConstantOnTheRight()) { |
| 2608 | return; |
| 2609 | } |
| 2610 | // Order according to instruction id. |
| 2611 | if (left->GetId() > right->GetId()) { |
| 2612 | ReplaceInput(right, 0); |
| 2613 | ReplaceInput(left, 1); |
| 2614 | } |
| 2615 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2616 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2617 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2618 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2619 | return true; |
| 2620 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2621 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2622 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2623 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2624 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2625 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2626 | |
| 2627 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2628 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2629 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2630 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2631 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2632 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2633 | return nullptr; |
| 2634 | } |
| 2635 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2636 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2637 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2638 | return nullptr; |
| 2639 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2640 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2641 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| 2642 | VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; |
| 2643 | return nullptr; |
| 2644 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2645 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2646 | // 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] | 2647 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2648 | HConstant* GetConstantRight() const; |
| 2649 | |
| 2650 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2651 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2652 | HInstruction* GetLeastConstantLeft() const; |
| 2653 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2654 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2655 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2656 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2657 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2658 | }; |
| 2659 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2660 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2661 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2662 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2663 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2664 | kGtBias, // return 1 for NaN comparisons |
| 2665 | kLtBias, // return -1 for NaN comparisons |
| 2666 | }; |
| 2667 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2668 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2669 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2670 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2671 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2672 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2673 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2674 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2675 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2676 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2677 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2678 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2679 | // `instruction`, and disregard moves in between. |
| 2680 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2681 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2682 | DECLARE_INSTRUCTION(Condition); |
| 2683 | |
| 2684 | virtual IfCondition GetCondition() const = 0; |
| 2685 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2686 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2687 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2688 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2689 | |
| 2690 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2691 | |
| 2692 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2693 | return bias_ == other->AsCondition()->bias_; |
| 2694 | } |
| 2695 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2696 | bool IsFPConditionTrueIfNaN() const { |
| 2697 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2698 | IfCondition if_cond = GetCondition(); |
| 2699 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2700 | } |
| 2701 | |
| 2702 | bool IsFPConditionFalseIfNaN() const { |
| 2703 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2704 | IfCondition if_cond = GetCondition(); |
| 2705 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2706 | } |
| 2707 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2708 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2709 | // For register allocation purposes, returns whether this instruction needs to be |
| 2710 | // materialized (that is, not just be in the processor flags). |
| 2711 | bool needs_materialization_; |
| 2712 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2713 | // Needed if we merge a HCompare into a HCondition. |
| 2714 | ComparisonBias bias_; |
| 2715 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2716 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2717 | }; |
| 2718 | |
| 2719 | // Instruction to check if two inputs are equal to each other. |
| 2720 | class HEqual : public HCondition { |
| 2721 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2722 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2723 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2724 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2725 | bool IsCommutative() const OVERRIDE { return true; } |
| 2726 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2727 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2728 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2729 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2730 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2731 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2732 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2733 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2734 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2735 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2736 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2737 | return GetBlock()->GetGraph()->GetIntConstant(1); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2738 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2739 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2740 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2741 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2742 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2743 | return kCondEQ; |
| 2744 | } |
| 2745 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2746 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2747 | return kCondNE; |
| 2748 | } |
| 2749 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2750 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2751 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2752 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2753 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2754 | }; |
| 2755 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2756 | class HNotEqual : public HCondition { |
| 2757 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2758 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2759 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2760 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2761 | bool IsCommutative() const OVERRIDE { return true; } |
| 2762 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2763 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2764 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2765 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2766 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2767 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2768 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2769 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2770 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2771 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2772 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2773 | return GetBlock()->GetGraph()->GetIntConstant(0); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2774 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2775 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2776 | DECLARE_INSTRUCTION(NotEqual); |
| 2777 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2778 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2779 | return kCondNE; |
| 2780 | } |
| 2781 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2782 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2783 | return kCondEQ; |
| 2784 | } |
| 2785 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2786 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2787 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2788 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2789 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2790 | }; |
| 2791 | |
| 2792 | class HLessThan : public HCondition { |
| 2793 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2794 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2795 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2796 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2797 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2798 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2799 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2800 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2801 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2802 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2803 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2804 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2805 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2806 | DECLARE_INSTRUCTION(LessThan); |
| 2807 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2808 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2809 | return kCondLT; |
| 2810 | } |
| 2811 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2812 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2813 | return kCondGE; |
| 2814 | } |
| 2815 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2816 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2817 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2818 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2819 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2820 | }; |
| 2821 | |
| 2822 | class HLessThanOrEqual : public HCondition { |
| 2823 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2824 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2825 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2826 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2827 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2828 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2829 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2830 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2831 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2832 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2833 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2834 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2835 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2836 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2837 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2838 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2839 | return kCondLE; |
| 2840 | } |
| 2841 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2842 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2843 | return kCondGT; |
| 2844 | } |
| 2845 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2846 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2847 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2848 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2849 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2850 | }; |
| 2851 | |
| 2852 | class HGreaterThan : public HCondition { |
| 2853 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2854 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2855 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2856 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2857 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2858 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2859 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2860 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2861 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2862 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2863 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2864 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2865 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2866 | DECLARE_INSTRUCTION(GreaterThan); |
| 2867 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2868 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2869 | return kCondGT; |
| 2870 | } |
| 2871 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2872 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2873 | return kCondLE; |
| 2874 | } |
| 2875 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2876 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2877 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2878 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2879 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2880 | }; |
| 2881 | |
| 2882 | class HGreaterThanOrEqual : public HCondition { |
| 2883 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2884 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2885 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2886 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2887 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2888 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2889 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2890 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2891 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2892 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2893 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2894 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2895 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2896 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2897 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2898 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2899 | return kCondGE; |
| 2900 | } |
| 2901 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2902 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2903 | return kCondLT; |
| 2904 | } |
| 2905 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2906 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2907 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2908 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2909 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2910 | }; |
| 2911 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2912 | class HBelow : public HCondition { |
| 2913 | public: |
| 2914 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2915 | : HCondition(first, second, dex_pc) {} |
| 2916 | |
| 2917 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2918 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2919 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2920 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2921 | } |
| 2922 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2923 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2924 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2925 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2926 | } |
| 2927 | |
| 2928 | DECLARE_INSTRUCTION(Below); |
| 2929 | |
| 2930 | IfCondition GetCondition() const OVERRIDE { |
| 2931 | return kCondB; |
| 2932 | } |
| 2933 | |
| 2934 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2935 | return kCondAE; |
| 2936 | } |
| 2937 | |
| 2938 | private: |
| 2939 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2940 | |
| 2941 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 2942 | }; |
| 2943 | |
| 2944 | class HBelowOrEqual : public HCondition { |
| 2945 | public: |
| 2946 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2947 | : HCondition(first, second, dex_pc) {} |
| 2948 | |
| 2949 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2950 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2951 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2952 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2953 | } |
| 2954 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2955 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2956 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2957 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2958 | } |
| 2959 | |
| 2960 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 2961 | |
| 2962 | IfCondition GetCondition() const OVERRIDE { |
| 2963 | return kCondBE; |
| 2964 | } |
| 2965 | |
| 2966 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2967 | return kCondA; |
| 2968 | } |
| 2969 | |
| 2970 | private: |
| 2971 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2972 | |
| 2973 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 2974 | }; |
| 2975 | |
| 2976 | class HAbove : public HCondition { |
| 2977 | public: |
| 2978 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2979 | : HCondition(first, second, dex_pc) {} |
| 2980 | |
| 2981 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2982 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2983 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2984 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2985 | } |
| 2986 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2987 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2988 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2989 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2990 | } |
| 2991 | |
| 2992 | DECLARE_INSTRUCTION(Above); |
| 2993 | |
| 2994 | IfCondition GetCondition() const OVERRIDE { |
| 2995 | return kCondA; |
| 2996 | } |
| 2997 | |
| 2998 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2999 | return kCondBE; |
| 3000 | } |
| 3001 | |
| 3002 | private: |
| 3003 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3004 | |
| 3005 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3006 | }; |
| 3007 | |
| 3008 | class HAboveOrEqual : public HCondition { |
| 3009 | public: |
| 3010 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3011 | : HCondition(first, second, dex_pc) {} |
| 3012 | |
| 3013 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3014 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3015 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3016 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3017 | } |
| 3018 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3019 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3020 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3021 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3022 | } |
| 3023 | |
| 3024 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3025 | |
| 3026 | IfCondition GetCondition() const OVERRIDE { |
| 3027 | return kCondAE; |
| 3028 | } |
| 3029 | |
| 3030 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3031 | return kCondB; |
| 3032 | } |
| 3033 | |
| 3034 | private: |
| 3035 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3036 | |
| 3037 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3038 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3039 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3040 | // Instruction to check how two inputs compare to each other. |
| 3041 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3042 | class HCompare : public HBinaryOperation { |
| 3043 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3044 | HCompare(Primitive::Type type, |
| 3045 | HInstruction* first, |
| 3046 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3047 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3048 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3049 | : HBinaryOperation(Primitive::kPrimInt, |
| 3050 | first, |
| 3051 | second, |
| 3052 | SideEffectsForArchRuntimeCalls(type), |
| 3053 | dex_pc), |
| 3054 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3055 | DCHECK_EQ(type, first->GetType()); |
| 3056 | DCHECK_EQ(type, second->GetType()); |
| 3057 | } |
| 3058 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3059 | template <typename T> |
| 3060 | 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] | 3061 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3062 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3063 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3064 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3065 | } |
| 3066 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3067 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3068 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3069 | } |
| 3070 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3071 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3072 | return bias_ == other->AsCompare()->bias_; |
| 3073 | } |
| 3074 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3075 | ComparisonBias GetBias() const { return bias_; } |
| 3076 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3077 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3078 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3079 | |
| 3080 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3081 | // MIPS64 uses a runtime call for FP comparisons. |
| 3082 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3083 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3084 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3085 | DECLARE_INSTRUCTION(Compare); |
| 3086 | |
| 3087 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3088 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3089 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3090 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3091 | }; |
| 3092 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3093 | // A local in the graph. Corresponds to a Dex register. |
| 3094 | class HLocal : public HTemplateInstruction<0> { |
| 3095 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3096 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3097 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3098 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3099 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3100 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3101 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3102 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3103 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3104 | // The Dex register number. |
| 3105 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3106 | |
| 3107 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3108 | }; |
| 3109 | |
| 3110 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3111 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3112 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3113 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3114 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3115 | SetRawInputAt(0, local); |
| 3116 | } |
| 3117 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3118 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3119 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3120 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3121 | |
| 3122 | private: |
| 3123 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3124 | }; |
| 3125 | |
| 3126 | // Store a value in a given local. This instruction has two inputs: the value |
| 3127 | // and the local. |
| 3128 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3129 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3130 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3131 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3132 | SetRawInputAt(0, local); |
| 3133 | SetRawInputAt(1, value); |
| 3134 | } |
| 3135 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3136 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3137 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3138 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3139 | |
| 3140 | private: |
| 3141 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3142 | }; |
| 3143 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3144 | class HFloatConstant : public HConstant { |
| 3145 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3146 | float GetValue() const { return value_; } |
| 3147 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3148 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3149 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3150 | } |
| 3151 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3152 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3153 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3154 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3155 | } |
| 3156 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3157 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3158 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3159 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3160 | 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] | 3161 | } |
| 3162 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3163 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3164 | } |
| 3165 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3166 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3167 | } |
| 3168 | bool IsNaN() const { |
| 3169 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3170 | } |
| 3171 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3172 | DECLARE_INSTRUCTION(FloatConstant); |
| 3173 | |
| 3174 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3175 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3176 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3177 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3178 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3179 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3180 | const float value_; |
| 3181 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3182 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3183 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3184 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3185 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3186 | }; |
| 3187 | |
| 3188 | class HDoubleConstant : public HConstant { |
| 3189 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3190 | double GetValue() const { return value_; } |
| 3191 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3192 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3193 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3194 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3195 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3196 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3197 | } |
| 3198 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3199 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3200 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3201 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3202 | 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] | 3203 | } |
| 3204 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3205 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3206 | } |
| 3207 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3208 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3209 | } |
| 3210 | bool IsNaN() const { |
| 3211 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3212 | } |
| 3213 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3214 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3215 | |
| 3216 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3217 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3218 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3219 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3220 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3221 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3222 | const double value_; |
| 3223 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3224 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3225 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3226 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3227 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3228 | }; |
| 3229 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3230 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3231 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3232 | #include "intrinsics_list.h" |
| 3233 | kNone, |
| 3234 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3235 | #undef INTRINSICS_LIST |
| 3236 | #undef OPTIMIZING_INTRINSICS |
| 3237 | }; |
| 3238 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3239 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3240 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3241 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3242 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3243 | }; |
| 3244 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3245 | class HInvoke : public HInstruction { |
| 3246 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3247 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3248 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3249 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3250 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3251 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3252 | SetRawInputAt(index, argument); |
| 3253 | } |
| 3254 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3255 | // Return the number of arguments. This number can be lower than |
| 3256 | // the number of inputs returned by InputCount(), as some invoke |
| 3257 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3258 | // inputs at the end of their list of inputs. |
| 3259 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3260 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3261 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3262 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3263 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3264 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3265 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3266 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3267 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3268 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3269 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3270 | return intrinsic_; |
| 3271 | } |
| 3272 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3273 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3274 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3275 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3276 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3277 | } |
| 3278 | |
| 3279 | bool CanThrow() const OVERRIDE { return true; } |
| 3280 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3281 | uint32_t* GetIntrinsicOptimizations() { |
| 3282 | return &intrinsic_optimizations_; |
| 3283 | } |
| 3284 | |
| 3285 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3286 | return &intrinsic_optimizations_; |
| 3287 | } |
| 3288 | |
| 3289 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3290 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3291 | DECLARE_INSTRUCTION(Invoke); |
| 3292 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3293 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3294 | HInvoke(ArenaAllocator* arena, |
| 3295 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3296 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3297 | Primitive::Type return_type, |
| 3298 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3299 | uint32_t dex_method_index, |
| 3300 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3301 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3302 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3303 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3304 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3305 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3306 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3307 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3308 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3309 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3310 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3311 | } |
| 3312 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3313 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3314 | return inputs_[index]; |
| 3315 | } |
| 3316 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3317 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3318 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3319 | } |
| 3320 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3321 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3322 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3323 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3324 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3325 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3326 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3327 | |
| 3328 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3329 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3330 | |
| 3331 | private: |
| 3332 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3333 | }; |
| 3334 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3335 | class HInvokeUnresolved : public HInvoke { |
| 3336 | public: |
| 3337 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3338 | uint32_t number_of_arguments, |
| 3339 | Primitive::Type return_type, |
| 3340 | uint32_t dex_pc, |
| 3341 | uint32_t dex_method_index, |
| 3342 | InvokeType invoke_type) |
| 3343 | : HInvoke(arena, |
| 3344 | number_of_arguments, |
| 3345 | 0u /* number_of_other_inputs */, |
| 3346 | return_type, |
| 3347 | dex_pc, |
| 3348 | dex_method_index, |
| 3349 | invoke_type) { |
| 3350 | } |
| 3351 | |
| 3352 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3353 | |
| 3354 | private: |
| 3355 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3356 | }; |
| 3357 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3358 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3359 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3360 | // Requirements of this method call regarding the class |
| 3361 | // initialization (clinit) check of its declaring class. |
| 3362 | enum class ClinitCheckRequirement { |
| 3363 | kNone, // Class already initialized. |
| 3364 | kExplicit, // Static call having explicit clinit check as last input. |
| 3365 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3366 | }; |
| 3367 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3368 | // Determines how to load the target ArtMethod*. |
| 3369 | enum class MethodLoadKind { |
| 3370 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3371 | kStringInit, |
| 3372 | |
| 3373 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3374 | kRecursive, |
| 3375 | |
| 3376 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3377 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3378 | kDirectAddress, |
| 3379 | |
| 3380 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3381 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3382 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3383 | // the image relocatable or not. |
| 3384 | kDirectAddressWithFixup, |
| 3385 | |
| 3386 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3387 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3388 | // may cause class initialization (the entry may point to a resolution method), |
| 3389 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3390 | kDexCachePcRelative, |
| 3391 | |
| 3392 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3393 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3394 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3395 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3396 | kDexCacheViaMethod, |
| 3397 | }; |
| 3398 | |
| 3399 | // Determines the location of the code pointer. |
| 3400 | enum class CodePtrLocation { |
| 3401 | // Recursive call, use local PC-relative call instruction. |
| 3402 | kCallSelf, |
| 3403 | |
| 3404 | // Use PC-relative call instruction patched at link time. |
| 3405 | // Used for calls within an oat file, boot->boot or app->app. |
| 3406 | kCallPCRelative, |
| 3407 | |
| 3408 | // Call to a known target address, embed the direct address in code. |
| 3409 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3410 | kCallDirect, |
| 3411 | |
| 3412 | // Call to a target address that will be known at link time, embed the direct |
| 3413 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3414 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3415 | // the image relocatable or not. |
| 3416 | kCallDirectWithFixup, |
| 3417 | |
| 3418 | // Use code pointer from the ArtMethod*. |
| 3419 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3420 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3421 | kCallArtMethod, |
| 3422 | }; |
| 3423 | |
| 3424 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3425 | MethodLoadKind method_load_kind; |
| 3426 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3427 | // The method load data holds |
| 3428 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3429 | // Note that there are multiple string init methods, each having its own offset. |
| 3430 | // - the method address for kDirectAddress |
| 3431 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3432 | uint64_t method_load_data; |
| 3433 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3434 | }; |
| 3435 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3436 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3437 | uint32_t number_of_arguments, |
| 3438 | Primitive::Type return_type, |
| 3439 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3440 | uint32_t method_index, |
| 3441 | MethodReference target_method, |
| 3442 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3443 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3444 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3445 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3446 | : HInvoke(arena, |
| 3447 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3448 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3449 | // potentially one other if the clinit check is explicit, and potentially |
| 3450 | // one other if the method is a string factory. |
| 3451 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3452 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3453 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3454 | return_type, |
| 3455 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3456 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3457 | original_invoke_type), |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3458 | optimized_invoke_type_(optimized_invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3459 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3460 | target_method_(target_method), |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3461 | dispatch_info_(dispatch_info) { } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3462 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3463 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3464 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3465 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3466 | |
| 3467 | // Using the current method is the default and once we find a better |
| 3468 | // method load kind, we should not go back to using the current method. |
| 3469 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3470 | |
| 3471 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3472 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3473 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3474 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3475 | dispatch_info_ = dispatch_info; |
| 3476 | } |
| 3477 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3478 | void AddSpecialInput(HInstruction* input) { |
| 3479 | // We allow only one special input. |
| 3480 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3481 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3482 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3483 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3484 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3485 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3486 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3487 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3488 | // TODO: for intrinsics we can generate implicit null checks. |
| 3489 | return false; |
| 3490 | } |
| 3491 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3492 | bool CanBeNull() const OVERRIDE { |
| 3493 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3494 | } |
| 3495 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3496 | // Get the index of the special input, if any. |
| 3497 | // |
| 3498 | // If the invoke IsStringInit(), it initially has a HFakeString special argument |
| 3499 | // which is removed by the instruction simplifier; if the invoke HasCurrentMethodInput(), |
| 3500 | // the "special input" is the current method pointer; otherwise there may be one |
| 3501 | // platform-specific special input, such as PC-relative addressing base. |
| 3502 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
| 3503 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3504 | InvokeType GetOptimizedInvokeType() const { return optimized_invoke_type_; } |
| 3505 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
| 3506 | optimized_invoke_type_ = invoke_type; |
| 3507 | } |
| 3508 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3509 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3510 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3511 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3512 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3513 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3514 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3515 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3516 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3517 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3518 | bool HasCurrentMethodInput() const { |
| 3519 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3520 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3521 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3522 | return true; |
| 3523 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3524 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3525 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3526 | return false; |
| 3527 | } |
| 3528 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3529 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3530 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3531 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3532 | |
| 3533 | int32_t GetStringInitOffset() const { |
| 3534 | DCHECK(IsStringInit()); |
| 3535 | return dispatch_info_.method_load_data; |
| 3536 | } |
| 3537 | |
| 3538 | uint64_t GetMethodAddress() const { |
| 3539 | DCHECK(HasMethodAddress()); |
| 3540 | return dispatch_info_.method_load_data; |
| 3541 | } |
| 3542 | |
| 3543 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3544 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3545 | return dispatch_info_.method_load_data; |
| 3546 | } |
| 3547 | |
| 3548 | uint64_t GetDirectCodePtr() const { |
| 3549 | DCHECK(HasDirectCodePtr()); |
| 3550 | return dispatch_info_.direct_code_ptr; |
| 3551 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3552 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3553 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3554 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3555 | // Is this instruction a call to a static method? |
| 3556 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3557 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3558 | } |
| 3559 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3560 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3561 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3562 | // instruction; only relevant for static calls with explicit clinit check. |
| 3563 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3564 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3565 | size_t last_input_index = InputCount() - 1; |
| 3566 | HInstruction* last_input = InputAt(last_input_index); |
| 3567 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3568 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3569 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3570 | inputs_.pop_back(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3571 | clinit_check_requirement_ = new_requirement; |
| 3572 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3573 | } |
| 3574 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3575 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3576 | if (!IsStringInit()) return false; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3577 | DCHECK(!HasCurrentMethodInput()); |
| 3578 | if (InputCount() == (number_of_arguments_)) return false; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3579 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3580 | } |
| 3581 | |
| 3582 | void RemoveFakeStringArgumentAsLastInput() { |
| 3583 | DCHECK(IsStringInit()); |
| 3584 | size_t last_input_index = InputCount() - 1; |
| 3585 | HInstruction* last_input = InputAt(last_input_index); |
| 3586 | DCHECK(last_input != nullptr); |
| 3587 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3588 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3589 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3590 | } |
| 3591 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3592 | // 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] | 3593 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3594 | bool IsStaticWithExplicitClinitCheck() const { |
| 3595 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3596 | } |
| 3597 | |
| 3598 | // Is this a call to a static method whose declaring class has an |
| 3599 | // implicit intialization check requirement? |
| 3600 | bool IsStaticWithImplicitClinitCheck() const { |
| 3601 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3602 | } |
| 3603 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3604 | // Does this method load kind need the current method as an input? |
| 3605 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 3606 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 3607 | } |
| 3608 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3609 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3610 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3611 | protected: |
| 3612 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3613 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3614 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3615 | HInstruction* input = input_record.GetInstruction(); |
| 3616 | // `input` is the last input of a static invoke marked as having |
| 3617 | // an explicit clinit check. It must either be: |
| 3618 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3619 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3620 | DCHECK(input != nullptr); |
| 3621 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3622 | } |
| 3623 | return input_record; |
| 3624 | } |
| 3625 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3626 | void InsertInputAt(size_t index, HInstruction* input); |
| 3627 | void RemoveInputAt(size_t index); |
| 3628 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3629 | private: |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3630 | InvokeType optimized_invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3631 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3632 | // The target method may refer to different dex file or method index than the original |
| 3633 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3634 | // in derived class to increase visibility. |
| 3635 | MethodReference target_method_; |
| 3636 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3637 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3638 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3639 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 3640 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3641 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3642 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3643 | class HInvokeVirtual : public HInvoke { |
| 3644 | public: |
| 3645 | HInvokeVirtual(ArenaAllocator* arena, |
| 3646 | uint32_t number_of_arguments, |
| 3647 | Primitive::Type return_type, |
| 3648 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3649 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3650 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3651 | : 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] | 3652 | vtable_index_(vtable_index) {} |
| 3653 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3654 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3655 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3656 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3657 | } |
| 3658 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3659 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3660 | |
| 3661 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3662 | |
| 3663 | private: |
| 3664 | const uint32_t vtable_index_; |
| 3665 | |
| 3666 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3667 | }; |
| 3668 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3669 | class HInvokeInterface : public HInvoke { |
| 3670 | public: |
| 3671 | HInvokeInterface(ArenaAllocator* arena, |
| 3672 | uint32_t number_of_arguments, |
| 3673 | Primitive::Type return_type, |
| 3674 | uint32_t dex_pc, |
| 3675 | uint32_t dex_method_index, |
| 3676 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3677 | : 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] | 3678 | imt_index_(imt_index) {} |
| 3679 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3680 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3681 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3682 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3683 | } |
| 3684 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3685 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3686 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3687 | |
| 3688 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3689 | |
| 3690 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3691 | const uint32_t imt_index_; |
| 3692 | |
| 3693 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3694 | }; |
| 3695 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3696 | class HNewInstance : public HExpression<2> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3697 | public: |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3698 | HNewInstance(HInstruction* cls, |
| 3699 | HCurrentMethod* current_method, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3700 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3701 | uint16_t type_index, |
| 3702 | const DexFile& dex_file, |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3703 | bool can_throw, |
| 3704 | bool finalizable, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3705 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3706 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3707 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3708 | dex_file_(dex_file), |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3709 | can_throw_(can_throw), |
| 3710 | finalizable_(finalizable), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3711 | entrypoint_(entrypoint) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3712 | SetRawInputAt(0, cls); |
| 3713 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3714 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3715 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3716 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3717 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3718 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3719 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3720 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3721 | |
| 3722 | // It may throw when called on type that's not instantiable/accessible. |
| 3723 | // It can throw OOME. |
| 3724 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
| 3725 | bool CanThrow() const OVERRIDE { return can_throw_ || true; } |
| 3726 | |
| 3727 | bool IsFinalizable() const { return finalizable_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3728 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3729 | bool CanBeNull() const OVERRIDE { return false; } |
| 3730 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3731 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3732 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3733 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3734 | entrypoint_ = entrypoint; |
| 3735 | } |
| 3736 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3737 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3738 | |
| 3739 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3740 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3741 | const DexFile& dex_file_; |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3742 | const bool can_throw_; |
| 3743 | const bool finalizable_; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3744 | QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3745 | |
| 3746 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3747 | }; |
| 3748 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3749 | class HNeg : public HUnaryOperation { |
| 3750 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3751 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3752 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3753 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3754 | template <typename T> T Compute(T x) const { return -x; } |
| 3755 | |
| 3756 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3757 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3758 | } |
| 3759 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3760 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3761 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3762 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3763 | DECLARE_INSTRUCTION(Neg); |
| 3764 | |
| 3765 | private: |
| 3766 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3767 | }; |
| 3768 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3769 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3770 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3771 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3772 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3773 | uint32_t dex_pc, |
| 3774 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3775 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3776 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3777 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3778 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3779 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3780 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3781 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3782 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3783 | } |
| 3784 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3785 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3786 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3787 | |
| 3788 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3789 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3790 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3791 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3792 | bool CanThrow() const OVERRIDE { return true; } |
| 3793 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3794 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3795 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3796 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3797 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3798 | DECLARE_INSTRUCTION(NewArray); |
| 3799 | |
| 3800 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3801 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3802 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3803 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3804 | |
| 3805 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3806 | }; |
| 3807 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3808 | class HAdd : public HBinaryOperation { |
| 3809 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3810 | HAdd(Primitive::Type result_type, |
| 3811 | HInstruction* left, |
| 3812 | HInstruction* right, |
| 3813 | uint32_t dex_pc = kNoDexPc) |
| 3814 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3815 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3816 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3817 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3818 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3819 | |
| 3820 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3821 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3822 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3823 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3824 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3825 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3826 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3827 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3828 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3829 | DECLARE_INSTRUCTION(Add); |
| 3830 | |
| 3831 | private: |
| 3832 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3833 | }; |
| 3834 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3835 | class HSub : public HBinaryOperation { |
| 3836 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3837 | HSub(Primitive::Type result_type, |
| 3838 | HInstruction* left, |
| 3839 | HInstruction* right, |
| 3840 | uint32_t dex_pc = kNoDexPc) |
| 3841 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3842 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3843 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3844 | |
| 3845 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3846 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3847 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3848 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3849 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3850 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3851 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3852 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3853 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3854 | DECLARE_INSTRUCTION(Sub); |
| 3855 | |
| 3856 | private: |
| 3857 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3858 | }; |
| 3859 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3860 | class HMul : public HBinaryOperation { |
| 3861 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3862 | HMul(Primitive::Type result_type, |
| 3863 | HInstruction* left, |
| 3864 | HInstruction* right, |
| 3865 | uint32_t dex_pc = kNoDexPc) |
| 3866 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3867 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3868 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3869 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3870 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3871 | |
| 3872 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3873 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3874 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3875 | } |
| 3876 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3877 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3878 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3879 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3880 | |
| 3881 | DECLARE_INSTRUCTION(Mul); |
| 3882 | |
| 3883 | private: |
| 3884 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3885 | }; |
| 3886 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3887 | class HDiv : public HBinaryOperation { |
| 3888 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3889 | HDiv(Primitive::Type result_type, |
| 3890 | HInstruction* left, |
| 3891 | HInstruction* right, |
| 3892 | uint32_t dex_pc) |
| 3893 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3894 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3895 | template <typename T> |
| 3896 | T Compute(T x, T y) const { |
| 3897 | // Our graph structure ensures we never have 0 for `y` during |
| 3898 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3899 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3900 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3901 | return (y == -1) ? -x : x / y; |
| 3902 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3903 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3904 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3905 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3906 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3907 | } |
| 3908 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3909 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3910 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3911 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3912 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3913 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3914 | // The generated code can use a runtime call. |
| 3915 | return SideEffects::CanTriggerGC(); |
| 3916 | } |
| 3917 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3918 | DECLARE_INSTRUCTION(Div); |
| 3919 | |
| 3920 | private: |
| 3921 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3922 | }; |
| 3923 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3924 | class HRem : public HBinaryOperation { |
| 3925 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3926 | HRem(Primitive::Type result_type, |
| 3927 | HInstruction* left, |
| 3928 | HInstruction* right, |
| 3929 | uint32_t dex_pc) |
| 3930 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3931 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3932 | template <typename T> |
| 3933 | T Compute(T x, T y) const { |
| 3934 | // Our graph structure ensures we never have 0 for `y` during |
| 3935 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3936 | DCHECK_NE(y, 0); |
| 3937 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3938 | return (y == -1) ? 0 : x % y; |
| 3939 | } |
| 3940 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3941 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3942 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3943 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3944 | } |
| 3945 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3946 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3947 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3948 | } |
| 3949 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3950 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3951 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3952 | return SideEffects::CanTriggerGC(); |
| 3953 | } |
| 3954 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3955 | DECLARE_INSTRUCTION(Rem); |
| 3956 | |
| 3957 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3958 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3959 | }; |
| 3960 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3961 | class HDivZeroCheck : public HExpression<1> { |
| 3962 | public: |
| 3963 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3964 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3965 | SetRawInputAt(0, value); |
| 3966 | } |
| 3967 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3968 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3969 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3970 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3971 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3972 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3973 | return true; |
| 3974 | } |
| 3975 | |
| 3976 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3977 | bool CanThrow() const OVERRIDE { return true; } |
| 3978 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3979 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3980 | |
| 3981 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3982 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3983 | }; |
| 3984 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3985 | class HShl : public HBinaryOperation { |
| 3986 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3987 | HShl(Primitive::Type result_type, |
| 3988 | HInstruction* left, |
| 3989 | HInstruction* right, |
| 3990 | uint32_t dex_pc = kNoDexPc) |
| 3991 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3992 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3993 | template <typename T, typename U, typename V> |
| 3994 | T Compute(T x, U y, V max_shift_value) const { |
| 3995 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3996 | "V is not the unsigned integer type corresponding to T"); |
| 3997 | return x << (y & max_shift_value); |
| 3998 | } |
| 3999 | |
| 4000 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4001 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4002 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4003 | } |
| 4004 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4005 | // case is handled as `x << static_cast<int>(y)`. |
| 4006 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4007 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4008 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4009 | } |
| 4010 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4011 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4012 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4013 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4014 | |
| 4015 | DECLARE_INSTRUCTION(Shl); |
| 4016 | |
| 4017 | private: |
| 4018 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4019 | }; |
| 4020 | |
| 4021 | class HShr : public HBinaryOperation { |
| 4022 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4023 | HShr(Primitive::Type result_type, |
| 4024 | HInstruction* left, |
| 4025 | HInstruction* right, |
| 4026 | uint32_t dex_pc = kNoDexPc) |
| 4027 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4028 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4029 | template <typename T, typename U, typename V> |
| 4030 | T Compute(T x, U y, V max_shift_value) const { |
| 4031 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4032 | "V is not the unsigned integer type corresponding to T"); |
| 4033 | return x >> (y & max_shift_value); |
| 4034 | } |
| 4035 | |
| 4036 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4037 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4038 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4039 | } |
| 4040 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4041 | // case is handled as `x >> static_cast<int>(y)`. |
| 4042 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4043 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4044 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4045 | } |
| 4046 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4047 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4048 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4049 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4050 | |
| 4051 | DECLARE_INSTRUCTION(Shr); |
| 4052 | |
| 4053 | private: |
| 4054 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4055 | }; |
| 4056 | |
| 4057 | class HUShr : public HBinaryOperation { |
| 4058 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4059 | HUShr(Primitive::Type result_type, |
| 4060 | HInstruction* left, |
| 4061 | HInstruction* right, |
| 4062 | uint32_t dex_pc = kNoDexPc) |
| 4063 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4064 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4065 | template <typename T, typename U, typename V> |
| 4066 | T Compute(T x, U y, V max_shift_value) const { |
| 4067 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4068 | "V is not the unsigned integer type corresponding to T"); |
| 4069 | V ux = static_cast<V>(x); |
| 4070 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4071 | } |
| 4072 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4073 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4074 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4075 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4076 | } |
| 4077 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4078 | // case is handled as `x >>> static_cast<int>(y)`. |
| 4079 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4080 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4081 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4082 | } |
| 4083 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4084 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4085 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | DECLARE_INSTRUCTION(UShr); |
| 4089 | |
| 4090 | private: |
| 4091 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4092 | }; |
| 4093 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4094 | class HAnd : public HBinaryOperation { |
| 4095 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4096 | HAnd(Primitive::Type result_type, |
| 4097 | HInstruction* left, |
| 4098 | HInstruction* right, |
| 4099 | uint32_t dex_pc = kNoDexPc) |
| 4100 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4101 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4102 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4103 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4104 | template <typename T, typename U> |
| 4105 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 4106 | |
| 4107 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4108 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4109 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4110 | } |
| 4111 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4112 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4113 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4114 | } |
| 4115 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4116 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4117 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4118 | } |
| 4119 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4120 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4121 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4122 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4123 | |
| 4124 | DECLARE_INSTRUCTION(And); |
| 4125 | |
| 4126 | private: |
| 4127 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4128 | }; |
| 4129 | |
| 4130 | class HOr : public HBinaryOperation { |
| 4131 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4132 | HOr(Primitive::Type result_type, |
| 4133 | HInstruction* left, |
| 4134 | HInstruction* right, |
| 4135 | uint32_t dex_pc = kNoDexPc) |
| 4136 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4137 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4138 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4139 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4140 | template <typename T, typename U> |
| 4141 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4142 | |
| 4143 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4144 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4145 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4146 | } |
| 4147 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4148 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4149 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4150 | } |
| 4151 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4152 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4153 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4154 | } |
| 4155 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4156 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4157 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4158 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4159 | |
| 4160 | DECLARE_INSTRUCTION(Or); |
| 4161 | |
| 4162 | private: |
| 4163 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4164 | }; |
| 4165 | |
| 4166 | class HXor : public HBinaryOperation { |
| 4167 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4168 | HXor(Primitive::Type result_type, |
| 4169 | HInstruction* left, |
| 4170 | HInstruction* right, |
| 4171 | uint32_t dex_pc = kNoDexPc) |
| 4172 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4173 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4174 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4175 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4176 | template <typename T, typename U> |
| 4177 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4178 | |
| 4179 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4180 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4181 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4182 | } |
| 4183 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4184 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4185 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4186 | } |
| 4187 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4188 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4189 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4190 | } |
| 4191 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4192 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4193 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4194 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4195 | |
| 4196 | DECLARE_INSTRUCTION(Xor); |
| 4197 | |
| 4198 | private: |
| 4199 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4200 | }; |
| 4201 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4202 | class HRor : public HBinaryOperation { |
| 4203 | public: |
| 4204 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
| 4205 | : HBinaryOperation(result_type, value, distance) {} |
| 4206 | |
| 4207 | template <typename T, typename U, typename V> |
| 4208 | T Compute(T x, U y, V max_shift_value) const { |
| 4209 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4210 | "V is not the unsigned integer type corresponding to T"); |
| 4211 | V ux = static_cast<V>(x); |
| 4212 | if ((y & max_shift_value) == 0) { |
| 4213 | return static_cast<T>(ux); |
| 4214 | } else { |
| 4215 | const V reg_bits = sizeof(T) * 8; |
| 4216 | return static_cast<T>(ux >> (y & max_shift_value)) | |
| 4217 | (x << (reg_bits - (y & max_shift_value))); |
| 4218 | } |
| 4219 | } |
| 4220 | |
| 4221 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4222 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4223 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
| 4224 | } |
| 4225 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4226 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4227 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4228 | } |
| 4229 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4230 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4231 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4232 | } |
| 4233 | |
| 4234 | DECLARE_INSTRUCTION(Ror); |
| 4235 | |
| 4236 | private: |
| 4237 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4238 | }; |
| 4239 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4240 | // The value of a parameter in this method. Its location depends on |
| 4241 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4242 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4243 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4244 | HParameterValue(const DexFile& dex_file, |
| 4245 | uint16_t type_index, |
| 4246 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4247 | Primitive::Type parameter_type, |
| 4248 | bool is_this = false) |
| 4249 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4250 | dex_file_(dex_file), |
| 4251 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4252 | index_(index), |
| 4253 | is_this_(is_this), |
| 4254 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4255 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4256 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4257 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4258 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4259 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4260 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4261 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4262 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4263 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4264 | DECLARE_INSTRUCTION(ParameterValue); |
| 4265 | |
| 4266 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4267 | const DexFile& dex_file_; |
| 4268 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4269 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4270 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4271 | const uint8_t index_; |
| 4272 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4273 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4274 | const bool is_this_; |
| 4275 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4276 | bool can_be_null_; |
| 4277 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4278 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4279 | }; |
| 4280 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4281 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4282 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4283 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4284 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4285 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4286 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4287 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4288 | return true; |
| 4289 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4290 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4291 | template <typename T> T Compute(T x) const { return ~x; } |
| 4292 | |
| 4293 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4294 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4295 | } |
| 4296 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4297 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4298 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4299 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4300 | DECLARE_INSTRUCTION(Not); |
| 4301 | |
| 4302 | private: |
| 4303 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4304 | }; |
| 4305 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4306 | class HBooleanNot : public HUnaryOperation { |
| 4307 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4308 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4309 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4310 | |
| 4311 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4312 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4313 | return true; |
| 4314 | } |
| 4315 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4316 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4317 | DCHECK(IsUint<1>(x)); |
| 4318 | return !x; |
| 4319 | } |
| 4320 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4321 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4322 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4323 | } |
| 4324 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4325 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4326 | UNREACHABLE(); |
| 4327 | } |
| 4328 | |
| 4329 | DECLARE_INSTRUCTION(BooleanNot); |
| 4330 | |
| 4331 | private: |
| 4332 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4333 | }; |
| 4334 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4335 | class HTypeConversion : public HExpression<1> { |
| 4336 | public: |
| 4337 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4338 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4339 | : HExpression(result_type, |
| 4340 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4341 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4342 | SetRawInputAt(0, input); |
| 4343 | DCHECK_NE(input->GetType(), result_type); |
| 4344 | } |
| 4345 | |
| 4346 | HInstruction* GetInput() const { return InputAt(0); } |
| 4347 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4348 | Primitive::Type GetResultType() const { return GetType(); } |
| 4349 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4350 | // 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] | 4351 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4352 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4353 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4354 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4355 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4356 | // Try to statically evaluate the conversion and return a HConstant |
| 4357 | // containing the result. If the input cannot be converted, return nullptr. |
| 4358 | HConstant* TryStaticEvaluation() const; |
| 4359 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4360 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4361 | Primitive::Type result_type) { |
| 4362 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4363 | // in the compilation process we do not know what architecture we will |
| 4364 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4365 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4366 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4367 | return SideEffects::CanTriggerGC(); |
| 4368 | } |
| 4369 | return SideEffects::None(); |
| 4370 | } |
| 4371 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4372 | DECLARE_INSTRUCTION(TypeConversion); |
| 4373 | |
| 4374 | private: |
| 4375 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4376 | }; |
| 4377 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4378 | static constexpr uint32_t kNoRegNumber = -1; |
| 4379 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4380 | class HPhi : public HInstruction { |
| 4381 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4382 | HPhi(ArenaAllocator* arena, |
| 4383 | uint32_t reg_number, |
| 4384 | size_t number_of_inputs, |
| 4385 | Primitive::Type type, |
| 4386 | uint32_t dex_pc = kNoDexPc) |
| 4387 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4388 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4389 | reg_number_(reg_number), |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4390 | type_(ToPhiType(type)), |
| 4391 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4392 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4393 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4394 | is_live_(true), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4395 | can_be_null_(true) { |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4396 | DCHECK_NE(type_, Primitive::kPrimVoid); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4397 | } |
| 4398 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4399 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4400 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4401 | switch (type) { |
| 4402 | case Primitive::kPrimBoolean: |
| 4403 | case Primitive::kPrimByte: |
| 4404 | case Primitive::kPrimShort: |
| 4405 | case Primitive::kPrimChar: |
| 4406 | return Primitive::kPrimInt; |
| 4407 | default: |
| 4408 | return type; |
| 4409 | } |
| 4410 | } |
| 4411 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4412 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4413 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4414 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4415 | |
| 4416 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4417 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4418 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4419 | Primitive::Type GetType() const OVERRIDE { return type_; } |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4420 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4421 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4422 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4423 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4424 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4425 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4426 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4427 | void SetDead() { is_live_ = false; } |
| 4428 | void SetLive() { is_live_ = true; } |
| 4429 | bool IsDead() const { return !is_live_; } |
| 4430 | bool IsLive() const { return is_live_; } |
| 4431 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4432 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4433 | return other != nullptr |
| 4434 | && other->IsPhi() |
| 4435 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4436 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4437 | } |
| 4438 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4439 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4440 | // An equivalent phi is a phi having the same dex register and type. |
| 4441 | // It assumes that phis with the same dex register are adjacent. |
| 4442 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4443 | HInstruction* next = GetNext(); |
| 4444 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4445 | if (next->GetType() == GetType()) { |
| 4446 | return next->AsPhi(); |
| 4447 | } |
| 4448 | next = next->GetNext(); |
| 4449 | } |
| 4450 | return nullptr; |
| 4451 | } |
| 4452 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4453 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4454 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4455 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4456 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4457 | return inputs_[index]; |
| 4458 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4459 | |
| 4460 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4461 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4464 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4465 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4466 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4467 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4468 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4469 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4470 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4471 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4472 | }; |
| 4473 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4474 | class HNullCheck : public HExpression<1> { |
| 4475 | public: |
| 4476 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4477 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4478 | SetRawInputAt(0, value); |
| 4479 | } |
| 4480 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4481 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4482 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4483 | return true; |
| 4484 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4485 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4486 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4487 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4488 | bool CanThrow() const OVERRIDE { return true; } |
| 4489 | |
| 4490 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4491 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4492 | |
| 4493 | DECLARE_INSTRUCTION(NullCheck); |
| 4494 | |
| 4495 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4496 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4497 | }; |
| 4498 | |
| 4499 | class FieldInfo : public ValueObject { |
| 4500 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4501 | FieldInfo(MemberOffset field_offset, |
| 4502 | Primitive::Type field_type, |
| 4503 | bool is_volatile, |
| 4504 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4505 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4506 | const DexFile& dex_file, |
| 4507 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4508 | : field_offset_(field_offset), |
| 4509 | field_type_(field_type), |
| 4510 | is_volatile_(is_volatile), |
| 4511 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4512 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4513 | dex_file_(dex_file), |
| 4514 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4515 | |
| 4516 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4517 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4518 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4519 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4520 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4521 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4522 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4523 | |
| 4524 | private: |
| 4525 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4526 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4527 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4528 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4529 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4530 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4531 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4532 | }; |
| 4533 | |
| 4534 | class HInstanceFieldGet : public HExpression<1> { |
| 4535 | public: |
| 4536 | HInstanceFieldGet(HInstruction* value, |
| 4537 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4538 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4539 | bool is_volatile, |
| 4540 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4541 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4542 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4543 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4544 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4545 | : HExpression(field_type, |
| 4546 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4547 | dex_pc), |
| 4548 | field_info_(field_offset, |
| 4549 | field_type, |
| 4550 | is_volatile, |
| 4551 | field_idx, |
| 4552 | declaring_class_def_index, |
| 4553 | dex_file, |
| 4554 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4555 | SetRawInputAt(0, value); |
| 4556 | } |
| 4557 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4558 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4559 | |
| 4560 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4561 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4562 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4563 | } |
| 4564 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4565 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4566 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4567 | } |
| 4568 | |
| 4569 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4570 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4571 | } |
| 4572 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4573 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4574 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4575 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4576 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4577 | |
| 4578 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4579 | |
| 4580 | private: |
| 4581 | const FieldInfo field_info_; |
| 4582 | |
| 4583 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4584 | }; |
| 4585 | |
| 4586 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4587 | public: |
| 4588 | HInstanceFieldSet(HInstruction* object, |
| 4589 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4590 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4591 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4592 | bool is_volatile, |
| 4593 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4594 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4595 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4596 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4597 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4598 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4599 | dex_pc), |
| 4600 | field_info_(field_offset, |
| 4601 | field_type, |
| 4602 | is_volatile, |
| 4603 | field_idx, |
| 4604 | declaring_class_def_index, |
| 4605 | dex_file, |
| 4606 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4607 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4608 | SetRawInputAt(0, object); |
| 4609 | SetRawInputAt(1, value); |
| 4610 | } |
| 4611 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4612 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4613 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4614 | } |
| 4615 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4616 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4617 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4618 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4619 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4620 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4621 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4622 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4623 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4624 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4625 | |
| 4626 | private: |
| 4627 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4628 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4629 | |
| 4630 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4631 | }; |
| 4632 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4633 | class HArrayGet : public HExpression<2> { |
| 4634 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4635 | HArrayGet(HInstruction* array, |
| 4636 | HInstruction* index, |
| 4637 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4638 | uint32_t dex_pc, |
| 4639 | SideEffects additional_side_effects = SideEffects::None()) |
| 4640 | : HExpression(type, |
| 4641 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4642 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4643 | SetRawInputAt(0, array); |
| 4644 | SetRawInputAt(1, index); |
| 4645 | } |
| 4646 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4647 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4648 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4649 | return true; |
| 4650 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4651 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4652 | // TODO: We can be smarter here. |
| 4653 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4654 | // which generates the implicit null check. There are cases when these can be removed |
| 4655 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4656 | // implicit check here (as long as the address falls in the first page). |
| 4657 | return false; |
| 4658 | } |
| 4659 | |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4660 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4661 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4662 | HInstruction* GetArray() const { return InputAt(0); } |
| 4663 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4664 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4665 | DECLARE_INSTRUCTION(ArrayGet); |
| 4666 | |
| 4667 | private: |
| 4668 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4669 | }; |
| 4670 | |
| 4671 | class HArraySet : public HTemplateInstruction<3> { |
| 4672 | public: |
| 4673 | HArraySet(HInstruction* array, |
| 4674 | HInstruction* index, |
| 4675 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4676 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4677 | uint32_t dex_pc, |
| 4678 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4679 | : HTemplateInstruction( |
| 4680 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4681 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4682 | additional_side_effects), |
| 4683 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4684 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4685 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4686 | value_can_be_null_(true), |
| 4687 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4688 | SetRawInputAt(0, array); |
| 4689 | SetRawInputAt(1, index); |
| 4690 | SetRawInputAt(2, value); |
| 4691 | } |
| 4692 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4693 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4694 | // We currently always call a runtime method to catch array store |
| 4695 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4696 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4697 | } |
| 4698 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4699 | // Can throw ArrayStoreException. |
| 4700 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4701 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4702 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4703 | // TODO: Same as for ArrayGet. |
| 4704 | return false; |
| 4705 | } |
| 4706 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4707 | void ClearNeedsTypeCheck() { |
| 4708 | needs_type_check_ = false; |
| 4709 | } |
| 4710 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4711 | void ClearValueCanBeNull() { |
| 4712 | value_can_be_null_ = false; |
| 4713 | } |
| 4714 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4715 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4716 | static_type_of_array_is_object_array_ = true; |
| 4717 | } |
| 4718 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4719 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4720 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4721 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4722 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4723 | HInstruction* GetArray() const { return InputAt(0); } |
| 4724 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4725 | HInstruction* GetValue() const { return InputAt(2); } |
| 4726 | |
| 4727 | Primitive::Type GetComponentType() const { |
| 4728 | // The Dex format does not type floating point index operations. Since the |
| 4729 | // `expected_component_type_` is set during building and can therefore not |
| 4730 | // be correct, we also check what is the value type. If it is a floating |
| 4731 | // point type, we must use that type. |
| 4732 | Primitive::Type value_type = GetValue()->GetType(); |
| 4733 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4734 | ? value_type |
| 4735 | : expected_component_type_; |
| 4736 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4737 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4738 | Primitive::Type GetRawExpectedComponentType() const { |
| 4739 | return expected_component_type_; |
| 4740 | } |
| 4741 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4742 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4743 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4744 | } |
| 4745 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4746 | DECLARE_INSTRUCTION(ArraySet); |
| 4747 | |
| 4748 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4749 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4750 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4751 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4752 | // Cached information for the reference_type_info_ so that codegen |
| 4753 | // does not need to inspect the static type. |
| 4754 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4755 | |
| 4756 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4757 | }; |
| 4758 | |
| 4759 | class HArrayLength : public HExpression<1> { |
| 4760 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4761 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4762 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4763 | // Note that arrays do not change length, so the instruction does not |
| 4764 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4765 | SetRawInputAt(0, array); |
| 4766 | } |
| 4767 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4768 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4769 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4770 | return true; |
| 4771 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4772 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4773 | return obj == InputAt(0); |
| 4774 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4775 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4776 | DECLARE_INSTRUCTION(ArrayLength); |
| 4777 | |
| 4778 | private: |
| 4779 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4780 | }; |
| 4781 | |
| 4782 | class HBoundsCheck : public HExpression<2> { |
| 4783 | public: |
| 4784 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4785 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4786 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4787 | SetRawInputAt(0, index); |
| 4788 | SetRawInputAt(1, length); |
| 4789 | } |
| 4790 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4791 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4792 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4793 | return true; |
| 4794 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4795 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4796 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4797 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4798 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4799 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4800 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4801 | |
| 4802 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4803 | |
| 4804 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4805 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4806 | }; |
| 4807 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4808 | /** |
| 4809 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4810 | * to stay live until the last HInstruction. This class |
| 4811 | * 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] | 4812 | * HInstruction stays live. `index` represents the stack location index of the |
| 4813 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4814 | */ |
| 4815 | class HTemporary : public HTemplateInstruction<0> { |
| 4816 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4817 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4818 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4819 | |
| 4820 | size_t GetIndex() const { return index_; } |
| 4821 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4822 | Primitive::Type GetType() const OVERRIDE { |
| 4823 | // The previous instruction is the one that will be stored in the temporary location. |
| 4824 | DCHECK(GetPrevious() != nullptr); |
| 4825 | return GetPrevious()->GetType(); |
| 4826 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4827 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4828 | DECLARE_INSTRUCTION(Temporary); |
| 4829 | |
| 4830 | private: |
| 4831 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4832 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4833 | }; |
| 4834 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4835 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4836 | public: |
| 4837 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4838 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4839 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4840 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4841 | return true; |
| 4842 | } |
| 4843 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4844 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4845 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4846 | |
| 4847 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4848 | |
| 4849 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4850 | // Only used for code generation, in order to share the same slow path between back edges |
| 4851 | // of a same loop. |
| 4852 | SlowPathCode* slow_path_; |
| 4853 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4854 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4855 | }; |
| 4856 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4857 | /** |
| 4858 | * Instruction to load a Class object. |
| 4859 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4860 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4861 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4862 | HLoadClass(HCurrentMethod* current_method, |
| 4863 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4864 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4865 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4866 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4867 | bool needs_access_check, |
| 4868 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4869 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4870 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4871 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4872 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4873 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4874 | needs_access_check_(needs_access_check), |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4875 | is_in_dex_cache_(is_in_dex_cache), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4876 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4877 | // Referrers class should not need access check. We never inline unverified |
| 4878 | // methods so we can't possibly end up in this situation. |
| 4879 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4880 | SetRawInputAt(0, current_method); |
| 4881 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4882 | |
| 4883 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4884 | |
| 4885 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 4886 | // Note that we don't need to test for generate_clinit_check_. |
| 4887 | // Whether or not we need to generate the clinit check is processed in |
| 4888 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4889 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 4890 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4891 | } |
| 4892 | |
| 4893 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4894 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4895 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4896 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4897 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4898 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4899 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4900 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4901 | } |
| 4902 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4903 | bool MustGenerateClinitCheck() const { |
| 4904 | return generate_clinit_check_; |
| 4905 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4906 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4907 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 4908 | // The entrypoint the code generator is going to call does not do |
| 4909 | // clinit of the class. |
| 4910 | DCHECK(!NeedsAccessCheck()); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4911 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4915 | return MustGenerateClinitCheck() || |
| 4916 | (!is_referrers_class_ && !is_in_dex_cache_) || |
| 4917 | needs_access_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | bool NeedsAccessCheck() const { |
| 4921 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4922 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4923 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4924 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4925 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4926 | } |
| 4927 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4928 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4929 | return loaded_class_rti_; |
| 4930 | } |
| 4931 | |
| 4932 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4933 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4934 | DCHECK(rti.IsExact()); |
| 4935 | loaded_class_rti_ = rti; |
| 4936 | } |
| 4937 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4938 | const DexFile& GetDexFile() { return dex_file_; } |
| 4939 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4940 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4941 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4942 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4943 | return SideEffects::CanTriggerGC(); |
| 4944 | } |
| 4945 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4946 | bool IsInDexCache() const { return is_in_dex_cache_; } |
| 4947 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4948 | DECLARE_INSTRUCTION(LoadClass); |
| 4949 | |
| 4950 | private: |
| 4951 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4952 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4953 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4954 | // Whether this instruction must generate the initialization check. |
| 4955 | // Used for code generation. |
| 4956 | bool generate_clinit_check_; |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4957 | const bool needs_access_check_; |
| 4958 | const bool is_in_dex_cache_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4959 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4960 | ReferenceTypeInfo loaded_class_rti_; |
| 4961 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4962 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4963 | }; |
| 4964 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4965 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4966 | public: |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4967 | HLoadString(HCurrentMethod* current_method, |
| 4968 | uint32_t string_index, |
| 4969 | uint32_t dex_pc, |
| 4970 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4971 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4972 | string_index_(string_index), |
| 4973 | is_in_dex_cache_(is_in_dex_cache) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4974 | SetRawInputAt(0, current_method); |
| 4975 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4976 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4977 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4978 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4979 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4980 | return other->AsLoadString()->string_index_ == string_index_; |
| 4981 | } |
| 4982 | |
| 4983 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4984 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4985 | uint32_t GetStringIndex() const { return string_index_; } |
| 4986 | |
| 4987 | // TODO: Can we deopt or debug when we resolve a string? |
| 4988 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4989 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4990 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 4991 | bool IsInDexCache() const { return is_in_dex_cache_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4992 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4993 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4994 | return SideEffects::CanTriggerGC(); |
| 4995 | } |
| 4996 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4997 | DECLARE_INSTRUCTION(LoadString); |
| 4998 | |
| 4999 | private: |
| 5000 | const uint32_t string_index_; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5001 | const bool is_in_dex_cache_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5002 | |
| 5003 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5004 | }; |
| 5005 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5006 | /** |
| 5007 | * Performs an initialization check on its Class object input. |
| 5008 | */ |
| 5009 | class HClinitCheck : public HExpression<1> { |
| 5010 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5011 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5012 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5013 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5014 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5015 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5016 | SetRawInputAt(0, constant); |
| 5017 | } |
| 5018 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5019 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5020 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5021 | return true; |
| 5022 | } |
| 5023 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5024 | bool NeedsEnvironment() const OVERRIDE { |
| 5025 | // May call runtime to initialize the class. |
| 5026 | return true; |
| 5027 | } |
| 5028 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5029 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5030 | |
| 5031 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5032 | |
| 5033 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5034 | |
| 5035 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5036 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5037 | }; |
| 5038 | |
| 5039 | class HStaticFieldGet : public HExpression<1> { |
| 5040 | public: |
| 5041 | HStaticFieldGet(HInstruction* cls, |
| 5042 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5043 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5044 | bool is_volatile, |
| 5045 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5046 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5047 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5048 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5049 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5050 | : HExpression(field_type, |
| 5051 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5052 | dex_pc), |
| 5053 | field_info_(field_offset, |
| 5054 | field_type, |
| 5055 | is_volatile, |
| 5056 | field_idx, |
| 5057 | declaring_class_def_index, |
| 5058 | dex_file, |
| 5059 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5060 | SetRawInputAt(0, cls); |
| 5061 | } |
| 5062 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5063 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5064 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5065 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5066 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5067 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5068 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | size_t ComputeHashCode() const OVERRIDE { |
| 5072 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5073 | } |
| 5074 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5075 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5076 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5077 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5078 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5079 | |
| 5080 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5081 | |
| 5082 | private: |
| 5083 | const FieldInfo field_info_; |
| 5084 | |
| 5085 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5086 | }; |
| 5087 | |
| 5088 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5089 | public: |
| 5090 | HStaticFieldSet(HInstruction* cls, |
| 5091 | HInstruction* value, |
| 5092 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5093 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5094 | bool is_volatile, |
| 5095 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5096 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5097 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5098 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5099 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5100 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5101 | dex_pc), |
| 5102 | field_info_(field_offset, |
| 5103 | field_type, |
| 5104 | is_volatile, |
| 5105 | field_idx, |
| 5106 | declaring_class_def_index, |
| 5107 | dex_file, |
| 5108 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5109 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5110 | SetRawInputAt(0, cls); |
| 5111 | SetRawInputAt(1, value); |
| 5112 | } |
| 5113 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5114 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5115 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5116 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5117 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5118 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5119 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5120 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 5121 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5122 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5123 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5124 | |
| 5125 | private: |
| 5126 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5127 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5128 | |
| 5129 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5130 | }; |
| 5131 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5132 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5133 | public: |
| 5134 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5135 | 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 | SetRawInputAt(0, obj); |
| 5141 | } |
| 5142 | |
| 5143 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5144 | bool CanThrow() const OVERRIDE { return true; } |
| 5145 | |
| 5146 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5147 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5148 | |
| 5149 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5150 | |
| 5151 | private: |
| 5152 | const uint32_t field_index_; |
| 5153 | |
| 5154 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5155 | }; |
| 5156 | |
| 5157 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5158 | public: |
| 5159 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5160 | HInstruction* value, |
| 5161 | Primitive::Type field_type, |
| 5162 | uint32_t field_index, |
| 5163 | uint32_t dex_pc) |
| 5164 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5165 | field_type_(field_type), |
| 5166 | field_index_(field_index) { |
| 5167 | DCHECK_EQ(field_type, value->GetType()); |
| 5168 | SetRawInputAt(0, obj); |
| 5169 | SetRawInputAt(1, value); |
| 5170 | } |
| 5171 | |
| 5172 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5173 | bool CanThrow() const OVERRIDE { return true; } |
| 5174 | |
| 5175 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5176 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5177 | |
| 5178 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5179 | |
| 5180 | private: |
| 5181 | const Primitive::Type field_type_; |
| 5182 | const uint32_t field_index_; |
| 5183 | |
| 5184 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5185 | }; |
| 5186 | |
| 5187 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5188 | public: |
| 5189 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5190 | uint32_t field_index, |
| 5191 | uint32_t dex_pc) |
| 5192 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5193 | field_index_(field_index) { |
| 5194 | } |
| 5195 | |
| 5196 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5197 | bool CanThrow() const OVERRIDE { return true; } |
| 5198 | |
| 5199 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5200 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5201 | |
| 5202 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5203 | |
| 5204 | private: |
| 5205 | const uint32_t field_index_; |
| 5206 | |
| 5207 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5208 | }; |
| 5209 | |
| 5210 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5211 | public: |
| 5212 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5213 | Primitive::Type field_type, |
| 5214 | uint32_t field_index, |
| 5215 | uint32_t dex_pc) |
| 5216 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5217 | field_type_(field_type), |
| 5218 | field_index_(field_index) { |
| 5219 | DCHECK_EQ(field_type, value->GetType()); |
| 5220 | SetRawInputAt(0, value); |
| 5221 | } |
| 5222 | |
| 5223 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5224 | bool CanThrow() const OVERRIDE { return true; } |
| 5225 | |
| 5226 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5227 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5228 | |
| 5229 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5230 | |
| 5231 | private: |
| 5232 | const Primitive::Type field_type_; |
| 5233 | const uint32_t field_index_; |
| 5234 | |
| 5235 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5236 | }; |
| 5237 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5238 | // Implement the move-exception DEX instruction. |
| 5239 | class HLoadException : public HExpression<0> { |
| 5240 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5241 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5242 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5243 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5244 | bool CanBeNull() const OVERRIDE { return false; } |
| 5245 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5246 | DECLARE_INSTRUCTION(LoadException); |
| 5247 | |
| 5248 | private: |
| 5249 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5250 | }; |
| 5251 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5252 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5253 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5254 | class HClearException : public HTemplateInstruction<0> { |
| 5255 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5256 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5257 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5258 | |
| 5259 | DECLARE_INSTRUCTION(ClearException); |
| 5260 | |
| 5261 | private: |
| 5262 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5263 | }; |
| 5264 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5265 | class HThrow : public HTemplateInstruction<1> { |
| 5266 | public: |
| 5267 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5268 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5269 | SetRawInputAt(0, exception); |
| 5270 | } |
| 5271 | |
| 5272 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5273 | |
| 5274 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5275 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5276 | bool CanThrow() const OVERRIDE { return true; } |
| 5277 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5278 | |
| 5279 | DECLARE_INSTRUCTION(Throw); |
| 5280 | |
| 5281 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5282 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5283 | }; |
| 5284 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5285 | /** |
| 5286 | * Implementation strategies for the code generator of a HInstanceOf |
| 5287 | * or `HCheckCast`. |
| 5288 | */ |
| 5289 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5290 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5291 | kExactCheck, // Can do a single class compare. |
| 5292 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5293 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5294 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5295 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5296 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5297 | }; |
| 5298 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5299 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5300 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5301 | HInstanceOf(HInstruction* object, |
| 5302 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5303 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5304 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5305 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5306 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5307 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5308 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5309 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5310 | SetRawInputAt(0, object); |
| 5311 | SetRawInputAt(1, constant); |
| 5312 | } |
| 5313 | |
| 5314 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5315 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5316 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5317 | return true; |
| 5318 | } |
| 5319 | |
| 5320 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5321 | return false; |
| 5322 | } |
| 5323 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5324 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5325 | |
| 5326 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5327 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5328 | // Used only in code generation. |
| 5329 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5330 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5331 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5332 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 5333 | return (check_kind == TypeCheckKind::kExactCheck) |
| 5334 | ? SideEffects::None() |
| 5335 | // Mips currently does runtime calls for any other checks. |
| 5336 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5337 | } |
| 5338 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5339 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5340 | |
| 5341 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5342 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5343 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5344 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5345 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5346 | }; |
| 5347 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5348 | class HBoundType : public HExpression<1> { |
| 5349 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5350 | // Constructs an HBoundType with the given upper_bound. |
| 5351 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5352 | HBoundType(HInstruction* input, |
| 5353 | ReferenceTypeInfo upper_bound, |
| 5354 | bool upper_can_be_null, |
| 5355 | uint32_t dex_pc = kNoDexPc) |
| 5356 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5357 | upper_bound_(upper_bound), |
| 5358 | upper_can_be_null_(upper_can_be_null), |
| 5359 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5360 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5361 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5362 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5363 | } |
| 5364 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5365 | // GetUpper* should only be used in reference type propagation. |
| 5366 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5367 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5368 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5369 | void SetCanBeNull(bool can_be_null) { |
| 5370 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5371 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5372 | } |
| 5373 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5374 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5375 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5376 | DECLARE_INSTRUCTION(BoundType); |
| 5377 | |
| 5378 | private: |
| 5379 | // 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] | 5380 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5381 | // It is used to bound the type in cases like: |
| 5382 | // if (x instanceof ClassX) { |
| 5383 | // // uper_bound_ will be ClassX |
| 5384 | // } |
| 5385 | const ReferenceTypeInfo upper_bound_; |
| 5386 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5387 | // is false then can_be_null_ cannot be true). |
| 5388 | const bool upper_can_be_null_; |
| 5389 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5390 | |
| 5391 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5392 | }; |
| 5393 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5394 | class HCheckCast : public HTemplateInstruction<2> { |
| 5395 | public: |
| 5396 | HCheckCast(HInstruction* object, |
| 5397 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5398 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5399 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5400 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5401 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5402 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5403 | SetRawInputAt(0, object); |
| 5404 | SetRawInputAt(1, constant); |
| 5405 | } |
| 5406 | |
| 5407 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5408 | |
| 5409 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5410 | return true; |
| 5411 | } |
| 5412 | |
| 5413 | bool NeedsEnvironment() const OVERRIDE { |
| 5414 | // Instruction may throw a CheckCastError. |
| 5415 | return true; |
| 5416 | } |
| 5417 | |
| 5418 | bool CanThrow() const OVERRIDE { return true; } |
| 5419 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5420 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5421 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5422 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5423 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5424 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5425 | |
| 5426 | DECLARE_INSTRUCTION(CheckCast); |
| 5427 | |
| 5428 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5429 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5430 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5431 | |
| 5432 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5433 | }; |
| 5434 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5435 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5436 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5437 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5438 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5439 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5440 | barrier_kind_(barrier_kind) {} |
| 5441 | |
| 5442 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5443 | |
| 5444 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5445 | |
| 5446 | private: |
| 5447 | const MemBarrierKind barrier_kind_; |
| 5448 | |
| 5449 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5450 | }; |
| 5451 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5452 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5453 | public: |
| 5454 | enum OperationKind { |
| 5455 | kEnter, |
| 5456 | kExit, |
| 5457 | }; |
| 5458 | |
| 5459 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5460 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5461 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5462 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5463 | SetRawInputAt(0, object); |
| 5464 | } |
| 5465 | |
| 5466 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5467 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5468 | |
| 5469 | bool CanThrow() const OVERRIDE { |
| 5470 | // Verifier guarantees that monitor-exit cannot throw. |
| 5471 | // This is important because it allows the HGraphBuilder to remove |
| 5472 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5473 | return IsEnter(); |
| 5474 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5475 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5476 | |
| 5477 | bool IsEnter() const { return kind_ == kEnter; } |
| 5478 | |
| 5479 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5480 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5481 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5482 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5483 | |
| 5484 | private: |
| 5485 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5486 | }; |
| 5487 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5488 | /** |
| 5489 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5490 | * of a String to a call to a StringFactory. Only baseline will see |
| 5491 | * the node at code generation, where it will be be treated as null. |
| 5492 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5493 | * in the instruction simplifier. |
| 5494 | */ |
| 5495 | class HFakeString : public HTemplateInstruction<0> { |
| 5496 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5497 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5498 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5499 | |
| 5500 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5501 | |
| 5502 | DECLARE_INSTRUCTION(FakeString); |
| 5503 | |
| 5504 | private: |
| 5505 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5506 | }; |
| 5507 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5508 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5509 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5510 | MoveOperands(Location source, |
| 5511 | Location destination, |
| 5512 | Primitive::Type type, |
| 5513 | HInstruction* instruction) |
| 5514 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5515 | |
| 5516 | Location GetSource() const { return source_; } |
| 5517 | Location GetDestination() const { return destination_; } |
| 5518 | |
| 5519 | void SetSource(Location value) { source_ = value; } |
| 5520 | void SetDestination(Location value) { destination_ = value; } |
| 5521 | |
| 5522 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5523 | // destination (but not the source). |
| 5524 | Location MarkPending() { |
| 5525 | DCHECK(!IsPending()); |
| 5526 | Location dest = destination_; |
| 5527 | destination_ = Location::NoLocation(); |
| 5528 | return dest; |
| 5529 | } |
| 5530 | |
| 5531 | void ClearPending(Location dest) { |
| 5532 | DCHECK(IsPending()); |
| 5533 | destination_ = dest; |
| 5534 | } |
| 5535 | |
| 5536 | bool IsPending() const { |
| 5537 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5538 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5539 | } |
| 5540 | |
| 5541 | // True if this blocks a move from the given location. |
| 5542 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5543 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5544 | } |
| 5545 | |
| 5546 | // A move is redundant if it's been eliminated, if its source and |
| 5547 | // destination are the same, or if its destination is unneeded. |
| 5548 | bool IsRedundant() const { |
| 5549 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5550 | } |
| 5551 | |
| 5552 | // We clear both operands to indicate move that's been eliminated. |
| 5553 | void Eliminate() { |
| 5554 | source_ = destination_ = Location::NoLocation(); |
| 5555 | } |
| 5556 | |
| 5557 | bool IsEliminated() const { |
| 5558 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5559 | return source_.IsInvalid(); |
| 5560 | } |
| 5561 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5562 | Primitive::Type GetType() const { return type_; } |
| 5563 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5564 | bool Is64BitMove() const { |
| 5565 | return Primitive::Is64BitType(type_); |
| 5566 | } |
| 5567 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5568 | HInstruction* GetInstruction() const { return instruction_; } |
| 5569 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5570 | private: |
| 5571 | Location source_; |
| 5572 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5573 | // The type this move is for. |
| 5574 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5575 | // The instruction this move is assocatied with. Null when this move is |
| 5576 | // for moving an input in the expected locations of user (including a phi user). |
| 5577 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5578 | // in the same parallel move. |
| 5579 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5580 | }; |
| 5581 | |
| 5582 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5583 | |
| 5584 | class HParallelMove : public HTemplateInstruction<0> { |
| 5585 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5586 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5587 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5588 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5589 | moves_.reserve(kDefaultNumberOfMoves); |
| 5590 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5591 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5592 | void AddMove(Location source, |
| 5593 | Location destination, |
| 5594 | Primitive::Type type, |
| 5595 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5596 | DCHECK(source.IsValid()); |
| 5597 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5598 | if (kIsDebugBuild) { |
| 5599 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5600 | for (const MoveOperands& move : moves_) { |
| 5601 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5602 | // Special case the situation where the move is for the spill slot |
| 5603 | // of the instruction. |
| 5604 | if ((GetPrevious() == instruction) |
| 5605 | || ((GetPrevious() == nullptr) |
| 5606 | && instruction->IsPhi() |
| 5607 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5608 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5609 | << "Doing parallel moves for the same instruction."; |
| 5610 | } else { |
| 5611 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5612 | } |
| 5613 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5614 | } |
| 5615 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5616 | for (const MoveOperands& move : moves_) { |
| 5617 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5618 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5619 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5620 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5621 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5622 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5623 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5624 | } |
| 5625 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5626 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5627 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5628 | } |
| 5629 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5630 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5631 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5632 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5633 | |
| 5634 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5635 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5636 | |
| 5637 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5638 | }; |
| 5639 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5640 | } // namespace art |
| 5641 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 5642 | #ifdef ART_ENABLE_CODEGEN_arm |
| 5643 | #include "nodes_arm.h" |
| 5644 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5645 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5646 | #include "nodes_arm64.h" |
| 5647 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5648 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5649 | #include "nodes_x86.h" |
| 5650 | #endif |
| 5651 | |
| 5652 | namespace art { |
| 5653 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5654 | class HGraphVisitor : public ValueObject { |
| 5655 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5656 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5657 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5658 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5659 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5660 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5661 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5662 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5663 | void VisitInsertionOrder(); |
| 5664 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5665 | // Visit the graph following dominator tree reverse post-order. |
| 5666 | void VisitReversePostOrder(); |
| 5667 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5668 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5669 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5670 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5671 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5672 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5673 | |
| 5674 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5675 | |
| 5676 | #undef DECLARE_VISIT_INSTRUCTION |
| 5677 | |
| 5678 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5679 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5680 | |
| 5681 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5682 | }; |
| 5683 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5684 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5685 | public: |
| 5686 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5687 | virtual ~HGraphDelegateVisitor() {} |
| 5688 | |
| 5689 | // Visit functions that delegate to to super class. |
| 5690 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5691 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5692 | |
| 5693 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5694 | |
| 5695 | #undef DECLARE_VISIT_INSTRUCTION |
| 5696 | |
| 5697 | private: |
| 5698 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5699 | }; |
| 5700 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5701 | class HInsertionOrderIterator : public ValueObject { |
| 5702 | public: |
| 5703 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5704 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5705 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5706 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5707 | void Advance() { ++index_; } |
| 5708 | |
| 5709 | private: |
| 5710 | const HGraph& graph_; |
| 5711 | size_t index_; |
| 5712 | |
| 5713 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5714 | }; |
| 5715 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5716 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5717 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5718 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5719 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5720 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5721 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5722 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5723 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5724 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5725 | void Advance() { ++index_; } |
| 5726 | |
| 5727 | private: |
| 5728 | const HGraph& graph_; |
| 5729 | size_t index_; |
| 5730 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5731 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5732 | }; |
| 5733 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5734 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5735 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5736 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5737 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5738 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5739 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5740 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5741 | |
| 5742 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5743 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5744 | void Advance() { --index_; } |
| 5745 | |
| 5746 | private: |
| 5747 | const HGraph& graph_; |
| 5748 | size_t index_; |
| 5749 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5750 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5751 | }; |
| 5752 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5753 | class HLinearPostOrderIterator : public ValueObject { |
| 5754 | public: |
| 5755 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5756 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5757 | |
| 5758 | bool Done() const { return index_ == 0; } |
| 5759 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5760 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5761 | |
| 5762 | void Advance() { |
| 5763 | --index_; |
| 5764 | DCHECK_GE(index_, 0U); |
| 5765 | } |
| 5766 | |
| 5767 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5768 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5769 | size_t index_; |
| 5770 | |
| 5771 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5772 | }; |
| 5773 | |
| 5774 | class HLinearOrderIterator : public ValueObject { |
| 5775 | public: |
| 5776 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5777 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5778 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5779 | bool Done() const { return index_ == order_.size(); } |
| 5780 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5781 | void Advance() { ++index_; } |
| 5782 | |
| 5783 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5784 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5785 | size_t index_; |
| 5786 | |
| 5787 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5788 | }; |
| 5789 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5790 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5791 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5792 | // block id. |
| 5793 | class HBlocksInLoopIterator : public ValueObject { |
| 5794 | public: |
| 5795 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5796 | : blocks_in_loop_(info.GetBlocks()), |
| 5797 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5798 | index_(0) { |
| 5799 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5800 | Advance(); |
| 5801 | } |
| 5802 | } |
| 5803 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5804 | bool Done() const { return index_ == blocks_.size(); } |
| 5805 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5806 | void Advance() { |
| 5807 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5808 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5809 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5810 | break; |
| 5811 | } |
| 5812 | } |
| 5813 | } |
| 5814 | |
| 5815 | private: |
| 5816 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5817 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5818 | size_t index_; |
| 5819 | |
| 5820 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5821 | }; |
| 5822 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5823 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5824 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5825 | // post order. |
| 5826 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5827 | public: |
| 5828 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5829 | : blocks_in_loop_(info.GetBlocks()), |
| 5830 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5831 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5832 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5833 | Advance(); |
| 5834 | } |
| 5835 | } |
| 5836 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5837 | bool Done() const { return index_ == blocks_.size(); } |
| 5838 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5839 | void Advance() { |
| 5840 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5841 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5842 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5843 | break; |
| 5844 | } |
| 5845 | } |
| 5846 | } |
| 5847 | |
| 5848 | private: |
| 5849 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5850 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5851 | size_t index_; |
| 5852 | |
| 5853 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5854 | }; |
| 5855 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5856 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5857 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5858 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5859 | : constant->AsLongConstant()->GetValue(); |
| 5860 | } |
| 5861 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5862 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5863 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5864 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5865 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5866 | // times and provide different class resolution but no two class loaders should ever |
| 5867 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5868 | // all sorts of weird failures. |
| 5869 | return &lhs == &rhs; |
| 5870 | } |
| 5871 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5872 | } // namespace art |
| 5873 | |
| 5874 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |