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 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 101 | enum BuildSsaResult { |
| 102 | kBuildSsaFailNonNaturalLoop, |
| 103 | kBuildSsaFailThrowCatchLoop, |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 104 | kBuildSsaFailAmbiguousArrayOp, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 105 | kBuildSsaSuccess, |
| 106 | }; |
| 107 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 108 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 109 | public: |
| 110 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 111 | |
| 112 | void AddInstruction(HInstruction* instruction); |
| 113 | void RemoveInstruction(HInstruction* instruction); |
| 114 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 115 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 116 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 117 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 118 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 119 | // Return true if this list contains `instruction`. |
| 120 | bool Contains(HInstruction* instruction) const; |
| 121 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 122 | // Return true if `instruction1` is found before `instruction2` in |
| 123 | // this instruction list and false otherwise. Abort if none |
| 124 | // of these instructions is found. |
| 125 | bool FoundBefore(const HInstruction* instruction1, |
| 126 | const HInstruction* instruction2) const; |
| 127 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 128 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 129 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 130 | |
| 131 | // Update the block of all instructions to be `block`. |
| 132 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 133 | |
| 134 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 135 | void Add(const HInstructionList& instruction_list); |
| 136 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 137 | // Return the number of instructions in the list. This is an expensive operation. |
| 138 | size_t CountSize() const; |
| 139 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 140 | private: |
| 141 | HInstruction* first_instruction_; |
| 142 | HInstruction* last_instruction_; |
| 143 | |
| 144 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 145 | friend class HGraph; |
| 146 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 147 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 148 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 151 | }; |
| 152 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 153 | class ReferenceTypeInfo : ValueObject { |
| 154 | public: |
| 155 | typedef Handle<mirror::Class> TypeHandle; |
| 156 | |
| 157 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 158 | // The constructor will check that the type_handle is valid. |
| 159 | return ReferenceTypeInfo(type_handle, is_exact); |
| 160 | } |
| 161 | |
| 162 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 163 | |
| 164 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 165 | return handle.GetReference() != nullptr; |
| 166 | } |
| 167 | |
| 168 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 169 | return IsValidHandle(type_handle_); |
| 170 | } |
| 171 | |
| 172 | bool IsExact() const { return is_exact_; } |
| 173 | |
| 174 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 175 | DCHECK(IsValid()); |
| 176 | return GetTypeHandle()->IsObjectClass(); |
| 177 | } |
| 178 | |
| 179 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 180 | DCHECK(IsValid()); |
| 181 | return GetTypeHandle()->IsStringClass(); |
| 182 | } |
| 183 | |
| 184 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 185 | DCHECK(IsValid()); |
| 186 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 187 | } |
| 188 | |
| 189 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 190 | DCHECK(IsValid()); |
| 191 | return GetTypeHandle()->IsInterface(); |
| 192 | } |
| 193 | |
| 194 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 195 | DCHECK(IsValid()); |
| 196 | return GetTypeHandle()->IsArrayClass(); |
| 197 | } |
| 198 | |
| 199 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 200 | DCHECK(IsValid()); |
| 201 | return GetTypeHandle()->IsPrimitiveArray(); |
| 202 | } |
| 203 | |
| 204 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 205 | DCHECK(IsValid()); |
| 206 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 207 | } |
| 208 | |
| 209 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 210 | DCHECK(IsValid()); |
| 211 | if (!IsExact()) return false; |
| 212 | if (!IsArrayClass()) return false; |
| 213 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 214 | } |
| 215 | |
| 216 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 217 | DCHECK(IsValid()); |
| 218 | if (!IsExact()) return false; |
| 219 | if (!IsArrayClass()) return false; |
| 220 | if (!rti.IsArrayClass()) return false; |
| 221 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 222 | rti.GetTypeHandle()->GetComponentType()); |
| 223 | } |
| 224 | |
| 225 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 226 | |
| 227 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 228 | DCHECK(IsValid()); |
| 229 | DCHECK(rti.IsValid()); |
| 230 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 231 | } |
| 232 | |
| 233 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 234 | DCHECK(IsValid()); |
| 235 | DCHECK(rti.IsValid()); |
| 236 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 237 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 238 | } |
| 239 | |
| 240 | // Returns true if the type information provide the same amount of details. |
| 241 | // Note that it does not mean that the instructions have the same actual type |
| 242 | // (because the type can be the result of a merge). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 243 | bool IsEqual(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 244 | if (!IsValid() && !rti.IsValid()) { |
| 245 | // Invalid types are equal. |
| 246 | return true; |
| 247 | } |
| 248 | if (!IsValid() || !rti.IsValid()) { |
| 249 | // One is valid, the other not. |
| 250 | return false; |
| 251 | } |
| 252 | return IsExact() == rti.IsExact() |
| 253 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 254 | } |
| 255 | |
| 256 | private: |
| 257 | ReferenceTypeInfo(); |
| 258 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
| 259 | |
| 260 | // The class of the object. |
| 261 | TypeHandle type_handle_; |
| 262 | // Whether or not the type is exact or a superclass of the actual type. |
| 263 | // Whether or not we have any information about this type. |
| 264 | bool is_exact_; |
| 265 | }; |
| 266 | |
| 267 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 268 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 269 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 270 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 271 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 272 | HGraph(ArenaAllocator* arena, |
| 273 | const DexFile& dex_file, |
| 274 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 275 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 276 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 277 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 278 | bool debuggable = false, |
| 279 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 280 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 281 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 282 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 283 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 284 | entry_block_(nullptr), |
| 285 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 286 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 287 | number_of_vregs_(0), |
| 288 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 289 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 290 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 291 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 292 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 293 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 294 | dex_file_(dex_file), |
| 295 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 296 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 297 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 298 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 299 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 300 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 301 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 302 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 303 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 304 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 305 | cached_current_method_(nullptr), |
| 306 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 307 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 308 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 309 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 310 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 311 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 312 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 313 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 314 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 315 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 316 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 317 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 318 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 319 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 320 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 321 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 322 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 323 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 324 | // Try building the SSA form of this graph, with dominance computation and |
| 325 | // loop recognition. Returns a code specifying that it was successful or the |
| 326 | // reason for failure. |
| 327 | BuildSsaResult TryBuildingSsa(StackHandleScopeCollection* handles); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 328 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 329 | void ComputeDominanceInformation(); |
| 330 | void ClearDominanceInformation(); |
| 331 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 332 | void BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 333 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 334 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 335 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 336 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 337 | // was successful or the reason for failure. The method will fail if a loop |
| 338 | // is not natural, that is the header does not dominate a back edge, or if it |
| 339 | // is a throw-catch loop, i.e. the header is a catch block. |
| 340 | BuildSsaResult AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 341 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 342 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 343 | // order and loop information. |
| 344 | void ComputeTryBlockInformation(); |
| 345 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 346 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 347 | // Returns the instruction used to replace the invoke expression or null if the |
| 348 | // invoke is for a void method. |
| 349 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 350 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 351 | // Need to add a couple of blocks to test if the loop body is entered and |
| 352 | // put deoptimization instructions, etc. |
| 353 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 354 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 355 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 356 | // other blocks and has no instructions or phis. |
| 357 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 358 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 359 | // Splits the edge between `block` and `successor` while preserving the |
| 360 | // indices in the predecessor/successor lists. If there are multiple edges |
| 361 | // between the blocks, the lowest indices are used. |
| 362 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 363 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 364 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 365 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 366 | void SimplifyLoop(HBasicBlock* header); |
| 367 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 368 | int32_t GetNextInstructionId() { |
| 369 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 370 | return current_instruction_id_++; |
| 371 | } |
| 372 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 373 | int32_t GetCurrentInstructionId() const { |
| 374 | return current_instruction_id_; |
| 375 | } |
| 376 | |
| 377 | void SetCurrentInstructionId(int32_t id) { |
| 378 | current_instruction_id_ = id; |
| 379 | } |
| 380 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 381 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 382 | return maximum_number_of_out_vregs_; |
| 383 | } |
| 384 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 385 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 386 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 387 | } |
| 388 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 389 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 390 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 391 | } |
| 392 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 393 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 394 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 395 | } |
| 396 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 397 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 398 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 399 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 402 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 403 | number_of_vregs_ = number_of_vregs; |
| 404 | } |
| 405 | |
| 406 | uint16_t GetNumberOfVRegs() const { |
| 407 | return number_of_vregs_; |
| 408 | } |
| 409 | |
| 410 | void SetNumberOfInVRegs(uint16_t value) { |
| 411 | number_of_in_vregs_ = value; |
| 412 | } |
| 413 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 414 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 415 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 416 | return number_of_vregs_ - number_of_in_vregs_; |
| 417 | } |
| 418 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 419 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 420 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 421 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 422 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 423 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 424 | return linear_order_; |
| 425 | } |
| 426 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 427 | bool HasBoundsChecks() const { |
| 428 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 429 | } |
| 430 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 431 | void SetHasBoundsChecks(bool value) { |
| 432 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 435 | bool ShouldGenerateConstructorBarrier() const { |
| 436 | return should_generate_constructor_barrier_; |
| 437 | } |
| 438 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 439 | bool IsDebuggable() const { return debuggable_; } |
| 440 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 441 | // 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] | 442 | // already, it is created and inserted into the graph. This method is only for |
| 443 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 444 | 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] | 445 | |
| 446 | // TODO: This is problematic for the consistency of reference type propagation |
| 447 | // because it can be created anytime after the pass and thus it will be left |
| 448 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 449 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 450 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 451 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 452 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 453 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 454 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 455 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 456 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 457 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 458 | 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] | 459 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 460 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 461 | 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] | 462 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 463 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 464 | HCurrentMethod* GetCurrentMethod(); |
| 465 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 466 | const DexFile& GetDexFile() const { |
| 467 | return dex_file_; |
| 468 | } |
| 469 | |
| 470 | uint32_t GetMethodIdx() const { |
| 471 | return method_idx_; |
| 472 | } |
| 473 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 474 | InvokeType GetInvokeType() const { |
| 475 | return invoke_type_; |
| 476 | } |
| 477 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 478 | InstructionSet GetInstructionSet() const { |
| 479 | return instruction_set_; |
| 480 | } |
| 481 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 482 | bool HasTryCatch() const { return has_try_catch_; } |
| 483 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 484 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 485 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 486 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 487 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 488 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 489 | // The instruction has been inserted into the graph, either as a constant, or |
| 490 | // before cursor. |
| 491 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 492 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 493 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 494 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 495 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 496 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 497 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 498 | template <class InstructionType, typename ValueType> |
| 499 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 500 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 501 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 502 | // Try to find an existing constant of the given value. |
| 503 | InstructionType* constant = nullptr; |
| 504 | auto cached_constant = cache->find(value); |
| 505 | if (cached_constant != cache->end()) { |
| 506 | constant = cached_constant->second; |
| 507 | } |
| 508 | |
| 509 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 510 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 511 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 512 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 513 | cache->Overwrite(value, constant); |
| 514 | InsertConstant(constant); |
| 515 | } |
| 516 | return constant; |
| 517 | } |
| 518 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 519 | void InsertConstant(HConstant* instruction); |
| 520 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 521 | // Cache a float constant into the graph. This method should only be |
| 522 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 523 | void CacheFloatConstant(HFloatConstant* constant); |
| 524 | |
| 525 | // See CacheFloatConstant comment. |
| 526 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 527 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 528 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 529 | |
| 530 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 531 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 532 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 533 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 534 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 535 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 536 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 537 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 538 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 539 | HBasicBlock* entry_block_; |
| 540 | HBasicBlock* exit_block_; |
| 541 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 542 | // 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] | 543 | uint16_t maximum_number_of_out_vregs_; |
| 544 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 545 | // The number of virtual registers in this method. Contains the parameters. |
| 546 | uint16_t number_of_vregs_; |
| 547 | |
| 548 | // The number of virtual registers used by parameters of this method. |
| 549 | uint16_t number_of_in_vregs_; |
| 550 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 551 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 552 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 553 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 554 | // Has bounds checks. We can totally skip BCE if it's false. |
| 555 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 556 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 557 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 558 | // try/catch-related passes if false. |
| 559 | bool has_try_catch_; |
| 560 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 561 | // Indicates whether the graph should be compiled in a way that |
| 562 | // ensures full debuggability. If false, we can apply more |
| 563 | // aggressive optimizations that may limit the level of debugging. |
| 564 | const bool debuggable_; |
| 565 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 566 | // 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] | 567 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 568 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 569 | // The dex file from which the method is from. |
| 570 | const DexFile& dex_file_; |
| 571 | |
| 572 | // The method index in the dex file. |
| 573 | const uint32_t method_idx_; |
| 574 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 575 | // If inlined, this encodes how the callee is being invoked. |
| 576 | const InvokeType invoke_type_; |
| 577 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 578 | // Whether the graph has been transformed to SSA form. Only used |
| 579 | // in debug mode to ensure we are not using properties only valid |
| 580 | // for non-SSA form (like the number of temporaries). |
| 581 | bool in_ssa_form_; |
| 582 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 583 | const bool should_generate_constructor_barrier_; |
| 584 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 585 | const InstructionSet instruction_set_; |
| 586 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 587 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 588 | HNullConstant* cached_null_constant_; |
| 589 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 590 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 591 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 592 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 593 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 594 | HCurrentMethod* cached_current_method_; |
| 595 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 596 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 597 | // for example for methods whose declaring class could not be resolved |
| 598 | // (such as when the superclass could not be found). |
| 599 | ArtMethod* art_method_; |
| 600 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 601 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 602 | // collection pointer to passes which may create NullConstant. |
| 603 | ReferenceTypeInfo inexact_object_rti_; |
| 604 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 605 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 606 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 607 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 608 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 609 | }; |
| 610 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 611 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 612 | public: |
| 613 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 614 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 615 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 616 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 617 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 618 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 619 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 620 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 621 | |
| 622 | HBasicBlock* GetHeader() const { |
| 623 | return header_; |
| 624 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 625 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 626 | void SetHeader(HBasicBlock* block) { |
| 627 | header_ = block; |
| 628 | } |
| 629 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 630 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 631 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 632 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 633 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 634 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 635 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 638 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 639 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 640 | } |
| 641 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 642 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 643 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 644 | } |
| 645 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 646 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 647 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 650 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 651 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 652 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 653 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 654 | } |
| 655 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 656 | // Returns the lifetime position of the back edge that has the |
| 657 | // greatest lifetime position. |
| 658 | size_t GetLifetimeEnd() const; |
| 659 | |
| 660 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 661 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 662 | } |
| 663 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 664 | // 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] | 665 | // that is the header dominates the back edge. |
| 666 | bool Populate(); |
| 667 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 668 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 669 | // Populate(). If there are no back edges left, the loop info is completely |
| 670 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 671 | // inner loops first. |
| 672 | void Update(); |
| 673 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 674 | // Returns whether this loop information contains `block`. |
| 675 | // Note that this loop information *must* be populated before entering this function. |
| 676 | bool Contains(const HBasicBlock& block) const; |
| 677 | |
| 678 | // Returns whether this loop information is an inner loop of `other`. |
| 679 | // Note that `other` *must* be populated before entering this function. |
| 680 | bool IsIn(const HLoopInformation& other) const; |
| 681 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 682 | // Returns true if instruction is not defined within this loop. |
| 683 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 684 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 685 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 686 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 687 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 688 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 689 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 690 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 691 | // Internal recursive implementation of `Populate`. |
| 692 | void PopulateRecursive(HBasicBlock* block); |
| 693 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 694 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 695 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 696 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 697 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 698 | |
| 699 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 700 | }; |
| 701 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 702 | // Stores try/catch information for basic blocks. |
| 703 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 704 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 705 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 706 | public: |
| 707 | // Try block information constructor. |
| 708 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 709 | : try_entry_(&try_entry), |
| 710 | catch_dex_file_(nullptr), |
| 711 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 712 | DCHECK(try_entry_ != nullptr); |
| 713 | } |
| 714 | |
| 715 | // Catch block information constructor. |
| 716 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 717 | : try_entry_(nullptr), |
| 718 | catch_dex_file_(&dex_file), |
| 719 | catch_type_index_(catch_type_index) {} |
| 720 | |
| 721 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 722 | |
| 723 | const HTryBoundary& GetTryEntry() const { |
| 724 | DCHECK(IsTryBlock()); |
| 725 | return *try_entry_; |
| 726 | } |
| 727 | |
| 728 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 729 | |
| 730 | bool IsCatchAllTypeIndex() const { |
| 731 | DCHECK(IsCatchBlock()); |
| 732 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 733 | } |
| 734 | |
| 735 | uint16_t GetCatchTypeIndex() const { |
| 736 | DCHECK(IsCatchBlock()); |
| 737 | return catch_type_index_; |
| 738 | } |
| 739 | |
| 740 | const DexFile& GetCatchDexFile() const { |
| 741 | DCHECK(IsCatchBlock()); |
| 742 | return *catch_dex_file_; |
| 743 | } |
| 744 | |
| 745 | private: |
| 746 | // One of possibly several TryBoundary instructions entering the block's try. |
| 747 | // Only set for try blocks. |
| 748 | const HTryBoundary* try_entry_; |
| 749 | |
| 750 | // Exception type information. Only set for catch blocks. |
| 751 | const DexFile* catch_dex_file_; |
| 752 | const uint16_t catch_type_index_; |
| 753 | }; |
| 754 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 755 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 756 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 757 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 758 | // A block in a method. Contains the list of instructions represented |
| 759 | // as a double linked list. Each block knows its predecessors and |
| 760 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 761 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 762 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 763 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 764 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 765 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 766 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 767 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 768 | loop_information_(nullptr), |
| 769 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 770 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 771 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 772 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 773 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 774 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 775 | try_catch_information_(nullptr) { |
| 776 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 777 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 778 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 779 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 780 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 781 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 782 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 783 | } |
| 784 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 785 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 786 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 787 | } |
| 788 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 789 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 790 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 791 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 792 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 793 | return ContainsElement(successors_, block, start_from); |
| 794 | } |
| 795 | |
| 796 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 797 | return dominated_blocks_; |
| 798 | } |
| 799 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 800 | bool IsEntryBlock() const { |
| 801 | return graph_->GetEntryBlock() == this; |
| 802 | } |
| 803 | |
| 804 | bool IsExitBlock() const { |
| 805 | return graph_->GetExitBlock() == this; |
| 806 | } |
| 807 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 808 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 809 | bool IsSingleTryBoundary() const; |
| 810 | |
| 811 | // Returns true if this block emits nothing but a jump. |
| 812 | bool IsSingleJump() const { |
| 813 | HLoopInformation* loop_info = GetLoopInformation(); |
| 814 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 815 | // Back edges generate a suspend check. |
| 816 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 817 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 818 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 819 | void AddBackEdge(HBasicBlock* back_edge) { |
| 820 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 821 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 822 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 823 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 824 | loop_information_->AddBackEdge(back_edge); |
| 825 | } |
| 826 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 827 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 828 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 829 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 830 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 831 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 832 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 833 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 834 | HBasicBlock* GetDominator() const { return dominator_; } |
| 835 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 836 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 837 | |
| 838 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 839 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 840 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 841 | |
| 842 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 843 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 844 | } |
| 845 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 846 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 847 | |
| 848 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 849 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 852 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 853 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 854 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 855 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 856 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 857 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 858 | |
| 859 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 860 | successors_.push_back(block); |
| 861 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 862 | } |
| 863 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 864 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 865 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 866 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 867 | new_block->predecessors_.push_back(this); |
| 868 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 869 | } |
| 870 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 871 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 872 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 873 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 874 | new_block->successors_.push_back(this); |
| 875 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 876 | } |
| 877 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 878 | // Insert `this` between `predecessor` and `successor. This method |
| 879 | // preserves the indicies, and will update the first edge found between |
| 880 | // `predecessor` and `successor`. |
| 881 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 882 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 883 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 884 | successor->predecessors_[predecessor_index] = this; |
| 885 | predecessor->successors_[successor_index] = this; |
| 886 | successors_.push_back(successor); |
| 887 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 888 | } |
| 889 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 890 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 891 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 892 | } |
| 893 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 894 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 895 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 896 | } |
| 897 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 898 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 899 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 903 | predecessors_.push_back(block); |
| 904 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 907 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 908 | DCHECK_EQ(predecessors_.size(), 2u); |
| 909 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 910 | } |
| 911 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 912 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 913 | DCHECK_EQ(successors_.size(), 2u); |
| 914 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 915 | } |
| 916 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 917 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 918 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 919 | } |
| 920 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 921 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 922 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 923 | } |
| 924 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 925 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 926 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 927 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 931 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 932 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | // Returns whether the first occurrence of `predecessor` in the list of |
| 936 | // predecessors is at index `idx`. |
| 937 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 938 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 939 | return GetPredecessorIndexOf(predecessor) == idx; |
| 940 | } |
| 941 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 942 | // Create a new block between this block and its predecessors. The new block |
| 943 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 944 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 945 | // loop and try/catch information are not updated. |
| 946 | HBasicBlock* CreateImmediateDominator(); |
| 947 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 948 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 949 | // created, latter block. Note that this method will add the block to the |
| 950 | // graph, create a Goto at the end of the former block and will create an edge |
| 951 | // 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] | 952 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 953 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 954 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 955 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 956 | // created block. Note that this method just updates raw block information, |
| 957 | // like predecessors, successors, dominators, and instruction list. It does not |
| 958 | // update the graph, reverse post order, loop information, nor make sure the |
| 959 | // blocks are consistent (for example ending with a control flow instruction). |
| 960 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 961 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 962 | // Split catch block into two blocks after the original move-exception bytecode |
| 963 | // instruction, or at the beginning if not present. Returns the newly created, |
| 964 | // latter block, or nullptr if such block could not be created (must be dead |
| 965 | // in that case). Note that this method just updates raw block information, |
| 966 | // like predecessors, successors, dominators, and instruction list. It does not |
| 967 | // update the graph, reverse post order, loop information, nor make sure the |
| 968 | // blocks are consistent (for example ending with a control flow instruction). |
| 969 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 970 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 971 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 972 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 973 | // that this method does not update the graph, reverse post order, loop |
| 974 | // information, nor make sure the blocks are consistent (for example ending |
| 975 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 976 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 977 | |
| 978 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 979 | // of `this` are moved to `other`. |
| 980 | // Note that this method does not update the graph, reverse post order, loop |
| 981 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 982 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 983 | void ReplaceWith(HBasicBlock* other); |
| 984 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 985 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 986 | // order, links to predecessors, successors, dominators and deletes the block |
| 987 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 988 | // predecessor of `other` and vice versa. |
| 989 | void MergeWith(HBasicBlock* other); |
| 990 | |
| 991 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 992 | // removes it from all loops it is included in and eventually from the graph. |
| 993 | // The block must not dominate any other block. Predecessors and successors |
| 994 | // are safely updated. |
| 995 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 996 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 997 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 998 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 999 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1000 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1001 | // Replace instruction `initial` with `replacement` within this block. |
| 1002 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1003 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1004 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1005 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1006 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1007 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1008 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1009 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1010 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1011 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1012 | |
| 1013 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1014 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1015 | } |
| 1016 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1017 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1018 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1019 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1022 | HLoopInformation* GetLoopInformation() const { |
| 1023 | return loop_information_; |
| 1024 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1025 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1026 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1027 | // 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] | 1028 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1029 | void SetInLoop(HLoopInformation* info) { |
| 1030 | if (IsLoopHeader()) { |
| 1031 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1032 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1033 | loop_information_ = info; |
| 1034 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1035 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1036 | // Note that a non loop header having a loop information means this loop information |
| 1037 | // has already been populated |
| 1038 | loop_information_ = info; |
| 1039 | } else { |
| 1040 | // Block is part of an inner loop. Do not update the loop information. |
| 1041 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1042 | // at this point, because this method is being called while populating `info`. |
| 1043 | } |
| 1044 | } |
| 1045 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1046 | // Raw update of the loop information. |
| 1047 | void SetLoopInformation(HLoopInformation* info) { |
| 1048 | loop_information_ = info; |
| 1049 | } |
| 1050 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1051 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1052 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1053 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1054 | |
| 1055 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1056 | try_catch_information_ = try_catch_information; |
| 1057 | } |
| 1058 | |
| 1059 | bool IsTryBlock() const { |
| 1060 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1061 | } |
| 1062 | |
| 1063 | bool IsCatchBlock() const { |
| 1064 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1065 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1066 | |
| 1067 | // Returns the try entry that this block's successors should have. They will |
| 1068 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1069 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1070 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1071 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1072 | bool HasThrowingInstructions() const; |
| 1073 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1074 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1075 | bool Dominates(HBasicBlock* block) const; |
| 1076 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1077 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1078 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1079 | |
| 1080 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1081 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1082 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1083 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1084 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1085 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1086 | bool HasSinglePhi() const; |
| 1087 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1088 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1089 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1090 | ArenaVector<HBasicBlock*> predecessors_; |
| 1091 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1092 | HInstructionList instructions_; |
| 1093 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1094 | HLoopInformation* loop_information_; |
| 1095 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1096 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1097 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1098 | // The dex program counter of the first instruction of this block. |
| 1099 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1100 | size_t lifetime_start_; |
| 1101 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1102 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1103 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1104 | friend class HGraph; |
| 1105 | friend class HInstruction; |
| 1106 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1107 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1108 | }; |
| 1109 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1110 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1111 | // from the innermost to the outermost. |
| 1112 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1113 | public: |
| 1114 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1115 | : current_(block.GetLoopInformation()) {} |
| 1116 | |
| 1117 | bool Done() const { return current_ == nullptr; } |
| 1118 | |
| 1119 | void Advance() { |
| 1120 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1121 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | HLoopInformation* Current() const { |
| 1125 | DCHECK(!Done()); |
| 1126 | return current_; |
| 1127 | } |
| 1128 | |
| 1129 | private: |
| 1130 | HLoopInformation* current_; |
| 1131 | |
| 1132 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1133 | }; |
| 1134 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1135 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1136 | M(Above, Condition) \ |
| 1137 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1138 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1139 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1140 | M(ArrayGet, Instruction) \ |
| 1141 | M(ArrayLength, Instruction) \ |
| 1142 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1143 | M(Below, Condition) \ |
| 1144 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1145 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1146 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1147 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1148 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1149 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1150 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1151 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1152 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1153 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1154 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1155 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1156 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1157 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1158 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1159 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1160 | M(FloatConstant, Constant) \ |
| 1161 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1162 | M(GreaterThan, Condition) \ |
| 1163 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1164 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1165 | M(InstanceFieldGet, Instruction) \ |
| 1166 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1167 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1168 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1169 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1170 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1171 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1172 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1173 | M(LessThan, Condition) \ |
| 1174 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1175 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1176 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1177 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1178 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1179 | M(Local, Instruction) \ |
| 1180 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1181 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1182 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1183 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1184 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1185 | M(Neg, UnaryOperation) \ |
| 1186 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1187 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1188 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1189 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1190 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1191 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1192 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1193 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1194 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1195 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1196 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1197 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1198 | M(Return, Instruction) \ |
| 1199 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1200 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1201 | M(Shl, BinaryOperation) \ |
| 1202 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1203 | M(StaticFieldGet, Instruction) \ |
| 1204 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1205 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1206 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1207 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1208 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1209 | M(StoreLocal, Instruction) \ |
| 1210 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1211 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1212 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1213 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1214 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1215 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1216 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1217 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1218 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1219 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1220 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1221 | #else |
| 1222 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1223 | M(ArmDexCacheArraysBase, Instruction) |
| 1224 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1225 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1226 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1227 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1228 | #else |
| 1229 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1230 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1231 | M(Arm64IntermediateAddress, Instruction) \ |
| 1232 | M(Arm64MultiplyAccumulate, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1233 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1234 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1235 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1236 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1237 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1238 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1239 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1240 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1241 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1242 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1243 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1244 | M(X86LoadFromConstantTable, Instruction) \ |
| 1245 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1246 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1247 | |
| 1248 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1249 | |
| 1250 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1251 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1252 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1253 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1254 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1255 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1256 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1257 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1258 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1259 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1260 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1261 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1262 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1263 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1264 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1265 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1266 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1267 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1268 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1269 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1270 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1271 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1272 | #undef FORWARD_DECLARATION |
| 1273 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1274 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1275 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1276 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1277 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1278 | return other->Is##type(); \ |
| 1279 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1280 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1281 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1282 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1283 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1284 | const H##type* As##type() const { return this; } \ |
| 1285 | H##type* As##type() { return this; } |
| 1286 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1287 | template <typename T> class HUseList; |
| 1288 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1289 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1290 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1291 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1292 | HUseListNode* GetPrevious() const { return prev_; } |
| 1293 | HUseListNode* GetNext() const { return next_; } |
| 1294 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1295 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1296 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1297 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1298 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1299 | HUseListNode(T user, size_t index) |
| 1300 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1301 | |
| 1302 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1303 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1304 | HUseListNode<T>* prev_; |
| 1305 | HUseListNode<T>* next_; |
| 1306 | |
| 1307 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1308 | |
| 1309 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1310 | }; |
| 1311 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1312 | template <typename T> |
| 1313 | class HUseList : public ValueObject { |
| 1314 | public: |
| 1315 | HUseList() : first_(nullptr) {} |
| 1316 | |
| 1317 | void Clear() { |
| 1318 | first_ = nullptr; |
| 1319 | } |
| 1320 | |
| 1321 | // Adds a new entry at the beginning of the use list and returns |
| 1322 | // the newly created node. |
| 1323 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1324 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1325 | if (IsEmpty()) { |
| 1326 | first_ = new_node; |
| 1327 | } else { |
| 1328 | first_->prev_ = new_node; |
| 1329 | new_node->next_ = first_; |
| 1330 | first_ = new_node; |
| 1331 | } |
| 1332 | return new_node; |
| 1333 | } |
| 1334 | |
| 1335 | HUseListNode<T>* GetFirst() const { |
| 1336 | return first_; |
| 1337 | } |
| 1338 | |
| 1339 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1340 | DCHECK(node != nullptr); |
| 1341 | DCHECK(Contains(node)); |
| 1342 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1343 | if (node->prev_ != nullptr) { |
| 1344 | node->prev_->next_ = node->next_; |
| 1345 | } |
| 1346 | if (node->next_ != nullptr) { |
| 1347 | node->next_->prev_ = node->prev_; |
| 1348 | } |
| 1349 | if (node == first_) { |
| 1350 | first_ = node->next_; |
| 1351 | } |
| 1352 | } |
| 1353 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1354 | bool Contains(const HUseListNode<T>* node) const { |
| 1355 | if (node == nullptr) { |
| 1356 | return false; |
| 1357 | } |
| 1358 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1359 | if (current == node) { |
| 1360 | return true; |
| 1361 | } |
| 1362 | } |
| 1363 | return false; |
| 1364 | } |
| 1365 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1366 | bool IsEmpty() const { |
| 1367 | return first_ == nullptr; |
| 1368 | } |
| 1369 | |
| 1370 | bool HasOnlyOneUse() const { |
| 1371 | return first_ != nullptr && first_->next_ == nullptr; |
| 1372 | } |
| 1373 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1374 | size_t SizeSlow() const { |
| 1375 | size_t count = 0; |
| 1376 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1377 | ++count; |
| 1378 | } |
| 1379 | return count; |
| 1380 | } |
| 1381 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1382 | private: |
| 1383 | HUseListNode<T>* first_; |
| 1384 | }; |
| 1385 | |
| 1386 | template<typename T> |
| 1387 | class HUseIterator : public ValueObject { |
| 1388 | public: |
| 1389 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1390 | |
| 1391 | bool Done() const { return current_ == nullptr; } |
| 1392 | |
| 1393 | void Advance() { |
| 1394 | DCHECK(!Done()); |
| 1395 | current_ = current_->GetNext(); |
| 1396 | } |
| 1397 | |
| 1398 | HUseListNode<T>* Current() const { |
| 1399 | DCHECK(!Done()); |
| 1400 | return current_; |
| 1401 | } |
| 1402 | |
| 1403 | private: |
| 1404 | HUseListNode<T>* current_; |
| 1405 | |
| 1406 | friend class HValue; |
| 1407 | }; |
| 1408 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1409 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1410 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1411 | // by the used instructions. |
| 1412 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1413 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1414 | public: |
| 1415 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1416 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1417 | |
| 1418 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1419 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1420 | DCHECK(instruction_ != nullptr); |
| 1421 | DCHECK(use_node_ != nullptr); |
| 1422 | DCHECK(old_record.use_node_ == nullptr); |
| 1423 | } |
| 1424 | |
| 1425 | HInstruction* GetInstruction() const { return instruction_; } |
| 1426 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1427 | |
| 1428 | private: |
| 1429 | // Instruction used by the user. |
| 1430 | HInstruction* instruction_; |
| 1431 | |
| 1432 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1433 | HUseListNode<T>* use_node_; |
| 1434 | }; |
| 1435 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1436 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1437 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1438 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1439 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1440 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1441 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1442 | * modify the value of a reference field read [although it may modify the |
| 1443 | * reference fetch prior to reading the field, which is represented by its own |
| 1444 | * write/read dependence]). The analysis makes conservative points-to |
| 1445 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1446 | * the same, and any reference read depends on any reference read without |
| 1447 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1448 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1449 | * The internal representation uses 38-bit and is described in the table below. |
| 1450 | * The first line indicates the side effect, and for field/array accesses the |
| 1451 | * second line indicates the type of the access (in the order of the |
| 1452 | * Primitive::Type enum). |
| 1453 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1454 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1455 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1456 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1457 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1458 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1459 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1460 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1461 | * |
| 1462 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1463 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1464 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1465 | class SideEffects : public ValueObject { |
| 1466 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1467 | SideEffects() : flags_(0) {} |
| 1468 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1469 | static SideEffects None() { |
| 1470 | return SideEffects(0); |
| 1471 | } |
| 1472 | |
| 1473 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1474 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1475 | } |
| 1476 | |
| 1477 | static SideEffects AllChanges() { |
| 1478 | return SideEffects(kAllChangeBits); |
| 1479 | } |
| 1480 | |
| 1481 | static SideEffects AllDependencies() { |
| 1482 | return SideEffects(kAllDependOnBits); |
| 1483 | } |
| 1484 | |
| 1485 | static SideEffects AllExceptGCDependency() { |
| 1486 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1487 | } |
| 1488 | |
| 1489 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1490 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1491 | } |
| 1492 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1493 | static SideEffects AllWrites() { |
| 1494 | return SideEffects(kAllWrites); |
| 1495 | } |
| 1496 | |
| 1497 | static SideEffects AllReads() { |
| 1498 | return SideEffects(kAllReads); |
| 1499 | } |
| 1500 | |
| 1501 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1502 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1503 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1504 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1505 | } |
| 1506 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1507 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1508 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1509 | } |
| 1510 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1511 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1512 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1513 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1514 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1518 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1519 | } |
| 1520 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1521 | static SideEffects CanTriggerGC() { |
| 1522 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1523 | } |
| 1524 | |
| 1525 | static SideEffects DependsOnGC() { |
| 1526 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1527 | } |
| 1528 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1529 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1530 | SideEffects Union(SideEffects other) const { |
| 1531 | return SideEffects(flags_ | other.flags_); |
| 1532 | } |
| 1533 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1534 | SideEffects Exclusion(SideEffects other) const { |
| 1535 | return SideEffects(flags_ & ~other.flags_); |
| 1536 | } |
| 1537 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1538 | void Add(SideEffects other) { |
| 1539 | flags_ |= other.flags_; |
| 1540 | } |
| 1541 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1542 | bool Includes(SideEffects other) const { |
| 1543 | return (other.flags_ & flags_) == other.flags_; |
| 1544 | } |
| 1545 | |
| 1546 | bool HasSideEffects() const { |
| 1547 | return (flags_ & kAllChangeBits); |
| 1548 | } |
| 1549 | |
| 1550 | bool HasDependencies() const { |
| 1551 | return (flags_ & kAllDependOnBits); |
| 1552 | } |
| 1553 | |
| 1554 | // Returns true if there are no side effects or dependencies. |
| 1555 | bool DoesNothing() const { |
| 1556 | return flags_ == 0; |
| 1557 | } |
| 1558 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1559 | // Returns true if something is written. |
| 1560 | bool DoesAnyWrite() const { |
| 1561 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1562 | } |
| 1563 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1564 | // Returns true if something is read. |
| 1565 | bool DoesAnyRead() const { |
| 1566 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1567 | } |
| 1568 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1569 | // Returns true if potentially everything is written and read |
| 1570 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1571 | bool DoesAllReadWrite() const { |
| 1572 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1573 | } |
| 1574 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1575 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1576 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1579 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1580 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1581 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1582 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1586 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1587 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1588 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1589 | for (int s = kLastBit; s >= 0; s--) { |
| 1590 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1591 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1592 | // This is a bit for the GC side effect. |
| 1593 | if (current_bit_is_set) { |
| 1594 | flags += "GC"; |
| 1595 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1596 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1597 | } else { |
| 1598 | // This is a bit for the array/field analysis. |
| 1599 | // The underscore character stands for the 'can trigger GC' bit. |
| 1600 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1601 | if (current_bit_is_set) { |
| 1602 | flags += kDebug[s]; |
| 1603 | } |
| 1604 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1605 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1606 | flags += "|"; |
| 1607 | } |
| 1608 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1609 | } |
| 1610 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1611 | } |
| 1612 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1613 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1614 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1615 | private: |
| 1616 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1617 | |
| 1618 | static constexpr int kFieldWriteOffset = 0; |
| 1619 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1620 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1621 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1622 | |
| 1623 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1624 | |
| 1625 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1626 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1627 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1628 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1629 | |
| 1630 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1631 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1632 | |
| 1633 | // Aliases. |
| 1634 | |
| 1635 | static_assert(kChangeBits == kDependOnBits, |
| 1636 | "the 'change' bits should match the 'depend on' bits."); |
| 1637 | |
| 1638 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1639 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1640 | static constexpr uint64_t kAllWrites = |
| 1641 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1642 | static constexpr uint64_t kAllReads = |
| 1643 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1644 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1645 | // Work around the fact that HIR aliases I/F and J/D. |
| 1646 | // TODO: remove this interceptor once HIR types are clean |
| 1647 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1648 | switch (type) { |
| 1649 | case Primitive::kPrimInt: |
| 1650 | case Primitive::kPrimFloat: |
| 1651 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1652 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1653 | case Primitive::kPrimLong: |
| 1654 | case Primitive::kPrimDouble: |
| 1655 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1656 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1657 | default: |
| 1658 | return TypeFlag(type, offset); |
| 1659 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1660 | } |
| 1661 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1662 | // Translates type to bit flag. |
| 1663 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1664 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1665 | const uint64_t one = 1; |
| 1666 | const int shift = type; // 0-based consecutive enum |
| 1667 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1668 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1669 | return one << (type + offset); |
| 1670 | } |
| 1671 | |
| 1672 | // Private constructor on direct flags value. |
| 1673 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1674 | |
| 1675 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1676 | }; |
| 1677 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1678 | // 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] | 1679 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1680 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1681 | HEnvironment(ArenaAllocator* arena, |
| 1682 | size_t number_of_vregs, |
| 1683 | const DexFile& dex_file, |
| 1684 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1685 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1686 | InvokeType invoke_type, |
| 1687 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1688 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1689 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1690 | parent_(nullptr), |
| 1691 | dex_file_(dex_file), |
| 1692 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1693 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1694 | invoke_type_(invoke_type), |
| 1695 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1696 | } |
| 1697 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1698 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1699 | : HEnvironment(arena, |
| 1700 | to_copy.Size(), |
| 1701 | to_copy.GetDexFile(), |
| 1702 | to_copy.GetMethodIdx(), |
| 1703 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1704 | to_copy.GetInvokeType(), |
| 1705 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1706 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1707 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1708 | if (parent_ != nullptr) { |
| 1709 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1710 | } else { |
| 1711 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1712 | parent_->CopyFrom(parent); |
| 1713 | if (parent->GetParent() != nullptr) { |
| 1714 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1715 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1716 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1717 | } |
| 1718 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1719 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1720 | void CopyFrom(HEnvironment* environment); |
| 1721 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1722 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1723 | // input to the loop phi instead. This is for inserting instructions that |
| 1724 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1725 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1726 | |
| 1727 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1728 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1732 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1735 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1736 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1737 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1738 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1739 | HEnvironment* GetParent() const { return parent_; } |
| 1740 | |
| 1741 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1742 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1746 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | uint32_t GetDexPc() const { |
| 1750 | return dex_pc_; |
| 1751 | } |
| 1752 | |
| 1753 | uint32_t GetMethodIdx() const { |
| 1754 | return method_idx_; |
| 1755 | } |
| 1756 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1757 | InvokeType GetInvokeType() const { |
| 1758 | return invoke_type_; |
| 1759 | } |
| 1760 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1761 | const DexFile& GetDexFile() const { |
| 1762 | return dex_file_; |
| 1763 | } |
| 1764 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1765 | HInstruction* GetHolder() const { |
| 1766 | return holder_; |
| 1767 | } |
| 1768 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1769 | |
| 1770 | bool IsFromInlinedInvoke() const { |
| 1771 | return GetParent() != nullptr; |
| 1772 | } |
| 1773 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1774 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1775 | // Record instructions' use entries of this environment for constant-time removal. |
| 1776 | // It should only be called by HInstruction when a new environment use is added. |
| 1777 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1778 | DCHECK(env_use->GetUser() == this); |
| 1779 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1780 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1781 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1782 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1783 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1784 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1785 | HEnvironment* parent_; |
| 1786 | const DexFile& dex_file_; |
| 1787 | const uint32_t method_idx_; |
| 1788 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1789 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1790 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1791 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1792 | HInstruction* const holder_; |
| 1793 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1794 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1795 | |
| 1796 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1797 | }; |
| 1798 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1799 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1800 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1801 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1802 | : previous_(nullptr), |
| 1803 | next_(nullptr), |
| 1804 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1805 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1806 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1807 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1808 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1809 | locations_(nullptr), |
| 1810 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1811 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1812 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1813 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1814 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1815 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1816 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1817 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1818 | enum InstructionKind { |
| 1819 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1820 | }; |
| 1821 | #undef DECLARE_KIND |
| 1822 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1823 | HInstruction* GetNext() const { return next_; } |
| 1824 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1825 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1826 | HInstruction* GetNextDisregardingMoves() const; |
| 1827 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1828 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1829 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1830 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1831 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1832 | bool IsInBlock() const { return block_ != nullptr; } |
| 1833 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1834 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1835 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1836 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1837 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1838 | |
| 1839 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1840 | virtual const char* DebugName() const = 0; |
| 1841 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1842 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1843 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1844 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1845 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1846 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1847 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1848 | |
| 1849 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1850 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1851 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1852 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1853 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1854 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1855 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1856 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1857 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1858 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1859 | // Does not apply for all instructions, but having this at top level greatly |
| 1860 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1861 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1862 | virtual bool CanBeNull() const { |
| 1863 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1864 | return true; |
| 1865 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1866 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1867 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1868 | return false; |
| 1869 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1870 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1871 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1872 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1873 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1874 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1875 | return reference_type_info_; |
| 1876 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1877 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1878 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1879 | DCHECK(user != nullptr); |
| 1880 | HUseListNode<HInstruction*>* use = |
| 1881 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1882 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1883 | } |
| 1884 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1885 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1886 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1887 | HUseListNode<HEnvironment*>* env_use = |
| 1888 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1889 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1890 | } |
| 1891 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1892 | void RemoveAsUserOfInput(size_t input) { |
| 1893 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1894 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1895 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1896 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1897 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1898 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1899 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1900 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1901 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1902 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1903 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1904 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1905 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1906 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1907 | // Does this instruction strictly dominate `other_instruction`? |
| 1908 | // Returns false if this instruction and `other_instruction` are the same. |
| 1909 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1910 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1911 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1912 | int GetId() const { return id_; } |
| 1913 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1914 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1915 | int GetSsaIndex() const { return ssa_index_; } |
| 1916 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1917 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1918 | |
| 1919 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1920 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1921 | // Set the `environment_` field. Raw because this method does not |
| 1922 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1923 | void SetRawEnvironment(HEnvironment* environment) { |
| 1924 | DCHECK(environment_ == nullptr); |
| 1925 | DCHECK_EQ(environment->GetHolder(), this); |
| 1926 | environment_ = environment; |
| 1927 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1928 | |
| 1929 | // Set the environment of this instruction, copying it from `environment`. While |
| 1930 | // copying, the uses lists are being updated. |
| 1931 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1932 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1933 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1934 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1935 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1936 | if (environment->GetParent() != nullptr) { |
| 1937 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1938 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1939 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1940 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1941 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1942 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1943 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1944 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1945 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1946 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1947 | if (environment->GetParent() != nullptr) { |
| 1948 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1949 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1952 | // Returns the number of entries in the environment. Typically, that is the |
| 1953 | // number of dex registers in a method. It could be more in case of inlining. |
| 1954 | size_t EnvironmentSize() const; |
| 1955 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1956 | LocationSummary* GetLocations() const { return locations_; } |
| 1957 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1958 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1959 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1960 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1961 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1962 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1963 | // uses of this instruction by `other` are *not* updated. |
| 1964 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1965 | ReplaceWith(other); |
| 1966 | other->ReplaceInput(this, use_index); |
| 1967 | } |
| 1968 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1969 | // Move `this` instruction before `cursor`. |
| 1970 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1971 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 1972 | // Move `this` before its first user and out of any loops. If there is no |
| 1973 | // out-of-loop user that dominates all other users, move the instruction |
| 1974 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 1975 | // |
| 1976 | // This can be used only on non-throwing instructions with no side effects that |
| 1977 | // have at least one use but no environment uses. |
| 1978 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 1979 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1980 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1981 | bool Is##type() const; \ |
| 1982 | const H##type* As##type() const; \ |
| 1983 | H##type* As##type(); |
| 1984 | |
| 1985 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1986 | #undef INSTRUCTION_TYPE_CHECK |
| 1987 | |
| 1988 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1989 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1990 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1991 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1992 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1993 | #undef INSTRUCTION_TYPE_CHECK |
| 1994 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1995 | // Returns whether the instruction can be moved within the graph. |
| 1996 | virtual bool CanBeMoved() const { return false; } |
| 1997 | |
| 1998 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1999 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2000 | return false; |
| 2001 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2002 | |
| 2003 | // Returns whether any data encoded in the two instructions is equal. |
| 2004 | // This method does not look at the inputs. Both instructions must be |
| 2005 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2006 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2007 | return false; |
| 2008 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2009 | |
| 2010 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2011 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2012 | // 2) Their inputs are identical. |
| 2013 | bool Equals(HInstruction* other) const; |
| 2014 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2015 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2016 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2017 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2018 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2019 | InstructionKind GetKind() const PURE; |
| 2020 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2021 | |
| 2022 | virtual size_t ComputeHashCode() const { |
| 2023 | size_t result = GetKind(); |
| 2024 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2025 | result = (result * 31) + InputAt(i)->GetId(); |
| 2026 | } |
| 2027 | return result; |
| 2028 | } |
| 2029 | |
| 2030 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2031 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2032 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2033 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2034 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2035 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2036 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2037 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2038 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2039 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2040 | |
| 2041 | // Returns whether the code generation of the instruction will require to have access |
| 2042 | // to the current method. Such instructions are: |
| 2043 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2044 | // to walk the stack and have the current method stored at a specific stack address. |
| 2045 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2046 | // fields of the current method. |
| 2047 | bool NeedsCurrentMethod() const { |
| 2048 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2049 | } |
| 2050 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2051 | // Returns whether the code generation of the instruction will require to have access |
| 2052 | // to the dex cache of the current method's declaring class via the current method. |
| 2053 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2054 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2055 | // Does this instruction have any use in an environment before |
| 2056 | // control flow hits 'other'? |
| 2057 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2058 | |
| 2059 | // Remove all references to environment uses of this instruction. |
| 2060 | // The caller must ensure that this is safe to do. |
| 2061 | void RemoveEnvironmentUsers(); |
| 2062 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2063 | protected: |
| 2064 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2065 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 2066 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2067 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2068 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2069 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2070 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2071 | HInstruction* previous_; |
| 2072 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2073 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2074 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2075 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2076 | // An instruction gets an id when it is added to the graph. |
| 2077 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2078 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2079 | int id_; |
| 2080 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2081 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2082 | int ssa_index_; |
| 2083 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2084 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2085 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2086 | |
| 2087 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2088 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2089 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2090 | // The environment associated with this instruction. Not null if the instruction |
| 2091 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2092 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2093 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2094 | // Set by the code generator. |
| 2095 | LocationSummary* locations_; |
| 2096 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2097 | // Set by the liveness analysis. |
| 2098 | LiveInterval* live_interval_; |
| 2099 | |
| 2100 | // Set by the liveness analysis, this is the position in a linear |
| 2101 | // order of blocks where this instruction's live interval start. |
| 2102 | size_t lifetime_position_; |
| 2103 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2104 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2105 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2106 | // TODO: for primitive types this should be marked as invalid. |
| 2107 | ReferenceTypeInfo reference_type_info_; |
| 2108 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2109 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2110 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2111 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2112 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2113 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2114 | |
| 2115 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2116 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2117 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2118 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2119 | class HInputIterator : public ValueObject { |
| 2120 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2121 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2122 | |
| 2123 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2124 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2125 | void Advance() { index_++; } |
| 2126 | |
| 2127 | private: |
| 2128 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2129 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2130 | |
| 2131 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2132 | }; |
| 2133 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2134 | class HInstructionIterator : public ValueObject { |
| 2135 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2136 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2137 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2138 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2141 | bool Done() const { return instruction_ == nullptr; } |
| 2142 | HInstruction* Current() const { return instruction_; } |
| 2143 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2144 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2145 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2146 | } |
| 2147 | |
| 2148 | private: |
| 2149 | HInstruction* instruction_; |
| 2150 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2151 | |
| 2152 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2153 | }; |
| 2154 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2155 | class HBackwardInstructionIterator : public ValueObject { |
| 2156 | public: |
| 2157 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2158 | : instruction_(instructions.last_instruction_) { |
| 2159 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2160 | } |
| 2161 | |
| 2162 | bool Done() const { return instruction_ == nullptr; } |
| 2163 | HInstruction* Current() const { return instruction_; } |
| 2164 | void Advance() { |
| 2165 | instruction_ = next_; |
| 2166 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2167 | } |
| 2168 | |
| 2169 | private: |
| 2170 | HInstruction* instruction_; |
| 2171 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2172 | |
| 2173 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2174 | }; |
| 2175 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2176 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2177 | class HTemplateInstruction: public HInstruction { |
| 2178 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2179 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2180 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2181 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2182 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2183 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2184 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2185 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2186 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2187 | DCHECK_LT(i, N); |
| 2188 | return inputs_[i]; |
| 2189 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2190 | |
| 2191 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2192 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2193 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2194 | } |
| 2195 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2196 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2197 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2198 | |
| 2199 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2200 | }; |
| 2201 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2202 | // HTemplateInstruction specialization for N=0. |
| 2203 | template<> |
| 2204 | class HTemplateInstruction<0>: public HInstruction { |
| 2205 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2206 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2207 | : HInstruction(side_effects, dex_pc) {} |
| 2208 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2209 | virtual ~HTemplateInstruction() {} |
| 2210 | |
| 2211 | size_t InputCount() const OVERRIDE { return 0; } |
| 2212 | |
| 2213 | protected: |
| 2214 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2215 | LOG(FATAL) << "Unreachable"; |
| 2216 | UNREACHABLE(); |
| 2217 | } |
| 2218 | |
| 2219 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2220 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2221 | LOG(FATAL) << "Unreachable"; |
| 2222 | UNREACHABLE(); |
| 2223 | } |
| 2224 | |
| 2225 | private: |
| 2226 | friend class SsaBuilder; |
| 2227 | }; |
| 2228 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2229 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2230 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2231 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2232 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2233 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2234 | virtual ~HExpression() {} |
| 2235 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2236 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2237 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2238 | protected: |
| 2239 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2240 | }; |
| 2241 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2242 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2243 | // instruction that branches to the exit block. |
| 2244 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2245 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2246 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2247 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2248 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2249 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2250 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2251 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2252 | |
| 2253 | private: |
| 2254 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2255 | }; |
| 2256 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2257 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2258 | // instruction that branches to the exit block. |
| 2259 | class HReturn : public HTemplateInstruction<1> { |
| 2260 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2261 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2262 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2263 | SetRawInputAt(0, value); |
| 2264 | } |
| 2265 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2266 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2267 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2268 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2269 | |
| 2270 | private: |
| 2271 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2272 | }; |
| 2273 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2274 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2275 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2276 | // exit block. |
| 2277 | class HExit : public HTemplateInstruction<0> { |
| 2278 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2279 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2280 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2281 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2282 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2283 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2284 | |
| 2285 | private: |
| 2286 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2287 | }; |
| 2288 | |
| 2289 | // Jumps from one block to another. |
| 2290 | class HGoto : public HTemplateInstruction<0> { |
| 2291 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2292 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2293 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2294 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2295 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2296 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2297 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2300 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2301 | |
| 2302 | private: |
| 2303 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2304 | }; |
| 2305 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2306 | class HConstant : public HExpression<0> { |
| 2307 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2308 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2309 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2310 | |
| 2311 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2312 | |
| 2313 | virtual bool IsMinusOne() const { return false; } |
| 2314 | virtual bool IsZero() const { return false; } |
| 2315 | virtual bool IsOne() const { return false; } |
| 2316 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2317 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2318 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2319 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2320 | |
| 2321 | private: |
| 2322 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2323 | }; |
| 2324 | |
| 2325 | class HNullConstant : public HConstant { |
| 2326 | public: |
| 2327 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2328 | return true; |
| 2329 | } |
| 2330 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2331 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2332 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2333 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2334 | |
| 2335 | DECLARE_INSTRUCTION(NullConstant); |
| 2336 | |
| 2337 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2338 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2339 | |
| 2340 | friend class HGraph; |
| 2341 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2342 | }; |
| 2343 | |
| 2344 | // Constants of the type int. Those can be from Dex instructions, or |
| 2345 | // synthesized (for example with the if-eqz instruction). |
| 2346 | class HIntConstant : public HConstant { |
| 2347 | public: |
| 2348 | int32_t GetValue() const { return value_; } |
| 2349 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2350 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2351 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2352 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2353 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2354 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2355 | DCHECK(other->IsIntConstant()); |
| 2356 | return other->AsIntConstant()->value_ == value_; |
| 2357 | } |
| 2358 | |
| 2359 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2360 | |
| 2361 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2362 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2363 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2364 | |
| 2365 | DECLARE_INSTRUCTION(IntConstant); |
| 2366 | |
| 2367 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2368 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2369 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2370 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2371 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2372 | |
| 2373 | const int32_t value_; |
| 2374 | |
| 2375 | friend class HGraph; |
| 2376 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2377 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2378 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2379 | }; |
| 2380 | |
| 2381 | class HLongConstant : public HConstant { |
| 2382 | public: |
| 2383 | int64_t GetValue() const { return value_; } |
| 2384 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2385 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2386 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2387 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2388 | DCHECK(other->IsLongConstant()); |
| 2389 | return other->AsLongConstant()->value_ == value_; |
| 2390 | } |
| 2391 | |
| 2392 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2393 | |
| 2394 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2395 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2396 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2397 | |
| 2398 | DECLARE_INSTRUCTION(LongConstant); |
| 2399 | |
| 2400 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2401 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2402 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2403 | |
| 2404 | const int64_t value_; |
| 2405 | |
| 2406 | friend class HGraph; |
| 2407 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2408 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2409 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2410 | // Conditional branch. A block ending with an HIf instruction must have |
| 2411 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2412 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2413 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2414 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2415 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2416 | SetRawInputAt(0, input); |
| 2417 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2418 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2419 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2420 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2421 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2422 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2426 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2427 | } |
| 2428 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2429 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2430 | |
| 2431 | private: |
| 2432 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2433 | }; |
| 2434 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2435 | |
| 2436 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2437 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2438 | // non-exceptional control flow. |
| 2439 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2440 | // higher indices in no particular order. |
| 2441 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2442 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2443 | enum BoundaryKind { |
| 2444 | kEntry, |
| 2445 | kExit, |
| 2446 | }; |
| 2447 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2448 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2449 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2450 | |
| 2451 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2452 | |
| 2453 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2454 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2455 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2456 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2457 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2458 | } |
| 2459 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2460 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2461 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2462 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2463 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2464 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
| 2467 | // If not present already, adds `handler` to its block's list of exception |
| 2468 | // handlers. |
| 2469 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2470 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2471 | GetBlock()->AddSuccessor(handler); |
| 2472 | } |
| 2473 | } |
| 2474 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2475 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2476 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2477 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2478 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2479 | DECLARE_INSTRUCTION(TryBoundary); |
| 2480 | |
| 2481 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2482 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2483 | |
| 2484 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2485 | }; |
| 2486 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2487 | // Deoptimize to interpreter, upon checking a condition. |
| 2488 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2489 | public: |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2490 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2491 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2492 | SetRawInputAt(0, cond); |
| 2493 | } |
| 2494 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2495 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2496 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2497 | return true; |
| 2498 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2499 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2500 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2501 | |
| 2502 | DECLARE_INSTRUCTION(Deoptimize); |
| 2503 | |
| 2504 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2505 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2506 | }; |
| 2507 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2508 | // Represents the ArtMethod that was passed as a first argument to |
| 2509 | // the method. It is used by instructions that depend on it, like |
| 2510 | // instructions that work with the dex cache. |
| 2511 | class HCurrentMethod : public HExpression<0> { |
| 2512 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2513 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2514 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2515 | |
| 2516 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2517 | |
| 2518 | private: |
| 2519 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2520 | }; |
| 2521 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2522 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2523 | // have one successor for each entry in the switch table, and the final successor |
| 2524 | // will be the block containing the next Dex opcode. |
| 2525 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2526 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2527 | HPackedSwitch(int32_t start_value, |
| 2528 | uint32_t num_entries, |
| 2529 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2530 | uint32_t dex_pc = kNoDexPc) |
| 2531 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2532 | start_value_(start_value), |
| 2533 | num_entries_(num_entries) { |
| 2534 | SetRawInputAt(0, input); |
| 2535 | } |
| 2536 | |
| 2537 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2538 | |
| 2539 | int32_t GetStartValue() const { return start_value_; } |
| 2540 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2541 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2542 | |
| 2543 | HBasicBlock* GetDefaultBlock() const { |
| 2544 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2545 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2546 | } |
| 2547 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2548 | |
| 2549 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2550 | const int32_t start_value_; |
| 2551 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2552 | |
| 2553 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2554 | }; |
| 2555 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2556 | class HUnaryOperation : public HExpression<1> { |
| 2557 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2558 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2559 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2560 | SetRawInputAt(0, input); |
| 2561 | } |
| 2562 | |
| 2563 | HInstruction* GetInput() const { return InputAt(0); } |
| 2564 | Primitive::Type GetResultType() const { return GetType(); } |
| 2565 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2566 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2567 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2568 | return true; |
| 2569 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2570 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2571 | // Try to statically evaluate `operation` and return a HConstant |
| 2572 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2573 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2574 | HConstant* TryStaticEvaluation() const; |
| 2575 | |
| 2576 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2577 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2578 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2579 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2580 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2581 | |
| 2582 | private: |
| 2583 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2584 | }; |
| 2585 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2586 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2587 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2588 | HBinaryOperation(Primitive::Type result_type, |
| 2589 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2590 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2591 | SideEffects side_effects = SideEffects::None(), |
| 2592 | uint32_t dex_pc = kNoDexPc) |
| 2593 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2594 | SetRawInputAt(0, left); |
| 2595 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2596 | } |
| 2597 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2598 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2599 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2600 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2601 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2602 | virtual bool IsCommutative() const { return false; } |
| 2603 | |
| 2604 | // Put constant on the right. |
| 2605 | // Returns whether order is changed. |
| 2606 | bool OrderInputsWithConstantOnTheRight() { |
| 2607 | HInstruction* left = InputAt(0); |
| 2608 | HInstruction* right = InputAt(1); |
| 2609 | if (left->IsConstant() && !right->IsConstant()) { |
| 2610 | ReplaceInput(right, 0); |
| 2611 | ReplaceInput(left, 1); |
| 2612 | return true; |
| 2613 | } |
| 2614 | return false; |
| 2615 | } |
| 2616 | |
| 2617 | // Order inputs by instruction id, but favor constant on the right side. |
| 2618 | // This helps GVN for commutative ops. |
| 2619 | void OrderInputs() { |
| 2620 | DCHECK(IsCommutative()); |
| 2621 | HInstruction* left = InputAt(0); |
| 2622 | HInstruction* right = InputAt(1); |
| 2623 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2624 | return; |
| 2625 | } |
| 2626 | if (OrderInputsWithConstantOnTheRight()) { |
| 2627 | return; |
| 2628 | } |
| 2629 | // Order according to instruction id. |
| 2630 | if (left->GetId() > right->GetId()) { |
| 2631 | ReplaceInput(right, 0); |
| 2632 | ReplaceInput(left, 1); |
| 2633 | } |
| 2634 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2635 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2636 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2637 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2638 | return true; |
| 2639 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2640 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2641 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2642 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2643 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2644 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2645 | |
| 2646 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2647 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2648 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2649 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2650 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2651 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2652 | return nullptr; |
| 2653 | } |
| 2654 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2655 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2656 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2657 | return nullptr; |
| 2658 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2659 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2660 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| 2661 | VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; |
| 2662 | return nullptr; |
| 2663 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2664 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2665 | // 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] | 2666 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2667 | HConstant* GetConstantRight() const; |
| 2668 | |
| 2669 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2670 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2671 | HInstruction* GetLeastConstantLeft() const; |
| 2672 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2673 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2674 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2675 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2676 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2677 | }; |
| 2678 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2679 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2680 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2681 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2682 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2683 | kGtBias, // return 1 for NaN comparisons |
| 2684 | kLtBias, // return -1 for NaN comparisons |
| 2685 | }; |
| 2686 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2687 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2688 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2689 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2690 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2691 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2692 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2693 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2694 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2695 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2696 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2697 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2698 | // `instruction`, and disregard moves in between. |
| 2699 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2700 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2701 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2702 | |
| 2703 | virtual IfCondition GetCondition() const = 0; |
| 2704 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2705 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2706 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2707 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2708 | |
| 2709 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2710 | |
| 2711 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2712 | return bias_ == other->AsCondition()->bias_; |
| 2713 | } |
| 2714 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2715 | bool IsFPConditionTrueIfNaN() const { |
| 2716 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2717 | IfCondition if_cond = GetCondition(); |
| 2718 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2719 | } |
| 2720 | |
| 2721 | bool IsFPConditionFalseIfNaN() const { |
| 2722 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2723 | IfCondition if_cond = GetCondition(); |
| 2724 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2725 | } |
| 2726 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2727 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2728 | // For register allocation purposes, returns whether this instruction needs to be |
| 2729 | // materialized (that is, not just be in the processor flags). |
| 2730 | bool needs_materialization_; |
| 2731 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2732 | // Needed if we merge a HCompare into a HCondition. |
| 2733 | ComparisonBias bias_; |
| 2734 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2735 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2736 | }; |
| 2737 | |
| 2738 | // Instruction to check if two inputs are equal to each other. |
| 2739 | class HEqual : public HCondition { |
| 2740 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2741 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2742 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2743 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2744 | bool IsCommutative() const OVERRIDE { return true; } |
| 2745 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2746 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2747 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2748 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2749 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2750 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2751 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2752 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2753 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2754 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2755 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2756 | return GetBlock()->GetGraph()->GetIntConstant(1); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2757 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2758 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2759 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2760 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2761 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2762 | return kCondEQ; |
| 2763 | } |
| 2764 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2765 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2766 | return kCondNE; |
| 2767 | } |
| 2768 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2769 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2770 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2771 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2772 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2773 | }; |
| 2774 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2775 | class HNotEqual : public HCondition { |
| 2776 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2777 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2778 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2779 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2780 | bool IsCommutative() const OVERRIDE { return true; } |
| 2781 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2782 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2783 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2784 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2785 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2786 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2787 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2788 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2789 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2790 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2791 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2792 | return GetBlock()->GetGraph()->GetIntConstant(0); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2793 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2794 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2795 | DECLARE_INSTRUCTION(NotEqual); |
| 2796 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2797 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2798 | return kCondNE; |
| 2799 | } |
| 2800 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2801 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2802 | return kCondEQ; |
| 2803 | } |
| 2804 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2805 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2806 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2807 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2808 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2809 | }; |
| 2810 | |
| 2811 | class HLessThan : public HCondition { |
| 2812 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2813 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2814 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2815 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2816 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2817 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2818 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2819 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2820 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2821 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2822 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2823 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2824 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2825 | DECLARE_INSTRUCTION(LessThan); |
| 2826 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2827 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2828 | return kCondLT; |
| 2829 | } |
| 2830 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2831 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2832 | return kCondGE; |
| 2833 | } |
| 2834 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2835 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2836 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2837 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2838 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2839 | }; |
| 2840 | |
| 2841 | class HLessThanOrEqual : public HCondition { |
| 2842 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2843 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2844 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2845 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2846 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2847 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2848 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2849 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2850 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2851 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2852 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2853 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2854 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2855 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2856 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2857 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2858 | return kCondLE; |
| 2859 | } |
| 2860 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2861 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2862 | return kCondGT; |
| 2863 | } |
| 2864 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2865 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2866 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2867 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2868 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2869 | }; |
| 2870 | |
| 2871 | class HGreaterThan : public HCondition { |
| 2872 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2873 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2874 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2875 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2876 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2877 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2878 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2879 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2880 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2881 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2882 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2883 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2884 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2885 | DECLARE_INSTRUCTION(GreaterThan); |
| 2886 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2887 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2888 | return kCondGT; |
| 2889 | } |
| 2890 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2891 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2892 | return kCondLE; |
| 2893 | } |
| 2894 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2895 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2896 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2897 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2898 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2899 | }; |
| 2900 | |
| 2901 | class HGreaterThanOrEqual : public HCondition { |
| 2902 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2903 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2904 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2905 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2906 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2907 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2908 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2909 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2910 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2911 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2912 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2913 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2914 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2915 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2916 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2917 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2918 | return kCondGE; |
| 2919 | } |
| 2920 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2921 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2922 | return kCondLT; |
| 2923 | } |
| 2924 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2925 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2926 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2927 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2928 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2929 | }; |
| 2930 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2931 | class HBelow : public HCondition { |
| 2932 | public: |
| 2933 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2934 | : HCondition(first, second, dex_pc) {} |
| 2935 | |
| 2936 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2937 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2938 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2939 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2940 | } |
| 2941 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2942 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2943 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2944 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2945 | } |
| 2946 | |
| 2947 | DECLARE_INSTRUCTION(Below); |
| 2948 | |
| 2949 | IfCondition GetCondition() const OVERRIDE { |
| 2950 | return kCondB; |
| 2951 | } |
| 2952 | |
| 2953 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2954 | return kCondAE; |
| 2955 | } |
| 2956 | |
| 2957 | private: |
| 2958 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2959 | |
| 2960 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 2961 | }; |
| 2962 | |
| 2963 | class HBelowOrEqual : public HCondition { |
| 2964 | public: |
| 2965 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2966 | : HCondition(first, second, dex_pc) {} |
| 2967 | |
| 2968 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2969 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2970 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2971 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2972 | } |
| 2973 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2974 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2975 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2976 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2977 | } |
| 2978 | |
| 2979 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 2980 | |
| 2981 | IfCondition GetCondition() const OVERRIDE { |
| 2982 | return kCondBE; |
| 2983 | } |
| 2984 | |
| 2985 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2986 | return kCondA; |
| 2987 | } |
| 2988 | |
| 2989 | private: |
| 2990 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2991 | |
| 2992 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 2993 | }; |
| 2994 | |
| 2995 | class HAbove : public HCondition { |
| 2996 | public: |
| 2997 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2998 | : HCondition(first, second, dex_pc) {} |
| 2999 | |
| 3000 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3001 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3002 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3003 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3004 | } |
| 3005 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3006 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3007 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3008 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3009 | } |
| 3010 | |
| 3011 | DECLARE_INSTRUCTION(Above); |
| 3012 | |
| 3013 | IfCondition GetCondition() const OVERRIDE { |
| 3014 | return kCondA; |
| 3015 | } |
| 3016 | |
| 3017 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3018 | return kCondBE; |
| 3019 | } |
| 3020 | |
| 3021 | private: |
| 3022 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3023 | |
| 3024 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3025 | }; |
| 3026 | |
| 3027 | class HAboveOrEqual : public HCondition { |
| 3028 | public: |
| 3029 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3030 | : HCondition(first, second, dex_pc) {} |
| 3031 | |
| 3032 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3033 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3034 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3035 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3036 | } |
| 3037 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3038 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3039 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3040 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3041 | } |
| 3042 | |
| 3043 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3044 | |
| 3045 | IfCondition GetCondition() const OVERRIDE { |
| 3046 | return kCondAE; |
| 3047 | } |
| 3048 | |
| 3049 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3050 | return kCondB; |
| 3051 | } |
| 3052 | |
| 3053 | private: |
| 3054 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3055 | |
| 3056 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3057 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3058 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3059 | // Instruction to check how two inputs compare to each other. |
| 3060 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3061 | class HCompare : public HBinaryOperation { |
| 3062 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3063 | HCompare(Primitive::Type type, |
| 3064 | HInstruction* first, |
| 3065 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3066 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3067 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3068 | : HBinaryOperation(Primitive::kPrimInt, |
| 3069 | first, |
| 3070 | second, |
| 3071 | SideEffectsForArchRuntimeCalls(type), |
| 3072 | dex_pc), |
| 3073 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3074 | DCHECK_EQ(type, first->GetType()); |
| 3075 | DCHECK_EQ(type, second->GetType()); |
| 3076 | } |
| 3077 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3078 | template <typename T> |
| 3079 | 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] | 3080 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3081 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3082 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3083 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3084 | } |
| 3085 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3086 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3087 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3088 | } |
| 3089 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3090 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3091 | return bias_ == other->AsCompare()->bias_; |
| 3092 | } |
| 3093 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3094 | ComparisonBias GetBias() const { return bias_; } |
| 3095 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3096 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3097 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3098 | |
| 3099 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3100 | // MIPS64 uses a runtime call for FP comparisons. |
| 3101 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3102 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3103 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3104 | DECLARE_INSTRUCTION(Compare); |
| 3105 | |
| 3106 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3107 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3108 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3109 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3110 | }; |
| 3111 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3112 | // A local in the graph. Corresponds to a Dex register. |
| 3113 | class HLocal : public HTemplateInstruction<0> { |
| 3114 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3115 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3116 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3117 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3118 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3119 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3120 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3121 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3122 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3123 | // The Dex register number. |
| 3124 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3125 | |
| 3126 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3127 | }; |
| 3128 | |
| 3129 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3130 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3131 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3132 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3133 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3134 | SetRawInputAt(0, local); |
| 3135 | } |
| 3136 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3137 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3138 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3139 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3140 | |
| 3141 | private: |
| 3142 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3143 | }; |
| 3144 | |
| 3145 | // Store a value in a given local. This instruction has two inputs: the value |
| 3146 | // and the local. |
| 3147 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3148 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3149 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3150 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3151 | SetRawInputAt(0, local); |
| 3152 | SetRawInputAt(1, value); |
| 3153 | } |
| 3154 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3155 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3156 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3157 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3158 | |
| 3159 | private: |
| 3160 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3161 | }; |
| 3162 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3163 | class HFloatConstant : public HConstant { |
| 3164 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3165 | float GetValue() const { return value_; } |
| 3166 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3167 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3168 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3169 | } |
| 3170 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3171 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3172 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3173 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3174 | } |
| 3175 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3176 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3177 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3178 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3179 | 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] | 3180 | } |
| 3181 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3182 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3183 | } |
| 3184 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3185 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3186 | } |
| 3187 | bool IsNaN() const { |
| 3188 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3191 | DECLARE_INSTRUCTION(FloatConstant); |
| 3192 | |
| 3193 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3194 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3195 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3196 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3197 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3198 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3199 | const float value_; |
| 3200 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3201 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3202 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3203 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3204 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3205 | }; |
| 3206 | |
| 3207 | class HDoubleConstant : public HConstant { |
| 3208 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3209 | double GetValue() const { return value_; } |
| 3210 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3211 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3212 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3213 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3214 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3215 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3216 | } |
| 3217 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3218 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3219 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3220 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3221 | 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] | 3222 | } |
| 3223 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3224 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3225 | } |
| 3226 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3227 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3228 | } |
| 3229 | bool IsNaN() const { |
| 3230 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3231 | } |
| 3232 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3233 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3234 | |
| 3235 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3236 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3237 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3238 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3239 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3240 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3241 | const double value_; |
| 3242 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3243 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3244 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3245 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3246 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3247 | }; |
| 3248 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3249 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3250 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3251 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3252 | #include "intrinsics_list.h" |
| 3253 | kNone, |
| 3254 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3255 | #undef INTRINSICS_LIST |
| 3256 | #undef OPTIMIZING_INTRINSICS |
| 3257 | }; |
| 3258 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3259 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3260 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3261 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3262 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3263 | }; |
| 3264 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3265 | enum IntrinsicSideEffects { |
| 3266 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3267 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3268 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3269 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3270 | }; |
| 3271 | |
| 3272 | enum IntrinsicExceptions { |
| 3273 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3274 | kCanThrow // Intrinsic may throw exceptions. |
| 3275 | }; |
| 3276 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3277 | class HInvoke : public HInstruction { |
| 3278 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3279 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3280 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3281 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3282 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3283 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3284 | SetRawInputAt(index, argument); |
| 3285 | } |
| 3286 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3287 | // Return the number of arguments. This number can be lower than |
| 3288 | // the number of inputs returned by InputCount(), as some invoke |
| 3289 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3290 | // inputs at the end of their list of inputs. |
| 3291 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3292 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3293 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3294 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3295 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3296 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3297 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3298 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3299 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3300 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3301 | return intrinsic_; |
| 3302 | } |
| 3303 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3304 | void SetIntrinsic(Intrinsics intrinsic, |
| 3305 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3306 | IntrinsicSideEffects side_effects, |
| 3307 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3308 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3309 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3310 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3311 | } |
| 3312 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3313 | bool CanThrow() const OVERRIDE { return can_throw_; } |
| 3314 | |
| 3315 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3316 | |
| 3317 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3318 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3319 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3320 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3321 | uint32_t* GetIntrinsicOptimizations() { |
| 3322 | return &intrinsic_optimizations_; |
| 3323 | } |
| 3324 | |
| 3325 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3326 | return &intrinsic_optimizations_; |
| 3327 | } |
| 3328 | |
| 3329 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3330 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3331 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3332 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3333 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3334 | HInvoke(ArenaAllocator* arena, |
| 3335 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3336 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3337 | Primitive::Type return_type, |
| 3338 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3339 | uint32_t dex_method_index, |
| 3340 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3341 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3342 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3343 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3344 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3345 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3346 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3347 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3348 | original_invoke_type_(original_invoke_type), |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3349 | can_throw_(true), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3350 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3351 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3352 | } |
| 3353 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3354 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3355 | return inputs_[index]; |
| 3356 | } |
| 3357 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3358 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3359 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3362 | void SetCanThrow(bool can_throw) { can_throw_ = can_throw; } |
| 3363 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3364 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3365 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3366 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3367 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3368 | const InvokeType original_invoke_type_; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3369 | bool can_throw_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3370 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3371 | |
| 3372 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3373 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3374 | |
| 3375 | private: |
| 3376 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3377 | }; |
| 3378 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3379 | class HInvokeUnresolved : public HInvoke { |
| 3380 | public: |
| 3381 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3382 | uint32_t number_of_arguments, |
| 3383 | Primitive::Type return_type, |
| 3384 | uint32_t dex_pc, |
| 3385 | uint32_t dex_method_index, |
| 3386 | InvokeType invoke_type) |
| 3387 | : HInvoke(arena, |
| 3388 | number_of_arguments, |
| 3389 | 0u /* number_of_other_inputs */, |
| 3390 | return_type, |
| 3391 | dex_pc, |
| 3392 | dex_method_index, |
| 3393 | invoke_type) { |
| 3394 | } |
| 3395 | |
| 3396 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3397 | |
| 3398 | private: |
| 3399 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3400 | }; |
| 3401 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3402 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3403 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3404 | // Requirements of this method call regarding the class |
| 3405 | // initialization (clinit) check of its declaring class. |
| 3406 | enum class ClinitCheckRequirement { |
| 3407 | kNone, // Class already initialized. |
| 3408 | kExplicit, // Static call having explicit clinit check as last input. |
| 3409 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3410 | }; |
| 3411 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3412 | // Determines how to load the target ArtMethod*. |
| 3413 | enum class MethodLoadKind { |
| 3414 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3415 | kStringInit, |
| 3416 | |
| 3417 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3418 | kRecursive, |
| 3419 | |
| 3420 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3421 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3422 | kDirectAddress, |
| 3423 | |
| 3424 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3425 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3426 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3427 | // the image relocatable or not. |
| 3428 | kDirectAddressWithFixup, |
| 3429 | |
| 3430 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3431 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3432 | // may cause class initialization (the entry may point to a resolution method), |
| 3433 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3434 | kDexCachePcRelative, |
| 3435 | |
| 3436 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3437 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3438 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3439 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3440 | kDexCacheViaMethod, |
| 3441 | }; |
| 3442 | |
| 3443 | // Determines the location of the code pointer. |
| 3444 | enum class CodePtrLocation { |
| 3445 | // Recursive call, use local PC-relative call instruction. |
| 3446 | kCallSelf, |
| 3447 | |
| 3448 | // Use PC-relative call instruction patched at link time. |
| 3449 | // Used for calls within an oat file, boot->boot or app->app. |
| 3450 | kCallPCRelative, |
| 3451 | |
| 3452 | // Call to a known target address, embed the direct address in code. |
| 3453 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3454 | kCallDirect, |
| 3455 | |
| 3456 | // Call to a target address that will be known at link time, embed the direct |
| 3457 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3458 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3459 | // the image relocatable or not. |
| 3460 | kCallDirectWithFixup, |
| 3461 | |
| 3462 | // Use code pointer from the ArtMethod*. |
| 3463 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3464 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3465 | kCallArtMethod, |
| 3466 | }; |
| 3467 | |
| 3468 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3469 | MethodLoadKind method_load_kind; |
| 3470 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3471 | // The method load data holds |
| 3472 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3473 | // Note that there are multiple string init methods, each having its own offset. |
| 3474 | // - the method address for kDirectAddress |
| 3475 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3476 | uint64_t method_load_data; |
| 3477 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3478 | }; |
| 3479 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3480 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3481 | uint32_t number_of_arguments, |
| 3482 | Primitive::Type return_type, |
| 3483 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3484 | uint32_t method_index, |
| 3485 | MethodReference target_method, |
| 3486 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3487 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3488 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3489 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3490 | : HInvoke(arena, |
| 3491 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3492 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3493 | // potentially one other if the clinit check is explicit, and potentially |
| 3494 | // one other if the method is a string factory. |
| 3495 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3496 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3497 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3498 | return_type, |
| 3499 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3500 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3501 | original_invoke_type), |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3502 | optimized_invoke_type_(optimized_invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3503 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3504 | target_method_(target_method), |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3505 | dispatch_info_(dispatch_info) { } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3506 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3507 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3508 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3509 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3510 | |
| 3511 | // Using the current method is the default and once we find a better |
| 3512 | // method load kind, we should not go back to using the current method. |
| 3513 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3514 | |
| 3515 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3516 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3517 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3518 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3519 | dispatch_info_ = dispatch_info; |
| 3520 | } |
| 3521 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3522 | void AddSpecialInput(HInstruction* input) { |
| 3523 | // We allow only one special input. |
| 3524 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3525 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3526 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3527 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3528 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3529 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3530 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3531 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3532 | // TODO: for intrinsics we can generate implicit null checks. |
| 3533 | return false; |
| 3534 | } |
| 3535 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3536 | bool CanBeNull() const OVERRIDE { |
| 3537 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3538 | } |
| 3539 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3540 | // Get the index of the special input, if any. |
| 3541 | // |
| 3542 | // If the invoke IsStringInit(), it initially has a HFakeString special argument |
| 3543 | // which is removed by the instruction simplifier; if the invoke HasCurrentMethodInput(), |
| 3544 | // the "special input" is the current method pointer; otherwise there may be one |
| 3545 | // platform-specific special input, such as PC-relative addressing base. |
| 3546 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
| 3547 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3548 | InvokeType GetOptimizedInvokeType() const { return optimized_invoke_type_; } |
| 3549 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
| 3550 | optimized_invoke_type_ = invoke_type; |
| 3551 | } |
| 3552 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3553 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3554 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3555 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3556 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3557 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3558 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3559 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3560 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3561 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3562 | bool HasCurrentMethodInput() const { |
| 3563 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3564 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3565 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3566 | return true; |
| 3567 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3568 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3569 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3570 | return false; |
| 3571 | } |
| 3572 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3573 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3574 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3575 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3576 | |
| 3577 | int32_t GetStringInitOffset() const { |
| 3578 | DCHECK(IsStringInit()); |
| 3579 | return dispatch_info_.method_load_data; |
| 3580 | } |
| 3581 | |
| 3582 | uint64_t GetMethodAddress() const { |
| 3583 | DCHECK(HasMethodAddress()); |
| 3584 | return dispatch_info_.method_load_data; |
| 3585 | } |
| 3586 | |
| 3587 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3588 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3589 | return dispatch_info_.method_load_data; |
| 3590 | } |
| 3591 | |
| 3592 | uint64_t GetDirectCodePtr() const { |
| 3593 | DCHECK(HasDirectCodePtr()); |
| 3594 | return dispatch_info_.direct_code_ptr; |
| 3595 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3596 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3597 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3598 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3599 | // Is this instruction a call to a static method? |
| 3600 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3601 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3602 | } |
| 3603 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3604 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3605 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3606 | // instruction; only relevant for static calls with explicit clinit check. |
| 3607 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3608 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3609 | size_t last_input_index = InputCount() - 1; |
| 3610 | HInstruction* last_input = InputAt(last_input_index); |
| 3611 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3612 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3613 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3614 | inputs_.pop_back(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3615 | clinit_check_requirement_ = new_requirement; |
| 3616 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3617 | } |
| 3618 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3619 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3620 | if (!IsStringInit()) return false; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3621 | DCHECK(!HasCurrentMethodInput()); |
| 3622 | if (InputCount() == (number_of_arguments_)) return false; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3623 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3624 | } |
| 3625 | |
| 3626 | void RemoveFakeStringArgumentAsLastInput() { |
| 3627 | DCHECK(IsStringInit()); |
| 3628 | size_t last_input_index = InputCount() - 1; |
| 3629 | HInstruction* last_input = InputAt(last_input_index); |
| 3630 | DCHECK(last_input != nullptr); |
| 3631 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3632 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3633 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3634 | } |
| 3635 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3636 | // 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] | 3637 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3638 | bool IsStaticWithExplicitClinitCheck() const { |
| 3639 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3640 | } |
| 3641 | |
| 3642 | // Is this a call to a static method whose declaring class has an |
| 3643 | // implicit intialization check requirement? |
| 3644 | bool IsStaticWithImplicitClinitCheck() const { |
| 3645 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3646 | } |
| 3647 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3648 | // Does this method load kind need the current method as an input? |
| 3649 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 3650 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 3651 | } |
| 3652 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3653 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3654 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3655 | protected: |
| 3656 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3657 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3658 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3659 | HInstruction* input = input_record.GetInstruction(); |
| 3660 | // `input` is the last input of a static invoke marked as having |
| 3661 | // an explicit clinit check. It must either be: |
| 3662 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3663 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3664 | DCHECK(input != nullptr); |
| 3665 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3666 | } |
| 3667 | return input_record; |
| 3668 | } |
| 3669 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3670 | void InsertInputAt(size_t index, HInstruction* input); |
| 3671 | void RemoveInputAt(size_t index); |
| 3672 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3673 | private: |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3674 | InvokeType optimized_invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3675 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3676 | // The target method may refer to different dex file or method index than the original |
| 3677 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3678 | // in derived class to increase visibility. |
| 3679 | MethodReference target_method_; |
| 3680 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3681 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3682 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3683 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 3684 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3685 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3686 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3687 | class HInvokeVirtual : public HInvoke { |
| 3688 | public: |
| 3689 | HInvokeVirtual(ArenaAllocator* arena, |
| 3690 | uint32_t number_of_arguments, |
| 3691 | Primitive::Type return_type, |
| 3692 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3693 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3694 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3695 | : 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] | 3696 | vtable_index_(vtable_index) {} |
| 3697 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3698 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3699 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3700 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3701 | } |
| 3702 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3703 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3704 | |
| 3705 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3706 | |
| 3707 | private: |
| 3708 | const uint32_t vtable_index_; |
| 3709 | |
| 3710 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3711 | }; |
| 3712 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3713 | class HInvokeInterface : public HInvoke { |
| 3714 | public: |
| 3715 | HInvokeInterface(ArenaAllocator* arena, |
| 3716 | uint32_t number_of_arguments, |
| 3717 | Primitive::Type return_type, |
| 3718 | uint32_t dex_pc, |
| 3719 | uint32_t dex_method_index, |
| 3720 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3721 | : 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] | 3722 | imt_index_(imt_index) {} |
| 3723 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3724 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3725 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3726 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3727 | } |
| 3728 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3729 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3730 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3731 | |
| 3732 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3733 | |
| 3734 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3735 | const uint32_t imt_index_; |
| 3736 | |
| 3737 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3738 | }; |
| 3739 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3740 | class HNewInstance : public HExpression<2> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3741 | public: |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3742 | HNewInstance(HInstruction* cls, |
| 3743 | HCurrentMethod* current_method, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3744 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3745 | uint16_t type_index, |
| 3746 | const DexFile& dex_file, |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3747 | bool can_throw, |
| 3748 | bool finalizable, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3749 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3750 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3751 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3752 | dex_file_(dex_file), |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3753 | can_throw_(can_throw), |
| 3754 | finalizable_(finalizable), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3755 | entrypoint_(entrypoint) { |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3756 | SetRawInputAt(0, cls); |
| 3757 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3758 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3759 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3760 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3761 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3762 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3763 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3764 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3765 | |
| 3766 | // It may throw when called on type that's not instantiable/accessible. |
| 3767 | // It can throw OOME. |
| 3768 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
| 3769 | bool CanThrow() const OVERRIDE { return can_throw_ || true; } |
| 3770 | |
| 3771 | bool IsFinalizable() const { return finalizable_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3772 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3773 | bool CanBeNull() const OVERRIDE { return false; } |
| 3774 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3775 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3776 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3777 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3778 | entrypoint_ = entrypoint; |
| 3779 | } |
| 3780 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3781 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3782 | |
| 3783 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3784 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3785 | const DexFile& dex_file_; |
Mingyao Yang | fb8464a | 2015-11-02 10:56:59 -0800 | [diff] [blame] | 3786 | const bool can_throw_; |
| 3787 | const bool finalizable_; |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 3788 | QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3789 | |
| 3790 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3791 | }; |
| 3792 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3793 | class HNeg : public HUnaryOperation { |
| 3794 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3795 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3796 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3797 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3798 | template <typename T> T Compute(T x) const { return -x; } |
| 3799 | |
| 3800 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3801 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3802 | } |
| 3803 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3804 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3805 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3806 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3807 | DECLARE_INSTRUCTION(Neg); |
| 3808 | |
| 3809 | private: |
| 3810 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3811 | }; |
| 3812 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3813 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3814 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3815 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3816 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3817 | uint32_t dex_pc, |
| 3818 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3819 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3820 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3821 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3822 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3823 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3824 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3825 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3826 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3827 | } |
| 3828 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3829 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3830 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3831 | |
| 3832 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3833 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3834 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3835 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3836 | bool CanThrow() const OVERRIDE { return true; } |
| 3837 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3838 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3839 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3840 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3841 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3842 | DECLARE_INSTRUCTION(NewArray); |
| 3843 | |
| 3844 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3845 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3846 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3847 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3848 | |
| 3849 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3850 | }; |
| 3851 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3852 | class HAdd : public HBinaryOperation { |
| 3853 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3854 | HAdd(Primitive::Type result_type, |
| 3855 | HInstruction* left, |
| 3856 | HInstruction* right, |
| 3857 | uint32_t dex_pc = kNoDexPc) |
| 3858 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3859 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3860 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3861 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3862 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3863 | |
| 3864 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3865 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3866 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3867 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3868 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3869 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3870 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3871 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3872 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3873 | DECLARE_INSTRUCTION(Add); |
| 3874 | |
| 3875 | private: |
| 3876 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3877 | }; |
| 3878 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3879 | class HSub : public HBinaryOperation { |
| 3880 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3881 | HSub(Primitive::Type result_type, |
| 3882 | HInstruction* left, |
| 3883 | HInstruction* right, |
| 3884 | uint32_t dex_pc = kNoDexPc) |
| 3885 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3886 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3887 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3888 | |
| 3889 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3890 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3891 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3892 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3893 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3894 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3895 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3896 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3897 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3898 | DECLARE_INSTRUCTION(Sub); |
| 3899 | |
| 3900 | private: |
| 3901 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3902 | }; |
| 3903 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3904 | class HMul : public HBinaryOperation { |
| 3905 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3906 | HMul(Primitive::Type result_type, |
| 3907 | HInstruction* left, |
| 3908 | HInstruction* right, |
| 3909 | uint32_t dex_pc = kNoDexPc) |
| 3910 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3911 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3912 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3913 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3914 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3915 | |
| 3916 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3917 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3918 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3919 | } |
| 3920 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3921 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3922 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3923 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3924 | |
| 3925 | DECLARE_INSTRUCTION(Mul); |
| 3926 | |
| 3927 | private: |
| 3928 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3929 | }; |
| 3930 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3931 | class HDiv : public HBinaryOperation { |
| 3932 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3933 | HDiv(Primitive::Type result_type, |
| 3934 | HInstruction* left, |
| 3935 | HInstruction* right, |
| 3936 | uint32_t dex_pc) |
| 3937 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3938 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3939 | template <typename T> |
| 3940 | T Compute(T x, T y) const { |
| 3941 | // Our graph structure ensures we never have 0 for `y` during |
| 3942 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3943 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3944 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3945 | return (y == -1) ? -x : x / y; |
| 3946 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3947 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3948 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3949 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3950 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3951 | } |
| 3952 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3953 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3954 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3955 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3956 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3957 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3958 | // The generated code can use a runtime call. |
| 3959 | return SideEffects::CanTriggerGC(); |
| 3960 | } |
| 3961 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3962 | DECLARE_INSTRUCTION(Div); |
| 3963 | |
| 3964 | private: |
| 3965 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3966 | }; |
| 3967 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3968 | class HRem : public HBinaryOperation { |
| 3969 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3970 | HRem(Primitive::Type result_type, |
| 3971 | HInstruction* left, |
| 3972 | HInstruction* right, |
| 3973 | uint32_t dex_pc) |
| 3974 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3975 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3976 | template <typename T> |
| 3977 | T Compute(T x, T y) const { |
| 3978 | // Our graph structure ensures we never have 0 for `y` during |
| 3979 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3980 | DCHECK_NE(y, 0); |
| 3981 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3982 | return (y == -1) ? 0 : x % y; |
| 3983 | } |
| 3984 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3985 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3986 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3987 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3988 | } |
| 3989 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3990 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3991 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3992 | } |
| 3993 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3994 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3995 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3996 | return SideEffects::CanTriggerGC(); |
| 3997 | } |
| 3998 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3999 | DECLARE_INSTRUCTION(Rem); |
| 4000 | |
| 4001 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4002 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4003 | }; |
| 4004 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4005 | class HDivZeroCheck : public HExpression<1> { |
| 4006 | public: |
| 4007 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4008 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4009 | SetRawInputAt(0, value); |
| 4010 | } |
| 4011 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4012 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4013 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4014 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4015 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4016 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4017 | return true; |
| 4018 | } |
| 4019 | |
| 4020 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4021 | bool CanThrow() const OVERRIDE { return true; } |
| 4022 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4023 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4024 | |
| 4025 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4026 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4027 | }; |
| 4028 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4029 | class HShl : public HBinaryOperation { |
| 4030 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4031 | HShl(Primitive::Type result_type, |
| 4032 | HInstruction* left, |
| 4033 | HInstruction* right, |
| 4034 | uint32_t dex_pc = kNoDexPc) |
| 4035 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4036 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4037 | template <typename T, typename U, typename V> |
| 4038 | T Compute(T x, U y, V max_shift_value) const { |
| 4039 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4040 | "V is not the unsigned integer type corresponding to T"); |
| 4041 | return x << (y & max_shift_value); |
| 4042 | } |
| 4043 | |
| 4044 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4045 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4046 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4047 | } |
| 4048 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4049 | // case is handled as `x << static_cast<int>(y)`. |
| 4050 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4051 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4052 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4053 | } |
| 4054 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4055 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4056 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4057 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4058 | |
| 4059 | DECLARE_INSTRUCTION(Shl); |
| 4060 | |
| 4061 | private: |
| 4062 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4063 | }; |
| 4064 | |
| 4065 | class HShr : public HBinaryOperation { |
| 4066 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4067 | HShr(Primitive::Type result_type, |
| 4068 | HInstruction* left, |
| 4069 | HInstruction* right, |
| 4070 | uint32_t dex_pc = kNoDexPc) |
| 4071 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4072 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4073 | template <typename T, typename U, typename V> |
| 4074 | T Compute(T x, U y, V max_shift_value) const { |
| 4075 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4076 | "V is not the unsigned integer type corresponding to T"); |
| 4077 | return x >> (y & max_shift_value); |
| 4078 | } |
| 4079 | |
| 4080 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4081 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4082 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4083 | } |
| 4084 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4085 | // case is handled as `x >> static_cast<int>(y)`. |
| 4086 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4087 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4088 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4089 | } |
| 4090 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4091 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4092 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4093 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4094 | |
| 4095 | DECLARE_INSTRUCTION(Shr); |
| 4096 | |
| 4097 | private: |
| 4098 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4099 | }; |
| 4100 | |
| 4101 | class HUShr : public HBinaryOperation { |
| 4102 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4103 | HUShr(Primitive::Type result_type, |
| 4104 | HInstruction* left, |
| 4105 | HInstruction* right, |
| 4106 | uint32_t dex_pc = kNoDexPc) |
| 4107 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4108 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4109 | template <typename T, typename U, typename V> |
| 4110 | T Compute(T x, U y, V max_shift_value) const { |
| 4111 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4112 | "V is not the unsigned integer type corresponding to T"); |
| 4113 | V ux = static_cast<V>(x); |
| 4114 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4115 | } |
| 4116 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4117 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4118 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4119 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4120 | } |
| 4121 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4122 | // case is handled as `x >>> static_cast<int>(y)`. |
| 4123 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4124 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4125 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4126 | } |
| 4127 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4128 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4129 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4130 | } |
| 4131 | |
| 4132 | DECLARE_INSTRUCTION(UShr); |
| 4133 | |
| 4134 | private: |
| 4135 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4136 | }; |
| 4137 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4138 | class HAnd : public HBinaryOperation { |
| 4139 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4140 | HAnd(Primitive::Type result_type, |
| 4141 | HInstruction* left, |
| 4142 | HInstruction* right, |
| 4143 | uint32_t dex_pc = kNoDexPc) |
| 4144 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4145 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4146 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4147 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4148 | template <typename T, typename U> |
| 4149 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 4150 | |
| 4151 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4152 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4153 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4154 | } |
| 4155 | HConstant* Evaluate(HIntConstant* 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 | } |
| 4159 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4160 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4161 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4162 | } |
| 4163 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4164 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4165 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4166 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4167 | |
| 4168 | DECLARE_INSTRUCTION(And); |
| 4169 | |
| 4170 | private: |
| 4171 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4172 | }; |
| 4173 | |
| 4174 | class HOr : public HBinaryOperation { |
| 4175 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4176 | HOr(Primitive::Type result_type, |
| 4177 | HInstruction* left, |
| 4178 | HInstruction* right, |
| 4179 | uint32_t dex_pc = kNoDexPc) |
| 4180 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4181 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4182 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4183 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4184 | template <typename T, typename U> |
| 4185 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4186 | |
| 4187 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4188 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4189 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4190 | } |
| 4191 | HConstant* Evaluate(HIntConstant* 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 | } |
| 4195 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4196 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4197 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4198 | } |
| 4199 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4200 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4201 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4202 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4203 | |
| 4204 | DECLARE_INSTRUCTION(Or); |
| 4205 | |
| 4206 | private: |
| 4207 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4208 | }; |
| 4209 | |
| 4210 | class HXor : public HBinaryOperation { |
| 4211 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4212 | HXor(Primitive::Type result_type, |
| 4213 | HInstruction* left, |
| 4214 | HInstruction* right, |
| 4215 | uint32_t dex_pc = kNoDexPc) |
| 4216 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4217 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4218 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4219 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4220 | template <typename T, typename U> |
| 4221 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4222 | |
| 4223 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4224 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4225 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4226 | } |
| 4227 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4228 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4229 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4230 | } |
| 4231 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4232 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4233 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4234 | } |
| 4235 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4236 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4237 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4238 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4239 | |
| 4240 | DECLARE_INSTRUCTION(Xor); |
| 4241 | |
| 4242 | private: |
| 4243 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4244 | }; |
| 4245 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4246 | class HRor : public HBinaryOperation { |
| 4247 | public: |
| 4248 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
| 4249 | : HBinaryOperation(result_type, value, distance) {} |
| 4250 | |
| 4251 | template <typename T, typename U, typename V> |
| 4252 | T Compute(T x, U y, V max_shift_value) const { |
| 4253 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4254 | "V is not the unsigned integer type corresponding to T"); |
| 4255 | V ux = static_cast<V>(x); |
| 4256 | if ((y & max_shift_value) == 0) { |
| 4257 | return static_cast<T>(ux); |
| 4258 | } else { |
| 4259 | const V reg_bits = sizeof(T) * 8; |
| 4260 | return static_cast<T>(ux >> (y & max_shift_value)) | |
| 4261 | (x << (reg_bits - (y & max_shift_value))); |
| 4262 | } |
| 4263 | } |
| 4264 | |
| 4265 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4266 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4267 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
| 4268 | } |
| 4269 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4270 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4271 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4272 | } |
| 4273 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4274 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4275 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4276 | } |
| 4277 | |
| 4278 | DECLARE_INSTRUCTION(Ror); |
| 4279 | |
| 4280 | private: |
| 4281 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4282 | }; |
| 4283 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4284 | // The value of a parameter in this method. Its location depends on |
| 4285 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4286 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4287 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4288 | HParameterValue(const DexFile& dex_file, |
| 4289 | uint16_t type_index, |
| 4290 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4291 | Primitive::Type parameter_type, |
| 4292 | bool is_this = false) |
| 4293 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4294 | dex_file_(dex_file), |
| 4295 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4296 | index_(index), |
| 4297 | is_this_(is_this), |
| 4298 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4299 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4300 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4301 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4302 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4303 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4304 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4305 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4306 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4307 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4308 | DECLARE_INSTRUCTION(ParameterValue); |
| 4309 | |
| 4310 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4311 | const DexFile& dex_file_; |
| 4312 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4313 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4314 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4315 | const uint8_t index_; |
| 4316 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4317 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4318 | const bool is_this_; |
| 4319 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4320 | bool can_be_null_; |
| 4321 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4322 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4323 | }; |
| 4324 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4325 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4326 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4327 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4328 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4329 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4330 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4331 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4332 | return true; |
| 4333 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4334 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4335 | template <typename T> T Compute(T x) const { return ~x; } |
| 4336 | |
| 4337 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4338 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4339 | } |
| 4340 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4341 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4342 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4343 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4344 | DECLARE_INSTRUCTION(Not); |
| 4345 | |
| 4346 | private: |
| 4347 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4348 | }; |
| 4349 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4350 | class HBooleanNot : public HUnaryOperation { |
| 4351 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4352 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4353 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4354 | |
| 4355 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4356 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4357 | return true; |
| 4358 | } |
| 4359 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4360 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4361 | DCHECK(IsUint<1>(x)); |
| 4362 | return !x; |
| 4363 | } |
| 4364 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4365 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4366 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4367 | } |
| 4368 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4369 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4370 | UNREACHABLE(); |
| 4371 | } |
| 4372 | |
| 4373 | DECLARE_INSTRUCTION(BooleanNot); |
| 4374 | |
| 4375 | private: |
| 4376 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4377 | }; |
| 4378 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4379 | class HTypeConversion : public HExpression<1> { |
| 4380 | public: |
| 4381 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4382 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4383 | : HExpression(result_type, |
| 4384 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4385 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4386 | SetRawInputAt(0, input); |
| 4387 | DCHECK_NE(input->GetType(), result_type); |
| 4388 | } |
| 4389 | |
| 4390 | HInstruction* GetInput() const { return InputAt(0); } |
| 4391 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4392 | Primitive::Type GetResultType() const { return GetType(); } |
| 4393 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4394 | // 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] | 4395 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4396 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4397 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4398 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4399 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4400 | // Try to statically evaluate the conversion and return a HConstant |
| 4401 | // containing the result. If the input cannot be converted, return nullptr. |
| 4402 | HConstant* TryStaticEvaluation() const; |
| 4403 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4404 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4405 | Primitive::Type result_type) { |
| 4406 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4407 | // in the compilation process we do not know what architecture we will |
| 4408 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4409 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4410 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4411 | return SideEffects::CanTriggerGC(); |
| 4412 | } |
| 4413 | return SideEffects::None(); |
| 4414 | } |
| 4415 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4416 | DECLARE_INSTRUCTION(TypeConversion); |
| 4417 | |
| 4418 | private: |
| 4419 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4420 | }; |
| 4421 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4422 | static constexpr uint32_t kNoRegNumber = -1; |
| 4423 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4424 | class HPhi : public HInstruction { |
| 4425 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4426 | HPhi(ArenaAllocator* arena, |
| 4427 | uint32_t reg_number, |
| 4428 | size_t number_of_inputs, |
| 4429 | Primitive::Type type, |
| 4430 | uint32_t dex_pc = kNoDexPc) |
| 4431 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4432 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4433 | reg_number_(reg_number), |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4434 | type_(ToPhiType(type)), |
| 4435 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4436 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4437 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4438 | is_live_(true), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4439 | can_be_null_(true) { |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4440 | DCHECK_NE(type_, Primitive::kPrimVoid); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4441 | } |
| 4442 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4443 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4444 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4445 | switch (type) { |
| 4446 | case Primitive::kPrimBoolean: |
| 4447 | case Primitive::kPrimByte: |
| 4448 | case Primitive::kPrimShort: |
| 4449 | case Primitive::kPrimChar: |
| 4450 | return Primitive::kPrimInt; |
| 4451 | default: |
| 4452 | return type; |
| 4453 | } |
| 4454 | } |
| 4455 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4456 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4457 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4458 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4459 | |
| 4460 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4461 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4462 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4463 | Primitive::Type GetType() const OVERRIDE { return type_; } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4464 | void SetType(Primitive::Type new_type) { |
| 4465 | // Make sure that only valid type changes occur. The following are allowed: |
| 4466 | // (1) int -> float/ref (primitive type propagation), |
| 4467 | // (2) long -> double (primitive type propagation). |
| 4468 | DCHECK(type_ == new_type || |
| 4469 | (type_ == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 4470 | (type_ == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 4471 | (type_ == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 4472 | type_ = new_type; |
| 4473 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4474 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4475 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4476 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4477 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4478 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4479 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4480 | void SetDead() { is_live_ = false; } |
| 4481 | void SetLive() { is_live_ = true; } |
| 4482 | bool IsDead() const { return !is_live_; } |
| 4483 | bool IsLive() const { return is_live_; } |
| 4484 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4485 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4486 | return other != nullptr |
| 4487 | && other->IsPhi() |
| 4488 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4489 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4490 | } |
| 4491 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4492 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4493 | // An equivalent phi is a phi having the same dex register and type. |
| 4494 | // It assumes that phis with the same dex register are adjacent. |
| 4495 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4496 | HInstruction* next = GetNext(); |
| 4497 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4498 | if (next->GetType() == GetType()) { |
| 4499 | return next->AsPhi(); |
| 4500 | } |
| 4501 | next = next->GetNext(); |
| 4502 | } |
| 4503 | return nullptr; |
| 4504 | } |
| 4505 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4506 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4507 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4508 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4509 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4510 | return inputs_[index]; |
| 4511 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4512 | |
| 4513 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4514 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4515 | } |
| 4516 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4517 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4518 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4519 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4520 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4521 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4522 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4523 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4524 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4525 | }; |
| 4526 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4527 | class HNullCheck : public HExpression<1> { |
| 4528 | public: |
| 4529 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4530 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4531 | SetRawInputAt(0, value); |
| 4532 | } |
| 4533 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4534 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4535 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4536 | return true; |
| 4537 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4538 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4539 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4540 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4541 | bool CanThrow() const OVERRIDE { return true; } |
| 4542 | |
| 4543 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4544 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4545 | |
| 4546 | DECLARE_INSTRUCTION(NullCheck); |
| 4547 | |
| 4548 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4549 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4550 | }; |
| 4551 | |
| 4552 | class FieldInfo : public ValueObject { |
| 4553 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4554 | FieldInfo(MemberOffset field_offset, |
| 4555 | Primitive::Type field_type, |
| 4556 | bool is_volatile, |
| 4557 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4558 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4559 | const DexFile& dex_file, |
| 4560 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4561 | : field_offset_(field_offset), |
| 4562 | field_type_(field_type), |
| 4563 | is_volatile_(is_volatile), |
| 4564 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4565 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4566 | dex_file_(dex_file), |
| 4567 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4568 | |
| 4569 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4570 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4571 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4572 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4573 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4574 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4575 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4576 | |
| 4577 | private: |
| 4578 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4579 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4580 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4581 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4582 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4583 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4584 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4585 | }; |
| 4586 | |
| 4587 | class HInstanceFieldGet : public HExpression<1> { |
| 4588 | public: |
| 4589 | HInstanceFieldGet(HInstruction* value, |
| 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 | : HExpression(field_type, |
| 4599 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4600 | dex_pc), |
| 4601 | field_info_(field_offset, |
| 4602 | field_type, |
| 4603 | is_volatile, |
| 4604 | field_idx, |
| 4605 | declaring_class_def_index, |
| 4606 | dex_file, |
| 4607 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4608 | SetRawInputAt(0, value); |
| 4609 | } |
| 4610 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4611 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4612 | |
| 4613 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4614 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4615 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4616 | } |
| 4617 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4618 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4619 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4620 | } |
| 4621 | |
| 4622 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4623 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4624 | } |
| 4625 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4626 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4627 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4628 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4629 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4630 | |
| 4631 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4632 | |
| 4633 | private: |
| 4634 | const FieldInfo field_info_; |
| 4635 | |
| 4636 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4637 | }; |
| 4638 | |
| 4639 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4640 | public: |
| 4641 | HInstanceFieldSet(HInstruction* object, |
| 4642 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4643 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4644 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4645 | bool is_volatile, |
| 4646 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4647 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4648 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4649 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4650 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4651 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4652 | dex_pc), |
| 4653 | field_info_(field_offset, |
| 4654 | field_type, |
| 4655 | is_volatile, |
| 4656 | field_idx, |
| 4657 | declaring_class_def_index, |
| 4658 | dex_file, |
| 4659 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4660 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4661 | SetRawInputAt(0, object); |
| 4662 | SetRawInputAt(1, value); |
| 4663 | } |
| 4664 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4665 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4666 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4667 | } |
| 4668 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4669 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4670 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4671 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4672 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4673 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4674 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4675 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4676 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4677 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4678 | |
| 4679 | private: |
| 4680 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4681 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4682 | |
| 4683 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4684 | }; |
| 4685 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4686 | class HArrayGet : public HExpression<2> { |
| 4687 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4688 | HArrayGet(HInstruction* array, |
| 4689 | HInstruction* index, |
| 4690 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4691 | uint32_t dex_pc, |
| 4692 | SideEffects additional_side_effects = SideEffects::None()) |
| 4693 | : HExpression(type, |
| 4694 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4695 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4696 | SetRawInputAt(0, array); |
| 4697 | SetRawInputAt(1, index); |
| 4698 | } |
| 4699 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4700 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4701 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4702 | return true; |
| 4703 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4704 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4705 | // TODO: We can be smarter here. |
| 4706 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4707 | // which generates the implicit null check. There are cases when these can be removed |
| 4708 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4709 | // implicit check here (as long as the address falls in the first page). |
| 4710 | return false; |
| 4711 | } |
| 4712 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4713 | bool IsEquivalentOf(HArrayGet* other) const { |
| 4714 | bool result = (GetDexPc() == other->GetDexPc()); |
| 4715 | if (kIsDebugBuild && result) { |
| 4716 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 4717 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 4718 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 4719 | if (Primitive::IsIntOrLongType(GetType())) { |
| 4720 | DCHECK(Primitive::IsFloatingPointType(other->GetType())); |
| 4721 | } else { |
| 4722 | DCHECK(Primitive::IsFloatingPointType(GetType())); |
| 4723 | DCHECK(Primitive::IsIntOrLongType(other->GetType())); |
| 4724 | } |
| 4725 | } |
| 4726 | return result; |
| 4727 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4728 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4729 | HInstruction* GetArray() const { return InputAt(0); } |
| 4730 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4731 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4732 | DECLARE_INSTRUCTION(ArrayGet); |
| 4733 | |
| 4734 | private: |
| 4735 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4736 | }; |
| 4737 | |
| 4738 | class HArraySet : public HTemplateInstruction<3> { |
| 4739 | public: |
| 4740 | HArraySet(HInstruction* array, |
| 4741 | HInstruction* index, |
| 4742 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4743 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4744 | uint32_t dex_pc, |
| 4745 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4746 | : HTemplateInstruction( |
| 4747 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4748 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4749 | additional_side_effects), |
| 4750 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4751 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4752 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4753 | value_can_be_null_(true), |
| 4754 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4755 | SetRawInputAt(0, array); |
| 4756 | SetRawInputAt(1, index); |
| 4757 | SetRawInputAt(2, value); |
| 4758 | } |
| 4759 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4760 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4761 | // We currently always call a runtime method to catch array store |
| 4762 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4763 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4764 | } |
| 4765 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4766 | // Can throw ArrayStoreException. |
| 4767 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4768 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4769 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4770 | // TODO: Same as for ArrayGet. |
| 4771 | return false; |
| 4772 | } |
| 4773 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4774 | void ClearNeedsTypeCheck() { |
| 4775 | needs_type_check_ = false; |
| 4776 | } |
| 4777 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4778 | void ClearValueCanBeNull() { |
| 4779 | value_can_be_null_ = false; |
| 4780 | } |
| 4781 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4782 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4783 | static_type_of_array_is_object_array_ = true; |
| 4784 | } |
| 4785 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4786 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4787 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4788 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4789 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4790 | HInstruction* GetArray() const { return InputAt(0); } |
| 4791 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4792 | HInstruction* GetValue() const { return InputAt(2); } |
| 4793 | |
| 4794 | Primitive::Type GetComponentType() const { |
| 4795 | // The Dex format does not type floating point index operations. Since the |
| 4796 | // `expected_component_type_` is set during building and can therefore not |
| 4797 | // be correct, we also check what is the value type. If it is a floating |
| 4798 | // point type, we must use that type. |
| 4799 | Primitive::Type value_type = GetValue()->GetType(); |
| 4800 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4801 | ? value_type |
| 4802 | : expected_component_type_; |
| 4803 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4804 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4805 | Primitive::Type GetRawExpectedComponentType() const { |
| 4806 | return expected_component_type_; |
| 4807 | } |
| 4808 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4809 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4810 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4811 | } |
| 4812 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4813 | DECLARE_INSTRUCTION(ArraySet); |
| 4814 | |
| 4815 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4816 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4817 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4818 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4819 | // Cached information for the reference_type_info_ so that codegen |
| 4820 | // does not need to inspect the static type. |
| 4821 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4822 | |
| 4823 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4824 | }; |
| 4825 | |
| 4826 | class HArrayLength : public HExpression<1> { |
| 4827 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4828 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4829 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4830 | // Note that arrays do not change length, so the instruction does not |
| 4831 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4832 | SetRawInputAt(0, array); |
| 4833 | } |
| 4834 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4835 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4836 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4837 | return true; |
| 4838 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4839 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4840 | return obj == InputAt(0); |
| 4841 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4842 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4843 | DECLARE_INSTRUCTION(ArrayLength); |
| 4844 | |
| 4845 | private: |
| 4846 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4847 | }; |
| 4848 | |
| 4849 | class HBoundsCheck : public HExpression<2> { |
| 4850 | public: |
| 4851 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4852 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4853 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4854 | SetRawInputAt(0, index); |
| 4855 | SetRawInputAt(1, length); |
| 4856 | } |
| 4857 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4858 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4859 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4860 | return true; |
| 4861 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4862 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4863 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4864 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4865 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4866 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4867 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4868 | |
| 4869 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4870 | |
| 4871 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4872 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4873 | }; |
| 4874 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4875 | /** |
| 4876 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4877 | * to stay live until the last HInstruction. This class |
| 4878 | * 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] | 4879 | * HInstruction stays live. `index` represents the stack location index of the |
| 4880 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4881 | */ |
| 4882 | class HTemporary : public HTemplateInstruction<0> { |
| 4883 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4884 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4885 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4886 | |
| 4887 | size_t GetIndex() const { return index_; } |
| 4888 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4889 | Primitive::Type GetType() const OVERRIDE { |
| 4890 | // The previous instruction is the one that will be stored in the temporary location. |
| 4891 | DCHECK(GetPrevious() != nullptr); |
| 4892 | return GetPrevious()->GetType(); |
| 4893 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4894 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4895 | DECLARE_INSTRUCTION(Temporary); |
| 4896 | |
| 4897 | private: |
| 4898 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4899 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4900 | }; |
| 4901 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4902 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4903 | public: |
| 4904 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4905 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4906 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4907 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4908 | return true; |
| 4909 | } |
| 4910 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4911 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4912 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4913 | |
| 4914 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4915 | |
| 4916 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4917 | // Only used for code generation, in order to share the same slow path between back edges |
| 4918 | // of a same loop. |
| 4919 | SlowPathCode* slow_path_; |
| 4920 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4921 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4922 | }; |
| 4923 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4924 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 4925 | // It ensures that we can generate line number and local variables at this point. |
| 4926 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 4927 | public: |
| 4928 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 4929 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 4930 | |
| 4931 | bool NeedsEnvironment() const OVERRIDE { |
| 4932 | return true; |
| 4933 | } |
| 4934 | |
| 4935 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 4936 | |
| 4937 | private: |
| 4938 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 4939 | }; |
| 4940 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4941 | /** |
| 4942 | * Instruction to load a Class object. |
| 4943 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4944 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4945 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4946 | HLoadClass(HCurrentMethod* current_method, |
| 4947 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4948 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4949 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4950 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4951 | bool needs_access_check, |
| 4952 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4953 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4954 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4955 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4956 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4957 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4958 | needs_access_check_(needs_access_check), |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4959 | is_in_dex_cache_(is_in_dex_cache), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4960 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4961 | // Referrers class should not need access check. We never inline unverified |
| 4962 | // methods so we can't possibly end up in this situation. |
| 4963 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4964 | SetRawInputAt(0, current_method); |
| 4965 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4966 | |
| 4967 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4968 | |
| 4969 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 4970 | // Note that we don't need to test for generate_clinit_check_. |
| 4971 | // Whether or not we need to generate the clinit check is processed in |
| 4972 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4973 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 4974 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4978 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4979 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4980 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4981 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4982 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4983 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4984 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4985 | } |
| 4986 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4987 | bool MustGenerateClinitCheck() const { |
| 4988 | return generate_clinit_check_; |
| 4989 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4990 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4991 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 4992 | // The entrypoint the code generator is going to call does not do |
| 4993 | // clinit of the class. |
| 4994 | DCHECK(!NeedsAccessCheck()); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4995 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4999 | return MustGenerateClinitCheck() || |
| 5000 | (!is_referrers_class_ && !is_in_dex_cache_) || |
| 5001 | needs_access_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5002 | } |
| 5003 | |
| 5004 | bool NeedsAccessCheck() const { |
| 5005 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5006 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5007 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5008 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5009 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5010 | } |
| 5011 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5012 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5013 | return loaded_class_rti_; |
| 5014 | } |
| 5015 | |
| 5016 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5017 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5018 | DCHECK(rti.IsExact()); |
| 5019 | loaded_class_rti_ = rti; |
| 5020 | } |
| 5021 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5022 | const DexFile& GetDexFile() { return dex_file_; } |
| 5023 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5024 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5025 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5026 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5027 | return SideEffects::CanTriggerGC(); |
| 5028 | } |
| 5029 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5030 | bool IsInDexCache() const { return is_in_dex_cache_; } |
| 5031 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5032 | DECLARE_INSTRUCTION(LoadClass); |
| 5033 | |
| 5034 | private: |
| 5035 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5036 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5037 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5038 | // Whether this instruction must generate the initialization check. |
| 5039 | // Used for code generation. |
| 5040 | bool generate_clinit_check_; |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5041 | const bool needs_access_check_; |
| 5042 | const bool is_in_dex_cache_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5043 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5044 | ReferenceTypeInfo loaded_class_rti_; |
| 5045 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5046 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5047 | }; |
| 5048 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5049 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5050 | public: |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5051 | HLoadString(HCurrentMethod* current_method, |
| 5052 | uint32_t string_index, |
| 5053 | uint32_t dex_pc, |
| 5054 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5055 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5056 | string_index_(string_index), |
| 5057 | is_in_dex_cache_(is_in_dex_cache) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5058 | SetRawInputAt(0, current_method); |
| 5059 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5060 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5061 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5062 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5063 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5064 | return other->AsLoadString()->string_index_ == string_index_; |
| 5065 | } |
| 5066 | |
| 5067 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5068 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5069 | uint32_t GetStringIndex() const { return string_index_; } |
| 5070 | |
| 5071 | // TODO: Can we deopt or debug when we resolve a string? |
| 5072 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5073 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5074 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5075 | bool IsInDexCache() const { return is_in_dex_cache_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5076 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5077 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5078 | return SideEffects::CanTriggerGC(); |
| 5079 | } |
| 5080 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5081 | DECLARE_INSTRUCTION(LoadString); |
| 5082 | |
| 5083 | private: |
| 5084 | const uint32_t string_index_; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5085 | const bool is_in_dex_cache_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5086 | |
| 5087 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5088 | }; |
| 5089 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5090 | /** |
| 5091 | * Performs an initialization check on its Class object input. |
| 5092 | */ |
| 5093 | class HClinitCheck : public HExpression<1> { |
| 5094 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5095 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5096 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5097 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5098 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5099 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5100 | SetRawInputAt(0, constant); |
| 5101 | } |
| 5102 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5103 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5104 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5105 | return true; |
| 5106 | } |
| 5107 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5108 | bool NeedsEnvironment() const OVERRIDE { |
| 5109 | // May call runtime to initialize the class. |
| 5110 | return true; |
| 5111 | } |
| 5112 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5113 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5114 | |
| 5115 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5116 | |
| 5117 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5118 | |
| 5119 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5120 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5121 | }; |
| 5122 | |
| 5123 | class HStaticFieldGet : public HExpression<1> { |
| 5124 | public: |
| 5125 | HStaticFieldGet(HInstruction* cls, |
| 5126 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5127 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5128 | bool is_volatile, |
| 5129 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5130 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5131 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5132 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5133 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5134 | : HExpression(field_type, |
| 5135 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5136 | dex_pc), |
| 5137 | field_info_(field_offset, |
| 5138 | field_type, |
| 5139 | is_volatile, |
| 5140 | field_idx, |
| 5141 | declaring_class_def_index, |
| 5142 | dex_file, |
| 5143 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5144 | SetRawInputAt(0, cls); |
| 5145 | } |
| 5146 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5147 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5148 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5149 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5150 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5151 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5152 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5153 | } |
| 5154 | |
| 5155 | size_t ComputeHashCode() const OVERRIDE { |
| 5156 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5157 | } |
| 5158 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5159 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5160 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5161 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5162 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5163 | |
| 5164 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5165 | |
| 5166 | private: |
| 5167 | const FieldInfo field_info_; |
| 5168 | |
| 5169 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5170 | }; |
| 5171 | |
| 5172 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5173 | public: |
| 5174 | HStaticFieldSet(HInstruction* cls, |
| 5175 | HInstruction* value, |
| 5176 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5177 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5178 | bool is_volatile, |
| 5179 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5180 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5181 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5182 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5183 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5184 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5185 | dex_pc), |
| 5186 | field_info_(field_offset, |
| 5187 | field_type, |
| 5188 | is_volatile, |
| 5189 | field_idx, |
| 5190 | declaring_class_def_index, |
| 5191 | dex_file, |
| 5192 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5193 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5194 | SetRawInputAt(0, cls); |
| 5195 | SetRawInputAt(1, value); |
| 5196 | } |
| 5197 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5198 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5199 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5200 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5201 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5202 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5203 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5204 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 5205 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5206 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5207 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5208 | |
| 5209 | private: |
| 5210 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5211 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5212 | |
| 5213 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5214 | }; |
| 5215 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5216 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5217 | public: |
| 5218 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5219 | Primitive::Type field_type, |
| 5220 | uint32_t field_index, |
| 5221 | uint32_t dex_pc) |
| 5222 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5223 | field_index_(field_index) { |
| 5224 | SetRawInputAt(0, obj); |
| 5225 | } |
| 5226 | |
| 5227 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5228 | bool CanThrow() const OVERRIDE { return true; } |
| 5229 | |
| 5230 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5231 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5232 | |
| 5233 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5234 | |
| 5235 | private: |
| 5236 | const uint32_t field_index_; |
| 5237 | |
| 5238 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5239 | }; |
| 5240 | |
| 5241 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5242 | public: |
| 5243 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5244 | HInstruction* value, |
| 5245 | Primitive::Type field_type, |
| 5246 | uint32_t field_index, |
| 5247 | uint32_t dex_pc) |
| 5248 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5249 | field_type_(field_type), |
| 5250 | field_index_(field_index) { |
| 5251 | DCHECK_EQ(field_type, value->GetType()); |
| 5252 | SetRawInputAt(0, obj); |
| 5253 | SetRawInputAt(1, value); |
| 5254 | } |
| 5255 | |
| 5256 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5257 | bool CanThrow() const OVERRIDE { return true; } |
| 5258 | |
| 5259 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5260 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5261 | |
| 5262 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5263 | |
| 5264 | private: |
| 5265 | const Primitive::Type field_type_; |
| 5266 | const uint32_t field_index_; |
| 5267 | |
| 5268 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5269 | }; |
| 5270 | |
| 5271 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5272 | public: |
| 5273 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5274 | uint32_t field_index, |
| 5275 | uint32_t dex_pc) |
| 5276 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5277 | field_index_(field_index) { |
| 5278 | } |
| 5279 | |
| 5280 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5281 | bool CanThrow() const OVERRIDE { return true; } |
| 5282 | |
| 5283 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5284 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5285 | |
| 5286 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5287 | |
| 5288 | private: |
| 5289 | const uint32_t field_index_; |
| 5290 | |
| 5291 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5292 | }; |
| 5293 | |
| 5294 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5295 | public: |
| 5296 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5297 | Primitive::Type field_type, |
| 5298 | uint32_t field_index, |
| 5299 | uint32_t dex_pc) |
| 5300 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5301 | field_type_(field_type), |
| 5302 | field_index_(field_index) { |
| 5303 | DCHECK_EQ(field_type, value->GetType()); |
| 5304 | SetRawInputAt(0, value); |
| 5305 | } |
| 5306 | |
| 5307 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5308 | bool CanThrow() const OVERRIDE { return true; } |
| 5309 | |
| 5310 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5311 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5312 | |
| 5313 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5314 | |
| 5315 | private: |
| 5316 | const Primitive::Type field_type_; |
| 5317 | const uint32_t field_index_; |
| 5318 | |
| 5319 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5320 | }; |
| 5321 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5322 | // Implement the move-exception DEX instruction. |
| 5323 | class HLoadException : public HExpression<0> { |
| 5324 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5325 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5326 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5327 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5328 | bool CanBeNull() const OVERRIDE { return false; } |
| 5329 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5330 | DECLARE_INSTRUCTION(LoadException); |
| 5331 | |
| 5332 | private: |
| 5333 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5334 | }; |
| 5335 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5336 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5337 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5338 | class HClearException : public HTemplateInstruction<0> { |
| 5339 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5340 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5341 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5342 | |
| 5343 | DECLARE_INSTRUCTION(ClearException); |
| 5344 | |
| 5345 | private: |
| 5346 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5347 | }; |
| 5348 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5349 | class HThrow : public HTemplateInstruction<1> { |
| 5350 | public: |
| 5351 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5352 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5353 | SetRawInputAt(0, exception); |
| 5354 | } |
| 5355 | |
| 5356 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5357 | |
| 5358 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5359 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5360 | bool CanThrow() const OVERRIDE { return true; } |
| 5361 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5362 | |
| 5363 | DECLARE_INSTRUCTION(Throw); |
| 5364 | |
| 5365 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5366 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5367 | }; |
| 5368 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5369 | /** |
| 5370 | * Implementation strategies for the code generator of a HInstanceOf |
| 5371 | * or `HCheckCast`. |
| 5372 | */ |
| 5373 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5374 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5375 | kExactCheck, // Can do a single class compare. |
| 5376 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5377 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5378 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5379 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5380 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5381 | }; |
| 5382 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5383 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5384 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5385 | HInstanceOf(HInstruction* object, |
| 5386 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5387 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5388 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5389 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5390 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5391 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5392 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5393 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5394 | SetRawInputAt(0, object); |
| 5395 | SetRawInputAt(1, constant); |
| 5396 | } |
| 5397 | |
| 5398 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5399 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5400 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5401 | return true; |
| 5402 | } |
| 5403 | |
| 5404 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5405 | return false; |
| 5406 | } |
| 5407 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5408 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5409 | |
| 5410 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5411 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5412 | // Used only in code generation. |
| 5413 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5414 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5415 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5416 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 5417 | return (check_kind == TypeCheckKind::kExactCheck) |
| 5418 | ? SideEffects::None() |
| 5419 | // Mips currently does runtime calls for any other checks. |
| 5420 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5421 | } |
| 5422 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5423 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5424 | |
| 5425 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5426 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5427 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5428 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5429 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5430 | }; |
| 5431 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5432 | class HBoundType : public HExpression<1> { |
| 5433 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5434 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5435 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5436 | upper_bound_(ReferenceTypeInfo::CreateInvalid()), |
| 5437 | upper_can_be_null_(true), |
| 5438 | can_be_null_(true) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5439 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5440 | SetRawInputAt(0, input); |
| 5441 | } |
| 5442 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5443 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5444 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5445 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5446 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5447 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5448 | void SetCanBeNull(bool can_be_null) { |
| 5449 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5450 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5451 | } |
| 5452 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5453 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5454 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5455 | DECLARE_INSTRUCTION(BoundType); |
| 5456 | |
| 5457 | private: |
| 5458 | // 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] | 5459 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5460 | // It is used to bound the type in cases like: |
| 5461 | // if (x instanceof ClassX) { |
| 5462 | // // uper_bound_ will be ClassX |
| 5463 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5464 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5465 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5466 | // is false then can_be_null_ cannot be true). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5467 | bool upper_can_be_null_; |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5468 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5469 | |
| 5470 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5471 | }; |
| 5472 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5473 | class HCheckCast : public HTemplateInstruction<2> { |
| 5474 | public: |
| 5475 | HCheckCast(HInstruction* object, |
| 5476 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5477 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5478 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5479 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5480 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5481 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5482 | SetRawInputAt(0, object); |
| 5483 | SetRawInputAt(1, constant); |
| 5484 | } |
| 5485 | |
| 5486 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5487 | |
| 5488 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5489 | return true; |
| 5490 | } |
| 5491 | |
| 5492 | bool NeedsEnvironment() const OVERRIDE { |
| 5493 | // Instruction may throw a CheckCastError. |
| 5494 | return true; |
| 5495 | } |
| 5496 | |
| 5497 | bool CanThrow() const OVERRIDE { return true; } |
| 5498 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5499 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5500 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5501 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5502 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5503 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5504 | |
| 5505 | DECLARE_INSTRUCTION(CheckCast); |
| 5506 | |
| 5507 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5508 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5509 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5510 | |
| 5511 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5512 | }; |
| 5513 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5514 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5515 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5516 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5517 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5518 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5519 | barrier_kind_(barrier_kind) {} |
| 5520 | |
| 5521 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5522 | |
| 5523 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5524 | |
| 5525 | private: |
| 5526 | const MemBarrierKind barrier_kind_; |
| 5527 | |
| 5528 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5529 | }; |
| 5530 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5531 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5532 | public: |
| 5533 | enum OperationKind { |
| 5534 | kEnter, |
| 5535 | kExit, |
| 5536 | }; |
| 5537 | |
| 5538 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5539 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5540 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5541 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5542 | SetRawInputAt(0, object); |
| 5543 | } |
| 5544 | |
| 5545 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5546 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5547 | |
| 5548 | bool CanThrow() const OVERRIDE { |
| 5549 | // Verifier guarantees that monitor-exit cannot throw. |
| 5550 | // This is important because it allows the HGraphBuilder to remove |
| 5551 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5552 | return IsEnter(); |
| 5553 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5554 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5555 | |
| 5556 | bool IsEnter() const { return kind_ == kEnter; } |
| 5557 | |
| 5558 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5559 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5560 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5561 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5562 | |
| 5563 | private: |
| 5564 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5565 | }; |
| 5566 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5567 | /** |
| 5568 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5569 | * of a String to a call to a StringFactory. Only baseline will see |
| 5570 | * the node at code generation, where it will be be treated as null. |
| 5571 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5572 | * in the instruction simplifier. |
| 5573 | */ |
| 5574 | class HFakeString : public HTemplateInstruction<0> { |
| 5575 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5576 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5577 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5578 | |
| 5579 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5580 | |
| 5581 | DECLARE_INSTRUCTION(FakeString); |
| 5582 | |
| 5583 | private: |
| 5584 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5585 | }; |
| 5586 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5587 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5588 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5589 | MoveOperands(Location source, |
| 5590 | Location destination, |
| 5591 | Primitive::Type type, |
| 5592 | HInstruction* instruction) |
| 5593 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5594 | |
| 5595 | Location GetSource() const { return source_; } |
| 5596 | Location GetDestination() const { return destination_; } |
| 5597 | |
| 5598 | void SetSource(Location value) { source_ = value; } |
| 5599 | void SetDestination(Location value) { destination_ = value; } |
| 5600 | |
| 5601 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5602 | // destination (but not the source). |
| 5603 | Location MarkPending() { |
| 5604 | DCHECK(!IsPending()); |
| 5605 | Location dest = destination_; |
| 5606 | destination_ = Location::NoLocation(); |
| 5607 | return dest; |
| 5608 | } |
| 5609 | |
| 5610 | void ClearPending(Location dest) { |
| 5611 | DCHECK(IsPending()); |
| 5612 | destination_ = dest; |
| 5613 | } |
| 5614 | |
| 5615 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5616 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 5617 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | // True if this blocks a move from the given location. |
| 5621 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5622 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | // A move is redundant if it's been eliminated, if its source and |
| 5626 | // destination are the same, or if its destination is unneeded. |
| 5627 | bool IsRedundant() const { |
| 5628 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5629 | } |
| 5630 | |
| 5631 | // We clear both operands to indicate move that's been eliminated. |
| 5632 | void Eliminate() { |
| 5633 | source_ = destination_ = Location::NoLocation(); |
| 5634 | } |
| 5635 | |
| 5636 | bool IsEliminated() const { |
| 5637 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5638 | return source_.IsInvalid(); |
| 5639 | } |
| 5640 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5641 | Primitive::Type GetType() const { return type_; } |
| 5642 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5643 | bool Is64BitMove() const { |
| 5644 | return Primitive::Is64BitType(type_); |
| 5645 | } |
| 5646 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5647 | HInstruction* GetInstruction() const { return instruction_; } |
| 5648 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5649 | private: |
| 5650 | Location source_; |
| 5651 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5652 | // The type this move is for. |
| 5653 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5654 | // The instruction this move is assocatied with. Null when this move is |
| 5655 | // for moving an input in the expected locations of user (including a phi user). |
| 5656 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5657 | // in the same parallel move. |
| 5658 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5659 | }; |
| 5660 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5661 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 5662 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5663 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5664 | |
| 5665 | class HParallelMove : public HTemplateInstruction<0> { |
| 5666 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5667 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5668 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5669 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5670 | moves_.reserve(kDefaultNumberOfMoves); |
| 5671 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5672 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5673 | void AddMove(Location source, |
| 5674 | Location destination, |
| 5675 | Primitive::Type type, |
| 5676 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5677 | DCHECK(source.IsValid()); |
| 5678 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5679 | if (kIsDebugBuild) { |
| 5680 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5681 | for (const MoveOperands& move : moves_) { |
| 5682 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5683 | // Special case the situation where the move is for the spill slot |
| 5684 | // of the instruction. |
| 5685 | if ((GetPrevious() == instruction) |
| 5686 | || ((GetPrevious() == nullptr) |
| 5687 | && instruction->IsPhi() |
| 5688 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5689 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5690 | << "Doing parallel moves for the same instruction."; |
| 5691 | } else { |
| 5692 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5693 | } |
| 5694 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5695 | } |
| 5696 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5697 | for (const MoveOperands& move : moves_) { |
| 5698 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5699 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5700 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5701 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5702 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5703 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5704 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5705 | } |
| 5706 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5707 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5708 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5709 | } |
| 5710 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5711 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5712 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5713 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5714 | |
| 5715 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5716 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5717 | |
| 5718 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5719 | }; |
| 5720 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5721 | } // namespace art |
| 5722 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 5723 | #ifdef ART_ENABLE_CODEGEN_arm |
| 5724 | #include "nodes_arm.h" |
| 5725 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5726 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5727 | #include "nodes_arm64.h" |
| 5728 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5729 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5730 | #include "nodes_x86.h" |
| 5731 | #endif |
| 5732 | |
| 5733 | namespace art { |
| 5734 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5735 | class HGraphVisitor : public ValueObject { |
| 5736 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5737 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5738 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5739 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5740 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5741 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5742 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5743 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5744 | void VisitInsertionOrder(); |
| 5745 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5746 | // Visit the graph following dominator tree reverse post-order. |
| 5747 | void VisitReversePostOrder(); |
| 5748 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5749 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5750 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5751 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5752 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5753 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5754 | |
| 5755 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5756 | |
| 5757 | #undef DECLARE_VISIT_INSTRUCTION |
| 5758 | |
| 5759 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5760 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5761 | |
| 5762 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5763 | }; |
| 5764 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5765 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5766 | public: |
| 5767 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5768 | virtual ~HGraphDelegateVisitor() {} |
| 5769 | |
| 5770 | // Visit functions that delegate to to super class. |
| 5771 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5772 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5773 | |
| 5774 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5775 | |
| 5776 | #undef DECLARE_VISIT_INSTRUCTION |
| 5777 | |
| 5778 | private: |
| 5779 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5780 | }; |
| 5781 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5782 | class HInsertionOrderIterator : public ValueObject { |
| 5783 | public: |
| 5784 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5785 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5786 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5787 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5788 | void Advance() { ++index_; } |
| 5789 | |
| 5790 | private: |
| 5791 | const HGraph& graph_; |
| 5792 | size_t index_; |
| 5793 | |
| 5794 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5795 | }; |
| 5796 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5797 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5798 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5799 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5800 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5801 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5802 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5803 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5804 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5805 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5806 | void Advance() { ++index_; } |
| 5807 | |
| 5808 | private: |
| 5809 | const HGraph& graph_; |
| 5810 | size_t index_; |
| 5811 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5812 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5813 | }; |
| 5814 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5815 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5816 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5817 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5818 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5819 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5820 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5821 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5822 | |
| 5823 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5824 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5825 | void Advance() { --index_; } |
| 5826 | |
| 5827 | private: |
| 5828 | const HGraph& graph_; |
| 5829 | size_t index_; |
| 5830 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5831 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5832 | }; |
| 5833 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5834 | class HLinearPostOrderIterator : public ValueObject { |
| 5835 | public: |
| 5836 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5837 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5838 | |
| 5839 | bool Done() const { return index_ == 0; } |
| 5840 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5841 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5842 | |
| 5843 | void Advance() { |
| 5844 | --index_; |
| 5845 | DCHECK_GE(index_, 0U); |
| 5846 | } |
| 5847 | |
| 5848 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5849 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5850 | size_t index_; |
| 5851 | |
| 5852 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5853 | }; |
| 5854 | |
| 5855 | class HLinearOrderIterator : public ValueObject { |
| 5856 | public: |
| 5857 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5858 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5859 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5860 | bool Done() const { return index_ == order_.size(); } |
| 5861 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5862 | void Advance() { ++index_; } |
| 5863 | |
| 5864 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5865 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5866 | size_t index_; |
| 5867 | |
| 5868 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5869 | }; |
| 5870 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5871 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5872 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5873 | // block id. |
| 5874 | class HBlocksInLoopIterator : public ValueObject { |
| 5875 | public: |
| 5876 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5877 | : blocks_in_loop_(info.GetBlocks()), |
| 5878 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5879 | index_(0) { |
| 5880 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5881 | Advance(); |
| 5882 | } |
| 5883 | } |
| 5884 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5885 | bool Done() const { return index_ == blocks_.size(); } |
| 5886 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5887 | void Advance() { |
| 5888 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5889 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5890 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5891 | break; |
| 5892 | } |
| 5893 | } |
| 5894 | } |
| 5895 | |
| 5896 | private: |
| 5897 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5898 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5899 | size_t index_; |
| 5900 | |
| 5901 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5902 | }; |
| 5903 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5904 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5905 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5906 | // post order. |
| 5907 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5908 | public: |
| 5909 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5910 | : blocks_in_loop_(info.GetBlocks()), |
| 5911 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5912 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5913 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5914 | Advance(); |
| 5915 | } |
| 5916 | } |
| 5917 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5918 | bool Done() const { return index_ == blocks_.size(); } |
| 5919 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5920 | void Advance() { |
| 5921 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5922 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5923 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5924 | break; |
| 5925 | } |
| 5926 | } |
| 5927 | } |
| 5928 | |
| 5929 | private: |
| 5930 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5931 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5932 | size_t index_; |
| 5933 | |
| 5934 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5935 | }; |
| 5936 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5937 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5938 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5939 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5940 | : constant->AsLongConstant()->GetValue(); |
| 5941 | } |
| 5942 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5943 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5944 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5945 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5946 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5947 | // times and provide different class resolution but no two class loaders should ever |
| 5948 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5949 | // all sorts of weird failures. |
| 5950 | return &lhs == &rhs; |
| 5951 | } |
| 5952 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5953 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 5954 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 5955 | inline const H##type* HInstruction::As##type() const { \ |
| 5956 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 5957 | } \ |
| 5958 | inline H##type* HInstruction::As##type() { \ |
| 5959 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 5960 | } |
| 5961 | |
| 5962 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 5963 | #undef INSTRUCTION_TYPE_CHECK |
| 5964 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5965 | } // namespace art |
| 5966 | |
| 5967 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |