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) { |
| 390 | current_instruction_id_ = id; |
| 391 | } |
| 392 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 393 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 394 | return maximum_number_of_out_vregs_; |
| 395 | } |
| 396 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 397 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 398 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 399 | } |
| 400 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 401 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 402 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 403 | } |
| 404 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 405 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 406 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 409 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 410 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 411 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 414 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 415 | number_of_vregs_ = number_of_vregs; |
| 416 | } |
| 417 | |
| 418 | uint16_t GetNumberOfVRegs() const { |
| 419 | return number_of_vregs_; |
| 420 | } |
| 421 | |
| 422 | void SetNumberOfInVRegs(uint16_t value) { |
| 423 | number_of_in_vregs_ = value; |
| 424 | } |
| 425 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 426 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 427 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 428 | return number_of_vregs_ - number_of_in_vregs_; |
| 429 | } |
| 430 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 431 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 432 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 433 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 434 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 435 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 436 | return linear_order_; |
| 437 | } |
| 438 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 439 | bool HasBoundsChecks() const { |
| 440 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 441 | } |
| 442 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 443 | void SetHasBoundsChecks(bool value) { |
| 444 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 447 | bool ShouldGenerateConstructorBarrier() const { |
| 448 | return should_generate_constructor_barrier_; |
| 449 | } |
| 450 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 451 | bool IsDebuggable() const { return debuggable_; } |
| 452 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 453 | // 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] | 454 | // already, it is created and inserted into the graph. This method is only for |
| 455 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 456 | 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] | 457 | |
| 458 | // TODO: This is problematic for the consistency of reference type propagation |
| 459 | // because it can be created anytime after the pass and thus it will be left |
| 460 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 461 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 462 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 463 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 464 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 465 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 466 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 467 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 468 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 469 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 470 | 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] | 471 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 472 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 473 | 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] | 474 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 475 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 476 | HCurrentMethod* GetCurrentMethod(); |
| 477 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 478 | const DexFile& GetDexFile() const { |
| 479 | return dex_file_; |
| 480 | } |
| 481 | |
| 482 | uint32_t GetMethodIdx() const { |
| 483 | return method_idx_; |
| 484 | } |
| 485 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 486 | InvokeType GetInvokeType() const { |
| 487 | return invoke_type_; |
| 488 | } |
| 489 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 490 | InstructionSet GetInstructionSet() const { |
| 491 | return instruction_set_; |
| 492 | } |
| 493 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 494 | bool IsCompilingOsr() const { return osr_; } |
| 495 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 496 | bool HasTryCatch() const { return has_try_catch_; } |
| 497 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 498 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 499 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 500 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 501 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 502 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 503 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 504 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 505 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 506 | // The instruction has been inserted into the graph, either as a constant, or |
| 507 | // before cursor. |
| 508 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 509 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 510 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 511 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 512 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 513 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 514 | template <class InstructionType, typename ValueType> |
| 515 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 516 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 517 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 518 | // Try to find an existing constant of the given value. |
| 519 | InstructionType* constant = nullptr; |
| 520 | auto cached_constant = cache->find(value); |
| 521 | if (cached_constant != cache->end()) { |
| 522 | constant = cached_constant->second; |
| 523 | } |
| 524 | |
| 525 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 526 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 527 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 528 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 529 | cache->Overwrite(value, constant); |
| 530 | InsertConstant(constant); |
| 531 | } |
| 532 | return constant; |
| 533 | } |
| 534 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 535 | void InsertConstant(HConstant* instruction); |
| 536 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 537 | // Cache a float constant into the graph. This method should only be |
| 538 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 539 | void CacheFloatConstant(HFloatConstant* constant); |
| 540 | |
| 541 | // See CacheFloatConstant comment. |
| 542 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 543 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 544 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 545 | |
| 546 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 547 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 548 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 549 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 550 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 551 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 552 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 553 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 554 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 555 | HBasicBlock* entry_block_; |
| 556 | HBasicBlock* exit_block_; |
| 557 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 558 | // 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] | 559 | uint16_t maximum_number_of_out_vregs_; |
| 560 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 561 | // The number of virtual registers in this method. Contains the parameters. |
| 562 | uint16_t number_of_vregs_; |
| 563 | |
| 564 | // The number of virtual registers used by parameters of this method. |
| 565 | uint16_t number_of_in_vregs_; |
| 566 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 567 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 568 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 569 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 570 | // Has bounds checks. We can totally skip BCE if it's false. |
| 571 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 572 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 573 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 574 | // try/catch-related passes if false. |
| 575 | bool has_try_catch_; |
| 576 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 577 | // Flag whether there are any irreducible loops in the graph. |
| 578 | bool has_irreducible_loops_; |
| 579 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 580 | // Indicates whether the graph should be compiled in a way that |
| 581 | // ensures full debuggability. If false, we can apply more |
| 582 | // aggressive optimizations that may limit the level of debugging. |
| 583 | const bool debuggable_; |
| 584 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 585 | // 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] | 586 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 587 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 588 | // The dex file from which the method is from. |
| 589 | const DexFile& dex_file_; |
| 590 | |
| 591 | // The method index in the dex file. |
| 592 | const uint32_t method_idx_; |
| 593 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 594 | // If inlined, this encodes how the callee is being invoked. |
| 595 | const InvokeType invoke_type_; |
| 596 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 597 | // Whether the graph has been transformed to SSA form. Only used |
| 598 | // in debug mode to ensure we are not using properties only valid |
| 599 | // for non-SSA form (like the number of temporaries). |
| 600 | bool in_ssa_form_; |
| 601 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 602 | const bool should_generate_constructor_barrier_; |
| 603 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 604 | const InstructionSet instruction_set_; |
| 605 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 606 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 607 | HNullConstant* cached_null_constant_; |
| 608 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 609 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 610 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 611 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 612 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 613 | HCurrentMethod* cached_current_method_; |
| 614 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 615 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 616 | // for example for methods whose declaring class could not be resolved |
| 617 | // (such as when the superclass could not be found). |
| 618 | ArtMethod* art_method_; |
| 619 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 620 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 621 | // collection pointer to passes which may create NullConstant. |
| 622 | ReferenceTypeInfo inexact_object_rti_; |
| 623 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 624 | // Whether we are compiling this graph for on stack replacement: this will |
| 625 | // make all loops seen as irreducible and emit special stack maps to mark |
| 626 | // compiled code entries which the interpreter can directly jump to. |
| 627 | const bool osr_; |
| 628 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 629 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 630 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 631 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 632 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 633 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 634 | }; |
| 635 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 636 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 637 | public: |
| 638 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 639 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 640 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 641 | irreducible_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 642 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 643 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 644 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 645 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 646 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 647 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 648 | bool IsIrreducible() const { return irreducible_; } |
| 649 | |
| 650 | void Dump(std::ostream& os); |
| 651 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 652 | HBasicBlock* GetHeader() const { |
| 653 | return header_; |
| 654 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 655 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 656 | void SetHeader(HBasicBlock* block) { |
| 657 | header_ = block; |
| 658 | } |
| 659 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 660 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 661 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 662 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 663 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 664 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 665 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 668 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 669 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 670 | } |
| 671 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 672 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 673 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 674 | } |
| 675 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 676 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 677 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 680 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 681 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 682 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 683 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 684 | } |
| 685 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 686 | // Returns the lifetime position of the back edge that has the |
| 687 | // greatest lifetime position. |
| 688 | size_t GetLifetimeEnd() const; |
| 689 | |
| 690 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 691 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 692 | } |
| 693 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 694 | // Finds blocks that are part of this loop. |
| 695 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 696 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 697 | // Returns whether this loop information contains `block`. |
| 698 | // Note that this loop information *must* be populated before entering this function. |
| 699 | bool Contains(const HBasicBlock& block) const; |
| 700 | |
| 701 | // Returns whether this loop information is an inner loop of `other`. |
| 702 | // Note that `other` *must* be populated before entering this function. |
| 703 | bool IsIn(const HLoopInformation& other) const; |
| 704 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 705 | // Returns true if instruction is not defined within this loop. |
| 706 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 707 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 708 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 709 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 710 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 711 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 712 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 713 | void ClearAllBlocks() { |
| 714 | blocks_.ClearAllBits(); |
| 715 | } |
| 716 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 717 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 718 | // Internal recursive implementation of `Populate`. |
| 719 | void PopulateRecursive(HBasicBlock* block); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 720 | void PopulateIrreducibleRecursive(HBasicBlock* block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 721 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 722 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 723 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 724 | bool irreducible_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 725 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 726 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 727 | |
| 728 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 729 | }; |
| 730 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 731 | // Stores try/catch information for basic blocks. |
| 732 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 733 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 734 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 735 | public: |
| 736 | // Try block information constructor. |
| 737 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 738 | : try_entry_(&try_entry), |
| 739 | catch_dex_file_(nullptr), |
| 740 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 741 | DCHECK(try_entry_ != nullptr); |
| 742 | } |
| 743 | |
| 744 | // Catch block information constructor. |
| 745 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 746 | : try_entry_(nullptr), |
| 747 | catch_dex_file_(&dex_file), |
| 748 | catch_type_index_(catch_type_index) {} |
| 749 | |
| 750 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 751 | |
| 752 | const HTryBoundary& GetTryEntry() const { |
| 753 | DCHECK(IsTryBlock()); |
| 754 | return *try_entry_; |
| 755 | } |
| 756 | |
| 757 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 758 | |
| 759 | bool IsCatchAllTypeIndex() const { |
| 760 | DCHECK(IsCatchBlock()); |
| 761 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 762 | } |
| 763 | |
| 764 | uint16_t GetCatchTypeIndex() const { |
| 765 | DCHECK(IsCatchBlock()); |
| 766 | return catch_type_index_; |
| 767 | } |
| 768 | |
| 769 | const DexFile& GetCatchDexFile() const { |
| 770 | DCHECK(IsCatchBlock()); |
| 771 | return *catch_dex_file_; |
| 772 | } |
| 773 | |
| 774 | private: |
| 775 | // One of possibly several TryBoundary instructions entering the block's try. |
| 776 | // Only set for try blocks. |
| 777 | const HTryBoundary* try_entry_; |
| 778 | |
| 779 | // Exception type information. Only set for catch blocks. |
| 780 | const DexFile* catch_dex_file_; |
| 781 | const uint16_t catch_type_index_; |
| 782 | }; |
| 783 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 784 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 785 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 786 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 787 | // A block in a method. Contains the list of instructions represented |
| 788 | // as a double linked list. Each block knows its predecessors and |
| 789 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 790 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 791 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 792 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 793 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 794 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 795 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 796 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 797 | loop_information_(nullptr), |
| 798 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 799 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 800 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 801 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 802 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 803 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 804 | try_catch_information_(nullptr) { |
| 805 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 806 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 807 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 808 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 809 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 810 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 811 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 814 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 815 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 816 | } |
| 817 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 818 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 819 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 820 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 821 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 822 | return ContainsElement(successors_, block, start_from); |
| 823 | } |
| 824 | |
| 825 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 826 | return dominated_blocks_; |
| 827 | } |
| 828 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 829 | bool IsEntryBlock() const { |
| 830 | return graph_->GetEntryBlock() == this; |
| 831 | } |
| 832 | |
| 833 | bool IsExitBlock() const { |
| 834 | return graph_->GetExitBlock() == this; |
| 835 | } |
| 836 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 837 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 838 | bool IsSingleTryBoundary() const; |
| 839 | |
| 840 | // Returns true if this block emits nothing but a jump. |
| 841 | bool IsSingleJump() const { |
| 842 | HLoopInformation* loop_info = GetLoopInformation(); |
| 843 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 844 | // Back edges generate a suspend check. |
| 845 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 846 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 847 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 848 | void AddBackEdge(HBasicBlock* back_edge) { |
| 849 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 850 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 851 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 852 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 853 | loop_information_->AddBackEdge(back_edge); |
| 854 | } |
| 855 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 856 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 857 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 858 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 859 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 860 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 861 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 862 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 863 | HBasicBlock* GetDominator() const { return dominator_; } |
| 864 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 865 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 866 | |
| 867 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 868 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 869 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 870 | |
| 871 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 872 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 873 | } |
| 874 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 875 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 876 | |
| 877 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 878 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 879 | } |
| 880 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 881 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 882 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 883 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 884 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 885 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 886 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 887 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 888 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 889 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 890 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 891 | successors_.push_back(block); |
| 892 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 895 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 896 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 897 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 898 | new_block->predecessors_.push_back(this); |
| 899 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 902 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 903 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 904 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 905 | new_block->successors_.push_back(this); |
| 906 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 909 | // Insert `this` between `predecessor` and `successor. This method |
| 910 | // preserves the indicies, and will update the first edge found between |
| 911 | // `predecessor` and `successor`. |
| 912 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 913 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 914 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 915 | successor->predecessors_[predecessor_index] = this; |
| 916 | predecessor->successors_[successor_index] = this; |
| 917 | successors_.push_back(successor); |
| 918 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 919 | } |
| 920 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 921 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 922 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 923 | } |
| 924 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 925 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 926 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 927 | } |
| 928 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 929 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 930 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 934 | predecessors_.push_back(block); |
| 935 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 936 | } |
| 937 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 938 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 939 | DCHECK_EQ(predecessors_.size(), 2u); |
| 940 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 941 | } |
| 942 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 943 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 944 | DCHECK_EQ(successors_.size(), 2u); |
| 945 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 946 | } |
| 947 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 948 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 949 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 950 | } |
| 951 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 952 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 953 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 954 | } |
| 955 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 956 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 957 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 958 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 962 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 963 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | // Returns whether the first occurrence of `predecessor` in the list of |
| 967 | // predecessors is at index `idx`. |
| 968 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 969 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 970 | return GetPredecessorIndexOf(predecessor) == idx; |
| 971 | } |
| 972 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 973 | // Create a new block between this block and its predecessors. The new block |
| 974 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 975 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 976 | // loop and try/catch information are not updated. |
| 977 | HBasicBlock* CreateImmediateDominator(); |
| 978 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 979 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 980 | // created, latter block. Note that this method will add the block to the |
| 981 | // graph, create a Goto at the end of the former block and will create an edge |
| 982 | // 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] | 983 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 984 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 985 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 986 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 987 | // created block. Note that this method just updates raw block information, |
| 988 | // like predecessors, successors, dominators, and instruction list. It does not |
| 989 | // update the graph, reverse post order, loop information, nor make sure the |
| 990 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 991 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 992 | |
| 993 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 994 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 995 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 996 | // Split catch block into two blocks after the original move-exception bytecode |
| 997 | // instruction, or at the beginning if not present. Returns the newly created, |
| 998 | // latter block, or nullptr if such block could not be created (must be dead |
| 999 | // in that case). Note that this method just updates raw block information, |
| 1000 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1001 | // update the graph, reverse post order, loop information, nor make sure the |
| 1002 | // blocks are consistent (for example ending with a control flow instruction). |
| 1003 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 1004 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1005 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1006 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1007 | // that this method does not update the graph, reverse post order, loop |
| 1008 | // information, nor make sure the blocks are consistent (for example ending |
| 1009 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1010 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1011 | |
| 1012 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1013 | // of `this` are moved to `other`. |
| 1014 | // Note that this method does not update the graph, reverse post order, loop |
| 1015 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1016 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1017 | void ReplaceWith(HBasicBlock* other); |
| 1018 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1019 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1020 | // order, links to predecessors, successors, dominators and deletes the block |
| 1021 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1022 | // predecessor of `other` and vice versa. |
| 1023 | void MergeWith(HBasicBlock* other); |
| 1024 | |
| 1025 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1026 | // removes it from all loops it is included in and eventually from the graph. |
| 1027 | // The block must not dominate any other block. Predecessors and successors |
| 1028 | // are safely updated. |
| 1029 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1030 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1031 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1032 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1033 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1034 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1035 | // Replace instruction `initial` with `replacement` within this block. |
| 1036 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1037 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1038 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1039 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1040 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1041 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1042 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1043 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1044 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1045 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1046 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1047 | |
| 1048 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1049 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1050 | } |
| 1051 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1052 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1053 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1054 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1055 | } |
| 1056 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1057 | bool IsFirstPredecessorBackEdge() const { |
| 1058 | DCHECK(IsLoopHeader()); |
| 1059 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1060 | } |
| 1061 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1062 | HLoopInformation* GetLoopInformation() const { |
| 1063 | return loop_information_; |
| 1064 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1065 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1066 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1067 | // 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] | 1068 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1069 | void SetInLoop(HLoopInformation* info) { |
| 1070 | if (IsLoopHeader()) { |
| 1071 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1072 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1073 | loop_information_ = info; |
| 1074 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1075 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1076 | // Note that a non loop header having a loop information means this loop information |
| 1077 | // has already been populated |
| 1078 | loop_information_ = info; |
| 1079 | } else { |
| 1080 | // Block is part of an inner loop. Do not update the loop information. |
| 1081 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1082 | // at this point, because this method is being called while populating `info`. |
| 1083 | } |
| 1084 | } |
| 1085 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1086 | // Raw update of the loop information. |
| 1087 | void SetLoopInformation(HLoopInformation* info) { |
| 1088 | loop_information_ = info; |
| 1089 | } |
| 1090 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1091 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1092 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1093 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1094 | |
| 1095 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1096 | try_catch_information_ = try_catch_information; |
| 1097 | } |
| 1098 | |
| 1099 | bool IsTryBlock() const { |
| 1100 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1101 | } |
| 1102 | |
| 1103 | bool IsCatchBlock() const { |
| 1104 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1105 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1106 | |
| 1107 | // Returns the try entry that this block's successors should have. They will |
| 1108 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1109 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1110 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1111 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1112 | bool HasThrowingInstructions() const; |
| 1113 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1114 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1115 | bool Dominates(HBasicBlock* block) const; |
| 1116 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1117 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1118 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1119 | |
| 1120 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1121 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1122 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1123 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1124 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1125 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1126 | bool HasSinglePhi() const; |
| 1127 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1128 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1129 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1130 | ArenaVector<HBasicBlock*> predecessors_; |
| 1131 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1132 | HInstructionList instructions_; |
| 1133 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1134 | HLoopInformation* loop_information_; |
| 1135 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1136 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1137 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1138 | // The dex program counter of the first instruction of this block. |
| 1139 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1140 | size_t lifetime_start_; |
| 1141 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1142 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1143 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1144 | friend class HGraph; |
| 1145 | friend class HInstruction; |
| 1146 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1147 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1148 | }; |
| 1149 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1150 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1151 | // from the innermost to the outermost. |
| 1152 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1153 | public: |
| 1154 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1155 | : current_(block.GetLoopInformation()) {} |
| 1156 | |
| 1157 | bool Done() const { return current_ == nullptr; } |
| 1158 | |
| 1159 | void Advance() { |
| 1160 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1161 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | HLoopInformation* Current() const { |
| 1165 | DCHECK(!Done()); |
| 1166 | return current_; |
| 1167 | } |
| 1168 | |
| 1169 | private: |
| 1170 | HLoopInformation* current_; |
| 1171 | |
| 1172 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1173 | }; |
| 1174 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1175 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1176 | M(Above, Condition) \ |
| 1177 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1178 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1179 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1180 | M(ArrayGet, Instruction) \ |
| 1181 | M(ArrayLength, Instruction) \ |
| 1182 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1183 | M(Below, Condition) \ |
| 1184 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1185 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1186 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1187 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1188 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1189 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1190 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1191 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1192 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1193 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1194 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1195 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1196 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1197 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1198 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1199 | M(Exit, Instruction) \ |
| 1200 | M(FloatConstant, Constant) \ |
| 1201 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1202 | M(GreaterThan, Condition) \ |
| 1203 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1204 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1205 | M(InstanceFieldGet, Instruction) \ |
| 1206 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1207 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1208 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1209 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1210 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1211 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1212 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1213 | M(LessThan, Condition) \ |
| 1214 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1215 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1216 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1217 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1218 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1219 | M(Local, Instruction) \ |
| 1220 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1221 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1222 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1223 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1224 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1225 | M(Neg, UnaryOperation) \ |
| 1226 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1227 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1228 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1229 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1230 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1231 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1232 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1233 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1234 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1235 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1236 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1237 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1238 | M(Return, Instruction) \ |
| 1239 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1240 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1241 | M(Shl, BinaryOperation) \ |
| 1242 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1243 | M(StaticFieldGet, Instruction) \ |
| 1244 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1245 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1246 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1247 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1248 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1249 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1250 | M(StoreLocal, Instruction) \ |
| 1251 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1252 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1253 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1254 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1255 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1256 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1257 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1258 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1259 | /* |
| 1260 | * Instructions, shared across several (not all) architectures. |
| 1261 | */ |
| 1262 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1263 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1264 | #else |
| 1265 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
| 1266 | M(MultiplyAccumulate, Instruction) |
| 1267 | #endif |
| 1268 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1269 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1270 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1271 | #else |
| 1272 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1273 | M(ArmDexCacheArraysBase, Instruction) |
| 1274 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1275 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1276 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1277 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1278 | #else |
| 1279 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1280 | M(Arm64BitwiseNegatedRight, Instruction) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1281 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1282 | M(Arm64IntermediateAddress, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1283 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1284 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1285 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1286 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1287 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1288 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1289 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1290 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1291 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1292 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1293 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1294 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1295 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1296 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1297 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1298 | |
| 1299 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1300 | |
| 1301 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1302 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1303 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1304 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1305 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1306 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1307 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1308 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1309 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1310 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1311 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1312 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1313 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1314 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1315 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1316 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1317 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1318 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1319 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1320 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1321 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1322 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1323 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1324 | #undef FORWARD_DECLARATION |
| 1325 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1326 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1327 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1328 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1329 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1330 | return other->Is##type(); \ |
| 1331 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1332 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1333 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1334 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1335 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1336 | const H##type* As##type() const { return this; } \ |
| 1337 | H##type* As##type() { return this; } |
| 1338 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1339 | template <typename T> class HUseList; |
| 1340 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1341 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1342 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1343 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1344 | HUseListNode* GetPrevious() const { return prev_; } |
| 1345 | HUseListNode* GetNext() const { return next_; } |
| 1346 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1347 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1348 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1349 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1350 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1351 | HUseListNode(T user, size_t index) |
| 1352 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1353 | |
| 1354 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1355 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1356 | HUseListNode<T>* prev_; |
| 1357 | HUseListNode<T>* next_; |
| 1358 | |
| 1359 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1360 | |
| 1361 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1362 | }; |
| 1363 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1364 | template <typename T> |
| 1365 | class HUseList : public ValueObject { |
| 1366 | public: |
| 1367 | HUseList() : first_(nullptr) {} |
| 1368 | |
| 1369 | void Clear() { |
| 1370 | first_ = nullptr; |
| 1371 | } |
| 1372 | |
| 1373 | // Adds a new entry at the beginning of the use list and returns |
| 1374 | // the newly created node. |
| 1375 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1376 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1377 | if (IsEmpty()) { |
| 1378 | first_ = new_node; |
| 1379 | } else { |
| 1380 | first_->prev_ = new_node; |
| 1381 | new_node->next_ = first_; |
| 1382 | first_ = new_node; |
| 1383 | } |
| 1384 | return new_node; |
| 1385 | } |
| 1386 | |
| 1387 | HUseListNode<T>* GetFirst() const { |
| 1388 | return first_; |
| 1389 | } |
| 1390 | |
| 1391 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1392 | DCHECK(node != nullptr); |
| 1393 | DCHECK(Contains(node)); |
| 1394 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1395 | if (node->prev_ != nullptr) { |
| 1396 | node->prev_->next_ = node->next_; |
| 1397 | } |
| 1398 | if (node->next_ != nullptr) { |
| 1399 | node->next_->prev_ = node->prev_; |
| 1400 | } |
| 1401 | if (node == first_) { |
| 1402 | first_ = node->next_; |
| 1403 | } |
| 1404 | } |
| 1405 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1406 | bool Contains(const HUseListNode<T>* node) const { |
| 1407 | if (node == nullptr) { |
| 1408 | return false; |
| 1409 | } |
| 1410 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1411 | if (current == node) { |
| 1412 | return true; |
| 1413 | } |
| 1414 | } |
| 1415 | return false; |
| 1416 | } |
| 1417 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1418 | bool IsEmpty() const { |
| 1419 | return first_ == nullptr; |
| 1420 | } |
| 1421 | |
| 1422 | bool HasOnlyOneUse() const { |
| 1423 | return first_ != nullptr && first_->next_ == nullptr; |
| 1424 | } |
| 1425 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1426 | size_t SizeSlow() const { |
| 1427 | size_t count = 0; |
| 1428 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1429 | ++count; |
| 1430 | } |
| 1431 | return count; |
| 1432 | } |
| 1433 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1434 | private: |
| 1435 | HUseListNode<T>* first_; |
| 1436 | }; |
| 1437 | |
| 1438 | template<typename T> |
| 1439 | class HUseIterator : public ValueObject { |
| 1440 | public: |
| 1441 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1442 | |
| 1443 | bool Done() const { return current_ == nullptr; } |
| 1444 | |
| 1445 | void Advance() { |
| 1446 | DCHECK(!Done()); |
| 1447 | current_ = current_->GetNext(); |
| 1448 | } |
| 1449 | |
| 1450 | HUseListNode<T>* Current() const { |
| 1451 | DCHECK(!Done()); |
| 1452 | return current_; |
| 1453 | } |
| 1454 | |
| 1455 | private: |
| 1456 | HUseListNode<T>* current_; |
| 1457 | |
| 1458 | friend class HValue; |
| 1459 | }; |
| 1460 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1461 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1462 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1463 | // by the used instructions. |
| 1464 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1465 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1466 | public: |
| 1467 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1468 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1469 | |
| 1470 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1471 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1472 | DCHECK(instruction_ != nullptr); |
| 1473 | DCHECK(use_node_ != nullptr); |
| 1474 | DCHECK(old_record.use_node_ == nullptr); |
| 1475 | } |
| 1476 | |
| 1477 | HInstruction* GetInstruction() const { return instruction_; } |
| 1478 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1479 | |
| 1480 | private: |
| 1481 | // Instruction used by the user. |
| 1482 | HInstruction* instruction_; |
| 1483 | |
| 1484 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1485 | HUseListNode<T>* use_node_; |
| 1486 | }; |
| 1487 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1488 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1489 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1490 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1491 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1492 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1493 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1494 | * modify the value of a reference field read [although it may modify the |
| 1495 | * reference fetch prior to reading the field, which is represented by its own |
| 1496 | * write/read dependence]). The analysis makes conservative points-to |
| 1497 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1498 | * the same, and any reference read depends on any reference read without |
| 1499 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1500 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1501 | * The internal representation uses 38-bit and is described in the table below. |
| 1502 | * The first line indicates the side effect, and for field/array accesses the |
| 1503 | * second line indicates the type of the access (in the order of the |
| 1504 | * Primitive::Type enum). |
| 1505 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1506 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1507 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1508 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1509 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1510 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1511 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1512 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1513 | * |
| 1514 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1515 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1516 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1517 | class SideEffects : public ValueObject { |
| 1518 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1519 | SideEffects() : flags_(0) {} |
| 1520 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1521 | static SideEffects None() { |
| 1522 | return SideEffects(0); |
| 1523 | } |
| 1524 | |
| 1525 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1526 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1527 | } |
| 1528 | |
| 1529 | static SideEffects AllChanges() { |
| 1530 | return SideEffects(kAllChangeBits); |
| 1531 | } |
| 1532 | |
| 1533 | static SideEffects AllDependencies() { |
| 1534 | return SideEffects(kAllDependOnBits); |
| 1535 | } |
| 1536 | |
| 1537 | static SideEffects AllExceptGCDependency() { |
| 1538 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1539 | } |
| 1540 | |
| 1541 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1542 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1543 | } |
| 1544 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1545 | static SideEffects AllWrites() { |
| 1546 | return SideEffects(kAllWrites); |
| 1547 | } |
| 1548 | |
| 1549 | static SideEffects AllReads() { |
| 1550 | return SideEffects(kAllReads); |
| 1551 | } |
| 1552 | |
| 1553 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1554 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1555 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1556 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1557 | } |
| 1558 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1559 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1560 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1561 | } |
| 1562 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1563 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1564 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1565 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1566 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1570 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1571 | } |
| 1572 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1573 | static SideEffects CanTriggerGC() { |
| 1574 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1575 | } |
| 1576 | |
| 1577 | static SideEffects DependsOnGC() { |
| 1578 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1579 | } |
| 1580 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1581 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1582 | SideEffects Union(SideEffects other) const { |
| 1583 | return SideEffects(flags_ | other.flags_); |
| 1584 | } |
| 1585 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1586 | SideEffects Exclusion(SideEffects other) const { |
| 1587 | return SideEffects(flags_ & ~other.flags_); |
| 1588 | } |
| 1589 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1590 | void Add(SideEffects other) { |
| 1591 | flags_ |= other.flags_; |
| 1592 | } |
| 1593 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1594 | bool Includes(SideEffects other) const { |
| 1595 | return (other.flags_ & flags_) == other.flags_; |
| 1596 | } |
| 1597 | |
| 1598 | bool HasSideEffects() const { |
| 1599 | return (flags_ & kAllChangeBits); |
| 1600 | } |
| 1601 | |
| 1602 | bool HasDependencies() const { |
| 1603 | return (flags_ & kAllDependOnBits); |
| 1604 | } |
| 1605 | |
| 1606 | // Returns true if there are no side effects or dependencies. |
| 1607 | bool DoesNothing() const { |
| 1608 | return flags_ == 0; |
| 1609 | } |
| 1610 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1611 | // Returns true if something is written. |
| 1612 | bool DoesAnyWrite() const { |
| 1613 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1614 | } |
| 1615 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1616 | // Returns true if something is read. |
| 1617 | bool DoesAnyRead() const { |
| 1618 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1621 | // Returns true if potentially everything is written and read |
| 1622 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1623 | bool DoesAllReadWrite() const { |
| 1624 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1625 | } |
| 1626 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1627 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1628 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1631 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1632 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1633 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1634 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1638 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1639 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1640 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1641 | for (int s = kLastBit; s >= 0; s--) { |
| 1642 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1643 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1644 | // This is a bit for the GC side effect. |
| 1645 | if (current_bit_is_set) { |
| 1646 | flags += "GC"; |
| 1647 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1648 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1649 | } else { |
| 1650 | // This is a bit for the array/field analysis. |
| 1651 | // The underscore character stands for the 'can trigger GC' bit. |
| 1652 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1653 | if (current_bit_is_set) { |
| 1654 | flags += kDebug[s]; |
| 1655 | } |
| 1656 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1657 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1658 | flags += "|"; |
| 1659 | } |
| 1660 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1661 | } |
| 1662 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1663 | } |
| 1664 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1665 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1666 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1667 | private: |
| 1668 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1669 | |
| 1670 | static constexpr int kFieldWriteOffset = 0; |
| 1671 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1672 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1673 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1674 | |
| 1675 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1676 | |
| 1677 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1678 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1679 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1680 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1681 | |
| 1682 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1683 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1684 | |
| 1685 | // Aliases. |
| 1686 | |
| 1687 | static_assert(kChangeBits == kDependOnBits, |
| 1688 | "the 'change' bits should match the 'depend on' bits."); |
| 1689 | |
| 1690 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1691 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1692 | static constexpr uint64_t kAllWrites = |
| 1693 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1694 | static constexpr uint64_t kAllReads = |
| 1695 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1696 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1697 | // Work around the fact that HIR aliases I/F and J/D. |
| 1698 | // TODO: remove this interceptor once HIR types are clean |
| 1699 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1700 | switch (type) { |
| 1701 | case Primitive::kPrimInt: |
| 1702 | case Primitive::kPrimFloat: |
| 1703 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1704 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1705 | case Primitive::kPrimLong: |
| 1706 | case Primitive::kPrimDouble: |
| 1707 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1708 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1709 | default: |
| 1710 | return TypeFlag(type, offset); |
| 1711 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1712 | } |
| 1713 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1714 | // Translates type to bit flag. |
| 1715 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1716 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1717 | const uint64_t one = 1; |
| 1718 | const int shift = type; // 0-based consecutive enum |
| 1719 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1720 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1721 | return one << (type + offset); |
| 1722 | } |
| 1723 | |
| 1724 | // Private constructor on direct flags value. |
| 1725 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1726 | |
| 1727 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1728 | }; |
| 1729 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1730 | // 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] | 1731 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1732 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1733 | HEnvironment(ArenaAllocator* arena, |
| 1734 | size_t number_of_vregs, |
| 1735 | const DexFile& dex_file, |
| 1736 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1737 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1738 | InvokeType invoke_type, |
| 1739 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1740 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1741 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1742 | parent_(nullptr), |
| 1743 | dex_file_(dex_file), |
| 1744 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1745 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1746 | invoke_type_(invoke_type), |
| 1747 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1748 | } |
| 1749 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1750 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1751 | : HEnvironment(arena, |
| 1752 | to_copy.Size(), |
| 1753 | to_copy.GetDexFile(), |
| 1754 | to_copy.GetMethodIdx(), |
| 1755 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1756 | to_copy.GetInvokeType(), |
| 1757 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1758 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1759 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1760 | if (parent_ != nullptr) { |
| 1761 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1762 | } else { |
| 1763 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1764 | parent_->CopyFrom(parent); |
| 1765 | if (parent->GetParent() != nullptr) { |
| 1766 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1767 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1768 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1769 | } |
| 1770 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1771 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1772 | void CopyFrom(HEnvironment* environment); |
| 1773 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1774 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1775 | // input to the loop phi instead. This is for inserting instructions that |
| 1776 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1777 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1778 | |
| 1779 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1780 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1781 | } |
| 1782 | |
| 1783 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1784 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1785 | } |
| 1786 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1787 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1788 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1789 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1790 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1791 | HEnvironment* GetParent() const { return parent_; } |
| 1792 | |
| 1793 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1794 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1798 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | uint32_t GetDexPc() const { |
| 1802 | return dex_pc_; |
| 1803 | } |
| 1804 | |
| 1805 | uint32_t GetMethodIdx() const { |
| 1806 | return method_idx_; |
| 1807 | } |
| 1808 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1809 | InvokeType GetInvokeType() const { |
| 1810 | return invoke_type_; |
| 1811 | } |
| 1812 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1813 | const DexFile& GetDexFile() const { |
| 1814 | return dex_file_; |
| 1815 | } |
| 1816 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1817 | HInstruction* GetHolder() const { |
| 1818 | return holder_; |
| 1819 | } |
| 1820 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1821 | |
| 1822 | bool IsFromInlinedInvoke() const { |
| 1823 | return GetParent() != nullptr; |
| 1824 | } |
| 1825 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1826 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1827 | // Record instructions' use entries of this environment for constant-time removal. |
| 1828 | // It should only be called by HInstruction when a new environment use is added. |
| 1829 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1830 | DCHECK(env_use->GetUser() == this); |
| 1831 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1832 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1833 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1834 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1835 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1836 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1837 | HEnvironment* parent_; |
| 1838 | const DexFile& dex_file_; |
| 1839 | const uint32_t method_idx_; |
| 1840 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1841 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1842 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1843 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1844 | HInstruction* const holder_; |
| 1845 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1846 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1847 | |
| 1848 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1849 | }; |
| 1850 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1851 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1852 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1853 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1854 | : previous_(nullptr), |
| 1855 | next_(nullptr), |
| 1856 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1857 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1858 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1859 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1860 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1861 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1862 | locations_(nullptr), |
| 1863 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1864 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1865 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1866 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1867 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1868 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1869 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1870 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1871 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1872 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1873 | enum InstructionKind { |
| 1874 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1875 | }; |
| 1876 | #undef DECLARE_KIND |
| 1877 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1878 | HInstruction* GetNext() const { return next_; } |
| 1879 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1880 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1881 | HInstruction* GetNextDisregardingMoves() const; |
| 1882 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1883 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1884 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1885 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1886 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1887 | bool IsInBlock() const { return block_ != nullptr; } |
| 1888 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1889 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1890 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1891 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1892 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1893 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1894 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1895 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1896 | |
| 1897 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1898 | virtual const char* DebugName() const = 0; |
| 1899 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1900 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1901 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1902 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1903 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1904 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1905 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1906 | |
| 1907 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1908 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1909 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1910 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1911 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1912 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1913 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1914 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1915 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1916 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1917 | // Does not apply for all instructions, but having this at top level greatly |
| 1918 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1919 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1920 | virtual bool CanBeNull() const { |
| 1921 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1922 | return true; |
| 1923 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1924 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1925 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1926 | return false; |
| 1927 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1928 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1929 | virtual bool IsActualObject() const { |
| 1930 | return GetType() == Primitive::kPrimNot; |
| 1931 | } |
| 1932 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1933 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1934 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1935 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1936 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1937 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
| 1938 | GetPackedFlag<kFlagReferenceTypeIsExact>());; |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1939 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1940 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1941 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1942 | DCHECK(user != nullptr); |
| 1943 | HUseListNode<HInstruction*>* use = |
| 1944 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1945 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1948 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1949 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1950 | HUseListNode<HEnvironment*>* env_use = |
| 1951 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1952 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1953 | } |
| 1954 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1955 | void RemoveAsUserOfInput(size_t input) { |
| 1956 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1957 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1958 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1959 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1960 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1961 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1962 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1963 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1964 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1965 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1966 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1967 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1968 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1969 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1970 | // Does this instruction strictly dominate `other_instruction`? |
| 1971 | // Returns false if this instruction and `other_instruction` are the same. |
| 1972 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1973 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1974 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1975 | int GetId() const { return id_; } |
| 1976 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1977 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1978 | int GetSsaIndex() const { return ssa_index_; } |
| 1979 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1980 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1981 | |
| 1982 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1983 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1984 | // Set the `environment_` field. Raw because this method does not |
| 1985 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1986 | void SetRawEnvironment(HEnvironment* environment) { |
| 1987 | DCHECK(environment_ == nullptr); |
| 1988 | DCHECK_EQ(environment->GetHolder(), this); |
| 1989 | environment_ = environment; |
| 1990 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1991 | |
| 1992 | // Set the environment of this instruction, copying it from `environment`. While |
| 1993 | // copying, the uses lists are being updated. |
| 1994 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1995 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1996 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1997 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1998 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1999 | if (environment->GetParent() != nullptr) { |
| 2000 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2001 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2002 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2003 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2004 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2005 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2006 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2007 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2008 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2009 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2010 | if (environment->GetParent() != nullptr) { |
| 2011 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2012 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2015 | // Returns the number of entries in the environment. Typically, that is the |
| 2016 | // number of dex registers in a method. It could be more in case of inlining. |
| 2017 | size_t EnvironmentSize() const; |
| 2018 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2019 | LocationSummary* GetLocations() const { return locations_; } |
| 2020 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2021 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2022 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2023 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2024 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2025 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2026 | // uses of this instruction by `other` are *not* updated. |
| 2027 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2028 | ReplaceWith(other); |
| 2029 | other->ReplaceInput(this, use_index); |
| 2030 | } |
| 2031 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2032 | // Move `this` instruction before `cursor`. |
| 2033 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2034 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2035 | // Move `this` before its first user and out of any loops. If there is no |
| 2036 | // out-of-loop user that dominates all other users, move the instruction |
| 2037 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2038 | // |
| 2039 | // This can be used only on non-throwing instructions with no side effects that |
| 2040 | // have at least one use but no environment uses. |
| 2041 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2042 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2043 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2044 | bool Is##type() const; \ |
| 2045 | const H##type* As##type() const; \ |
| 2046 | H##type* As##type(); |
| 2047 | |
| 2048 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2049 | #undef INSTRUCTION_TYPE_CHECK |
| 2050 | |
| 2051 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2052 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2053 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2054 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2055 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2056 | #undef INSTRUCTION_TYPE_CHECK |
| 2057 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2058 | // Returns whether the instruction can be moved within the graph. |
| 2059 | virtual bool CanBeMoved() const { return false; } |
| 2060 | |
| 2061 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2062 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2063 | return false; |
| 2064 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2065 | |
| 2066 | // Returns whether any data encoded in the two instructions is equal. |
| 2067 | // This method does not look at the inputs. Both instructions must be |
| 2068 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2069 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2070 | return false; |
| 2071 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2072 | |
| 2073 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2074 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2075 | // 2) Their inputs are identical. |
| 2076 | bool Equals(HInstruction* other) const; |
| 2077 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2078 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2079 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2080 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2081 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2082 | InstructionKind GetKind() const PURE; |
| 2083 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2084 | |
| 2085 | virtual size_t ComputeHashCode() const { |
| 2086 | size_t result = GetKind(); |
| 2087 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2088 | result = (result * 31) + InputAt(i)->GetId(); |
| 2089 | } |
| 2090 | return result; |
| 2091 | } |
| 2092 | |
| 2093 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2094 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2095 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2096 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2097 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2098 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2099 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2100 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2101 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2102 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2103 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2104 | |
| 2105 | // Returns whether the code generation of the instruction will require to have access |
| 2106 | // to the current method. Such instructions are: |
| 2107 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2108 | // to walk the stack and have the current method stored at a specific stack address. |
| 2109 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2110 | // fields of the current method. |
| 2111 | bool NeedsCurrentMethod() const { |
| 2112 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2113 | } |
| 2114 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2115 | // Returns whether the code generation of the instruction will require to have access |
| 2116 | // to the dex cache of the current method's declaring class via the current method. |
| 2117 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2118 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2119 | // Does this instruction have any use in an environment before |
| 2120 | // control flow hits 'other'? |
| 2121 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2122 | |
| 2123 | // Remove all references to environment uses of this instruction. |
| 2124 | // The caller must ensure that this is safe to do. |
| 2125 | void RemoveEnvironmentUsers(); |
| 2126 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2127 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2128 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2129 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2130 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2131 | // If set, the machine code for this instruction is assumed to be generated by |
| 2132 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2133 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2134 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2135 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2136 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2137 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2138 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2139 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2140 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2141 | uint32_t GetPackedFields() const { |
| 2142 | return packed_fields_; |
| 2143 | } |
| 2144 | |
| 2145 | template <size_t flag> |
| 2146 | bool GetPackedFlag() const { |
| 2147 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2148 | } |
| 2149 | |
| 2150 | template <size_t flag> |
| 2151 | void SetPackedFlag(bool value = true) { |
| 2152 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2153 | } |
| 2154 | |
| 2155 | template <typename BitFieldType> |
| 2156 | typename BitFieldType::value_type GetPackedField() const { |
| 2157 | return BitFieldType::Decode(packed_fields_); |
| 2158 | } |
| 2159 | |
| 2160 | template <typename BitFieldType> |
| 2161 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2162 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2163 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2164 | } |
| 2165 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2166 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2167 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2168 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2169 | HInstruction* previous_; |
| 2170 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2171 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2172 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2173 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2174 | // An instruction gets an id when it is added to the graph. |
| 2175 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2176 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2177 | int id_; |
| 2178 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2179 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2180 | int ssa_index_; |
| 2181 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2182 | // Packed fields. |
| 2183 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2184 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2185 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2186 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2187 | |
| 2188 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2189 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2190 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2191 | // The environment associated with this instruction. Not null if the instruction |
| 2192 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2193 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2194 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2195 | // Set by the code generator. |
| 2196 | LocationSummary* locations_; |
| 2197 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2198 | // Set by the liveness analysis. |
| 2199 | LiveInterval* live_interval_; |
| 2200 | |
| 2201 | // Set by the liveness analysis, this is the position in a linear |
| 2202 | // order of blocks where this instruction's live interval start. |
| 2203 | size_t lifetime_position_; |
| 2204 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2205 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2206 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2207 | // The reference handle part of the reference type info. |
| 2208 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2209 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2210 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2211 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2212 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2213 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2214 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2215 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2216 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2217 | |
| 2218 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2219 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2220 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2221 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2222 | class HInputIterator : public ValueObject { |
| 2223 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2224 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2225 | |
| 2226 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2227 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2228 | void Advance() { index_++; } |
| 2229 | |
| 2230 | private: |
| 2231 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2232 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2233 | |
| 2234 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2235 | }; |
| 2236 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2237 | class HInstructionIterator : public ValueObject { |
| 2238 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2239 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2240 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2241 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2242 | } |
| 2243 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2244 | bool Done() const { return instruction_ == nullptr; } |
| 2245 | HInstruction* Current() const { return instruction_; } |
| 2246 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2247 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2248 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | private: |
| 2252 | HInstruction* instruction_; |
| 2253 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2254 | |
| 2255 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2256 | }; |
| 2257 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2258 | class HBackwardInstructionIterator : public ValueObject { |
| 2259 | public: |
| 2260 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2261 | : instruction_(instructions.last_instruction_) { |
| 2262 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2263 | } |
| 2264 | |
| 2265 | bool Done() const { return instruction_ == nullptr; } |
| 2266 | HInstruction* Current() const { return instruction_; } |
| 2267 | void Advance() { |
| 2268 | instruction_ = next_; |
| 2269 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2270 | } |
| 2271 | |
| 2272 | private: |
| 2273 | HInstruction* instruction_; |
| 2274 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2275 | |
| 2276 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2277 | }; |
| 2278 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2279 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2280 | class HTemplateInstruction: public HInstruction { |
| 2281 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2282 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2283 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2284 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2285 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2286 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2287 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2288 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2289 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2290 | DCHECK_LT(i, N); |
| 2291 | return inputs_[i]; |
| 2292 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2293 | |
| 2294 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2295 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2296 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2297 | } |
| 2298 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2299 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2300 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2301 | |
| 2302 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2303 | }; |
| 2304 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2305 | // HTemplateInstruction specialization for N=0. |
| 2306 | template<> |
| 2307 | class HTemplateInstruction<0>: public HInstruction { |
| 2308 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2309 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2310 | : HInstruction(side_effects, dex_pc) {} |
| 2311 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2312 | virtual ~HTemplateInstruction() {} |
| 2313 | |
| 2314 | size_t InputCount() const OVERRIDE { return 0; } |
| 2315 | |
| 2316 | protected: |
| 2317 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2318 | LOG(FATAL) << "Unreachable"; |
| 2319 | UNREACHABLE(); |
| 2320 | } |
| 2321 | |
| 2322 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2323 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2324 | LOG(FATAL) << "Unreachable"; |
| 2325 | UNREACHABLE(); |
| 2326 | } |
| 2327 | |
| 2328 | private: |
| 2329 | friend class SsaBuilder; |
| 2330 | }; |
| 2331 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2332 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2333 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2334 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2335 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2336 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2337 | this->template SetPackedField<TypeField>(type); |
| 2338 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2339 | virtual ~HExpression() {} |
| 2340 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2341 | Primitive::Type GetType() const OVERRIDE { |
| 2342 | return TypeField::Decode(this->GetPackedFields()); |
| 2343 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2344 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2345 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2346 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2347 | static constexpr size_t kFieldTypeSize = |
| 2348 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2349 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2350 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2351 | "Too many packed fields."); |
| 2352 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2353 | }; |
| 2354 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2355 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2356 | // instruction that branches to the exit block. |
| 2357 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2358 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2359 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2360 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2361 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2362 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2363 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2364 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2365 | |
| 2366 | private: |
| 2367 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2368 | }; |
| 2369 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2370 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2371 | // instruction that branches to the exit block. |
| 2372 | class HReturn : public HTemplateInstruction<1> { |
| 2373 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2374 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2375 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2376 | SetRawInputAt(0, value); |
| 2377 | } |
| 2378 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2379 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2380 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2381 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2382 | |
| 2383 | private: |
| 2384 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2385 | }; |
| 2386 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2387 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2388 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2389 | // exit block. |
| 2390 | class HExit : public HTemplateInstruction<0> { |
| 2391 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2392 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2393 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2394 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2395 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2396 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2397 | |
| 2398 | private: |
| 2399 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2400 | }; |
| 2401 | |
| 2402 | // Jumps from one block to another. |
| 2403 | class HGoto : public HTemplateInstruction<0> { |
| 2404 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2405 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2406 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2407 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2408 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2409 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2410 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2411 | } |
| 2412 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2413 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2414 | |
| 2415 | private: |
| 2416 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2417 | }; |
| 2418 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2419 | class HConstant : public HExpression<0> { |
| 2420 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2421 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2422 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2423 | |
| 2424 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2425 | |
| 2426 | virtual bool IsMinusOne() const { return false; } |
| 2427 | virtual bool IsZero() const { return false; } |
| 2428 | virtual bool IsOne() const { return false; } |
| 2429 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2430 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2431 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2432 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2433 | |
| 2434 | private: |
| 2435 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2436 | }; |
| 2437 | |
| 2438 | class HNullConstant : public HConstant { |
| 2439 | public: |
| 2440 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2441 | return true; |
| 2442 | } |
| 2443 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2444 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2445 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2446 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2447 | |
| 2448 | DECLARE_INSTRUCTION(NullConstant); |
| 2449 | |
| 2450 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2451 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2452 | |
| 2453 | friend class HGraph; |
| 2454 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2455 | }; |
| 2456 | |
| 2457 | // Constants of the type int. Those can be from Dex instructions, or |
| 2458 | // synthesized (for example with the if-eqz instruction). |
| 2459 | class HIntConstant : public HConstant { |
| 2460 | public: |
| 2461 | int32_t GetValue() const { return value_; } |
| 2462 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2463 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2464 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2465 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2466 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2467 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2468 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2469 | return other->AsIntConstant()->value_ == value_; |
| 2470 | } |
| 2471 | |
| 2472 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2473 | |
| 2474 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2475 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2476 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2477 | |
| 2478 | DECLARE_INSTRUCTION(IntConstant); |
| 2479 | |
| 2480 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2481 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2482 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2483 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2484 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2485 | |
| 2486 | const int32_t value_; |
| 2487 | |
| 2488 | friend class HGraph; |
| 2489 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2490 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2491 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2492 | }; |
| 2493 | |
| 2494 | class HLongConstant : public HConstant { |
| 2495 | public: |
| 2496 | int64_t GetValue() const { return value_; } |
| 2497 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2498 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2499 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2500 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2501 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2502 | return other->AsLongConstant()->value_ == value_; |
| 2503 | } |
| 2504 | |
| 2505 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2506 | |
| 2507 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2508 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2509 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2510 | |
| 2511 | DECLARE_INSTRUCTION(LongConstant); |
| 2512 | |
| 2513 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2514 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2515 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2516 | |
| 2517 | const int64_t value_; |
| 2518 | |
| 2519 | friend class HGraph; |
| 2520 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2521 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2522 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2523 | class HFloatConstant : public HConstant { |
| 2524 | public: |
| 2525 | float GetValue() const { return value_; } |
| 2526 | |
| 2527 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2528 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2529 | } |
| 2530 | |
| 2531 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2532 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2533 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2534 | } |
| 2535 | |
| 2536 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2537 | |
| 2538 | bool IsMinusOne() const OVERRIDE { |
| 2539 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2540 | } |
| 2541 | bool IsZero() const OVERRIDE { |
| 2542 | return value_ == 0.0f; |
| 2543 | } |
| 2544 | bool IsOne() const OVERRIDE { |
| 2545 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2546 | } |
| 2547 | bool IsNaN() const { |
| 2548 | return std::isnan(value_); |
| 2549 | } |
| 2550 | |
| 2551 | DECLARE_INSTRUCTION(FloatConstant); |
| 2552 | |
| 2553 | private: |
| 2554 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2555 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2556 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2557 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2558 | |
| 2559 | const float value_; |
| 2560 | |
| 2561 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2562 | friend class SsaBuilder; |
| 2563 | friend class HGraph; |
| 2564 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2565 | }; |
| 2566 | |
| 2567 | class HDoubleConstant : public HConstant { |
| 2568 | public: |
| 2569 | double GetValue() const { return value_; } |
| 2570 | |
| 2571 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2572 | |
| 2573 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2574 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2575 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2576 | } |
| 2577 | |
| 2578 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2579 | |
| 2580 | bool IsMinusOne() const OVERRIDE { |
| 2581 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2582 | } |
| 2583 | bool IsZero() const OVERRIDE { |
| 2584 | return value_ == 0.0; |
| 2585 | } |
| 2586 | bool IsOne() const OVERRIDE { |
| 2587 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2588 | } |
| 2589 | bool IsNaN() const { |
| 2590 | return std::isnan(value_); |
| 2591 | } |
| 2592 | |
| 2593 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2594 | |
| 2595 | private: |
| 2596 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2597 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2598 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2599 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2600 | |
| 2601 | const double value_; |
| 2602 | |
| 2603 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2604 | friend class SsaBuilder; |
| 2605 | friend class HGraph; |
| 2606 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2607 | }; |
| 2608 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2609 | // Conditional branch. A block ending with an HIf instruction must have |
| 2610 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2611 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2612 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2613 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2614 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2615 | SetRawInputAt(0, input); |
| 2616 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2617 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2618 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2619 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2620 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2621 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2625 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2628 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2629 | |
| 2630 | private: |
| 2631 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2632 | }; |
| 2633 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2634 | |
| 2635 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2636 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2637 | // non-exceptional control flow. |
| 2638 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2639 | // higher indices in no particular order. |
| 2640 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2641 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2642 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2643 | kEntry, |
| 2644 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2645 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2646 | }; |
| 2647 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2648 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2649 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2650 | SetPackedField<BoundaryKindField>(kind); |
| 2651 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2652 | |
| 2653 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2654 | |
| 2655 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2656 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2657 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2658 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2659 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2660 | } |
| 2661 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2662 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2663 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2664 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2665 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2666 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2667 | } |
| 2668 | |
| 2669 | // If not present already, adds `handler` to its block's list of exception |
| 2670 | // handlers. |
| 2671 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2672 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2673 | GetBlock()->AddSuccessor(handler); |
| 2674 | } |
| 2675 | } |
| 2676 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2677 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2678 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2679 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2680 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2681 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2682 | DECLARE_INSTRUCTION(TryBoundary); |
| 2683 | |
| 2684 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2685 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2686 | static constexpr size_t kFieldBoundaryKindSize = |
| 2687 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2688 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2689 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2690 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2691 | "Too many packed fields."); |
| 2692 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2693 | |
| 2694 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2695 | }; |
| 2696 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2697 | // Deoptimize to interpreter, upon checking a condition. |
| 2698 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2699 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2700 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2701 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2702 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2703 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2704 | SetRawInputAt(0, cond); |
| 2705 | } |
| 2706 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2707 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2708 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2709 | return true; |
| 2710 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2711 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2712 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2713 | |
| 2714 | DECLARE_INSTRUCTION(Deoptimize); |
| 2715 | |
| 2716 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2717 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2718 | }; |
| 2719 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2720 | // Represents the ArtMethod that was passed as a first argument to |
| 2721 | // the method. It is used by instructions that depend on it, like |
| 2722 | // instructions that work with the dex cache. |
| 2723 | class HCurrentMethod : public HExpression<0> { |
| 2724 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2725 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2726 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2727 | |
| 2728 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2729 | |
| 2730 | private: |
| 2731 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2732 | }; |
| 2733 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2734 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2735 | // of a class. |
| 2736 | class HClassTableGet : public HExpression<1> { |
| 2737 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2738 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2739 | kVTable, |
| 2740 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2741 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2742 | }; |
| 2743 | HClassTableGet(HInstruction* cls, |
| 2744 | Primitive::Type type, |
| 2745 | TableKind kind, |
| 2746 | size_t index, |
| 2747 | uint32_t dex_pc) |
| 2748 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2749 | index_(index) { |
| 2750 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2751 | SetRawInputAt(0, cls); |
| 2752 | } |
| 2753 | |
| 2754 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2755 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2756 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2757 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2758 | } |
| 2759 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2760 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2761 | size_t GetIndex() const { return index_; } |
| 2762 | |
| 2763 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2764 | |
| 2765 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2766 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2767 | static constexpr size_t kFieldTableKindSize = |
| 2768 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2769 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2770 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2771 | "Too many packed fields."); |
| 2772 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2773 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2774 | // The index of the ArtMethod in the table. |
| 2775 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2776 | |
| 2777 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2778 | }; |
| 2779 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2780 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2781 | // have one successor for each entry in the switch table, and the final successor |
| 2782 | // will be the block containing the next Dex opcode. |
| 2783 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2784 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2785 | HPackedSwitch(int32_t start_value, |
| 2786 | uint32_t num_entries, |
| 2787 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2788 | uint32_t dex_pc = kNoDexPc) |
| 2789 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2790 | start_value_(start_value), |
| 2791 | num_entries_(num_entries) { |
| 2792 | SetRawInputAt(0, input); |
| 2793 | } |
| 2794 | |
| 2795 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2796 | |
| 2797 | int32_t GetStartValue() const { return start_value_; } |
| 2798 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2799 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2800 | |
| 2801 | HBasicBlock* GetDefaultBlock() const { |
| 2802 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2803 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2804 | } |
| 2805 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2806 | |
| 2807 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2808 | const int32_t start_value_; |
| 2809 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2810 | |
| 2811 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2812 | }; |
| 2813 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2814 | class HUnaryOperation : public HExpression<1> { |
| 2815 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2816 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2817 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2818 | SetRawInputAt(0, input); |
| 2819 | } |
| 2820 | |
| 2821 | HInstruction* GetInput() const { return InputAt(0); } |
| 2822 | Primitive::Type GetResultType() const { return GetType(); } |
| 2823 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2824 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2825 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2826 | return true; |
| 2827 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2828 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2829 | // Try to statically evaluate `this` and return a HConstant |
| 2830 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2831 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2832 | HConstant* TryStaticEvaluation() const; |
| 2833 | |
| 2834 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2835 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2836 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2837 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2838 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2839 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2840 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2841 | |
| 2842 | private: |
| 2843 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2844 | }; |
| 2845 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2846 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2847 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2848 | HBinaryOperation(Primitive::Type result_type, |
| 2849 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2850 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2851 | SideEffects side_effects = SideEffects::None(), |
| 2852 | uint32_t dex_pc = kNoDexPc) |
| 2853 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2854 | SetRawInputAt(0, left); |
| 2855 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2858 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2859 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2860 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2861 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2862 | virtual bool IsCommutative() const { return false; } |
| 2863 | |
| 2864 | // Put constant on the right. |
| 2865 | // Returns whether order is changed. |
| 2866 | bool OrderInputsWithConstantOnTheRight() { |
| 2867 | HInstruction* left = InputAt(0); |
| 2868 | HInstruction* right = InputAt(1); |
| 2869 | if (left->IsConstant() && !right->IsConstant()) { |
| 2870 | ReplaceInput(right, 0); |
| 2871 | ReplaceInput(left, 1); |
| 2872 | return true; |
| 2873 | } |
| 2874 | return false; |
| 2875 | } |
| 2876 | |
| 2877 | // Order inputs by instruction id, but favor constant on the right side. |
| 2878 | // This helps GVN for commutative ops. |
| 2879 | void OrderInputs() { |
| 2880 | DCHECK(IsCommutative()); |
| 2881 | HInstruction* left = InputAt(0); |
| 2882 | HInstruction* right = InputAt(1); |
| 2883 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2884 | return; |
| 2885 | } |
| 2886 | if (OrderInputsWithConstantOnTheRight()) { |
| 2887 | return; |
| 2888 | } |
| 2889 | // Order according to instruction id. |
| 2890 | if (left->GetId() > right->GetId()) { |
| 2891 | ReplaceInput(right, 0); |
| 2892 | ReplaceInput(left, 1); |
| 2893 | } |
| 2894 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2895 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2896 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2897 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2898 | return true; |
| 2899 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2900 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2901 | // Try to statically evaluate `this` and return a HConstant |
| 2902 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2903 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2904 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2905 | |
| 2906 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2907 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2908 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2909 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 2910 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2911 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2912 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2913 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2914 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2915 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2916 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 2917 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2918 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2919 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 2920 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2921 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2922 | // 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] | 2923 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2924 | HConstant* GetConstantRight() const; |
| 2925 | |
| 2926 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2927 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2928 | HInstruction* GetLeastConstantLeft() const; |
| 2929 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2930 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2931 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2932 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2933 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2934 | }; |
| 2935 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2936 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2937 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2938 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2939 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2940 | kGtBias, // return 1 for NaN comparisons |
| 2941 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2942 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2943 | }; |
| 2944 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2945 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 2946 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2947 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2948 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2949 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2950 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 2951 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 2952 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2953 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2954 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2955 | // `instruction`, and disregard moves in between. |
| 2956 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2957 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2958 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2959 | |
| 2960 | virtual IfCondition GetCondition() const = 0; |
| 2961 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2962 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2963 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2964 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
| 2965 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 2966 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2967 | |
| 2968 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2969 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2970 | } |
| 2971 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2972 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2973 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2974 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2975 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2979 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2980 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2981 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2982 | } |
| 2983 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2984 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2985 | // Needed if we merge a HCompare into a HCondition. |
| 2986 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 2987 | static constexpr size_t kFieldComparisonBiasSize = |
| 2988 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 2989 | static constexpr size_t kNumberOfConditionPackedBits = |
| 2990 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 2991 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2992 | using ComparisonBiasField = |
| 2993 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 2994 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2995 | template <typename T> |
| 2996 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 2997 | |
| 2998 | template <typename T> |
| 2999 | int32_t CompareFP(T x, T y) const { |
| 3000 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3001 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3002 | // Handle the bias. |
| 3003 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3004 | } |
| 3005 | |
| 3006 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3007 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3008 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3009 | } |
| 3010 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3011 | private: |
| 3012 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3013 | }; |
| 3014 | |
| 3015 | // Instruction to check if two inputs are equal to each other. |
| 3016 | class HEqual : public HCondition { |
| 3017 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3018 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3019 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3020 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3021 | bool IsCommutative() const OVERRIDE { return true; } |
| 3022 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3023 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3024 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3025 | return MakeConstantCondition(true, GetDexPc()); |
| 3026 | } |
| 3027 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3028 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3029 | } |
| 3030 | // In the following Evaluate methods, a HCompare instruction has |
| 3031 | // been merged into this HEqual instruction; evaluate it as |
| 3032 | // `Compare(x, y) == 0`. |
| 3033 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3034 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3035 | GetDexPc()); |
| 3036 | } |
| 3037 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3038 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3039 | } |
| 3040 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3041 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3042 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3043 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3044 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3045 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3046 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3047 | return kCondEQ; |
| 3048 | } |
| 3049 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3050 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3051 | return kCondNE; |
| 3052 | } |
| 3053 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3054 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3055 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 3056 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3057 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3058 | }; |
| 3059 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3060 | class HNotEqual : public HCondition { |
| 3061 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3062 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3063 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3064 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3065 | bool IsCommutative() const OVERRIDE { return true; } |
| 3066 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3067 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3068 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3069 | return MakeConstantCondition(false, GetDexPc()); |
| 3070 | } |
| 3071 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3072 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3073 | } |
| 3074 | // In the following Evaluate methods, a HCompare instruction has |
| 3075 | // been merged into this HNotEqual instruction; evaluate it as |
| 3076 | // `Compare(x, y) != 0`. |
| 3077 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3078 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3079 | } |
| 3080 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3081 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3082 | } |
| 3083 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3084 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3085 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3086 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3087 | DECLARE_INSTRUCTION(NotEqual); |
| 3088 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3089 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3090 | return kCondNE; |
| 3091 | } |
| 3092 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3093 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3094 | return kCondEQ; |
| 3095 | } |
| 3096 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3097 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3098 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 3099 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3100 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3101 | }; |
| 3102 | |
| 3103 | class HLessThan : public HCondition { |
| 3104 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3105 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3106 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3107 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3108 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3109 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3110 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3111 | // In the following Evaluate methods, a HCompare instruction has |
| 3112 | // been merged into this HLessThan instruction; evaluate it as |
| 3113 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3114 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3115 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3116 | } |
| 3117 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3118 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3119 | } |
| 3120 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3121 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3122 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3123 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3124 | DECLARE_INSTRUCTION(LessThan); |
| 3125 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3126 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3127 | return kCondLT; |
| 3128 | } |
| 3129 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3130 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3131 | return kCondGE; |
| 3132 | } |
| 3133 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3134 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3135 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3136 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3137 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3138 | }; |
| 3139 | |
| 3140 | class HLessThanOrEqual : public HCondition { |
| 3141 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3142 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3143 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3144 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3145 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3146 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3147 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3148 | // In the following Evaluate methods, a HCompare instruction has |
| 3149 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3150 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3151 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3152 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3153 | } |
| 3154 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3155 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3156 | } |
| 3157 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3158 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3159 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3160 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3161 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3162 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3163 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3164 | return kCondLE; |
| 3165 | } |
| 3166 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3167 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3168 | return kCondGT; |
| 3169 | } |
| 3170 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3171 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3172 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3173 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3174 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3175 | }; |
| 3176 | |
| 3177 | class HGreaterThan : public HCondition { |
| 3178 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3179 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3180 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3181 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3182 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3183 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3184 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3185 | // In the following Evaluate methods, a HCompare instruction has |
| 3186 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3187 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3188 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3189 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3190 | } |
| 3191 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3192 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3193 | } |
| 3194 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3195 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3196 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3197 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3198 | DECLARE_INSTRUCTION(GreaterThan); |
| 3199 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3200 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3201 | return kCondGT; |
| 3202 | } |
| 3203 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3204 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3205 | return kCondLE; |
| 3206 | } |
| 3207 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3208 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3209 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3210 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3211 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3212 | }; |
| 3213 | |
| 3214 | class HGreaterThanOrEqual : public HCondition { |
| 3215 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3216 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3217 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3218 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3219 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3220 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3221 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3222 | // In the following Evaluate methods, a HCompare instruction has |
| 3223 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3224 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3225 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3226 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3227 | } |
| 3228 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3229 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3230 | } |
| 3231 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3232 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3233 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3234 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3235 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3236 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3237 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3238 | return kCondGE; |
| 3239 | } |
| 3240 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3241 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3242 | return kCondLT; |
| 3243 | } |
| 3244 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3245 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3246 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3247 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3248 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3249 | }; |
| 3250 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3251 | class HBelow : public HCondition { |
| 3252 | public: |
| 3253 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3254 | : HCondition(first, second, dex_pc) {} |
| 3255 | |
| 3256 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3257 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3258 | } |
| 3259 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3260 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3261 | } |
| 3262 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3263 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3264 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3265 | UNREACHABLE(); |
| 3266 | } |
| 3267 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3268 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3269 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3270 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | DECLARE_INSTRUCTION(Below); |
| 3274 | |
| 3275 | IfCondition GetCondition() const OVERRIDE { |
| 3276 | return kCondB; |
| 3277 | } |
| 3278 | |
| 3279 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3280 | return kCondAE; |
| 3281 | } |
| 3282 | |
| 3283 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3284 | template <typename T> bool Compute(T x, T y) const { |
| 3285 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3286 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3287 | |
| 3288 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3289 | }; |
| 3290 | |
| 3291 | class HBelowOrEqual : public HCondition { |
| 3292 | public: |
| 3293 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3294 | : HCondition(first, second, dex_pc) {} |
| 3295 | |
| 3296 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3297 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3298 | } |
| 3299 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3300 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3301 | } |
| 3302 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3303 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3304 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3305 | UNREACHABLE(); |
| 3306 | } |
| 3307 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3308 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3309 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3310 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3314 | |
| 3315 | IfCondition GetCondition() const OVERRIDE { |
| 3316 | return kCondBE; |
| 3317 | } |
| 3318 | |
| 3319 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3320 | return kCondA; |
| 3321 | } |
| 3322 | |
| 3323 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3324 | template <typename T> bool Compute(T x, T y) const { |
| 3325 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3326 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3327 | |
| 3328 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3329 | }; |
| 3330 | |
| 3331 | class HAbove : public HCondition { |
| 3332 | public: |
| 3333 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3334 | : HCondition(first, second, dex_pc) {} |
| 3335 | |
| 3336 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3337 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3338 | } |
| 3339 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3340 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3341 | } |
| 3342 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3343 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3344 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3345 | UNREACHABLE(); |
| 3346 | } |
| 3347 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3348 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3349 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3350 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3351 | } |
| 3352 | |
| 3353 | DECLARE_INSTRUCTION(Above); |
| 3354 | |
| 3355 | IfCondition GetCondition() const OVERRIDE { |
| 3356 | return kCondA; |
| 3357 | } |
| 3358 | |
| 3359 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3360 | return kCondBE; |
| 3361 | } |
| 3362 | |
| 3363 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3364 | template <typename T> bool Compute(T x, T y) const { |
| 3365 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3366 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3367 | |
| 3368 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3369 | }; |
| 3370 | |
| 3371 | class HAboveOrEqual : public HCondition { |
| 3372 | public: |
| 3373 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3374 | : HCondition(first, second, dex_pc) {} |
| 3375 | |
| 3376 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3377 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3378 | } |
| 3379 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3380 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3381 | } |
| 3382 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3383 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3384 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3385 | UNREACHABLE(); |
| 3386 | } |
| 3387 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3388 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3389 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3390 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3394 | |
| 3395 | IfCondition GetCondition() const OVERRIDE { |
| 3396 | return kCondAE; |
| 3397 | } |
| 3398 | |
| 3399 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3400 | return kCondB; |
| 3401 | } |
| 3402 | |
| 3403 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3404 | template <typename T> bool Compute(T x, T y) const { |
| 3405 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3406 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3407 | |
| 3408 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3409 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3410 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3411 | // Instruction to check how two inputs compare to each other. |
| 3412 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3413 | class HCompare : public HBinaryOperation { |
| 3414 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3415 | HCompare(Primitive::Type type, |
| 3416 | HInstruction* first, |
| 3417 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3418 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3419 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3420 | : HBinaryOperation(Primitive::kPrimInt, |
| 3421 | first, |
| 3422 | second, |
| 3423 | SideEffectsForArchRuntimeCalls(type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3424 | dex_pc) { |
| 3425 | SetPackedField<ComparisonBiasField>(bias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3426 | DCHECK_EQ(type, first->GetType()); |
| 3427 | DCHECK_EQ(type, second->GetType()); |
| 3428 | } |
| 3429 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3430 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3431 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3432 | |
| 3433 | template <typename T> |
| 3434 | int32_t ComputeFP(T x, T y) const { |
| 3435 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3436 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3437 | // Handle the bias. |
| 3438 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3439 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3440 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3441 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3442 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3443 | // reach this code path when processing a freshly built HIR |
| 3444 | // graph. However HCompare integer instructions can be synthesized |
| 3445 | // by the instruction simplifier to implement IntegerCompare and |
| 3446 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3447 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3448 | } |
| 3449 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3450 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3451 | } |
| 3452 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3453 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3454 | } |
| 3455 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3456 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3457 | } |
| 3458 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3459 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3460 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3461 | } |
| 3462 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3463 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3464 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3465 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3466 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3467 | bool IsGtBias() const { |
| 3468 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3469 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3470 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3471 | |
| 3472 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3473 | // MIPS64 uses a runtime call for FP comparisons. |
| 3474 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3475 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3476 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3477 | DECLARE_INSTRUCTION(Compare); |
| 3478 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3479 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3480 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3481 | static constexpr size_t kFieldComparisonBiasSize = |
| 3482 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3483 | static constexpr size_t kNumberOfComparePackedBits = |
| 3484 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3485 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3486 | using ComparisonBiasField = |
| 3487 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3488 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3489 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3490 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3491 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3492 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3493 | } |
| 3494 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3495 | private: |
| 3496 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3497 | }; |
| 3498 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3499 | // A local in the graph. Corresponds to a Dex register. |
| 3500 | class HLocal : public HTemplateInstruction<0> { |
| 3501 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3502 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3503 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3504 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3505 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3506 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3507 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3508 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3509 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3510 | // The Dex register number. |
| 3511 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3512 | |
| 3513 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3514 | }; |
| 3515 | |
| 3516 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3517 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3518 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3519 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3520 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3521 | SetRawInputAt(0, local); |
| 3522 | } |
| 3523 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3524 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3525 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3526 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3527 | |
| 3528 | private: |
| 3529 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3530 | }; |
| 3531 | |
| 3532 | // Store a value in a given local. This instruction has two inputs: the value |
| 3533 | // and the local. |
| 3534 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3535 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3536 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3537 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3538 | SetRawInputAt(0, local); |
| 3539 | SetRawInputAt(1, value); |
| 3540 | } |
| 3541 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3542 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3543 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3544 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3545 | |
| 3546 | private: |
| 3547 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3548 | }; |
| 3549 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3550 | class HNewInstance : public HExpression<2> { |
| 3551 | public: |
| 3552 | HNewInstance(HInstruction* cls, |
| 3553 | HCurrentMethod* current_method, |
| 3554 | uint32_t dex_pc, |
| 3555 | uint16_t type_index, |
| 3556 | const DexFile& dex_file, |
| 3557 | bool can_throw, |
| 3558 | bool finalizable, |
| 3559 | QuickEntrypointEnum entrypoint) |
| 3560 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3561 | type_index_(type_index), |
| 3562 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3563 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3564 | SetPackedFlag<kFlagCanThrow>(can_throw); |
| 3565 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3566 | SetRawInputAt(0, cls); |
| 3567 | SetRawInputAt(1, current_method); |
| 3568 | } |
| 3569 | |
| 3570 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3571 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3572 | |
| 3573 | // Calls runtime so needs an environment. |
| 3574 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3575 | |
| 3576 | // It may throw when called on type that's not instantiable/accessible. |
| 3577 | // It can throw OOME. |
| 3578 | // 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] | 3579 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>() || true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3580 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3581 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3582 | |
| 3583 | bool CanBeNull() const OVERRIDE { return false; } |
| 3584 | |
| 3585 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3586 | |
| 3587 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3588 | entrypoint_ = entrypoint; |
| 3589 | } |
| 3590 | |
| 3591 | bool IsStringAlloc() const; |
| 3592 | |
| 3593 | DECLARE_INSTRUCTION(NewInstance); |
| 3594 | |
| 3595 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3596 | static constexpr size_t kFlagCanThrow = kNumberOfExpressionPackedBits; |
| 3597 | static constexpr size_t kFlagFinalizable = kFlagCanThrow + 1; |
| 3598 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3599 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3600 | "Too many packed fields."); |
| 3601 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3602 | const uint16_t type_index_; |
| 3603 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3604 | QuickEntrypointEnum entrypoint_; |
| 3605 | |
| 3606 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3607 | }; |
| 3608 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3609 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3610 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3611 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3612 | #include "intrinsics_list.h" |
| 3613 | kNone, |
| 3614 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3615 | #undef INTRINSICS_LIST |
| 3616 | #undef OPTIMIZING_INTRINSICS |
| 3617 | }; |
| 3618 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3619 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3620 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3621 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3622 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3623 | }; |
| 3624 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3625 | enum IntrinsicSideEffects { |
| 3626 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3627 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3628 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3629 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3630 | }; |
| 3631 | |
| 3632 | enum IntrinsicExceptions { |
| 3633 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3634 | kCanThrow // Intrinsic may throw exceptions. |
| 3635 | }; |
| 3636 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3637 | class HInvoke : public HInstruction { |
| 3638 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3639 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3640 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3641 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3642 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3643 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3644 | SetRawInputAt(index, argument); |
| 3645 | } |
| 3646 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3647 | // Return the number of arguments. This number can be lower than |
| 3648 | // the number of inputs returned by InputCount(), as some invoke |
| 3649 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3650 | // inputs at the end of their list of inputs. |
| 3651 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3652 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3653 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3654 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3655 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3656 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3657 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3658 | InvokeType GetOriginalInvokeType() const { |
| 3659 | return GetPackedField<OriginalInvokeTypeField>(); |
| 3660 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3661 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3662 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3663 | return intrinsic_; |
| 3664 | } |
| 3665 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3666 | void SetIntrinsic(Intrinsics intrinsic, |
| 3667 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3668 | IntrinsicSideEffects side_effects, |
| 3669 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3670 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3671 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3672 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3673 | } |
| 3674 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3675 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3676 | |
| 3677 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3678 | |
| 3679 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3680 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3681 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3682 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3683 | uint32_t* GetIntrinsicOptimizations() { |
| 3684 | return &intrinsic_optimizations_; |
| 3685 | } |
| 3686 | |
| 3687 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3688 | return &intrinsic_optimizations_; |
| 3689 | } |
| 3690 | |
| 3691 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3692 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3693 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3694 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3695 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3696 | static constexpr size_t kFieldOriginalInvokeType = kNumberOfGenericPackedBits; |
| 3697 | static constexpr size_t kFieldOriginalInvokeTypeSize = |
| 3698 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3699 | static constexpr size_t kFieldReturnType = |
| 3700 | kFieldOriginalInvokeType + kFieldOriginalInvokeTypeSize; |
| 3701 | static constexpr size_t kFieldReturnTypeSize = |
| 3702 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3703 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3704 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3705 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3706 | using OriginalInvokeTypeField = |
| 3707 | BitField<InvokeType, kFieldOriginalInvokeType, kFieldOriginalInvokeTypeSize>; |
| 3708 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3709 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3710 | HInvoke(ArenaAllocator* arena, |
| 3711 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3712 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3713 | Primitive::Type return_type, |
| 3714 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3715 | uint32_t dex_method_index, |
| 3716 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3717 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3718 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3719 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3720 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3721 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3722 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3723 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3724 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3725 | SetPackedField<ReturnTypeField>(return_type); |
| 3726 | SetPackedField<OriginalInvokeTypeField>(original_invoke_type); |
| 3727 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3728 | } |
| 3729 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3730 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3731 | return inputs_[index]; |
| 3732 | } |
| 3733 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3734 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3735 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3738 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3739 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3740 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3741 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3742 | const uint32_t dex_method_index_; |
| 3743 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3744 | |
| 3745 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3746 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3747 | |
| 3748 | private: |
| 3749 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3750 | }; |
| 3751 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3752 | class HInvokeUnresolved : public HInvoke { |
| 3753 | public: |
| 3754 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3755 | uint32_t number_of_arguments, |
| 3756 | Primitive::Type return_type, |
| 3757 | uint32_t dex_pc, |
| 3758 | uint32_t dex_method_index, |
| 3759 | InvokeType invoke_type) |
| 3760 | : HInvoke(arena, |
| 3761 | number_of_arguments, |
| 3762 | 0u /* number_of_other_inputs */, |
| 3763 | return_type, |
| 3764 | dex_pc, |
| 3765 | dex_method_index, |
| 3766 | invoke_type) { |
| 3767 | } |
| 3768 | |
| 3769 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3770 | |
| 3771 | private: |
| 3772 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3773 | }; |
| 3774 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3775 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3776 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3777 | // Requirements of this method call regarding the class |
| 3778 | // initialization (clinit) check of its declaring class. |
| 3779 | enum class ClinitCheckRequirement { |
| 3780 | kNone, // Class already initialized. |
| 3781 | kExplicit, // Static call having explicit clinit check as last input. |
| 3782 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3783 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3784 | }; |
| 3785 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3786 | // Determines how to load the target ArtMethod*. |
| 3787 | enum class MethodLoadKind { |
| 3788 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3789 | kStringInit, |
| 3790 | |
| 3791 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3792 | kRecursive, |
| 3793 | |
| 3794 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3795 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3796 | kDirectAddress, |
| 3797 | |
| 3798 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3799 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3800 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3801 | // the image relocatable or not. |
| 3802 | kDirectAddressWithFixup, |
| 3803 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3804 | // 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] | 3805 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3806 | // may cause class initialization (the entry may point to a resolution method), |
| 3807 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3808 | kDexCachePcRelative, |
| 3809 | |
| 3810 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3811 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3812 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3813 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3814 | kDexCacheViaMethod, |
| 3815 | }; |
| 3816 | |
| 3817 | // Determines the location of the code pointer. |
| 3818 | enum class CodePtrLocation { |
| 3819 | // Recursive call, use local PC-relative call instruction. |
| 3820 | kCallSelf, |
| 3821 | |
| 3822 | // Use PC-relative call instruction patched at link time. |
| 3823 | // Used for calls within an oat file, boot->boot or app->app. |
| 3824 | kCallPCRelative, |
| 3825 | |
| 3826 | // Call to a known target address, embed the direct address in code. |
| 3827 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3828 | kCallDirect, |
| 3829 | |
| 3830 | // Call to a target address that will be known at link time, embed the direct |
| 3831 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3832 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3833 | // the image relocatable or not. |
| 3834 | kCallDirectWithFixup, |
| 3835 | |
| 3836 | // Use code pointer from the ArtMethod*. |
| 3837 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3838 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3839 | kCallArtMethod, |
| 3840 | }; |
| 3841 | |
| 3842 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3843 | MethodLoadKind method_load_kind; |
| 3844 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3845 | // The method load data holds |
| 3846 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3847 | // Note that there are multiple string init methods, each having its own offset. |
| 3848 | // - the method address for kDirectAddress |
| 3849 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3850 | uint64_t method_load_data; |
| 3851 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3852 | }; |
| 3853 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3854 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3855 | uint32_t number_of_arguments, |
| 3856 | Primitive::Type return_type, |
| 3857 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3858 | uint32_t method_index, |
| 3859 | MethodReference target_method, |
| 3860 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3861 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3862 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3863 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3864 | : HInvoke(arena, |
| 3865 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3866 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3867 | // potentially one other if the clinit check is explicit, and potentially |
| 3868 | // one other if the method is a string factory. |
| 3869 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3870 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3871 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3872 | return_type, |
| 3873 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3874 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3875 | original_invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3876 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3877 | dispatch_info_(dispatch_info) { |
| 3878 | SetPackedField<OptimizedInvokeTypeField>(optimized_invoke_type); |
| 3879 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3880 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3881 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3882 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3883 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3884 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3885 | |
| 3886 | // Using the current method is the default and once we find a better |
| 3887 | // method load kind, we should not go back to using the current method. |
| 3888 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3889 | |
| 3890 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3891 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3892 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3893 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3894 | dispatch_info_ = dispatch_info; |
| 3895 | } |
| 3896 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3897 | void AddSpecialInput(HInstruction* input) { |
| 3898 | // We allow only one special input. |
| 3899 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3900 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3901 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3902 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3903 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3904 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3905 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3906 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3907 | // TODO: for intrinsics we can generate implicit null checks. |
| 3908 | return false; |
| 3909 | } |
| 3910 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3911 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3912 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3913 | } |
| 3914 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3915 | // Get the index of the special input, if any. |
| 3916 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3917 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3918 | // method pointer; otherwise there may be one platform-specific special input, |
| 3919 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3920 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 3921 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3922 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3923 | InvokeType GetOptimizedInvokeType() const { |
| 3924 | return GetPackedField<OptimizedInvokeTypeField>(); |
| 3925 | } |
| 3926 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3927 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3928 | SetPackedField<OptimizedInvokeTypeField>(invoke_type); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3929 | } |
| 3930 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3931 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3932 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3933 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3934 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3935 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3936 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3937 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3938 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3939 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3940 | bool HasCurrentMethodInput() const { |
| 3941 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3942 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3943 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3944 | return true; |
| 3945 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3946 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3947 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3948 | return false; |
| 3949 | } |
| 3950 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3951 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3952 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3953 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3954 | |
| 3955 | int32_t GetStringInitOffset() const { |
| 3956 | DCHECK(IsStringInit()); |
| 3957 | return dispatch_info_.method_load_data; |
| 3958 | } |
| 3959 | |
| 3960 | uint64_t GetMethodAddress() const { |
| 3961 | DCHECK(HasMethodAddress()); |
| 3962 | return dispatch_info_.method_load_data; |
| 3963 | } |
| 3964 | |
| 3965 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3966 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3967 | return dispatch_info_.method_load_data; |
| 3968 | } |
| 3969 | |
| 3970 | uint64_t GetDirectCodePtr() const { |
| 3971 | DCHECK(HasDirectCodePtr()); |
| 3972 | return dispatch_info_.direct_code_ptr; |
| 3973 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3974 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3975 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 3976 | return GetPackedField<ClinitCheckRequirementField>(); |
| 3977 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3978 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3979 | // Is this instruction a call to a static method? |
| 3980 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3981 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3982 | } |
| 3983 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3984 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3985 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3986 | // instruction; only relevant for static calls with explicit clinit check. |
| 3987 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3988 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3989 | size_t last_input_index = InputCount() - 1; |
| 3990 | HInstruction* last_input = InputAt(last_input_index); |
| 3991 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3992 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3993 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3994 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3995 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3996 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3997 | } |
| 3998 | |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3999 | HInstruction* GetAndRemoveThisArgumentOfStringInit() { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4000 | DCHECK(IsStringInit()); |
| 4001 | size_t index = InputCount() - 1; |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 4002 | HInstruction* input = InputAt(index); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4003 | RemoveAsUserOfInput(index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4004 | inputs_.pop_back(); |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 4005 | return input; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4006 | } |
| 4007 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4008 | // 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] | 4009 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4010 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4011 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | // Is this a call to a static method whose declaring class has an |
| 4015 | // implicit intialization check requirement? |
| 4016 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4017 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4018 | } |
| 4019 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4020 | // Does this method load kind need the current method as an input? |
| 4021 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4022 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4023 | } |
| 4024 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4025 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4026 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4027 | protected: |
| 4028 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 4029 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 4030 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 4031 | HInstruction* input = input_record.GetInstruction(); |
| 4032 | // `input` is the last input of a static invoke marked as having |
| 4033 | // an explicit clinit check. It must either be: |
| 4034 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4035 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4036 | DCHECK(input != nullptr); |
| 4037 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 4038 | } |
| 4039 | return input_record; |
| 4040 | } |
| 4041 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4042 | void InsertInputAt(size_t index, HInstruction* input); |
| 4043 | void RemoveInputAt(size_t index); |
| 4044 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4045 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4046 | static constexpr size_t kFieldOptimizedInvokeType = kNumberOfInvokePackedBits; |
| 4047 | static constexpr size_t kFieldOptimizedInvokeTypeSize = |
| 4048 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4049 | static constexpr size_t kFieldClinitCheckRequirement = |
| 4050 | kFieldOptimizedInvokeType + kFieldOptimizedInvokeTypeSize; |
| 4051 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4052 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4053 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4054 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4055 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4056 | "Too many packed fields."); |
| 4057 | using OptimizedInvokeTypeField = |
| 4058 | BitField<InvokeType, kFieldOptimizedInvokeType, kFieldOptimizedInvokeTypeSize>; |
| 4059 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4060 | kFieldClinitCheckRequirement, |
| 4061 | kFieldClinitCheckRequirementSize>; |
| 4062 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4063 | // The target method may refer to different dex file or method index than the original |
| 4064 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 4065 | // in derived class to increase visibility. |
| 4066 | MethodReference target_method_; |
| 4067 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4068 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4069 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4070 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4071 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4072 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4073 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4074 | class HInvokeVirtual : public HInvoke { |
| 4075 | public: |
| 4076 | HInvokeVirtual(ArenaAllocator* arena, |
| 4077 | uint32_t number_of_arguments, |
| 4078 | Primitive::Type return_type, |
| 4079 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4080 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4081 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4082 | : 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] | 4083 | vtable_index_(vtable_index) {} |
| 4084 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4085 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4086 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4087 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4090 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4091 | |
| 4092 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4093 | |
| 4094 | private: |
| 4095 | const uint32_t vtable_index_; |
| 4096 | |
| 4097 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4098 | }; |
| 4099 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4100 | class HInvokeInterface : public HInvoke { |
| 4101 | public: |
| 4102 | HInvokeInterface(ArenaAllocator* arena, |
| 4103 | uint32_t number_of_arguments, |
| 4104 | Primitive::Type return_type, |
| 4105 | uint32_t dex_pc, |
| 4106 | uint32_t dex_method_index, |
| 4107 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4108 | : 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] | 4109 | imt_index_(imt_index) {} |
| 4110 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4111 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4112 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4113 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4114 | } |
| 4115 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4116 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4117 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4118 | |
| 4119 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4120 | |
| 4121 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4122 | const uint32_t imt_index_; |
| 4123 | |
| 4124 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4125 | }; |
| 4126 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4127 | class HNeg : public HUnaryOperation { |
| 4128 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4129 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4130 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4131 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4132 | template <typename T> T Compute(T x) const { return -x; } |
| 4133 | |
| 4134 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4135 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4136 | } |
| 4137 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4138 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4139 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4140 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4141 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4142 | } |
| 4143 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4144 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4145 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4146 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4147 | DECLARE_INSTRUCTION(Neg); |
| 4148 | |
| 4149 | private: |
| 4150 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4151 | }; |
| 4152 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4153 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4154 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4155 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4156 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4157 | uint32_t dex_pc, |
| 4158 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4159 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4160 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4161 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4162 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4163 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4164 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4165 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4166 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4167 | } |
| 4168 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4169 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4170 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4171 | |
| 4172 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4173 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4174 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4175 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4176 | bool CanThrow() const OVERRIDE { return true; } |
| 4177 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4178 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4179 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4180 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4181 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4182 | DECLARE_INSTRUCTION(NewArray); |
| 4183 | |
| 4184 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4185 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4186 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4187 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4188 | |
| 4189 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4190 | }; |
| 4191 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4192 | class HAdd : public HBinaryOperation { |
| 4193 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4194 | HAdd(Primitive::Type result_type, |
| 4195 | HInstruction* left, |
| 4196 | HInstruction* right, |
| 4197 | uint32_t dex_pc = kNoDexPc) |
| 4198 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4199 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4200 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4201 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4202 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 4203 | |
| 4204 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4205 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4206 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4207 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4208 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4209 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4210 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4211 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4212 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4213 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4214 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4215 | } |
| 4216 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4217 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4218 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4219 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4220 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4221 | DECLARE_INSTRUCTION(Add); |
| 4222 | |
| 4223 | private: |
| 4224 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4225 | }; |
| 4226 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4227 | class HSub : public HBinaryOperation { |
| 4228 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4229 | HSub(Primitive::Type result_type, |
| 4230 | HInstruction* left, |
| 4231 | HInstruction* right, |
| 4232 | uint32_t dex_pc = kNoDexPc) |
| 4233 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4234 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4235 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 4236 | |
| 4237 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4238 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4239 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4240 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4241 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4242 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4243 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4244 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4245 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4246 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4247 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4248 | } |
| 4249 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4250 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4251 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4252 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4253 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4254 | DECLARE_INSTRUCTION(Sub); |
| 4255 | |
| 4256 | private: |
| 4257 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4258 | }; |
| 4259 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4260 | class HMul : public HBinaryOperation { |
| 4261 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4262 | HMul(Primitive::Type result_type, |
| 4263 | HInstruction* left, |
| 4264 | HInstruction* right, |
| 4265 | uint32_t dex_pc = kNoDexPc) |
| 4266 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4267 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4268 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4269 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4270 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 4271 | |
| 4272 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4273 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4274 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4275 | } |
| 4276 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4277 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4278 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4279 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4280 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4281 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4282 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4283 | } |
| 4284 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4285 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4286 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4287 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4288 | |
| 4289 | DECLARE_INSTRUCTION(Mul); |
| 4290 | |
| 4291 | private: |
| 4292 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4293 | }; |
| 4294 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4295 | class HDiv : public HBinaryOperation { |
| 4296 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4297 | HDiv(Primitive::Type result_type, |
| 4298 | HInstruction* left, |
| 4299 | HInstruction* right, |
| 4300 | uint32_t dex_pc) |
| 4301 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4302 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4303 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4304 | T ComputeIntegral(T x, T y) const { |
| 4305 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4306 | // Our graph structure ensures we never have 0 for `y` during |
| 4307 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4308 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4309 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4310 | return (y == -1) ? -x : x / y; |
| 4311 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4312 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4313 | template <typename T> |
| 4314 | T ComputeFP(T x, T y) const { |
| 4315 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4316 | return x / y; |
| 4317 | } |
| 4318 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4319 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4320 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4321 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4322 | } |
| 4323 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4324 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4325 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4326 | } |
| 4327 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4328 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4329 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4330 | } |
| 4331 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4332 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4333 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4334 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4335 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4336 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4337 | // The generated code can use a runtime call. |
| 4338 | return SideEffects::CanTriggerGC(); |
| 4339 | } |
| 4340 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4341 | DECLARE_INSTRUCTION(Div); |
| 4342 | |
| 4343 | private: |
| 4344 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4345 | }; |
| 4346 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4347 | class HRem : public HBinaryOperation { |
| 4348 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4349 | HRem(Primitive::Type result_type, |
| 4350 | HInstruction* left, |
| 4351 | HInstruction* right, |
| 4352 | uint32_t dex_pc) |
| 4353 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4354 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4355 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4356 | T ComputeIntegral(T x, T y) const { |
| 4357 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4358 | // Our graph structure ensures we never have 0 for `y` during |
| 4359 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4360 | DCHECK_NE(y, 0); |
| 4361 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4362 | return (y == -1) ? 0 : x % y; |
| 4363 | } |
| 4364 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4365 | template <typename T> |
| 4366 | T ComputeFP(T x, T y) const { |
| 4367 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4368 | return std::fmod(x, y); |
| 4369 | } |
| 4370 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4371 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4372 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4373 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4374 | } |
| 4375 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4376 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4377 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4378 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4379 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4380 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4381 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4382 | } |
| 4383 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4384 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4385 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4386 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4387 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4388 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4389 | return SideEffects::CanTriggerGC(); |
| 4390 | } |
| 4391 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4392 | DECLARE_INSTRUCTION(Rem); |
| 4393 | |
| 4394 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4395 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4396 | }; |
| 4397 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4398 | class HDivZeroCheck : public HExpression<1> { |
| 4399 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4400 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4401 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4402 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4403 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4404 | SetRawInputAt(0, value); |
| 4405 | } |
| 4406 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4407 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4408 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4409 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4410 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4411 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4412 | return true; |
| 4413 | } |
| 4414 | |
| 4415 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4416 | bool CanThrow() const OVERRIDE { return true; } |
| 4417 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4418 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4419 | |
| 4420 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4421 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4422 | }; |
| 4423 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4424 | class HShl : public HBinaryOperation { |
| 4425 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4426 | HShl(Primitive::Type result_type, |
| 4427 | HInstruction* left, |
| 4428 | HInstruction* right, |
| 4429 | uint32_t dex_pc = kNoDexPc) |
| 4430 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4431 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4432 | template <typename T, typename U, typename V> |
| 4433 | T Compute(T x, U y, V max_shift_value) const { |
| 4434 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4435 | "V is not the unsigned integer type corresponding to T"); |
| 4436 | return x << (y & max_shift_value); |
| 4437 | } |
| 4438 | |
| 4439 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4440 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4441 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4442 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4443 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4444 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4445 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4446 | } |
| 4447 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4448 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4449 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4450 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4451 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4452 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4453 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4454 | UNREACHABLE(); |
| 4455 | } |
| 4456 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4457 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4458 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4459 | UNREACHABLE(); |
| 4460 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4461 | |
| 4462 | DECLARE_INSTRUCTION(Shl); |
| 4463 | |
| 4464 | private: |
| 4465 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4466 | }; |
| 4467 | |
| 4468 | class HShr : public HBinaryOperation { |
| 4469 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4470 | HShr(Primitive::Type result_type, |
| 4471 | HInstruction* left, |
| 4472 | HInstruction* right, |
| 4473 | uint32_t dex_pc = kNoDexPc) |
| 4474 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4475 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4476 | template <typename T, typename U, typename V> |
| 4477 | T Compute(T x, U y, V max_shift_value) const { |
| 4478 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4479 | "V is not the unsigned integer type corresponding to T"); |
| 4480 | return x >> (y & max_shift_value); |
| 4481 | } |
| 4482 | |
| 4483 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4484 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4485 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4486 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4487 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4488 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4489 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4490 | } |
| 4491 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4492 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4493 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4494 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4495 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4496 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4497 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4498 | UNREACHABLE(); |
| 4499 | } |
| 4500 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4501 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4502 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4503 | UNREACHABLE(); |
| 4504 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4505 | |
| 4506 | DECLARE_INSTRUCTION(Shr); |
| 4507 | |
| 4508 | private: |
| 4509 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4510 | }; |
| 4511 | |
| 4512 | class HUShr : public HBinaryOperation { |
| 4513 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4514 | HUShr(Primitive::Type result_type, |
| 4515 | HInstruction* left, |
| 4516 | HInstruction* right, |
| 4517 | uint32_t dex_pc = kNoDexPc) |
| 4518 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4519 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4520 | template <typename T, typename U, typename V> |
| 4521 | T Compute(T x, U y, V max_shift_value) const { |
| 4522 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4523 | "V is not the unsigned integer type corresponding to T"); |
| 4524 | V ux = static_cast<V>(x); |
| 4525 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4528 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4529 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4530 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4531 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4532 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4533 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4534 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4535 | } |
| 4536 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4537 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4538 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4539 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4540 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4541 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4542 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4543 | UNREACHABLE(); |
| 4544 | } |
| 4545 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4546 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4547 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4548 | UNREACHABLE(); |
| 4549 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4550 | |
| 4551 | DECLARE_INSTRUCTION(UShr); |
| 4552 | |
| 4553 | private: |
| 4554 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4555 | }; |
| 4556 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4557 | class HAnd : public HBinaryOperation { |
| 4558 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4559 | HAnd(Primitive::Type result_type, |
| 4560 | HInstruction* left, |
| 4561 | HInstruction* right, |
| 4562 | uint32_t dex_pc = kNoDexPc) |
| 4563 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4564 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4565 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4566 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4567 | 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] | 4568 | |
| 4569 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4570 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4571 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4572 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4573 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4574 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4575 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4576 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4577 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4578 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4579 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4580 | UNREACHABLE(); |
| 4581 | } |
| 4582 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4583 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4584 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4585 | UNREACHABLE(); |
| 4586 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4587 | |
| 4588 | DECLARE_INSTRUCTION(And); |
| 4589 | |
| 4590 | private: |
| 4591 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4592 | }; |
| 4593 | |
| 4594 | class HOr : public HBinaryOperation { |
| 4595 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4596 | HOr(Primitive::Type result_type, |
| 4597 | HInstruction* left, |
| 4598 | HInstruction* right, |
| 4599 | uint32_t dex_pc = kNoDexPc) |
| 4600 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4601 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4602 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4603 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4604 | 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] | 4605 | |
| 4606 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4607 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4608 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4609 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4610 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4611 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4612 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4613 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4614 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4615 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4616 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4617 | UNREACHABLE(); |
| 4618 | } |
| 4619 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4620 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4621 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4622 | UNREACHABLE(); |
| 4623 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4624 | |
| 4625 | DECLARE_INSTRUCTION(Or); |
| 4626 | |
| 4627 | private: |
| 4628 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4629 | }; |
| 4630 | |
| 4631 | class HXor : public HBinaryOperation { |
| 4632 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4633 | HXor(Primitive::Type result_type, |
| 4634 | HInstruction* left, |
| 4635 | HInstruction* right, |
| 4636 | uint32_t dex_pc = kNoDexPc) |
| 4637 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4638 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4639 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4640 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4641 | 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] | 4642 | |
| 4643 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4644 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4645 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4646 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4647 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4648 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4649 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4650 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4651 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4652 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4653 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4654 | UNREACHABLE(); |
| 4655 | } |
| 4656 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4657 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4658 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4659 | UNREACHABLE(); |
| 4660 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4661 | |
| 4662 | DECLARE_INSTRUCTION(Xor); |
| 4663 | |
| 4664 | private: |
| 4665 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4666 | }; |
| 4667 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4668 | class HRor : public HBinaryOperation { |
| 4669 | public: |
| 4670 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
| 4671 | : HBinaryOperation(result_type, value, distance) {} |
| 4672 | |
| 4673 | template <typename T, typename U, typename V> |
| 4674 | T Compute(T x, U y, V max_shift_value) const { |
| 4675 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4676 | "V is not the unsigned integer type corresponding to T"); |
| 4677 | V ux = static_cast<V>(x); |
| 4678 | if ((y & max_shift_value) == 0) { |
| 4679 | return static_cast<T>(ux); |
| 4680 | } else { |
| 4681 | const V reg_bits = sizeof(T) * 8; |
| 4682 | return static_cast<T>(ux >> (y & max_shift_value)) | |
| 4683 | (x << (reg_bits - (y & max_shift_value))); |
| 4684 | } |
| 4685 | } |
| 4686 | |
| 4687 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4688 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4689 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
| 4690 | } |
| 4691 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4692 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4693 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4694 | } |
| 4695 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4696 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4697 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4698 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4699 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4700 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4701 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4702 | UNREACHABLE(); |
| 4703 | } |
| 4704 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4705 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4706 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4707 | UNREACHABLE(); |
| 4708 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4709 | |
| 4710 | DECLARE_INSTRUCTION(Ror); |
| 4711 | |
| 4712 | private: |
| 4713 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4714 | }; |
| 4715 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4716 | // The value of a parameter in this method. Its location depends on |
| 4717 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4718 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4719 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4720 | HParameterValue(const DexFile& dex_file, |
| 4721 | uint16_t type_index, |
| 4722 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4723 | Primitive::Type parameter_type, |
| 4724 | bool is_this = false) |
| 4725 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4726 | dex_file_(dex_file), |
| 4727 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4728 | index_(index) { |
| 4729 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4730 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4731 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4732 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4733 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4734 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4735 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4736 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4737 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4738 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4739 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4740 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4741 | DECLARE_INSTRUCTION(ParameterValue); |
| 4742 | |
| 4743 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4744 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4745 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4746 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4747 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4748 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4749 | "Too many packed fields."); |
| 4750 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4751 | const DexFile& dex_file_; |
| 4752 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4753 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4754 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4755 | const uint8_t index_; |
| 4756 | |
| 4757 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4758 | }; |
| 4759 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4760 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4761 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4762 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4763 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4764 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4765 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4766 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4767 | return true; |
| 4768 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4769 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4770 | template <typename T> T Compute(T x) const { return ~x; } |
| 4771 | |
| 4772 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4773 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4774 | } |
| 4775 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4776 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4777 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4778 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4779 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4780 | UNREACHABLE(); |
| 4781 | } |
| 4782 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4783 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4784 | UNREACHABLE(); |
| 4785 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4786 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4787 | DECLARE_INSTRUCTION(Not); |
| 4788 | |
| 4789 | private: |
| 4790 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4791 | }; |
| 4792 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4793 | class HBooleanNot : public HUnaryOperation { |
| 4794 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4795 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4796 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4797 | |
| 4798 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4799 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4800 | return true; |
| 4801 | } |
| 4802 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4803 | template <typename T> bool Compute(T x) const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4804 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4805 | return !x; |
| 4806 | } |
| 4807 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4808 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4809 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4810 | } |
| 4811 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4812 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4813 | UNREACHABLE(); |
| 4814 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4815 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4816 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4817 | UNREACHABLE(); |
| 4818 | } |
| 4819 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4820 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4821 | UNREACHABLE(); |
| 4822 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4823 | |
| 4824 | DECLARE_INSTRUCTION(BooleanNot); |
| 4825 | |
| 4826 | private: |
| 4827 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4828 | }; |
| 4829 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4830 | class HTypeConversion : public HExpression<1> { |
| 4831 | public: |
| 4832 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4833 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4834 | : HExpression(result_type, |
| 4835 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4836 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4837 | SetRawInputAt(0, input); |
| 4838 | DCHECK_NE(input->GetType(), result_type); |
| 4839 | } |
| 4840 | |
| 4841 | HInstruction* GetInput() const { return InputAt(0); } |
| 4842 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4843 | Primitive::Type GetResultType() const { return GetType(); } |
| 4844 | |
| 4845 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4846 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4847 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4848 | // Try to statically evaluate the conversion and return a HConstant |
| 4849 | // containing the result. If the input cannot be converted, return nullptr. |
| 4850 | HConstant* TryStaticEvaluation() const; |
| 4851 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4852 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4853 | Primitive::Type result_type) { |
| 4854 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4855 | // in the compilation process we do not know what architecture we will |
| 4856 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4857 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4858 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4859 | return SideEffects::CanTriggerGC(); |
| 4860 | } |
| 4861 | return SideEffects::None(); |
| 4862 | } |
| 4863 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4864 | DECLARE_INSTRUCTION(TypeConversion); |
| 4865 | |
| 4866 | private: |
| 4867 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4868 | }; |
| 4869 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4870 | static constexpr uint32_t kNoRegNumber = -1; |
| 4871 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4872 | class HPhi : public HInstruction { |
| 4873 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4874 | HPhi(ArenaAllocator* arena, |
| 4875 | uint32_t reg_number, |
| 4876 | size_t number_of_inputs, |
| 4877 | Primitive::Type type, |
| 4878 | uint32_t dex_pc = kNoDexPc) |
| 4879 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4880 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4881 | reg_number_(reg_number) { |
| 4882 | SetPackedField<TypeField>(ToPhiType(type)); |
| 4883 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 4884 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4885 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4886 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4887 | SetPackedFlag<kFlagIsLive>(true); |
| 4888 | SetPackedFlag<kFlagCanBeNull>(true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4889 | } |
| 4890 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4891 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4892 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4893 | switch (type) { |
| 4894 | case Primitive::kPrimBoolean: |
| 4895 | case Primitive::kPrimByte: |
| 4896 | case Primitive::kPrimShort: |
| 4897 | case Primitive::kPrimChar: |
| 4898 | return Primitive::kPrimInt; |
| 4899 | default: |
| 4900 | return type; |
| 4901 | } |
| 4902 | } |
| 4903 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4904 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4905 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4906 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4907 | |
| 4908 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4909 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4910 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4911 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4912 | void SetType(Primitive::Type new_type) { |
| 4913 | // Make sure that only valid type changes occur. The following are allowed: |
| 4914 | // (1) int -> float/ref (primitive type propagation), |
| 4915 | // (2) long -> double (primitive type propagation). |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4916 | DCHECK(GetType() == new_type || |
| 4917 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 4918 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 4919 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 4920 | SetPackedField<TypeField>(new_type); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4921 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4922 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4923 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4924 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4925 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4926 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4927 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4928 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 4929 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 4930 | bool IsDead() const { return !IsLive(); } |
| 4931 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4932 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4933 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4934 | return other != nullptr |
| 4935 | && other->IsPhi() |
| 4936 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4937 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4938 | } |
| 4939 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4940 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4941 | // An equivalent phi is a phi having the same dex register and type. |
| 4942 | // It assumes that phis with the same dex register are adjacent. |
| 4943 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4944 | HInstruction* next = GetNext(); |
| 4945 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4946 | if (next->GetType() == GetType()) { |
| 4947 | return next->AsPhi(); |
| 4948 | } |
| 4949 | next = next->GetNext(); |
| 4950 | } |
| 4951 | return nullptr; |
| 4952 | } |
| 4953 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4954 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4955 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4956 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4957 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4958 | return inputs_[index]; |
| 4959 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4960 | |
| 4961 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4962 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4963 | } |
| 4964 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4965 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4966 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 4967 | static constexpr size_t kFieldTypeSize = |
| 4968 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 4969 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 4970 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 4971 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 4972 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4973 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 4974 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4975 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4976 | const uint32_t reg_number_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4977 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4978 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4979 | }; |
| 4980 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4981 | class HNullCheck : public HExpression<1> { |
| 4982 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4983 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4984 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4985 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4986 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4987 | SetRawInputAt(0, value); |
| 4988 | } |
| 4989 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4990 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4991 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4992 | return true; |
| 4993 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4994 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4995 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4996 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4997 | bool CanThrow() const OVERRIDE { return true; } |
| 4998 | |
| 4999 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5000 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5001 | |
| 5002 | DECLARE_INSTRUCTION(NullCheck); |
| 5003 | |
| 5004 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5005 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 5006 | }; |
| 5007 | |
| 5008 | class FieldInfo : public ValueObject { |
| 5009 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5010 | FieldInfo(MemberOffset field_offset, |
| 5011 | Primitive::Type field_type, |
| 5012 | bool is_volatile, |
| 5013 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5014 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5015 | const DexFile& dex_file, |
| 5016 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5017 | : field_offset_(field_offset), |
| 5018 | field_type_(field_type), |
| 5019 | is_volatile_(is_volatile), |
| 5020 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5021 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5022 | dex_file_(dex_file), |
| 5023 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5024 | |
| 5025 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5026 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5027 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5028 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5029 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5030 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5031 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5032 | |
| 5033 | private: |
| 5034 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5035 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5036 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5037 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5038 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5039 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5040 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5041 | }; |
| 5042 | |
| 5043 | class HInstanceFieldGet : public HExpression<1> { |
| 5044 | public: |
| 5045 | HInstanceFieldGet(HInstruction* value, |
| 5046 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5047 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5048 | bool is_volatile, |
| 5049 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5050 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5051 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5052 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5053 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5054 | : HExpression(field_type, |
| 5055 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5056 | dex_pc), |
| 5057 | field_info_(field_offset, |
| 5058 | field_type, |
| 5059 | is_volatile, |
| 5060 | field_idx, |
| 5061 | declaring_class_def_index, |
| 5062 | dex_file, |
| 5063 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5064 | SetRawInputAt(0, value); |
| 5065 | } |
| 5066 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5067 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5068 | |
| 5069 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5070 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 5071 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5072 | } |
| 5073 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5074 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5075 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5079 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5080 | } |
| 5081 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5082 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5083 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5084 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5085 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5086 | |
| 5087 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5088 | |
| 5089 | private: |
| 5090 | const FieldInfo field_info_; |
| 5091 | |
| 5092 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5093 | }; |
| 5094 | |
| 5095 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 5096 | public: |
| 5097 | HInstanceFieldSet(HInstruction* object, |
| 5098 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5099 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5100 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5101 | bool is_volatile, |
| 5102 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5103 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5104 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5105 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5106 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5107 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5108 | dex_pc), |
| 5109 | field_info_(field_offset, |
| 5110 | field_type, |
| 5111 | is_volatile, |
| 5112 | field_idx, |
| 5113 | declaring_class_def_index, |
| 5114 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5115 | dex_cache) { |
| 5116 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5117 | SetRawInputAt(0, object); |
| 5118 | SetRawInputAt(1, value); |
| 5119 | } |
| 5120 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5121 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5122 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5123 | } |
| 5124 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5125 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5126 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5127 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5128 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5129 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5130 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5131 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5132 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5133 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5134 | |
| 5135 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5136 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5137 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5138 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5139 | "Too many packed fields."); |
| 5140 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5141 | const FieldInfo field_info_; |
| 5142 | |
| 5143 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5144 | }; |
| 5145 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5146 | class HArrayGet : public HExpression<2> { |
| 5147 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5148 | HArrayGet(HInstruction* array, |
| 5149 | HInstruction* index, |
| 5150 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5151 | uint32_t dex_pc, |
| 5152 | SideEffects additional_side_effects = SideEffects::None()) |
| 5153 | : HExpression(type, |
| 5154 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 5155 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5156 | SetRawInputAt(0, array); |
| 5157 | SetRawInputAt(1, index); |
| 5158 | } |
| 5159 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5160 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5161 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5162 | return true; |
| 5163 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5164 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5165 | // TODO: We can be smarter here. |
| 5166 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5167 | // which generates the implicit null check. There are cases when these can be removed |
| 5168 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5169 | // implicit check here (as long as the address falls in the first page). |
| 5170 | return false; |
| 5171 | } |
| 5172 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5173 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5174 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5175 | if (kIsDebugBuild && result) { |
| 5176 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5177 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5178 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5179 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5180 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5181 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5182 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5183 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5184 | } |
| 5185 | } |
| 5186 | return result; |
| 5187 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5188 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5189 | HInstruction* GetArray() const { return InputAt(0); } |
| 5190 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5191 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5192 | DECLARE_INSTRUCTION(ArrayGet); |
| 5193 | |
| 5194 | private: |
| 5195 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5196 | }; |
| 5197 | |
| 5198 | class HArraySet : public HTemplateInstruction<3> { |
| 5199 | public: |
| 5200 | HArraySet(HInstruction* array, |
| 5201 | HInstruction* index, |
| 5202 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5203 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5204 | uint32_t dex_pc, |
| 5205 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5206 | : HTemplateInstruction( |
| 5207 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5208 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 5209 | additional_side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5210 | dex_pc) { |
| 5211 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5212 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5213 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5214 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5215 | SetRawInputAt(0, array); |
| 5216 | SetRawInputAt(1, index); |
| 5217 | SetRawInputAt(2, value); |
| 5218 | } |
| 5219 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5220 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5221 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5222 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5223 | } |
| 5224 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5225 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5226 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5227 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5228 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5229 | // TODO: Same as for ArrayGet. |
| 5230 | return false; |
| 5231 | } |
| 5232 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5233 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5234 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5237 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5238 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5239 | } |
| 5240 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5241 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5242 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5243 | } |
| 5244 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5245 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5246 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5247 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5248 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5249 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5250 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5251 | HInstruction* GetArray() const { return InputAt(0); } |
| 5252 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5253 | HInstruction* GetValue() const { return InputAt(2); } |
| 5254 | |
| 5255 | Primitive::Type GetComponentType() const { |
| 5256 | // The Dex format does not type floating point index operations. Since the |
| 5257 | // `expected_component_type_` is set during building and can therefore not |
| 5258 | // be correct, we also check what is the value type. If it is a floating |
| 5259 | // point type, we must use that type. |
| 5260 | Primitive::Type value_type = GetValue()->GetType(); |
| 5261 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5262 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5263 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5264 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5265 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5266 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5267 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5268 | } |
| 5269 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5270 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5271 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5272 | } |
| 5273 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5274 | DECLARE_INSTRUCTION(ArraySet); |
| 5275 | |
| 5276 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5277 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5278 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5279 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5280 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5281 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5282 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5283 | // Cached information for the reference_type_info_ so that codegen |
| 5284 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5285 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5286 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5287 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5288 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5289 | using ExpectedComponentTypeField = |
| 5290 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5291 | |
| 5292 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5293 | }; |
| 5294 | |
| 5295 | class HArrayLength : public HExpression<1> { |
| 5296 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 5297 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5298 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5299 | // Note that arrays do not change length, so the instruction does not |
| 5300 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5301 | SetRawInputAt(0, array); |
| 5302 | } |
| 5303 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5304 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5305 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5306 | return true; |
| 5307 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5308 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5309 | return obj == InputAt(0); |
| 5310 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5311 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5312 | DECLARE_INSTRUCTION(ArrayLength); |
| 5313 | |
| 5314 | private: |
| 5315 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5316 | }; |
| 5317 | |
| 5318 | class HBoundsCheck : public HExpression<2> { |
| 5319 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5320 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5321 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5322 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5323 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5324 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 5325 | SetRawInputAt(0, index); |
| 5326 | SetRawInputAt(1, length); |
| 5327 | } |
| 5328 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5329 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5330 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5331 | return true; |
| 5332 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5333 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5334 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5335 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5336 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5337 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5338 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5339 | |
| 5340 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5341 | |
| 5342 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5343 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5344 | }; |
| 5345 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5346 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 5347 | public: |
| 5348 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5349 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5350 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5351 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5352 | return true; |
| 5353 | } |
| 5354 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5355 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5356 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5357 | |
| 5358 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5359 | |
| 5360 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5361 | // Only used for code generation, in order to share the same slow path between back edges |
| 5362 | // of a same loop. |
| 5363 | SlowPathCode* slow_path_; |
| 5364 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5365 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5366 | }; |
| 5367 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5368 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5369 | // It ensures that we can generate line number and local variables at this point. |
| 5370 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5371 | public: |
| 5372 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5373 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5374 | |
| 5375 | bool NeedsEnvironment() const OVERRIDE { |
| 5376 | return true; |
| 5377 | } |
| 5378 | |
| 5379 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5380 | |
| 5381 | private: |
| 5382 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5383 | }; |
| 5384 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5385 | /** |
| 5386 | * Instruction to load a Class object. |
| 5387 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5388 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5389 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5390 | HLoadClass(HCurrentMethod* current_method, |
| 5391 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5392 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5393 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5394 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5395 | bool needs_access_check, |
| 5396 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5397 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5398 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5399 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5400 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5401 | // Referrers class should not need access check. We never inline unverified |
| 5402 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5403 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5404 | |
| 5405 | SetPackedFlag<kFlagIsReferrersClass>(is_referrers_class); |
| 5406 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5407 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
| 5408 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5409 | SetRawInputAt(0, current_method); |
| 5410 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5411 | |
| 5412 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5413 | |
| 5414 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5415 | // Note that we don't need to test for generate_clinit_check_. |
| 5416 | // Whether or not we need to generate the clinit check is processed in |
| 5417 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5418 | return other->AsLoadClass()->type_index_ == type_index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5419 | other->AsLoadClass()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5423 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5424 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5425 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5426 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5427 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5428 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5429 | } |
| 5430 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5431 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5432 | // The entrypoint the code generator is going to call does not do |
| 5433 | // clinit of the class. |
| 5434 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5435 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5436 | } |
| 5437 | |
| 5438 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5439 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5440 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5441 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5442 | } |
| 5443 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5444 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5445 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5446 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5447 | } |
| 5448 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5449 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5450 | return loaded_class_rti_; |
| 5451 | } |
| 5452 | |
| 5453 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5454 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5455 | DCHECK(rti.IsExact()); |
| 5456 | loaded_class_rti_ = rti; |
| 5457 | } |
| 5458 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5459 | const DexFile& GetDexFile() { return dex_file_; } |
| 5460 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5461 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5462 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5463 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5464 | return SideEffects::CanTriggerGC(); |
| 5465 | } |
| 5466 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5467 | bool IsReferrersClass() const { return GetPackedFlag<kFlagIsReferrersClass>(); } |
| 5468 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5469 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5470 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5471 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5472 | DECLARE_INSTRUCTION(LoadClass); |
| 5473 | |
| 5474 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5475 | static constexpr size_t kFlagIsReferrersClass = kNumberOfExpressionPackedBits; |
| 5476 | static constexpr size_t kFlagNeedsAccessCheck = kFlagIsReferrersClass + 1; |
| 5477 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5478 | // Whether this instruction must generate the initialization check. |
| 5479 | // Used for code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5480 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInDexCache + 1; |
| 5481 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagGenerateClInitCheck + 1; |
| 5482 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5483 | |
| 5484 | const uint16_t type_index_; |
| 5485 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5486 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5487 | ReferenceTypeInfo loaded_class_rti_; |
| 5488 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5489 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5490 | }; |
| 5491 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5492 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5493 | public: |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5494 | HLoadString(HCurrentMethod* current_method, |
| 5495 | uint32_t string_index, |
| 5496 | uint32_t dex_pc, |
| 5497 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5498 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5499 | string_index_(string_index) { |
| 5500 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5501 | SetRawInputAt(0, current_method); |
| 5502 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5503 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5504 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5505 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5506 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5507 | return other->AsLoadString()->string_index_ == string_index_; |
| 5508 | } |
| 5509 | |
| 5510 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5511 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5512 | uint32_t GetStringIndex() const { return string_index_; } |
| 5513 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5514 | // Will call the runtime if the string is not already in the dex cache. |
| 5515 | bool NeedsEnvironment() const OVERRIDE { return !IsInDexCache(); } |
| 5516 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5517 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5518 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5519 | bool CanThrow() const OVERRIDE { return !IsInDexCache(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5520 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5521 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5522 | return SideEffects::CanTriggerGC(); |
| 5523 | } |
| 5524 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5525 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5526 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5527 | DECLARE_INSTRUCTION(LoadString); |
| 5528 | |
| 5529 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5530 | static constexpr size_t kFlagIsInDexCache = kNumberOfExpressionPackedBits; |
| 5531 | static constexpr size_t kNumberOfLoadStringPackedBits = kFlagIsInDexCache + 1; |
| 5532 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5533 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5534 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5535 | |
| 5536 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5537 | }; |
| 5538 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5539 | /** |
| 5540 | * Performs an initialization check on its Class object input. |
| 5541 | */ |
| 5542 | class HClinitCheck : public HExpression<1> { |
| 5543 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5544 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5545 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5546 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5547 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5548 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5549 | SetRawInputAt(0, constant); |
| 5550 | } |
| 5551 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5552 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5553 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5554 | return true; |
| 5555 | } |
| 5556 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5557 | bool NeedsEnvironment() const OVERRIDE { |
| 5558 | // May call runtime to initialize the class. |
| 5559 | return true; |
| 5560 | } |
| 5561 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5562 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5563 | |
| 5564 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5565 | |
| 5566 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5567 | |
| 5568 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5569 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5570 | }; |
| 5571 | |
| 5572 | class HStaticFieldGet : public HExpression<1> { |
| 5573 | public: |
| 5574 | HStaticFieldGet(HInstruction* cls, |
| 5575 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5576 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5577 | bool is_volatile, |
| 5578 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5579 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5580 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5581 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5582 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5583 | : HExpression(field_type, |
| 5584 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5585 | dex_pc), |
| 5586 | field_info_(field_offset, |
| 5587 | field_type, |
| 5588 | is_volatile, |
| 5589 | field_idx, |
| 5590 | declaring_class_def_index, |
| 5591 | dex_file, |
| 5592 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5593 | SetRawInputAt(0, cls); |
| 5594 | } |
| 5595 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5596 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5597 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5598 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5599 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5600 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5601 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | size_t ComputeHashCode() const OVERRIDE { |
| 5605 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5606 | } |
| 5607 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5608 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5609 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5610 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5611 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5612 | |
| 5613 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5614 | |
| 5615 | private: |
| 5616 | const FieldInfo field_info_; |
| 5617 | |
| 5618 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5619 | }; |
| 5620 | |
| 5621 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5622 | public: |
| 5623 | HStaticFieldSet(HInstruction* cls, |
| 5624 | HInstruction* value, |
| 5625 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5626 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5627 | bool is_volatile, |
| 5628 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5629 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5630 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5631 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5632 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5633 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5634 | dex_pc), |
| 5635 | field_info_(field_offset, |
| 5636 | field_type, |
| 5637 | is_volatile, |
| 5638 | field_idx, |
| 5639 | declaring_class_def_index, |
| 5640 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5641 | dex_cache) { |
| 5642 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5643 | SetRawInputAt(0, cls); |
| 5644 | SetRawInputAt(1, value); |
| 5645 | } |
| 5646 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5647 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5648 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5649 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5650 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5651 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5652 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5653 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5654 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5655 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5656 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5657 | |
| 5658 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5659 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5660 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5661 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5662 | "Too many packed fields."); |
| 5663 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5664 | const FieldInfo field_info_; |
| 5665 | |
| 5666 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5667 | }; |
| 5668 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5669 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5670 | public: |
| 5671 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5672 | Primitive::Type field_type, |
| 5673 | uint32_t field_index, |
| 5674 | uint32_t dex_pc) |
| 5675 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5676 | field_index_(field_index) { |
| 5677 | SetRawInputAt(0, obj); |
| 5678 | } |
| 5679 | |
| 5680 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5681 | bool CanThrow() const OVERRIDE { return true; } |
| 5682 | |
| 5683 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5684 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5685 | |
| 5686 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5687 | |
| 5688 | private: |
| 5689 | const uint32_t field_index_; |
| 5690 | |
| 5691 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5692 | }; |
| 5693 | |
| 5694 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5695 | public: |
| 5696 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5697 | HInstruction* value, |
| 5698 | Primitive::Type field_type, |
| 5699 | uint32_t field_index, |
| 5700 | uint32_t dex_pc) |
| 5701 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5702 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5703 | SetPackedField<FieldTypeField>(field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5704 | DCHECK_EQ(field_type, value->GetType()); |
| 5705 | SetRawInputAt(0, obj); |
| 5706 | SetRawInputAt(1, value); |
| 5707 | } |
| 5708 | |
| 5709 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5710 | bool CanThrow() const OVERRIDE { return true; } |
| 5711 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5712 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5713 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5714 | |
| 5715 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5716 | |
| 5717 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5718 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5719 | static constexpr size_t kFieldFieldTypeSize = |
| 5720 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5721 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5722 | kFieldFieldType + kFieldFieldTypeSize; |
| 5723 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5724 | "Too many packed fields."); |
| 5725 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5726 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5727 | const uint32_t field_index_; |
| 5728 | |
| 5729 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5730 | }; |
| 5731 | |
| 5732 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5733 | public: |
| 5734 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5735 | uint32_t field_index, |
| 5736 | uint32_t dex_pc) |
| 5737 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5738 | field_index_(field_index) { |
| 5739 | } |
| 5740 | |
| 5741 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5742 | bool CanThrow() const OVERRIDE { return true; } |
| 5743 | |
| 5744 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5745 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5746 | |
| 5747 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5748 | |
| 5749 | private: |
| 5750 | const uint32_t field_index_; |
| 5751 | |
| 5752 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5753 | }; |
| 5754 | |
| 5755 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5756 | public: |
| 5757 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5758 | Primitive::Type field_type, |
| 5759 | uint32_t field_index, |
| 5760 | uint32_t dex_pc) |
| 5761 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5762 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5763 | SetPackedField<FieldTypeField>(field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5764 | DCHECK_EQ(field_type, value->GetType()); |
| 5765 | SetRawInputAt(0, value); |
| 5766 | } |
| 5767 | |
| 5768 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5769 | bool CanThrow() const OVERRIDE { return true; } |
| 5770 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5771 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5772 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5773 | |
| 5774 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5775 | |
| 5776 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5777 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5778 | static constexpr size_t kFieldFieldTypeSize = |
| 5779 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5780 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5781 | kFieldFieldType + kFieldFieldTypeSize; |
| 5782 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5783 | "Too many packed fields."); |
| 5784 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5785 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5786 | const uint32_t field_index_; |
| 5787 | |
| 5788 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5789 | }; |
| 5790 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5791 | // Implement the move-exception DEX instruction. |
| 5792 | class HLoadException : public HExpression<0> { |
| 5793 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5794 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5795 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5796 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5797 | bool CanBeNull() const OVERRIDE { return false; } |
| 5798 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5799 | DECLARE_INSTRUCTION(LoadException); |
| 5800 | |
| 5801 | private: |
| 5802 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5803 | }; |
| 5804 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5805 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5806 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5807 | class HClearException : public HTemplateInstruction<0> { |
| 5808 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5809 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5810 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5811 | |
| 5812 | DECLARE_INSTRUCTION(ClearException); |
| 5813 | |
| 5814 | private: |
| 5815 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5816 | }; |
| 5817 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5818 | class HThrow : public HTemplateInstruction<1> { |
| 5819 | public: |
| 5820 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5821 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5822 | SetRawInputAt(0, exception); |
| 5823 | } |
| 5824 | |
| 5825 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5826 | |
| 5827 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5828 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5829 | bool CanThrow() const OVERRIDE { return true; } |
| 5830 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5831 | |
| 5832 | DECLARE_INSTRUCTION(Throw); |
| 5833 | |
| 5834 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5835 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5836 | }; |
| 5837 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5838 | /** |
| 5839 | * Implementation strategies for the code generator of a HInstanceOf |
| 5840 | * or `HCheckCast`. |
| 5841 | */ |
| 5842 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5843 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5844 | kExactCheck, // Can do a single class compare. |
| 5845 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5846 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5847 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5848 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5849 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 5850 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5851 | }; |
| 5852 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5853 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 5854 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5855 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5856 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5857 | HInstanceOf(HInstruction* object, |
| 5858 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5859 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5860 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5861 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5862 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5863 | dex_pc) { |
| 5864 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5865 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5866 | SetRawInputAt(0, object); |
| 5867 | SetRawInputAt(1, constant); |
| 5868 | } |
| 5869 | |
| 5870 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5871 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5872 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5873 | return true; |
| 5874 | } |
| 5875 | |
| 5876 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5877 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5878 | } |
| 5879 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5880 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5881 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 5882 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 5883 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 5884 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5885 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5886 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 5887 | // Mips currently does runtime calls for any other checks. |
| 5888 | return check_kind != TypeCheckKind::kExactCheck; |
| 5889 | } |
| 5890 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5891 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5892 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5893 | } |
| 5894 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5895 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5896 | |
| 5897 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5898 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 5899 | static constexpr size_t kFieldTypeCheckKindSize = |
| 5900 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 5901 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 5902 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 5903 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5904 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5905 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5906 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5907 | }; |
| 5908 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5909 | class HBoundType : public HExpression<1> { |
| 5910 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5911 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5912 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5913 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 5914 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 5915 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5916 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5917 | SetRawInputAt(0, input); |
| 5918 | } |
| 5919 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5920 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5921 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5922 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5923 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5924 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5925 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5926 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 5927 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5928 | } |
| 5929 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5930 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5931 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5932 | DECLARE_INSTRUCTION(BoundType); |
| 5933 | |
| 5934 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5935 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5936 | // is false then CanBeNull() cannot be true). |
| 5937 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 5938 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 5939 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 5940 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5941 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5942 | // 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] | 5943 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5944 | // It is used to bound the type in cases like: |
| 5945 | // if (x instanceof ClassX) { |
| 5946 | // // uper_bound_ will be ClassX |
| 5947 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5948 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5949 | |
| 5950 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5951 | }; |
| 5952 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5953 | class HCheckCast : public HTemplateInstruction<2> { |
| 5954 | public: |
| 5955 | HCheckCast(HInstruction* object, |
| 5956 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5957 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5958 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5959 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 5960 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5961 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5962 | SetRawInputAt(0, object); |
| 5963 | SetRawInputAt(1, constant); |
| 5964 | } |
| 5965 | |
| 5966 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5967 | |
| 5968 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5969 | return true; |
| 5970 | } |
| 5971 | |
| 5972 | bool NeedsEnvironment() const OVERRIDE { |
| 5973 | // Instruction may throw a CheckCastError. |
| 5974 | return true; |
| 5975 | } |
| 5976 | |
| 5977 | bool CanThrow() const OVERRIDE { return true; } |
| 5978 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5979 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 5980 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 5981 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 5982 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5983 | |
| 5984 | DECLARE_INSTRUCTION(CheckCast); |
| 5985 | |
| 5986 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5987 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 5988 | static constexpr size_t kFieldTypeCheckKindSize = |
| 5989 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 5990 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 5991 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 5992 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5993 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5994 | |
| 5995 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5996 | }; |
| 5997 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5998 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5999 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6000 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6001 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6002 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6003 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6004 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6005 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6006 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6007 | |
| 6008 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6009 | |
| 6010 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6011 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6012 | static constexpr size_t kFieldBarrierKindSize = |
| 6013 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6014 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6015 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6016 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6017 | "Too many packed fields."); |
| 6018 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6019 | |
| 6020 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6021 | }; |
| 6022 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6023 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 6024 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6025 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6026 | kEnter, |
| 6027 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6028 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6029 | }; |
| 6030 | |
| 6031 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6032 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6033 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6034 | dex_pc) { |
| 6035 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6036 | SetRawInputAt(0, object); |
| 6037 | } |
| 6038 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6039 | // Instruction may go into runtime, so we need an environment. |
| 6040 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6041 | |
| 6042 | bool CanThrow() const OVERRIDE { |
| 6043 | // Verifier guarantees that monitor-exit cannot throw. |
| 6044 | // This is important because it allows the HGraphBuilder to remove |
| 6045 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6046 | return IsEnter(); |
| 6047 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6048 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6049 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6050 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6051 | |
| 6052 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6053 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6054 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6055 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6056 | static constexpr size_t kFieldOperationKindSize = |
| 6057 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6058 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6059 | kFieldOperationKind + kFieldOperationKindSize; |
| 6060 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6061 | "Too many packed fields."); |
| 6062 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6063 | |
| 6064 | private: |
| 6065 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6066 | }; |
| 6067 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6068 | class HSelect : public HExpression<3> { |
| 6069 | public: |
| 6070 | HSelect(HInstruction* condition, |
| 6071 | HInstruction* true_value, |
| 6072 | HInstruction* false_value, |
| 6073 | uint32_t dex_pc) |
| 6074 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6075 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6076 | |
| 6077 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6078 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6079 | // that architectures which implement HSelect as a conditional move also |
| 6080 | // will not need to invert the condition. |
| 6081 | SetRawInputAt(0, false_value); |
| 6082 | SetRawInputAt(1, true_value); |
| 6083 | SetRawInputAt(2, condition); |
| 6084 | } |
| 6085 | |
| 6086 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6087 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6088 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6089 | |
| 6090 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6091 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
| 6092 | |
| 6093 | bool CanBeNull() const OVERRIDE { |
| 6094 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6095 | } |
| 6096 | |
| 6097 | DECLARE_INSTRUCTION(Select); |
| 6098 | |
| 6099 | private: |
| 6100 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6101 | }; |
| 6102 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6103 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6104 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6105 | MoveOperands(Location source, |
| 6106 | Location destination, |
| 6107 | Primitive::Type type, |
| 6108 | HInstruction* instruction) |
| 6109 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6110 | |
| 6111 | Location GetSource() const { return source_; } |
| 6112 | Location GetDestination() const { return destination_; } |
| 6113 | |
| 6114 | void SetSource(Location value) { source_ = value; } |
| 6115 | void SetDestination(Location value) { destination_ = value; } |
| 6116 | |
| 6117 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6118 | // destination (but not the source). |
| 6119 | Location MarkPending() { |
| 6120 | DCHECK(!IsPending()); |
| 6121 | Location dest = destination_; |
| 6122 | destination_ = Location::NoLocation(); |
| 6123 | return dest; |
| 6124 | } |
| 6125 | |
| 6126 | void ClearPending(Location dest) { |
| 6127 | DCHECK(IsPending()); |
| 6128 | destination_ = dest; |
| 6129 | } |
| 6130 | |
| 6131 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6132 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6133 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6134 | } |
| 6135 | |
| 6136 | // True if this blocks a move from the given location. |
| 6137 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6138 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6139 | } |
| 6140 | |
| 6141 | // A move is redundant if it's been eliminated, if its source and |
| 6142 | // destination are the same, or if its destination is unneeded. |
| 6143 | bool IsRedundant() const { |
| 6144 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6145 | } |
| 6146 | |
| 6147 | // We clear both operands to indicate move that's been eliminated. |
| 6148 | void Eliminate() { |
| 6149 | source_ = destination_ = Location::NoLocation(); |
| 6150 | } |
| 6151 | |
| 6152 | bool IsEliminated() const { |
| 6153 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6154 | return source_.IsInvalid(); |
| 6155 | } |
| 6156 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6157 | Primitive::Type GetType() const { return type_; } |
| 6158 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6159 | bool Is64BitMove() const { |
| 6160 | return Primitive::Is64BitType(type_); |
| 6161 | } |
| 6162 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6163 | HInstruction* GetInstruction() const { return instruction_; } |
| 6164 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6165 | private: |
| 6166 | Location source_; |
| 6167 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6168 | // The type this move is for. |
| 6169 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6170 | // The instruction this move is assocatied with. Null when this move is |
| 6171 | // for moving an input in the expected locations of user (including a phi user). |
| 6172 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6173 | // in the same parallel move. |
| 6174 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6175 | }; |
| 6176 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6177 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6178 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6179 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6180 | |
| 6181 | class HParallelMove : public HTemplateInstruction<0> { |
| 6182 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6183 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6184 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6185 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6186 | moves_.reserve(kDefaultNumberOfMoves); |
| 6187 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6188 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6189 | void AddMove(Location source, |
| 6190 | Location destination, |
| 6191 | Primitive::Type type, |
| 6192 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6193 | DCHECK(source.IsValid()); |
| 6194 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6195 | if (kIsDebugBuild) { |
| 6196 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6197 | for (const MoveOperands& move : moves_) { |
| 6198 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6199 | // Special case the situation where the move is for the spill slot |
| 6200 | // of the instruction. |
| 6201 | if ((GetPrevious() == instruction) |
| 6202 | || ((GetPrevious() == nullptr) |
| 6203 | && instruction->IsPhi() |
| 6204 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6205 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6206 | << "Doing parallel moves for the same instruction."; |
| 6207 | } else { |
| 6208 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6209 | } |
| 6210 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6211 | } |
| 6212 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6213 | for (const MoveOperands& move : moves_) { |
| 6214 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6215 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6216 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6217 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6218 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6219 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6220 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6221 | } |
| 6222 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6223 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6224 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6225 | } |
| 6226 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6227 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6228 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6229 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6230 | |
| 6231 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6232 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6233 | |
| 6234 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6235 | }; |
| 6236 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6237 | } // namespace art |
| 6238 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6239 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6240 | #include "nodes_shared.h" |
| 6241 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6242 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6243 | #include "nodes_arm.h" |
| 6244 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6245 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6246 | #include "nodes_arm64.h" |
| 6247 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6248 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6249 | #include "nodes_x86.h" |
| 6250 | #endif |
| 6251 | |
| 6252 | namespace art { |
| 6253 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6254 | class HGraphVisitor : public ValueObject { |
| 6255 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6256 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6257 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6258 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6259 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6260 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6261 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6262 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6263 | void VisitInsertionOrder(); |
| 6264 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6265 | // Visit the graph following dominator tree reverse post-order. |
| 6266 | void VisitReversePostOrder(); |
| 6267 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6268 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6269 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6270 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6271 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6272 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6273 | |
| 6274 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6275 | |
| 6276 | #undef DECLARE_VISIT_INSTRUCTION |
| 6277 | |
| 6278 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6279 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6280 | |
| 6281 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6282 | }; |
| 6283 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6284 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6285 | public: |
| 6286 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6287 | virtual ~HGraphDelegateVisitor() {} |
| 6288 | |
| 6289 | // Visit functions that delegate to to super class. |
| 6290 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6291 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6292 | |
| 6293 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6294 | |
| 6295 | #undef DECLARE_VISIT_INSTRUCTION |
| 6296 | |
| 6297 | private: |
| 6298 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6299 | }; |
| 6300 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6301 | class HInsertionOrderIterator : public ValueObject { |
| 6302 | public: |
| 6303 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6304 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6305 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6306 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6307 | void Advance() { ++index_; } |
| 6308 | |
| 6309 | private: |
| 6310 | const HGraph& graph_; |
| 6311 | size_t index_; |
| 6312 | |
| 6313 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6314 | }; |
| 6315 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6316 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6317 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6318 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6319 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6320 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6321 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6322 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6323 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6324 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6325 | void Advance() { ++index_; } |
| 6326 | |
| 6327 | private: |
| 6328 | const HGraph& graph_; |
| 6329 | size_t index_; |
| 6330 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6331 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6332 | }; |
| 6333 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6334 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6335 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6336 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6337 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6338 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6339 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6340 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6341 | |
| 6342 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6343 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6344 | void Advance() { --index_; } |
| 6345 | |
| 6346 | private: |
| 6347 | const HGraph& graph_; |
| 6348 | size_t index_; |
| 6349 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6350 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6351 | }; |
| 6352 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6353 | class HLinearPostOrderIterator : public ValueObject { |
| 6354 | public: |
| 6355 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6356 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6357 | |
| 6358 | bool Done() const { return index_ == 0; } |
| 6359 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6360 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6361 | |
| 6362 | void Advance() { |
| 6363 | --index_; |
| 6364 | DCHECK_GE(index_, 0U); |
| 6365 | } |
| 6366 | |
| 6367 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6368 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6369 | size_t index_; |
| 6370 | |
| 6371 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 6372 | }; |
| 6373 | |
| 6374 | class HLinearOrderIterator : public ValueObject { |
| 6375 | public: |
| 6376 | explicit HLinearOrderIterator(const HGraph& graph) |
| 6377 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 6378 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6379 | bool Done() const { return index_ == order_.size(); } |
| 6380 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6381 | void Advance() { ++index_; } |
| 6382 | |
| 6383 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6384 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6385 | size_t index_; |
| 6386 | |
| 6387 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 6388 | }; |
| 6389 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6390 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6391 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6392 | // block id. |
| 6393 | class HBlocksInLoopIterator : public ValueObject { |
| 6394 | public: |
| 6395 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6396 | : blocks_in_loop_(info.GetBlocks()), |
| 6397 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6398 | index_(0) { |
| 6399 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6400 | Advance(); |
| 6401 | } |
| 6402 | } |
| 6403 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6404 | bool Done() const { return index_ == blocks_.size(); } |
| 6405 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6406 | void Advance() { |
| 6407 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6408 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6409 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6410 | break; |
| 6411 | } |
| 6412 | } |
| 6413 | } |
| 6414 | |
| 6415 | private: |
| 6416 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6417 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6418 | size_t index_; |
| 6419 | |
| 6420 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6421 | }; |
| 6422 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6423 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6424 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6425 | // post order. |
| 6426 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6427 | public: |
| 6428 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6429 | : blocks_in_loop_(info.GetBlocks()), |
| 6430 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6431 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6432 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6433 | Advance(); |
| 6434 | } |
| 6435 | } |
| 6436 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6437 | bool Done() const { return index_ == blocks_.size(); } |
| 6438 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6439 | void Advance() { |
| 6440 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6441 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6442 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6443 | break; |
| 6444 | } |
| 6445 | } |
| 6446 | } |
| 6447 | |
| 6448 | private: |
| 6449 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6450 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6451 | size_t index_; |
| 6452 | |
| 6453 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6454 | }; |
| 6455 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6456 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6457 | if (constant->IsIntConstant()) { |
| 6458 | return constant->AsIntConstant()->GetValue(); |
| 6459 | } else if (constant->IsLongConstant()) { |
| 6460 | return constant->AsLongConstant()->GetValue(); |
| 6461 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6462 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6463 | return 0; |
| 6464 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6465 | } |
| 6466 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6467 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6468 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6469 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6470 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6471 | // times and provide different class resolution but no two class loaders should ever |
| 6472 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6473 | // all sorts of weird failures. |
| 6474 | return &lhs == &rhs; |
| 6475 | } |
| 6476 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6477 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6478 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6479 | inline const H##type* HInstruction::As##type() const { \ |
| 6480 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6481 | } \ |
| 6482 | inline H##type* HInstruction::As##type() { \ |
| 6483 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6484 | } |
| 6485 | |
| 6486 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6487 | #undef INSTRUCTION_TYPE_CHECK |
| 6488 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 6489 | class SwitchTable : public ValueObject { |
| 6490 | public: |
| 6491 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 6492 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 6493 | int32_t table_offset = instruction.VRegB_31t(); |
| 6494 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 6495 | if (sparse) { |
| 6496 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 6497 | } else { |
| 6498 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 6499 | } |
| 6500 | num_entries_ = table[1]; |
| 6501 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 6502 | } |
| 6503 | |
| 6504 | uint16_t GetNumEntries() const { |
| 6505 | return num_entries_; |
| 6506 | } |
| 6507 | |
| 6508 | void CheckIndex(size_t index) const { |
| 6509 | if (sparse_) { |
| 6510 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6511 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 6512 | } else { |
| 6513 | // In a packed table, we have the starting key and num_entries_ values. |
| 6514 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 6515 | } |
| 6516 | } |
| 6517 | |
| 6518 | int32_t GetEntryAt(size_t index) const { |
| 6519 | CheckIndex(index); |
| 6520 | return values_[index]; |
| 6521 | } |
| 6522 | |
| 6523 | uint32_t GetDexPcForIndex(size_t index) const { |
| 6524 | CheckIndex(index); |
| 6525 | return dex_pc_ + |
| 6526 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 6527 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 6528 | } |
| 6529 | |
| 6530 | // Index of the first value in the table. |
| 6531 | size_t GetFirstValueIndex() const { |
| 6532 | if (sparse_) { |
| 6533 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6534 | return num_entries_; |
| 6535 | } else { |
| 6536 | // In a packed table, we have the starting key and num_entries_ values. |
| 6537 | return 1; |
| 6538 | } |
| 6539 | } |
| 6540 | |
| 6541 | private: |
| 6542 | const Instruction& instruction_; |
| 6543 | const uint32_t dex_pc_; |
| 6544 | |
| 6545 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 6546 | const bool sparse_; |
| 6547 | |
| 6548 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 6549 | // expressions in the initializer list seemed very ugly. |
| 6550 | uint16_t num_entries_; |
| 6551 | |
| 6552 | const int32_t* values_; |
| 6553 | |
| 6554 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 6555 | }; |
| 6556 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6557 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6558 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6559 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6560 | size_t number_of_new_blocks, |
| 6561 | size_t after) { |
| 6562 | DCHECK_LT(after, blocks->size()); |
| 6563 | size_t old_size = blocks->size(); |
| 6564 | size_t new_size = old_size + number_of_new_blocks; |
| 6565 | blocks->resize(new_size); |
| 6566 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6567 | } |
| 6568 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6569 | } // namespace art |
| 6570 | |
| 6571 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |