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; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 47 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 48 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 49 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 50 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 51 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 52 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 53 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 54 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 55 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 56 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 57 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 58 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 59 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 60 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 61 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 62 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 63 | namespace mirror { |
| 64 | class DexCache; |
| 65 | } // namespace mirror |
| 66 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | static const int kDefaultNumberOfBlocks = 8; |
| 68 | static const int kDefaultNumberOfSuccessors = 2; |
| 69 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 70 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 72 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 73 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 74 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 75 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 76 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 77 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 78 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 79 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 80 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 81 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 82 | static constexpr uint32_t kNoDexPc = -1; |
| 83 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 84 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 85 | // All types. |
| 86 | kCondEQ, // == |
| 87 | kCondNE, // != |
| 88 | // Signed integers and floating-point numbers. |
| 89 | kCondLT, // < |
| 90 | kCondLE, // <= |
| 91 | kCondGT, // > |
| 92 | kCondGE, // >= |
| 93 | // Unsigned integers. |
| 94 | kCondB, // < |
| 95 | kCondBE, // <= |
| 96 | kCondA, // > |
| 97 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 100 | enum BuildSsaResult { |
| 101 | kBuildSsaFailNonNaturalLoop, |
| 102 | kBuildSsaFailThrowCatchLoop, |
David Brazdil | 15693bf | 2015-12-16 10:30:45 +0000 | [diff] [blame] | 103 | kBuildSsaFailAmbiguousArrayOp, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 104 | kBuildSsaSuccess, |
| 105 | }; |
| 106 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 107 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 108 | public: |
| 109 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 110 | |
| 111 | void AddInstruction(HInstruction* instruction); |
| 112 | void RemoveInstruction(HInstruction* instruction); |
| 113 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 114 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 115 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 116 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 117 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 118 | // Return true if this list contains `instruction`. |
| 119 | bool Contains(HInstruction* instruction) const; |
| 120 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 121 | // Return true if `instruction1` is found before `instruction2` in |
| 122 | // this instruction list and false otherwise. Abort if none |
| 123 | // of these instructions is found. |
| 124 | bool FoundBefore(const HInstruction* instruction1, |
| 125 | const HInstruction* instruction2) const; |
| 126 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 127 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 128 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 129 | |
| 130 | // Update the block of all instructions to be `block`. |
| 131 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 132 | |
| 133 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 134 | void Add(const HInstructionList& instruction_list); |
| 135 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 136 | // Return the number of instructions in the list. This is an expensive operation. |
| 137 | size_t CountSize() const; |
| 138 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 139 | private: |
| 140 | HInstruction* first_instruction_; |
| 141 | HInstruction* last_instruction_; |
| 142 | |
| 143 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 144 | friend class HGraph; |
| 145 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 146 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 147 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 148 | |
| 149 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 150 | }; |
| 151 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 152 | class ReferenceTypeInfo : ValueObject { |
| 153 | public: |
| 154 | typedef Handle<mirror::Class> TypeHandle; |
| 155 | |
| 156 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 157 | // The constructor will check that the type_handle is valid. |
| 158 | return ReferenceTypeInfo(type_handle, is_exact); |
| 159 | } |
| 160 | |
| 161 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 162 | |
| 163 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 164 | return handle.GetReference() != nullptr; |
| 165 | } |
| 166 | |
| 167 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 168 | return IsValidHandle(type_handle_); |
| 169 | } |
| 170 | |
| 171 | bool IsExact() const { return is_exact_; } |
| 172 | |
| 173 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 174 | DCHECK(IsValid()); |
| 175 | return GetTypeHandle()->IsObjectClass(); |
| 176 | } |
| 177 | |
| 178 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 179 | DCHECK(IsValid()); |
| 180 | return GetTypeHandle()->IsStringClass(); |
| 181 | } |
| 182 | |
| 183 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 184 | DCHECK(IsValid()); |
| 185 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 186 | } |
| 187 | |
| 188 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 189 | DCHECK(IsValid()); |
| 190 | return GetTypeHandle()->IsInterface(); |
| 191 | } |
| 192 | |
| 193 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 194 | DCHECK(IsValid()); |
| 195 | return GetTypeHandle()->IsArrayClass(); |
| 196 | } |
| 197 | |
| 198 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 199 | DCHECK(IsValid()); |
| 200 | return GetTypeHandle()->IsPrimitiveArray(); |
| 201 | } |
| 202 | |
| 203 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 204 | DCHECK(IsValid()); |
| 205 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 206 | } |
| 207 | |
| 208 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 209 | DCHECK(IsValid()); |
| 210 | if (!IsExact()) return false; |
| 211 | if (!IsArrayClass()) return false; |
| 212 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 213 | } |
| 214 | |
| 215 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 216 | DCHECK(IsValid()); |
| 217 | if (!IsExact()) return false; |
| 218 | if (!IsArrayClass()) return false; |
| 219 | if (!rti.IsArrayClass()) return false; |
| 220 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 221 | rti.GetTypeHandle()->GetComponentType()); |
| 222 | } |
| 223 | |
| 224 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 225 | |
| 226 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 227 | DCHECK(IsValid()); |
| 228 | DCHECK(rti.IsValid()); |
| 229 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 230 | } |
| 231 | |
| 232 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 233 | DCHECK(IsValid()); |
| 234 | DCHECK(rti.IsValid()); |
| 235 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 236 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 237 | } |
| 238 | |
| 239 | // Returns true if the type information provide the same amount of details. |
| 240 | // Note that it does not mean that the instructions have the same actual type |
| 241 | // (because the type can be the result of a merge). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 242 | bool IsEqual(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 243 | if (!IsValid() && !rti.IsValid()) { |
| 244 | // Invalid types are equal. |
| 245 | return true; |
| 246 | } |
| 247 | if (!IsValid() || !rti.IsValid()) { |
| 248 | // One is valid, the other not. |
| 249 | return false; |
| 250 | } |
| 251 | return IsExact() == rti.IsExact() |
| 252 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 253 | } |
| 254 | |
| 255 | private: |
| 256 | ReferenceTypeInfo(); |
| 257 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
| 258 | |
| 259 | // The class of the object. |
| 260 | TypeHandle type_handle_; |
| 261 | // Whether or not the type is exact or a superclass of the actual type. |
| 262 | // Whether or not we have any information about this type. |
| 263 | bool is_exact_; |
| 264 | }; |
| 265 | |
| 266 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 267 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 268 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 269 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 270 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 271 | HGraph(ArenaAllocator* arena, |
| 272 | const DexFile& dex_file, |
| 273 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 274 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 275 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 276 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 277 | bool debuggable = false, |
| 278 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 279 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 280 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 281 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 282 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 283 | entry_block_(nullptr), |
| 284 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 285 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 286 | number_of_vregs_(0), |
| 287 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 288 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 289 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 290 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 291 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 292 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 293 | dex_file_(dex_file), |
| 294 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 295 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 296 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 297 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 298 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 299 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 300 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 301 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 302 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 303 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 304 | cached_current_method_(nullptr), |
| 305 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 306 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 307 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 308 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 309 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 310 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 311 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 312 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 313 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 314 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 315 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 316 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 317 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 318 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 319 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 320 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 321 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 322 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 323 | // Try building the SSA form of this graph, with dominance computation and |
| 324 | // loop recognition. Returns a code specifying that it was successful or the |
| 325 | // reason for failure. |
| 326 | BuildSsaResult TryBuildingSsa(StackHandleScopeCollection* handles); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 327 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 328 | void ComputeDominanceInformation(); |
| 329 | void ClearDominanceInformation(); |
| 330 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 331 | void BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 332 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 333 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 334 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 335 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 336 | // was successful or the reason for failure. The method will fail if a loop |
| 337 | // is not natural, that is the header does not dominate a back edge, or if it |
| 338 | // is a throw-catch loop, i.e. the header is a catch block. |
| 339 | BuildSsaResult AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 340 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 341 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 342 | // order and loop information. |
| 343 | void ComputeTryBlockInformation(); |
| 344 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 345 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 346 | // Returns the instruction used to replace the invoke expression or null if the |
| 347 | // invoke is for a void method. |
| 348 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 349 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 350 | // Need to add a couple of blocks to test if the loop body is entered and |
| 351 | // put deoptimization instructions, etc. |
| 352 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 353 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 354 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 355 | // other blocks and has no instructions or phis. |
| 356 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 357 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 358 | // Splits the edge between `block` and `successor` while preserving the |
| 359 | // indices in the predecessor/successor lists. If there are multiple edges |
| 360 | // between the blocks, the lowest indices are used. |
| 361 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 362 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 363 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 364 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 365 | void SimplifyLoop(HBasicBlock* header); |
| 366 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 367 | int32_t GetNextInstructionId() { |
| 368 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 369 | return current_instruction_id_++; |
| 370 | } |
| 371 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 372 | int32_t GetCurrentInstructionId() const { |
| 373 | return current_instruction_id_; |
| 374 | } |
| 375 | |
| 376 | void SetCurrentInstructionId(int32_t id) { |
| 377 | current_instruction_id_ = id; |
| 378 | } |
| 379 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 380 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 381 | return maximum_number_of_out_vregs_; |
| 382 | } |
| 383 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 384 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 385 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 388 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 389 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 390 | } |
| 391 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 392 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 393 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 394 | } |
| 395 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 396 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 397 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 398 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 401 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 402 | number_of_vregs_ = number_of_vregs; |
| 403 | } |
| 404 | |
| 405 | uint16_t GetNumberOfVRegs() const { |
| 406 | return number_of_vregs_; |
| 407 | } |
| 408 | |
| 409 | void SetNumberOfInVRegs(uint16_t value) { |
| 410 | number_of_in_vregs_ = value; |
| 411 | } |
| 412 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 413 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 414 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 415 | return number_of_vregs_ - number_of_in_vregs_; |
| 416 | } |
| 417 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 418 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 419 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 420 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 421 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 422 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 423 | return linear_order_; |
| 424 | } |
| 425 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 426 | bool HasBoundsChecks() const { |
| 427 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 430 | void SetHasBoundsChecks(bool value) { |
| 431 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 434 | bool ShouldGenerateConstructorBarrier() const { |
| 435 | return should_generate_constructor_barrier_; |
| 436 | } |
| 437 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 438 | bool IsDebuggable() const { return debuggable_; } |
| 439 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 440 | // 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] | 441 | // already, it is created and inserted into the graph. This method is only for |
| 442 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 443 | 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] | 444 | |
| 445 | // TODO: This is problematic for the consistency of reference type propagation |
| 446 | // because it can be created anytime after the pass and thus it will be left |
| 447 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 448 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 449 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 450 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 451 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 452 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 453 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 454 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 455 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 456 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 457 | 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] | 458 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 459 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 460 | 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] | 461 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 462 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 463 | HCurrentMethod* GetCurrentMethod(); |
| 464 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 465 | const DexFile& GetDexFile() const { |
| 466 | return dex_file_; |
| 467 | } |
| 468 | |
| 469 | uint32_t GetMethodIdx() const { |
| 470 | return method_idx_; |
| 471 | } |
| 472 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 473 | InvokeType GetInvokeType() const { |
| 474 | return invoke_type_; |
| 475 | } |
| 476 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 477 | InstructionSet GetInstructionSet() const { |
| 478 | return instruction_set_; |
| 479 | } |
| 480 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 481 | bool HasTryCatch() const { return has_try_catch_; } |
| 482 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 483 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 484 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 485 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 486 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 487 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 488 | // The instruction has been inserted into the graph, either as a constant, or |
| 489 | // before cursor. |
| 490 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 491 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 492 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 493 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 494 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 495 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 496 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 497 | template <class InstructionType, typename ValueType> |
| 498 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 499 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 500 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 501 | // Try to find an existing constant of the given value. |
| 502 | InstructionType* constant = nullptr; |
| 503 | auto cached_constant = cache->find(value); |
| 504 | if (cached_constant != cache->end()) { |
| 505 | constant = cached_constant->second; |
| 506 | } |
| 507 | |
| 508 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 509 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 510 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 511 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 512 | cache->Overwrite(value, constant); |
| 513 | InsertConstant(constant); |
| 514 | } |
| 515 | return constant; |
| 516 | } |
| 517 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 518 | void InsertConstant(HConstant* instruction); |
| 519 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 520 | // Cache a float constant into the graph. This method should only be |
| 521 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 522 | void CacheFloatConstant(HFloatConstant* constant); |
| 523 | |
| 524 | // See CacheFloatConstant comment. |
| 525 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 526 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 527 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 528 | |
| 529 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 530 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 531 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 532 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 533 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 534 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 535 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 536 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 537 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 538 | HBasicBlock* entry_block_; |
| 539 | HBasicBlock* exit_block_; |
| 540 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 541 | // 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] | 542 | uint16_t maximum_number_of_out_vregs_; |
| 543 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 544 | // The number of virtual registers in this method. Contains the parameters. |
| 545 | uint16_t number_of_vregs_; |
| 546 | |
| 547 | // The number of virtual registers used by parameters of this method. |
| 548 | uint16_t number_of_in_vregs_; |
| 549 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 550 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 551 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 552 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 553 | // Has bounds checks. We can totally skip BCE if it's false. |
| 554 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 555 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 556 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 557 | // try/catch-related passes if false. |
| 558 | bool has_try_catch_; |
| 559 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 560 | // Indicates whether the graph should be compiled in a way that |
| 561 | // ensures full debuggability. If false, we can apply more |
| 562 | // aggressive optimizations that may limit the level of debugging. |
| 563 | const bool debuggable_; |
| 564 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 565 | // 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] | 566 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 567 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 568 | // The dex file from which the method is from. |
| 569 | const DexFile& dex_file_; |
| 570 | |
| 571 | // The method index in the dex file. |
| 572 | const uint32_t method_idx_; |
| 573 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 574 | // If inlined, this encodes how the callee is being invoked. |
| 575 | const InvokeType invoke_type_; |
| 576 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 577 | // Whether the graph has been transformed to SSA form. Only used |
| 578 | // in debug mode to ensure we are not using properties only valid |
| 579 | // for non-SSA form (like the number of temporaries). |
| 580 | bool in_ssa_form_; |
| 581 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 582 | const bool should_generate_constructor_barrier_; |
| 583 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 584 | const InstructionSet instruction_set_; |
| 585 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 586 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 587 | HNullConstant* cached_null_constant_; |
| 588 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 589 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 590 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 591 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 592 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 593 | HCurrentMethod* cached_current_method_; |
| 594 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 595 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 596 | // for example for methods whose declaring class could not be resolved |
| 597 | // (such as when the superclass could not be found). |
| 598 | ArtMethod* art_method_; |
| 599 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 600 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 601 | // collection pointer to passes which may create NullConstant. |
| 602 | ReferenceTypeInfo inexact_object_rti_; |
| 603 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 604 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 605 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 606 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 607 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 608 | }; |
| 609 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 610 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 611 | public: |
| 612 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 613 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 614 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 615 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 616 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 617 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 618 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 619 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 620 | |
| 621 | HBasicBlock* GetHeader() const { |
| 622 | return header_; |
| 623 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 624 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 625 | void SetHeader(HBasicBlock* block) { |
| 626 | header_ = block; |
| 627 | } |
| 628 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 629 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 630 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 631 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 632 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 633 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 634 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 635 | } |
| 636 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 637 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 638 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 639 | } |
| 640 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 641 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 642 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 643 | } |
| 644 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 645 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 646 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 649 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 650 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 651 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 652 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 653 | } |
| 654 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 655 | // Returns the lifetime position of the back edge that has the |
| 656 | // greatest lifetime position. |
| 657 | size_t GetLifetimeEnd() const; |
| 658 | |
| 659 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 660 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 661 | } |
| 662 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 663 | // 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] | 664 | // that is the header dominates the back edge. |
| 665 | bool Populate(); |
| 666 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 667 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 668 | // Populate(). If there are no back edges left, the loop info is completely |
| 669 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 670 | // inner loops first. |
| 671 | void Update(); |
| 672 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 673 | // Returns whether this loop information contains `block`. |
| 674 | // Note that this loop information *must* be populated before entering this function. |
| 675 | bool Contains(const HBasicBlock& block) const; |
| 676 | |
| 677 | // Returns whether this loop information is an inner loop of `other`. |
| 678 | // Note that `other` *must* be populated before entering this function. |
| 679 | bool IsIn(const HLoopInformation& other) const; |
| 680 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 681 | // Returns true if instruction is not defined within this loop. |
| 682 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 683 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 684 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 685 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 686 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 687 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 688 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 689 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 690 | // Internal recursive implementation of `Populate`. |
| 691 | void PopulateRecursive(HBasicBlock* block); |
| 692 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 693 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 694 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 695 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 696 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 697 | |
| 698 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 699 | }; |
| 700 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 701 | // Stores try/catch information for basic blocks. |
| 702 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 703 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 704 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 705 | public: |
| 706 | // Try block information constructor. |
| 707 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 708 | : try_entry_(&try_entry), |
| 709 | catch_dex_file_(nullptr), |
| 710 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 711 | DCHECK(try_entry_ != nullptr); |
| 712 | } |
| 713 | |
| 714 | // Catch block information constructor. |
| 715 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 716 | : try_entry_(nullptr), |
| 717 | catch_dex_file_(&dex_file), |
| 718 | catch_type_index_(catch_type_index) {} |
| 719 | |
| 720 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 721 | |
| 722 | const HTryBoundary& GetTryEntry() const { |
| 723 | DCHECK(IsTryBlock()); |
| 724 | return *try_entry_; |
| 725 | } |
| 726 | |
| 727 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 728 | |
| 729 | bool IsCatchAllTypeIndex() const { |
| 730 | DCHECK(IsCatchBlock()); |
| 731 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 732 | } |
| 733 | |
| 734 | uint16_t GetCatchTypeIndex() const { |
| 735 | DCHECK(IsCatchBlock()); |
| 736 | return catch_type_index_; |
| 737 | } |
| 738 | |
| 739 | const DexFile& GetCatchDexFile() const { |
| 740 | DCHECK(IsCatchBlock()); |
| 741 | return *catch_dex_file_; |
| 742 | } |
| 743 | |
| 744 | private: |
| 745 | // One of possibly several TryBoundary instructions entering the block's try. |
| 746 | // Only set for try blocks. |
| 747 | const HTryBoundary* try_entry_; |
| 748 | |
| 749 | // Exception type information. Only set for catch blocks. |
| 750 | const DexFile* catch_dex_file_; |
| 751 | const uint16_t catch_type_index_; |
| 752 | }; |
| 753 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 754 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 755 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 756 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 757 | // A block in a method. Contains the list of instructions represented |
| 758 | // as a double linked list. Each block knows its predecessors and |
| 759 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 760 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 761 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 762 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 763 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 764 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 765 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 766 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 767 | loop_information_(nullptr), |
| 768 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 769 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 770 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 771 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 772 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 773 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 774 | try_catch_information_(nullptr) { |
| 775 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 776 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 777 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 778 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 779 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 780 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 781 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 784 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 785 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 786 | } |
| 787 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 788 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 789 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 790 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 791 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 792 | return ContainsElement(successors_, block, start_from); |
| 793 | } |
| 794 | |
| 795 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 796 | return dominated_blocks_; |
| 797 | } |
| 798 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 799 | bool IsEntryBlock() const { |
| 800 | return graph_->GetEntryBlock() == this; |
| 801 | } |
| 802 | |
| 803 | bool IsExitBlock() const { |
| 804 | return graph_->GetExitBlock() == this; |
| 805 | } |
| 806 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 807 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 808 | bool IsSingleTryBoundary() const; |
| 809 | |
| 810 | // Returns true if this block emits nothing but a jump. |
| 811 | bool IsSingleJump() const { |
| 812 | HLoopInformation* loop_info = GetLoopInformation(); |
| 813 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 814 | // Back edges generate a suspend check. |
| 815 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 816 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 817 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 818 | void AddBackEdge(HBasicBlock* back_edge) { |
| 819 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 820 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 821 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 822 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 823 | loop_information_->AddBackEdge(back_edge); |
| 824 | } |
| 825 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 826 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 827 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 828 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 829 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 830 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 831 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 832 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 833 | HBasicBlock* GetDominator() const { return dominator_; } |
| 834 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 835 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 836 | |
| 837 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 838 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 839 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 840 | |
| 841 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 842 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 843 | } |
| 844 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 845 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 846 | |
| 847 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 848 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 851 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 852 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 853 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 854 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 855 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 856 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 857 | |
| 858 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 859 | successors_.push_back(block); |
| 860 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 861 | } |
| 862 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 863 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 864 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 865 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 866 | new_block->predecessors_.push_back(this); |
| 867 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 870 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 871 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 872 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 873 | new_block->successors_.push_back(this); |
| 874 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 877 | // Insert `this` between `predecessor` and `successor. This method |
| 878 | // preserves the indicies, and will update the first edge found between |
| 879 | // `predecessor` and `successor`. |
| 880 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 881 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 882 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 883 | successor->predecessors_[predecessor_index] = this; |
| 884 | predecessor->successors_[successor_index] = this; |
| 885 | successors_.push_back(successor); |
| 886 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 887 | } |
| 888 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 889 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 890 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 891 | } |
| 892 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 893 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 894 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 895 | } |
| 896 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 897 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 898 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 902 | predecessors_.push_back(block); |
| 903 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 904 | } |
| 905 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 906 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 907 | DCHECK_EQ(predecessors_.size(), 2u); |
| 908 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 909 | } |
| 910 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 911 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 912 | DCHECK_EQ(successors_.size(), 2u); |
| 913 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 914 | } |
| 915 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 916 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 917 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 918 | } |
| 919 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 920 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 921 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 922 | } |
| 923 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 924 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 925 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 926 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 930 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 931 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | // Returns whether the first occurrence of `predecessor` in the list of |
| 935 | // predecessors is at index `idx`. |
| 936 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 937 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 938 | return GetPredecessorIndexOf(predecessor) == idx; |
| 939 | } |
| 940 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 941 | // Create a new block between this block and its predecessors. The new block |
| 942 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 943 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 944 | // loop and try/catch information are not updated. |
| 945 | HBasicBlock* CreateImmediateDominator(); |
| 946 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 947 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 948 | // created, latter block. Note that this method will add the block to the |
| 949 | // graph, create a Goto at the end of the former block and will create an edge |
| 950 | // 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] | 951 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 952 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 953 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 954 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 955 | // created block. Note that this method just updates raw block information, |
| 956 | // like predecessors, successors, dominators, and instruction list. It does not |
| 957 | // update the graph, reverse post order, loop information, nor make sure the |
| 958 | // blocks are consistent (for example ending with a control flow instruction). |
| 959 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 960 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 961 | // Split catch block into two blocks after the original move-exception bytecode |
| 962 | // instruction, or at the beginning if not present. Returns the newly created, |
| 963 | // latter block, or nullptr if such block could not be created (must be dead |
| 964 | // in that case). Note that this method just updates raw block information, |
| 965 | // like predecessors, successors, dominators, and instruction list. It does not |
| 966 | // update the graph, reverse post order, loop information, nor make sure the |
| 967 | // blocks are consistent (for example ending with a control flow instruction). |
| 968 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 969 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 970 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 971 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 972 | // that this method does not update the graph, reverse post order, loop |
| 973 | // information, nor make sure the blocks are consistent (for example ending |
| 974 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 975 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 976 | |
| 977 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 978 | // of `this` are moved to `other`. |
| 979 | // Note that this method does not update the graph, reverse post order, loop |
| 980 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 981 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 982 | void ReplaceWith(HBasicBlock* other); |
| 983 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 984 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 985 | // order, links to predecessors, successors, dominators and deletes the block |
| 986 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 987 | // predecessor of `other` and vice versa. |
| 988 | void MergeWith(HBasicBlock* other); |
| 989 | |
| 990 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 991 | // removes it from all loops it is included in and eventually from the graph. |
| 992 | // The block must not dominate any other block. Predecessors and successors |
| 993 | // are safely updated. |
| 994 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 995 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 996 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 997 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 998 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 999 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1000 | // Replace instruction `initial` with `replacement` within this block. |
| 1001 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1002 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1003 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1004 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1005 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1006 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1007 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1008 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1009 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1010 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1011 | |
| 1012 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1013 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1014 | } |
| 1015 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1016 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1017 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1018 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1019 | } |
| 1020 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1021 | HLoopInformation* GetLoopInformation() const { |
| 1022 | return loop_information_; |
| 1023 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1024 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1025 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1026 | // 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] | 1027 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1028 | void SetInLoop(HLoopInformation* info) { |
| 1029 | if (IsLoopHeader()) { |
| 1030 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1031 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1032 | loop_information_ = info; |
| 1033 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1034 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1035 | // Note that a non loop header having a loop information means this loop information |
| 1036 | // has already been populated |
| 1037 | loop_information_ = info; |
| 1038 | } else { |
| 1039 | // Block is part of an inner loop. Do not update the loop information. |
| 1040 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1041 | // at this point, because this method is being called while populating `info`. |
| 1042 | } |
| 1043 | } |
| 1044 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1045 | // Raw update of the loop information. |
| 1046 | void SetLoopInformation(HLoopInformation* info) { |
| 1047 | loop_information_ = info; |
| 1048 | } |
| 1049 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1050 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1051 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1052 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1053 | |
| 1054 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1055 | try_catch_information_ = try_catch_information; |
| 1056 | } |
| 1057 | |
| 1058 | bool IsTryBlock() const { |
| 1059 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1060 | } |
| 1061 | |
| 1062 | bool IsCatchBlock() const { |
| 1063 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1064 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1065 | |
| 1066 | // Returns the try entry that this block's successors should have. They will |
| 1067 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1068 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1069 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1070 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1071 | bool HasThrowingInstructions() const; |
| 1072 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1073 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1074 | bool Dominates(HBasicBlock* block) const; |
| 1075 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1076 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1077 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1078 | |
| 1079 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1080 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1081 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1082 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1083 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1084 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1085 | bool HasSinglePhi() const; |
| 1086 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1087 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1088 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1089 | ArenaVector<HBasicBlock*> predecessors_; |
| 1090 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1091 | HInstructionList instructions_; |
| 1092 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1093 | HLoopInformation* loop_information_; |
| 1094 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1095 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1096 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1097 | // The dex program counter of the first instruction of this block. |
| 1098 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1099 | size_t lifetime_start_; |
| 1100 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1101 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1102 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1103 | friend class HGraph; |
| 1104 | friend class HInstruction; |
| 1105 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1106 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1107 | }; |
| 1108 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1109 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1110 | // from the innermost to the outermost. |
| 1111 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1112 | public: |
| 1113 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1114 | : current_(block.GetLoopInformation()) {} |
| 1115 | |
| 1116 | bool Done() const { return current_ == nullptr; } |
| 1117 | |
| 1118 | void Advance() { |
| 1119 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1120 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | HLoopInformation* Current() const { |
| 1124 | DCHECK(!Done()); |
| 1125 | return current_; |
| 1126 | } |
| 1127 | |
| 1128 | private: |
| 1129 | HLoopInformation* current_; |
| 1130 | |
| 1131 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1132 | }; |
| 1133 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1134 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1135 | M(Above, Condition) \ |
| 1136 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1137 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1138 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1139 | M(ArrayGet, Instruction) \ |
| 1140 | M(ArrayLength, Instruction) \ |
| 1141 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1142 | M(Below, Condition) \ |
| 1143 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1144 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1145 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1146 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1147 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1148 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1149 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1150 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1151 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1152 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1153 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1154 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1155 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1156 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1157 | M(Exit, Instruction) \ |
| 1158 | M(FloatConstant, Constant) \ |
| 1159 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1160 | M(GreaterThan, Condition) \ |
| 1161 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1162 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1163 | M(InstanceFieldGet, Instruction) \ |
| 1164 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1165 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1166 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1167 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1168 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1169 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1170 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1171 | M(LessThan, Condition) \ |
| 1172 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1173 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1174 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1175 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1176 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1177 | M(Local, Instruction) \ |
| 1178 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1179 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1180 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1181 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1182 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1183 | M(Neg, UnaryOperation) \ |
| 1184 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1185 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1186 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1187 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1188 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1189 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1190 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1191 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1192 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1193 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1194 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1195 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1196 | M(Return, Instruction) \ |
| 1197 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1198 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1199 | M(Shl, BinaryOperation) \ |
| 1200 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1201 | M(StaticFieldGet, Instruction) \ |
| 1202 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1203 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1204 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1205 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1206 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1207 | M(StoreLocal, Instruction) \ |
| 1208 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1209 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1210 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1211 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1212 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1213 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1214 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1215 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1216 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1217 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1218 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1219 | #else |
| 1220 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1221 | M(ArmDexCacheArraysBase, Instruction) |
| 1222 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1223 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1224 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1225 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1226 | #else |
| 1227 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1228 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Alexandre Rames | 418318f | 2015-11-20 15:55:47 +0000 | [diff] [blame] | 1229 | M(Arm64IntermediateAddress, Instruction) \ |
| 1230 | M(Arm64MultiplyAccumulate, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1231 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1232 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1233 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1234 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1235 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1236 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1237 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1238 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1239 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1240 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1241 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1242 | M(X86LoadFromConstantTable, Instruction) \ |
| 1243 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1244 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1245 | |
| 1246 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1247 | |
| 1248 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1249 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1250 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1251 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1252 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1253 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1254 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1255 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1256 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1257 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1258 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1259 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1260 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1261 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1262 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1263 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1264 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1265 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1266 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1267 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1268 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1269 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1270 | #undef FORWARD_DECLARATION |
| 1271 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1272 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1273 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1274 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1275 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1276 | return other->Is##type(); \ |
| 1277 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1278 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1279 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1280 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1281 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1282 | const H##type* As##type() const { return this; } \ |
| 1283 | H##type* As##type() { return this; } |
| 1284 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1285 | template <typename T> class HUseList; |
| 1286 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1287 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1288 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1289 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1290 | HUseListNode* GetPrevious() const { return prev_; } |
| 1291 | HUseListNode* GetNext() const { return next_; } |
| 1292 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1293 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1294 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1295 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1296 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1297 | HUseListNode(T user, size_t index) |
| 1298 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1299 | |
| 1300 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1301 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1302 | HUseListNode<T>* prev_; |
| 1303 | HUseListNode<T>* next_; |
| 1304 | |
| 1305 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1306 | |
| 1307 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1308 | }; |
| 1309 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1310 | template <typename T> |
| 1311 | class HUseList : public ValueObject { |
| 1312 | public: |
| 1313 | HUseList() : first_(nullptr) {} |
| 1314 | |
| 1315 | void Clear() { |
| 1316 | first_ = nullptr; |
| 1317 | } |
| 1318 | |
| 1319 | // Adds a new entry at the beginning of the use list and returns |
| 1320 | // the newly created node. |
| 1321 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1322 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1323 | if (IsEmpty()) { |
| 1324 | first_ = new_node; |
| 1325 | } else { |
| 1326 | first_->prev_ = new_node; |
| 1327 | new_node->next_ = first_; |
| 1328 | first_ = new_node; |
| 1329 | } |
| 1330 | return new_node; |
| 1331 | } |
| 1332 | |
| 1333 | HUseListNode<T>* GetFirst() const { |
| 1334 | return first_; |
| 1335 | } |
| 1336 | |
| 1337 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1338 | DCHECK(node != nullptr); |
| 1339 | DCHECK(Contains(node)); |
| 1340 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1341 | if (node->prev_ != nullptr) { |
| 1342 | node->prev_->next_ = node->next_; |
| 1343 | } |
| 1344 | if (node->next_ != nullptr) { |
| 1345 | node->next_->prev_ = node->prev_; |
| 1346 | } |
| 1347 | if (node == first_) { |
| 1348 | first_ = node->next_; |
| 1349 | } |
| 1350 | } |
| 1351 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1352 | bool Contains(const HUseListNode<T>* node) const { |
| 1353 | if (node == nullptr) { |
| 1354 | return false; |
| 1355 | } |
| 1356 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1357 | if (current == node) { |
| 1358 | return true; |
| 1359 | } |
| 1360 | } |
| 1361 | return false; |
| 1362 | } |
| 1363 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1364 | bool IsEmpty() const { |
| 1365 | return first_ == nullptr; |
| 1366 | } |
| 1367 | |
| 1368 | bool HasOnlyOneUse() const { |
| 1369 | return first_ != nullptr && first_->next_ == nullptr; |
| 1370 | } |
| 1371 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1372 | size_t SizeSlow() const { |
| 1373 | size_t count = 0; |
| 1374 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1375 | ++count; |
| 1376 | } |
| 1377 | return count; |
| 1378 | } |
| 1379 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1380 | private: |
| 1381 | HUseListNode<T>* first_; |
| 1382 | }; |
| 1383 | |
| 1384 | template<typename T> |
| 1385 | class HUseIterator : public ValueObject { |
| 1386 | public: |
| 1387 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1388 | |
| 1389 | bool Done() const { return current_ == nullptr; } |
| 1390 | |
| 1391 | void Advance() { |
| 1392 | DCHECK(!Done()); |
| 1393 | current_ = current_->GetNext(); |
| 1394 | } |
| 1395 | |
| 1396 | HUseListNode<T>* Current() const { |
| 1397 | DCHECK(!Done()); |
| 1398 | return current_; |
| 1399 | } |
| 1400 | |
| 1401 | private: |
| 1402 | HUseListNode<T>* current_; |
| 1403 | |
| 1404 | friend class HValue; |
| 1405 | }; |
| 1406 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1407 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1408 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1409 | // by the used instructions. |
| 1410 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1411 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1412 | public: |
| 1413 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1414 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1415 | |
| 1416 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1417 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1418 | DCHECK(instruction_ != nullptr); |
| 1419 | DCHECK(use_node_ != nullptr); |
| 1420 | DCHECK(old_record.use_node_ == nullptr); |
| 1421 | } |
| 1422 | |
| 1423 | HInstruction* GetInstruction() const { return instruction_; } |
| 1424 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1425 | |
| 1426 | private: |
| 1427 | // Instruction used by the user. |
| 1428 | HInstruction* instruction_; |
| 1429 | |
| 1430 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1431 | HUseListNode<T>* use_node_; |
| 1432 | }; |
| 1433 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1434 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1435 | * Side-effects representation. |
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 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1438 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1439 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1440 | * modify the value of a reference field read [although it may modify the |
| 1441 | * reference fetch prior to reading the field, which is represented by its own |
| 1442 | * write/read dependence]). The analysis makes conservative points-to |
| 1443 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1444 | * the same, and any reference read depends on any reference read without |
| 1445 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1446 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1447 | * The internal representation uses 38-bit and is described in the table below. |
| 1448 | * The first line indicates the side effect, and for field/array accesses the |
| 1449 | * second line indicates the type of the access (in the order of the |
| 1450 | * Primitive::Type enum). |
| 1451 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1452 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1453 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1454 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1455 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1456 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1457 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1458 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1459 | * |
| 1460 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1461 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1462 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1463 | class SideEffects : public ValueObject { |
| 1464 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1465 | SideEffects() : flags_(0) {} |
| 1466 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1467 | static SideEffects None() { |
| 1468 | return SideEffects(0); |
| 1469 | } |
| 1470 | |
| 1471 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1472 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1473 | } |
| 1474 | |
| 1475 | static SideEffects AllChanges() { |
| 1476 | return SideEffects(kAllChangeBits); |
| 1477 | } |
| 1478 | |
| 1479 | static SideEffects AllDependencies() { |
| 1480 | return SideEffects(kAllDependOnBits); |
| 1481 | } |
| 1482 | |
| 1483 | static SideEffects AllExceptGCDependency() { |
| 1484 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1485 | } |
| 1486 | |
| 1487 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1488 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1489 | } |
| 1490 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1491 | static SideEffects AllWrites() { |
| 1492 | return SideEffects(kAllWrites); |
| 1493 | } |
| 1494 | |
| 1495 | static SideEffects AllReads() { |
| 1496 | return SideEffects(kAllReads); |
| 1497 | } |
| 1498 | |
| 1499 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1500 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1501 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1502 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1503 | } |
| 1504 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1505 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1506 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1507 | } |
| 1508 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1509 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1510 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1511 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1512 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1516 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1517 | } |
| 1518 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1519 | static SideEffects CanTriggerGC() { |
| 1520 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1521 | } |
| 1522 | |
| 1523 | static SideEffects DependsOnGC() { |
| 1524 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1525 | } |
| 1526 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1527 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1528 | SideEffects Union(SideEffects other) const { |
| 1529 | return SideEffects(flags_ | other.flags_); |
| 1530 | } |
| 1531 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1532 | SideEffects Exclusion(SideEffects other) const { |
| 1533 | return SideEffects(flags_ & ~other.flags_); |
| 1534 | } |
| 1535 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1536 | void Add(SideEffects other) { |
| 1537 | flags_ |= other.flags_; |
| 1538 | } |
| 1539 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1540 | bool Includes(SideEffects other) const { |
| 1541 | return (other.flags_ & flags_) == other.flags_; |
| 1542 | } |
| 1543 | |
| 1544 | bool HasSideEffects() const { |
| 1545 | return (flags_ & kAllChangeBits); |
| 1546 | } |
| 1547 | |
| 1548 | bool HasDependencies() const { |
| 1549 | return (flags_ & kAllDependOnBits); |
| 1550 | } |
| 1551 | |
| 1552 | // Returns true if there are no side effects or dependencies. |
| 1553 | bool DoesNothing() const { |
| 1554 | return flags_ == 0; |
| 1555 | } |
| 1556 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1557 | // Returns true if something is written. |
| 1558 | bool DoesAnyWrite() const { |
| 1559 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1560 | } |
| 1561 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1562 | // Returns true if something is read. |
| 1563 | bool DoesAnyRead() const { |
| 1564 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1565 | } |
| 1566 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1567 | // Returns true if potentially everything is written and read |
| 1568 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1569 | bool DoesAllReadWrite() const { |
| 1570 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1571 | } |
| 1572 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1573 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1574 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1577 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1578 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1579 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1580 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1584 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1585 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1586 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1587 | for (int s = kLastBit; s >= 0; s--) { |
| 1588 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1589 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1590 | // This is a bit for the GC side effect. |
| 1591 | if (current_bit_is_set) { |
| 1592 | flags += "GC"; |
| 1593 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1594 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1595 | } else { |
| 1596 | // This is a bit for the array/field analysis. |
| 1597 | // The underscore character stands for the 'can trigger GC' bit. |
| 1598 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1599 | if (current_bit_is_set) { |
| 1600 | flags += kDebug[s]; |
| 1601 | } |
| 1602 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1603 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1604 | flags += "|"; |
| 1605 | } |
| 1606 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1607 | } |
| 1608 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1609 | } |
| 1610 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1611 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1612 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1613 | private: |
| 1614 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1615 | |
| 1616 | static constexpr int kFieldWriteOffset = 0; |
| 1617 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1618 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1619 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1620 | |
| 1621 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1622 | |
| 1623 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1624 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1625 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1626 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1627 | |
| 1628 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1629 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1630 | |
| 1631 | // Aliases. |
| 1632 | |
| 1633 | static_assert(kChangeBits == kDependOnBits, |
| 1634 | "the 'change' bits should match the 'depend on' bits."); |
| 1635 | |
| 1636 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1637 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1638 | static constexpr uint64_t kAllWrites = |
| 1639 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1640 | static constexpr uint64_t kAllReads = |
| 1641 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1642 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1643 | // Work around the fact that HIR aliases I/F and J/D. |
| 1644 | // TODO: remove this interceptor once HIR types are clean |
| 1645 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1646 | switch (type) { |
| 1647 | case Primitive::kPrimInt: |
| 1648 | case Primitive::kPrimFloat: |
| 1649 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1650 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1651 | case Primitive::kPrimLong: |
| 1652 | case Primitive::kPrimDouble: |
| 1653 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1654 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1655 | default: |
| 1656 | return TypeFlag(type, offset); |
| 1657 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1658 | } |
| 1659 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1660 | // Translates type to bit flag. |
| 1661 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1662 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1663 | const uint64_t one = 1; |
| 1664 | const int shift = type; // 0-based consecutive enum |
| 1665 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1666 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1667 | return one << (type + offset); |
| 1668 | } |
| 1669 | |
| 1670 | // Private constructor on direct flags value. |
| 1671 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1672 | |
| 1673 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1674 | }; |
| 1675 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1676 | // 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] | 1677 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1678 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1679 | HEnvironment(ArenaAllocator* arena, |
| 1680 | size_t number_of_vregs, |
| 1681 | const DexFile& dex_file, |
| 1682 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1683 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1684 | InvokeType invoke_type, |
| 1685 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1686 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1687 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1688 | parent_(nullptr), |
| 1689 | dex_file_(dex_file), |
| 1690 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1691 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1692 | invoke_type_(invoke_type), |
| 1693 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1694 | } |
| 1695 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1696 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1697 | : HEnvironment(arena, |
| 1698 | to_copy.Size(), |
| 1699 | to_copy.GetDexFile(), |
| 1700 | to_copy.GetMethodIdx(), |
| 1701 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1702 | to_copy.GetInvokeType(), |
| 1703 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1704 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1705 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1706 | if (parent_ != nullptr) { |
| 1707 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1708 | } else { |
| 1709 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1710 | parent_->CopyFrom(parent); |
| 1711 | if (parent->GetParent() != nullptr) { |
| 1712 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1713 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1714 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1717 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1718 | void CopyFrom(HEnvironment* environment); |
| 1719 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1720 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1721 | // input to the loop phi instead. This is for inserting instructions that |
| 1722 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1723 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1724 | |
| 1725 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1726 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1730 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1731 | } |
| 1732 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1733 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1734 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1735 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1736 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1737 | HEnvironment* GetParent() const { return parent_; } |
| 1738 | |
| 1739 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1740 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1744 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | uint32_t GetDexPc() const { |
| 1748 | return dex_pc_; |
| 1749 | } |
| 1750 | |
| 1751 | uint32_t GetMethodIdx() const { |
| 1752 | return method_idx_; |
| 1753 | } |
| 1754 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1755 | InvokeType GetInvokeType() const { |
| 1756 | return invoke_type_; |
| 1757 | } |
| 1758 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1759 | const DexFile& GetDexFile() const { |
| 1760 | return dex_file_; |
| 1761 | } |
| 1762 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1763 | HInstruction* GetHolder() const { |
| 1764 | return holder_; |
| 1765 | } |
| 1766 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1767 | |
| 1768 | bool IsFromInlinedInvoke() const { |
| 1769 | return GetParent() != nullptr; |
| 1770 | } |
| 1771 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1772 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1773 | // Record instructions' use entries of this environment for constant-time removal. |
| 1774 | // It should only be called by HInstruction when a new environment use is added. |
| 1775 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1776 | DCHECK(env_use->GetUser() == this); |
| 1777 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1778 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1779 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1780 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1781 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1782 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1783 | HEnvironment* parent_; |
| 1784 | const DexFile& dex_file_; |
| 1785 | const uint32_t method_idx_; |
| 1786 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1787 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1788 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1789 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1790 | HInstruction* const holder_; |
| 1791 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1792 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1793 | |
| 1794 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1795 | }; |
| 1796 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1797 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1798 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1799 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1800 | : previous_(nullptr), |
| 1801 | next_(nullptr), |
| 1802 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1803 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1804 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1805 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1806 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1807 | locations_(nullptr), |
| 1808 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1809 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1810 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1811 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1812 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1813 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1814 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1815 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1816 | enum InstructionKind { |
| 1817 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1818 | }; |
| 1819 | #undef DECLARE_KIND |
| 1820 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1821 | HInstruction* GetNext() const { return next_; } |
| 1822 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1823 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1824 | HInstruction* GetNextDisregardingMoves() const; |
| 1825 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1826 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1827 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1828 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1829 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1830 | bool IsInBlock() const { return block_ != nullptr; } |
| 1831 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1832 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1833 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1834 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1835 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1836 | |
| 1837 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1838 | virtual const char* DebugName() const = 0; |
| 1839 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1840 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1841 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1842 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1843 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1844 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1845 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1846 | |
| 1847 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1848 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1849 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1850 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1851 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1852 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1853 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1854 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1855 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1856 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1857 | // Does not apply for all instructions, but having this at top level greatly |
| 1858 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1859 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1860 | virtual bool CanBeNull() const { |
| 1861 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1862 | return true; |
| 1863 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1864 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1865 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1866 | return false; |
| 1867 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1868 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1869 | virtual bool IsActualObject() const { |
| 1870 | return GetType() == Primitive::kPrimNot; |
| 1871 | } |
| 1872 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1873 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1874 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1875 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1876 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1877 | return reference_type_info_; |
| 1878 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1879 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1880 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1881 | DCHECK(user != nullptr); |
| 1882 | HUseListNode<HInstruction*>* use = |
| 1883 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1884 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1885 | } |
| 1886 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1887 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1888 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1889 | HUseListNode<HEnvironment*>* env_use = |
| 1890 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1891 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1894 | void RemoveAsUserOfInput(size_t input) { |
| 1895 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1896 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1897 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1898 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1899 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1900 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1901 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1902 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1903 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1904 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1905 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1906 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1907 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1908 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1909 | // Does this instruction strictly dominate `other_instruction`? |
| 1910 | // Returns false if this instruction and `other_instruction` are the same. |
| 1911 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1912 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1913 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1914 | int GetId() const { return id_; } |
| 1915 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1916 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1917 | int GetSsaIndex() const { return ssa_index_; } |
| 1918 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1919 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1920 | |
| 1921 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1922 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1923 | // Set the `environment_` field. Raw because this method does not |
| 1924 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1925 | void SetRawEnvironment(HEnvironment* environment) { |
| 1926 | DCHECK(environment_ == nullptr); |
| 1927 | DCHECK_EQ(environment->GetHolder(), this); |
| 1928 | environment_ = environment; |
| 1929 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1930 | |
| 1931 | // Set the environment of this instruction, copying it from `environment`. While |
| 1932 | // copying, the uses lists are being updated. |
| 1933 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1934 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1935 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1936 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1937 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1938 | if (environment->GetParent() != nullptr) { |
| 1939 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1940 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1941 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1942 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1943 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1944 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1945 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1946 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1947 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1948 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1949 | if (environment->GetParent() != nullptr) { |
| 1950 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1951 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1954 | // Returns the number of entries in the environment. Typically, that is the |
| 1955 | // number of dex registers in a method. It could be more in case of inlining. |
| 1956 | size_t EnvironmentSize() const; |
| 1957 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1958 | LocationSummary* GetLocations() const { return locations_; } |
| 1959 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1960 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1961 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1962 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1963 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1964 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1965 | // uses of this instruction by `other` are *not* updated. |
| 1966 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1967 | ReplaceWith(other); |
| 1968 | other->ReplaceInput(this, use_index); |
| 1969 | } |
| 1970 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1971 | // Move `this` instruction before `cursor`. |
| 1972 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1973 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 1974 | // Move `this` before its first user and out of any loops. If there is no |
| 1975 | // out-of-loop user that dominates all other users, move the instruction |
| 1976 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 1977 | // |
| 1978 | // This can be used only on non-throwing instructions with no side effects that |
| 1979 | // have at least one use but no environment uses. |
| 1980 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 1981 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1982 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1983 | bool Is##type() const; \ |
| 1984 | const H##type* As##type() const; \ |
| 1985 | H##type* As##type(); |
| 1986 | |
| 1987 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1988 | #undef INSTRUCTION_TYPE_CHECK |
| 1989 | |
| 1990 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1991 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1992 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1993 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1994 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1995 | #undef INSTRUCTION_TYPE_CHECK |
| 1996 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1997 | // Returns whether the instruction can be moved within the graph. |
| 1998 | virtual bool CanBeMoved() const { return false; } |
| 1999 | |
| 2000 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2001 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2002 | return false; |
| 2003 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2004 | |
| 2005 | // Returns whether any data encoded in the two instructions is equal. |
| 2006 | // This method does not look at the inputs. Both instructions must be |
| 2007 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2008 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2011 | |
| 2012 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2013 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2014 | // 2) Their inputs are identical. |
| 2015 | bool Equals(HInstruction* other) const; |
| 2016 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2017 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2018 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2019 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2020 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2021 | InstructionKind GetKind() const PURE; |
| 2022 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2023 | |
| 2024 | virtual size_t ComputeHashCode() const { |
| 2025 | size_t result = GetKind(); |
| 2026 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2027 | result = (result * 31) + InputAt(i)->GetId(); |
| 2028 | } |
| 2029 | return result; |
| 2030 | } |
| 2031 | |
| 2032 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2033 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2034 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2035 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2036 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2037 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2038 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2039 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2040 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2041 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2042 | |
| 2043 | // Returns whether the code generation of the instruction will require to have access |
| 2044 | // to the current method. Such instructions are: |
| 2045 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2046 | // to walk the stack and have the current method stored at a specific stack address. |
| 2047 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2048 | // fields of the current method. |
| 2049 | bool NeedsCurrentMethod() const { |
| 2050 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2051 | } |
| 2052 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2053 | // Returns whether the code generation of the instruction will require to have access |
| 2054 | // to the dex cache of the current method's declaring class via the current method. |
| 2055 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2056 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2057 | // Does this instruction have any use in an environment before |
| 2058 | // control flow hits 'other'? |
| 2059 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2060 | |
| 2061 | // Remove all references to environment uses of this instruction. |
| 2062 | // The caller must ensure that this is safe to do. |
| 2063 | void RemoveEnvironmentUsers(); |
| 2064 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2065 | protected: |
| 2066 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2067 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 2068 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2069 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2070 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2071 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2072 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2073 | HInstruction* previous_; |
| 2074 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2075 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2076 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2077 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2078 | // An instruction gets an id when it is added to the graph. |
| 2079 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2080 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2081 | int id_; |
| 2082 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2083 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2084 | int ssa_index_; |
| 2085 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2086 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2087 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2088 | |
| 2089 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2090 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2091 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2092 | // The environment associated with this instruction. Not null if the instruction |
| 2093 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2094 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2095 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2096 | // Set by the code generator. |
| 2097 | LocationSummary* locations_; |
| 2098 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2099 | // Set by the liveness analysis. |
| 2100 | LiveInterval* live_interval_; |
| 2101 | |
| 2102 | // Set by the liveness analysis, this is the position in a linear |
| 2103 | // order of blocks where this instruction's live interval start. |
| 2104 | size_t lifetime_position_; |
| 2105 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2106 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2107 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2108 | // TODO: for primitive types this should be marked as invalid. |
| 2109 | ReferenceTypeInfo reference_type_info_; |
| 2110 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2111 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2112 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2113 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2114 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2115 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2116 | |
| 2117 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2118 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2119 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2120 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2121 | class HInputIterator : public ValueObject { |
| 2122 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2123 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2124 | |
| 2125 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2126 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2127 | void Advance() { index_++; } |
| 2128 | |
| 2129 | private: |
| 2130 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2131 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2132 | |
| 2133 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2134 | }; |
| 2135 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2136 | class HInstructionIterator : public ValueObject { |
| 2137 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2138 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2139 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2140 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2143 | bool Done() const { return instruction_ == nullptr; } |
| 2144 | HInstruction* Current() const { return instruction_; } |
| 2145 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2146 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2147 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | private: |
| 2151 | HInstruction* instruction_; |
| 2152 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2153 | |
| 2154 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2155 | }; |
| 2156 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2157 | class HBackwardInstructionIterator : public ValueObject { |
| 2158 | public: |
| 2159 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2160 | : instruction_(instructions.last_instruction_) { |
| 2161 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2162 | } |
| 2163 | |
| 2164 | bool Done() const { return instruction_ == nullptr; } |
| 2165 | HInstruction* Current() const { return instruction_; } |
| 2166 | void Advance() { |
| 2167 | instruction_ = next_; |
| 2168 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2169 | } |
| 2170 | |
| 2171 | private: |
| 2172 | HInstruction* instruction_; |
| 2173 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2174 | |
| 2175 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2176 | }; |
| 2177 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2178 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2179 | class HTemplateInstruction: public HInstruction { |
| 2180 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2181 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2182 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2183 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2184 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2185 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2186 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2187 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2188 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2189 | DCHECK_LT(i, N); |
| 2190 | return inputs_[i]; |
| 2191 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2192 | |
| 2193 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2194 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2195 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2196 | } |
| 2197 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2198 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2199 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2200 | |
| 2201 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2202 | }; |
| 2203 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2204 | // HTemplateInstruction specialization for N=0. |
| 2205 | template<> |
| 2206 | class HTemplateInstruction<0>: public HInstruction { |
| 2207 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2208 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2209 | : HInstruction(side_effects, dex_pc) {} |
| 2210 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2211 | virtual ~HTemplateInstruction() {} |
| 2212 | |
| 2213 | size_t InputCount() const OVERRIDE { return 0; } |
| 2214 | |
| 2215 | protected: |
| 2216 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2217 | LOG(FATAL) << "Unreachable"; |
| 2218 | UNREACHABLE(); |
| 2219 | } |
| 2220 | |
| 2221 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2222 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2223 | LOG(FATAL) << "Unreachable"; |
| 2224 | UNREACHABLE(); |
| 2225 | } |
| 2226 | |
| 2227 | private: |
| 2228 | friend class SsaBuilder; |
| 2229 | }; |
| 2230 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2231 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2232 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2233 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2234 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2235 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2236 | virtual ~HExpression() {} |
| 2237 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2238 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2239 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2240 | protected: |
| 2241 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2242 | }; |
| 2243 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2244 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2245 | // instruction that branches to the exit block. |
| 2246 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2247 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2248 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2249 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2250 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2251 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2252 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2253 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2254 | |
| 2255 | private: |
| 2256 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2257 | }; |
| 2258 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2259 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2260 | // instruction that branches to the exit block. |
| 2261 | class HReturn : public HTemplateInstruction<1> { |
| 2262 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2263 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2264 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2265 | SetRawInputAt(0, value); |
| 2266 | } |
| 2267 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2268 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2269 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2270 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2271 | |
| 2272 | private: |
| 2273 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2274 | }; |
| 2275 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2276 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2277 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2278 | // exit block. |
| 2279 | class HExit : public HTemplateInstruction<0> { |
| 2280 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2281 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2282 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2283 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2284 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2285 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2286 | |
| 2287 | private: |
| 2288 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2289 | }; |
| 2290 | |
| 2291 | // Jumps from one block to another. |
| 2292 | class HGoto : public HTemplateInstruction<0> { |
| 2293 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2294 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2295 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2296 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2297 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2298 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2299 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2302 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2303 | |
| 2304 | private: |
| 2305 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2306 | }; |
| 2307 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2308 | class HConstant : public HExpression<0> { |
| 2309 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2310 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2311 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2312 | |
| 2313 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2314 | |
| 2315 | virtual bool IsMinusOne() const { return false; } |
| 2316 | virtual bool IsZero() const { return false; } |
| 2317 | virtual bool IsOne() const { return false; } |
| 2318 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2319 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2320 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2321 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2322 | |
| 2323 | private: |
| 2324 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2325 | }; |
| 2326 | |
| 2327 | class HNullConstant : public HConstant { |
| 2328 | public: |
| 2329 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2330 | return true; |
| 2331 | } |
| 2332 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2333 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2334 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2335 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2336 | |
| 2337 | DECLARE_INSTRUCTION(NullConstant); |
| 2338 | |
| 2339 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2340 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2341 | |
| 2342 | friend class HGraph; |
| 2343 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2344 | }; |
| 2345 | |
| 2346 | // Constants of the type int. Those can be from Dex instructions, or |
| 2347 | // synthesized (for example with the if-eqz instruction). |
| 2348 | class HIntConstant : public HConstant { |
| 2349 | public: |
| 2350 | int32_t GetValue() const { return value_; } |
| 2351 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2352 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2353 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2354 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2355 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2356 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2357 | DCHECK(other->IsIntConstant()); |
| 2358 | return other->AsIntConstant()->value_ == value_; |
| 2359 | } |
| 2360 | |
| 2361 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2362 | |
| 2363 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2364 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2365 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2366 | |
| 2367 | DECLARE_INSTRUCTION(IntConstant); |
| 2368 | |
| 2369 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2370 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2371 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2372 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2373 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2374 | |
| 2375 | const int32_t value_; |
| 2376 | |
| 2377 | friend class HGraph; |
| 2378 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2379 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2380 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2381 | }; |
| 2382 | |
| 2383 | class HLongConstant : public HConstant { |
| 2384 | public: |
| 2385 | int64_t GetValue() const { return value_; } |
| 2386 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2387 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2388 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2389 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2390 | DCHECK(other->IsLongConstant()); |
| 2391 | return other->AsLongConstant()->value_ == value_; |
| 2392 | } |
| 2393 | |
| 2394 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2395 | |
| 2396 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2397 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2398 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2399 | |
| 2400 | DECLARE_INSTRUCTION(LongConstant); |
| 2401 | |
| 2402 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2403 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2404 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2405 | |
| 2406 | const int64_t value_; |
| 2407 | |
| 2408 | friend class HGraph; |
| 2409 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2410 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2411 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2412 | // Conditional branch. A block ending with an HIf instruction must have |
| 2413 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2414 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2415 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2416 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2417 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2418 | SetRawInputAt(0, input); |
| 2419 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2420 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2421 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2422 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2423 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2424 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2428 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2431 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2432 | |
| 2433 | private: |
| 2434 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2435 | }; |
| 2436 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2437 | |
| 2438 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2439 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2440 | // non-exceptional control flow. |
| 2441 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2442 | // higher indices in no particular order. |
| 2443 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2444 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2445 | enum BoundaryKind { |
| 2446 | kEntry, |
| 2447 | kExit, |
| 2448 | }; |
| 2449 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2450 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2451 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2452 | |
| 2453 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2454 | |
| 2455 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2456 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2457 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2458 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2459 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2460 | } |
| 2461 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2462 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2463 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2464 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2465 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2466 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | // If not present already, adds `handler` to its block's list of exception |
| 2470 | // handlers. |
| 2471 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2472 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2473 | GetBlock()->AddSuccessor(handler); |
| 2474 | } |
| 2475 | } |
| 2476 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2477 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2478 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2479 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2480 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2481 | DECLARE_INSTRUCTION(TryBoundary); |
| 2482 | |
| 2483 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2484 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2485 | |
| 2486 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2487 | }; |
| 2488 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2489 | // Deoptimize to interpreter, upon checking a condition. |
| 2490 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2491 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2492 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2493 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2494 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2495 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2496 | SetRawInputAt(0, cond); |
| 2497 | } |
| 2498 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2499 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2500 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2501 | return true; |
| 2502 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2503 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2504 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2505 | |
| 2506 | DECLARE_INSTRUCTION(Deoptimize); |
| 2507 | |
| 2508 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2509 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2510 | }; |
| 2511 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2512 | // Represents the ArtMethod that was passed as a first argument to |
| 2513 | // the method. It is used by instructions that depend on it, like |
| 2514 | // instructions that work with the dex cache. |
| 2515 | class HCurrentMethod : public HExpression<0> { |
| 2516 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2517 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2518 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2519 | |
| 2520 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2521 | |
| 2522 | private: |
| 2523 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2524 | }; |
| 2525 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2526 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2527 | // have one successor for each entry in the switch table, and the final successor |
| 2528 | // will be the block containing the next Dex opcode. |
| 2529 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2530 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2531 | HPackedSwitch(int32_t start_value, |
| 2532 | uint32_t num_entries, |
| 2533 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2534 | uint32_t dex_pc = kNoDexPc) |
| 2535 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2536 | start_value_(start_value), |
| 2537 | num_entries_(num_entries) { |
| 2538 | SetRawInputAt(0, input); |
| 2539 | } |
| 2540 | |
| 2541 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2542 | |
| 2543 | int32_t GetStartValue() const { return start_value_; } |
| 2544 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2545 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2546 | |
| 2547 | HBasicBlock* GetDefaultBlock() const { |
| 2548 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2549 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2550 | } |
| 2551 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2552 | |
| 2553 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2554 | const int32_t start_value_; |
| 2555 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2556 | |
| 2557 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2558 | }; |
| 2559 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2560 | class HUnaryOperation : public HExpression<1> { |
| 2561 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2562 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2563 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2564 | SetRawInputAt(0, input); |
| 2565 | } |
| 2566 | |
| 2567 | HInstruction* GetInput() const { return InputAt(0); } |
| 2568 | Primitive::Type GetResultType() const { return GetType(); } |
| 2569 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2570 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2571 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2572 | return true; |
| 2573 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2574 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2575 | // Try to statically evaluate `operation` and return a HConstant |
| 2576 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2577 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2578 | HConstant* TryStaticEvaluation() const; |
| 2579 | |
| 2580 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2581 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2582 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2583 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2584 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2585 | |
| 2586 | private: |
| 2587 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2588 | }; |
| 2589 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2590 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2591 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2592 | HBinaryOperation(Primitive::Type result_type, |
| 2593 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2594 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2595 | SideEffects side_effects = SideEffects::None(), |
| 2596 | uint32_t dex_pc = kNoDexPc) |
| 2597 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2598 | SetRawInputAt(0, left); |
| 2599 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2602 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2603 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2604 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2605 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2606 | virtual bool IsCommutative() const { return false; } |
| 2607 | |
| 2608 | // Put constant on the right. |
| 2609 | // Returns whether order is changed. |
| 2610 | bool OrderInputsWithConstantOnTheRight() { |
| 2611 | HInstruction* left = InputAt(0); |
| 2612 | HInstruction* right = InputAt(1); |
| 2613 | if (left->IsConstant() && !right->IsConstant()) { |
| 2614 | ReplaceInput(right, 0); |
| 2615 | ReplaceInput(left, 1); |
| 2616 | return true; |
| 2617 | } |
| 2618 | return false; |
| 2619 | } |
| 2620 | |
| 2621 | // Order inputs by instruction id, but favor constant on the right side. |
| 2622 | // This helps GVN for commutative ops. |
| 2623 | void OrderInputs() { |
| 2624 | DCHECK(IsCommutative()); |
| 2625 | HInstruction* left = InputAt(0); |
| 2626 | HInstruction* right = InputAt(1); |
| 2627 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2628 | return; |
| 2629 | } |
| 2630 | if (OrderInputsWithConstantOnTheRight()) { |
| 2631 | return; |
| 2632 | } |
| 2633 | // Order according to instruction id. |
| 2634 | if (left->GetId() > right->GetId()) { |
| 2635 | ReplaceInput(right, 0); |
| 2636 | ReplaceInput(left, 1); |
| 2637 | } |
| 2638 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2639 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2640 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2641 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2642 | return true; |
| 2643 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2644 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2645 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2646 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2647 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2648 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2649 | |
| 2650 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2651 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2652 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2653 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2654 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2655 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2656 | return nullptr; |
| 2657 | } |
| 2658 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2659 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2660 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2661 | return nullptr; |
| 2662 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2663 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2664 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| 2665 | VLOG(compiler) << DebugName() << " is not defined for the (null, null) case."; |
| 2666 | return nullptr; |
| 2667 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2668 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2669 | // 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] | 2670 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2671 | HConstant* GetConstantRight() const; |
| 2672 | |
| 2673 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2674 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2675 | HInstruction* GetLeastConstantLeft() const; |
| 2676 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2677 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2678 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2679 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2680 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2681 | }; |
| 2682 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2683 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2684 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2685 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2686 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2687 | kGtBias, // return 1 for NaN comparisons |
| 2688 | kLtBias, // return -1 for NaN comparisons |
| 2689 | }; |
| 2690 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2691 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2692 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2693 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2694 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2695 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2696 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2697 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2698 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2699 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2700 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2701 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2702 | // `instruction`, and disregard moves in between. |
| 2703 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2704 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2705 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2706 | |
| 2707 | virtual IfCondition GetCondition() const = 0; |
| 2708 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2709 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2710 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2711 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2712 | |
| 2713 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2714 | |
| 2715 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2716 | return bias_ == other->AsCondition()->bias_; |
| 2717 | } |
| 2718 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2719 | bool IsFPConditionTrueIfNaN() const { |
| 2720 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2721 | IfCondition if_cond = GetCondition(); |
| 2722 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2723 | } |
| 2724 | |
| 2725 | bool IsFPConditionFalseIfNaN() const { |
| 2726 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2727 | IfCondition if_cond = GetCondition(); |
| 2728 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2729 | } |
| 2730 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2731 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2732 | // For register allocation purposes, returns whether this instruction needs to be |
| 2733 | // materialized (that is, not just be in the processor flags). |
| 2734 | bool needs_materialization_; |
| 2735 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2736 | // Needed if we merge a HCompare into a HCondition. |
| 2737 | ComparisonBias bias_; |
| 2738 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2739 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2740 | }; |
| 2741 | |
| 2742 | // Instruction to check if two inputs are equal to each other. |
| 2743 | class HEqual : public HCondition { |
| 2744 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2745 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2746 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2747 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2748 | bool IsCommutative() const OVERRIDE { return true; } |
| 2749 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2750 | HConstant* Evaluate(HIntConstant* x, HIntConstant* 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 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2754 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2755 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2756 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2757 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2758 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2759 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2760 | return GetBlock()->GetGraph()->GetIntConstant(1); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2761 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2762 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2763 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2764 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2765 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2766 | return kCondEQ; |
| 2767 | } |
| 2768 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2769 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2770 | return kCondNE; |
| 2771 | } |
| 2772 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2773 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2774 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2775 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2776 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2777 | }; |
| 2778 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2779 | class HNotEqual : public HCondition { |
| 2780 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2781 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2782 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2783 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2784 | bool IsCommutative() const OVERRIDE { return true; } |
| 2785 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2786 | HConstant* Evaluate(HIntConstant* x, HIntConstant* 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 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2790 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2791 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2792 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2793 | } |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2794 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2795 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Vladimir Marko | 040db34 | 2015-11-10 19:53:01 +0000 | [diff] [blame] | 2796 | return GetBlock()->GetGraph()->GetIntConstant(0); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 2797 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2798 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2799 | DECLARE_INSTRUCTION(NotEqual); |
| 2800 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2801 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2802 | return kCondNE; |
| 2803 | } |
| 2804 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2805 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2806 | return kCondEQ; |
| 2807 | } |
| 2808 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2809 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2810 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2811 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2812 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2813 | }; |
| 2814 | |
| 2815 | class HLessThan : public HCondition { |
| 2816 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2817 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2818 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2819 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2820 | HConstant* Evaluate(HIntConstant* x, HIntConstant* 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 | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2824 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2825 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2826 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2827 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2828 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2829 | DECLARE_INSTRUCTION(LessThan); |
| 2830 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2831 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2832 | return kCondLT; |
| 2833 | } |
| 2834 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2835 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2836 | return kCondGE; |
| 2837 | } |
| 2838 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2839 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2840 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2841 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2842 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2843 | }; |
| 2844 | |
| 2845 | class HLessThanOrEqual : public HCondition { |
| 2846 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2847 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2848 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2849 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2850 | HConstant* Evaluate(HIntConstant* x, HIntConstant* 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 | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2854 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2855 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2856 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2857 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2858 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2859 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2860 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2861 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2862 | return kCondLE; |
| 2863 | } |
| 2864 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2865 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2866 | return kCondGT; |
| 2867 | } |
| 2868 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2869 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2870 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2871 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2872 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2873 | }; |
| 2874 | |
| 2875 | class HGreaterThan : public HCondition { |
| 2876 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2877 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2878 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2879 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2880 | HConstant* Evaluate(HIntConstant* x, HIntConstant* 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 | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2884 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2885 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2886 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2887 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2888 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2889 | DECLARE_INSTRUCTION(GreaterThan); |
| 2890 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2891 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2892 | return kCondGT; |
| 2893 | } |
| 2894 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2895 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2896 | return kCondLE; |
| 2897 | } |
| 2898 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2899 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2900 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2901 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2902 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2903 | }; |
| 2904 | |
| 2905 | class HGreaterThanOrEqual : public HCondition { |
| 2906 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2907 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2908 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2909 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2910 | HConstant* Evaluate(HIntConstant* x, HIntConstant* 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 | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2914 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2915 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2916 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2917 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2918 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2919 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2920 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2921 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2922 | return kCondGE; |
| 2923 | } |
| 2924 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2925 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2926 | return kCondLT; |
| 2927 | } |
| 2928 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2929 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2930 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2931 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2932 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2933 | }; |
| 2934 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2935 | class HBelow : public HCondition { |
| 2936 | public: |
| 2937 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2938 | : HCondition(first, second, dex_pc) {} |
| 2939 | |
| 2940 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2941 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2942 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2943 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2944 | } |
| 2945 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2946 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2947 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2948 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2949 | } |
| 2950 | |
| 2951 | DECLARE_INSTRUCTION(Below); |
| 2952 | |
| 2953 | IfCondition GetCondition() const OVERRIDE { |
| 2954 | return kCondB; |
| 2955 | } |
| 2956 | |
| 2957 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2958 | return kCondAE; |
| 2959 | } |
| 2960 | |
| 2961 | private: |
| 2962 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2963 | |
| 2964 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 2965 | }; |
| 2966 | |
| 2967 | class HBelowOrEqual : public HCondition { |
| 2968 | public: |
| 2969 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2970 | : HCondition(first, second, dex_pc) {} |
| 2971 | |
| 2972 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2973 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2974 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2975 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2976 | } |
| 2977 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2978 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2979 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2980 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2981 | } |
| 2982 | |
| 2983 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 2984 | |
| 2985 | IfCondition GetCondition() const OVERRIDE { |
| 2986 | return kCondBE; |
| 2987 | } |
| 2988 | |
| 2989 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2990 | return kCondA; |
| 2991 | } |
| 2992 | |
| 2993 | private: |
| 2994 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2995 | |
| 2996 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 2997 | }; |
| 2998 | |
| 2999 | class HAbove : public HCondition { |
| 3000 | public: |
| 3001 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3002 | : HCondition(first, second, dex_pc) {} |
| 3003 | |
| 3004 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3005 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3006 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3007 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3008 | } |
| 3009 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3010 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3011 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3012 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3013 | } |
| 3014 | |
| 3015 | DECLARE_INSTRUCTION(Above); |
| 3016 | |
| 3017 | IfCondition GetCondition() const OVERRIDE { |
| 3018 | return kCondA; |
| 3019 | } |
| 3020 | |
| 3021 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3022 | return kCondBE; |
| 3023 | } |
| 3024 | |
| 3025 | private: |
| 3026 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3027 | |
| 3028 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3029 | }; |
| 3030 | |
| 3031 | class HAboveOrEqual : public HCondition { |
| 3032 | public: |
| 3033 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3034 | : HCondition(first, second, dex_pc) {} |
| 3035 | |
| 3036 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3037 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3038 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 3039 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 3040 | } |
| 3041 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3042 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3043 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 3044 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 3045 | } |
| 3046 | |
| 3047 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3048 | |
| 3049 | IfCondition GetCondition() const OVERRIDE { |
| 3050 | return kCondAE; |
| 3051 | } |
| 3052 | |
| 3053 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3054 | return kCondB; |
| 3055 | } |
| 3056 | |
| 3057 | private: |
| 3058 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3059 | |
| 3060 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3061 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3062 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3063 | // Instruction to check how two inputs compare to each other. |
| 3064 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3065 | class HCompare : public HBinaryOperation { |
| 3066 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3067 | HCompare(Primitive::Type type, |
| 3068 | HInstruction* first, |
| 3069 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3070 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3071 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3072 | : HBinaryOperation(Primitive::kPrimInt, |
| 3073 | first, |
| 3074 | second, |
| 3075 | SideEffectsForArchRuntimeCalls(type), |
| 3076 | dex_pc), |
| 3077 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3078 | DCHECK_EQ(type, first->GetType()); |
| 3079 | DCHECK_EQ(type, second->GetType()); |
| 3080 | } |
| 3081 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3082 | template <typename T> |
| 3083 | 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] | 3084 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3085 | HConstant* Evaluate(HIntConstant* x, HIntConstant* 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 | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3088 | } |
| 3089 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3090 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3091 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3092 | } |
| 3093 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3094 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3095 | return bias_ == other->AsCompare()->bias_; |
| 3096 | } |
| 3097 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3098 | ComparisonBias GetBias() const { return bias_; } |
| 3099 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3100 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3101 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3102 | |
| 3103 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3104 | // MIPS64 uses a runtime call for FP comparisons. |
| 3105 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3106 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3107 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3108 | DECLARE_INSTRUCTION(Compare); |
| 3109 | |
| 3110 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3111 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3112 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3113 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3114 | }; |
| 3115 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3116 | // A local in the graph. Corresponds to a Dex register. |
| 3117 | class HLocal : public HTemplateInstruction<0> { |
| 3118 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3119 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3120 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3121 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3122 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3123 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3124 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3125 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3126 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3127 | // The Dex register number. |
| 3128 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3129 | |
| 3130 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3131 | }; |
| 3132 | |
| 3133 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3134 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3135 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3136 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3137 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3138 | SetRawInputAt(0, local); |
| 3139 | } |
| 3140 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3141 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3142 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3143 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3144 | |
| 3145 | private: |
| 3146 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3147 | }; |
| 3148 | |
| 3149 | // Store a value in a given local. This instruction has two inputs: the value |
| 3150 | // and the local. |
| 3151 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3152 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3153 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3154 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3155 | SetRawInputAt(0, local); |
| 3156 | SetRawInputAt(1, value); |
| 3157 | } |
| 3158 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3159 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3160 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3161 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3162 | |
| 3163 | private: |
| 3164 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3165 | }; |
| 3166 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3167 | class HFloatConstant : public HConstant { |
| 3168 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3169 | float GetValue() const { return value_; } |
| 3170 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3171 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3172 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3173 | } |
| 3174 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3175 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3176 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3177 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3178 | } |
| 3179 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3180 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3181 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3182 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3183 | 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] | 3184 | } |
| 3185 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3186 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3187 | } |
| 3188 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3189 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3190 | } |
| 3191 | bool IsNaN() const { |
| 3192 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3193 | } |
| 3194 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3195 | DECLARE_INSTRUCTION(FloatConstant); |
| 3196 | |
| 3197 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3198 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3199 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3200 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3201 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3202 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3203 | const float value_; |
| 3204 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3205 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3206 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3207 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3208 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3209 | }; |
| 3210 | |
| 3211 | class HDoubleConstant : public HConstant { |
| 3212 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3213 | double GetValue() const { return value_; } |
| 3214 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3215 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3216 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3217 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3218 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3219 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3220 | } |
| 3221 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3222 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3223 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3224 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3225 | 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] | 3226 | } |
| 3227 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3228 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3229 | } |
| 3230 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3231 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3232 | } |
| 3233 | bool IsNaN() const { |
| 3234 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3235 | } |
| 3236 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3237 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3238 | |
| 3239 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3240 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3241 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3242 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3243 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3244 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3245 | const double value_; |
| 3246 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3247 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3248 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3249 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3250 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3251 | }; |
| 3252 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame^] | 3253 | class HNewInstance : public HExpression<2> { |
| 3254 | public: |
| 3255 | HNewInstance(HInstruction* cls, |
| 3256 | HCurrentMethod* current_method, |
| 3257 | uint32_t dex_pc, |
| 3258 | uint16_t type_index, |
| 3259 | const DexFile& dex_file, |
| 3260 | bool can_throw, |
| 3261 | bool finalizable, |
| 3262 | QuickEntrypointEnum entrypoint) |
| 3263 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3264 | type_index_(type_index), |
| 3265 | dex_file_(dex_file), |
| 3266 | can_throw_(can_throw), |
| 3267 | finalizable_(finalizable), |
| 3268 | entrypoint_(entrypoint) { |
| 3269 | SetRawInputAt(0, cls); |
| 3270 | SetRawInputAt(1, current_method); |
| 3271 | } |
| 3272 | |
| 3273 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3274 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3275 | |
| 3276 | // Calls runtime so needs an environment. |
| 3277 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3278 | |
| 3279 | // It may throw when called on type that's not instantiable/accessible. |
| 3280 | // It can throw OOME. |
| 3281 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
| 3282 | bool CanThrow() const OVERRIDE { return can_throw_ || true; } |
| 3283 | |
| 3284 | bool IsFinalizable() const { return finalizable_; } |
| 3285 | |
| 3286 | bool CanBeNull() const OVERRIDE { return false; } |
| 3287 | |
| 3288 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3289 | |
| 3290 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3291 | entrypoint_ = entrypoint; |
| 3292 | } |
| 3293 | |
| 3294 | bool IsStringAlloc() const; |
| 3295 | |
| 3296 | DECLARE_INSTRUCTION(NewInstance); |
| 3297 | |
| 3298 | private: |
| 3299 | const uint16_t type_index_; |
| 3300 | const DexFile& dex_file_; |
| 3301 | const bool can_throw_; |
| 3302 | const bool finalizable_; |
| 3303 | QuickEntrypointEnum entrypoint_; |
| 3304 | |
| 3305 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3306 | }; |
| 3307 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3308 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3309 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3310 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3311 | #include "intrinsics_list.h" |
| 3312 | kNone, |
| 3313 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3314 | #undef INTRINSICS_LIST |
| 3315 | #undef OPTIMIZING_INTRINSICS |
| 3316 | }; |
| 3317 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3318 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3319 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3320 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3321 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3322 | }; |
| 3323 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3324 | enum IntrinsicSideEffects { |
| 3325 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3326 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3327 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3328 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3329 | }; |
| 3330 | |
| 3331 | enum IntrinsicExceptions { |
| 3332 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3333 | kCanThrow // Intrinsic may throw exceptions. |
| 3334 | }; |
| 3335 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3336 | class HInvoke : public HInstruction { |
| 3337 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3338 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3339 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3340 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3341 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3342 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3343 | SetRawInputAt(index, argument); |
| 3344 | } |
| 3345 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3346 | // Return the number of arguments. This number can be lower than |
| 3347 | // the number of inputs returned by InputCount(), as some invoke |
| 3348 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3349 | // inputs at the end of their list of inputs. |
| 3350 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3351 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3352 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3353 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3354 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3355 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3356 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3357 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3358 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3359 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3360 | return intrinsic_; |
| 3361 | } |
| 3362 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3363 | void SetIntrinsic(Intrinsics intrinsic, |
| 3364 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3365 | IntrinsicSideEffects side_effects, |
| 3366 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3367 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3368 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3369 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3370 | } |
| 3371 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3372 | bool CanThrow() const OVERRIDE { return can_throw_; } |
| 3373 | |
| 3374 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3375 | |
| 3376 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3377 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3378 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3379 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3380 | uint32_t* GetIntrinsicOptimizations() { |
| 3381 | return &intrinsic_optimizations_; |
| 3382 | } |
| 3383 | |
| 3384 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3385 | return &intrinsic_optimizations_; |
| 3386 | } |
| 3387 | |
| 3388 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3389 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3390 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3391 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3392 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3393 | HInvoke(ArenaAllocator* arena, |
| 3394 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3395 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3396 | Primitive::Type return_type, |
| 3397 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3398 | uint32_t dex_method_index, |
| 3399 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3400 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3401 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3402 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3403 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3404 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3405 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3406 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3407 | original_invoke_type_(original_invoke_type), |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3408 | can_throw_(true), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3409 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3410 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3411 | } |
| 3412 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3413 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3414 | return inputs_[index]; |
| 3415 | } |
| 3416 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3417 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3418 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3419 | } |
| 3420 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3421 | void SetCanThrow(bool can_throw) { can_throw_ = can_throw; } |
| 3422 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3423 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3424 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3425 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3426 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3427 | const InvokeType original_invoke_type_; |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3428 | bool can_throw_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3429 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3430 | |
| 3431 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3432 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3433 | |
| 3434 | private: |
| 3435 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3436 | }; |
| 3437 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3438 | class HInvokeUnresolved : public HInvoke { |
| 3439 | public: |
| 3440 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3441 | uint32_t number_of_arguments, |
| 3442 | Primitive::Type return_type, |
| 3443 | uint32_t dex_pc, |
| 3444 | uint32_t dex_method_index, |
| 3445 | InvokeType invoke_type) |
| 3446 | : HInvoke(arena, |
| 3447 | number_of_arguments, |
| 3448 | 0u /* number_of_other_inputs */, |
| 3449 | return_type, |
| 3450 | dex_pc, |
| 3451 | dex_method_index, |
| 3452 | invoke_type) { |
| 3453 | } |
| 3454 | |
| 3455 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3456 | |
| 3457 | private: |
| 3458 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3459 | }; |
| 3460 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3461 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3462 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3463 | // Requirements of this method call regarding the class |
| 3464 | // initialization (clinit) check of its declaring class. |
| 3465 | enum class ClinitCheckRequirement { |
| 3466 | kNone, // Class already initialized. |
| 3467 | kExplicit, // Static call having explicit clinit check as last input. |
| 3468 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3469 | }; |
| 3470 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3471 | // Determines how to load the target ArtMethod*. |
| 3472 | enum class MethodLoadKind { |
| 3473 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3474 | kStringInit, |
| 3475 | |
| 3476 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3477 | kRecursive, |
| 3478 | |
| 3479 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3480 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3481 | kDirectAddress, |
| 3482 | |
| 3483 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3484 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3485 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3486 | // the image relocatable or not. |
| 3487 | kDirectAddressWithFixup, |
| 3488 | |
| 3489 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3490 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3491 | // may cause class initialization (the entry may point to a resolution method), |
| 3492 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3493 | kDexCachePcRelative, |
| 3494 | |
| 3495 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3496 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3497 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3498 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3499 | kDexCacheViaMethod, |
| 3500 | }; |
| 3501 | |
| 3502 | // Determines the location of the code pointer. |
| 3503 | enum class CodePtrLocation { |
| 3504 | // Recursive call, use local PC-relative call instruction. |
| 3505 | kCallSelf, |
| 3506 | |
| 3507 | // Use PC-relative call instruction patched at link time. |
| 3508 | // Used for calls within an oat file, boot->boot or app->app. |
| 3509 | kCallPCRelative, |
| 3510 | |
| 3511 | // Call to a known target address, embed the direct address in code. |
| 3512 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3513 | kCallDirect, |
| 3514 | |
| 3515 | // Call to a target address that will be known at link time, embed the direct |
| 3516 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3517 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3518 | // the image relocatable or not. |
| 3519 | kCallDirectWithFixup, |
| 3520 | |
| 3521 | // Use code pointer from the ArtMethod*. |
| 3522 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3523 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3524 | kCallArtMethod, |
| 3525 | }; |
| 3526 | |
| 3527 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3528 | MethodLoadKind method_load_kind; |
| 3529 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3530 | // The method load data holds |
| 3531 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3532 | // Note that there are multiple string init methods, each having its own offset. |
| 3533 | // - the method address for kDirectAddress |
| 3534 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3535 | uint64_t method_load_data; |
| 3536 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3537 | }; |
| 3538 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3539 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3540 | uint32_t number_of_arguments, |
| 3541 | Primitive::Type return_type, |
| 3542 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3543 | uint32_t method_index, |
| 3544 | MethodReference target_method, |
| 3545 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3546 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3547 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3548 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3549 | : HInvoke(arena, |
| 3550 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3551 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3552 | // potentially one other if the clinit check is explicit, and potentially |
| 3553 | // one other if the method is a string factory. |
| 3554 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3555 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3556 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3557 | return_type, |
| 3558 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3559 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3560 | original_invoke_type), |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3561 | optimized_invoke_type_(optimized_invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3562 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3563 | target_method_(target_method), |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3564 | dispatch_info_(dispatch_info) { } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3565 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3566 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3567 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3568 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3569 | |
| 3570 | // Using the current method is the default and once we find a better |
| 3571 | // method load kind, we should not go back to using the current method. |
| 3572 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3573 | |
| 3574 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3575 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3576 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3577 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3578 | dispatch_info_ = dispatch_info; |
| 3579 | } |
| 3580 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3581 | void AddSpecialInput(HInstruction* input) { |
| 3582 | // We allow only one special input. |
| 3583 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3584 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3585 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3586 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3587 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3588 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3589 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3590 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3591 | // TODO: for intrinsics we can generate implicit null checks. |
| 3592 | return false; |
| 3593 | } |
| 3594 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3595 | bool CanBeNull() const OVERRIDE { |
| 3596 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3597 | } |
| 3598 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3599 | // Get the index of the special input, if any. |
| 3600 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame^] | 3601 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3602 | // method pointer; otherwise there may be one platform-specific special input, |
| 3603 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3604 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
| 3605 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3606 | InvokeType GetOptimizedInvokeType() const { return optimized_invoke_type_; } |
| 3607 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
| 3608 | optimized_invoke_type_ = invoke_type; |
| 3609 | } |
| 3610 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3611 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3612 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3613 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3614 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3615 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3616 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3617 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3618 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3619 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3620 | bool HasCurrentMethodInput() const { |
| 3621 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3622 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3623 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3624 | return true; |
| 3625 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3626 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3627 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3628 | return false; |
| 3629 | } |
| 3630 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3631 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3632 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3633 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3634 | |
| 3635 | int32_t GetStringInitOffset() const { |
| 3636 | DCHECK(IsStringInit()); |
| 3637 | return dispatch_info_.method_load_data; |
| 3638 | } |
| 3639 | |
| 3640 | uint64_t GetMethodAddress() const { |
| 3641 | DCHECK(HasMethodAddress()); |
| 3642 | return dispatch_info_.method_load_data; |
| 3643 | } |
| 3644 | |
| 3645 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3646 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3647 | return dispatch_info_.method_load_data; |
| 3648 | } |
| 3649 | |
| 3650 | uint64_t GetDirectCodePtr() const { |
| 3651 | DCHECK(HasDirectCodePtr()); |
| 3652 | return dispatch_info_.direct_code_ptr; |
| 3653 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3654 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3655 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3656 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3657 | // Is this instruction a call to a static method? |
| 3658 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3659 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3660 | } |
| 3661 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3662 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3663 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3664 | // instruction; only relevant for static calls with explicit clinit check. |
| 3665 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3666 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3667 | size_t last_input_index = InputCount() - 1; |
| 3668 | HInstruction* last_input = InputAt(last_input_index); |
| 3669 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3670 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3671 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3672 | inputs_.pop_back(); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3673 | clinit_check_requirement_ = new_requirement; |
| 3674 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3675 | } |
| 3676 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame^] | 3677 | HNewInstance* GetThisArgumentOfStringInit() const { |
| 3678 | DCHECK(IsStringInit()); |
| 3679 | size_t index = InputCount() - 1; |
| 3680 | DCHECK(InputAt(index)->IsNewInstance()); |
| 3681 | return InputAt(index)->AsNewInstance(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3682 | } |
| 3683 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame^] | 3684 | void RemoveThisArgumentOfStringInit() { |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3685 | DCHECK(IsStringInit()); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame^] | 3686 | size_t index = InputCount() - 1; |
| 3687 | DCHECK(InputAt(index)->IsNewInstance()); |
| 3688 | RemoveAsUserOfInput(index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3689 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3690 | } |
| 3691 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3692 | // 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] | 3693 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3694 | bool IsStaticWithExplicitClinitCheck() const { |
| 3695 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3696 | } |
| 3697 | |
| 3698 | // Is this a call to a static method whose declaring class has an |
| 3699 | // implicit intialization check requirement? |
| 3700 | bool IsStaticWithImplicitClinitCheck() const { |
| 3701 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3702 | } |
| 3703 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3704 | // Does this method load kind need the current method as an input? |
| 3705 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 3706 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 3707 | } |
| 3708 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3709 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3710 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3711 | protected: |
| 3712 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3713 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3714 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3715 | HInstruction* input = input_record.GetInstruction(); |
| 3716 | // `input` is the last input of a static invoke marked as having |
| 3717 | // an explicit clinit check. It must either be: |
| 3718 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3719 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3720 | DCHECK(input != nullptr); |
| 3721 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3722 | } |
| 3723 | return input_record; |
| 3724 | } |
| 3725 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3726 | void InsertInputAt(size_t index, HInstruction* input); |
| 3727 | void RemoveInputAt(size_t index); |
| 3728 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3729 | private: |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3730 | InvokeType optimized_invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3731 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3732 | // The target method may refer to different dex file or method index than the original |
| 3733 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3734 | // in derived class to increase visibility. |
| 3735 | MethodReference target_method_; |
| 3736 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3737 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3738 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3739 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 3740 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3741 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3742 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3743 | class HInvokeVirtual : public HInvoke { |
| 3744 | public: |
| 3745 | HInvokeVirtual(ArenaAllocator* arena, |
| 3746 | uint32_t number_of_arguments, |
| 3747 | Primitive::Type return_type, |
| 3748 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3749 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3750 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3751 | : 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] | 3752 | vtable_index_(vtable_index) {} |
| 3753 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3754 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3755 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3756 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3757 | } |
| 3758 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3759 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3760 | |
| 3761 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3762 | |
| 3763 | private: |
| 3764 | const uint32_t vtable_index_; |
| 3765 | |
| 3766 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3767 | }; |
| 3768 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3769 | class HInvokeInterface : public HInvoke { |
| 3770 | public: |
| 3771 | HInvokeInterface(ArenaAllocator* arena, |
| 3772 | uint32_t number_of_arguments, |
| 3773 | Primitive::Type return_type, |
| 3774 | uint32_t dex_pc, |
| 3775 | uint32_t dex_method_index, |
| 3776 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3777 | : 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] | 3778 | imt_index_(imt_index) {} |
| 3779 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3780 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3781 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3782 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3783 | } |
| 3784 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3785 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3786 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3787 | |
| 3788 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3789 | |
| 3790 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3791 | const uint32_t imt_index_; |
| 3792 | |
| 3793 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3794 | }; |
| 3795 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3796 | class HNeg : public HUnaryOperation { |
| 3797 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3798 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3799 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3800 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3801 | template <typename T> T Compute(T x) const { return -x; } |
| 3802 | |
| 3803 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3804 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3805 | } |
| 3806 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3807 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3808 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3809 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3810 | DECLARE_INSTRUCTION(Neg); |
| 3811 | |
| 3812 | private: |
| 3813 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3814 | }; |
| 3815 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3816 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3817 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3818 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3819 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3820 | uint32_t dex_pc, |
| 3821 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3822 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3823 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3824 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3825 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3826 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3827 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3828 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3829 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3830 | } |
| 3831 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3832 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3833 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3834 | |
| 3835 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3836 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3837 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3838 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3839 | bool CanThrow() const OVERRIDE { return true; } |
| 3840 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3841 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3842 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3843 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3844 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3845 | DECLARE_INSTRUCTION(NewArray); |
| 3846 | |
| 3847 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3848 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3849 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3850 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3851 | |
| 3852 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3853 | }; |
| 3854 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3855 | class HAdd : public HBinaryOperation { |
| 3856 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3857 | HAdd(Primitive::Type result_type, |
| 3858 | HInstruction* left, |
| 3859 | HInstruction* right, |
| 3860 | uint32_t dex_pc = kNoDexPc) |
| 3861 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3862 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3863 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3864 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3865 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3866 | |
| 3867 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3868 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3869 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3870 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3871 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3872 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3873 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3874 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3875 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3876 | DECLARE_INSTRUCTION(Add); |
| 3877 | |
| 3878 | private: |
| 3879 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3880 | }; |
| 3881 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3882 | class HSub : public HBinaryOperation { |
| 3883 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3884 | HSub(Primitive::Type result_type, |
| 3885 | HInstruction* left, |
| 3886 | HInstruction* right, |
| 3887 | uint32_t dex_pc = kNoDexPc) |
| 3888 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3889 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3890 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3891 | |
| 3892 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3893 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3894 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3895 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3896 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3897 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3898 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3899 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3900 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3901 | DECLARE_INSTRUCTION(Sub); |
| 3902 | |
| 3903 | private: |
| 3904 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3905 | }; |
| 3906 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3907 | class HMul : public HBinaryOperation { |
| 3908 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3909 | HMul(Primitive::Type result_type, |
| 3910 | HInstruction* left, |
| 3911 | HInstruction* right, |
| 3912 | uint32_t dex_pc = kNoDexPc) |
| 3913 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3914 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3915 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3916 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3917 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3918 | |
| 3919 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3920 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3921 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3922 | } |
| 3923 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3924 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3925 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3926 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3927 | |
| 3928 | DECLARE_INSTRUCTION(Mul); |
| 3929 | |
| 3930 | private: |
| 3931 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3932 | }; |
| 3933 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3934 | class HDiv : public HBinaryOperation { |
| 3935 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3936 | HDiv(Primitive::Type result_type, |
| 3937 | HInstruction* left, |
| 3938 | HInstruction* right, |
| 3939 | uint32_t dex_pc) |
| 3940 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3941 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3942 | template <typename T> |
| 3943 | T Compute(T x, T y) const { |
| 3944 | // Our graph structure ensures we never have 0 for `y` during |
| 3945 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3946 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3947 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3948 | return (y == -1) ? -x : x / y; |
| 3949 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3950 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3951 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3952 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3953 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3954 | } |
| 3955 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3956 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3957 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3958 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3959 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3960 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3961 | // The generated code can use a runtime call. |
| 3962 | return SideEffects::CanTriggerGC(); |
| 3963 | } |
| 3964 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3965 | DECLARE_INSTRUCTION(Div); |
| 3966 | |
| 3967 | private: |
| 3968 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3969 | }; |
| 3970 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3971 | class HRem : public HBinaryOperation { |
| 3972 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3973 | HRem(Primitive::Type result_type, |
| 3974 | HInstruction* left, |
| 3975 | HInstruction* right, |
| 3976 | uint32_t dex_pc) |
| 3977 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3978 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3979 | template <typename T> |
| 3980 | T Compute(T x, T y) const { |
| 3981 | // Our graph structure ensures we never have 0 for `y` during |
| 3982 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3983 | DCHECK_NE(y, 0); |
| 3984 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3985 | return (y == -1) ? 0 : x % y; |
| 3986 | } |
| 3987 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3988 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3989 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3990 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3991 | } |
| 3992 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3993 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3994 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3995 | } |
| 3996 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3997 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3998 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3999 | return SideEffects::CanTriggerGC(); |
| 4000 | } |
| 4001 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4002 | DECLARE_INSTRUCTION(Rem); |
| 4003 | |
| 4004 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4005 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4006 | }; |
| 4007 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4008 | class HDivZeroCheck : public HExpression<1> { |
| 4009 | public: |
| 4010 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4011 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4012 | SetRawInputAt(0, value); |
| 4013 | } |
| 4014 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4015 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4016 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4017 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4018 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4019 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4020 | return true; |
| 4021 | } |
| 4022 | |
| 4023 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4024 | bool CanThrow() const OVERRIDE { return true; } |
| 4025 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4026 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4027 | |
| 4028 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4029 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4030 | }; |
| 4031 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4032 | class HShl : public HBinaryOperation { |
| 4033 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4034 | HShl(Primitive::Type result_type, |
| 4035 | HInstruction* left, |
| 4036 | HInstruction* right, |
| 4037 | uint32_t dex_pc = kNoDexPc) |
| 4038 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4039 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4040 | template <typename T, typename U, typename V> |
| 4041 | T Compute(T x, U y, V max_shift_value) const { |
| 4042 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4043 | "V is not the unsigned integer type corresponding to T"); |
| 4044 | return x << (y & max_shift_value); |
| 4045 | } |
| 4046 | |
| 4047 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4048 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4049 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4050 | } |
| 4051 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4052 | // case is handled as `x << static_cast<int>(y)`. |
| 4053 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4054 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4055 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4056 | } |
| 4057 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4058 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4059 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4060 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4061 | |
| 4062 | DECLARE_INSTRUCTION(Shl); |
| 4063 | |
| 4064 | private: |
| 4065 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4066 | }; |
| 4067 | |
| 4068 | class HShr : public HBinaryOperation { |
| 4069 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4070 | HShr(Primitive::Type result_type, |
| 4071 | HInstruction* left, |
| 4072 | HInstruction* right, |
| 4073 | uint32_t dex_pc = kNoDexPc) |
| 4074 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4075 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4076 | template <typename T, typename U, typename V> |
| 4077 | T Compute(T x, U y, V max_shift_value) const { |
| 4078 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4079 | "V is not the unsigned integer type corresponding to T"); |
| 4080 | return x >> (y & max_shift_value); |
| 4081 | } |
| 4082 | |
| 4083 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4084 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4085 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4086 | } |
| 4087 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4088 | // case is handled as `x >> static_cast<int>(y)`. |
| 4089 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4090 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4091 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4092 | } |
| 4093 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4094 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4095 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4096 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4097 | |
| 4098 | DECLARE_INSTRUCTION(Shr); |
| 4099 | |
| 4100 | private: |
| 4101 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4102 | }; |
| 4103 | |
| 4104 | class HUShr : public HBinaryOperation { |
| 4105 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4106 | HUShr(Primitive::Type result_type, |
| 4107 | HInstruction* left, |
| 4108 | HInstruction* right, |
| 4109 | uint32_t dex_pc = kNoDexPc) |
| 4110 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4111 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4112 | template <typename T, typename U, typename V> |
| 4113 | T Compute(T x, U y, V max_shift_value) const { |
| 4114 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4115 | "V is not the unsigned integer type corresponding to T"); |
| 4116 | V ux = static_cast<V>(x); |
| 4117 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4118 | } |
| 4119 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4120 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4121 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4122 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4123 | } |
| 4124 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 4125 | // case is handled as `x >>> static_cast<int>(y)`. |
| 4126 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4127 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4128 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4129 | } |
| 4130 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4131 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4132 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | DECLARE_INSTRUCTION(UShr); |
| 4136 | |
| 4137 | private: |
| 4138 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4139 | }; |
| 4140 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4141 | class HAnd : public HBinaryOperation { |
| 4142 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4143 | HAnd(Primitive::Type result_type, |
| 4144 | HInstruction* left, |
| 4145 | HInstruction* right, |
| 4146 | uint32_t dex_pc = kNoDexPc) |
| 4147 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4148 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4149 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4150 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4151 | template <typename T, typename U> |
| 4152 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 4153 | |
| 4154 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4155 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4156 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4157 | } |
| 4158 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4159 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4160 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4161 | } |
| 4162 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4163 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4164 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4165 | } |
| 4166 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4167 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4168 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4169 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4170 | |
| 4171 | DECLARE_INSTRUCTION(And); |
| 4172 | |
| 4173 | private: |
| 4174 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4175 | }; |
| 4176 | |
| 4177 | class HOr : public HBinaryOperation { |
| 4178 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4179 | HOr(Primitive::Type result_type, |
| 4180 | HInstruction* left, |
| 4181 | HInstruction* right, |
| 4182 | uint32_t dex_pc = kNoDexPc) |
| 4183 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4184 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4185 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4186 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4187 | template <typename T, typename U> |
| 4188 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4189 | |
| 4190 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4191 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4192 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4193 | } |
| 4194 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4195 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4196 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4197 | } |
| 4198 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4199 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4200 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4201 | } |
| 4202 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4203 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4204 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4205 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4206 | |
| 4207 | DECLARE_INSTRUCTION(Or); |
| 4208 | |
| 4209 | private: |
| 4210 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4211 | }; |
| 4212 | |
| 4213 | class HXor : public HBinaryOperation { |
| 4214 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4215 | HXor(Primitive::Type result_type, |
| 4216 | HInstruction* left, |
| 4217 | HInstruction* right, |
| 4218 | uint32_t dex_pc = kNoDexPc) |
| 4219 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4220 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4221 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4222 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4223 | template <typename T, typename U> |
| 4224 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4225 | |
| 4226 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4227 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4228 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4229 | } |
| 4230 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4231 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4232 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4233 | } |
| 4234 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4235 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4236 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4237 | } |
| 4238 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4239 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4240 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4241 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4242 | |
| 4243 | DECLARE_INSTRUCTION(Xor); |
| 4244 | |
| 4245 | private: |
| 4246 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4247 | }; |
| 4248 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4249 | class HRor : public HBinaryOperation { |
| 4250 | public: |
| 4251 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
| 4252 | : HBinaryOperation(result_type, value, distance) {} |
| 4253 | |
| 4254 | template <typename T, typename U, typename V> |
| 4255 | T Compute(T x, U y, V max_shift_value) const { |
| 4256 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4257 | "V is not the unsigned integer type corresponding to T"); |
| 4258 | V ux = static_cast<V>(x); |
| 4259 | if ((y & max_shift_value) == 0) { |
| 4260 | return static_cast<T>(ux); |
| 4261 | } else { |
| 4262 | const V reg_bits = sizeof(T) * 8; |
| 4263 | return static_cast<T>(ux >> (y & max_shift_value)) | |
| 4264 | (x << (reg_bits - (y & max_shift_value))); |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4269 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4270 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
| 4271 | } |
| 4272 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4273 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4274 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4275 | } |
| 4276 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4277 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4278 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4279 | } |
| 4280 | |
| 4281 | DECLARE_INSTRUCTION(Ror); |
| 4282 | |
| 4283 | private: |
| 4284 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4285 | }; |
| 4286 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4287 | // The value of a parameter in this method. Its location depends on |
| 4288 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4289 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4290 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4291 | HParameterValue(const DexFile& dex_file, |
| 4292 | uint16_t type_index, |
| 4293 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4294 | Primitive::Type parameter_type, |
| 4295 | bool is_this = false) |
| 4296 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4297 | dex_file_(dex_file), |
| 4298 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4299 | index_(index), |
| 4300 | is_this_(is_this), |
| 4301 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4302 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4303 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4304 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4305 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4306 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4307 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4308 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4309 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4310 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4311 | DECLARE_INSTRUCTION(ParameterValue); |
| 4312 | |
| 4313 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4314 | const DexFile& dex_file_; |
| 4315 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4316 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4317 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4318 | const uint8_t index_; |
| 4319 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4320 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4321 | const bool is_this_; |
| 4322 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4323 | bool can_be_null_; |
| 4324 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4325 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4326 | }; |
| 4327 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4328 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4329 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4330 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4331 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4332 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4333 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4334 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4335 | return true; |
| 4336 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4337 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4338 | template <typename T> T Compute(T x) const { return ~x; } |
| 4339 | |
| 4340 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4341 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4342 | } |
| 4343 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4344 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4345 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4346 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4347 | DECLARE_INSTRUCTION(Not); |
| 4348 | |
| 4349 | private: |
| 4350 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4351 | }; |
| 4352 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4353 | class HBooleanNot : public HUnaryOperation { |
| 4354 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4355 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4356 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4357 | |
| 4358 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4359 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4360 | return true; |
| 4361 | } |
| 4362 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4363 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4364 | DCHECK(IsUint<1>(x)); |
| 4365 | return !x; |
| 4366 | } |
| 4367 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4368 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4369 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4370 | } |
| 4371 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4372 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4373 | UNREACHABLE(); |
| 4374 | } |
| 4375 | |
| 4376 | DECLARE_INSTRUCTION(BooleanNot); |
| 4377 | |
| 4378 | private: |
| 4379 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4380 | }; |
| 4381 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4382 | class HTypeConversion : public HExpression<1> { |
| 4383 | public: |
| 4384 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4385 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4386 | : HExpression(result_type, |
| 4387 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4388 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4389 | SetRawInputAt(0, input); |
| 4390 | DCHECK_NE(input->GetType(), result_type); |
| 4391 | } |
| 4392 | |
| 4393 | HInstruction* GetInput() const { return InputAt(0); } |
| 4394 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4395 | Primitive::Type GetResultType() const { return GetType(); } |
| 4396 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4397 | // 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] | 4398 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4399 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4400 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4401 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4402 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4403 | // Try to statically evaluate the conversion and return a HConstant |
| 4404 | // containing the result. If the input cannot be converted, return nullptr. |
| 4405 | HConstant* TryStaticEvaluation() const; |
| 4406 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4407 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4408 | Primitive::Type result_type) { |
| 4409 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4410 | // in the compilation process we do not know what architecture we will |
| 4411 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4412 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4413 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4414 | return SideEffects::CanTriggerGC(); |
| 4415 | } |
| 4416 | return SideEffects::None(); |
| 4417 | } |
| 4418 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4419 | DECLARE_INSTRUCTION(TypeConversion); |
| 4420 | |
| 4421 | private: |
| 4422 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4423 | }; |
| 4424 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4425 | static constexpr uint32_t kNoRegNumber = -1; |
| 4426 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4427 | class HPhi : public HInstruction { |
| 4428 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4429 | HPhi(ArenaAllocator* arena, |
| 4430 | uint32_t reg_number, |
| 4431 | size_t number_of_inputs, |
| 4432 | Primitive::Type type, |
| 4433 | uint32_t dex_pc = kNoDexPc) |
| 4434 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4435 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4436 | reg_number_(reg_number), |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4437 | type_(ToPhiType(type)), |
| 4438 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4439 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4440 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4441 | is_live_(true), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4442 | can_be_null_(true) { |
David Brazdil | 809d70f | 2015-11-19 10:29:39 +0000 | [diff] [blame] | 4443 | DCHECK_NE(type_, Primitive::kPrimVoid); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4444 | } |
| 4445 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4446 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4447 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4448 | switch (type) { |
| 4449 | case Primitive::kPrimBoolean: |
| 4450 | case Primitive::kPrimByte: |
| 4451 | case Primitive::kPrimShort: |
| 4452 | case Primitive::kPrimChar: |
| 4453 | return Primitive::kPrimInt; |
| 4454 | default: |
| 4455 | return type; |
| 4456 | } |
| 4457 | } |
| 4458 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4459 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4460 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4461 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4462 | |
| 4463 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4464 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4465 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4466 | Primitive::Type GetType() const OVERRIDE { return type_; } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4467 | void SetType(Primitive::Type new_type) { |
| 4468 | // Make sure that only valid type changes occur. The following are allowed: |
| 4469 | // (1) int -> float/ref (primitive type propagation), |
| 4470 | // (2) long -> double (primitive type propagation). |
| 4471 | DCHECK(type_ == new_type || |
| 4472 | (type_ == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 4473 | (type_ == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 4474 | (type_ == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 4475 | type_ = new_type; |
| 4476 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4477 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4478 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4479 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4480 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4481 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4482 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4483 | void SetDead() { is_live_ = false; } |
| 4484 | void SetLive() { is_live_ = true; } |
| 4485 | bool IsDead() const { return !is_live_; } |
| 4486 | bool IsLive() const { return is_live_; } |
| 4487 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4488 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4489 | return other != nullptr |
| 4490 | && other->IsPhi() |
| 4491 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4492 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4493 | } |
| 4494 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4495 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4496 | // An equivalent phi is a phi having the same dex register and type. |
| 4497 | // It assumes that phis with the same dex register are adjacent. |
| 4498 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4499 | HInstruction* next = GetNext(); |
| 4500 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4501 | if (next->GetType() == GetType()) { |
| 4502 | return next->AsPhi(); |
| 4503 | } |
| 4504 | next = next->GetNext(); |
| 4505 | } |
| 4506 | return nullptr; |
| 4507 | } |
| 4508 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4509 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4510 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4511 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4512 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4513 | return inputs_[index]; |
| 4514 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4515 | |
| 4516 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4517 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4518 | } |
| 4519 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4520 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4521 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4522 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4523 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4524 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4525 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4526 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4527 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4528 | }; |
| 4529 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4530 | class HNullCheck : public HExpression<1> { |
| 4531 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4532 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4533 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4534 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4535 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4536 | SetRawInputAt(0, value); |
| 4537 | } |
| 4538 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4539 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4540 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4541 | return true; |
| 4542 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4543 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4544 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4545 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4546 | bool CanThrow() const OVERRIDE { return true; } |
| 4547 | |
| 4548 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4549 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4550 | |
| 4551 | DECLARE_INSTRUCTION(NullCheck); |
| 4552 | |
| 4553 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4554 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4555 | }; |
| 4556 | |
| 4557 | class FieldInfo : public ValueObject { |
| 4558 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4559 | FieldInfo(MemberOffset field_offset, |
| 4560 | Primitive::Type field_type, |
| 4561 | bool is_volatile, |
| 4562 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4563 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4564 | const DexFile& dex_file, |
| 4565 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4566 | : field_offset_(field_offset), |
| 4567 | field_type_(field_type), |
| 4568 | is_volatile_(is_volatile), |
| 4569 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4570 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4571 | dex_file_(dex_file), |
| 4572 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4573 | |
| 4574 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4575 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4576 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4577 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4578 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4579 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4580 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4581 | |
| 4582 | private: |
| 4583 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4584 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4585 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4586 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4587 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4588 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4589 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4590 | }; |
| 4591 | |
| 4592 | class HInstanceFieldGet : public HExpression<1> { |
| 4593 | public: |
| 4594 | HInstanceFieldGet(HInstruction* value, |
| 4595 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4596 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4597 | bool is_volatile, |
| 4598 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4599 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4600 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4601 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4602 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4603 | : HExpression(field_type, |
| 4604 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4605 | dex_pc), |
| 4606 | field_info_(field_offset, |
| 4607 | field_type, |
| 4608 | is_volatile, |
| 4609 | field_idx, |
| 4610 | declaring_class_def_index, |
| 4611 | dex_file, |
| 4612 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4613 | SetRawInputAt(0, value); |
| 4614 | } |
| 4615 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4616 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4617 | |
| 4618 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4619 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4620 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4621 | } |
| 4622 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4623 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4624 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4625 | } |
| 4626 | |
| 4627 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4628 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4629 | } |
| 4630 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4631 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4632 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4633 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4634 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4635 | |
| 4636 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4637 | |
| 4638 | private: |
| 4639 | const FieldInfo field_info_; |
| 4640 | |
| 4641 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4642 | }; |
| 4643 | |
| 4644 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4645 | public: |
| 4646 | HInstanceFieldSet(HInstruction* object, |
| 4647 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4648 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4649 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4650 | bool is_volatile, |
| 4651 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4652 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4653 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4654 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4655 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4656 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4657 | dex_pc), |
| 4658 | field_info_(field_offset, |
| 4659 | field_type, |
| 4660 | is_volatile, |
| 4661 | field_idx, |
| 4662 | declaring_class_def_index, |
| 4663 | dex_file, |
| 4664 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4665 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4666 | SetRawInputAt(0, object); |
| 4667 | SetRawInputAt(1, value); |
| 4668 | } |
| 4669 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4670 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4671 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4672 | } |
| 4673 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4674 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4675 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4676 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4677 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4678 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4679 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4680 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4681 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4682 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4683 | |
| 4684 | private: |
| 4685 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4686 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4687 | |
| 4688 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4689 | }; |
| 4690 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4691 | class HArrayGet : public HExpression<2> { |
| 4692 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4693 | HArrayGet(HInstruction* array, |
| 4694 | HInstruction* index, |
| 4695 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4696 | uint32_t dex_pc, |
| 4697 | SideEffects additional_side_effects = SideEffects::None()) |
| 4698 | : HExpression(type, |
| 4699 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 4700 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4701 | SetRawInputAt(0, array); |
| 4702 | SetRawInputAt(1, index); |
| 4703 | } |
| 4704 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4705 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4706 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4707 | return true; |
| 4708 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4709 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4710 | // TODO: We can be smarter here. |
| 4711 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4712 | // which generates the implicit null check. There are cases when these can be removed |
| 4713 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4714 | // implicit check here (as long as the address falls in the first page). |
| 4715 | return false; |
| 4716 | } |
| 4717 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4718 | bool IsEquivalentOf(HArrayGet* other) const { |
| 4719 | bool result = (GetDexPc() == other->GetDexPc()); |
| 4720 | if (kIsDebugBuild && result) { |
| 4721 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 4722 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 4723 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 4724 | if (Primitive::IsIntOrLongType(GetType())) { |
| 4725 | DCHECK(Primitive::IsFloatingPointType(other->GetType())); |
| 4726 | } else { |
| 4727 | DCHECK(Primitive::IsFloatingPointType(GetType())); |
| 4728 | DCHECK(Primitive::IsIntOrLongType(other->GetType())); |
| 4729 | } |
| 4730 | } |
| 4731 | return result; |
| 4732 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4733 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4734 | HInstruction* GetArray() const { return InputAt(0); } |
| 4735 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4736 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4737 | DECLARE_INSTRUCTION(ArrayGet); |
| 4738 | |
| 4739 | private: |
| 4740 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4741 | }; |
| 4742 | |
| 4743 | class HArraySet : public HTemplateInstruction<3> { |
| 4744 | public: |
| 4745 | HArraySet(HInstruction* array, |
| 4746 | HInstruction* index, |
| 4747 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4748 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4749 | uint32_t dex_pc, |
| 4750 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4751 | : HTemplateInstruction( |
| 4752 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4753 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4754 | additional_side_effects), |
| 4755 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4756 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4757 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4758 | value_can_be_null_(true), |
| 4759 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4760 | SetRawInputAt(0, array); |
| 4761 | SetRawInputAt(1, index); |
| 4762 | SetRawInputAt(2, value); |
| 4763 | } |
| 4764 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4765 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4766 | // We currently always call a runtime method to catch array store |
| 4767 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4768 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4769 | } |
| 4770 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4771 | // Can throw ArrayStoreException. |
| 4772 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4773 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4774 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4775 | // TODO: Same as for ArrayGet. |
| 4776 | return false; |
| 4777 | } |
| 4778 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4779 | void ClearNeedsTypeCheck() { |
| 4780 | needs_type_check_ = false; |
| 4781 | } |
| 4782 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4783 | void ClearValueCanBeNull() { |
| 4784 | value_can_be_null_ = false; |
| 4785 | } |
| 4786 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4787 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4788 | static_type_of_array_is_object_array_ = true; |
| 4789 | } |
| 4790 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4791 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4792 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4793 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4794 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4795 | HInstruction* GetArray() const { return InputAt(0); } |
| 4796 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4797 | HInstruction* GetValue() const { return InputAt(2); } |
| 4798 | |
| 4799 | Primitive::Type GetComponentType() const { |
| 4800 | // The Dex format does not type floating point index operations. Since the |
| 4801 | // `expected_component_type_` is set during building and can therefore not |
| 4802 | // be correct, we also check what is the value type. If it is a floating |
| 4803 | // point type, we must use that type. |
| 4804 | Primitive::Type value_type = GetValue()->GetType(); |
| 4805 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4806 | ? value_type |
| 4807 | : expected_component_type_; |
| 4808 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4809 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4810 | Primitive::Type GetRawExpectedComponentType() const { |
| 4811 | return expected_component_type_; |
| 4812 | } |
| 4813 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4814 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4815 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4816 | } |
| 4817 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4818 | DECLARE_INSTRUCTION(ArraySet); |
| 4819 | |
| 4820 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4821 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4822 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4823 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4824 | // Cached information for the reference_type_info_ so that codegen |
| 4825 | // does not need to inspect the static type. |
| 4826 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4827 | |
| 4828 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4829 | }; |
| 4830 | |
| 4831 | class HArrayLength : public HExpression<1> { |
| 4832 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4833 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4834 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4835 | // Note that arrays do not change length, so the instruction does not |
| 4836 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4837 | SetRawInputAt(0, array); |
| 4838 | } |
| 4839 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4840 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4841 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4842 | return true; |
| 4843 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4844 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4845 | return obj == InputAt(0); |
| 4846 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4847 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4848 | DECLARE_INSTRUCTION(ArrayLength); |
| 4849 | |
| 4850 | private: |
| 4851 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4852 | }; |
| 4853 | |
| 4854 | class HBoundsCheck : public HExpression<2> { |
| 4855 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4856 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 4857 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4858 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4859 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4860 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4861 | SetRawInputAt(0, index); |
| 4862 | SetRawInputAt(1, length); |
| 4863 | } |
| 4864 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4865 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4866 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4867 | return true; |
| 4868 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4869 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4870 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4871 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4872 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4873 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4874 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4875 | |
| 4876 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4877 | |
| 4878 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4879 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4880 | }; |
| 4881 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4882 | /** |
| 4883 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4884 | * to stay live until the last HInstruction. This class |
| 4885 | * 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] | 4886 | * HInstruction stays live. `index` represents the stack location index of the |
| 4887 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4888 | */ |
| 4889 | class HTemporary : public HTemplateInstruction<0> { |
| 4890 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4891 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4892 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4893 | |
| 4894 | size_t GetIndex() const { return index_; } |
| 4895 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4896 | Primitive::Type GetType() const OVERRIDE { |
| 4897 | // The previous instruction is the one that will be stored in the temporary location. |
| 4898 | DCHECK(GetPrevious() != nullptr); |
| 4899 | return GetPrevious()->GetType(); |
| 4900 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4901 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4902 | DECLARE_INSTRUCTION(Temporary); |
| 4903 | |
| 4904 | private: |
| 4905 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4906 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4907 | }; |
| 4908 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4909 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4910 | public: |
| 4911 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4912 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4913 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4914 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4915 | return true; |
| 4916 | } |
| 4917 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4918 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4919 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4920 | |
| 4921 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4922 | |
| 4923 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4924 | // Only used for code generation, in order to share the same slow path between back edges |
| 4925 | // of a same loop. |
| 4926 | SlowPathCode* slow_path_; |
| 4927 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4928 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4929 | }; |
| 4930 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 4931 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 4932 | // It ensures that we can generate line number and local variables at this point. |
| 4933 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 4934 | public: |
| 4935 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 4936 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 4937 | |
| 4938 | bool NeedsEnvironment() const OVERRIDE { |
| 4939 | return true; |
| 4940 | } |
| 4941 | |
| 4942 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 4943 | |
| 4944 | private: |
| 4945 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 4946 | }; |
| 4947 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4948 | /** |
| 4949 | * Instruction to load a Class object. |
| 4950 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4951 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4952 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4953 | HLoadClass(HCurrentMethod* current_method, |
| 4954 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4955 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4956 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4957 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4958 | bool needs_access_check, |
| 4959 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4960 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4961 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4962 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4963 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4964 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4965 | needs_access_check_(needs_access_check), |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4966 | is_in_dex_cache_(is_in_dex_cache), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4967 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4968 | // Referrers class should not need access check. We never inline unverified |
| 4969 | // methods so we can't possibly end up in this situation. |
| 4970 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4971 | SetRawInputAt(0, current_method); |
| 4972 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4973 | |
| 4974 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4975 | |
| 4976 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 4977 | // Note that we don't need to test for generate_clinit_check_. |
| 4978 | // Whether or not we need to generate the clinit check is processed in |
| 4979 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4980 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 4981 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4982 | } |
| 4983 | |
| 4984 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4985 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4986 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4987 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4988 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4989 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4990 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4991 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4992 | } |
| 4993 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4994 | bool MustGenerateClinitCheck() const { |
| 4995 | return generate_clinit_check_; |
| 4996 | } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 4997 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4998 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 4999 | // The entrypoint the code generator is going to call does not do |
| 5000 | // clinit of the class. |
| 5001 | DCHECK(!NeedsAccessCheck()); |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5002 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5006 | return MustGenerateClinitCheck() || |
| 5007 | (!is_referrers_class_ && !is_in_dex_cache_) || |
| 5008 | needs_access_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | bool NeedsAccessCheck() const { |
| 5012 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5013 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5014 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5015 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5016 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5017 | } |
| 5018 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5019 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5020 | return loaded_class_rti_; |
| 5021 | } |
| 5022 | |
| 5023 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5024 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5025 | DCHECK(rti.IsExact()); |
| 5026 | loaded_class_rti_ = rti; |
| 5027 | } |
| 5028 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5029 | const DexFile& GetDexFile() { return dex_file_; } |
| 5030 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5031 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5032 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5033 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5034 | return SideEffects::CanTriggerGC(); |
| 5035 | } |
| 5036 | |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5037 | bool IsInDexCache() const { return is_in_dex_cache_; } |
| 5038 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5039 | DECLARE_INSTRUCTION(LoadClass); |
| 5040 | |
| 5041 | private: |
| 5042 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5043 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5044 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5045 | // Whether this instruction must generate the initialization check. |
| 5046 | // Used for code generation. |
| 5047 | bool generate_clinit_check_; |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5048 | const bool needs_access_check_; |
| 5049 | const bool is_in_dex_cache_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5050 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5051 | ReferenceTypeInfo loaded_class_rti_; |
| 5052 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5053 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5054 | }; |
| 5055 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5056 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5057 | public: |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5058 | HLoadString(HCurrentMethod* current_method, |
| 5059 | uint32_t string_index, |
| 5060 | uint32_t dex_pc, |
| 5061 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5062 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5063 | string_index_(string_index), |
| 5064 | is_in_dex_cache_(is_in_dex_cache) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5065 | SetRawInputAt(0, current_method); |
| 5066 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5067 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5068 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5069 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5070 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5071 | return other->AsLoadString()->string_index_ == string_index_; |
| 5072 | } |
| 5073 | |
| 5074 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5075 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5076 | uint32_t GetStringIndex() const { return string_index_; } |
| 5077 | |
| 5078 | // TODO: Can we deopt or debug when we resolve a string? |
| 5079 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5080 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5081 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5082 | bool IsInDexCache() const { return is_in_dex_cache_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5083 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5084 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5085 | return SideEffects::CanTriggerGC(); |
| 5086 | } |
| 5087 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5088 | DECLARE_INSTRUCTION(LoadString); |
| 5089 | |
| 5090 | private: |
| 5091 | const uint32_t string_index_; |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5092 | const bool is_in_dex_cache_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5093 | |
| 5094 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5095 | }; |
| 5096 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5097 | /** |
| 5098 | * Performs an initialization check on its Class object input. |
| 5099 | */ |
| 5100 | class HClinitCheck : public HExpression<1> { |
| 5101 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5102 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5103 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5104 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5105 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5106 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5107 | SetRawInputAt(0, constant); |
| 5108 | } |
| 5109 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5110 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5111 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5112 | return true; |
| 5113 | } |
| 5114 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5115 | bool NeedsEnvironment() const OVERRIDE { |
| 5116 | // May call runtime to initialize the class. |
| 5117 | return true; |
| 5118 | } |
| 5119 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5120 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5121 | |
| 5122 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5123 | |
| 5124 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5125 | |
| 5126 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5127 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5128 | }; |
| 5129 | |
| 5130 | class HStaticFieldGet : public HExpression<1> { |
| 5131 | public: |
| 5132 | HStaticFieldGet(HInstruction* cls, |
| 5133 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5134 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5135 | bool is_volatile, |
| 5136 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5137 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5138 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5139 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5140 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5141 | : HExpression(field_type, |
| 5142 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5143 | dex_pc), |
| 5144 | field_info_(field_offset, |
| 5145 | field_type, |
| 5146 | is_volatile, |
| 5147 | field_idx, |
| 5148 | declaring_class_def_index, |
| 5149 | dex_file, |
| 5150 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5151 | SetRawInputAt(0, cls); |
| 5152 | } |
| 5153 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5154 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5155 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5156 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5157 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5158 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5159 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | size_t ComputeHashCode() const OVERRIDE { |
| 5163 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5164 | } |
| 5165 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5166 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5167 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5168 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5169 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5170 | |
| 5171 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5172 | |
| 5173 | private: |
| 5174 | const FieldInfo field_info_; |
| 5175 | |
| 5176 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5177 | }; |
| 5178 | |
| 5179 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5180 | public: |
| 5181 | HStaticFieldSet(HInstruction* cls, |
| 5182 | HInstruction* value, |
| 5183 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5184 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5185 | bool is_volatile, |
| 5186 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5187 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5188 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5189 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5190 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5191 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5192 | dex_pc), |
| 5193 | field_info_(field_offset, |
| 5194 | field_type, |
| 5195 | is_volatile, |
| 5196 | field_idx, |
| 5197 | declaring_class_def_index, |
| 5198 | dex_file, |
| 5199 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5200 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5201 | SetRawInputAt(0, cls); |
| 5202 | SetRawInputAt(1, value); |
| 5203 | } |
| 5204 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5205 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5206 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5207 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5208 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5209 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5210 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5211 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 5212 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5213 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5214 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5215 | |
| 5216 | private: |
| 5217 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5218 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5219 | |
| 5220 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5221 | }; |
| 5222 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5223 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5224 | public: |
| 5225 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5226 | Primitive::Type field_type, |
| 5227 | uint32_t field_index, |
| 5228 | uint32_t dex_pc) |
| 5229 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5230 | field_index_(field_index) { |
| 5231 | SetRawInputAt(0, obj); |
| 5232 | } |
| 5233 | |
| 5234 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5235 | bool CanThrow() const OVERRIDE { return true; } |
| 5236 | |
| 5237 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5238 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5239 | |
| 5240 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5241 | |
| 5242 | private: |
| 5243 | const uint32_t field_index_; |
| 5244 | |
| 5245 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5246 | }; |
| 5247 | |
| 5248 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5249 | public: |
| 5250 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5251 | HInstruction* value, |
| 5252 | Primitive::Type field_type, |
| 5253 | uint32_t field_index, |
| 5254 | uint32_t dex_pc) |
| 5255 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5256 | field_type_(field_type), |
| 5257 | field_index_(field_index) { |
| 5258 | DCHECK_EQ(field_type, value->GetType()); |
| 5259 | SetRawInputAt(0, obj); |
| 5260 | SetRawInputAt(1, value); |
| 5261 | } |
| 5262 | |
| 5263 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5264 | bool CanThrow() const OVERRIDE { return true; } |
| 5265 | |
| 5266 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5267 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5268 | |
| 5269 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5270 | |
| 5271 | private: |
| 5272 | const Primitive::Type field_type_; |
| 5273 | const uint32_t field_index_; |
| 5274 | |
| 5275 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5276 | }; |
| 5277 | |
| 5278 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5279 | public: |
| 5280 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5281 | uint32_t field_index, |
| 5282 | uint32_t dex_pc) |
| 5283 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5284 | field_index_(field_index) { |
| 5285 | } |
| 5286 | |
| 5287 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5288 | bool CanThrow() const OVERRIDE { return true; } |
| 5289 | |
| 5290 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5291 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5292 | |
| 5293 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5294 | |
| 5295 | private: |
| 5296 | const uint32_t field_index_; |
| 5297 | |
| 5298 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5299 | }; |
| 5300 | |
| 5301 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5302 | public: |
| 5303 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5304 | Primitive::Type field_type, |
| 5305 | uint32_t field_index, |
| 5306 | uint32_t dex_pc) |
| 5307 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5308 | field_type_(field_type), |
| 5309 | field_index_(field_index) { |
| 5310 | DCHECK_EQ(field_type, value->GetType()); |
| 5311 | SetRawInputAt(0, value); |
| 5312 | } |
| 5313 | |
| 5314 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5315 | bool CanThrow() const OVERRIDE { return true; } |
| 5316 | |
| 5317 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5318 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5319 | |
| 5320 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5321 | |
| 5322 | private: |
| 5323 | const Primitive::Type field_type_; |
| 5324 | const uint32_t field_index_; |
| 5325 | |
| 5326 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5327 | }; |
| 5328 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5329 | // Implement the move-exception DEX instruction. |
| 5330 | class HLoadException : public HExpression<0> { |
| 5331 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5332 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5333 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5334 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5335 | bool CanBeNull() const OVERRIDE { return false; } |
| 5336 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5337 | DECLARE_INSTRUCTION(LoadException); |
| 5338 | |
| 5339 | private: |
| 5340 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5341 | }; |
| 5342 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5343 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5344 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5345 | class HClearException : public HTemplateInstruction<0> { |
| 5346 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5347 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5348 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5349 | |
| 5350 | DECLARE_INSTRUCTION(ClearException); |
| 5351 | |
| 5352 | private: |
| 5353 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5354 | }; |
| 5355 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5356 | class HThrow : public HTemplateInstruction<1> { |
| 5357 | public: |
| 5358 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5359 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5360 | SetRawInputAt(0, exception); |
| 5361 | } |
| 5362 | |
| 5363 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5364 | |
| 5365 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5366 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5367 | bool CanThrow() const OVERRIDE { return true; } |
| 5368 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5369 | |
| 5370 | DECLARE_INSTRUCTION(Throw); |
| 5371 | |
| 5372 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5373 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5374 | }; |
| 5375 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5376 | /** |
| 5377 | * Implementation strategies for the code generator of a HInstanceOf |
| 5378 | * or `HCheckCast`. |
| 5379 | */ |
| 5380 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5381 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5382 | kExactCheck, // Can do a single class compare. |
| 5383 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5384 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5385 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5386 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5387 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5388 | }; |
| 5389 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5390 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5391 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5392 | HInstanceOf(HInstruction* object, |
| 5393 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5394 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5395 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5396 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5397 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5398 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5399 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5400 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5401 | SetRawInputAt(0, object); |
| 5402 | SetRawInputAt(1, constant); |
| 5403 | } |
| 5404 | |
| 5405 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5406 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5407 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5408 | return true; |
| 5409 | } |
| 5410 | |
| 5411 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5412 | return false; |
| 5413 | } |
| 5414 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5415 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5416 | |
| 5417 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5418 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5419 | // Used only in code generation. |
| 5420 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5421 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5422 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5423 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 5424 | return (check_kind == TypeCheckKind::kExactCheck) |
| 5425 | ? SideEffects::None() |
| 5426 | // Mips currently does runtime calls for any other checks. |
| 5427 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5428 | } |
| 5429 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5430 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5431 | |
| 5432 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5433 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5434 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5435 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5436 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5437 | }; |
| 5438 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5439 | class HBoundType : public HExpression<1> { |
| 5440 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5441 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5442 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5443 | upper_bound_(ReferenceTypeInfo::CreateInvalid()), |
| 5444 | upper_can_be_null_(true), |
| 5445 | can_be_null_(true) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5446 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5447 | SetRawInputAt(0, input); |
| 5448 | } |
| 5449 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5450 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5451 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5452 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5453 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5454 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5455 | void SetCanBeNull(bool can_be_null) { |
| 5456 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5457 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5458 | } |
| 5459 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5460 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5461 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5462 | DECLARE_INSTRUCTION(BoundType); |
| 5463 | |
| 5464 | private: |
| 5465 | // 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] | 5466 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5467 | // It is used to bound the type in cases like: |
| 5468 | // if (x instanceof ClassX) { |
| 5469 | // // uper_bound_ will be ClassX |
| 5470 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5471 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5472 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5473 | // is false then can_be_null_ cannot be true). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5474 | bool upper_can_be_null_; |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5475 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5476 | |
| 5477 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5478 | }; |
| 5479 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5480 | class HCheckCast : public HTemplateInstruction<2> { |
| 5481 | public: |
| 5482 | HCheckCast(HInstruction* object, |
| 5483 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5484 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5485 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5486 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5487 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5488 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5489 | SetRawInputAt(0, object); |
| 5490 | SetRawInputAt(1, constant); |
| 5491 | } |
| 5492 | |
| 5493 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5494 | |
| 5495 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5496 | return true; |
| 5497 | } |
| 5498 | |
| 5499 | bool NeedsEnvironment() const OVERRIDE { |
| 5500 | // Instruction may throw a CheckCastError. |
| 5501 | return true; |
| 5502 | } |
| 5503 | |
| 5504 | bool CanThrow() const OVERRIDE { return true; } |
| 5505 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5506 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5507 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5508 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5509 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5510 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5511 | |
| 5512 | DECLARE_INSTRUCTION(CheckCast); |
| 5513 | |
| 5514 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5515 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5516 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5517 | |
| 5518 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5519 | }; |
| 5520 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5521 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5522 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5523 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5524 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5525 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5526 | barrier_kind_(barrier_kind) {} |
| 5527 | |
| 5528 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5529 | |
| 5530 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5531 | |
| 5532 | private: |
| 5533 | const MemBarrierKind barrier_kind_; |
| 5534 | |
| 5535 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5536 | }; |
| 5537 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5538 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5539 | public: |
| 5540 | enum OperationKind { |
| 5541 | kEnter, |
| 5542 | kExit, |
| 5543 | }; |
| 5544 | |
| 5545 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5546 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5547 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5548 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5549 | SetRawInputAt(0, object); |
| 5550 | } |
| 5551 | |
| 5552 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5553 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5554 | |
| 5555 | bool CanThrow() const OVERRIDE { |
| 5556 | // Verifier guarantees that monitor-exit cannot throw. |
| 5557 | // This is important because it allows the HGraphBuilder to remove |
| 5558 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5559 | return IsEnter(); |
| 5560 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5561 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5562 | |
| 5563 | bool IsEnter() const { return kind_ == kEnter; } |
| 5564 | |
| 5565 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5566 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5567 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5568 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5569 | |
| 5570 | private: |
| 5571 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5572 | }; |
| 5573 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5574 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5575 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5576 | MoveOperands(Location source, |
| 5577 | Location destination, |
| 5578 | Primitive::Type type, |
| 5579 | HInstruction* instruction) |
| 5580 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5581 | |
| 5582 | Location GetSource() const { return source_; } |
| 5583 | Location GetDestination() const { return destination_; } |
| 5584 | |
| 5585 | void SetSource(Location value) { source_ = value; } |
| 5586 | void SetDestination(Location value) { destination_ = value; } |
| 5587 | |
| 5588 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5589 | // destination (but not the source). |
| 5590 | Location MarkPending() { |
| 5591 | DCHECK(!IsPending()); |
| 5592 | Location dest = destination_; |
| 5593 | destination_ = Location::NoLocation(); |
| 5594 | return dest; |
| 5595 | } |
| 5596 | |
| 5597 | void ClearPending(Location dest) { |
| 5598 | DCHECK(IsPending()); |
| 5599 | destination_ = dest; |
| 5600 | } |
| 5601 | |
| 5602 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5603 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 5604 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | // True if this blocks a move from the given location. |
| 5608 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5609 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5610 | } |
| 5611 | |
| 5612 | // A move is redundant if it's been eliminated, if its source and |
| 5613 | // destination are the same, or if its destination is unneeded. |
| 5614 | bool IsRedundant() const { |
| 5615 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5616 | } |
| 5617 | |
| 5618 | // We clear both operands to indicate move that's been eliminated. |
| 5619 | void Eliminate() { |
| 5620 | source_ = destination_ = Location::NoLocation(); |
| 5621 | } |
| 5622 | |
| 5623 | bool IsEliminated() const { |
| 5624 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5625 | return source_.IsInvalid(); |
| 5626 | } |
| 5627 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5628 | Primitive::Type GetType() const { return type_; } |
| 5629 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5630 | bool Is64BitMove() const { |
| 5631 | return Primitive::Is64BitType(type_); |
| 5632 | } |
| 5633 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5634 | HInstruction* GetInstruction() const { return instruction_; } |
| 5635 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5636 | private: |
| 5637 | Location source_; |
| 5638 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5639 | // The type this move is for. |
| 5640 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5641 | // The instruction this move is assocatied with. Null when this move is |
| 5642 | // for moving an input in the expected locations of user (including a phi user). |
| 5643 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5644 | // in the same parallel move. |
| 5645 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5646 | }; |
| 5647 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 5648 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 5649 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5650 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5651 | |
| 5652 | class HParallelMove : public HTemplateInstruction<0> { |
| 5653 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5654 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5655 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5656 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5657 | moves_.reserve(kDefaultNumberOfMoves); |
| 5658 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5659 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5660 | void AddMove(Location source, |
| 5661 | Location destination, |
| 5662 | Primitive::Type type, |
| 5663 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5664 | DCHECK(source.IsValid()); |
| 5665 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5666 | if (kIsDebugBuild) { |
| 5667 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5668 | for (const MoveOperands& move : moves_) { |
| 5669 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5670 | // Special case the situation where the move is for the spill slot |
| 5671 | // of the instruction. |
| 5672 | if ((GetPrevious() == instruction) |
| 5673 | || ((GetPrevious() == nullptr) |
| 5674 | && instruction->IsPhi() |
| 5675 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5676 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5677 | << "Doing parallel moves for the same instruction."; |
| 5678 | } else { |
| 5679 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5680 | } |
| 5681 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5682 | } |
| 5683 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5684 | for (const MoveOperands& move : moves_) { |
| 5685 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5686 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5687 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5688 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5689 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5690 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5691 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5692 | } |
| 5693 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5694 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5695 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5696 | } |
| 5697 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5698 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5699 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5700 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5701 | |
| 5702 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5703 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5704 | |
| 5705 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5706 | }; |
| 5707 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5708 | } // namespace art |
| 5709 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 5710 | #ifdef ART_ENABLE_CODEGEN_arm |
| 5711 | #include "nodes_arm.h" |
| 5712 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5713 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5714 | #include "nodes_arm64.h" |
| 5715 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5716 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5717 | #include "nodes_x86.h" |
| 5718 | #endif |
| 5719 | |
| 5720 | namespace art { |
| 5721 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5722 | class HGraphVisitor : public ValueObject { |
| 5723 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5724 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5725 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5726 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5727 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5728 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5729 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5730 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5731 | void VisitInsertionOrder(); |
| 5732 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5733 | // Visit the graph following dominator tree reverse post-order. |
| 5734 | void VisitReversePostOrder(); |
| 5735 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5736 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5737 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5738 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5739 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5740 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5741 | |
| 5742 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5743 | |
| 5744 | #undef DECLARE_VISIT_INSTRUCTION |
| 5745 | |
| 5746 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5747 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5748 | |
| 5749 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5750 | }; |
| 5751 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5752 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5753 | public: |
| 5754 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5755 | virtual ~HGraphDelegateVisitor() {} |
| 5756 | |
| 5757 | // Visit functions that delegate to to super class. |
| 5758 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5759 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5760 | |
| 5761 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5762 | |
| 5763 | #undef DECLARE_VISIT_INSTRUCTION |
| 5764 | |
| 5765 | private: |
| 5766 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5767 | }; |
| 5768 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5769 | class HInsertionOrderIterator : public ValueObject { |
| 5770 | public: |
| 5771 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5772 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5773 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5774 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5775 | void Advance() { ++index_; } |
| 5776 | |
| 5777 | private: |
| 5778 | const HGraph& graph_; |
| 5779 | size_t index_; |
| 5780 | |
| 5781 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5782 | }; |
| 5783 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5784 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5785 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5786 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5787 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5788 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5789 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5790 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5791 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5792 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5793 | void Advance() { ++index_; } |
| 5794 | |
| 5795 | private: |
| 5796 | const HGraph& graph_; |
| 5797 | size_t index_; |
| 5798 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5799 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5800 | }; |
| 5801 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5802 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5803 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5804 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5805 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5806 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5807 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5808 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5809 | |
| 5810 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5811 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5812 | void Advance() { --index_; } |
| 5813 | |
| 5814 | private: |
| 5815 | const HGraph& graph_; |
| 5816 | size_t index_; |
| 5817 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5818 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5819 | }; |
| 5820 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5821 | class HLinearPostOrderIterator : public ValueObject { |
| 5822 | public: |
| 5823 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5824 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5825 | |
| 5826 | bool Done() const { return index_ == 0; } |
| 5827 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5828 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5829 | |
| 5830 | void Advance() { |
| 5831 | --index_; |
| 5832 | DCHECK_GE(index_, 0U); |
| 5833 | } |
| 5834 | |
| 5835 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5836 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5837 | size_t index_; |
| 5838 | |
| 5839 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5840 | }; |
| 5841 | |
| 5842 | class HLinearOrderIterator : public ValueObject { |
| 5843 | public: |
| 5844 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5845 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5846 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5847 | bool Done() const { return index_ == order_.size(); } |
| 5848 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5849 | void Advance() { ++index_; } |
| 5850 | |
| 5851 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5852 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5853 | size_t index_; |
| 5854 | |
| 5855 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5856 | }; |
| 5857 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5858 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5859 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5860 | // block id. |
| 5861 | class HBlocksInLoopIterator : public ValueObject { |
| 5862 | public: |
| 5863 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5864 | : blocks_in_loop_(info.GetBlocks()), |
| 5865 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5866 | index_(0) { |
| 5867 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5868 | Advance(); |
| 5869 | } |
| 5870 | } |
| 5871 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5872 | bool Done() const { return index_ == blocks_.size(); } |
| 5873 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5874 | void Advance() { |
| 5875 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5876 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5877 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5878 | break; |
| 5879 | } |
| 5880 | } |
| 5881 | } |
| 5882 | |
| 5883 | private: |
| 5884 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5885 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5886 | size_t index_; |
| 5887 | |
| 5888 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5889 | }; |
| 5890 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5891 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5892 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5893 | // post order. |
| 5894 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5895 | public: |
| 5896 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5897 | : blocks_in_loop_(info.GetBlocks()), |
| 5898 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5899 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5900 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5901 | Advance(); |
| 5902 | } |
| 5903 | } |
| 5904 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5905 | bool Done() const { return index_ == blocks_.size(); } |
| 5906 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5907 | void Advance() { |
| 5908 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5909 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5910 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5911 | break; |
| 5912 | } |
| 5913 | } |
| 5914 | } |
| 5915 | |
| 5916 | private: |
| 5917 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5918 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5919 | size_t index_; |
| 5920 | |
| 5921 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5922 | }; |
| 5923 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5924 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5925 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5926 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5927 | : constant->AsLongConstant()->GetValue(); |
| 5928 | } |
| 5929 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5930 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5931 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5932 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5933 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5934 | // times and provide different class resolution but no two class loaders should ever |
| 5935 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5936 | // all sorts of weird failures. |
| 5937 | return &lhs == &rhs; |
| 5938 | } |
| 5939 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 5940 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 5941 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 5942 | inline const H##type* HInstruction::As##type() const { \ |
| 5943 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 5944 | } \ |
| 5945 | inline H##type* HInstruction::As##type() { \ |
| 5946 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 5947 | } |
| 5948 | |
| 5949 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 5950 | #undef INSTRUCTION_TYPE_CHECK |
| 5951 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5952 | } // namespace art |
| 5953 | |
| 5954 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |