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 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 100 | enum GraphAnalysisResult { |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 101 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 102 | kAnalysisFailThrowCatchLoop, |
| 103 | kAnalysisFailAmbiguousArrayOp, |
| 104 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 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); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 134 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 135 | void Add(const HInstructionList& instruction_list); |
| 136 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 137 | // Return the number of instructions in the list. This is an expensive operation. |
| 138 | size_t CountSize() const; |
| 139 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 140 | private: |
| 141 | HInstruction* first_instruction_; |
| 142 | HInstruction* last_instruction_; |
| 143 | |
| 144 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 145 | friend class HGraph; |
| 146 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 147 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 148 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 149 | |
| 150 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 151 | }; |
| 152 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 153 | class ReferenceTypeInfo : ValueObject { |
| 154 | public: |
| 155 | typedef Handle<mirror::Class> TypeHandle; |
| 156 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 157 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 158 | |
| 159 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 160 | return ReferenceTypeInfo(type_handle, is_exact); |
| 161 | } |
| 162 | |
| 163 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 164 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 165 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 166 | return handle.GetReference() != nullptr; |
| 167 | } |
| 168 | |
| 169 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 170 | return IsValidHandle(type_handle_); |
| 171 | } |
| 172 | |
| 173 | bool IsExact() const { return is_exact_; } |
| 174 | |
| 175 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 176 | DCHECK(IsValid()); |
| 177 | return GetTypeHandle()->IsObjectClass(); |
| 178 | } |
| 179 | |
| 180 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 181 | DCHECK(IsValid()); |
| 182 | return GetTypeHandle()->IsStringClass(); |
| 183 | } |
| 184 | |
| 185 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 186 | DCHECK(IsValid()); |
| 187 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 188 | } |
| 189 | |
| 190 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 191 | DCHECK(IsValid()); |
| 192 | return GetTypeHandle()->IsInterface(); |
| 193 | } |
| 194 | |
| 195 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 196 | DCHECK(IsValid()); |
| 197 | return GetTypeHandle()->IsArrayClass(); |
| 198 | } |
| 199 | |
| 200 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 201 | DCHECK(IsValid()); |
| 202 | return GetTypeHandle()->IsPrimitiveArray(); |
| 203 | } |
| 204 | |
| 205 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 206 | DCHECK(IsValid()); |
| 207 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 208 | } |
| 209 | |
| 210 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 211 | DCHECK(IsValid()); |
| 212 | if (!IsExact()) return false; |
| 213 | if (!IsArrayClass()) return false; |
| 214 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 215 | } |
| 216 | |
| 217 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 218 | DCHECK(IsValid()); |
| 219 | if (!IsExact()) return false; |
| 220 | if (!IsArrayClass()) return false; |
| 221 | if (!rti.IsArrayClass()) return false; |
| 222 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 223 | rti.GetTypeHandle()->GetComponentType()); |
| 224 | } |
| 225 | |
| 226 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 227 | |
| 228 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 229 | DCHECK(IsValid()); |
| 230 | DCHECK(rti.IsValid()); |
| 231 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 232 | } |
| 233 | |
| 234 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 235 | DCHECK(IsValid()); |
| 236 | DCHECK(rti.IsValid()); |
| 237 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 238 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 239 | } |
| 240 | |
| 241 | // Returns true if the type information provide the same amount of details. |
| 242 | // Note that it does not mean that the instructions have the same actual type |
| 243 | // (because the type can be the result of a merge). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 244 | bool IsEqual(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 245 | if (!IsValid() && !rti.IsValid()) { |
| 246 | // Invalid types are equal. |
| 247 | return true; |
| 248 | } |
| 249 | if (!IsValid() || !rti.IsValid()) { |
| 250 | // One is valid, the other not. |
| 251 | return false; |
| 252 | } |
| 253 | return IsExact() == rti.IsExact() |
| 254 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 255 | } |
| 256 | |
| 257 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 258 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 259 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 260 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 261 | |
| 262 | // The class of the object. |
| 263 | TypeHandle type_handle_; |
| 264 | // Whether or not the type is exact or a superclass of the actual type. |
| 265 | // Whether or not we have any information about this type. |
| 266 | bool is_exact_; |
| 267 | }; |
| 268 | |
| 269 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 270 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 271 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 272 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 273 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 274 | HGraph(ArenaAllocator* arena, |
| 275 | const DexFile& dex_file, |
| 276 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 277 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 278 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 279 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 280 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 281 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 282 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 283 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 284 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 285 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 286 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 287 | entry_block_(nullptr), |
| 288 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 289 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 290 | number_of_vregs_(0), |
| 291 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 292 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 293 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 294 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 295 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 296 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 297 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 298 | dex_file_(dex_file), |
| 299 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 300 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 301 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 302 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 303 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 304 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 305 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 306 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 307 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 308 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 309 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 310 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| 311 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 312 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 313 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 314 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 315 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
| 316 | void InitializeInexactObjectRTI(StackHandleScopeCollection* handles); |
| 317 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 318 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 319 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 320 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 321 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 322 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 323 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 324 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 325 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 326 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 327 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 328 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 329 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 330 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 331 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 332 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 333 | void ComputeDominanceInformation(); |
| 334 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 335 | void ClearLoopInformation(); |
| 336 | void FindBackEdges(ArenaBitVector* visited); |
| 337 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 338 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 339 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 340 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 341 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 342 | // was successful or the reason for failure. The method will fail if a loop |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 343 | // is a throw-catch loop, i.e. the header is a catch block. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 344 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 345 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 346 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 347 | // order and loop information. |
| 348 | void ComputeTryBlockInformation(); |
| 349 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 350 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 351 | // Returns the instruction to replace the invoke expression or null if the |
| 352 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 353 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 354 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 355 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 356 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 357 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 358 | // should be the new back edge. |
| 359 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 360 | HBasicBlock* reference, |
| 361 | bool replace_if_back_edge); |
| 362 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 363 | // Need to add a couple of blocks to test if the loop body is entered and |
| 364 | // put deoptimization instructions, etc. |
| 365 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 366 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 367 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 368 | // other blocks and has no instructions or phis. |
| 369 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 370 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 371 | // Splits the edge between `block` and `successor` while preserving the |
| 372 | // indices in the predecessor/successor lists. If there are multiple edges |
| 373 | // between the blocks, the lowest indices are used. |
| 374 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 375 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 376 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 377 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 378 | void SimplifyLoop(HBasicBlock* header); |
| 379 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 380 | int32_t GetNextInstructionId() { |
| 381 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 382 | return current_instruction_id_++; |
| 383 | } |
| 384 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 385 | int32_t GetCurrentInstructionId() const { |
| 386 | return current_instruction_id_; |
| 387 | } |
| 388 | |
| 389 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame^] | 390 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 391 | current_instruction_id_ = id; |
| 392 | } |
| 393 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 394 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 395 | return maximum_number_of_out_vregs_; |
| 396 | } |
| 397 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 398 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 399 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 402 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 403 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 404 | } |
| 405 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 406 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 407 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 410 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 411 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 412 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 413 | } |
| 414 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 415 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 416 | number_of_vregs_ = number_of_vregs; |
| 417 | } |
| 418 | |
| 419 | uint16_t GetNumberOfVRegs() const { |
| 420 | return number_of_vregs_; |
| 421 | } |
| 422 | |
| 423 | void SetNumberOfInVRegs(uint16_t value) { |
| 424 | number_of_in_vregs_ = value; |
| 425 | } |
| 426 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 427 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 428 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 429 | return number_of_vregs_ - number_of_in_vregs_; |
| 430 | } |
| 431 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 432 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 433 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 434 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 435 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 436 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 437 | return linear_order_; |
| 438 | } |
| 439 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 440 | bool HasBoundsChecks() const { |
| 441 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 442 | } |
| 443 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 444 | void SetHasBoundsChecks(bool value) { |
| 445 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 448 | bool ShouldGenerateConstructorBarrier() const { |
| 449 | return should_generate_constructor_barrier_; |
| 450 | } |
| 451 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 452 | bool IsDebuggable() const { return debuggable_; } |
| 453 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 454 | // 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] | 455 | // already, it is created and inserted into the graph. This method is only for |
| 456 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 457 | 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] | 458 | |
| 459 | // TODO: This is problematic for the consistency of reference type propagation |
| 460 | // because it can be created anytime after the pass and thus it will be left |
| 461 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 462 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 463 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 464 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 465 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 466 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 467 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 468 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 469 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 470 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 471 | 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] | 472 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 473 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 474 | 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] | 475 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 476 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 477 | HCurrentMethod* GetCurrentMethod(); |
| 478 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 479 | const DexFile& GetDexFile() const { |
| 480 | return dex_file_; |
| 481 | } |
| 482 | |
| 483 | uint32_t GetMethodIdx() const { |
| 484 | return method_idx_; |
| 485 | } |
| 486 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 487 | InvokeType GetInvokeType() const { |
| 488 | return invoke_type_; |
| 489 | } |
| 490 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 491 | InstructionSet GetInstructionSet() const { |
| 492 | return instruction_set_; |
| 493 | } |
| 494 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 495 | bool IsCompilingOsr() const { return osr_; } |
| 496 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 497 | bool HasTryCatch() const { return has_try_catch_; } |
| 498 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 499 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 500 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 501 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 502 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 503 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 504 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 505 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 506 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 507 | // The instruction has been inserted into the graph, either as a constant, or |
| 508 | // before cursor. |
| 509 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 510 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 511 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 512 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 513 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 514 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 515 | template <class InstructionType, typename ValueType> |
| 516 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 517 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 518 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 519 | // Try to find an existing constant of the given value. |
| 520 | InstructionType* constant = nullptr; |
| 521 | auto cached_constant = cache->find(value); |
| 522 | if (cached_constant != cache->end()) { |
| 523 | constant = cached_constant->second; |
| 524 | } |
| 525 | |
| 526 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 527 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 528 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 529 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 530 | cache->Overwrite(value, constant); |
| 531 | InsertConstant(constant); |
| 532 | } |
| 533 | return constant; |
| 534 | } |
| 535 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 536 | void InsertConstant(HConstant* instruction); |
| 537 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 538 | // Cache a float constant into the graph. This method should only be |
| 539 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 540 | void CacheFloatConstant(HFloatConstant* constant); |
| 541 | |
| 542 | // See CacheFloatConstant comment. |
| 543 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 544 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 545 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 546 | |
| 547 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 548 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 549 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 550 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 551 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 552 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 553 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 554 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 555 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 556 | HBasicBlock* entry_block_; |
| 557 | HBasicBlock* exit_block_; |
| 558 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 559 | // 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] | 560 | uint16_t maximum_number_of_out_vregs_; |
| 561 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 562 | // The number of virtual registers in this method. Contains the parameters. |
| 563 | uint16_t number_of_vregs_; |
| 564 | |
| 565 | // The number of virtual registers used by parameters of this method. |
| 566 | uint16_t number_of_in_vregs_; |
| 567 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 568 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 569 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 570 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 571 | // Has bounds checks. We can totally skip BCE if it's false. |
| 572 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 573 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 574 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 575 | // try/catch-related passes if false. |
| 576 | bool has_try_catch_; |
| 577 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 578 | // Flag whether there are any irreducible loops in the graph. |
| 579 | bool has_irreducible_loops_; |
| 580 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 581 | // Indicates whether the graph should be compiled in a way that |
| 582 | // ensures full debuggability. If false, we can apply more |
| 583 | // aggressive optimizations that may limit the level of debugging. |
| 584 | const bool debuggable_; |
| 585 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 586 | // 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] | 587 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 588 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 589 | // The dex file from which the method is from. |
| 590 | const DexFile& dex_file_; |
| 591 | |
| 592 | // The method index in the dex file. |
| 593 | const uint32_t method_idx_; |
| 594 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 595 | // If inlined, this encodes how the callee is being invoked. |
| 596 | const InvokeType invoke_type_; |
| 597 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 598 | // Whether the graph has been transformed to SSA form. Only used |
| 599 | // in debug mode to ensure we are not using properties only valid |
| 600 | // for non-SSA form (like the number of temporaries). |
| 601 | bool in_ssa_form_; |
| 602 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 603 | const bool should_generate_constructor_barrier_; |
| 604 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 605 | const InstructionSet instruction_set_; |
| 606 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 607 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 608 | HNullConstant* cached_null_constant_; |
| 609 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 610 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 611 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 612 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 613 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 614 | HCurrentMethod* cached_current_method_; |
| 615 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 616 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 617 | // for example for methods whose declaring class could not be resolved |
| 618 | // (such as when the superclass could not be found). |
| 619 | ArtMethod* art_method_; |
| 620 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 621 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 622 | // collection pointer to passes which may create NullConstant. |
| 623 | ReferenceTypeInfo inexact_object_rti_; |
| 624 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 625 | // Whether we are compiling this graph for on stack replacement: this will |
| 626 | // make all loops seen as irreducible and emit special stack maps to mark |
| 627 | // compiled code entries which the interpreter can directly jump to. |
| 628 | const bool osr_; |
| 629 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 630 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 631 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 632 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 633 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 634 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 635 | }; |
| 636 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 637 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 638 | public: |
| 639 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 640 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 641 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 642 | irreducible_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 643 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 644 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 645 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 646 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 647 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 648 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 649 | bool IsIrreducible() const { return irreducible_; } |
| 650 | |
| 651 | void Dump(std::ostream& os); |
| 652 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 653 | HBasicBlock* GetHeader() const { |
| 654 | return header_; |
| 655 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 656 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 657 | void SetHeader(HBasicBlock* block) { |
| 658 | header_ = block; |
| 659 | } |
| 660 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 661 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 662 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 663 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 664 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 665 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 666 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 669 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 670 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 671 | } |
| 672 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 673 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 674 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 675 | } |
| 676 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 677 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 678 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 681 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 682 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 683 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 684 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 685 | } |
| 686 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 687 | // Returns the lifetime position of the back edge that has the |
| 688 | // greatest lifetime position. |
| 689 | size_t GetLifetimeEnd() const; |
| 690 | |
| 691 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 692 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 693 | } |
| 694 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 695 | // Finds blocks that are part of this loop. |
| 696 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 697 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 698 | // Returns whether this loop information contains `block`. |
| 699 | // Note that this loop information *must* be populated before entering this function. |
| 700 | bool Contains(const HBasicBlock& block) const; |
| 701 | |
| 702 | // Returns whether this loop information is an inner loop of `other`. |
| 703 | // Note that `other` *must* be populated before entering this function. |
| 704 | bool IsIn(const HLoopInformation& other) const; |
| 705 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 706 | // Returns true if instruction is not defined within this loop. |
| 707 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 708 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 709 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 710 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 711 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 712 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 713 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 714 | void ClearAllBlocks() { |
| 715 | blocks_.ClearAllBits(); |
| 716 | } |
| 717 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 718 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 719 | // Internal recursive implementation of `Populate`. |
| 720 | void PopulateRecursive(HBasicBlock* block); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 721 | void PopulateIrreducibleRecursive(HBasicBlock* block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 722 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 723 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 724 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 725 | bool irreducible_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 726 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 727 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 728 | |
| 729 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 730 | }; |
| 731 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 732 | // Stores try/catch information for basic blocks. |
| 733 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 734 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 735 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 736 | public: |
| 737 | // Try block information constructor. |
| 738 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 739 | : try_entry_(&try_entry), |
| 740 | catch_dex_file_(nullptr), |
| 741 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 742 | DCHECK(try_entry_ != nullptr); |
| 743 | } |
| 744 | |
| 745 | // Catch block information constructor. |
| 746 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 747 | : try_entry_(nullptr), |
| 748 | catch_dex_file_(&dex_file), |
| 749 | catch_type_index_(catch_type_index) {} |
| 750 | |
| 751 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 752 | |
| 753 | const HTryBoundary& GetTryEntry() const { |
| 754 | DCHECK(IsTryBlock()); |
| 755 | return *try_entry_; |
| 756 | } |
| 757 | |
| 758 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 759 | |
| 760 | bool IsCatchAllTypeIndex() const { |
| 761 | DCHECK(IsCatchBlock()); |
| 762 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 763 | } |
| 764 | |
| 765 | uint16_t GetCatchTypeIndex() const { |
| 766 | DCHECK(IsCatchBlock()); |
| 767 | return catch_type_index_; |
| 768 | } |
| 769 | |
| 770 | const DexFile& GetCatchDexFile() const { |
| 771 | DCHECK(IsCatchBlock()); |
| 772 | return *catch_dex_file_; |
| 773 | } |
| 774 | |
| 775 | private: |
| 776 | // One of possibly several TryBoundary instructions entering the block's try. |
| 777 | // Only set for try blocks. |
| 778 | const HTryBoundary* try_entry_; |
| 779 | |
| 780 | // Exception type information. Only set for catch blocks. |
| 781 | const DexFile* catch_dex_file_; |
| 782 | const uint16_t catch_type_index_; |
| 783 | }; |
| 784 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 785 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 786 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 787 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 788 | // A block in a method. Contains the list of instructions represented |
| 789 | // as a double linked list. Each block knows its predecessors and |
| 790 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 791 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 792 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 793 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 794 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 795 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 796 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 797 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 798 | loop_information_(nullptr), |
| 799 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 800 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 801 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 802 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 803 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 804 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 805 | try_catch_information_(nullptr) { |
| 806 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 807 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 808 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 809 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 810 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 812 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 815 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 816 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 817 | } |
| 818 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 819 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 820 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 821 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 822 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 823 | return ContainsElement(successors_, block, start_from); |
| 824 | } |
| 825 | |
| 826 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 827 | return dominated_blocks_; |
| 828 | } |
| 829 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 830 | bool IsEntryBlock() const { |
| 831 | return graph_->GetEntryBlock() == this; |
| 832 | } |
| 833 | |
| 834 | bool IsExitBlock() const { |
| 835 | return graph_->GetExitBlock() == this; |
| 836 | } |
| 837 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 838 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 839 | bool IsSingleTryBoundary() const; |
| 840 | |
| 841 | // Returns true if this block emits nothing but a jump. |
| 842 | bool IsSingleJump() const { |
| 843 | HLoopInformation* loop_info = GetLoopInformation(); |
| 844 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 845 | // Back edges generate a suspend check. |
| 846 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 847 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 848 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 849 | void AddBackEdge(HBasicBlock* back_edge) { |
| 850 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 851 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 852 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 853 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 854 | loop_information_->AddBackEdge(back_edge); |
| 855 | } |
| 856 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 857 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 858 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 859 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 860 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 861 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 862 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 863 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 864 | HBasicBlock* GetDominator() const { return dominator_; } |
| 865 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 866 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 867 | |
| 868 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 869 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 870 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 871 | |
| 872 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 873 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 874 | } |
| 875 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 876 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 877 | |
| 878 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 879 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 882 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 883 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 884 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 885 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 886 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 887 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 888 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 889 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 890 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 891 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 892 | successors_.push_back(block); |
| 893 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 896 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 897 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 898 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 899 | new_block->predecessors_.push_back(this); |
| 900 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 901 | } |
| 902 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 903 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 904 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 905 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 906 | new_block->successors_.push_back(this); |
| 907 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 908 | } |
| 909 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 910 | // Insert `this` between `predecessor` and `successor. This method |
| 911 | // preserves the indicies, and will update the first edge found between |
| 912 | // `predecessor` and `successor`. |
| 913 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 914 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 915 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 916 | successor->predecessors_[predecessor_index] = this; |
| 917 | predecessor->successors_[successor_index] = this; |
| 918 | successors_.push_back(successor); |
| 919 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 920 | } |
| 921 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 922 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 923 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 924 | } |
| 925 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 926 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 927 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 930 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 931 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 935 | predecessors_.push_back(block); |
| 936 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 937 | } |
| 938 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 939 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 940 | DCHECK_EQ(predecessors_.size(), 2u); |
| 941 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 942 | } |
| 943 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 944 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 945 | DCHECK_EQ(successors_.size(), 2u); |
| 946 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 947 | } |
| 948 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 949 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 950 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 951 | } |
| 952 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 953 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 954 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 955 | } |
| 956 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 957 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 958 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 959 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 963 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 964 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | // Returns whether the first occurrence of `predecessor` in the list of |
| 968 | // predecessors is at index `idx`. |
| 969 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 970 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 971 | return GetPredecessorIndexOf(predecessor) == idx; |
| 972 | } |
| 973 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 974 | // Create a new block between this block and its predecessors. The new block |
| 975 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 976 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 977 | // loop and try/catch information are not updated. |
| 978 | HBasicBlock* CreateImmediateDominator(); |
| 979 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 980 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 981 | // created, latter block. Note that this method will add the block to the |
| 982 | // graph, create a Goto at the end of the former block and will create an edge |
| 983 | // 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] | 984 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 985 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 986 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 987 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 988 | // created block. Note that this method just updates raw block information, |
| 989 | // like predecessors, successors, dominators, and instruction list. It does not |
| 990 | // update the graph, reverse post order, loop information, nor make sure the |
| 991 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 992 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 993 | |
| 994 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 995 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 996 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 997 | // Split catch block into two blocks after the original move-exception bytecode |
| 998 | // instruction, or at the beginning if not present. Returns the newly created, |
| 999 | // latter block, or nullptr if such block could not be created (must be dead |
| 1000 | // in that case). Note that this method just updates raw block information, |
| 1001 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1002 | // update the graph, reverse post order, loop information, nor make sure the |
| 1003 | // blocks are consistent (for example ending with a control flow instruction). |
| 1004 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 1005 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1006 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1007 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1008 | // that this method does not update the graph, reverse post order, loop |
| 1009 | // information, nor make sure the blocks are consistent (for example ending |
| 1010 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1011 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1012 | |
| 1013 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1014 | // of `this` are moved to `other`. |
| 1015 | // Note that this method does not update the graph, reverse post order, loop |
| 1016 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1017 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1018 | void ReplaceWith(HBasicBlock* other); |
| 1019 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1020 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1021 | // order, links to predecessors, successors, dominators and deletes the block |
| 1022 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1023 | // predecessor of `other` and vice versa. |
| 1024 | void MergeWith(HBasicBlock* other); |
| 1025 | |
| 1026 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1027 | // removes it from all loops it is included in and eventually from the graph. |
| 1028 | // The block must not dominate any other block. Predecessors and successors |
| 1029 | // are safely updated. |
| 1030 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1031 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1032 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1033 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1034 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1035 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1036 | // Replace instruction `initial` with `replacement` within this block. |
| 1037 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1038 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1039 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1040 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1041 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1042 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1043 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1044 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1045 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1046 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1047 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1048 | |
| 1049 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1050 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1051 | } |
| 1052 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1053 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1054 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1055 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1058 | bool IsFirstPredecessorBackEdge() const { |
| 1059 | DCHECK(IsLoopHeader()); |
| 1060 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1061 | } |
| 1062 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1063 | HLoopInformation* GetLoopInformation() const { |
| 1064 | return loop_information_; |
| 1065 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1066 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1067 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1068 | // 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] | 1069 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1070 | void SetInLoop(HLoopInformation* info) { |
| 1071 | if (IsLoopHeader()) { |
| 1072 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1073 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1074 | loop_information_ = info; |
| 1075 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1076 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1077 | // Note that a non loop header having a loop information means this loop information |
| 1078 | // has already been populated |
| 1079 | loop_information_ = info; |
| 1080 | } else { |
| 1081 | // Block is part of an inner loop. Do not update the loop information. |
| 1082 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1083 | // at this point, because this method is being called while populating `info`. |
| 1084 | } |
| 1085 | } |
| 1086 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1087 | // Raw update of the loop information. |
| 1088 | void SetLoopInformation(HLoopInformation* info) { |
| 1089 | loop_information_ = info; |
| 1090 | } |
| 1091 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1092 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1093 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1094 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1095 | |
| 1096 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1097 | try_catch_information_ = try_catch_information; |
| 1098 | } |
| 1099 | |
| 1100 | bool IsTryBlock() const { |
| 1101 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1102 | } |
| 1103 | |
| 1104 | bool IsCatchBlock() const { |
| 1105 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1106 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1107 | |
| 1108 | // Returns the try entry that this block's successors should have. They will |
| 1109 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1110 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1111 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1112 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1113 | bool HasThrowingInstructions() const; |
| 1114 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1115 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1116 | bool Dominates(HBasicBlock* block) const; |
| 1117 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1118 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1119 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1120 | |
| 1121 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1122 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1123 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1124 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1125 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1126 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1127 | bool HasSinglePhi() const; |
| 1128 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1129 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1130 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1131 | ArenaVector<HBasicBlock*> predecessors_; |
| 1132 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1133 | HInstructionList instructions_; |
| 1134 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1135 | HLoopInformation* loop_information_; |
| 1136 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1137 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1138 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1139 | // The dex program counter of the first instruction of this block. |
| 1140 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1141 | size_t lifetime_start_; |
| 1142 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1143 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1144 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1145 | friend class HGraph; |
| 1146 | friend class HInstruction; |
| 1147 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1148 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1149 | }; |
| 1150 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1151 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1152 | // from the innermost to the outermost. |
| 1153 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1154 | public: |
| 1155 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1156 | : current_(block.GetLoopInformation()) {} |
| 1157 | |
| 1158 | bool Done() const { return current_ == nullptr; } |
| 1159 | |
| 1160 | void Advance() { |
| 1161 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1162 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | HLoopInformation* Current() const { |
| 1166 | DCHECK(!Done()); |
| 1167 | return current_; |
| 1168 | } |
| 1169 | |
| 1170 | private: |
| 1171 | HLoopInformation* current_; |
| 1172 | |
| 1173 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1174 | }; |
| 1175 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1176 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1177 | M(Above, Condition) \ |
| 1178 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1179 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1180 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1181 | M(ArrayGet, Instruction) \ |
| 1182 | M(ArrayLength, Instruction) \ |
| 1183 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1184 | M(Below, Condition) \ |
| 1185 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1186 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1187 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1188 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1189 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1190 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1191 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1192 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1193 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1194 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1195 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1196 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1197 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1198 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1199 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1200 | M(Exit, Instruction) \ |
| 1201 | M(FloatConstant, Constant) \ |
| 1202 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1203 | M(GreaterThan, Condition) \ |
| 1204 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1205 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1206 | M(InstanceFieldGet, Instruction) \ |
| 1207 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1208 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1209 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1210 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1211 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1212 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1213 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1214 | M(LessThan, Condition) \ |
| 1215 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1216 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1217 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1218 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1219 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1220 | M(Local, Instruction) \ |
| 1221 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1222 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1223 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1224 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1225 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1226 | M(Neg, UnaryOperation) \ |
| 1227 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1228 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1229 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1230 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1231 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1232 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1233 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1234 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1235 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1236 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1237 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1238 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1239 | M(Return, Instruction) \ |
| 1240 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1241 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1242 | M(Shl, BinaryOperation) \ |
| 1243 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1244 | M(StaticFieldGet, Instruction) \ |
| 1245 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1246 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1247 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1248 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1249 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1250 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1251 | M(StoreLocal, Instruction) \ |
| 1252 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1253 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1254 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1255 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1256 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1257 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1258 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1259 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1260 | /* |
| 1261 | * Instructions, shared across several (not all) architectures. |
| 1262 | */ |
| 1263 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1264 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1265 | #else |
| 1266 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
| 1267 | M(MultiplyAccumulate, Instruction) |
| 1268 | #endif |
| 1269 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1270 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1271 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1272 | #else |
| 1273 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1274 | M(ArmDexCacheArraysBase, Instruction) |
| 1275 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1276 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1277 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1278 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1279 | #else |
| 1280 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1281 | M(Arm64BitwiseNegatedRight, Instruction) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1282 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1283 | M(Arm64IntermediateAddress, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1284 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1285 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1286 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1287 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1288 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1289 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1290 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1291 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1292 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1293 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1294 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1295 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1296 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1297 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1298 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1299 | |
| 1300 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1301 | |
| 1302 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1303 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1304 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1305 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1306 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1307 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1308 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1309 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1310 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1311 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1312 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1313 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1314 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1315 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1316 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1317 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1318 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1319 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1320 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1321 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1322 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1323 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1324 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1325 | #undef FORWARD_DECLARATION |
| 1326 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1327 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1328 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1329 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1330 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1331 | return other->Is##type(); \ |
| 1332 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1333 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1334 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1335 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1336 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1337 | const H##type* As##type() const { return this; } \ |
| 1338 | H##type* As##type() { return this; } |
| 1339 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1340 | template <typename T> class HUseList; |
| 1341 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1342 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1343 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1344 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1345 | HUseListNode* GetPrevious() const { return prev_; } |
| 1346 | HUseListNode* GetNext() const { return next_; } |
| 1347 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1348 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1349 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1350 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1351 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1352 | HUseListNode(T user, size_t index) |
| 1353 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1354 | |
| 1355 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1356 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1357 | HUseListNode<T>* prev_; |
| 1358 | HUseListNode<T>* next_; |
| 1359 | |
| 1360 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1361 | |
| 1362 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1363 | }; |
| 1364 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1365 | template <typename T> |
| 1366 | class HUseList : public ValueObject { |
| 1367 | public: |
| 1368 | HUseList() : first_(nullptr) {} |
| 1369 | |
| 1370 | void Clear() { |
| 1371 | first_ = nullptr; |
| 1372 | } |
| 1373 | |
| 1374 | // Adds a new entry at the beginning of the use list and returns |
| 1375 | // the newly created node. |
| 1376 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1377 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1378 | if (IsEmpty()) { |
| 1379 | first_ = new_node; |
| 1380 | } else { |
| 1381 | first_->prev_ = new_node; |
| 1382 | new_node->next_ = first_; |
| 1383 | first_ = new_node; |
| 1384 | } |
| 1385 | return new_node; |
| 1386 | } |
| 1387 | |
| 1388 | HUseListNode<T>* GetFirst() const { |
| 1389 | return first_; |
| 1390 | } |
| 1391 | |
| 1392 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1393 | DCHECK(node != nullptr); |
| 1394 | DCHECK(Contains(node)); |
| 1395 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1396 | if (node->prev_ != nullptr) { |
| 1397 | node->prev_->next_ = node->next_; |
| 1398 | } |
| 1399 | if (node->next_ != nullptr) { |
| 1400 | node->next_->prev_ = node->prev_; |
| 1401 | } |
| 1402 | if (node == first_) { |
| 1403 | first_ = node->next_; |
| 1404 | } |
| 1405 | } |
| 1406 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1407 | bool Contains(const HUseListNode<T>* node) const { |
| 1408 | if (node == nullptr) { |
| 1409 | return false; |
| 1410 | } |
| 1411 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1412 | if (current == node) { |
| 1413 | return true; |
| 1414 | } |
| 1415 | } |
| 1416 | return false; |
| 1417 | } |
| 1418 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1419 | bool IsEmpty() const { |
| 1420 | return first_ == nullptr; |
| 1421 | } |
| 1422 | |
| 1423 | bool HasOnlyOneUse() const { |
| 1424 | return first_ != nullptr && first_->next_ == nullptr; |
| 1425 | } |
| 1426 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1427 | size_t SizeSlow() const { |
| 1428 | size_t count = 0; |
| 1429 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1430 | ++count; |
| 1431 | } |
| 1432 | return count; |
| 1433 | } |
| 1434 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1435 | private: |
| 1436 | HUseListNode<T>* first_; |
| 1437 | }; |
| 1438 | |
| 1439 | template<typename T> |
| 1440 | class HUseIterator : public ValueObject { |
| 1441 | public: |
| 1442 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1443 | |
| 1444 | bool Done() const { return current_ == nullptr; } |
| 1445 | |
| 1446 | void Advance() { |
| 1447 | DCHECK(!Done()); |
| 1448 | current_ = current_->GetNext(); |
| 1449 | } |
| 1450 | |
| 1451 | HUseListNode<T>* Current() const { |
| 1452 | DCHECK(!Done()); |
| 1453 | return current_; |
| 1454 | } |
| 1455 | |
| 1456 | private: |
| 1457 | HUseListNode<T>* current_; |
| 1458 | |
| 1459 | friend class HValue; |
| 1460 | }; |
| 1461 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1462 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1463 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1464 | // by the used instructions. |
| 1465 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1466 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1467 | public: |
| 1468 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1469 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1470 | |
| 1471 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1472 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1473 | DCHECK(instruction_ != nullptr); |
| 1474 | DCHECK(use_node_ != nullptr); |
| 1475 | DCHECK(old_record.use_node_ == nullptr); |
| 1476 | } |
| 1477 | |
| 1478 | HInstruction* GetInstruction() const { return instruction_; } |
| 1479 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1480 | |
| 1481 | private: |
| 1482 | // Instruction used by the user. |
| 1483 | HInstruction* instruction_; |
| 1484 | |
| 1485 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1486 | HUseListNode<T>* use_node_; |
| 1487 | }; |
| 1488 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1489 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1490 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1491 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1492 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1493 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1494 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1495 | * modify the value of a reference field read [although it may modify the |
| 1496 | * reference fetch prior to reading the field, which is represented by its own |
| 1497 | * write/read dependence]). The analysis makes conservative points-to |
| 1498 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1499 | * the same, and any reference read depends on any reference read without |
| 1500 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1501 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1502 | * The internal representation uses 38-bit and is described in the table below. |
| 1503 | * The first line indicates the side effect, and for field/array accesses the |
| 1504 | * second line indicates the type of the access (in the order of the |
| 1505 | * Primitive::Type enum). |
| 1506 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1507 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1508 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1509 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1510 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1511 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1512 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1513 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1514 | * |
| 1515 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1516 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1517 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1518 | class SideEffects : public ValueObject { |
| 1519 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1520 | SideEffects() : flags_(0) {} |
| 1521 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1522 | static SideEffects None() { |
| 1523 | return SideEffects(0); |
| 1524 | } |
| 1525 | |
| 1526 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1527 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1528 | } |
| 1529 | |
| 1530 | static SideEffects AllChanges() { |
| 1531 | return SideEffects(kAllChangeBits); |
| 1532 | } |
| 1533 | |
| 1534 | static SideEffects AllDependencies() { |
| 1535 | return SideEffects(kAllDependOnBits); |
| 1536 | } |
| 1537 | |
| 1538 | static SideEffects AllExceptGCDependency() { |
| 1539 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1540 | } |
| 1541 | |
| 1542 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1543 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1544 | } |
| 1545 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1546 | static SideEffects AllWrites() { |
| 1547 | return SideEffects(kAllWrites); |
| 1548 | } |
| 1549 | |
| 1550 | static SideEffects AllReads() { |
| 1551 | return SideEffects(kAllReads); |
| 1552 | } |
| 1553 | |
| 1554 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1555 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1556 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1557 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1558 | } |
| 1559 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1560 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1561 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1562 | } |
| 1563 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1564 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1565 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1566 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1567 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1571 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1572 | } |
| 1573 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1574 | static SideEffects CanTriggerGC() { |
| 1575 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1576 | } |
| 1577 | |
| 1578 | static SideEffects DependsOnGC() { |
| 1579 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1580 | } |
| 1581 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1582 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1583 | SideEffects Union(SideEffects other) const { |
| 1584 | return SideEffects(flags_ | other.flags_); |
| 1585 | } |
| 1586 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1587 | SideEffects Exclusion(SideEffects other) const { |
| 1588 | return SideEffects(flags_ & ~other.flags_); |
| 1589 | } |
| 1590 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1591 | void Add(SideEffects other) { |
| 1592 | flags_ |= other.flags_; |
| 1593 | } |
| 1594 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1595 | bool Includes(SideEffects other) const { |
| 1596 | return (other.flags_ & flags_) == other.flags_; |
| 1597 | } |
| 1598 | |
| 1599 | bool HasSideEffects() const { |
| 1600 | return (flags_ & kAllChangeBits); |
| 1601 | } |
| 1602 | |
| 1603 | bool HasDependencies() const { |
| 1604 | return (flags_ & kAllDependOnBits); |
| 1605 | } |
| 1606 | |
| 1607 | // Returns true if there are no side effects or dependencies. |
| 1608 | bool DoesNothing() const { |
| 1609 | return flags_ == 0; |
| 1610 | } |
| 1611 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1612 | // Returns true if something is written. |
| 1613 | bool DoesAnyWrite() const { |
| 1614 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1615 | } |
| 1616 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1617 | // Returns true if something is read. |
| 1618 | bool DoesAnyRead() const { |
| 1619 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1622 | // Returns true if potentially everything is written and read |
| 1623 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1624 | bool DoesAllReadWrite() const { |
| 1625 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1626 | } |
| 1627 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1628 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1629 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1630 | } |
| 1631 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1632 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1633 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1634 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1635 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1639 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1640 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1641 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1642 | for (int s = kLastBit; s >= 0; s--) { |
| 1643 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1644 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1645 | // This is a bit for the GC side effect. |
| 1646 | if (current_bit_is_set) { |
| 1647 | flags += "GC"; |
| 1648 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1649 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1650 | } else { |
| 1651 | // This is a bit for the array/field analysis. |
| 1652 | // The underscore character stands for the 'can trigger GC' bit. |
| 1653 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1654 | if (current_bit_is_set) { |
| 1655 | flags += kDebug[s]; |
| 1656 | } |
| 1657 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1658 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1659 | flags += "|"; |
| 1660 | } |
| 1661 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1662 | } |
| 1663 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1664 | } |
| 1665 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1666 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1667 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1668 | private: |
| 1669 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1670 | |
| 1671 | static constexpr int kFieldWriteOffset = 0; |
| 1672 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1673 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1674 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1675 | |
| 1676 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1677 | |
| 1678 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1679 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1680 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1681 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1682 | |
| 1683 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1684 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1685 | |
| 1686 | // Aliases. |
| 1687 | |
| 1688 | static_assert(kChangeBits == kDependOnBits, |
| 1689 | "the 'change' bits should match the 'depend on' bits."); |
| 1690 | |
| 1691 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1692 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1693 | static constexpr uint64_t kAllWrites = |
| 1694 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1695 | static constexpr uint64_t kAllReads = |
| 1696 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1697 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1698 | // Work around the fact that HIR aliases I/F and J/D. |
| 1699 | // TODO: remove this interceptor once HIR types are clean |
| 1700 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1701 | switch (type) { |
| 1702 | case Primitive::kPrimInt: |
| 1703 | case Primitive::kPrimFloat: |
| 1704 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1705 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1706 | case Primitive::kPrimLong: |
| 1707 | case Primitive::kPrimDouble: |
| 1708 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1709 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1710 | default: |
| 1711 | return TypeFlag(type, offset); |
| 1712 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1713 | } |
| 1714 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1715 | // Translates type to bit flag. |
| 1716 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1717 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1718 | const uint64_t one = 1; |
| 1719 | const int shift = type; // 0-based consecutive enum |
| 1720 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1721 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1722 | return one << (type + offset); |
| 1723 | } |
| 1724 | |
| 1725 | // Private constructor on direct flags value. |
| 1726 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1727 | |
| 1728 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1729 | }; |
| 1730 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1731 | // 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] | 1732 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1733 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1734 | HEnvironment(ArenaAllocator* arena, |
| 1735 | size_t number_of_vregs, |
| 1736 | const DexFile& dex_file, |
| 1737 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1738 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1739 | InvokeType invoke_type, |
| 1740 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1741 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1742 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1743 | parent_(nullptr), |
| 1744 | dex_file_(dex_file), |
| 1745 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1746 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1747 | invoke_type_(invoke_type), |
| 1748 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1749 | } |
| 1750 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1751 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1752 | : HEnvironment(arena, |
| 1753 | to_copy.Size(), |
| 1754 | to_copy.GetDexFile(), |
| 1755 | to_copy.GetMethodIdx(), |
| 1756 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1757 | to_copy.GetInvokeType(), |
| 1758 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1759 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1760 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1761 | if (parent_ != nullptr) { |
| 1762 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1763 | } else { |
| 1764 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1765 | parent_->CopyFrom(parent); |
| 1766 | if (parent->GetParent() != nullptr) { |
| 1767 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1768 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1769 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1772 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1773 | void CopyFrom(HEnvironment* environment); |
| 1774 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1775 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1776 | // input to the loop phi instead. This is for inserting instructions that |
| 1777 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1778 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1779 | |
| 1780 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1781 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1785 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1788 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1789 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1790 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1791 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1792 | HEnvironment* GetParent() const { return parent_; } |
| 1793 | |
| 1794 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1795 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1799 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | uint32_t GetDexPc() const { |
| 1803 | return dex_pc_; |
| 1804 | } |
| 1805 | |
| 1806 | uint32_t GetMethodIdx() const { |
| 1807 | return method_idx_; |
| 1808 | } |
| 1809 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1810 | InvokeType GetInvokeType() const { |
| 1811 | return invoke_type_; |
| 1812 | } |
| 1813 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1814 | const DexFile& GetDexFile() const { |
| 1815 | return dex_file_; |
| 1816 | } |
| 1817 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1818 | HInstruction* GetHolder() const { |
| 1819 | return holder_; |
| 1820 | } |
| 1821 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1822 | |
| 1823 | bool IsFromInlinedInvoke() const { |
| 1824 | return GetParent() != nullptr; |
| 1825 | } |
| 1826 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1827 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1828 | // Record instructions' use entries of this environment for constant-time removal. |
| 1829 | // It should only be called by HInstruction when a new environment use is added. |
| 1830 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1831 | DCHECK(env_use->GetUser() == this); |
| 1832 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1833 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1834 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1835 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1836 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1837 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1838 | HEnvironment* parent_; |
| 1839 | const DexFile& dex_file_; |
| 1840 | const uint32_t method_idx_; |
| 1841 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1842 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1843 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1844 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1845 | HInstruction* const holder_; |
| 1846 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1847 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1848 | |
| 1849 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1850 | }; |
| 1851 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1852 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1853 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1854 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1855 | : previous_(nullptr), |
| 1856 | next_(nullptr), |
| 1857 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1858 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1859 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1860 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1861 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1862 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1863 | locations_(nullptr), |
| 1864 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1865 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1866 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1867 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1868 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1869 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1870 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1871 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1872 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1873 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1874 | enum InstructionKind { |
| 1875 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1876 | }; |
| 1877 | #undef DECLARE_KIND |
| 1878 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1879 | HInstruction* GetNext() const { return next_; } |
| 1880 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1881 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1882 | HInstruction* GetNextDisregardingMoves() const; |
| 1883 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1884 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1885 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1886 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1887 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1888 | bool IsInBlock() const { return block_ != nullptr; } |
| 1889 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1890 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1891 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1892 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1893 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1894 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1895 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1896 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1897 | |
| 1898 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1899 | virtual const char* DebugName() const = 0; |
| 1900 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1901 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1902 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1903 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1904 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1905 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1906 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1907 | |
| 1908 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1909 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1910 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1911 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1912 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1913 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1914 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1915 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1916 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1917 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1918 | // Does not apply for all instructions, but having this at top level greatly |
| 1919 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1920 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1921 | virtual bool CanBeNull() const { |
| 1922 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1923 | return true; |
| 1924 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1925 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1926 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1927 | return false; |
| 1928 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1929 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1930 | virtual bool IsActualObject() const { |
| 1931 | return GetType() == Primitive::kPrimNot; |
| 1932 | } |
| 1933 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1934 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1935 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1936 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1937 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1938 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
| 1939 | GetPackedFlag<kFlagReferenceTypeIsExact>());; |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1940 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1941 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1942 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1943 | DCHECK(user != nullptr); |
| 1944 | HUseListNode<HInstruction*>* use = |
| 1945 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1946 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1949 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1950 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1951 | HUseListNode<HEnvironment*>* env_use = |
| 1952 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1953 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1954 | } |
| 1955 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1956 | void RemoveAsUserOfInput(size_t input) { |
| 1957 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1958 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1959 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1960 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1961 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1962 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1963 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1964 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1965 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1966 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1967 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1968 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1969 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1970 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1971 | // Does this instruction strictly dominate `other_instruction`? |
| 1972 | // Returns false if this instruction and `other_instruction` are the same. |
| 1973 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1974 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1975 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1976 | int GetId() const { return id_; } |
| 1977 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1978 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1979 | int GetSsaIndex() const { return ssa_index_; } |
| 1980 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1981 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1982 | |
| 1983 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1984 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1985 | // Set the `environment_` field. Raw because this method does not |
| 1986 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1987 | void SetRawEnvironment(HEnvironment* environment) { |
| 1988 | DCHECK(environment_ == nullptr); |
| 1989 | DCHECK_EQ(environment->GetHolder(), this); |
| 1990 | environment_ = environment; |
| 1991 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1992 | |
| 1993 | // Set the environment of this instruction, copying it from `environment`. While |
| 1994 | // copying, the uses lists are being updated. |
| 1995 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1996 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1997 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1998 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1999 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2000 | if (environment->GetParent() != nullptr) { |
| 2001 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2002 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2003 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2004 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2005 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2006 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2007 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2008 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2009 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2010 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2011 | if (environment->GetParent() != nullptr) { |
| 2012 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2013 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2014 | } |
| 2015 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2016 | // Returns the number of entries in the environment. Typically, that is the |
| 2017 | // number of dex registers in a method. It could be more in case of inlining. |
| 2018 | size_t EnvironmentSize() const; |
| 2019 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2020 | LocationSummary* GetLocations() const { return locations_; } |
| 2021 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2022 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2023 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2024 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2025 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2026 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2027 | // uses of this instruction by `other` are *not* updated. |
| 2028 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2029 | ReplaceWith(other); |
| 2030 | other->ReplaceInput(this, use_index); |
| 2031 | } |
| 2032 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2033 | // Move `this` instruction before `cursor`. |
| 2034 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2035 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2036 | // Move `this` before its first user and out of any loops. If there is no |
| 2037 | // out-of-loop user that dominates all other users, move the instruction |
| 2038 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2039 | // |
| 2040 | // This can be used only on non-throwing instructions with no side effects that |
| 2041 | // have at least one use but no environment uses. |
| 2042 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2043 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2044 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2045 | bool Is##type() const; \ |
| 2046 | const H##type* As##type() const; \ |
| 2047 | H##type* As##type(); |
| 2048 | |
| 2049 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2050 | #undef INSTRUCTION_TYPE_CHECK |
| 2051 | |
| 2052 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2053 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2054 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2055 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2056 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2057 | #undef INSTRUCTION_TYPE_CHECK |
| 2058 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2059 | // Returns whether the instruction can be moved within the graph. |
| 2060 | virtual bool CanBeMoved() const { return false; } |
| 2061 | |
| 2062 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2063 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2064 | return false; |
| 2065 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2066 | |
| 2067 | // Returns whether any data encoded in the two instructions is equal. |
| 2068 | // This method does not look at the inputs. Both instructions must be |
| 2069 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2070 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2071 | return false; |
| 2072 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2073 | |
| 2074 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2075 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2076 | // 2) Their inputs are identical. |
| 2077 | bool Equals(HInstruction* other) const; |
| 2078 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2079 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2080 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2081 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2082 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2083 | InstructionKind GetKind() const PURE; |
| 2084 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2085 | |
| 2086 | virtual size_t ComputeHashCode() const { |
| 2087 | size_t result = GetKind(); |
| 2088 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2089 | result = (result * 31) + InputAt(i)->GetId(); |
| 2090 | } |
| 2091 | return result; |
| 2092 | } |
| 2093 | |
| 2094 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2095 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2096 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2097 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2098 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2099 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2100 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2101 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2102 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2103 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2104 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2105 | |
| 2106 | // Returns whether the code generation of the instruction will require to have access |
| 2107 | // to the current method. Such instructions are: |
| 2108 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2109 | // to walk the stack and have the current method stored at a specific stack address. |
| 2110 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2111 | // fields of the current method. |
| 2112 | bool NeedsCurrentMethod() const { |
| 2113 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2114 | } |
| 2115 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2116 | // Returns whether the code generation of the instruction will require to have access |
| 2117 | // to the dex cache of the current method's declaring class via the current method. |
| 2118 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2119 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2120 | // Does this instruction have any use in an environment before |
| 2121 | // control flow hits 'other'? |
| 2122 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2123 | |
| 2124 | // Remove all references to environment uses of this instruction. |
| 2125 | // The caller must ensure that this is safe to do. |
| 2126 | void RemoveEnvironmentUsers(); |
| 2127 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2128 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2129 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2130 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2131 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2132 | // If set, the machine code for this instruction is assumed to be generated by |
| 2133 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2134 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2135 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2136 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2137 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2138 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2139 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2140 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2141 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2142 | uint32_t GetPackedFields() const { |
| 2143 | return packed_fields_; |
| 2144 | } |
| 2145 | |
| 2146 | template <size_t flag> |
| 2147 | bool GetPackedFlag() const { |
| 2148 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2149 | } |
| 2150 | |
| 2151 | template <size_t flag> |
| 2152 | void SetPackedFlag(bool value = true) { |
| 2153 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2154 | } |
| 2155 | |
| 2156 | template <typename BitFieldType> |
| 2157 | typename BitFieldType::value_type GetPackedField() const { |
| 2158 | return BitFieldType::Decode(packed_fields_); |
| 2159 | } |
| 2160 | |
| 2161 | template <typename BitFieldType> |
| 2162 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2163 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2164 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2165 | } |
| 2166 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2167 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2168 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2169 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2170 | HInstruction* previous_; |
| 2171 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2172 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2173 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2174 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2175 | // An instruction gets an id when it is added to the graph. |
| 2176 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2177 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2178 | int id_; |
| 2179 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2180 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2181 | int ssa_index_; |
| 2182 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2183 | // Packed fields. |
| 2184 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2185 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2186 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2187 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2188 | |
| 2189 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2190 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2191 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2192 | // The environment associated with this instruction. Not null if the instruction |
| 2193 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2194 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2195 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2196 | // Set by the code generator. |
| 2197 | LocationSummary* locations_; |
| 2198 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2199 | // Set by the liveness analysis. |
| 2200 | LiveInterval* live_interval_; |
| 2201 | |
| 2202 | // Set by the liveness analysis, this is the position in a linear |
| 2203 | // order of blocks where this instruction's live interval start. |
| 2204 | size_t lifetime_position_; |
| 2205 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2206 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2207 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2208 | // The reference handle part of the reference type info. |
| 2209 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2210 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2211 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2212 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2213 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2214 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2215 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2216 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2217 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2218 | |
| 2219 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2220 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2221 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2222 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2223 | class HInputIterator : public ValueObject { |
| 2224 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2225 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2226 | |
| 2227 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2228 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2229 | void Advance() { index_++; } |
| 2230 | |
| 2231 | private: |
| 2232 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2233 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2234 | |
| 2235 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2236 | }; |
| 2237 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2238 | class HInstructionIterator : public ValueObject { |
| 2239 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2240 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2241 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2242 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2245 | bool Done() const { return instruction_ == nullptr; } |
| 2246 | HInstruction* Current() const { return instruction_; } |
| 2247 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2248 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2249 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | private: |
| 2253 | HInstruction* instruction_; |
| 2254 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2255 | |
| 2256 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2257 | }; |
| 2258 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2259 | class HBackwardInstructionIterator : public ValueObject { |
| 2260 | public: |
| 2261 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2262 | : instruction_(instructions.last_instruction_) { |
| 2263 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2264 | } |
| 2265 | |
| 2266 | bool Done() const { return instruction_ == nullptr; } |
| 2267 | HInstruction* Current() const { return instruction_; } |
| 2268 | void Advance() { |
| 2269 | instruction_ = next_; |
| 2270 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2271 | } |
| 2272 | |
| 2273 | private: |
| 2274 | HInstruction* instruction_; |
| 2275 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2276 | |
| 2277 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2278 | }; |
| 2279 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2280 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2281 | class HTemplateInstruction: public HInstruction { |
| 2282 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2283 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2284 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2285 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2286 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2287 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2288 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2289 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2290 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2291 | DCHECK_LT(i, N); |
| 2292 | return inputs_[i]; |
| 2293 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2294 | |
| 2295 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2296 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2297 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2300 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2301 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2302 | |
| 2303 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2304 | }; |
| 2305 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2306 | // HTemplateInstruction specialization for N=0. |
| 2307 | template<> |
| 2308 | class HTemplateInstruction<0>: public HInstruction { |
| 2309 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2310 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2311 | : HInstruction(side_effects, dex_pc) {} |
| 2312 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2313 | virtual ~HTemplateInstruction() {} |
| 2314 | |
| 2315 | size_t InputCount() const OVERRIDE { return 0; } |
| 2316 | |
| 2317 | protected: |
| 2318 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2319 | LOG(FATAL) << "Unreachable"; |
| 2320 | UNREACHABLE(); |
| 2321 | } |
| 2322 | |
| 2323 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2324 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2325 | LOG(FATAL) << "Unreachable"; |
| 2326 | UNREACHABLE(); |
| 2327 | } |
| 2328 | |
| 2329 | private: |
| 2330 | friend class SsaBuilder; |
| 2331 | }; |
| 2332 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2333 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2334 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2335 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2336 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2337 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2338 | this->template SetPackedField<TypeField>(type); |
| 2339 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2340 | virtual ~HExpression() {} |
| 2341 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2342 | Primitive::Type GetType() const OVERRIDE { |
| 2343 | return TypeField::Decode(this->GetPackedFields()); |
| 2344 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2345 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2346 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2347 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2348 | static constexpr size_t kFieldTypeSize = |
| 2349 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2350 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2351 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2352 | "Too many packed fields."); |
| 2353 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2354 | }; |
| 2355 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2356 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2357 | // instruction that branches to the exit block. |
| 2358 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2359 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2360 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2361 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2362 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2363 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2364 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2365 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2366 | |
| 2367 | private: |
| 2368 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2369 | }; |
| 2370 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2371 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2372 | // instruction that branches to the exit block. |
| 2373 | class HReturn : public HTemplateInstruction<1> { |
| 2374 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2375 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2376 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2377 | SetRawInputAt(0, value); |
| 2378 | } |
| 2379 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2380 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2381 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2382 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2383 | |
| 2384 | private: |
| 2385 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2386 | }; |
| 2387 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2388 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2389 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2390 | // exit block. |
| 2391 | class HExit : public HTemplateInstruction<0> { |
| 2392 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2393 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2394 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2395 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2396 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2397 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2398 | |
| 2399 | private: |
| 2400 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2401 | }; |
| 2402 | |
| 2403 | // Jumps from one block to another. |
| 2404 | class HGoto : public HTemplateInstruction<0> { |
| 2405 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2406 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2407 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2408 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2409 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2410 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2411 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2414 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2415 | |
| 2416 | private: |
| 2417 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2418 | }; |
| 2419 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2420 | class HConstant : public HExpression<0> { |
| 2421 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2422 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2423 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2424 | |
| 2425 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2426 | |
| 2427 | virtual bool IsMinusOne() const { return false; } |
| 2428 | virtual bool IsZero() const { return false; } |
| 2429 | virtual bool IsOne() const { return false; } |
| 2430 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2431 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2432 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2433 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2434 | |
| 2435 | private: |
| 2436 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2437 | }; |
| 2438 | |
| 2439 | class HNullConstant : public HConstant { |
| 2440 | public: |
| 2441 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2442 | return true; |
| 2443 | } |
| 2444 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2445 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2446 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2447 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2448 | |
| 2449 | DECLARE_INSTRUCTION(NullConstant); |
| 2450 | |
| 2451 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2452 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2453 | |
| 2454 | friend class HGraph; |
| 2455 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2456 | }; |
| 2457 | |
| 2458 | // Constants of the type int. Those can be from Dex instructions, or |
| 2459 | // synthesized (for example with the if-eqz instruction). |
| 2460 | class HIntConstant : public HConstant { |
| 2461 | public: |
| 2462 | int32_t GetValue() const { return value_; } |
| 2463 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2464 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2465 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2466 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2467 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2468 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2469 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2470 | return other->AsIntConstant()->value_ == value_; |
| 2471 | } |
| 2472 | |
| 2473 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2474 | |
| 2475 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2476 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2477 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2478 | |
| 2479 | DECLARE_INSTRUCTION(IntConstant); |
| 2480 | |
| 2481 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2482 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2483 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2484 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2485 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2486 | |
| 2487 | const int32_t value_; |
| 2488 | |
| 2489 | friend class HGraph; |
| 2490 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2491 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2492 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2493 | }; |
| 2494 | |
| 2495 | class HLongConstant : public HConstant { |
| 2496 | public: |
| 2497 | int64_t GetValue() const { return value_; } |
| 2498 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2499 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2500 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2501 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2502 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2503 | return other->AsLongConstant()->value_ == value_; |
| 2504 | } |
| 2505 | |
| 2506 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2507 | |
| 2508 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2509 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2510 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2511 | |
| 2512 | DECLARE_INSTRUCTION(LongConstant); |
| 2513 | |
| 2514 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2515 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2516 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2517 | |
| 2518 | const int64_t value_; |
| 2519 | |
| 2520 | friend class HGraph; |
| 2521 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2522 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2523 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2524 | class HFloatConstant : public HConstant { |
| 2525 | public: |
| 2526 | float GetValue() const { return value_; } |
| 2527 | |
| 2528 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2529 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2530 | } |
| 2531 | |
| 2532 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2533 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2534 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2535 | } |
| 2536 | |
| 2537 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2538 | |
| 2539 | bool IsMinusOne() const OVERRIDE { |
| 2540 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2541 | } |
| 2542 | bool IsZero() const OVERRIDE { |
| 2543 | return value_ == 0.0f; |
| 2544 | } |
| 2545 | bool IsOne() const OVERRIDE { |
| 2546 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2547 | } |
| 2548 | bool IsNaN() const { |
| 2549 | return std::isnan(value_); |
| 2550 | } |
| 2551 | |
| 2552 | DECLARE_INSTRUCTION(FloatConstant); |
| 2553 | |
| 2554 | private: |
| 2555 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2556 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2557 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2558 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2559 | |
| 2560 | const float value_; |
| 2561 | |
| 2562 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2563 | friend class SsaBuilder; |
| 2564 | friend class HGraph; |
| 2565 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2566 | }; |
| 2567 | |
| 2568 | class HDoubleConstant : public HConstant { |
| 2569 | public: |
| 2570 | double GetValue() const { return value_; } |
| 2571 | |
| 2572 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2573 | |
| 2574 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2575 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2576 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2577 | } |
| 2578 | |
| 2579 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2580 | |
| 2581 | bool IsMinusOne() const OVERRIDE { |
| 2582 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2583 | } |
| 2584 | bool IsZero() const OVERRIDE { |
| 2585 | return value_ == 0.0; |
| 2586 | } |
| 2587 | bool IsOne() const OVERRIDE { |
| 2588 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2589 | } |
| 2590 | bool IsNaN() const { |
| 2591 | return std::isnan(value_); |
| 2592 | } |
| 2593 | |
| 2594 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2595 | |
| 2596 | private: |
| 2597 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2598 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2599 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2600 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2601 | |
| 2602 | const double value_; |
| 2603 | |
| 2604 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2605 | friend class SsaBuilder; |
| 2606 | friend class HGraph; |
| 2607 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2608 | }; |
| 2609 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2610 | // Conditional branch. A block ending with an HIf instruction must have |
| 2611 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2612 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2613 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2614 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2615 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2616 | SetRawInputAt(0, input); |
| 2617 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2618 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2619 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2620 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2621 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2622 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2626 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2629 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2630 | |
| 2631 | private: |
| 2632 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2633 | }; |
| 2634 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2635 | |
| 2636 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2637 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2638 | // non-exceptional control flow. |
| 2639 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2640 | // higher indices in no particular order. |
| 2641 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2642 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2643 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2644 | kEntry, |
| 2645 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2646 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2647 | }; |
| 2648 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2649 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2650 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2651 | SetPackedField<BoundaryKindField>(kind); |
| 2652 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2653 | |
| 2654 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2655 | |
| 2656 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2657 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2658 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2659 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2660 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2661 | } |
| 2662 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2663 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2664 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2665 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2666 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2667 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | // If not present already, adds `handler` to its block's list of exception |
| 2671 | // handlers. |
| 2672 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2673 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2674 | GetBlock()->AddSuccessor(handler); |
| 2675 | } |
| 2676 | } |
| 2677 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2678 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2679 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2680 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2681 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2682 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2683 | DECLARE_INSTRUCTION(TryBoundary); |
| 2684 | |
| 2685 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2686 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2687 | static constexpr size_t kFieldBoundaryKindSize = |
| 2688 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2689 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2690 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2691 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2692 | "Too many packed fields."); |
| 2693 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2694 | |
| 2695 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2696 | }; |
| 2697 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2698 | // Deoptimize to interpreter, upon checking a condition. |
| 2699 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2700 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2701 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2702 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2703 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2704 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2705 | SetRawInputAt(0, cond); |
| 2706 | } |
| 2707 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2708 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2709 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2710 | return true; |
| 2711 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2712 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2713 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2714 | |
| 2715 | DECLARE_INSTRUCTION(Deoptimize); |
| 2716 | |
| 2717 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2718 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2719 | }; |
| 2720 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2721 | // Represents the ArtMethod that was passed as a first argument to |
| 2722 | // the method. It is used by instructions that depend on it, like |
| 2723 | // instructions that work with the dex cache. |
| 2724 | class HCurrentMethod : public HExpression<0> { |
| 2725 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2726 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2727 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2728 | |
| 2729 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2730 | |
| 2731 | private: |
| 2732 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2733 | }; |
| 2734 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2735 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2736 | // of a class. |
| 2737 | class HClassTableGet : public HExpression<1> { |
| 2738 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2739 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2740 | kVTable, |
| 2741 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2742 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2743 | }; |
| 2744 | HClassTableGet(HInstruction* cls, |
| 2745 | Primitive::Type type, |
| 2746 | TableKind kind, |
| 2747 | size_t index, |
| 2748 | uint32_t dex_pc) |
| 2749 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2750 | index_(index) { |
| 2751 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2752 | SetRawInputAt(0, cls); |
| 2753 | } |
| 2754 | |
| 2755 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2756 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2757 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2758 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2759 | } |
| 2760 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2761 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2762 | size_t GetIndex() const { return index_; } |
| 2763 | |
| 2764 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2765 | |
| 2766 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2767 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2768 | static constexpr size_t kFieldTableKindSize = |
| 2769 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2770 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2771 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2772 | "Too many packed fields."); |
| 2773 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2774 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2775 | // The index of the ArtMethod in the table. |
| 2776 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2777 | |
| 2778 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2779 | }; |
| 2780 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2781 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2782 | // have one successor for each entry in the switch table, and the final successor |
| 2783 | // will be the block containing the next Dex opcode. |
| 2784 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2785 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2786 | HPackedSwitch(int32_t start_value, |
| 2787 | uint32_t num_entries, |
| 2788 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2789 | uint32_t dex_pc = kNoDexPc) |
| 2790 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2791 | start_value_(start_value), |
| 2792 | num_entries_(num_entries) { |
| 2793 | SetRawInputAt(0, input); |
| 2794 | } |
| 2795 | |
| 2796 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2797 | |
| 2798 | int32_t GetStartValue() const { return start_value_; } |
| 2799 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2800 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2801 | |
| 2802 | HBasicBlock* GetDefaultBlock() const { |
| 2803 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2804 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2805 | } |
| 2806 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2807 | |
| 2808 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2809 | const int32_t start_value_; |
| 2810 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2811 | |
| 2812 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2813 | }; |
| 2814 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2815 | class HUnaryOperation : public HExpression<1> { |
| 2816 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2817 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2818 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2819 | SetRawInputAt(0, input); |
| 2820 | } |
| 2821 | |
| 2822 | HInstruction* GetInput() const { return InputAt(0); } |
| 2823 | Primitive::Type GetResultType() const { return GetType(); } |
| 2824 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2825 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2826 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2827 | return true; |
| 2828 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2829 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2830 | // Try to statically evaluate `this` and return a HConstant |
| 2831 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2832 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2833 | HConstant* TryStaticEvaluation() const; |
| 2834 | |
| 2835 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2836 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2837 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2838 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2839 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2840 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2841 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2842 | |
| 2843 | private: |
| 2844 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2845 | }; |
| 2846 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2847 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2848 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2849 | HBinaryOperation(Primitive::Type result_type, |
| 2850 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2851 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2852 | SideEffects side_effects = SideEffects::None(), |
| 2853 | uint32_t dex_pc = kNoDexPc) |
| 2854 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2855 | SetRawInputAt(0, left); |
| 2856 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2857 | } |
| 2858 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2859 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2860 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2861 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2862 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2863 | virtual bool IsCommutative() const { return false; } |
| 2864 | |
| 2865 | // Put constant on the right. |
| 2866 | // Returns whether order is changed. |
| 2867 | bool OrderInputsWithConstantOnTheRight() { |
| 2868 | HInstruction* left = InputAt(0); |
| 2869 | HInstruction* right = InputAt(1); |
| 2870 | if (left->IsConstant() && !right->IsConstant()) { |
| 2871 | ReplaceInput(right, 0); |
| 2872 | ReplaceInput(left, 1); |
| 2873 | return true; |
| 2874 | } |
| 2875 | return false; |
| 2876 | } |
| 2877 | |
| 2878 | // Order inputs by instruction id, but favor constant on the right side. |
| 2879 | // This helps GVN for commutative ops. |
| 2880 | void OrderInputs() { |
| 2881 | DCHECK(IsCommutative()); |
| 2882 | HInstruction* left = InputAt(0); |
| 2883 | HInstruction* right = InputAt(1); |
| 2884 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2885 | return; |
| 2886 | } |
| 2887 | if (OrderInputsWithConstantOnTheRight()) { |
| 2888 | return; |
| 2889 | } |
| 2890 | // Order according to instruction id. |
| 2891 | if (left->GetId() > right->GetId()) { |
| 2892 | ReplaceInput(right, 0); |
| 2893 | ReplaceInput(left, 1); |
| 2894 | } |
| 2895 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2896 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2897 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2898 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2899 | return true; |
| 2900 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2901 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2902 | // Try to statically evaluate `this` and return a HConstant |
| 2903 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2904 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2905 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2906 | |
| 2907 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2908 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2909 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2910 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 2911 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2912 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2913 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2914 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2915 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2916 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2917 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 2918 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2919 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2920 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 2921 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2922 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2923 | // 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] | 2924 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2925 | HConstant* GetConstantRight() const; |
| 2926 | |
| 2927 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2928 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2929 | HInstruction* GetLeastConstantLeft() const; |
| 2930 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2931 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2932 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2933 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2934 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2935 | }; |
| 2936 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2937 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2938 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2939 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2940 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2941 | kGtBias, // return 1 for NaN comparisons |
| 2942 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2943 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2944 | }; |
| 2945 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2946 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 2947 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2948 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2949 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2950 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2951 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 2952 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 2953 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2954 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2955 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2956 | // `instruction`, and disregard moves in between. |
| 2957 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2958 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2959 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2960 | |
| 2961 | virtual IfCondition GetCondition() const = 0; |
| 2962 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2963 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2964 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2965 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
| 2966 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 2967 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2968 | |
| 2969 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2970 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2971 | } |
| 2972 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2973 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2974 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2975 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2976 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2980 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2981 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2982 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2983 | } |
| 2984 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2985 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2986 | // Needed if we merge a HCompare into a HCondition. |
| 2987 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 2988 | static constexpr size_t kFieldComparisonBiasSize = |
| 2989 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 2990 | static constexpr size_t kNumberOfConditionPackedBits = |
| 2991 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 2992 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2993 | using ComparisonBiasField = |
| 2994 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 2995 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2996 | template <typename T> |
| 2997 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 2998 | |
| 2999 | template <typename T> |
| 3000 | int32_t CompareFP(T x, T y) const { |
| 3001 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3002 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3003 | // Handle the bias. |
| 3004 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3005 | } |
| 3006 | |
| 3007 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3008 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3009 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3010 | } |
| 3011 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3012 | private: |
| 3013 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3014 | }; |
| 3015 | |
| 3016 | // Instruction to check if two inputs are equal to each other. |
| 3017 | class HEqual : public HCondition { |
| 3018 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3019 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3020 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3021 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3022 | bool IsCommutative() const OVERRIDE { return true; } |
| 3023 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3024 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3025 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3026 | return MakeConstantCondition(true, GetDexPc()); |
| 3027 | } |
| 3028 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3029 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3030 | } |
| 3031 | // In the following Evaluate methods, a HCompare instruction has |
| 3032 | // been merged into this HEqual instruction; evaluate it as |
| 3033 | // `Compare(x, y) == 0`. |
| 3034 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3035 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3036 | GetDexPc()); |
| 3037 | } |
| 3038 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3039 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3040 | } |
| 3041 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3042 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3043 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3044 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3045 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3046 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3047 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3048 | return kCondEQ; |
| 3049 | } |
| 3050 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3051 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3052 | return kCondNE; |
| 3053 | } |
| 3054 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3055 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3056 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 3057 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3058 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3059 | }; |
| 3060 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3061 | class HNotEqual : public HCondition { |
| 3062 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3063 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3064 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3065 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3066 | bool IsCommutative() const OVERRIDE { return true; } |
| 3067 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3068 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3069 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3070 | return MakeConstantCondition(false, GetDexPc()); |
| 3071 | } |
| 3072 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3073 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3074 | } |
| 3075 | // In the following Evaluate methods, a HCompare instruction has |
| 3076 | // been merged into this HNotEqual instruction; evaluate it as |
| 3077 | // `Compare(x, y) != 0`. |
| 3078 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3079 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3080 | } |
| 3081 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3082 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3083 | } |
| 3084 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3085 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3086 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3087 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3088 | DECLARE_INSTRUCTION(NotEqual); |
| 3089 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3090 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3091 | return kCondNE; |
| 3092 | } |
| 3093 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3094 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3095 | return kCondEQ; |
| 3096 | } |
| 3097 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3098 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3099 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 3100 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3101 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3102 | }; |
| 3103 | |
| 3104 | class HLessThan : public HCondition { |
| 3105 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3106 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3107 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3108 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3109 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3110 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3111 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3112 | // In the following Evaluate methods, a HCompare instruction has |
| 3113 | // been merged into this HLessThan instruction; evaluate it as |
| 3114 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3115 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3116 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3117 | } |
| 3118 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3119 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3120 | } |
| 3121 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3122 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3123 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3124 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3125 | DECLARE_INSTRUCTION(LessThan); |
| 3126 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3127 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3128 | return kCondLT; |
| 3129 | } |
| 3130 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3131 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3132 | return kCondGE; |
| 3133 | } |
| 3134 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3135 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3136 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3137 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3138 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3139 | }; |
| 3140 | |
| 3141 | class HLessThanOrEqual : public HCondition { |
| 3142 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3143 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3144 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3145 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3146 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3147 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3148 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3149 | // In the following Evaluate methods, a HCompare instruction has |
| 3150 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3151 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3152 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3153 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3154 | } |
| 3155 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3156 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3157 | } |
| 3158 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3159 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3160 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3161 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3162 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3163 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3164 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3165 | return kCondLE; |
| 3166 | } |
| 3167 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3168 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3169 | return kCondGT; |
| 3170 | } |
| 3171 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3172 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3173 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3174 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3175 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3176 | }; |
| 3177 | |
| 3178 | class HGreaterThan : public HCondition { |
| 3179 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3180 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3181 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3182 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3183 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3184 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3185 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3186 | // In the following Evaluate methods, a HCompare instruction has |
| 3187 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3188 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3189 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3190 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3191 | } |
| 3192 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3193 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3194 | } |
| 3195 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3196 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3197 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3198 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3199 | DECLARE_INSTRUCTION(GreaterThan); |
| 3200 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3201 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3202 | return kCondGT; |
| 3203 | } |
| 3204 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3205 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3206 | return kCondLE; |
| 3207 | } |
| 3208 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3209 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3210 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3211 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3212 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3213 | }; |
| 3214 | |
| 3215 | class HGreaterThanOrEqual : public HCondition { |
| 3216 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3217 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3218 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3219 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3220 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3221 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3222 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3223 | // In the following Evaluate methods, a HCompare instruction has |
| 3224 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3225 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3226 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3227 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3228 | } |
| 3229 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3230 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3231 | } |
| 3232 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3233 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3234 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3235 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3236 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3237 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3238 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3239 | return kCondGE; |
| 3240 | } |
| 3241 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3242 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3243 | return kCondLT; |
| 3244 | } |
| 3245 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3246 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3247 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3248 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3249 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3250 | }; |
| 3251 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3252 | class HBelow : public HCondition { |
| 3253 | public: |
| 3254 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3255 | : HCondition(first, second, dex_pc) {} |
| 3256 | |
| 3257 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3258 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3259 | } |
| 3260 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3261 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3262 | } |
| 3263 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3264 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3265 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3266 | UNREACHABLE(); |
| 3267 | } |
| 3268 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3269 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3270 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3271 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
| 3274 | DECLARE_INSTRUCTION(Below); |
| 3275 | |
| 3276 | IfCondition GetCondition() const OVERRIDE { |
| 3277 | return kCondB; |
| 3278 | } |
| 3279 | |
| 3280 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3281 | return kCondAE; |
| 3282 | } |
| 3283 | |
| 3284 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3285 | template <typename T> bool Compute(T x, T y) const { |
| 3286 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3287 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3288 | |
| 3289 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3290 | }; |
| 3291 | |
| 3292 | class HBelowOrEqual : public HCondition { |
| 3293 | public: |
| 3294 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3295 | : HCondition(first, second, dex_pc) {} |
| 3296 | |
| 3297 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3298 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3299 | } |
| 3300 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3301 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3302 | } |
| 3303 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3304 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3305 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3306 | UNREACHABLE(); |
| 3307 | } |
| 3308 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3309 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3310 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3311 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3315 | |
| 3316 | IfCondition GetCondition() const OVERRIDE { |
| 3317 | return kCondBE; |
| 3318 | } |
| 3319 | |
| 3320 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3321 | return kCondA; |
| 3322 | } |
| 3323 | |
| 3324 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3325 | template <typename T> bool Compute(T x, T y) const { |
| 3326 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3327 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3328 | |
| 3329 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3330 | }; |
| 3331 | |
| 3332 | class HAbove : public HCondition { |
| 3333 | public: |
| 3334 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3335 | : HCondition(first, second, dex_pc) {} |
| 3336 | |
| 3337 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3338 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3339 | } |
| 3340 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3341 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3342 | } |
| 3343 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3344 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3345 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3346 | UNREACHABLE(); |
| 3347 | } |
| 3348 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3349 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3350 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3351 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
| 3354 | DECLARE_INSTRUCTION(Above); |
| 3355 | |
| 3356 | IfCondition GetCondition() const OVERRIDE { |
| 3357 | return kCondA; |
| 3358 | } |
| 3359 | |
| 3360 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3361 | return kCondBE; |
| 3362 | } |
| 3363 | |
| 3364 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3365 | template <typename T> bool Compute(T x, T y) const { |
| 3366 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3367 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3368 | |
| 3369 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3370 | }; |
| 3371 | |
| 3372 | class HAboveOrEqual : public HCondition { |
| 3373 | public: |
| 3374 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3375 | : HCondition(first, second, dex_pc) {} |
| 3376 | |
| 3377 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3378 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3379 | } |
| 3380 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3381 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3382 | } |
| 3383 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3384 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3385 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3386 | UNREACHABLE(); |
| 3387 | } |
| 3388 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3389 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3390 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3391 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3395 | |
| 3396 | IfCondition GetCondition() const OVERRIDE { |
| 3397 | return kCondAE; |
| 3398 | } |
| 3399 | |
| 3400 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3401 | return kCondB; |
| 3402 | } |
| 3403 | |
| 3404 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3405 | template <typename T> bool Compute(T x, T y) const { |
| 3406 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3407 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3408 | |
| 3409 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3410 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3411 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3412 | // Instruction to check how two inputs compare to each other. |
| 3413 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3414 | class HCompare : public HBinaryOperation { |
| 3415 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3416 | HCompare(Primitive::Type type, |
| 3417 | HInstruction* first, |
| 3418 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3419 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3420 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3421 | : HBinaryOperation(Primitive::kPrimInt, |
| 3422 | first, |
| 3423 | second, |
| 3424 | SideEffectsForArchRuntimeCalls(type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3425 | dex_pc) { |
| 3426 | SetPackedField<ComparisonBiasField>(bias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3427 | DCHECK_EQ(type, first->GetType()); |
| 3428 | DCHECK_EQ(type, second->GetType()); |
| 3429 | } |
| 3430 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3431 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3432 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3433 | |
| 3434 | template <typename T> |
| 3435 | int32_t ComputeFP(T x, T y) const { |
| 3436 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3437 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3438 | // Handle the bias. |
| 3439 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3440 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3441 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3442 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3443 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3444 | // reach this code path when processing a freshly built HIR |
| 3445 | // graph. However HCompare integer instructions can be synthesized |
| 3446 | // by the instruction simplifier to implement IntegerCompare and |
| 3447 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3448 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3449 | } |
| 3450 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3451 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3452 | } |
| 3453 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3454 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3455 | } |
| 3456 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3457 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3458 | } |
| 3459 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3460 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3461 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3462 | } |
| 3463 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3464 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3465 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3466 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3467 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3468 | bool IsGtBias() const { |
| 3469 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3470 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3471 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3472 | |
| 3473 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3474 | // MIPS64 uses a runtime call for FP comparisons. |
| 3475 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3476 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3477 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3478 | DECLARE_INSTRUCTION(Compare); |
| 3479 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3480 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3481 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3482 | static constexpr size_t kFieldComparisonBiasSize = |
| 3483 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3484 | static constexpr size_t kNumberOfComparePackedBits = |
| 3485 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3486 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3487 | using ComparisonBiasField = |
| 3488 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3489 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3490 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3491 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3492 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3493 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3494 | } |
| 3495 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3496 | private: |
| 3497 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3498 | }; |
| 3499 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3500 | // A local in the graph. Corresponds to a Dex register. |
| 3501 | class HLocal : public HTemplateInstruction<0> { |
| 3502 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3503 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3504 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3505 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3506 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3507 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3508 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3509 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3510 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3511 | // The Dex register number. |
| 3512 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3513 | |
| 3514 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3515 | }; |
| 3516 | |
| 3517 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3518 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3519 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3520 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3521 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3522 | SetRawInputAt(0, local); |
| 3523 | } |
| 3524 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3525 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3526 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3527 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3528 | |
| 3529 | private: |
| 3530 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3531 | }; |
| 3532 | |
| 3533 | // Store a value in a given local. This instruction has two inputs: the value |
| 3534 | // and the local. |
| 3535 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3536 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3537 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3538 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3539 | SetRawInputAt(0, local); |
| 3540 | SetRawInputAt(1, value); |
| 3541 | } |
| 3542 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3543 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3544 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3545 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3546 | |
| 3547 | private: |
| 3548 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3549 | }; |
| 3550 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3551 | class HNewInstance : public HExpression<2> { |
| 3552 | public: |
| 3553 | HNewInstance(HInstruction* cls, |
| 3554 | HCurrentMethod* current_method, |
| 3555 | uint32_t dex_pc, |
| 3556 | uint16_t type_index, |
| 3557 | const DexFile& dex_file, |
| 3558 | bool can_throw, |
| 3559 | bool finalizable, |
| 3560 | QuickEntrypointEnum entrypoint) |
| 3561 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3562 | type_index_(type_index), |
| 3563 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3564 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3565 | SetPackedFlag<kFlagCanThrow>(can_throw); |
| 3566 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3567 | SetRawInputAt(0, cls); |
| 3568 | SetRawInputAt(1, current_method); |
| 3569 | } |
| 3570 | |
| 3571 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3572 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3573 | |
| 3574 | // Calls runtime so needs an environment. |
| 3575 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3576 | |
| 3577 | // It may throw when called on type that's not instantiable/accessible. |
| 3578 | // It can throw OOME. |
| 3579 | // TODO: distinguish between the two cases so we can for example allow allocation elimination. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3580 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>() || true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3581 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3582 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3583 | |
| 3584 | bool CanBeNull() const OVERRIDE { return false; } |
| 3585 | |
| 3586 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3587 | |
| 3588 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3589 | entrypoint_ = entrypoint; |
| 3590 | } |
| 3591 | |
| 3592 | bool IsStringAlloc() const; |
| 3593 | |
| 3594 | DECLARE_INSTRUCTION(NewInstance); |
| 3595 | |
| 3596 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3597 | static constexpr size_t kFlagCanThrow = kNumberOfExpressionPackedBits; |
| 3598 | static constexpr size_t kFlagFinalizable = kFlagCanThrow + 1; |
| 3599 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3600 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3601 | "Too many packed fields."); |
| 3602 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3603 | const uint16_t type_index_; |
| 3604 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3605 | QuickEntrypointEnum entrypoint_; |
| 3606 | |
| 3607 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3608 | }; |
| 3609 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3610 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3611 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3612 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3613 | #include "intrinsics_list.h" |
| 3614 | kNone, |
| 3615 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3616 | #undef INTRINSICS_LIST |
| 3617 | #undef OPTIMIZING_INTRINSICS |
| 3618 | }; |
| 3619 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3620 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3621 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3622 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3623 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3624 | }; |
| 3625 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3626 | enum IntrinsicSideEffects { |
| 3627 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3628 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3629 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3630 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3631 | }; |
| 3632 | |
| 3633 | enum IntrinsicExceptions { |
| 3634 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3635 | kCanThrow // Intrinsic may throw exceptions. |
| 3636 | }; |
| 3637 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3638 | class HInvoke : public HInstruction { |
| 3639 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3640 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3641 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3642 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3643 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3644 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3645 | SetRawInputAt(index, argument); |
| 3646 | } |
| 3647 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3648 | // Return the number of arguments. This number can be lower than |
| 3649 | // the number of inputs returned by InputCount(), as some invoke |
| 3650 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3651 | // inputs at the end of their list of inputs. |
| 3652 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3653 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3654 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3655 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3656 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3657 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3658 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3659 | InvokeType GetOriginalInvokeType() const { |
| 3660 | return GetPackedField<OriginalInvokeTypeField>(); |
| 3661 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3662 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3663 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3664 | return intrinsic_; |
| 3665 | } |
| 3666 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3667 | void SetIntrinsic(Intrinsics intrinsic, |
| 3668 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3669 | IntrinsicSideEffects side_effects, |
| 3670 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3671 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3672 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3673 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3674 | } |
| 3675 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3676 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3677 | |
| 3678 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3679 | |
| 3680 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3681 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3682 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3683 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3684 | uint32_t* GetIntrinsicOptimizations() { |
| 3685 | return &intrinsic_optimizations_; |
| 3686 | } |
| 3687 | |
| 3688 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3689 | return &intrinsic_optimizations_; |
| 3690 | } |
| 3691 | |
| 3692 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3693 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3694 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3695 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3696 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3697 | static constexpr size_t kFieldOriginalInvokeType = kNumberOfGenericPackedBits; |
| 3698 | static constexpr size_t kFieldOriginalInvokeTypeSize = |
| 3699 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3700 | static constexpr size_t kFieldReturnType = |
| 3701 | kFieldOriginalInvokeType + kFieldOriginalInvokeTypeSize; |
| 3702 | static constexpr size_t kFieldReturnTypeSize = |
| 3703 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3704 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3705 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3706 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3707 | using OriginalInvokeTypeField = |
| 3708 | BitField<InvokeType, kFieldOriginalInvokeType, kFieldOriginalInvokeTypeSize>; |
| 3709 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3710 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3711 | HInvoke(ArenaAllocator* arena, |
| 3712 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3713 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3714 | Primitive::Type return_type, |
| 3715 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3716 | uint32_t dex_method_index, |
| 3717 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3718 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3719 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3720 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3721 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3722 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3723 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3724 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3725 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3726 | SetPackedField<ReturnTypeField>(return_type); |
| 3727 | SetPackedField<OriginalInvokeTypeField>(original_invoke_type); |
| 3728 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3729 | } |
| 3730 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3731 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3732 | return inputs_[index]; |
| 3733 | } |
| 3734 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3735 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3736 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3737 | } |
| 3738 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3739 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3740 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3741 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3742 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3743 | const uint32_t dex_method_index_; |
| 3744 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3745 | |
| 3746 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3747 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3748 | |
| 3749 | private: |
| 3750 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3751 | }; |
| 3752 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3753 | class HInvokeUnresolved : public HInvoke { |
| 3754 | public: |
| 3755 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3756 | uint32_t number_of_arguments, |
| 3757 | Primitive::Type return_type, |
| 3758 | uint32_t dex_pc, |
| 3759 | uint32_t dex_method_index, |
| 3760 | InvokeType invoke_type) |
| 3761 | : HInvoke(arena, |
| 3762 | number_of_arguments, |
| 3763 | 0u /* number_of_other_inputs */, |
| 3764 | return_type, |
| 3765 | dex_pc, |
| 3766 | dex_method_index, |
| 3767 | invoke_type) { |
| 3768 | } |
| 3769 | |
| 3770 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3771 | |
| 3772 | private: |
| 3773 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3774 | }; |
| 3775 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3776 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3777 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3778 | // Requirements of this method call regarding the class |
| 3779 | // initialization (clinit) check of its declaring class. |
| 3780 | enum class ClinitCheckRequirement { |
| 3781 | kNone, // Class already initialized. |
| 3782 | kExplicit, // Static call having explicit clinit check as last input. |
| 3783 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3784 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3785 | }; |
| 3786 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3787 | // Determines how to load the target ArtMethod*. |
| 3788 | enum class MethodLoadKind { |
| 3789 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3790 | kStringInit, |
| 3791 | |
| 3792 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3793 | kRecursive, |
| 3794 | |
| 3795 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3796 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3797 | kDirectAddress, |
| 3798 | |
| 3799 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3800 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3801 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3802 | // the image relocatable or not. |
| 3803 | kDirectAddressWithFixup, |
| 3804 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3805 | // Load from resolved methods array in the dex cache using a PC-relative load. |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3806 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3807 | // may cause class initialization (the entry may point to a resolution method), |
| 3808 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3809 | kDexCachePcRelative, |
| 3810 | |
| 3811 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3812 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3813 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3814 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3815 | kDexCacheViaMethod, |
| 3816 | }; |
| 3817 | |
| 3818 | // Determines the location of the code pointer. |
| 3819 | enum class CodePtrLocation { |
| 3820 | // Recursive call, use local PC-relative call instruction. |
| 3821 | kCallSelf, |
| 3822 | |
| 3823 | // Use PC-relative call instruction patched at link time. |
| 3824 | // Used for calls within an oat file, boot->boot or app->app. |
| 3825 | kCallPCRelative, |
| 3826 | |
| 3827 | // Call to a known target address, embed the direct address in code. |
| 3828 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3829 | kCallDirect, |
| 3830 | |
| 3831 | // Call to a target address that will be known at link time, embed the direct |
| 3832 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3833 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3834 | // the image relocatable or not. |
| 3835 | kCallDirectWithFixup, |
| 3836 | |
| 3837 | // Use code pointer from the ArtMethod*. |
| 3838 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3839 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3840 | kCallArtMethod, |
| 3841 | }; |
| 3842 | |
| 3843 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3844 | MethodLoadKind method_load_kind; |
| 3845 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3846 | // The method load data holds |
| 3847 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3848 | // Note that there are multiple string init methods, each having its own offset. |
| 3849 | // - the method address for kDirectAddress |
| 3850 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3851 | uint64_t method_load_data; |
| 3852 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3853 | }; |
| 3854 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3855 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3856 | uint32_t number_of_arguments, |
| 3857 | Primitive::Type return_type, |
| 3858 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3859 | uint32_t method_index, |
| 3860 | MethodReference target_method, |
| 3861 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3862 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3863 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3864 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3865 | : HInvoke(arena, |
| 3866 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3867 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3868 | // potentially one other if the clinit check is explicit, and potentially |
| 3869 | // one other if the method is a string factory. |
| 3870 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3871 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3872 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3873 | return_type, |
| 3874 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3875 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3876 | original_invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3877 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3878 | dispatch_info_(dispatch_info) { |
| 3879 | SetPackedField<OptimizedInvokeTypeField>(optimized_invoke_type); |
| 3880 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3881 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3882 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3883 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3884 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3885 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3886 | |
| 3887 | // Using the current method is the default and once we find a better |
| 3888 | // method load kind, we should not go back to using the current method. |
| 3889 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3890 | |
| 3891 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3892 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3893 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3894 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3895 | dispatch_info_ = dispatch_info; |
| 3896 | } |
| 3897 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3898 | void AddSpecialInput(HInstruction* input) { |
| 3899 | // We allow only one special input. |
| 3900 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3901 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3902 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3903 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3904 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3905 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3906 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3907 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3908 | // TODO: for intrinsics we can generate implicit null checks. |
| 3909 | return false; |
| 3910 | } |
| 3911 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3912 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3913 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3914 | } |
| 3915 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3916 | // Get the index of the special input, if any. |
| 3917 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3918 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3919 | // method pointer; otherwise there may be one platform-specific special input, |
| 3920 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3921 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 3922 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3923 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3924 | InvokeType GetOptimizedInvokeType() const { |
| 3925 | return GetPackedField<OptimizedInvokeTypeField>(); |
| 3926 | } |
| 3927 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3928 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3929 | SetPackedField<OptimizedInvokeTypeField>(invoke_type); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3932 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3933 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3934 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3935 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3936 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3937 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3938 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3939 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3940 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3941 | bool HasCurrentMethodInput() const { |
| 3942 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3943 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3944 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3945 | return true; |
| 3946 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3947 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3948 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3949 | return false; |
| 3950 | } |
| 3951 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3952 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3953 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3954 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3955 | |
| 3956 | int32_t GetStringInitOffset() const { |
| 3957 | DCHECK(IsStringInit()); |
| 3958 | return dispatch_info_.method_load_data; |
| 3959 | } |
| 3960 | |
| 3961 | uint64_t GetMethodAddress() const { |
| 3962 | DCHECK(HasMethodAddress()); |
| 3963 | return dispatch_info_.method_load_data; |
| 3964 | } |
| 3965 | |
| 3966 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3967 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3968 | return dispatch_info_.method_load_data; |
| 3969 | } |
| 3970 | |
| 3971 | uint64_t GetDirectCodePtr() const { |
| 3972 | DCHECK(HasDirectCodePtr()); |
| 3973 | return dispatch_info_.direct_code_ptr; |
| 3974 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3975 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3976 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 3977 | return GetPackedField<ClinitCheckRequirementField>(); |
| 3978 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3979 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3980 | // Is this instruction a call to a static method? |
| 3981 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3982 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3983 | } |
| 3984 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3985 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3986 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3987 | // instruction; only relevant for static calls with explicit clinit check. |
| 3988 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3989 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3990 | size_t last_input_index = InputCount() - 1; |
| 3991 | HInstruction* last_input = InputAt(last_input_index); |
| 3992 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3993 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3994 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3995 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3996 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3997 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3998 | } |
| 3999 | |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 4000 | HInstruction* GetAndRemoveThisArgumentOfStringInit() { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4001 | DCHECK(IsStringInit()); |
| 4002 | size_t index = InputCount() - 1; |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 4003 | HInstruction* input = InputAt(index); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4004 | RemoveAsUserOfInput(index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4005 | inputs_.pop_back(); |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 4006 | return input; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4007 | } |
| 4008 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4009 | // 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] | 4010 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4011 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4012 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4013 | } |
| 4014 | |
| 4015 | // Is this a call to a static method whose declaring class has an |
| 4016 | // implicit intialization check requirement? |
| 4017 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4018 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4019 | } |
| 4020 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4021 | // Does this method load kind need the current method as an input? |
| 4022 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4023 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4024 | } |
| 4025 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4026 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4027 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4028 | protected: |
| 4029 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 4030 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 4031 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 4032 | HInstruction* input = input_record.GetInstruction(); |
| 4033 | // `input` is the last input of a static invoke marked as having |
| 4034 | // an explicit clinit check. It must either be: |
| 4035 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4036 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4037 | DCHECK(input != nullptr); |
| 4038 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 4039 | } |
| 4040 | return input_record; |
| 4041 | } |
| 4042 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4043 | void InsertInputAt(size_t index, HInstruction* input); |
| 4044 | void RemoveInputAt(size_t index); |
| 4045 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4046 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4047 | static constexpr size_t kFieldOptimizedInvokeType = kNumberOfInvokePackedBits; |
| 4048 | static constexpr size_t kFieldOptimizedInvokeTypeSize = |
| 4049 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4050 | static constexpr size_t kFieldClinitCheckRequirement = |
| 4051 | kFieldOptimizedInvokeType + kFieldOptimizedInvokeTypeSize; |
| 4052 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4053 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4054 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4055 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4056 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4057 | "Too many packed fields."); |
| 4058 | using OptimizedInvokeTypeField = |
| 4059 | BitField<InvokeType, kFieldOptimizedInvokeType, kFieldOptimizedInvokeTypeSize>; |
| 4060 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4061 | kFieldClinitCheckRequirement, |
| 4062 | kFieldClinitCheckRequirementSize>; |
| 4063 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4064 | // The target method may refer to different dex file or method index than the original |
| 4065 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 4066 | // in derived class to increase visibility. |
| 4067 | MethodReference target_method_; |
| 4068 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4069 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4070 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4071 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4072 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4073 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4074 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4075 | class HInvokeVirtual : public HInvoke { |
| 4076 | public: |
| 4077 | HInvokeVirtual(ArenaAllocator* arena, |
| 4078 | uint32_t number_of_arguments, |
| 4079 | Primitive::Type return_type, |
| 4080 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4081 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4082 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4083 | : 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] | 4084 | vtable_index_(vtable_index) {} |
| 4085 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4086 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4087 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4088 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4089 | } |
| 4090 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4091 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4092 | |
| 4093 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4094 | |
| 4095 | private: |
| 4096 | const uint32_t vtable_index_; |
| 4097 | |
| 4098 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4099 | }; |
| 4100 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4101 | class HInvokeInterface : public HInvoke { |
| 4102 | public: |
| 4103 | HInvokeInterface(ArenaAllocator* arena, |
| 4104 | uint32_t number_of_arguments, |
| 4105 | Primitive::Type return_type, |
| 4106 | uint32_t dex_pc, |
| 4107 | uint32_t dex_method_index, |
| 4108 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4109 | : 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] | 4110 | imt_index_(imt_index) {} |
| 4111 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4112 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4113 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4114 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4115 | } |
| 4116 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4117 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4118 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4119 | |
| 4120 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4121 | |
| 4122 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4123 | const uint32_t imt_index_; |
| 4124 | |
| 4125 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4126 | }; |
| 4127 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4128 | class HNeg : public HUnaryOperation { |
| 4129 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4130 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4131 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4132 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4133 | template <typename T> T Compute(T x) const { return -x; } |
| 4134 | |
| 4135 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4136 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4137 | } |
| 4138 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4139 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4140 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4141 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4142 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4143 | } |
| 4144 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4145 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4146 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4147 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4148 | DECLARE_INSTRUCTION(Neg); |
| 4149 | |
| 4150 | private: |
| 4151 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4152 | }; |
| 4153 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4154 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4155 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4156 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4157 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4158 | uint32_t dex_pc, |
| 4159 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4160 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4161 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4162 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4163 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4164 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4165 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4166 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4167 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4168 | } |
| 4169 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4170 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4171 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4172 | |
| 4173 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4174 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4175 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4176 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4177 | bool CanThrow() const OVERRIDE { return true; } |
| 4178 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4179 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4180 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4181 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4182 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4183 | DECLARE_INSTRUCTION(NewArray); |
| 4184 | |
| 4185 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4186 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4187 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4188 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4189 | |
| 4190 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4191 | }; |
| 4192 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4193 | class HAdd : public HBinaryOperation { |
| 4194 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4195 | HAdd(Primitive::Type result_type, |
| 4196 | HInstruction* left, |
| 4197 | HInstruction* right, |
| 4198 | uint32_t dex_pc = kNoDexPc) |
| 4199 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4200 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4201 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4202 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4203 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 4204 | |
| 4205 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4206 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4207 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4208 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4209 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4210 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4211 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4212 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4213 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4214 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4215 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4216 | } |
| 4217 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4218 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4219 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4220 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4221 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4222 | DECLARE_INSTRUCTION(Add); |
| 4223 | |
| 4224 | private: |
| 4225 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4226 | }; |
| 4227 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4228 | class HSub : public HBinaryOperation { |
| 4229 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4230 | HSub(Primitive::Type result_type, |
| 4231 | HInstruction* left, |
| 4232 | HInstruction* right, |
| 4233 | uint32_t dex_pc = kNoDexPc) |
| 4234 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4235 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4236 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 4237 | |
| 4238 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4239 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4240 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4241 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4242 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4243 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4244 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4245 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4246 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4247 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4248 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4249 | } |
| 4250 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4251 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4252 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4253 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4254 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4255 | DECLARE_INSTRUCTION(Sub); |
| 4256 | |
| 4257 | private: |
| 4258 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4259 | }; |
| 4260 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4261 | class HMul : public HBinaryOperation { |
| 4262 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4263 | HMul(Primitive::Type result_type, |
| 4264 | HInstruction* left, |
| 4265 | HInstruction* right, |
| 4266 | uint32_t dex_pc = kNoDexPc) |
| 4267 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4268 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4269 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4270 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4271 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 4272 | |
| 4273 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4274 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4275 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4276 | } |
| 4277 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4278 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4279 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4280 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4281 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4282 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4283 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4284 | } |
| 4285 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4286 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4287 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4288 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4289 | |
| 4290 | DECLARE_INSTRUCTION(Mul); |
| 4291 | |
| 4292 | private: |
| 4293 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4294 | }; |
| 4295 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4296 | class HDiv : public HBinaryOperation { |
| 4297 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4298 | HDiv(Primitive::Type result_type, |
| 4299 | HInstruction* left, |
| 4300 | HInstruction* right, |
| 4301 | uint32_t dex_pc) |
| 4302 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4303 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4304 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4305 | T ComputeIntegral(T x, T y) const { |
| 4306 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4307 | // Our graph structure ensures we never have 0 for `y` during |
| 4308 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4309 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4310 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4311 | return (y == -1) ? -x : x / y; |
| 4312 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4313 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4314 | template <typename T> |
| 4315 | T ComputeFP(T x, T y) const { |
| 4316 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4317 | return x / y; |
| 4318 | } |
| 4319 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4320 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4321 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4322 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4323 | } |
| 4324 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4325 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4326 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4327 | } |
| 4328 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4329 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4330 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4331 | } |
| 4332 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4333 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4334 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4335 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4336 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4337 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4338 | // The generated code can use a runtime call. |
| 4339 | return SideEffects::CanTriggerGC(); |
| 4340 | } |
| 4341 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4342 | DECLARE_INSTRUCTION(Div); |
| 4343 | |
| 4344 | private: |
| 4345 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4346 | }; |
| 4347 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4348 | class HRem : public HBinaryOperation { |
| 4349 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4350 | HRem(Primitive::Type result_type, |
| 4351 | HInstruction* left, |
| 4352 | HInstruction* right, |
| 4353 | uint32_t dex_pc) |
| 4354 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4355 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4356 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4357 | T ComputeIntegral(T x, T y) const { |
| 4358 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4359 | // Our graph structure ensures we never have 0 for `y` during |
| 4360 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4361 | DCHECK_NE(y, 0); |
| 4362 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4363 | return (y == -1) ? 0 : x % y; |
| 4364 | } |
| 4365 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4366 | template <typename T> |
| 4367 | T ComputeFP(T x, T y) const { |
| 4368 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4369 | return std::fmod(x, y); |
| 4370 | } |
| 4371 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4372 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4373 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4374 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4375 | } |
| 4376 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4377 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4378 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4379 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4380 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4381 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4382 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4383 | } |
| 4384 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4385 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4386 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4387 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4388 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4389 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4390 | return SideEffects::CanTriggerGC(); |
| 4391 | } |
| 4392 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4393 | DECLARE_INSTRUCTION(Rem); |
| 4394 | |
| 4395 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4396 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4397 | }; |
| 4398 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4399 | class HDivZeroCheck : public HExpression<1> { |
| 4400 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4401 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4402 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4403 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4404 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4405 | SetRawInputAt(0, value); |
| 4406 | } |
| 4407 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4408 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4409 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4410 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4411 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4412 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4413 | return true; |
| 4414 | } |
| 4415 | |
| 4416 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4417 | bool CanThrow() const OVERRIDE { return true; } |
| 4418 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4419 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4420 | |
| 4421 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4422 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4423 | }; |
| 4424 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4425 | class HShl : public HBinaryOperation { |
| 4426 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4427 | HShl(Primitive::Type result_type, |
| 4428 | HInstruction* left, |
| 4429 | HInstruction* right, |
| 4430 | uint32_t dex_pc = kNoDexPc) |
| 4431 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4432 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4433 | template <typename T, typename U, typename V> |
| 4434 | T Compute(T x, U y, V max_shift_value) const { |
| 4435 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4436 | "V is not the unsigned integer type corresponding to T"); |
| 4437 | return x << (y & max_shift_value); |
| 4438 | } |
| 4439 | |
| 4440 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4441 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4442 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4443 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4444 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4445 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4446 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4447 | } |
| 4448 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4449 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4450 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4451 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4452 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4453 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4454 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4455 | UNREACHABLE(); |
| 4456 | } |
| 4457 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4458 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4459 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4460 | UNREACHABLE(); |
| 4461 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4462 | |
| 4463 | DECLARE_INSTRUCTION(Shl); |
| 4464 | |
| 4465 | private: |
| 4466 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4467 | }; |
| 4468 | |
| 4469 | class HShr : public HBinaryOperation { |
| 4470 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4471 | HShr(Primitive::Type result_type, |
| 4472 | HInstruction* left, |
| 4473 | HInstruction* right, |
| 4474 | uint32_t dex_pc = kNoDexPc) |
| 4475 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4476 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4477 | template <typename T, typename U, typename V> |
| 4478 | T Compute(T x, U y, V max_shift_value) const { |
| 4479 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4480 | "V is not the unsigned integer type corresponding to T"); |
| 4481 | return x >> (y & max_shift_value); |
| 4482 | } |
| 4483 | |
| 4484 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4485 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4486 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4487 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4488 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4489 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4490 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4491 | } |
| 4492 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4493 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4494 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4495 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4496 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4497 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4498 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4499 | UNREACHABLE(); |
| 4500 | } |
| 4501 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4502 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4503 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4504 | UNREACHABLE(); |
| 4505 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4506 | |
| 4507 | DECLARE_INSTRUCTION(Shr); |
| 4508 | |
| 4509 | private: |
| 4510 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4511 | }; |
| 4512 | |
| 4513 | class HUShr : public HBinaryOperation { |
| 4514 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4515 | HUShr(Primitive::Type result_type, |
| 4516 | HInstruction* left, |
| 4517 | HInstruction* right, |
| 4518 | uint32_t dex_pc = kNoDexPc) |
| 4519 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4520 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4521 | template <typename T, typename U, typename V> |
| 4522 | T Compute(T x, U y, V max_shift_value) const { |
| 4523 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4524 | "V is not the unsigned integer type corresponding to T"); |
| 4525 | V ux = static_cast<V>(x); |
| 4526 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4529 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4530 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4531 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4532 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4533 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4534 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4535 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4536 | } |
| 4537 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4538 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4539 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4540 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4541 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4542 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4543 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4544 | UNREACHABLE(); |
| 4545 | } |
| 4546 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4547 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4548 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4549 | UNREACHABLE(); |
| 4550 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4551 | |
| 4552 | DECLARE_INSTRUCTION(UShr); |
| 4553 | |
| 4554 | private: |
| 4555 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4556 | }; |
| 4557 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4558 | class HAnd : public HBinaryOperation { |
| 4559 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4560 | HAnd(Primitive::Type result_type, |
| 4561 | HInstruction* left, |
| 4562 | HInstruction* right, |
| 4563 | uint32_t dex_pc = kNoDexPc) |
| 4564 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4565 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4566 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4567 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4568 | template <typename T> T Compute(T x, T y) const { return x & y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4569 | |
| 4570 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4571 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4572 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4573 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4574 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4575 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4576 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4577 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4578 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4579 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4580 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4581 | UNREACHABLE(); |
| 4582 | } |
| 4583 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4584 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4585 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4586 | UNREACHABLE(); |
| 4587 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4588 | |
| 4589 | DECLARE_INSTRUCTION(And); |
| 4590 | |
| 4591 | private: |
| 4592 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4593 | }; |
| 4594 | |
| 4595 | class HOr : public HBinaryOperation { |
| 4596 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4597 | HOr(Primitive::Type result_type, |
| 4598 | HInstruction* left, |
| 4599 | HInstruction* right, |
| 4600 | uint32_t dex_pc = kNoDexPc) |
| 4601 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4602 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4603 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4604 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4605 | template <typename T> T Compute(T x, T y) const { return x | y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4606 | |
| 4607 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4608 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4609 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4610 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4611 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4612 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4613 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4614 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4615 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4616 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4617 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4618 | UNREACHABLE(); |
| 4619 | } |
| 4620 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4621 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4622 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4623 | UNREACHABLE(); |
| 4624 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4625 | |
| 4626 | DECLARE_INSTRUCTION(Or); |
| 4627 | |
| 4628 | private: |
| 4629 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4630 | }; |
| 4631 | |
| 4632 | class HXor : public HBinaryOperation { |
| 4633 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4634 | HXor(Primitive::Type result_type, |
| 4635 | HInstruction* left, |
| 4636 | HInstruction* right, |
| 4637 | uint32_t dex_pc = kNoDexPc) |
| 4638 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4639 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4640 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4641 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4642 | template <typename T> T Compute(T x, T y) const { return x ^ y; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4643 | |
| 4644 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4645 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4646 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4647 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4648 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4649 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4650 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4651 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4652 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4653 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4654 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4655 | UNREACHABLE(); |
| 4656 | } |
| 4657 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4658 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4659 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4660 | UNREACHABLE(); |
| 4661 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4662 | |
| 4663 | DECLARE_INSTRUCTION(Xor); |
| 4664 | |
| 4665 | private: |
| 4666 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4667 | }; |
| 4668 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4669 | class HRor : public HBinaryOperation { |
| 4670 | public: |
| 4671 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
| 4672 | : HBinaryOperation(result_type, value, distance) {} |
| 4673 | |
| 4674 | template <typename T, typename U, typename V> |
| 4675 | T Compute(T x, U y, V max_shift_value) const { |
| 4676 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4677 | "V is not the unsigned integer type corresponding to T"); |
| 4678 | V ux = static_cast<V>(x); |
| 4679 | if ((y & max_shift_value) == 0) { |
| 4680 | return static_cast<T>(ux); |
| 4681 | } else { |
| 4682 | const V reg_bits = sizeof(T) * 8; |
| 4683 | return static_cast<T>(ux >> (y & max_shift_value)) | |
| 4684 | (x << (reg_bits - (y & max_shift_value))); |
| 4685 | } |
| 4686 | } |
| 4687 | |
| 4688 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4689 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4690 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
| 4691 | } |
| 4692 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4693 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4694 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4695 | } |
| 4696 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4697 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4698 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4699 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4700 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4701 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4702 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4703 | UNREACHABLE(); |
| 4704 | } |
| 4705 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4706 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4707 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4708 | UNREACHABLE(); |
| 4709 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4710 | |
| 4711 | DECLARE_INSTRUCTION(Ror); |
| 4712 | |
| 4713 | private: |
| 4714 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4715 | }; |
| 4716 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4717 | // The value of a parameter in this method. Its location depends on |
| 4718 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4719 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4720 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4721 | HParameterValue(const DexFile& dex_file, |
| 4722 | uint16_t type_index, |
| 4723 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4724 | Primitive::Type parameter_type, |
| 4725 | bool is_this = false) |
| 4726 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4727 | dex_file_(dex_file), |
| 4728 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4729 | index_(index) { |
| 4730 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4731 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4732 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4733 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4734 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4735 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4736 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4737 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4738 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4739 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4740 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4741 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4742 | DECLARE_INSTRUCTION(ParameterValue); |
| 4743 | |
| 4744 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4745 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4746 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4747 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4748 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4749 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4750 | "Too many packed fields."); |
| 4751 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4752 | const DexFile& dex_file_; |
| 4753 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4754 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4755 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4756 | const uint8_t index_; |
| 4757 | |
| 4758 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4759 | }; |
| 4760 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4761 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4762 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4763 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4764 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4765 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4766 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4767 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4768 | return true; |
| 4769 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4770 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4771 | template <typename T> T Compute(T x) const { return ~x; } |
| 4772 | |
| 4773 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4774 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4775 | } |
| 4776 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4777 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4778 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4779 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4780 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4781 | UNREACHABLE(); |
| 4782 | } |
| 4783 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4784 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4785 | UNREACHABLE(); |
| 4786 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4787 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4788 | DECLARE_INSTRUCTION(Not); |
| 4789 | |
| 4790 | private: |
| 4791 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4792 | }; |
| 4793 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4794 | class HBooleanNot : public HUnaryOperation { |
| 4795 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4796 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4797 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4798 | |
| 4799 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4800 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4801 | return true; |
| 4802 | } |
| 4803 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4804 | template <typename T> bool Compute(T x) const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4805 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4806 | return !x; |
| 4807 | } |
| 4808 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4809 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4810 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4811 | } |
| 4812 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4813 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4814 | UNREACHABLE(); |
| 4815 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4816 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4817 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4818 | UNREACHABLE(); |
| 4819 | } |
| 4820 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4821 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4822 | UNREACHABLE(); |
| 4823 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4824 | |
| 4825 | DECLARE_INSTRUCTION(BooleanNot); |
| 4826 | |
| 4827 | private: |
| 4828 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4829 | }; |
| 4830 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4831 | class HTypeConversion : public HExpression<1> { |
| 4832 | public: |
| 4833 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4834 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4835 | : HExpression(result_type, |
| 4836 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4837 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4838 | SetRawInputAt(0, input); |
| 4839 | DCHECK_NE(input->GetType(), result_type); |
| 4840 | } |
| 4841 | |
| 4842 | HInstruction* GetInput() const { return InputAt(0); } |
| 4843 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4844 | Primitive::Type GetResultType() const { return GetType(); } |
| 4845 | |
| 4846 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4847 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4848 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4849 | // Try to statically evaluate the conversion and return a HConstant |
| 4850 | // containing the result. If the input cannot be converted, return nullptr. |
| 4851 | HConstant* TryStaticEvaluation() const; |
| 4852 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4853 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4854 | Primitive::Type result_type) { |
| 4855 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4856 | // in the compilation process we do not know what architecture we will |
| 4857 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4858 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4859 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4860 | return SideEffects::CanTriggerGC(); |
| 4861 | } |
| 4862 | return SideEffects::None(); |
| 4863 | } |
| 4864 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4865 | DECLARE_INSTRUCTION(TypeConversion); |
| 4866 | |
| 4867 | private: |
| 4868 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4869 | }; |
| 4870 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4871 | static constexpr uint32_t kNoRegNumber = -1; |
| 4872 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4873 | class HPhi : public HInstruction { |
| 4874 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4875 | HPhi(ArenaAllocator* arena, |
| 4876 | uint32_t reg_number, |
| 4877 | size_t number_of_inputs, |
| 4878 | Primitive::Type type, |
| 4879 | uint32_t dex_pc = kNoDexPc) |
| 4880 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4881 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4882 | reg_number_(reg_number) { |
| 4883 | SetPackedField<TypeField>(ToPhiType(type)); |
| 4884 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 4885 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4886 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4887 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4888 | SetPackedFlag<kFlagIsLive>(true); |
| 4889 | SetPackedFlag<kFlagCanBeNull>(true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4890 | } |
| 4891 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4892 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4893 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4894 | switch (type) { |
| 4895 | case Primitive::kPrimBoolean: |
| 4896 | case Primitive::kPrimByte: |
| 4897 | case Primitive::kPrimShort: |
| 4898 | case Primitive::kPrimChar: |
| 4899 | return Primitive::kPrimInt; |
| 4900 | default: |
| 4901 | return type; |
| 4902 | } |
| 4903 | } |
| 4904 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4905 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4906 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4907 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4908 | |
| 4909 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4910 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4911 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4912 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4913 | void SetType(Primitive::Type new_type) { |
| 4914 | // Make sure that only valid type changes occur. The following are allowed: |
| 4915 | // (1) int -> float/ref (primitive type propagation), |
| 4916 | // (2) long -> double (primitive type propagation). |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4917 | DCHECK(GetType() == new_type || |
| 4918 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 4919 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 4920 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 4921 | SetPackedField<TypeField>(new_type); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4922 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4923 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4924 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4925 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4926 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4927 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4928 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4929 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 4930 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 4931 | bool IsDead() const { return !IsLive(); } |
| 4932 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4933 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4934 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4935 | return other != nullptr |
| 4936 | && other->IsPhi() |
| 4937 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4938 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4939 | } |
| 4940 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4941 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4942 | // An equivalent phi is a phi having the same dex register and type. |
| 4943 | // It assumes that phis with the same dex register are adjacent. |
| 4944 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4945 | HInstruction* next = GetNext(); |
| 4946 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4947 | if (next->GetType() == GetType()) { |
| 4948 | return next->AsPhi(); |
| 4949 | } |
| 4950 | next = next->GetNext(); |
| 4951 | } |
| 4952 | return nullptr; |
| 4953 | } |
| 4954 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4955 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4956 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4957 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4958 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4959 | return inputs_[index]; |
| 4960 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4961 | |
| 4962 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4963 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4964 | } |
| 4965 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4966 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4967 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 4968 | static constexpr size_t kFieldTypeSize = |
| 4969 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 4970 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 4971 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 4972 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 4973 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4974 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 4975 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4976 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4977 | const uint32_t reg_number_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4978 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4979 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4980 | }; |
| 4981 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4982 | class HNullCheck : public HExpression<1> { |
| 4983 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4984 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4985 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4986 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4987 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4988 | SetRawInputAt(0, value); |
| 4989 | } |
| 4990 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4991 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4992 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4993 | return true; |
| 4994 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4995 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4996 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4997 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4998 | bool CanThrow() const OVERRIDE { return true; } |
| 4999 | |
| 5000 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5001 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5002 | |
| 5003 | DECLARE_INSTRUCTION(NullCheck); |
| 5004 | |
| 5005 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5006 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5007 | }; |
| 5008 | |
| 5009 | class FieldInfo : public ValueObject { |
| 5010 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5011 | FieldInfo(MemberOffset field_offset, |
| 5012 | Primitive::Type field_type, |
| 5013 | bool is_volatile, |
| 5014 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5015 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5016 | const DexFile& dex_file, |
| 5017 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5018 | : field_offset_(field_offset), |
| 5019 | field_type_(field_type), |
| 5020 | is_volatile_(is_volatile), |
| 5021 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5022 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5023 | dex_file_(dex_file), |
| 5024 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5025 | |
| 5026 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5027 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5028 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5029 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5030 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5031 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5032 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5033 | |
| 5034 | private: |
| 5035 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5036 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5037 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5038 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5039 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5040 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5041 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5042 | }; |
| 5043 | |
| 5044 | class HInstanceFieldGet : public HExpression<1> { |
| 5045 | public: |
| 5046 | HInstanceFieldGet(HInstruction* value, |
| 5047 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5048 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5049 | bool is_volatile, |
| 5050 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5051 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5052 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5053 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5054 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5055 | : HExpression(field_type, |
| 5056 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5057 | dex_pc), |
| 5058 | field_info_(field_offset, |
| 5059 | field_type, |
| 5060 | is_volatile, |
| 5061 | field_idx, |
| 5062 | declaring_class_def_index, |
| 5063 | dex_file, |
| 5064 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5065 | SetRawInputAt(0, value); |
| 5066 | } |
| 5067 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5068 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5069 | |
| 5070 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5071 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 5072 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5073 | } |
| 5074 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5075 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5076 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5077 | } |
| 5078 | |
| 5079 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5080 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5081 | } |
| 5082 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5083 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5084 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5085 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5086 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5087 | |
| 5088 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5089 | |
| 5090 | private: |
| 5091 | const FieldInfo field_info_; |
| 5092 | |
| 5093 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5094 | }; |
| 5095 | |
| 5096 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 5097 | public: |
| 5098 | HInstanceFieldSet(HInstruction* object, |
| 5099 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5100 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5101 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5102 | bool is_volatile, |
| 5103 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5104 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5105 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5106 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5107 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5108 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5109 | dex_pc), |
| 5110 | field_info_(field_offset, |
| 5111 | field_type, |
| 5112 | is_volatile, |
| 5113 | field_idx, |
| 5114 | declaring_class_def_index, |
| 5115 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5116 | dex_cache) { |
| 5117 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5118 | SetRawInputAt(0, object); |
| 5119 | SetRawInputAt(1, value); |
| 5120 | } |
| 5121 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5122 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5123 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5124 | } |
| 5125 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5126 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5127 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5128 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5129 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5130 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5131 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5132 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5133 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5134 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5135 | |
| 5136 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5137 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5138 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5139 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5140 | "Too many packed fields."); |
| 5141 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5142 | const FieldInfo field_info_; |
| 5143 | |
| 5144 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5145 | }; |
| 5146 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5147 | class HArrayGet : public HExpression<2> { |
| 5148 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5149 | HArrayGet(HInstruction* array, |
| 5150 | HInstruction* index, |
| 5151 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5152 | uint32_t dex_pc, |
| 5153 | SideEffects additional_side_effects = SideEffects::None()) |
| 5154 | : HExpression(type, |
| 5155 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 5156 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5157 | SetRawInputAt(0, array); |
| 5158 | SetRawInputAt(1, index); |
| 5159 | } |
| 5160 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5161 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5162 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5163 | return true; |
| 5164 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5165 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5166 | // TODO: We can be smarter here. |
| 5167 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5168 | // which generates the implicit null check. There are cases when these can be removed |
| 5169 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5170 | // implicit check here (as long as the address falls in the first page). |
| 5171 | return false; |
| 5172 | } |
| 5173 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5174 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5175 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5176 | if (kIsDebugBuild && result) { |
| 5177 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5178 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5179 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5180 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5181 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5182 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5183 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5184 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5185 | } |
| 5186 | } |
| 5187 | return result; |
| 5188 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5189 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5190 | HInstruction* GetArray() const { return InputAt(0); } |
| 5191 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5192 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5193 | DECLARE_INSTRUCTION(ArrayGet); |
| 5194 | |
| 5195 | private: |
| 5196 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5197 | }; |
| 5198 | |
| 5199 | class HArraySet : public HTemplateInstruction<3> { |
| 5200 | public: |
| 5201 | HArraySet(HInstruction* array, |
| 5202 | HInstruction* index, |
| 5203 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5204 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5205 | uint32_t dex_pc, |
| 5206 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5207 | : HTemplateInstruction( |
| 5208 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5209 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 5210 | additional_side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5211 | dex_pc) { |
| 5212 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5213 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5214 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5215 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5216 | SetRawInputAt(0, array); |
| 5217 | SetRawInputAt(1, index); |
| 5218 | SetRawInputAt(2, value); |
| 5219 | } |
| 5220 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5221 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5222 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5223 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5224 | } |
| 5225 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5226 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5227 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5228 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5229 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5230 | // TODO: Same as for ArrayGet. |
| 5231 | return false; |
| 5232 | } |
| 5233 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5234 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5235 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5236 | } |
| 5237 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5238 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5239 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5240 | } |
| 5241 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5242 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5243 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5244 | } |
| 5245 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5246 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5247 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5248 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5249 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5250 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5251 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5252 | HInstruction* GetArray() const { return InputAt(0); } |
| 5253 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5254 | HInstruction* GetValue() const { return InputAt(2); } |
| 5255 | |
| 5256 | Primitive::Type GetComponentType() const { |
| 5257 | // The Dex format does not type floating point index operations. Since the |
| 5258 | // `expected_component_type_` is set during building and can therefore not |
| 5259 | // be correct, we also check what is the value type. If it is a floating |
| 5260 | // point type, we must use that type. |
| 5261 | Primitive::Type value_type = GetValue()->GetType(); |
| 5262 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5263 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5264 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5265 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5266 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5267 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5268 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5269 | } |
| 5270 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5271 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5272 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5273 | } |
| 5274 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5275 | DECLARE_INSTRUCTION(ArraySet); |
| 5276 | |
| 5277 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5278 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5279 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5280 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5281 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5282 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5283 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5284 | // Cached information for the reference_type_info_ so that codegen |
| 5285 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5286 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5287 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5288 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5289 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5290 | using ExpectedComponentTypeField = |
| 5291 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5292 | |
| 5293 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5294 | }; |
| 5295 | |
| 5296 | class HArrayLength : public HExpression<1> { |
| 5297 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 5298 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5299 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5300 | // Note that arrays do not change length, so the instruction does not |
| 5301 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5302 | SetRawInputAt(0, array); |
| 5303 | } |
| 5304 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5305 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5306 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5307 | return true; |
| 5308 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5309 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5310 | return obj == InputAt(0); |
| 5311 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5312 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5313 | DECLARE_INSTRUCTION(ArrayLength); |
| 5314 | |
| 5315 | private: |
| 5316 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5317 | }; |
| 5318 | |
| 5319 | class HBoundsCheck : public HExpression<2> { |
| 5320 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5321 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5322 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5323 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5324 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5325 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 5326 | SetRawInputAt(0, index); |
| 5327 | SetRawInputAt(1, length); |
| 5328 | } |
| 5329 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5330 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5331 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5332 | return true; |
| 5333 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5334 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5335 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5336 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5337 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5338 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5339 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5340 | |
| 5341 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5342 | |
| 5343 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5344 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5345 | }; |
| 5346 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5347 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 5348 | public: |
| 5349 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5350 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5351 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5352 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5353 | return true; |
| 5354 | } |
| 5355 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5356 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5357 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5358 | |
| 5359 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5360 | |
| 5361 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5362 | // Only used for code generation, in order to share the same slow path between back edges |
| 5363 | // of a same loop. |
| 5364 | SlowPathCode* slow_path_; |
| 5365 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5366 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5367 | }; |
| 5368 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5369 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5370 | // It ensures that we can generate line number and local variables at this point. |
| 5371 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5372 | public: |
| 5373 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5374 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5375 | |
| 5376 | bool NeedsEnvironment() const OVERRIDE { |
| 5377 | return true; |
| 5378 | } |
| 5379 | |
| 5380 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5381 | |
| 5382 | private: |
| 5383 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5384 | }; |
| 5385 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5386 | /** |
| 5387 | * Instruction to load a Class object. |
| 5388 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5389 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5390 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5391 | HLoadClass(HCurrentMethod* current_method, |
| 5392 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5393 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5394 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5395 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5396 | bool needs_access_check, |
| 5397 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5398 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5399 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5400 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5401 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5402 | // Referrers class should not need access check. We never inline unverified |
| 5403 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5404 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5405 | |
| 5406 | SetPackedFlag<kFlagIsReferrersClass>(is_referrers_class); |
| 5407 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5408 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
| 5409 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5410 | SetRawInputAt(0, current_method); |
| 5411 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5412 | |
| 5413 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5414 | |
| 5415 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5416 | // Note that we don't need to test for generate_clinit_check_. |
| 5417 | // Whether or not we need to generate the clinit check is processed in |
| 5418 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5419 | return other->AsLoadClass()->type_index_ == type_index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5420 | other->AsLoadClass()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5424 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5425 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5426 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5427 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5428 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5429 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5430 | } |
| 5431 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5432 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5433 | // The entrypoint the code generator is going to call does not do |
| 5434 | // clinit of the class. |
| 5435 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5436 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5437 | } |
| 5438 | |
| 5439 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5440 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5441 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5442 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5443 | } |
| 5444 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5445 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5446 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5447 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5448 | } |
| 5449 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5450 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5451 | return loaded_class_rti_; |
| 5452 | } |
| 5453 | |
| 5454 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5455 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5456 | DCHECK(rti.IsExact()); |
| 5457 | loaded_class_rti_ = rti; |
| 5458 | } |
| 5459 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5460 | const DexFile& GetDexFile() { return dex_file_; } |
| 5461 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5462 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5463 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5464 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5465 | return SideEffects::CanTriggerGC(); |
| 5466 | } |
| 5467 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5468 | bool IsReferrersClass() const { return GetPackedFlag<kFlagIsReferrersClass>(); } |
| 5469 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5470 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5471 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5472 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5473 | DECLARE_INSTRUCTION(LoadClass); |
| 5474 | |
| 5475 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5476 | static constexpr size_t kFlagIsReferrersClass = kNumberOfExpressionPackedBits; |
| 5477 | static constexpr size_t kFlagNeedsAccessCheck = kFlagIsReferrersClass + 1; |
| 5478 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5479 | // Whether this instruction must generate the initialization check. |
| 5480 | // Used for code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5481 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInDexCache + 1; |
| 5482 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagGenerateClInitCheck + 1; |
| 5483 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5484 | |
| 5485 | const uint16_t type_index_; |
| 5486 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5487 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5488 | ReferenceTypeInfo loaded_class_rti_; |
| 5489 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5490 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5491 | }; |
| 5492 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5493 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5494 | public: |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5495 | HLoadString(HCurrentMethod* current_method, |
| 5496 | uint32_t string_index, |
| 5497 | uint32_t dex_pc, |
| 5498 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5499 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5500 | string_index_(string_index) { |
| 5501 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5502 | SetRawInputAt(0, current_method); |
| 5503 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5504 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5505 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5506 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5507 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5508 | return other->AsLoadString()->string_index_ == string_index_; |
| 5509 | } |
| 5510 | |
| 5511 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5512 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5513 | uint32_t GetStringIndex() const { return string_index_; } |
| 5514 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5515 | // Will call the runtime if the string is not already in the dex cache. |
| 5516 | bool NeedsEnvironment() const OVERRIDE { return !IsInDexCache(); } |
| 5517 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5518 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5519 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5520 | bool CanThrow() const OVERRIDE { return !IsInDexCache(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5521 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5522 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5523 | return SideEffects::CanTriggerGC(); |
| 5524 | } |
| 5525 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5526 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5527 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5528 | DECLARE_INSTRUCTION(LoadString); |
| 5529 | |
| 5530 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5531 | static constexpr size_t kFlagIsInDexCache = kNumberOfExpressionPackedBits; |
| 5532 | static constexpr size_t kNumberOfLoadStringPackedBits = kFlagIsInDexCache + 1; |
| 5533 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5534 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5535 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5536 | |
| 5537 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5538 | }; |
| 5539 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5540 | /** |
| 5541 | * Performs an initialization check on its Class object input. |
| 5542 | */ |
| 5543 | class HClinitCheck : public HExpression<1> { |
| 5544 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5545 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5546 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5547 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5548 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5549 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5550 | SetRawInputAt(0, constant); |
| 5551 | } |
| 5552 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5553 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5554 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5555 | return true; |
| 5556 | } |
| 5557 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5558 | bool NeedsEnvironment() const OVERRIDE { |
| 5559 | // May call runtime to initialize the class. |
| 5560 | return true; |
| 5561 | } |
| 5562 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5563 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5564 | |
| 5565 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5566 | |
| 5567 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5568 | |
| 5569 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5570 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5571 | }; |
| 5572 | |
| 5573 | class HStaticFieldGet : public HExpression<1> { |
| 5574 | public: |
| 5575 | HStaticFieldGet(HInstruction* cls, |
| 5576 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5577 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5578 | bool is_volatile, |
| 5579 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5580 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5581 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5582 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5583 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5584 | : HExpression(field_type, |
| 5585 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5586 | dex_pc), |
| 5587 | field_info_(field_offset, |
| 5588 | field_type, |
| 5589 | is_volatile, |
| 5590 | field_idx, |
| 5591 | declaring_class_def_index, |
| 5592 | dex_file, |
| 5593 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5594 | SetRawInputAt(0, cls); |
| 5595 | } |
| 5596 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5597 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5598 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5599 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5600 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5601 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5602 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5603 | } |
| 5604 | |
| 5605 | size_t ComputeHashCode() const OVERRIDE { |
| 5606 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5607 | } |
| 5608 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5609 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5610 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5611 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5612 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5613 | |
| 5614 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5615 | |
| 5616 | private: |
| 5617 | const FieldInfo field_info_; |
| 5618 | |
| 5619 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5620 | }; |
| 5621 | |
| 5622 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5623 | public: |
| 5624 | HStaticFieldSet(HInstruction* cls, |
| 5625 | HInstruction* value, |
| 5626 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5627 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5628 | bool is_volatile, |
| 5629 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5630 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5631 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5632 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5633 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5634 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5635 | dex_pc), |
| 5636 | field_info_(field_offset, |
| 5637 | field_type, |
| 5638 | is_volatile, |
| 5639 | field_idx, |
| 5640 | declaring_class_def_index, |
| 5641 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5642 | dex_cache) { |
| 5643 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5644 | SetRawInputAt(0, cls); |
| 5645 | SetRawInputAt(1, value); |
| 5646 | } |
| 5647 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5648 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5649 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5650 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5651 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5652 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5653 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5654 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5655 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5656 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5657 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5658 | |
| 5659 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5660 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5661 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5662 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5663 | "Too many packed fields."); |
| 5664 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5665 | const FieldInfo field_info_; |
| 5666 | |
| 5667 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5668 | }; |
| 5669 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5670 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5671 | public: |
| 5672 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5673 | Primitive::Type field_type, |
| 5674 | uint32_t field_index, |
| 5675 | uint32_t dex_pc) |
| 5676 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5677 | field_index_(field_index) { |
| 5678 | SetRawInputAt(0, obj); |
| 5679 | } |
| 5680 | |
| 5681 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5682 | bool CanThrow() const OVERRIDE { return true; } |
| 5683 | |
| 5684 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5685 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5686 | |
| 5687 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5688 | |
| 5689 | private: |
| 5690 | const uint32_t field_index_; |
| 5691 | |
| 5692 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5693 | }; |
| 5694 | |
| 5695 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5696 | public: |
| 5697 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5698 | HInstruction* value, |
| 5699 | Primitive::Type field_type, |
| 5700 | uint32_t field_index, |
| 5701 | uint32_t dex_pc) |
| 5702 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5703 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5704 | SetPackedField<FieldTypeField>(field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5705 | DCHECK_EQ(field_type, value->GetType()); |
| 5706 | SetRawInputAt(0, obj); |
| 5707 | SetRawInputAt(1, value); |
| 5708 | } |
| 5709 | |
| 5710 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5711 | bool CanThrow() const OVERRIDE { return true; } |
| 5712 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5713 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5714 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5715 | |
| 5716 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5717 | |
| 5718 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5719 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5720 | static constexpr size_t kFieldFieldTypeSize = |
| 5721 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5722 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5723 | kFieldFieldType + kFieldFieldTypeSize; |
| 5724 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5725 | "Too many packed fields."); |
| 5726 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5727 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5728 | const uint32_t field_index_; |
| 5729 | |
| 5730 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5731 | }; |
| 5732 | |
| 5733 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5734 | public: |
| 5735 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5736 | uint32_t field_index, |
| 5737 | uint32_t dex_pc) |
| 5738 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5739 | field_index_(field_index) { |
| 5740 | } |
| 5741 | |
| 5742 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5743 | bool CanThrow() const OVERRIDE { return true; } |
| 5744 | |
| 5745 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5746 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5747 | |
| 5748 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5749 | |
| 5750 | private: |
| 5751 | const uint32_t field_index_; |
| 5752 | |
| 5753 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5754 | }; |
| 5755 | |
| 5756 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5757 | public: |
| 5758 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5759 | Primitive::Type field_type, |
| 5760 | uint32_t field_index, |
| 5761 | uint32_t dex_pc) |
| 5762 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5763 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5764 | SetPackedField<FieldTypeField>(field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5765 | DCHECK_EQ(field_type, value->GetType()); |
| 5766 | SetRawInputAt(0, value); |
| 5767 | } |
| 5768 | |
| 5769 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5770 | bool CanThrow() const OVERRIDE { return true; } |
| 5771 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5772 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5773 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5774 | |
| 5775 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5776 | |
| 5777 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5778 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5779 | static constexpr size_t kFieldFieldTypeSize = |
| 5780 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5781 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5782 | kFieldFieldType + kFieldFieldTypeSize; |
| 5783 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5784 | "Too many packed fields."); |
| 5785 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5786 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5787 | const uint32_t field_index_; |
| 5788 | |
| 5789 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5790 | }; |
| 5791 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5792 | // Implement the move-exception DEX instruction. |
| 5793 | class HLoadException : public HExpression<0> { |
| 5794 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5795 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5796 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5797 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5798 | bool CanBeNull() const OVERRIDE { return false; } |
| 5799 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5800 | DECLARE_INSTRUCTION(LoadException); |
| 5801 | |
| 5802 | private: |
| 5803 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5804 | }; |
| 5805 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5806 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5807 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5808 | class HClearException : public HTemplateInstruction<0> { |
| 5809 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5810 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5811 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5812 | |
| 5813 | DECLARE_INSTRUCTION(ClearException); |
| 5814 | |
| 5815 | private: |
| 5816 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5817 | }; |
| 5818 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5819 | class HThrow : public HTemplateInstruction<1> { |
| 5820 | public: |
| 5821 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5822 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5823 | SetRawInputAt(0, exception); |
| 5824 | } |
| 5825 | |
| 5826 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5827 | |
| 5828 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5829 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5830 | bool CanThrow() const OVERRIDE { return true; } |
| 5831 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5832 | |
| 5833 | DECLARE_INSTRUCTION(Throw); |
| 5834 | |
| 5835 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5836 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5837 | }; |
| 5838 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5839 | /** |
| 5840 | * Implementation strategies for the code generator of a HInstanceOf |
| 5841 | * or `HCheckCast`. |
| 5842 | */ |
| 5843 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5844 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5845 | kExactCheck, // Can do a single class compare. |
| 5846 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5847 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5848 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5849 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5850 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 5851 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5852 | }; |
| 5853 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5854 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 5855 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5856 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5857 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5858 | HInstanceOf(HInstruction* object, |
| 5859 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5860 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5861 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5862 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5863 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5864 | dex_pc) { |
| 5865 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5866 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5867 | SetRawInputAt(0, object); |
| 5868 | SetRawInputAt(1, constant); |
| 5869 | } |
| 5870 | |
| 5871 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5872 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5873 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5874 | return true; |
| 5875 | } |
| 5876 | |
| 5877 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5878 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5881 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5882 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 5883 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 5884 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 5885 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5886 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5887 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 5888 | // Mips currently does runtime calls for any other checks. |
| 5889 | return check_kind != TypeCheckKind::kExactCheck; |
| 5890 | } |
| 5891 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5892 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5893 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5894 | } |
| 5895 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5896 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5897 | |
| 5898 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5899 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 5900 | static constexpr size_t kFieldTypeCheckKindSize = |
| 5901 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 5902 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 5903 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 5904 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5905 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5906 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5907 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5908 | }; |
| 5909 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5910 | class HBoundType : public HExpression<1> { |
| 5911 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5912 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5913 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5914 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 5915 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 5916 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5917 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5918 | SetRawInputAt(0, input); |
| 5919 | } |
| 5920 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5921 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5922 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5923 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5924 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5925 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5926 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5927 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 5928 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5929 | } |
| 5930 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5931 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5932 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5933 | DECLARE_INSTRUCTION(BoundType); |
| 5934 | |
| 5935 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5936 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5937 | // is false then CanBeNull() cannot be true). |
| 5938 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 5939 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 5940 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 5941 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5942 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5943 | // 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] | 5944 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5945 | // It is used to bound the type in cases like: |
| 5946 | // if (x instanceof ClassX) { |
| 5947 | // // uper_bound_ will be ClassX |
| 5948 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5949 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5950 | |
| 5951 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5952 | }; |
| 5953 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5954 | class HCheckCast : public HTemplateInstruction<2> { |
| 5955 | public: |
| 5956 | HCheckCast(HInstruction* object, |
| 5957 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5958 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5959 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5960 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 5961 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5962 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5963 | SetRawInputAt(0, object); |
| 5964 | SetRawInputAt(1, constant); |
| 5965 | } |
| 5966 | |
| 5967 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5968 | |
| 5969 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5970 | return true; |
| 5971 | } |
| 5972 | |
| 5973 | bool NeedsEnvironment() const OVERRIDE { |
| 5974 | // Instruction may throw a CheckCastError. |
| 5975 | return true; |
| 5976 | } |
| 5977 | |
| 5978 | bool CanThrow() const OVERRIDE { return true; } |
| 5979 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5980 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 5981 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 5982 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 5983 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5984 | |
| 5985 | DECLARE_INSTRUCTION(CheckCast); |
| 5986 | |
| 5987 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5988 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 5989 | static constexpr size_t kFieldTypeCheckKindSize = |
| 5990 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 5991 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 5992 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 5993 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5994 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5995 | |
| 5996 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5997 | }; |
| 5998 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5999 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 6000 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6001 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6002 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6003 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6004 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6005 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6006 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6007 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6008 | |
| 6009 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6010 | |
| 6011 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6012 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6013 | static constexpr size_t kFieldBarrierKindSize = |
| 6014 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6015 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6016 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6017 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6018 | "Too many packed fields."); |
| 6019 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6020 | |
| 6021 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6022 | }; |
| 6023 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6024 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 6025 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6026 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6027 | kEnter, |
| 6028 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6029 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6030 | }; |
| 6031 | |
| 6032 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6033 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6034 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6035 | dex_pc) { |
| 6036 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6037 | SetRawInputAt(0, object); |
| 6038 | } |
| 6039 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6040 | // Instruction may go into runtime, so we need an environment. |
| 6041 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6042 | |
| 6043 | bool CanThrow() const OVERRIDE { |
| 6044 | // Verifier guarantees that monitor-exit cannot throw. |
| 6045 | // This is important because it allows the HGraphBuilder to remove |
| 6046 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6047 | return IsEnter(); |
| 6048 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6049 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6050 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6051 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6052 | |
| 6053 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6054 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6055 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6056 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6057 | static constexpr size_t kFieldOperationKindSize = |
| 6058 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6059 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6060 | kFieldOperationKind + kFieldOperationKindSize; |
| 6061 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6062 | "Too many packed fields."); |
| 6063 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6064 | |
| 6065 | private: |
| 6066 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6067 | }; |
| 6068 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6069 | class HSelect : public HExpression<3> { |
| 6070 | public: |
| 6071 | HSelect(HInstruction* condition, |
| 6072 | HInstruction* true_value, |
| 6073 | HInstruction* false_value, |
| 6074 | uint32_t dex_pc) |
| 6075 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6076 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6077 | |
| 6078 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6079 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6080 | // that architectures which implement HSelect as a conditional move also |
| 6081 | // will not need to invert the condition. |
| 6082 | SetRawInputAt(0, false_value); |
| 6083 | SetRawInputAt(1, true_value); |
| 6084 | SetRawInputAt(2, condition); |
| 6085 | } |
| 6086 | |
| 6087 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6088 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6089 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6090 | |
| 6091 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6092 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
| 6093 | |
| 6094 | bool CanBeNull() const OVERRIDE { |
| 6095 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6096 | } |
| 6097 | |
| 6098 | DECLARE_INSTRUCTION(Select); |
| 6099 | |
| 6100 | private: |
| 6101 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6102 | }; |
| 6103 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6104 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6105 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6106 | MoveOperands(Location source, |
| 6107 | Location destination, |
| 6108 | Primitive::Type type, |
| 6109 | HInstruction* instruction) |
| 6110 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6111 | |
| 6112 | Location GetSource() const { return source_; } |
| 6113 | Location GetDestination() const { return destination_; } |
| 6114 | |
| 6115 | void SetSource(Location value) { source_ = value; } |
| 6116 | void SetDestination(Location value) { destination_ = value; } |
| 6117 | |
| 6118 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6119 | // destination (but not the source). |
| 6120 | Location MarkPending() { |
| 6121 | DCHECK(!IsPending()); |
| 6122 | Location dest = destination_; |
| 6123 | destination_ = Location::NoLocation(); |
| 6124 | return dest; |
| 6125 | } |
| 6126 | |
| 6127 | void ClearPending(Location dest) { |
| 6128 | DCHECK(IsPending()); |
| 6129 | destination_ = dest; |
| 6130 | } |
| 6131 | |
| 6132 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6133 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6134 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6135 | } |
| 6136 | |
| 6137 | // True if this blocks a move from the given location. |
| 6138 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6139 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6140 | } |
| 6141 | |
| 6142 | // A move is redundant if it's been eliminated, if its source and |
| 6143 | // destination are the same, or if its destination is unneeded. |
| 6144 | bool IsRedundant() const { |
| 6145 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6146 | } |
| 6147 | |
| 6148 | // We clear both operands to indicate move that's been eliminated. |
| 6149 | void Eliminate() { |
| 6150 | source_ = destination_ = Location::NoLocation(); |
| 6151 | } |
| 6152 | |
| 6153 | bool IsEliminated() const { |
| 6154 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6155 | return source_.IsInvalid(); |
| 6156 | } |
| 6157 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6158 | Primitive::Type GetType() const { return type_; } |
| 6159 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6160 | bool Is64BitMove() const { |
| 6161 | return Primitive::Is64BitType(type_); |
| 6162 | } |
| 6163 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6164 | HInstruction* GetInstruction() const { return instruction_; } |
| 6165 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6166 | private: |
| 6167 | Location source_; |
| 6168 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6169 | // The type this move is for. |
| 6170 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6171 | // The instruction this move is assocatied with. Null when this move is |
| 6172 | // for moving an input in the expected locations of user (including a phi user). |
| 6173 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6174 | // in the same parallel move. |
| 6175 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6176 | }; |
| 6177 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6178 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6179 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6180 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6181 | |
| 6182 | class HParallelMove : public HTemplateInstruction<0> { |
| 6183 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6184 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6185 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6186 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6187 | moves_.reserve(kDefaultNumberOfMoves); |
| 6188 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6189 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6190 | void AddMove(Location source, |
| 6191 | Location destination, |
| 6192 | Primitive::Type type, |
| 6193 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6194 | DCHECK(source.IsValid()); |
| 6195 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6196 | if (kIsDebugBuild) { |
| 6197 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6198 | for (const MoveOperands& move : moves_) { |
| 6199 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6200 | // Special case the situation where the move is for the spill slot |
| 6201 | // of the instruction. |
| 6202 | if ((GetPrevious() == instruction) |
| 6203 | || ((GetPrevious() == nullptr) |
| 6204 | && instruction->IsPhi() |
| 6205 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6206 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6207 | << "Doing parallel moves for the same instruction."; |
| 6208 | } else { |
| 6209 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6210 | } |
| 6211 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6212 | } |
| 6213 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6214 | for (const MoveOperands& move : moves_) { |
| 6215 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6216 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6217 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6218 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6219 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6220 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6221 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6222 | } |
| 6223 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6224 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6225 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6226 | } |
| 6227 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6228 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6229 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6230 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6231 | |
| 6232 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6233 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6234 | |
| 6235 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6236 | }; |
| 6237 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6238 | } // namespace art |
| 6239 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6240 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6241 | #include "nodes_shared.h" |
| 6242 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6243 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6244 | #include "nodes_arm.h" |
| 6245 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6246 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6247 | #include "nodes_arm64.h" |
| 6248 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6249 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6250 | #include "nodes_x86.h" |
| 6251 | #endif |
| 6252 | |
| 6253 | namespace art { |
| 6254 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6255 | class HGraphVisitor : public ValueObject { |
| 6256 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6257 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6258 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6259 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6260 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6261 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6262 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6263 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6264 | void VisitInsertionOrder(); |
| 6265 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6266 | // Visit the graph following dominator tree reverse post-order. |
| 6267 | void VisitReversePostOrder(); |
| 6268 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6269 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6270 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6271 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6272 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6273 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6274 | |
| 6275 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6276 | |
| 6277 | #undef DECLARE_VISIT_INSTRUCTION |
| 6278 | |
| 6279 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6280 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6281 | |
| 6282 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6283 | }; |
| 6284 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6285 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6286 | public: |
| 6287 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6288 | virtual ~HGraphDelegateVisitor() {} |
| 6289 | |
| 6290 | // Visit functions that delegate to to super class. |
| 6291 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6292 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6293 | |
| 6294 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6295 | |
| 6296 | #undef DECLARE_VISIT_INSTRUCTION |
| 6297 | |
| 6298 | private: |
| 6299 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6300 | }; |
| 6301 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6302 | class HInsertionOrderIterator : public ValueObject { |
| 6303 | public: |
| 6304 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6305 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6306 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6307 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6308 | void Advance() { ++index_; } |
| 6309 | |
| 6310 | private: |
| 6311 | const HGraph& graph_; |
| 6312 | size_t index_; |
| 6313 | |
| 6314 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6315 | }; |
| 6316 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6317 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6318 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6319 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6320 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6321 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6322 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6323 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6324 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6325 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6326 | void Advance() { ++index_; } |
| 6327 | |
| 6328 | private: |
| 6329 | const HGraph& graph_; |
| 6330 | size_t index_; |
| 6331 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6332 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6333 | }; |
| 6334 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6335 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6336 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6337 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6338 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6339 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6340 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6341 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6342 | |
| 6343 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6344 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6345 | void Advance() { --index_; } |
| 6346 | |
| 6347 | private: |
| 6348 | const HGraph& graph_; |
| 6349 | size_t index_; |
| 6350 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6351 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6352 | }; |
| 6353 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6354 | class HLinearPostOrderIterator : public ValueObject { |
| 6355 | public: |
| 6356 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6357 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6358 | |
| 6359 | bool Done() const { return index_ == 0; } |
| 6360 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6361 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6362 | |
| 6363 | void Advance() { |
| 6364 | --index_; |
| 6365 | DCHECK_GE(index_, 0U); |
| 6366 | } |
| 6367 | |
| 6368 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6369 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6370 | size_t index_; |
| 6371 | |
| 6372 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 6373 | }; |
| 6374 | |
| 6375 | class HLinearOrderIterator : public ValueObject { |
| 6376 | public: |
| 6377 | explicit HLinearOrderIterator(const HGraph& graph) |
| 6378 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 6379 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6380 | bool Done() const { return index_ == order_.size(); } |
| 6381 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6382 | void Advance() { ++index_; } |
| 6383 | |
| 6384 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6385 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6386 | size_t index_; |
| 6387 | |
| 6388 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 6389 | }; |
| 6390 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6391 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6392 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6393 | // block id. |
| 6394 | class HBlocksInLoopIterator : public ValueObject { |
| 6395 | public: |
| 6396 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6397 | : blocks_in_loop_(info.GetBlocks()), |
| 6398 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6399 | index_(0) { |
| 6400 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6401 | Advance(); |
| 6402 | } |
| 6403 | } |
| 6404 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6405 | bool Done() const { return index_ == blocks_.size(); } |
| 6406 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6407 | void Advance() { |
| 6408 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6409 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6410 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6411 | break; |
| 6412 | } |
| 6413 | } |
| 6414 | } |
| 6415 | |
| 6416 | private: |
| 6417 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6418 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6419 | size_t index_; |
| 6420 | |
| 6421 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6422 | }; |
| 6423 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6424 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6425 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6426 | // post order. |
| 6427 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6428 | public: |
| 6429 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6430 | : blocks_in_loop_(info.GetBlocks()), |
| 6431 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6432 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6433 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6434 | Advance(); |
| 6435 | } |
| 6436 | } |
| 6437 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6438 | bool Done() const { return index_ == blocks_.size(); } |
| 6439 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6440 | void Advance() { |
| 6441 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6442 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6443 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6444 | break; |
| 6445 | } |
| 6446 | } |
| 6447 | } |
| 6448 | |
| 6449 | private: |
| 6450 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6451 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6452 | size_t index_; |
| 6453 | |
| 6454 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6455 | }; |
| 6456 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6457 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6458 | if (constant->IsIntConstant()) { |
| 6459 | return constant->AsIntConstant()->GetValue(); |
| 6460 | } else if (constant->IsLongConstant()) { |
| 6461 | return constant->AsLongConstant()->GetValue(); |
| 6462 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6463 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6464 | return 0; |
| 6465 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6466 | } |
| 6467 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6468 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6469 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6470 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6471 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6472 | // times and provide different class resolution but no two class loaders should ever |
| 6473 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6474 | // all sorts of weird failures. |
| 6475 | return &lhs == &rhs; |
| 6476 | } |
| 6477 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6478 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6479 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6480 | inline const H##type* HInstruction::As##type() const { \ |
| 6481 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6482 | } \ |
| 6483 | inline H##type* HInstruction::As##type() { \ |
| 6484 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6485 | } |
| 6486 | |
| 6487 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6488 | #undef INSTRUCTION_TYPE_CHECK |
| 6489 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 6490 | class SwitchTable : public ValueObject { |
| 6491 | public: |
| 6492 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 6493 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 6494 | int32_t table_offset = instruction.VRegB_31t(); |
| 6495 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 6496 | if (sparse) { |
| 6497 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 6498 | } else { |
| 6499 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 6500 | } |
| 6501 | num_entries_ = table[1]; |
| 6502 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 6503 | } |
| 6504 | |
| 6505 | uint16_t GetNumEntries() const { |
| 6506 | return num_entries_; |
| 6507 | } |
| 6508 | |
| 6509 | void CheckIndex(size_t index) const { |
| 6510 | if (sparse_) { |
| 6511 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6512 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 6513 | } else { |
| 6514 | // In a packed table, we have the starting key and num_entries_ values. |
| 6515 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 6516 | } |
| 6517 | } |
| 6518 | |
| 6519 | int32_t GetEntryAt(size_t index) const { |
| 6520 | CheckIndex(index); |
| 6521 | return values_[index]; |
| 6522 | } |
| 6523 | |
| 6524 | uint32_t GetDexPcForIndex(size_t index) const { |
| 6525 | CheckIndex(index); |
| 6526 | return dex_pc_ + |
| 6527 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 6528 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 6529 | } |
| 6530 | |
| 6531 | // Index of the first value in the table. |
| 6532 | size_t GetFirstValueIndex() const { |
| 6533 | if (sparse_) { |
| 6534 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6535 | return num_entries_; |
| 6536 | } else { |
| 6537 | // In a packed table, we have the starting key and num_entries_ values. |
| 6538 | return 1; |
| 6539 | } |
| 6540 | } |
| 6541 | |
| 6542 | private: |
| 6543 | const Instruction& instruction_; |
| 6544 | const uint32_t dex_pc_; |
| 6545 | |
| 6546 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 6547 | const bool sparse_; |
| 6548 | |
| 6549 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 6550 | // expressions in the initializer list seemed very ugly. |
| 6551 | uint16_t num_entries_; |
| 6552 | |
| 6553 | const int32_t* values_; |
| 6554 | |
| 6555 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 6556 | }; |
| 6557 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6558 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6559 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6560 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6561 | size_t number_of_new_blocks, |
| 6562 | size_t after) { |
| 6563 | DCHECK_LT(after, blocks->size()); |
| 6564 | size_t old_size = blocks->size(); |
| 6565 | size_t new_size = old_size + number_of_new_blocks; |
| 6566 | blocks->resize(new_size); |
| 6567 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6568 | } |
| 6569 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6570 | } // namespace art |
| 6571 | |
| 6572 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |