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 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 356 | // Need to add a couple of blocks to test if the loop body is entered and |
| 357 | // put deoptimization instructions, etc. |
| 358 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 359 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 360 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 361 | // other blocks and has no instructions or phis. |
| 362 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 363 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 364 | // Splits the edge between `block` and `successor` while preserving the |
| 365 | // indices in the predecessor/successor lists. If there are multiple edges |
| 366 | // between the blocks, the lowest indices are used. |
| 367 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 368 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 369 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 370 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 371 | void SimplifyLoop(HBasicBlock* header); |
| 372 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 373 | int32_t GetNextInstructionId() { |
| 374 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 375 | return current_instruction_id_++; |
| 376 | } |
| 377 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 378 | int32_t GetCurrentInstructionId() const { |
| 379 | return current_instruction_id_; |
| 380 | } |
| 381 | |
| 382 | void SetCurrentInstructionId(int32_t id) { |
| 383 | current_instruction_id_ = id; |
| 384 | } |
| 385 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 386 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 387 | return maximum_number_of_out_vregs_; |
| 388 | } |
| 389 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 390 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 391 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 394 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 395 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 396 | } |
| 397 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 398 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 399 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 402 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 403 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 404 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 407 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 408 | number_of_vregs_ = number_of_vregs; |
| 409 | } |
| 410 | |
| 411 | uint16_t GetNumberOfVRegs() const { |
| 412 | return number_of_vregs_; |
| 413 | } |
| 414 | |
| 415 | void SetNumberOfInVRegs(uint16_t value) { |
| 416 | number_of_in_vregs_ = value; |
| 417 | } |
| 418 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 419 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 420 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 421 | return number_of_vregs_ - number_of_in_vregs_; |
| 422 | } |
| 423 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 424 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 425 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 426 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 427 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 428 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 429 | return linear_order_; |
| 430 | } |
| 431 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 432 | bool HasBoundsChecks() const { |
| 433 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 436 | void SetHasBoundsChecks(bool value) { |
| 437 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 438 | } |
| 439 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 440 | bool ShouldGenerateConstructorBarrier() const { |
| 441 | return should_generate_constructor_barrier_; |
| 442 | } |
| 443 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 444 | bool IsDebuggable() const { return debuggable_; } |
| 445 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 446 | // 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] | 447 | // already, it is created and inserted into the graph. This method is only for |
| 448 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 449 | 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] | 450 | |
| 451 | // TODO: This is problematic for the consistency of reference type propagation |
| 452 | // because it can be created anytime after the pass and thus it will be left |
| 453 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 454 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 455 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 456 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 457 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 458 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 459 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 460 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 461 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 462 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 463 | 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] | 464 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 465 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 466 | 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] | 467 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 468 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 469 | HCurrentMethod* GetCurrentMethod(); |
| 470 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 471 | const DexFile& GetDexFile() const { |
| 472 | return dex_file_; |
| 473 | } |
| 474 | |
| 475 | uint32_t GetMethodIdx() const { |
| 476 | return method_idx_; |
| 477 | } |
| 478 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 479 | InvokeType GetInvokeType() const { |
| 480 | return invoke_type_; |
| 481 | } |
| 482 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 483 | InstructionSet GetInstructionSet() const { |
| 484 | return instruction_set_; |
| 485 | } |
| 486 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 487 | bool IsCompilingOsr() const { return osr_; } |
| 488 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 489 | bool HasTryCatch() const { return has_try_catch_; } |
| 490 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 491 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 492 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 493 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 494 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 495 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 496 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 497 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 498 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 499 | // The instruction has been inserted into the graph, either as a constant, or |
| 500 | // before cursor. |
| 501 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 502 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 503 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 504 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 505 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 506 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 507 | template <class InstructionType, typename ValueType> |
| 508 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 509 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 510 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 511 | // Try to find an existing constant of the given value. |
| 512 | InstructionType* constant = nullptr; |
| 513 | auto cached_constant = cache->find(value); |
| 514 | if (cached_constant != cache->end()) { |
| 515 | constant = cached_constant->second; |
| 516 | } |
| 517 | |
| 518 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 519 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 520 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 521 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 522 | cache->Overwrite(value, constant); |
| 523 | InsertConstant(constant); |
| 524 | } |
| 525 | return constant; |
| 526 | } |
| 527 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 528 | void InsertConstant(HConstant* instruction); |
| 529 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 530 | // Cache a float constant into the graph. This method should only be |
| 531 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 532 | void CacheFloatConstant(HFloatConstant* constant); |
| 533 | |
| 534 | // See CacheFloatConstant comment. |
| 535 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 536 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 537 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 538 | |
| 539 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 540 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 541 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 542 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 543 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 544 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 545 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 546 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 547 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 548 | HBasicBlock* entry_block_; |
| 549 | HBasicBlock* exit_block_; |
| 550 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 551 | // 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] | 552 | uint16_t maximum_number_of_out_vregs_; |
| 553 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 554 | // The number of virtual registers in this method. Contains the parameters. |
| 555 | uint16_t number_of_vregs_; |
| 556 | |
| 557 | // The number of virtual registers used by parameters of this method. |
| 558 | uint16_t number_of_in_vregs_; |
| 559 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 560 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 561 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 562 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 563 | // Has bounds checks. We can totally skip BCE if it's false. |
| 564 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 565 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 566 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 567 | // try/catch-related passes if false. |
| 568 | bool has_try_catch_; |
| 569 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 570 | // Flag whether there are any irreducible loops in the graph. |
| 571 | bool has_irreducible_loops_; |
| 572 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 573 | // Indicates whether the graph should be compiled in a way that |
| 574 | // ensures full debuggability. If false, we can apply more |
| 575 | // aggressive optimizations that may limit the level of debugging. |
| 576 | const bool debuggable_; |
| 577 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 578 | // 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] | 579 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 580 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 581 | // The dex file from which the method is from. |
| 582 | const DexFile& dex_file_; |
| 583 | |
| 584 | // The method index in the dex file. |
| 585 | const uint32_t method_idx_; |
| 586 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 587 | // If inlined, this encodes how the callee is being invoked. |
| 588 | const InvokeType invoke_type_; |
| 589 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 590 | // Whether the graph has been transformed to SSA form. Only used |
| 591 | // in debug mode to ensure we are not using properties only valid |
| 592 | // for non-SSA form (like the number of temporaries). |
| 593 | bool in_ssa_form_; |
| 594 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 595 | const bool should_generate_constructor_barrier_; |
| 596 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 597 | const InstructionSet instruction_set_; |
| 598 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 599 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 600 | HNullConstant* cached_null_constant_; |
| 601 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 602 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 603 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 604 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 605 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 606 | HCurrentMethod* cached_current_method_; |
| 607 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 608 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 609 | // for example for methods whose declaring class could not be resolved |
| 610 | // (such as when the superclass could not be found). |
| 611 | ArtMethod* art_method_; |
| 612 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 613 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 614 | // collection pointer to passes which may create NullConstant. |
| 615 | ReferenceTypeInfo inexact_object_rti_; |
| 616 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 617 | // Whether we are compiling this graph for on stack replacement: this will |
| 618 | // make all loops seen as irreducible and emit special stack maps to mark |
| 619 | // compiled code entries which the interpreter can directly jump to. |
| 620 | const bool osr_; |
| 621 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 622 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 623 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 624 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 625 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 626 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 627 | }; |
| 628 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 629 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 630 | public: |
| 631 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 632 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 633 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 634 | irreducible_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 635 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 636 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 637 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 638 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 639 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 640 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 641 | bool IsIrreducible() const { return irreducible_; } |
| 642 | |
| 643 | void Dump(std::ostream& os); |
| 644 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 645 | HBasicBlock* GetHeader() const { |
| 646 | return header_; |
| 647 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 648 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 649 | void SetHeader(HBasicBlock* block) { |
| 650 | header_ = block; |
| 651 | } |
| 652 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 653 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 654 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 655 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 656 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 657 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 658 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 661 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 662 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 663 | } |
| 664 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 665 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 666 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 667 | } |
| 668 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 669 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 670 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 673 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 674 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 675 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 676 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 679 | // Returns the lifetime position of the back edge that has the |
| 680 | // greatest lifetime position. |
| 681 | size_t GetLifetimeEnd() const; |
| 682 | |
| 683 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 684 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 685 | } |
| 686 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 687 | // Finds blocks that are part of this loop. |
| 688 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 689 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 690 | // Returns whether this loop information contains `block`. |
| 691 | // Note that this loop information *must* be populated before entering this function. |
| 692 | bool Contains(const HBasicBlock& block) const; |
| 693 | |
| 694 | // Returns whether this loop information is an inner loop of `other`. |
| 695 | // Note that `other` *must* be populated before entering this function. |
| 696 | bool IsIn(const HLoopInformation& other) const; |
| 697 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 698 | // Returns true if instruction is not defined within this loop. |
| 699 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 700 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 701 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 702 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 703 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 704 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 705 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 706 | void ClearAllBlocks() { |
| 707 | blocks_.ClearAllBits(); |
| 708 | } |
| 709 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 710 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 711 | // Internal recursive implementation of `Populate`. |
| 712 | void PopulateRecursive(HBasicBlock* block); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 713 | void PopulateIrreducibleRecursive(HBasicBlock* block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 714 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 715 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 716 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 717 | bool irreducible_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 718 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 719 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 720 | |
| 721 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 722 | }; |
| 723 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 724 | // Stores try/catch information for basic blocks. |
| 725 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 726 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 727 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 728 | public: |
| 729 | // Try block information constructor. |
| 730 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 731 | : try_entry_(&try_entry), |
| 732 | catch_dex_file_(nullptr), |
| 733 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 734 | DCHECK(try_entry_ != nullptr); |
| 735 | } |
| 736 | |
| 737 | // Catch block information constructor. |
| 738 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 739 | : try_entry_(nullptr), |
| 740 | catch_dex_file_(&dex_file), |
| 741 | catch_type_index_(catch_type_index) {} |
| 742 | |
| 743 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 744 | |
| 745 | const HTryBoundary& GetTryEntry() const { |
| 746 | DCHECK(IsTryBlock()); |
| 747 | return *try_entry_; |
| 748 | } |
| 749 | |
| 750 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 751 | |
| 752 | bool IsCatchAllTypeIndex() const { |
| 753 | DCHECK(IsCatchBlock()); |
| 754 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 755 | } |
| 756 | |
| 757 | uint16_t GetCatchTypeIndex() const { |
| 758 | DCHECK(IsCatchBlock()); |
| 759 | return catch_type_index_; |
| 760 | } |
| 761 | |
| 762 | const DexFile& GetCatchDexFile() const { |
| 763 | DCHECK(IsCatchBlock()); |
| 764 | return *catch_dex_file_; |
| 765 | } |
| 766 | |
| 767 | private: |
| 768 | // One of possibly several TryBoundary instructions entering the block's try. |
| 769 | // Only set for try blocks. |
| 770 | const HTryBoundary* try_entry_; |
| 771 | |
| 772 | // Exception type information. Only set for catch blocks. |
| 773 | const DexFile* catch_dex_file_; |
| 774 | const uint16_t catch_type_index_; |
| 775 | }; |
| 776 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 777 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 778 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 779 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 780 | // A block in a method. Contains the list of instructions represented |
| 781 | // as a double linked list. Each block knows its predecessors and |
| 782 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 783 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 784 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 785 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 786 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 787 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 788 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 789 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 790 | loop_information_(nullptr), |
| 791 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 792 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 793 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 794 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 795 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 796 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 797 | try_catch_information_(nullptr) { |
| 798 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 799 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 800 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 801 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 802 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 803 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 804 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 807 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 808 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 809 | } |
| 810 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 811 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 812 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 813 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 814 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 815 | return ContainsElement(successors_, block, start_from); |
| 816 | } |
| 817 | |
| 818 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 819 | return dominated_blocks_; |
| 820 | } |
| 821 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 822 | bool IsEntryBlock() const { |
| 823 | return graph_->GetEntryBlock() == this; |
| 824 | } |
| 825 | |
| 826 | bool IsExitBlock() const { |
| 827 | return graph_->GetExitBlock() == this; |
| 828 | } |
| 829 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 830 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 831 | bool IsSingleTryBoundary() const; |
| 832 | |
| 833 | // Returns true if this block emits nothing but a jump. |
| 834 | bool IsSingleJump() const { |
| 835 | HLoopInformation* loop_info = GetLoopInformation(); |
| 836 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 837 | // Back edges generate a suspend check. |
| 838 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 839 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 840 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 841 | void AddBackEdge(HBasicBlock* back_edge) { |
| 842 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 843 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 844 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 845 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 846 | loop_information_->AddBackEdge(back_edge); |
| 847 | } |
| 848 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 849 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 850 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 851 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 852 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 853 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 854 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 855 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 856 | HBasicBlock* GetDominator() const { return dominator_; } |
| 857 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 858 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 859 | |
| 860 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 861 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 862 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 863 | |
| 864 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 865 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 866 | } |
| 867 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 868 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 869 | |
| 870 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 871 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 872 | } |
| 873 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 874 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 875 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 876 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 877 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 878 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 879 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 880 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 881 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 882 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 883 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 884 | successors_.push_back(block); |
| 885 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 886 | } |
| 887 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 888 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 889 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 890 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 891 | new_block->predecessors_.push_back(this); |
| 892 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 895 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 896 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 897 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 898 | new_block->successors_.push_back(this); |
| 899 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 902 | // Insert `this` between `predecessor` and `successor. This method |
| 903 | // preserves the indicies, and will update the first edge found between |
| 904 | // `predecessor` and `successor`. |
| 905 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 906 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 907 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 908 | successor->predecessors_[predecessor_index] = this; |
| 909 | predecessor->successors_[successor_index] = this; |
| 910 | successors_.push_back(successor); |
| 911 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 912 | } |
| 913 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 914 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 915 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 916 | } |
| 917 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 918 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 919 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 922 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 923 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 927 | predecessors_.push_back(block); |
| 928 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 929 | } |
| 930 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 931 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 932 | DCHECK_EQ(predecessors_.size(), 2u); |
| 933 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 934 | } |
| 935 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 936 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 937 | DCHECK_EQ(successors_.size(), 2u); |
| 938 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 939 | } |
| 940 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 941 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 942 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 943 | } |
| 944 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 945 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 946 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 947 | } |
| 948 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 949 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 950 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 951 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 955 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 956 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | // Returns whether the first occurrence of `predecessor` in the list of |
| 960 | // predecessors is at index `idx`. |
| 961 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 962 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 963 | return GetPredecessorIndexOf(predecessor) == idx; |
| 964 | } |
| 965 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 966 | // Create a new block between this block and its predecessors. The new block |
| 967 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 968 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 969 | // loop and try/catch information are not updated. |
| 970 | HBasicBlock* CreateImmediateDominator(); |
| 971 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 972 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 973 | // created, latter block. Note that this method will add the block to the |
| 974 | // graph, create a Goto at the end of the former block and will create an edge |
| 975 | // 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] | 976 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 977 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 978 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 979 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 980 | // created block. Note that this method just updates raw block information, |
| 981 | // like predecessors, successors, dominators, and instruction list. It does not |
| 982 | // update the graph, reverse post order, loop information, nor make sure the |
| 983 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 984 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 985 | |
| 986 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 987 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 988 | |
David Brazdil | 9bc4361 | 2015-11-05 21:25:24 +0000 | [diff] [blame] | 989 | // Split catch block into two blocks after the original move-exception bytecode |
| 990 | // instruction, or at the beginning if not present. Returns the newly created, |
| 991 | // latter block, or nullptr if such block could not be created (must be dead |
| 992 | // in that case). Note that this method just updates raw block information, |
| 993 | // like predecessors, successors, dominators, and instruction list. It does not |
| 994 | // update the graph, reverse post order, loop information, nor make sure the |
| 995 | // blocks are consistent (for example ending with a control flow instruction). |
| 996 | HBasicBlock* SplitCatchBlockAfterMoveException(); |
| 997 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 998 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 999 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1000 | // that this method does not update the graph, reverse post order, loop |
| 1001 | // information, nor make sure the blocks are consistent (for example ending |
| 1002 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1003 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1004 | |
| 1005 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1006 | // of `this` are moved to `other`. |
| 1007 | // Note that this method does not update the graph, reverse post order, loop |
| 1008 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1009 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1010 | void ReplaceWith(HBasicBlock* other); |
| 1011 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1012 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1013 | // order, links to predecessors, successors, dominators and deletes the block |
| 1014 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1015 | // predecessor of `other` and vice versa. |
| 1016 | void MergeWith(HBasicBlock* other); |
| 1017 | |
| 1018 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1019 | // removes it from all loops it is included in and eventually from the graph. |
| 1020 | // The block must not dominate any other block. Predecessors and successors |
| 1021 | // are safely updated. |
| 1022 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1023 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1024 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1025 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1026 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1027 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1028 | // Replace instruction `initial` with `replacement` within this block. |
| 1029 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1030 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1031 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1032 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1033 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1034 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1035 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1036 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1037 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1038 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1039 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1040 | |
| 1041 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1042 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1043 | } |
| 1044 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1045 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1046 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1047 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1048 | } |
| 1049 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1050 | bool IsFirstPredecessorBackEdge() const { |
| 1051 | DCHECK(IsLoopHeader()); |
| 1052 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1053 | } |
| 1054 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1055 | HLoopInformation* GetLoopInformation() const { |
| 1056 | return loop_information_; |
| 1057 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1058 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1059 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1060 | // 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] | 1061 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1062 | void SetInLoop(HLoopInformation* info) { |
| 1063 | if (IsLoopHeader()) { |
| 1064 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1065 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1066 | loop_information_ = info; |
| 1067 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1068 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1069 | // Note that a non loop header having a loop information means this loop information |
| 1070 | // has already been populated |
| 1071 | loop_information_ = info; |
| 1072 | } else { |
| 1073 | // Block is part of an inner loop. Do not update the loop information. |
| 1074 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1075 | // at this point, because this method is being called while populating `info`. |
| 1076 | } |
| 1077 | } |
| 1078 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1079 | // Raw update of the loop information. |
| 1080 | void SetLoopInformation(HLoopInformation* info) { |
| 1081 | loop_information_ = info; |
| 1082 | } |
| 1083 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1084 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1085 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1086 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1087 | |
| 1088 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1089 | try_catch_information_ = try_catch_information; |
| 1090 | } |
| 1091 | |
| 1092 | bool IsTryBlock() const { |
| 1093 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1094 | } |
| 1095 | |
| 1096 | bool IsCatchBlock() const { |
| 1097 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1098 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1099 | |
| 1100 | // Returns the try entry that this block's successors should have. They will |
| 1101 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1102 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1103 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1104 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1105 | bool HasThrowingInstructions() const; |
| 1106 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1107 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1108 | bool Dominates(HBasicBlock* block) const; |
| 1109 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1110 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1111 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1112 | |
| 1113 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1114 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1115 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1116 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1117 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1118 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1119 | bool HasSinglePhi() const; |
| 1120 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1121 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1122 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1123 | ArenaVector<HBasicBlock*> predecessors_; |
| 1124 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1125 | HInstructionList instructions_; |
| 1126 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1127 | HLoopInformation* loop_information_; |
| 1128 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1129 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1130 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1131 | // The dex program counter of the first instruction of this block. |
| 1132 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1133 | size_t lifetime_start_; |
| 1134 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1135 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1136 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1137 | friend class HGraph; |
| 1138 | friend class HInstruction; |
| 1139 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1140 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1141 | }; |
| 1142 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1143 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1144 | // from the innermost to the outermost. |
| 1145 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1146 | public: |
| 1147 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1148 | : current_(block.GetLoopInformation()) {} |
| 1149 | |
| 1150 | bool Done() const { return current_ == nullptr; } |
| 1151 | |
| 1152 | void Advance() { |
| 1153 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1154 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | HLoopInformation* Current() const { |
| 1158 | DCHECK(!Done()); |
| 1159 | return current_; |
| 1160 | } |
| 1161 | |
| 1162 | private: |
| 1163 | HLoopInformation* current_; |
| 1164 | |
| 1165 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1166 | }; |
| 1167 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1168 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1169 | M(Above, Condition) \ |
| 1170 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1171 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1172 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1173 | M(ArrayGet, Instruction) \ |
| 1174 | M(ArrayLength, Instruction) \ |
| 1175 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1176 | M(Below, Condition) \ |
| 1177 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1178 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1179 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1180 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1181 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1182 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1183 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1184 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1185 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1186 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1187 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1188 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1189 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1190 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1191 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1192 | M(Exit, Instruction) \ |
| 1193 | M(FloatConstant, Constant) \ |
| 1194 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1195 | M(GreaterThan, Condition) \ |
| 1196 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1197 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1198 | M(InstanceFieldGet, Instruction) \ |
| 1199 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1200 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1201 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1202 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1203 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1204 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1205 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1206 | M(LessThan, Condition) \ |
| 1207 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1208 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1209 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1210 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1211 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1212 | M(Local, Instruction) \ |
| 1213 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1214 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1215 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1216 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1217 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1218 | M(Neg, UnaryOperation) \ |
| 1219 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1220 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1221 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1222 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1223 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1224 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1225 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1226 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1227 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1228 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1229 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1230 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1231 | M(Return, Instruction) \ |
| 1232 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1233 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1234 | M(Shl, BinaryOperation) \ |
| 1235 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1236 | M(StaticFieldGet, Instruction) \ |
| 1237 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1238 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1239 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1240 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1241 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1242 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1243 | M(StoreLocal, Instruction) \ |
| 1244 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1245 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1246 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1247 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1248 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1249 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1250 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1251 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1252 | /* |
| 1253 | * Instructions, shared across several (not all) architectures. |
| 1254 | */ |
| 1255 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1256 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1257 | #else |
| 1258 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
| 1259 | M(MultiplyAccumulate, Instruction) |
| 1260 | #endif |
| 1261 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1262 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1263 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1264 | #else |
| 1265 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1266 | M(ArmDexCacheArraysBase, Instruction) |
| 1267 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1268 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1269 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1270 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1271 | #else |
| 1272 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Kevin Brodsky | 9ff0d20 | 2016-01-11 13:43:31 +0000 | [diff] [blame] | 1273 | M(Arm64BitwiseNegatedRight, Instruction) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1274 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1275 | M(Arm64IntermediateAddress, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1276 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1277 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1278 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1279 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1280 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1281 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1282 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1283 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1284 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1285 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1286 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1287 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1288 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1289 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1290 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1291 | |
| 1292 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1293 | |
| 1294 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1295 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1296 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1297 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1298 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1299 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1300 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1301 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1302 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1303 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1304 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1305 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1306 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1307 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1308 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1309 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1310 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1311 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1312 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1313 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1314 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1315 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1316 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1317 | #undef FORWARD_DECLARATION |
| 1318 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1319 | #define DECLARE_INSTRUCTION(type) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1320 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1321 | const char* DebugName() const OVERRIDE { return #type; } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1322 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1323 | return other->Is##type(); \ |
| 1324 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1325 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1326 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1327 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1328 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1329 | const H##type* As##type() const { return this; } \ |
| 1330 | H##type* As##type() { return this; } |
| 1331 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1332 | template <typename T> class HUseList; |
| 1333 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1334 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1335 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1336 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1337 | HUseListNode* GetPrevious() const { return prev_; } |
| 1338 | HUseListNode* GetNext() const { return next_; } |
| 1339 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1340 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1341 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1342 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1343 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1344 | HUseListNode(T user, size_t index) |
| 1345 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1346 | |
| 1347 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1348 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1349 | HUseListNode<T>* prev_; |
| 1350 | HUseListNode<T>* next_; |
| 1351 | |
| 1352 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1353 | |
| 1354 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1355 | }; |
| 1356 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1357 | template <typename T> |
| 1358 | class HUseList : public ValueObject { |
| 1359 | public: |
| 1360 | HUseList() : first_(nullptr) {} |
| 1361 | |
| 1362 | void Clear() { |
| 1363 | first_ = nullptr; |
| 1364 | } |
| 1365 | |
| 1366 | // Adds a new entry at the beginning of the use list and returns |
| 1367 | // the newly created node. |
| 1368 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1369 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1370 | if (IsEmpty()) { |
| 1371 | first_ = new_node; |
| 1372 | } else { |
| 1373 | first_->prev_ = new_node; |
| 1374 | new_node->next_ = first_; |
| 1375 | first_ = new_node; |
| 1376 | } |
| 1377 | return new_node; |
| 1378 | } |
| 1379 | |
| 1380 | HUseListNode<T>* GetFirst() const { |
| 1381 | return first_; |
| 1382 | } |
| 1383 | |
| 1384 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1385 | DCHECK(node != nullptr); |
| 1386 | DCHECK(Contains(node)); |
| 1387 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1388 | if (node->prev_ != nullptr) { |
| 1389 | node->prev_->next_ = node->next_; |
| 1390 | } |
| 1391 | if (node->next_ != nullptr) { |
| 1392 | node->next_->prev_ = node->prev_; |
| 1393 | } |
| 1394 | if (node == first_) { |
| 1395 | first_ = node->next_; |
| 1396 | } |
| 1397 | } |
| 1398 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1399 | bool Contains(const HUseListNode<T>* node) const { |
| 1400 | if (node == nullptr) { |
| 1401 | return false; |
| 1402 | } |
| 1403 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1404 | if (current == node) { |
| 1405 | return true; |
| 1406 | } |
| 1407 | } |
| 1408 | return false; |
| 1409 | } |
| 1410 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1411 | bool IsEmpty() const { |
| 1412 | return first_ == nullptr; |
| 1413 | } |
| 1414 | |
| 1415 | bool HasOnlyOneUse() const { |
| 1416 | return first_ != nullptr && first_->next_ == nullptr; |
| 1417 | } |
| 1418 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1419 | size_t SizeSlow() const { |
| 1420 | size_t count = 0; |
| 1421 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1422 | ++count; |
| 1423 | } |
| 1424 | return count; |
| 1425 | } |
| 1426 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1427 | private: |
| 1428 | HUseListNode<T>* first_; |
| 1429 | }; |
| 1430 | |
| 1431 | template<typename T> |
| 1432 | class HUseIterator : public ValueObject { |
| 1433 | public: |
| 1434 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1435 | |
| 1436 | bool Done() const { return current_ == nullptr; } |
| 1437 | |
| 1438 | void Advance() { |
| 1439 | DCHECK(!Done()); |
| 1440 | current_ = current_->GetNext(); |
| 1441 | } |
| 1442 | |
| 1443 | HUseListNode<T>* Current() const { |
| 1444 | DCHECK(!Done()); |
| 1445 | return current_; |
| 1446 | } |
| 1447 | |
| 1448 | private: |
| 1449 | HUseListNode<T>* current_; |
| 1450 | |
| 1451 | friend class HValue; |
| 1452 | }; |
| 1453 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1454 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1455 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1456 | // by the used instructions. |
| 1457 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1458 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1459 | public: |
| 1460 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1461 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1462 | |
| 1463 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1464 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1465 | DCHECK(instruction_ != nullptr); |
| 1466 | DCHECK(use_node_ != nullptr); |
| 1467 | DCHECK(old_record.use_node_ == nullptr); |
| 1468 | } |
| 1469 | |
| 1470 | HInstruction* GetInstruction() const { return instruction_; } |
| 1471 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1472 | |
| 1473 | private: |
| 1474 | // Instruction used by the user. |
| 1475 | HInstruction* instruction_; |
| 1476 | |
| 1477 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1478 | HUseListNode<T>* use_node_; |
| 1479 | }; |
| 1480 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1481 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1482 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1483 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1484 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1485 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1486 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1487 | * modify the value of a reference field read [although it may modify the |
| 1488 | * reference fetch prior to reading the field, which is represented by its own |
| 1489 | * write/read dependence]). The analysis makes conservative points-to |
| 1490 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1491 | * the same, and any reference read depends on any reference read without |
| 1492 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1493 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1494 | * The internal representation uses 38-bit and is described in the table below. |
| 1495 | * The first line indicates the side effect, and for field/array accesses the |
| 1496 | * second line indicates the type of the access (in the order of the |
| 1497 | * Primitive::Type enum). |
| 1498 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1499 | * vertically). |
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 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1502 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1503 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1504 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1505 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1506 | * |
| 1507 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1508 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1509 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1510 | class SideEffects : public ValueObject { |
| 1511 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1512 | SideEffects() : flags_(0) {} |
| 1513 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1514 | static SideEffects None() { |
| 1515 | return SideEffects(0); |
| 1516 | } |
| 1517 | |
| 1518 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1519 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1520 | } |
| 1521 | |
| 1522 | static SideEffects AllChanges() { |
| 1523 | return SideEffects(kAllChangeBits); |
| 1524 | } |
| 1525 | |
| 1526 | static SideEffects AllDependencies() { |
| 1527 | return SideEffects(kAllDependOnBits); |
| 1528 | } |
| 1529 | |
| 1530 | static SideEffects AllExceptGCDependency() { |
| 1531 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1532 | } |
| 1533 | |
| 1534 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1535 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1536 | } |
| 1537 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1538 | static SideEffects AllWrites() { |
| 1539 | return SideEffects(kAllWrites); |
| 1540 | } |
| 1541 | |
| 1542 | static SideEffects AllReads() { |
| 1543 | return SideEffects(kAllReads); |
| 1544 | } |
| 1545 | |
| 1546 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1547 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1548 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1549 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1550 | } |
| 1551 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1552 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1553 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1554 | } |
| 1555 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1556 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1557 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1558 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1559 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1563 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1564 | } |
| 1565 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1566 | static SideEffects CanTriggerGC() { |
| 1567 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1568 | } |
| 1569 | |
| 1570 | static SideEffects DependsOnGC() { |
| 1571 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1572 | } |
| 1573 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1574 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1575 | SideEffects Union(SideEffects other) const { |
| 1576 | return SideEffects(flags_ | other.flags_); |
| 1577 | } |
| 1578 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1579 | SideEffects Exclusion(SideEffects other) const { |
| 1580 | return SideEffects(flags_ & ~other.flags_); |
| 1581 | } |
| 1582 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1583 | void Add(SideEffects other) { |
| 1584 | flags_ |= other.flags_; |
| 1585 | } |
| 1586 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1587 | bool Includes(SideEffects other) const { |
| 1588 | return (other.flags_ & flags_) == other.flags_; |
| 1589 | } |
| 1590 | |
| 1591 | bool HasSideEffects() const { |
| 1592 | return (flags_ & kAllChangeBits); |
| 1593 | } |
| 1594 | |
| 1595 | bool HasDependencies() const { |
| 1596 | return (flags_ & kAllDependOnBits); |
| 1597 | } |
| 1598 | |
| 1599 | // Returns true if there are no side effects or dependencies. |
| 1600 | bool DoesNothing() const { |
| 1601 | return flags_ == 0; |
| 1602 | } |
| 1603 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1604 | // Returns true if something is written. |
| 1605 | bool DoesAnyWrite() const { |
| 1606 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1607 | } |
| 1608 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1609 | // Returns true if something is read. |
| 1610 | bool DoesAnyRead() const { |
| 1611 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1612 | } |
| 1613 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1614 | // Returns true if potentially everything is written and read |
| 1615 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1616 | bool DoesAllReadWrite() const { |
| 1617 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1618 | } |
| 1619 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1620 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1621 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1624 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1625 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1626 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1627 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1631 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1632 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1633 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1634 | for (int s = kLastBit; s >= 0; s--) { |
| 1635 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1636 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1637 | // This is a bit for the GC side effect. |
| 1638 | if (current_bit_is_set) { |
| 1639 | flags += "GC"; |
| 1640 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1641 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1642 | } else { |
| 1643 | // This is a bit for the array/field analysis. |
| 1644 | // The underscore character stands for the 'can trigger GC' bit. |
| 1645 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1646 | if (current_bit_is_set) { |
| 1647 | flags += kDebug[s]; |
| 1648 | } |
| 1649 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1650 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1651 | flags += "|"; |
| 1652 | } |
| 1653 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1654 | } |
| 1655 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1656 | } |
| 1657 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1658 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1659 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1660 | private: |
| 1661 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1662 | |
| 1663 | static constexpr int kFieldWriteOffset = 0; |
| 1664 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1665 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1666 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1667 | |
| 1668 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1669 | |
| 1670 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1671 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1672 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1673 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1674 | |
| 1675 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1676 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1677 | |
| 1678 | // Aliases. |
| 1679 | |
| 1680 | static_assert(kChangeBits == kDependOnBits, |
| 1681 | "the 'change' bits should match the 'depend on' bits."); |
| 1682 | |
| 1683 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1684 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1685 | static constexpr uint64_t kAllWrites = |
| 1686 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1687 | static constexpr uint64_t kAllReads = |
| 1688 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1689 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1690 | // Work around the fact that HIR aliases I/F and J/D. |
| 1691 | // TODO: remove this interceptor once HIR types are clean |
| 1692 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1693 | switch (type) { |
| 1694 | case Primitive::kPrimInt: |
| 1695 | case Primitive::kPrimFloat: |
| 1696 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1697 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1698 | case Primitive::kPrimLong: |
| 1699 | case Primitive::kPrimDouble: |
| 1700 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1701 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1702 | default: |
| 1703 | return TypeFlag(type, offset); |
| 1704 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1705 | } |
| 1706 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1707 | // Translates type to bit flag. |
| 1708 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1709 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1710 | const uint64_t one = 1; |
| 1711 | const int shift = type; // 0-based consecutive enum |
| 1712 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1713 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1714 | return one << (type + offset); |
| 1715 | } |
| 1716 | |
| 1717 | // Private constructor on direct flags value. |
| 1718 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1719 | |
| 1720 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1721 | }; |
| 1722 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1723 | // 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] | 1724 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1725 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1726 | HEnvironment(ArenaAllocator* arena, |
| 1727 | size_t number_of_vregs, |
| 1728 | const DexFile& dex_file, |
| 1729 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1730 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1731 | InvokeType invoke_type, |
| 1732 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1733 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1734 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1735 | parent_(nullptr), |
| 1736 | dex_file_(dex_file), |
| 1737 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1738 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1739 | invoke_type_(invoke_type), |
| 1740 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1741 | } |
| 1742 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1743 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1744 | : HEnvironment(arena, |
| 1745 | to_copy.Size(), |
| 1746 | to_copy.GetDexFile(), |
| 1747 | to_copy.GetMethodIdx(), |
| 1748 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1749 | to_copy.GetInvokeType(), |
| 1750 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1751 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1752 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1753 | if (parent_ != nullptr) { |
| 1754 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1755 | } else { |
| 1756 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1757 | parent_->CopyFrom(parent); |
| 1758 | if (parent->GetParent() != nullptr) { |
| 1759 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1760 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1761 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1762 | } |
| 1763 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1764 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1765 | void CopyFrom(HEnvironment* environment); |
| 1766 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1767 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1768 | // input to the loop phi instead. This is for inserting instructions that |
| 1769 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1770 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1771 | |
| 1772 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1773 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1777 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1780 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1781 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1782 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1783 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1784 | HEnvironment* GetParent() const { return parent_; } |
| 1785 | |
| 1786 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1787 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1791 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | uint32_t GetDexPc() const { |
| 1795 | return dex_pc_; |
| 1796 | } |
| 1797 | |
| 1798 | uint32_t GetMethodIdx() const { |
| 1799 | return method_idx_; |
| 1800 | } |
| 1801 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1802 | InvokeType GetInvokeType() const { |
| 1803 | return invoke_type_; |
| 1804 | } |
| 1805 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1806 | const DexFile& GetDexFile() const { |
| 1807 | return dex_file_; |
| 1808 | } |
| 1809 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1810 | HInstruction* GetHolder() const { |
| 1811 | return holder_; |
| 1812 | } |
| 1813 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1814 | |
| 1815 | bool IsFromInlinedInvoke() const { |
| 1816 | return GetParent() != nullptr; |
| 1817 | } |
| 1818 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1819 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1820 | // Record instructions' use entries of this environment for constant-time removal. |
| 1821 | // It should only be called by HInstruction when a new environment use is added. |
| 1822 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1823 | DCHECK(env_use->GetUser() == this); |
| 1824 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1825 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1826 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1827 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1828 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1829 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1830 | HEnvironment* parent_; |
| 1831 | const DexFile& dex_file_; |
| 1832 | const uint32_t method_idx_; |
| 1833 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1834 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1835 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1836 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1837 | HInstruction* const holder_; |
| 1838 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1839 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1840 | |
| 1841 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1842 | }; |
| 1843 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1844 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1845 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1846 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1847 | : previous_(nullptr), |
| 1848 | next_(nullptr), |
| 1849 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1850 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1851 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1852 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1853 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1854 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1855 | locations_(nullptr), |
| 1856 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1857 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1858 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1859 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1860 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1861 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1862 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1863 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1864 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1865 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1866 | enum InstructionKind { |
| 1867 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1868 | }; |
| 1869 | #undef DECLARE_KIND |
| 1870 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1871 | HInstruction* GetNext() const { return next_; } |
| 1872 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1873 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1874 | HInstruction* GetNextDisregardingMoves() const; |
| 1875 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1876 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1877 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1878 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1879 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1880 | bool IsInBlock() const { return block_ != nullptr; } |
| 1881 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1882 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1883 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1884 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1885 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1886 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1887 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1888 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1889 | |
| 1890 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1891 | virtual const char* DebugName() const = 0; |
| 1892 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1893 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1894 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1895 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1896 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1897 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1898 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1899 | |
| 1900 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1901 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1902 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1903 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1904 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1905 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1906 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1907 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1908 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1909 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1910 | // Does not apply for all instructions, but having this at top level greatly |
| 1911 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1912 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1913 | virtual bool CanBeNull() const { |
| 1914 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1915 | return true; |
| 1916 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1917 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1918 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1919 | return false; |
| 1920 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1921 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1922 | virtual bool IsActualObject() const { |
| 1923 | return GetType() == Primitive::kPrimNot; |
| 1924 | } |
| 1925 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1926 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1927 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1928 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1929 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1930 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
| 1931 | GetPackedFlag<kFlagReferenceTypeIsExact>());; |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1932 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1933 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1934 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1935 | DCHECK(user != nullptr); |
| 1936 | HUseListNode<HInstruction*>* use = |
| 1937 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1938 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1941 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1942 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1943 | HUseListNode<HEnvironment*>* env_use = |
| 1944 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1945 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1948 | void RemoveAsUserOfInput(size_t input) { |
| 1949 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1950 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1951 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1952 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1953 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1954 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1955 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1956 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1957 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1958 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1959 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1960 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1961 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1962 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1963 | // Does this instruction strictly dominate `other_instruction`? |
| 1964 | // Returns false if this instruction and `other_instruction` are the same. |
| 1965 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1966 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1967 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1968 | int GetId() const { return id_; } |
| 1969 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1970 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1971 | int GetSsaIndex() const { return ssa_index_; } |
| 1972 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1973 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1974 | |
| 1975 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1976 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1977 | // Set the `environment_` field. Raw because this method does not |
| 1978 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1979 | void SetRawEnvironment(HEnvironment* environment) { |
| 1980 | DCHECK(environment_ == nullptr); |
| 1981 | DCHECK_EQ(environment->GetHolder(), this); |
| 1982 | environment_ = environment; |
| 1983 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1984 | |
| 1985 | // Set the environment of this instruction, copying it from `environment`. While |
| 1986 | // copying, the uses lists are being updated. |
| 1987 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1988 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1989 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1990 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1991 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1992 | if (environment->GetParent() != nullptr) { |
| 1993 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1994 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1995 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1996 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1997 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1998 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1999 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2000 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2001 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2002 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2003 | if (environment->GetParent() != nullptr) { |
| 2004 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2005 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2008 | // Returns the number of entries in the environment. Typically, that is the |
| 2009 | // number of dex registers in a method. It could be more in case of inlining. |
| 2010 | size_t EnvironmentSize() const; |
| 2011 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2012 | LocationSummary* GetLocations() const { return locations_; } |
| 2013 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2014 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2015 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2016 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2017 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2018 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2019 | // uses of this instruction by `other` are *not* updated. |
| 2020 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2021 | ReplaceWith(other); |
| 2022 | other->ReplaceInput(this, use_index); |
| 2023 | } |
| 2024 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 2025 | // Move `this` instruction before `cursor`. |
| 2026 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2027 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2028 | // Move `this` before its first user and out of any loops. If there is no |
| 2029 | // out-of-loop user that dominates all other users, move the instruction |
| 2030 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2031 | // |
| 2032 | // This can be used only on non-throwing instructions with no side effects that |
| 2033 | // have at least one use but no environment uses. |
| 2034 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2035 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2036 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2037 | bool Is##type() const; \ |
| 2038 | const H##type* As##type() const; \ |
| 2039 | H##type* As##type(); |
| 2040 | |
| 2041 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2042 | #undef INSTRUCTION_TYPE_CHECK |
| 2043 | |
| 2044 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2045 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 2046 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2047 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2048 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2049 | #undef INSTRUCTION_TYPE_CHECK |
| 2050 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2051 | // Returns whether the instruction can be moved within the graph. |
| 2052 | virtual bool CanBeMoved() const { return false; } |
| 2053 | |
| 2054 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2055 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2056 | return false; |
| 2057 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2058 | |
| 2059 | // Returns whether any data encoded in the two instructions is equal. |
| 2060 | // This method does not look at the inputs. Both instructions must be |
| 2061 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2062 | virtual bool InstructionDataEquals(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 two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2067 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2068 | // 2) Their inputs are identical. |
| 2069 | bool Equals(HInstruction* other) const; |
| 2070 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2071 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2072 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2073 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2074 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2075 | InstructionKind GetKind() const PURE; |
| 2076 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2077 | |
| 2078 | virtual size_t ComputeHashCode() const { |
| 2079 | size_t result = GetKind(); |
| 2080 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 2081 | result = (result * 31) + InputAt(i)->GetId(); |
| 2082 | } |
| 2083 | return result; |
| 2084 | } |
| 2085 | |
| 2086 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2087 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2088 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2089 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2090 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2091 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2092 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2093 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2094 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2095 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2096 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2097 | |
| 2098 | // Returns whether the code generation of the instruction will require to have access |
| 2099 | // to the current method. Such instructions are: |
| 2100 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2101 | // to walk the stack and have the current method stored at a specific stack address. |
| 2102 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2103 | // fields of the current method. |
| 2104 | bool NeedsCurrentMethod() const { |
| 2105 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2106 | } |
| 2107 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2108 | // Returns whether the code generation of the instruction will require to have access |
| 2109 | // to the dex cache of the current method's declaring class via the current method. |
| 2110 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2111 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2112 | // Does this instruction have any use in an environment before |
| 2113 | // control flow hits 'other'? |
| 2114 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2115 | |
| 2116 | // Remove all references to environment uses of this instruction. |
| 2117 | // The caller must ensure that this is safe to do. |
| 2118 | void RemoveEnvironmentUsers(); |
| 2119 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2120 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2121 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2122 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2123 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2124 | // If set, the machine code for this instruction is assumed to be generated by |
| 2125 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2126 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2127 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2128 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2129 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2130 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2131 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 2132 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 2133 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2134 | uint32_t GetPackedFields() const { |
| 2135 | return packed_fields_; |
| 2136 | } |
| 2137 | |
| 2138 | template <size_t flag> |
| 2139 | bool GetPackedFlag() const { |
| 2140 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2141 | } |
| 2142 | |
| 2143 | template <size_t flag> |
| 2144 | void SetPackedFlag(bool value = true) { |
| 2145 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2146 | } |
| 2147 | |
| 2148 | template <typename BitFieldType> |
| 2149 | typename BitFieldType::value_type GetPackedField() const { |
| 2150 | return BitFieldType::Decode(packed_fields_); |
| 2151 | } |
| 2152 | |
| 2153 | template <typename BitFieldType> |
| 2154 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2155 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2156 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2157 | } |
| 2158 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2159 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2160 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2161 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2162 | HInstruction* previous_; |
| 2163 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2164 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2165 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2166 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2167 | // An instruction gets an id when it is added to the graph. |
| 2168 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2169 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2170 | int id_; |
| 2171 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2172 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2173 | int ssa_index_; |
| 2174 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2175 | // Packed fields. |
| 2176 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2177 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2178 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2179 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2180 | |
| 2181 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2182 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2183 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2184 | // The environment associated with this instruction. Not null if the instruction |
| 2185 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2186 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2187 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2188 | // Set by the code generator. |
| 2189 | LocationSummary* locations_; |
| 2190 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2191 | // Set by the liveness analysis. |
| 2192 | LiveInterval* live_interval_; |
| 2193 | |
| 2194 | // Set by the liveness analysis, this is the position in a linear |
| 2195 | // order of blocks where this instruction's live interval start. |
| 2196 | size_t lifetime_position_; |
| 2197 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2198 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2199 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2200 | // The reference handle part of the reference type info. |
| 2201 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2202 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2203 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2204 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2205 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2206 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2207 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2208 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2209 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2210 | |
| 2211 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2212 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2213 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2214 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2215 | class HInputIterator : public ValueObject { |
| 2216 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2217 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2218 | |
| 2219 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2220 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2221 | void Advance() { index_++; } |
| 2222 | |
| 2223 | private: |
| 2224 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2225 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2226 | |
| 2227 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2228 | }; |
| 2229 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2230 | class HInstructionIterator : public ValueObject { |
| 2231 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2232 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2233 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2234 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2235 | } |
| 2236 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2237 | bool Done() const { return instruction_ == nullptr; } |
| 2238 | HInstruction* Current() const { return instruction_; } |
| 2239 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2240 | instruction_ = next_; |
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 | |
| 2244 | private: |
| 2245 | HInstruction* instruction_; |
| 2246 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2247 | |
| 2248 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2249 | }; |
| 2250 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2251 | class HBackwardInstructionIterator : public ValueObject { |
| 2252 | public: |
| 2253 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2254 | : instruction_(instructions.last_instruction_) { |
| 2255 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2256 | } |
| 2257 | |
| 2258 | bool Done() const { return instruction_ == nullptr; } |
| 2259 | HInstruction* Current() const { return instruction_; } |
| 2260 | void Advance() { |
| 2261 | instruction_ = next_; |
| 2262 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2263 | } |
| 2264 | |
| 2265 | private: |
| 2266 | HInstruction* instruction_; |
| 2267 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2268 | |
| 2269 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2270 | }; |
| 2271 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2272 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2273 | class HTemplateInstruction: public HInstruction { |
| 2274 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2275 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2276 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2277 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2278 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2279 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2280 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2281 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2282 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2283 | DCHECK_LT(i, N); |
| 2284 | return inputs_[i]; |
| 2285 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2286 | |
| 2287 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2288 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2289 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2290 | } |
| 2291 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2292 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2293 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2294 | |
| 2295 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2296 | }; |
| 2297 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2298 | // HTemplateInstruction specialization for N=0. |
| 2299 | template<> |
| 2300 | class HTemplateInstruction<0>: public HInstruction { |
| 2301 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2302 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2303 | : HInstruction(side_effects, dex_pc) {} |
| 2304 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2305 | virtual ~HTemplateInstruction() {} |
| 2306 | |
| 2307 | size_t InputCount() const OVERRIDE { return 0; } |
| 2308 | |
| 2309 | protected: |
| 2310 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2311 | LOG(FATAL) << "Unreachable"; |
| 2312 | UNREACHABLE(); |
| 2313 | } |
| 2314 | |
| 2315 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2316 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2317 | LOG(FATAL) << "Unreachable"; |
| 2318 | UNREACHABLE(); |
| 2319 | } |
| 2320 | |
| 2321 | private: |
| 2322 | friend class SsaBuilder; |
| 2323 | }; |
| 2324 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2325 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2326 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2327 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2328 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2329 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2330 | this->template SetPackedField<TypeField>(type); |
| 2331 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2332 | virtual ~HExpression() {} |
| 2333 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2334 | Primitive::Type GetType() const OVERRIDE { |
| 2335 | return TypeField::Decode(this->GetPackedFields()); |
| 2336 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2337 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2338 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2339 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2340 | static constexpr size_t kFieldTypeSize = |
| 2341 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2342 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2343 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2344 | "Too many packed fields."); |
| 2345 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2346 | }; |
| 2347 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2348 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2349 | // instruction that branches to the exit block. |
| 2350 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2351 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2352 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2353 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2354 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2355 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2356 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2357 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2358 | |
| 2359 | private: |
| 2360 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2361 | }; |
| 2362 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2363 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2364 | // instruction that branches to the exit block. |
| 2365 | class HReturn : public HTemplateInstruction<1> { |
| 2366 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2367 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2368 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2369 | SetRawInputAt(0, value); |
| 2370 | } |
| 2371 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2372 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2373 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2374 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2375 | |
| 2376 | private: |
| 2377 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2378 | }; |
| 2379 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2380 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2381 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2382 | // exit block. |
| 2383 | class HExit : public HTemplateInstruction<0> { |
| 2384 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2385 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2386 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2387 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2388 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2389 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2390 | |
| 2391 | private: |
| 2392 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2393 | }; |
| 2394 | |
| 2395 | // Jumps from one block to another. |
| 2396 | class HGoto : public HTemplateInstruction<0> { |
| 2397 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2398 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2399 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2400 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2401 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2402 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2403 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2404 | } |
| 2405 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2406 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2407 | |
| 2408 | private: |
| 2409 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2410 | }; |
| 2411 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2412 | class HConstant : public HExpression<0> { |
| 2413 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2414 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2415 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2416 | |
| 2417 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2418 | |
| 2419 | virtual bool IsMinusOne() const { return false; } |
| 2420 | virtual bool IsZero() const { return false; } |
| 2421 | virtual bool IsOne() const { return false; } |
| 2422 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2423 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2424 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2425 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2426 | |
| 2427 | private: |
| 2428 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2429 | }; |
| 2430 | |
| 2431 | class HNullConstant : public HConstant { |
| 2432 | public: |
| 2433 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2434 | return true; |
| 2435 | } |
| 2436 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2437 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2438 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2439 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2440 | |
| 2441 | DECLARE_INSTRUCTION(NullConstant); |
| 2442 | |
| 2443 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2444 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2445 | |
| 2446 | friend class HGraph; |
| 2447 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2448 | }; |
| 2449 | |
| 2450 | // Constants of the type int. Those can be from Dex instructions, or |
| 2451 | // synthesized (for example with the if-eqz instruction). |
| 2452 | class HIntConstant : public HConstant { |
| 2453 | public: |
| 2454 | int32_t GetValue() const { return value_; } |
| 2455 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2456 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2457 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2458 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2459 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2460 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2461 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2462 | return other->AsIntConstant()->value_ == value_; |
| 2463 | } |
| 2464 | |
| 2465 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2466 | |
| 2467 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2468 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2469 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2470 | |
| 2471 | DECLARE_INSTRUCTION(IntConstant); |
| 2472 | |
| 2473 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2474 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2475 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2476 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2477 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2478 | |
| 2479 | const int32_t value_; |
| 2480 | |
| 2481 | friend class HGraph; |
| 2482 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2483 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2484 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2485 | }; |
| 2486 | |
| 2487 | class HLongConstant : public HConstant { |
| 2488 | public: |
| 2489 | int64_t GetValue() const { return value_; } |
| 2490 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2491 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2492 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2493 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2494 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2495 | return other->AsLongConstant()->value_ == value_; |
| 2496 | } |
| 2497 | |
| 2498 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2499 | |
| 2500 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2501 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2502 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2503 | |
| 2504 | DECLARE_INSTRUCTION(LongConstant); |
| 2505 | |
| 2506 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2507 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2508 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2509 | |
| 2510 | const int64_t value_; |
| 2511 | |
| 2512 | friend class HGraph; |
| 2513 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2514 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2515 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2516 | class HFloatConstant : public HConstant { |
| 2517 | public: |
| 2518 | float GetValue() const { return value_; } |
| 2519 | |
| 2520 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2521 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2522 | } |
| 2523 | |
| 2524 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2525 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2526 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2527 | } |
| 2528 | |
| 2529 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2530 | |
| 2531 | bool IsMinusOne() const OVERRIDE { |
| 2532 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2533 | } |
| 2534 | bool IsZero() const OVERRIDE { |
| 2535 | return value_ == 0.0f; |
| 2536 | } |
| 2537 | bool IsOne() const OVERRIDE { |
| 2538 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2539 | } |
| 2540 | bool IsNaN() const { |
| 2541 | return std::isnan(value_); |
| 2542 | } |
| 2543 | |
| 2544 | DECLARE_INSTRUCTION(FloatConstant); |
| 2545 | |
| 2546 | private: |
| 2547 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2548 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2549 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2550 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2551 | |
| 2552 | const float value_; |
| 2553 | |
| 2554 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2555 | friend class SsaBuilder; |
| 2556 | friend class HGraph; |
| 2557 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2558 | }; |
| 2559 | |
| 2560 | class HDoubleConstant : public HConstant { |
| 2561 | public: |
| 2562 | double GetValue() const { return value_; } |
| 2563 | |
| 2564 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2565 | |
| 2566 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2567 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2568 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2569 | } |
| 2570 | |
| 2571 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2572 | |
| 2573 | bool IsMinusOne() const OVERRIDE { |
| 2574 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2575 | } |
| 2576 | bool IsZero() const OVERRIDE { |
| 2577 | return value_ == 0.0; |
| 2578 | } |
| 2579 | bool IsOne() const OVERRIDE { |
| 2580 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2581 | } |
| 2582 | bool IsNaN() const { |
| 2583 | return std::isnan(value_); |
| 2584 | } |
| 2585 | |
| 2586 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2587 | |
| 2588 | private: |
| 2589 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2590 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2591 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2592 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2593 | |
| 2594 | const double value_; |
| 2595 | |
| 2596 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2597 | friend class SsaBuilder; |
| 2598 | friend class HGraph; |
| 2599 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2600 | }; |
| 2601 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2602 | // Conditional branch. A block ending with an HIf instruction must have |
| 2603 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2604 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2605 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2606 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2607 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2608 | SetRawInputAt(0, input); |
| 2609 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2610 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2611 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2612 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2613 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2614 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2618 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2619 | } |
| 2620 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2621 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2622 | |
| 2623 | private: |
| 2624 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2625 | }; |
| 2626 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2627 | |
| 2628 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2629 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2630 | // non-exceptional control flow. |
| 2631 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2632 | // higher indices in no particular order. |
| 2633 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2634 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2635 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2636 | kEntry, |
| 2637 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2638 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2639 | }; |
| 2640 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2641 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2642 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2643 | SetPackedField<BoundaryKindField>(kind); |
| 2644 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2645 | |
| 2646 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2647 | |
| 2648 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2649 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2650 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2651 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2652 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2653 | } |
| 2654 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2655 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2656 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2657 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2658 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2659 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | // If not present already, adds `handler` to its block's list of exception |
| 2663 | // handlers. |
| 2664 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2665 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2666 | GetBlock()->AddSuccessor(handler); |
| 2667 | } |
| 2668 | } |
| 2669 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2670 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2671 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2672 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2673 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2674 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2675 | DECLARE_INSTRUCTION(TryBoundary); |
| 2676 | |
| 2677 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2678 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2679 | static constexpr size_t kFieldBoundaryKindSize = |
| 2680 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2681 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2682 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2683 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2684 | "Too many packed fields."); |
| 2685 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2686 | |
| 2687 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2688 | }; |
| 2689 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2690 | // Deoptimize to interpreter, upon checking a condition. |
| 2691 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2692 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2693 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2694 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2695 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2696 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2697 | SetRawInputAt(0, cond); |
| 2698 | } |
| 2699 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2700 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2701 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2702 | return true; |
| 2703 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2704 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2705 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2706 | |
| 2707 | DECLARE_INSTRUCTION(Deoptimize); |
| 2708 | |
| 2709 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2710 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2711 | }; |
| 2712 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2713 | // Represents the ArtMethod that was passed as a first argument to |
| 2714 | // the method. It is used by instructions that depend on it, like |
| 2715 | // instructions that work with the dex cache. |
| 2716 | class HCurrentMethod : public HExpression<0> { |
| 2717 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2718 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2719 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2720 | |
| 2721 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2722 | |
| 2723 | private: |
| 2724 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2725 | }; |
| 2726 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2727 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2728 | // of a class. |
| 2729 | class HClassTableGet : public HExpression<1> { |
| 2730 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2731 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2732 | kVTable, |
| 2733 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2734 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2735 | }; |
| 2736 | HClassTableGet(HInstruction* cls, |
| 2737 | Primitive::Type type, |
| 2738 | TableKind kind, |
| 2739 | size_t index, |
| 2740 | uint32_t dex_pc) |
| 2741 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2742 | index_(index) { |
| 2743 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2744 | SetRawInputAt(0, cls); |
| 2745 | } |
| 2746 | |
| 2747 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2748 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2749 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2750 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2751 | } |
| 2752 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2753 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2754 | size_t GetIndex() const { return index_; } |
| 2755 | |
| 2756 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2757 | |
| 2758 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2759 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2760 | static constexpr size_t kFieldTableKindSize = |
| 2761 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2762 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2763 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2764 | "Too many packed fields."); |
| 2765 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2766 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2767 | // The index of the ArtMethod in the table. |
| 2768 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2769 | |
| 2770 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2771 | }; |
| 2772 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2773 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2774 | // have one successor for each entry in the switch table, and the final successor |
| 2775 | // will be the block containing the next Dex opcode. |
| 2776 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2777 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2778 | HPackedSwitch(int32_t start_value, |
| 2779 | uint32_t num_entries, |
| 2780 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2781 | uint32_t dex_pc = kNoDexPc) |
| 2782 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2783 | start_value_(start_value), |
| 2784 | num_entries_(num_entries) { |
| 2785 | SetRawInputAt(0, input); |
| 2786 | } |
| 2787 | |
| 2788 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2789 | |
| 2790 | int32_t GetStartValue() const { return start_value_; } |
| 2791 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2792 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2793 | |
| 2794 | HBasicBlock* GetDefaultBlock() const { |
| 2795 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2796 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2797 | } |
| 2798 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2799 | |
| 2800 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2801 | const int32_t start_value_; |
| 2802 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2803 | |
| 2804 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2805 | }; |
| 2806 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2807 | class HUnaryOperation : public HExpression<1> { |
| 2808 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2809 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2810 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2811 | SetRawInputAt(0, input); |
| 2812 | } |
| 2813 | |
| 2814 | HInstruction* GetInput() const { return InputAt(0); } |
| 2815 | Primitive::Type GetResultType() const { return GetType(); } |
| 2816 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2817 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2818 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2819 | return true; |
| 2820 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2821 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2822 | // Try to statically evaluate `this` and return a HConstant |
| 2823 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2824 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2825 | HConstant* TryStaticEvaluation() const; |
| 2826 | |
| 2827 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2828 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2829 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2830 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2831 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2832 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2833 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2834 | |
| 2835 | private: |
| 2836 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2837 | }; |
| 2838 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2839 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2840 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2841 | HBinaryOperation(Primitive::Type result_type, |
| 2842 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2843 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2844 | SideEffects side_effects = SideEffects::None(), |
| 2845 | uint32_t dex_pc = kNoDexPc) |
| 2846 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2847 | SetRawInputAt(0, left); |
| 2848 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2851 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2852 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2853 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2854 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2855 | virtual bool IsCommutative() const { return false; } |
| 2856 | |
| 2857 | // Put constant on the right. |
| 2858 | // Returns whether order is changed. |
| 2859 | bool OrderInputsWithConstantOnTheRight() { |
| 2860 | HInstruction* left = InputAt(0); |
| 2861 | HInstruction* right = InputAt(1); |
| 2862 | if (left->IsConstant() && !right->IsConstant()) { |
| 2863 | ReplaceInput(right, 0); |
| 2864 | ReplaceInput(left, 1); |
| 2865 | return true; |
| 2866 | } |
| 2867 | return false; |
| 2868 | } |
| 2869 | |
| 2870 | // Order inputs by instruction id, but favor constant on the right side. |
| 2871 | // This helps GVN for commutative ops. |
| 2872 | void OrderInputs() { |
| 2873 | DCHECK(IsCommutative()); |
| 2874 | HInstruction* left = InputAt(0); |
| 2875 | HInstruction* right = InputAt(1); |
| 2876 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2877 | return; |
| 2878 | } |
| 2879 | if (OrderInputsWithConstantOnTheRight()) { |
| 2880 | return; |
| 2881 | } |
| 2882 | // Order according to instruction id. |
| 2883 | if (left->GetId() > right->GetId()) { |
| 2884 | ReplaceInput(right, 0); |
| 2885 | ReplaceInput(left, 1); |
| 2886 | } |
| 2887 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2888 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2889 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2890 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2891 | return true; |
| 2892 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2893 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2894 | // Try to statically evaluate `this` and return a HConstant |
| 2895 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2896 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2897 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2898 | |
| 2899 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2900 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2901 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2902 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 2903 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2904 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2905 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2906 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2907 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2908 | HIntConstant* 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 (long, int) case."; |
| 2910 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2911 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2912 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 2913 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2914 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2915 | // 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] | 2916 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2917 | HConstant* GetConstantRight() const; |
| 2918 | |
| 2919 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2920 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2921 | HInstruction* GetLeastConstantLeft() const; |
| 2922 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2923 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2924 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2925 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2926 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2927 | }; |
| 2928 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2929 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2930 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2931 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2932 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2933 | kGtBias, // return 1 for NaN comparisons |
| 2934 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2935 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2936 | }; |
| 2937 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2938 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 2939 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2940 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2941 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2942 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2943 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 2944 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 2945 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2946 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2947 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2948 | // `instruction`, and disregard moves in between. |
| 2949 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2950 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2951 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2952 | |
| 2953 | virtual IfCondition GetCondition() const = 0; |
| 2954 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2955 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2956 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2957 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
| 2958 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 2959 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2960 | |
| 2961 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2962 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2963 | } |
| 2964 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2965 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2966 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2967 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2968 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2972 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2973 | IfCondition if_cond = GetCondition(); |
Nicolas Geoffray | d4aee94 | 2016-01-22 12:35:26 +0000 | [diff] [blame] | 2974 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2975 | } |
| 2976 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2977 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2978 | // Needed if we merge a HCompare into a HCondition. |
| 2979 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 2980 | static constexpr size_t kFieldComparisonBiasSize = |
| 2981 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 2982 | static constexpr size_t kNumberOfConditionPackedBits = |
| 2983 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 2984 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2985 | using ComparisonBiasField = |
| 2986 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 2987 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2988 | template <typename T> |
| 2989 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 2990 | |
| 2991 | template <typename T> |
| 2992 | int32_t CompareFP(T x, T y) const { |
| 2993 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 2994 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 2995 | // Handle the bias. |
| 2996 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 2997 | } |
| 2998 | |
| 2999 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3000 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3001 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3002 | } |
| 3003 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3004 | private: |
| 3005 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3006 | }; |
| 3007 | |
| 3008 | // Instruction to check if two inputs are equal to each other. |
| 3009 | class HEqual : public HCondition { |
| 3010 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3011 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3012 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3013 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3014 | bool IsCommutative() const OVERRIDE { return true; } |
| 3015 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3016 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3017 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3018 | return MakeConstantCondition(true, GetDexPc()); |
| 3019 | } |
| 3020 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3021 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3022 | } |
| 3023 | // In the following Evaluate methods, a HCompare instruction has |
| 3024 | // been merged into this HEqual instruction; evaluate it as |
| 3025 | // `Compare(x, y) == 0`. |
| 3026 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3027 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3028 | GetDexPc()); |
| 3029 | } |
| 3030 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3031 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3032 | } |
| 3033 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3034 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3035 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3036 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3037 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3038 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3039 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3040 | return kCondEQ; |
| 3041 | } |
| 3042 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3043 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3044 | return kCondNE; |
| 3045 | } |
| 3046 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3047 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3048 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 3049 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3050 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3051 | }; |
| 3052 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3053 | class HNotEqual : public HCondition { |
| 3054 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3055 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3056 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3057 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3058 | bool IsCommutative() const OVERRIDE { return true; } |
| 3059 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3060 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3061 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3062 | return MakeConstantCondition(false, GetDexPc()); |
| 3063 | } |
| 3064 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3065 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3066 | } |
| 3067 | // In the following Evaluate methods, a HCompare instruction has |
| 3068 | // been merged into this HNotEqual instruction; evaluate it as |
| 3069 | // `Compare(x, y) != 0`. |
| 3070 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3071 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3072 | } |
| 3073 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3074 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3075 | } |
| 3076 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3077 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3078 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3079 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3080 | DECLARE_INSTRUCTION(NotEqual); |
| 3081 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3082 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3083 | return kCondNE; |
| 3084 | } |
| 3085 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3086 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3087 | return kCondEQ; |
| 3088 | } |
| 3089 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3090 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3091 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 3092 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3093 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3094 | }; |
| 3095 | |
| 3096 | class HLessThan : public HCondition { |
| 3097 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3098 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3099 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3100 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3101 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3102 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3103 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3104 | // In the following Evaluate methods, a HCompare instruction has |
| 3105 | // been merged into this HLessThan instruction; evaluate it as |
| 3106 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3107 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3108 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3109 | } |
| 3110 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3111 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3112 | } |
| 3113 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3114 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3115 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3116 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3117 | DECLARE_INSTRUCTION(LessThan); |
| 3118 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3119 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3120 | return kCondLT; |
| 3121 | } |
| 3122 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3123 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3124 | return kCondGE; |
| 3125 | } |
| 3126 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3127 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3128 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3129 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3130 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3131 | }; |
| 3132 | |
| 3133 | class HLessThanOrEqual : public HCondition { |
| 3134 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3135 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3136 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3137 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3138 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3139 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3140 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3141 | // In the following Evaluate methods, a HCompare instruction has |
| 3142 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3143 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3144 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3145 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3146 | } |
| 3147 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3148 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3149 | } |
| 3150 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3151 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3152 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3153 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3154 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3155 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3156 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3157 | return kCondLE; |
| 3158 | } |
| 3159 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3160 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3161 | return kCondGT; |
| 3162 | } |
| 3163 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3164 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3165 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3166 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3167 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3168 | }; |
| 3169 | |
| 3170 | class HGreaterThan : public HCondition { |
| 3171 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3172 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3173 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3174 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3175 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3176 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3177 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3178 | // In the following Evaluate methods, a HCompare instruction has |
| 3179 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3180 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3181 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3182 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3183 | } |
| 3184 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3185 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3186 | } |
| 3187 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3188 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3189 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3190 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3191 | DECLARE_INSTRUCTION(GreaterThan); |
| 3192 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3193 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3194 | return kCondGT; |
| 3195 | } |
| 3196 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3197 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3198 | return kCondLE; |
| 3199 | } |
| 3200 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3201 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3202 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3203 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3204 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3205 | }; |
| 3206 | |
| 3207 | class HGreaterThanOrEqual : public HCondition { |
| 3208 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3209 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3210 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3211 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3212 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3213 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3214 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3215 | // In the following Evaluate methods, a HCompare instruction has |
| 3216 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3217 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3218 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3219 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3220 | } |
| 3221 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3222 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3223 | } |
| 3224 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3225 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3226 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3227 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3228 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3229 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3230 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3231 | return kCondGE; |
| 3232 | } |
| 3233 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3234 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3235 | return kCondLT; |
| 3236 | } |
| 3237 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3238 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3239 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3240 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3241 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3242 | }; |
| 3243 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3244 | class HBelow : public HCondition { |
| 3245 | public: |
| 3246 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3247 | : HCondition(first, second, dex_pc) {} |
| 3248 | |
| 3249 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3250 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3251 | } |
| 3252 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3253 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3254 | } |
| 3255 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3256 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3257 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3258 | UNREACHABLE(); |
| 3259 | } |
| 3260 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3261 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3262 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3263 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | DECLARE_INSTRUCTION(Below); |
| 3267 | |
| 3268 | IfCondition GetCondition() const OVERRIDE { |
| 3269 | return kCondB; |
| 3270 | } |
| 3271 | |
| 3272 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3273 | return kCondAE; |
| 3274 | } |
| 3275 | |
| 3276 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3277 | template <typename T> bool Compute(T x, T y) const { |
| 3278 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3279 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3280 | |
| 3281 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3282 | }; |
| 3283 | |
| 3284 | class HBelowOrEqual : public HCondition { |
| 3285 | public: |
| 3286 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3287 | : HCondition(first, second, dex_pc) {} |
| 3288 | |
| 3289 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3290 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3291 | } |
| 3292 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3293 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3294 | } |
| 3295 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3296 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3297 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3298 | UNREACHABLE(); |
| 3299 | } |
| 3300 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3301 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3302 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3303 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3307 | |
| 3308 | IfCondition GetCondition() const OVERRIDE { |
| 3309 | return kCondBE; |
| 3310 | } |
| 3311 | |
| 3312 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3313 | return kCondA; |
| 3314 | } |
| 3315 | |
| 3316 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3317 | template <typename T> bool Compute(T x, T y) const { |
| 3318 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3319 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3320 | |
| 3321 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3322 | }; |
| 3323 | |
| 3324 | class HAbove : public HCondition { |
| 3325 | public: |
| 3326 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3327 | : HCondition(first, second, dex_pc) {} |
| 3328 | |
| 3329 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3330 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3331 | } |
| 3332 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3333 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3334 | } |
| 3335 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3336 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3337 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3338 | UNREACHABLE(); |
| 3339 | } |
| 3340 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3341 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3342 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3343 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | DECLARE_INSTRUCTION(Above); |
| 3347 | |
| 3348 | IfCondition GetCondition() const OVERRIDE { |
| 3349 | return kCondA; |
| 3350 | } |
| 3351 | |
| 3352 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3353 | return kCondBE; |
| 3354 | } |
| 3355 | |
| 3356 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3357 | template <typename T> bool Compute(T x, T y) const { |
| 3358 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3359 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3360 | |
| 3361 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3362 | }; |
| 3363 | |
| 3364 | class HAboveOrEqual : public HCondition { |
| 3365 | public: |
| 3366 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3367 | : HCondition(first, second, dex_pc) {} |
| 3368 | |
| 3369 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3370 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3371 | } |
| 3372 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3373 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3374 | } |
| 3375 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3376 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3377 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3378 | UNREACHABLE(); |
| 3379 | } |
| 3380 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3381 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3382 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3383 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3387 | |
| 3388 | IfCondition GetCondition() const OVERRIDE { |
| 3389 | return kCondAE; |
| 3390 | } |
| 3391 | |
| 3392 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3393 | return kCondB; |
| 3394 | } |
| 3395 | |
| 3396 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3397 | template <typename T> bool Compute(T x, T y) const { |
| 3398 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3399 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3400 | |
| 3401 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3402 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3403 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3404 | // Instruction to check how two inputs compare to each other. |
| 3405 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 3406 | class HCompare : public HBinaryOperation { |
| 3407 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3408 | HCompare(Primitive::Type type, |
| 3409 | HInstruction* first, |
| 3410 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3411 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3412 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3413 | : HBinaryOperation(Primitive::kPrimInt, |
| 3414 | first, |
| 3415 | second, |
| 3416 | SideEffectsForArchRuntimeCalls(type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3417 | dex_pc) { |
| 3418 | SetPackedField<ComparisonBiasField>(bias); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3419 | DCHECK_EQ(type, first->GetType()); |
| 3420 | DCHECK_EQ(type, second->GetType()); |
| 3421 | } |
| 3422 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3423 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3424 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3425 | |
| 3426 | template <typename T> |
| 3427 | int32_t ComputeFP(T x, T y) const { |
| 3428 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3429 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3430 | // Handle the bias. |
| 3431 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3432 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3433 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3434 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3435 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3436 | // reach this code path when processing a freshly built HIR |
| 3437 | // graph. However HCompare integer instructions can be synthesized |
| 3438 | // by the instruction simplifier to implement IntegerCompare and |
| 3439 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3440 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3441 | } |
| 3442 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3443 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3444 | } |
| 3445 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3446 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3447 | } |
| 3448 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3449 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3450 | } |
| 3451 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3452 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3453 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3454 | } |
| 3455 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3456 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3457 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3458 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3459 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3460 | bool IsGtBias() const { |
| 3461 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3462 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3463 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3464 | |
| 3465 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3466 | // MIPS64 uses a runtime call for FP comparisons. |
| 3467 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3468 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3469 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3470 | DECLARE_INSTRUCTION(Compare); |
| 3471 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3472 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3473 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3474 | static constexpr size_t kFieldComparisonBiasSize = |
| 3475 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3476 | static constexpr size_t kNumberOfComparePackedBits = |
| 3477 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3478 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3479 | using ComparisonBiasField = |
| 3480 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3481 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3482 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3483 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3484 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3485 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3486 | } |
| 3487 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3488 | private: |
| 3489 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3490 | }; |
| 3491 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3492 | // A local in the graph. Corresponds to a Dex register. |
| 3493 | class HLocal : public HTemplateInstruction<0> { |
| 3494 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3495 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3496 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3497 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3498 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3499 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3500 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3501 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3502 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3503 | // The Dex register number. |
| 3504 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3505 | |
| 3506 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3507 | }; |
| 3508 | |
| 3509 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3510 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3511 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3512 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3513 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3514 | SetRawInputAt(0, local); |
| 3515 | } |
| 3516 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3517 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3518 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3519 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3520 | |
| 3521 | private: |
| 3522 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3523 | }; |
| 3524 | |
| 3525 | // Store a value in a given local. This instruction has two inputs: the value |
| 3526 | // and the local. |
| 3527 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3528 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3529 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3530 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3531 | SetRawInputAt(0, local); |
| 3532 | SetRawInputAt(1, value); |
| 3533 | } |
| 3534 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3535 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3536 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3537 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3538 | |
| 3539 | private: |
| 3540 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3541 | }; |
| 3542 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3543 | class HNewInstance : public HExpression<2> { |
| 3544 | public: |
| 3545 | HNewInstance(HInstruction* cls, |
| 3546 | HCurrentMethod* current_method, |
| 3547 | uint32_t dex_pc, |
| 3548 | uint16_t type_index, |
| 3549 | const DexFile& dex_file, |
| 3550 | bool can_throw, |
| 3551 | bool finalizable, |
| 3552 | QuickEntrypointEnum entrypoint) |
| 3553 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3554 | type_index_(type_index), |
| 3555 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3556 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3557 | SetPackedFlag<kFlagCanThrow>(can_throw); |
| 3558 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3559 | SetRawInputAt(0, cls); |
| 3560 | SetRawInputAt(1, current_method); |
| 3561 | } |
| 3562 | |
| 3563 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3564 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3565 | |
| 3566 | // Calls runtime so needs an environment. |
| 3567 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3568 | |
| 3569 | // It may throw when called on type that's not instantiable/accessible. |
| 3570 | // It can throw OOME. |
| 3571 | // 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] | 3572 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>() || true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3573 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3574 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3575 | |
| 3576 | bool CanBeNull() const OVERRIDE { return false; } |
| 3577 | |
| 3578 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3579 | |
| 3580 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3581 | entrypoint_ = entrypoint; |
| 3582 | } |
| 3583 | |
| 3584 | bool IsStringAlloc() const; |
| 3585 | |
| 3586 | DECLARE_INSTRUCTION(NewInstance); |
| 3587 | |
| 3588 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3589 | static constexpr size_t kFlagCanThrow = kNumberOfExpressionPackedBits; |
| 3590 | static constexpr size_t kFlagFinalizable = kFlagCanThrow + 1; |
| 3591 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3592 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3593 | "Too many packed fields."); |
| 3594 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3595 | const uint16_t type_index_; |
| 3596 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3597 | QuickEntrypointEnum entrypoint_; |
| 3598 | |
| 3599 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3600 | }; |
| 3601 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3602 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3603 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3604 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3605 | #include "intrinsics_list.h" |
| 3606 | kNone, |
| 3607 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3608 | #undef INTRINSICS_LIST |
| 3609 | #undef OPTIMIZING_INTRINSICS |
| 3610 | }; |
| 3611 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3612 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3613 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3614 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3615 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3616 | }; |
| 3617 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3618 | enum IntrinsicSideEffects { |
| 3619 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3620 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3621 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3622 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3623 | }; |
| 3624 | |
| 3625 | enum IntrinsicExceptions { |
| 3626 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3627 | kCanThrow // Intrinsic may throw exceptions. |
| 3628 | }; |
| 3629 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3630 | class HInvoke : public HInstruction { |
| 3631 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3632 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3633 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3634 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3635 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3636 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3637 | SetRawInputAt(index, argument); |
| 3638 | } |
| 3639 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3640 | // Return the number of arguments. This number can be lower than |
| 3641 | // the number of inputs returned by InputCount(), as some invoke |
| 3642 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3643 | // inputs at the end of their list of inputs. |
| 3644 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3645 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3646 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3647 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3648 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3649 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3650 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3651 | InvokeType GetOriginalInvokeType() const { |
| 3652 | return GetPackedField<OriginalInvokeTypeField>(); |
| 3653 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3654 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3655 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3656 | return intrinsic_; |
| 3657 | } |
| 3658 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3659 | void SetIntrinsic(Intrinsics intrinsic, |
| 3660 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3661 | IntrinsicSideEffects side_effects, |
| 3662 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3663 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3664 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3665 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3666 | } |
| 3667 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3668 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3669 | |
| 3670 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3671 | |
| 3672 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3673 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3674 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3675 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3676 | uint32_t* GetIntrinsicOptimizations() { |
| 3677 | return &intrinsic_optimizations_; |
| 3678 | } |
| 3679 | |
| 3680 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3681 | return &intrinsic_optimizations_; |
| 3682 | } |
| 3683 | |
| 3684 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3685 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3686 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3687 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3688 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3689 | static constexpr size_t kFieldOriginalInvokeType = kNumberOfGenericPackedBits; |
| 3690 | static constexpr size_t kFieldOriginalInvokeTypeSize = |
| 3691 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3692 | static constexpr size_t kFieldReturnType = |
| 3693 | kFieldOriginalInvokeType + kFieldOriginalInvokeTypeSize; |
| 3694 | static constexpr size_t kFieldReturnTypeSize = |
| 3695 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3696 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3697 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3698 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3699 | using OriginalInvokeTypeField = |
| 3700 | BitField<InvokeType, kFieldOriginalInvokeType, kFieldOriginalInvokeTypeSize>; |
| 3701 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3702 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3703 | HInvoke(ArenaAllocator* arena, |
| 3704 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3705 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3706 | Primitive::Type return_type, |
| 3707 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3708 | uint32_t dex_method_index, |
| 3709 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3710 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3711 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3712 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3713 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3714 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3715 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3716 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3717 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3718 | SetPackedField<ReturnTypeField>(return_type); |
| 3719 | SetPackedField<OriginalInvokeTypeField>(original_invoke_type); |
| 3720 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3721 | } |
| 3722 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3723 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3724 | return inputs_[index]; |
| 3725 | } |
| 3726 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3727 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3728 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3731 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3732 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3733 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3734 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3735 | const uint32_t dex_method_index_; |
| 3736 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3737 | |
| 3738 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3739 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3740 | |
| 3741 | private: |
| 3742 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3743 | }; |
| 3744 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3745 | class HInvokeUnresolved : public HInvoke { |
| 3746 | public: |
| 3747 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3748 | uint32_t number_of_arguments, |
| 3749 | Primitive::Type return_type, |
| 3750 | uint32_t dex_pc, |
| 3751 | uint32_t dex_method_index, |
| 3752 | InvokeType invoke_type) |
| 3753 | : HInvoke(arena, |
| 3754 | number_of_arguments, |
| 3755 | 0u /* number_of_other_inputs */, |
| 3756 | return_type, |
| 3757 | dex_pc, |
| 3758 | dex_method_index, |
| 3759 | invoke_type) { |
| 3760 | } |
| 3761 | |
| 3762 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3763 | |
| 3764 | private: |
| 3765 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3766 | }; |
| 3767 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3768 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3769 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3770 | // Requirements of this method call regarding the class |
| 3771 | // initialization (clinit) check of its declaring class. |
| 3772 | enum class ClinitCheckRequirement { |
| 3773 | kNone, // Class already initialized. |
| 3774 | kExplicit, // Static call having explicit clinit check as last input. |
| 3775 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3776 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3777 | }; |
| 3778 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3779 | // Determines how to load the target ArtMethod*. |
| 3780 | enum class MethodLoadKind { |
| 3781 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3782 | kStringInit, |
| 3783 | |
| 3784 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3785 | kRecursive, |
| 3786 | |
| 3787 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3788 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3789 | kDirectAddress, |
| 3790 | |
| 3791 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3792 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3793 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3794 | // the image relocatable or not. |
| 3795 | kDirectAddressWithFixup, |
| 3796 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3797 | // 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] | 3798 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3799 | // may cause class initialization (the entry may point to a resolution method), |
| 3800 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3801 | kDexCachePcRelative, |
| 3802 | |
| 3803 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3804 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3805 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3806 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3807 | kDexCacheViaMethod, |
| 3808 | }; |
| 3809 | |
| 3810 | // Determines the location of the code pointer. |
| 3811 | enum class CodePtrLocation { |
| 3812 | // Recursive call, use local PC-relative call instruction. |
| 3813 | kCallSelf, |
| 3814 | |
| 3815 | // Use PC-relative call instruction patched at link time. |
| 3816 | // Used for calls within an oat file, boot->boot or app->app. |
| 3817 | kCallPCRelative, |
| 3818 | |
| 3819 | // Call to a known target address, embed the direct address in code. |
| 3820 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3821 | kCallDirect, |
| 3822 | |
| 3823 | // Call to a target address that will be known at link time, embed the direct |
| 3824 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3825 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3826 | // the image relocatable or not. |
| 3827 | kCallDirectWithFixup, |
| 3828 | |
| 3829 | // Use code pointer from the ArtMethod*. |
| 3830 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3831 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3832 | kCallArtMethod, |
| 3833 | }; |
| 3834 | |
| 3835 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3836 | MethodLoadKind method_load_kind; |
| 3837 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3838 | // The method load data holds |
| 3839 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3840 | // Note that there are multiple string init methods, each having its own offset. |
| 3841 | // - the method address for kDirectAddress |
| 3842 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3843 | uint64_t method_load_data; |
| 3844 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3845 | }; |
| 3846 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3847 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3848 | uint32_t number_of_arguments, |
| 3849 | Primitive::Type return_type, |
| 3850 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3851 | uint32_t method_index, |
| 3852 | MethodReference target_method, |
| 3853 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3854 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3855 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3856 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3857 | : HInvoke(arena, |
| 3858 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3859 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3860 | // potentially one other if the clinit check is explicit, and potentially |
| 3861 | // one other if the method is a string factory. |
| 3862 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| 3863 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) + |
| 3864 | (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3865 | return_type, |
| 3866 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3867 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3868 | original_invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3869 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3870 | dispatch_info_(dispatch_info) { |
| 3871 | SetPackedField<OptimizedInvokeTypeField>(optimized_invoke_type); |
| 3872 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3873 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3874 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3875 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3876 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3877 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3878 | |
| 3879 | // Using the current method is the default and once we find a better |
| 3880 | // method load kind, we should not go back to using the current method. |
| 3881 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3882 | |
| 3883 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3884 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3885 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3886 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3887 | dispatch_info_ = dispatch_info; |
| 3888 | } |
| 3889 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3890 | void AddSpecialInput(HInstruction* input) { |
| 3891 | // We allow only one special input. |
| 3892 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3893 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3894 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3895 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3896 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3897 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3898 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3899 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3900 | // TODO: for intrinsics we can generate implicit null checks. |
| 3901 | return false; |
| 3902 | } |
| 3903 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3904 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3905 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3906 | } |
| 3907 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3908 | // Get the index of the special input, if any. |
| 3909 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3910 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3911 | // method pointer; otherwise there may be one platform-specific special input, |
| 3912 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3913 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 3914 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3915 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3916 | InvokeType GetOptimizedInvokeType() const { |
| 3917 | return GetPackedField<OptimizedInvokeTypeField>(); |
| 3918 | } |
| 3919 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3920 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3921 | SetPackedField<OptimizedInvokeTypeField>(invoke_type); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3922 | } |
| 3923 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3924 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3925 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3926 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3927 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3928 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3929 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3930 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3931 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3932 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3933 | bool HasCurrentMethodInput() const { |
| 3934 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3935 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3936 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3937 | return true; |
| 3938 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3939 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3940 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3941 | return false; |
| 3942 | } |
| 3943 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3944 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3945 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3946 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3947 | |
| 3948 | int32_t GetStringInitOffset() const { |
| 3949 | DCHECK(IsStringInit()); |
| 3950 | return dispatch_info_.method_load_data; |
| 3951 | } |
| 3952 | |
| 3953 | uint64_t GetMethodAddress() const { |
| 3954 | DCHECK(HasMethodAddress()); |
| 3955 | return dispatch_info_.method_load_data; |
| 3956 | } |
| 3957 | |
| 3958 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3959 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3960 | return dispatch_info_.method_load_data; |
| 3961 | } |
| 3962 | |
| 3963 | uint64_t GetDirectCodePtr() const { |
| 3964 | DCHECK(HasDirectCodePtr()); |
| 3965 | return dispatch_info_.direct_code_ptr; |
| 3966 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3967 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3968 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 3969 | return GetPackedField<ClinitCheckRequirementField>(); |
| 3970 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3971 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3972 | // Is this instruction a call to a static method? |
| 3973 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3974 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3975 | } |
| 3976 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3977 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 3978 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 3979 | // instruction; only relevant for static calls with explicit clinit check. |
| 3980 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3981 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3982 | size_t last_input_index = InputCount() - 1; |
| 3983 | HInstruction* last_input = InputAt(last_input_index); |
| 3984 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3985 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3986 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3987 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3988 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 3989 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3990 | } |
| 3991 | |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3992 | HInstruction* GetAndRemoveThisArgumentOfStringInit() { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3993 | DCHECK(IsStringInit()); |
| 3994 | size_t index = InputCount() - 1; |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3995 | HInstruction* input = InputAt(index); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3996 | RemoveAsUserOfInput(index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3997 | inputs_.pop_back(); |
David Brazdil | bc9ab16 | 2016-01-20 14:50:19 +0000 | [diff] [blame] | 3998 | return input; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3999 | } |
| 4000 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4001 | // 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] | 4002 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4003 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4004 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4005 | } |
| 4006 | |
| 4007 | // Is this a call to a static method whose declaring class has an |
| 4008 | // implicit intialization check requirement? |
| 4009 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4010 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4011 | } |
| 4012 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4013 | // Does this method load kind need the current method as an input? |
| 4014 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4015 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4016 | } |
| 4017 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4018 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4019 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4020 | protected: |
| 4021 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 4022 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 4023 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 4024 | HInstruction* input = input_record.GetInstruction(); |
| 4025 | // `input` is the last input of a static invoke marked as having |
| 4026 | // an explicit clinit check. It must either be: |
| 4027 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4028 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4029 | DCHECK(input != nullptr); |
| 4030 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 4031 | } |
| 4032 | return input_record; |
| 4033 | } |
| 4034 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4035 | void InsertInputAt(size_t index, HInstruction* input); |
| 4036 | void RemoveInputAt(size_t index); |
| 4037 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4038 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4039 | static constexpr size_t kFieldOptimizedInvokeType = kNumberOfInvokePackedBits; |
| 4040 | static constexpr size_t kFieldOptimizedInvokeTypeSize = |
| 4041 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4042 | static constexpr size_t kFieldClinitCheckRequirement = |
| 4043 | kFieldOptimizedInvokeType + kFieldOptimizedInvokeTypeSize; |
| 4044 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4045 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4046 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4047 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4048 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4049 | "Too many packed fields."); |
| 4050 | using OptimizedInvokeTypeField = |
| 4051 | BitField<InvokeType, kFieldOptimizedInvokeType, kFieldOptimizedInvokeTypeSize>; |
| 4052 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4053 | kFieldClinitCheckRequirement, |
| 4054 | kFieldClinitCheckRequirementSize>; |
| 4055 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4056 | // The target method may refer to different dex file or method index than the original |
| 4057 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 4058 | // in derived class to increase visibility. |
| 4059 | MethodReference target_method_; |
| 4060 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4061 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4062 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4063 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4064 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4065 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4066 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4067 | class HInvokeVirtual : public HInvoke { |
| 4068 | public: |
| 4069 | HInvokeVirtual(ArenaAllocator* arena, |
| 4070 | uint32_t number_of_arguments, |
| 4071 | Primitive::Type return_type, |
| 4072 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4073 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4074 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4075 | : 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] | 4076 | vtable_index_(vtable_index) {} |
| 4077 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4078 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4079 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4080 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4081 | } |
| 4082 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4083 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4084 | |
| 4085 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4086 | |
| 4087 | private: |
| 4088 | const uint32_t vtable_index_; |
| 4089 | |
| 4090 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4091 | }; |
| 4092 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4093 | class HInvokeInterface : public HInvoke { |
| 4094 | public: |
| 4095 | HInvokeInterface(ArenaAllocator* arena, |
| 4096 | uint32_t number_of_arguments, |
| 4097 | Primitive::Type return_type, |
| 4098 | uint32_t dex_pc, |
| 4099 | uint32_t dex_method_index, |
| 4100 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4101 | : 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] | 4102 | imt_index_(imt_index) {} |
| 4103 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4104 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4105 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4106 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4107 | } |
| 4108 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4109 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4110 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4111 | |
| 4112 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4113 | |
| 4114 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4115 | const uint32_t imt_index_; |
| 4116 | |
| 4117 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4118 | }; |
| 4119 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4120 | class HNeg : public HUnaryOperation { |
| 4121 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4122 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4123 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4124 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4125 | template <typename T> T Compute(T x) const { return -x; } |
| 4126 | |
| 4127 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4128 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4129 | } |
| 4130 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4131 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4132 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4133 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4134 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4135 | } |
| 4136 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4137 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4138 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4139 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4140 | DECLARE_INSTRUCTION(Neg); |
| 4141 | |
| 4142 | private: |
| 4143 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4144 | }; |
| 4145 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4146 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4147 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4148 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4149 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4150 | uint32_t dex_pc, |
| 4151 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4152 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4153 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4154 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4155 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4156 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4157 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4158 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4159 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4160 | } |
| 4161 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4162 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4163 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4164 | |
| 4165 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4166 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4167 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4168 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4169 | bool CanThrow() const OVERRIDE { return true; } |
| 4170 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4171 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4172 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4173 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4174 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4175 | DECLARE_INSTRUCTION(NewArray); |
| 4176 | |
| 4177 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4178 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4179 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4180 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4181 | |
| 4182 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4183 | }; |
| 4184 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4185 | class HAdd : public HBinaryOperation { |
| 4186 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4187 | HAdd(Primitive::Type result_type, |
| 4188 | HInstruction* left, |
| 4189 | HInstruction* right, |
| 4190 | uint32_t dex_pc = kNoDexPc) |
| 4191 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4192 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4193 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4194 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4195 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 4196 | |
| 4197 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4198 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4199 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4200 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4201 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4202 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4203 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4204 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4205 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4206 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4207 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4208 | } |
| 4209 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4210 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4211 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4212 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4213 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4214 | DECLARE_INSTRUCTION(Add); |
| 4215 | |
| 4216 | private: |
| 4217 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4218 | }; |
| 4219 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4220 | class HSub : public HBinaryOperation { |
| 4221 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4222 | HSub(Primitive::Type result_type, |
| 4223 | HInstruction* left, |
| 4224 | HInstruction* right, |
| 4225 | uint32_t dex_pc = kNoDexPc) |
| 4226 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4227 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4228 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 4229 | |
| 4230 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4231 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4232 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4233 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4234 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4235 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4236 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4237 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4238 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4239 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4240 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4241 | } |
| 4242 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4243 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4244 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4245 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4246 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4247 | DECLARE_INSTRUCTION(Sub); |
| 4248 | |
| 4249 | private: |
| 4250 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4251 | }; |
| 4252 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4253 | class HMul : public HBinaryOperation { |
| 4254 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4255 | HMul(Primitive::Type result_type, |
| 4256 | HInstruction* left, |
| 4257 | HInstruction* right, |
| 4258 | uint32_t dex_pc = kNoDexPc) |
| 4259 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4260 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4261 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4262 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4263 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 4264 | |
| 4265 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4266 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4267 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4268 | } |
| 4269 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4270 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4271 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4272 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4273 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4274 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4275 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4276 | } |
| 4277 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4278 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4279 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4280 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4281 | |
| 4282 | DECLARE_INSTRUCTION(Mul); |
| 4283 | |
| 4284 | private: |
| 4285 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4286 | }; |
| 4287 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4288 | class HDiv : public HBinaryOperation { |
| 4289 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4290 | HDiv(Primitive::Type result_type, |
| 4291 | HInstruction* left, |
| 4292 | HInstruction* right, |
| 4293 | uint32_t dex_pc) |
| 4294 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4295 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4296 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4297 | T ComputeIntegral(T x, T y) const { |
| 4298 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4299 | // Our graph structure ensures we never have 0 for `y` during |
| 4300 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4301 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4302 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4303 | return (y == -1) ? -x : x / y; |
| 4304 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4305 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4306 | template <typename T> |
| 4307 | T ComputeFP(T x, T y) const { |
| 4308 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4309 | return x / y; |
| 4310 | } |
| 4311 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4312 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4313 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4314 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4315 | } |
| 4316 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4317 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4318 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4319 | } |
| 4320 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4321 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4322 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4323 | } |
| 4324 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4325 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4326 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4327 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4328 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4329 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4330 | // The generated code can use a runtime call. |
| 4331 | return SideEffects::CanTriggerGC(); |
| 4332 | } |
| 4333 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4334 | DECLARE_INSTRUCTION(Div); |
| 4335 | |
| 4336 | private: |
| 4337 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4338 | }; |
| 4339 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4340 | class HRem : public HBinaryOperation { |
| 4341 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4342 | HRem(Primitive::Type result_type, |
| 4343 | HInstruction* left, |
| 4344 | HInstruction* right, |
| 4345 | uint32_t dex_pc) |
| 4346 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4347 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4348 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4349 | T ComputeIntegral(T x, T y) const { |
| 4350 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4351 | // Our graph structure ensures we never have 0 for `y` during |
| 4352 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4353 | DCHECK_NE(y, 0); |
| 4354 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4355 | return (y == -1) ? 0 : x % y; |
| 4356 | } |
| 4357 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4358 | template <typename T> |
| 4359 | T ComputeFP(T x, T y) const { |
| 4360 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4361 | return std::fmod(x, y); |
| 4362 | } |
| 4363 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4364 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4365 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4366 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4367 | } |
| 4368 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4369 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4370 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4371 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4372 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4373 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4374 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4375 | } |
| 4376 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4377 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4378 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4379 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4380 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4381 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4382 | return SideEffects::CanTriggerGC(); |
| 4383 | } |
| 4384 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4385 | DECLARE_INSTRUCTION(Rem); |
| 4386 | |
| 4387 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4388 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4389 | }; |
| 4390 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4391 | class HDivZeroCheck : public HExpression<1> { |
| 4392 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4393 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4394 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4395 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4396 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4397 | SetRawInputAt(0, value); |
| 4398 | } |
| 4399 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4400 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4401 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4402 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4403 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4404 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4405 | return true; |
| 4406 | } |
| 4407 | |
| 4408 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4409 | bool CanThrow() const OVERRIDE { return true; } |
| 4410 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4411 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4412 | |
| 4413 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4414 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4415 | }; |
| 4416 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4417 | class HShl : public HBinaryOperation { |
| 4418 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4419 | HShl(Primitive::Type result_type, |
| 4420 | HInstruction* left, |
| 4421 | HInstruction* right, |
| 4422 | uint32_t dex_pc = kNoDexPc) |
| 4423 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4424 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4425 | template <typename T, typename U, typename V> |
| 4426 | T Compute(T x, U y, V max_shift_value) const { |
| 4427 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4428 | "V is not the unsigned integer type corresponding to T"); |
| 4429 | return x << (y & max_shift_value); |
| 4430 | } |
| 4431 | |
| 4432 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4433 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4434 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4435 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4436 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4437 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4438 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4439 | } |
| 4440 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4441 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4442 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4443 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4444 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4445 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4446 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4447 | UNREACHABLE(); |
| 4448 | } |
| 4449 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4450 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4451 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4452 | UNREACHABLE(); |
| 4453 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4454 | |
| 4455 | DECLARE_INSTRUCTION(Shl); |
| 4456 | |
| 4457 | private: |
| 4458 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4459 | }; |
| 4460 | |
| 4461 | class HShr : public HBinaryOperation { |
| 4462 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4463 | HShr(Primitive::Type result_type, |
| 4464 | HInstruction* left, |
| 4465 | HInstruction* right, |
| 4466 | uint32_t dex_pc = kNoDexPc) |
| 4467 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4468 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4469 | template <typename T, typename U, typename V> |
| 4470 | T Compute(T x, U y, V max_shift_value) const { |
| 4471 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4472 | "V is not the unsigned integer type corresponding to T"); |
| 4473 | return x >> (y & max_shift_value); |
| 4474 | } |
| 4475 | |
| 4476 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4477 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4478 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4479 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4480 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4481 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4482 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4483 | } |
| 4484 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4485 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4486 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4487 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4488 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4489 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4490 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4491 | UNREACHABLE(); |
| 4492 | } |
| 4493 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4494 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4495 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4496 | UNREACHABLE(); |
| 4497 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4498 | |
| 4499 | DECLARE_INSTRUCTION(Shr); |
| 4500 | |
| 4501 | private: |
| 4502 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4503 | }; |
| 4504 | |
| 4505 | class HUShr : public HBinaryOperation { |
| 4506 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4507 | HUShr(Primitive::Type result_type, |
| 4508 | HInstruction* left, |
| 4509 | HInstruction* right, |
| 4510 | uint32_t dex_pc = kNoDexPc) |
| 4511 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4512 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4513 | template <typename T, typename U, typename V> |
| 4514 | T Compute(T x, U y, V max_shift_value) const { |
| 4515 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4516 | "V is not the unsigned integer type corresponding to T"); |
| 4517 | V ux = static_cast<V>(x); |
| 4518 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4519 | } |
| 4520 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4521 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4522 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4523 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4524 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4525 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4526 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4527 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4528 | } |
| 4529 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4530 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4531 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4532 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4533 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4534 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4535 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4536 | UNREACHABLE(); |
| 4537 | } |
| 4538 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4539 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4540 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4541 | UNREACHABLE(); |
| 4542 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4543 | |
| 4544 | DECLARE_INSTRUCTION(UShr); |
| 4545 | |
| 4546 | private: |
| 4547 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4548 | }; |
| 4549 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4550 | class HAnd : public HBinaryOperation { |
| 4551 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4552 | HAnd(Primitive::Type result_type, |
| 4553 | HInstruction* left, |
| 4554 | HInstruction* right, |
| 4555 | uint32_t dex_pc = kNoDexPc) |
| 4556 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4557 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4558 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4559 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4560 | 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] | 4561 | |
| 4562 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4563 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4564 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4565 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4566 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4567 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4568 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4569 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4570 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4571 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4572 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4573 | UNREACHABLE(); |
| 4574 | } |
| 4575 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4576 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4577 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4578 | UNREACHABLE(); |
| 4579 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4580 | |
| 4581 | DECLARE_INSTRUCTION(And); |
| 4582 | |
| 4583 | private: |
| 4584 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4585 | }; |
| 4586 | |
| 4587 | class HOr : public HBinaryOperation { |
| 4588 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4589 | HOr(Primitive::Type result_type, |
| 4590 | HInstruction* left, |
| 4591 | HInstruction* right, |
| 4592 | uint32_t dex_pc = kNoDexPc) |
| 4593 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4594 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4595 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4596 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4597 | 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] | 4598 | |
| 4599 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4600 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4601 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4602 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4603 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4604 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4605 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4606 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4607 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4608 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4609 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4610 | UNREACHABLE(); |
| 4611 | } |
| 4612 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4613 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4614 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4615 | UNREACHABLE(); |
| 4616 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4617 | |
| 4618 | DECLARE_INSTRUCTION(Or); |
| 4619 | |
| 4620 | private: |
| 4621 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4622 | }; |
| 4623 | |
| 4624 | class HXor : public HBinaryOperation { |
| 4625 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4626 | HXor(Primitive::Type result_type, |
| 4627 | HInstruction* left, |
| 4628 | HInstruction* right, |
| 4629 | uint32_t dex_pc = kNoDexPc) |
| 4630 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4631 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4632 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4633 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4634 | 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] | 4635 | |
| 4636 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4637 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4638 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4639 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4640 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4641 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4642 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4643 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4644 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4645 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4646 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4647 | UNREACHABLE(); |
| 4648 | } |
| 4649 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4650 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4651 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4652 | UNREACHABLE(); |
| 4653 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4654 | |
| 4655 | DECLARE_INSTRUCTION(Xor); |
| 4656 | |
| 4657 | private: |
| 4658 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4659 | }; |
| 4660 | |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4661 | class HRor : public HBinaryOperation { |
| 4662 | public: |
| 4663 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
| 4664 | : HBinaryOperation(result_type, value, distance) {} |
| 4665 | |
| 4666 | template <typename T, typename U, typename V> |
| 4667 | T Compute(T x, U y, V max_shift_value) const { |
| 4668 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 4669 | "V is not the unsigned integer type corresponding to T"); |
| 4670 | V ux = static_cast<V>(x); |
| 4671 | if ((y & max_shift_value) == 0) { |
| 4672 | return static_cast<T>(ux); |
| 4673 | } else { |
| 4674 | const V reg_bits = sizeof(T) * 8; |
| 4675 | return static_cast<T>(ux >> (y & max_shift_value)) | |
| 4676 | (x << (reg_bits - (y & max_shift_value))); |
| 4677 | } |
| 4678 | } |
| 4679 | |
| 4680 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 4681 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4682 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
| 4683 | } |
| 4684 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 4685 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4686 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4687 | } |
| 4688 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 4689 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4690 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
| 4691 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4692 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4693 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4694 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4695 | UNREACHABLE(); |
| 4696 | } |
| 4697 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4698 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4699 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4700 | UNREACHABLE(); |
| 4701 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4702 | |
| 4703 | DECLARE_INSTRUCTION(Ror); |
| 4704 | |
| 4705 | private: |
| 4706 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4707 | }; |
| 4708 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4709 | // The value of a parameter in this method. Its location depends on |
| 4710 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4711 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4712 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4713 | HParameterValue(const DexFile& dex_file, |
| 4714 | uint16_t type_index, |
| 4715 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4716 | Primitive::Type parameter_type, |
| 4717 | bool is_this = false) |
| 4718 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4719 | dex_file_(dex_file), |
| 4720 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4721 | index_(index) { |
| 4722 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4723 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4724 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4725 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4726 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4727 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4728 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4729 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4730 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4731 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4732 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4733 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4734 | DECLARE_INSTRUCTION(ParameterValue); |
| 4735 | |
| 4736 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4737 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4738 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4739 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4740 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4741 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4742 | "Too many packed fields."); |
| 4743 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4744 | const DexFile& dex_file_; |
| 4745 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4746 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4747 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4748 | const uint8_t index_; |
| 4749 | |
| 4750 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4751 | }; |
| 4752 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4753 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4754 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4755 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4756 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4757 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4758 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4759 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4760 | return true; |
| 4761 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4762 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4763 | template <typename T> T Compute(T x) const { return ~x; } |
| 4764 | |
| 4765 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4766 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4767 | } |
| 4768 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4769 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4770 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4771 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4772 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4773 | UNREACHABLE(); |
| 4774 | } |
| 4775 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4776 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4777 | UNREACHABLE(); |
| 4778 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4779 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4780 | DECLARE_INSTRUCTION(Not); |
| 4781 | |
| 4782 | private: |
| 4783 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4784 | }; |
| 4785 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4786 | class HBooleanNot : public HUnaryOperation { |
| 4787 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4788 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4789 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4790 | |
| 4791 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4792 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4793 | return true; |
| 4794 | } |
| 4795 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4796 | template <typename T> bool Compute(T x) const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4797 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4798 | return !x; |
| 4799 | } |
| 4800 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4801 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4802 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4803 | } |
| 4804 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4805 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4806 | UNREACHABLE(); |
| 4807 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4808 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4809 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4810 | UNREACHABLE(); |
| 4811 | } |
| 4812 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4813 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4814 | UNREACHABLE(); |
| 4815 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4816 | |
| 4817 | DECLARE_INSTRUCTION(BooleanNot); |
| 4818 | |
| 4819 | private: |
| 4820 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4821 | }; |
| 4822 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4823 | class HTypeConversion : public HExpression<1> { |
| 4824 | public: |
| 4825 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4826 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4827 | : HExpression(result_type, |
| 4828 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4829 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4830 | SetRawInputAt(0, input); |
| 4831 | DCHECK_NE(input->GetType(), result_type); |
| 4832 | } |
| 4833 | |
| 4834 | HInstruction* GetInput() const { return InputAt(0); } |
| 4835 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4836 | Primitive::Type GetResultType() const { return GetType(); } |
| 4837 | |
| 4838 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4839 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4840 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4841 | // Try to statically evaluate the conversion and return a HConstant |
| 4842 | // containing the result. If the input cannot be converted, return nullptr. |
| 4843 | HConstant* TryStaticEvaluation() const; |
| 4844 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4845 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4846 | Primitive::Type result_type) { |
| 4847 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4848 | // in the compilation process we do not know what architecture we will |
| 4849 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4850 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4851 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4852 | return SideEffects::CanTriggerGC(); |
| 4853 | } |
| 4854 | return SideEffects::None(); |
| 4855 | } |
| 4856 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4857 | DECLARE_INSTRUCTION(TypeConversion); |
| 4858 | |
| 4859 | private: |
| 4860 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4861 | }; |
| 4862 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4863 | static constexpr uint32_t kNoRegNumber = -1; |
| 4864 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4865 | class HPhi : public HInstruction { |
| 4866 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4867 | HPhi(ArenaAllocator* arena, |
| 4868 | uint32_t reg_number, |
| 4869 | size_t number_of_inputs, |
| 4870 | Primitive::Type type, |
| 4871 | uint32_t dex_pc = kNoDexPc) |
| 4872 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4873 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4874 | reg_number_(reg_number) { |
| 4875 | SetPackedField<TypeField>(ToPhiType(type)); |
| 4876 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 4877 | // Phis are constructed live and marked dead if conflicting or unused. |
| 4878 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 4879 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 4880 | SetPackedFlag<kFlagIsLive>(true); |
| 4881 | SetPackedFlag<kFlagCanBeNull>(true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4882 | } |
| 4883 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4884 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4885 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4886 | switch (type) { |
| 4887 | case Primitive::kPrimBoolean: |
| 4888 | case Primitive::kPrimByte: |
| 4889 | case Primitive::kPrimShort: |
| 4890 | case Primitive::kPrimChar: |
| 4891 | return Primitive::kPrimInt; |
| 4892 | default: |
| 4893 | return type; |
| 4894 | } |
| 4895 | } |
| 4896 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4897 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4898 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4899 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4900 | |
| 4901 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4902 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4903 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4904 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4905 | void SetType(Primitive::Type new_type) { |
| 4906 | // Make sure that only valid type changes occur. The following are allowed: |
| 4907 | // (1) int -> float/ref (primitive type propagation), |
| 4908 | // (2) long -> double (primitive type propagation). |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4909 | DCHECK(GetType() == new_type || |
| 4910 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 4911 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 4912 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 4913 | SetPackedField<TypeField>(new_type); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 4914 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4915 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4916 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4917 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4918 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4919 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4920 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4921 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 4922 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 4923 | bool IsDead() const { return !IsLive(); } |
| 4924 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4925 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4926 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4927 | return other != nullptr |
| 4928 | && other->IsPhi() |
| 4929 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4930 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4931 | } |
| 4932 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4933 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4934 | // An equivalent phi is a phi having the same dex register and type. |
| 4935 | // It assumes that phis with the same dex register are adjacent. |
| 4936 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4937 | HInstruction* next = GetNext(); |
| 4938 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4939 | if (next->GetType() == GetType()) { |
| 4940 | return next->AsPhi(); |
| 4941 | } |
| 4942 | next = next->GetNext(); |
| 4943 | } |
| 4944 | return nullptr; |
| 4945 | } |
| 4946 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4947 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4948 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4949 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4950 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4951 | return inputs_[index]; |
| 4952 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4953 | |
| 4954 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4955 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4956 | } |
| 4957 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4958 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4959 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 4960 | static constexpr size_t kFieldTypeSize = |
| 4961 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 4962 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 4963 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 4964 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 4965 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4966 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 4967 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4968 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4969 | const uint32_t reg_number_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4970 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4971 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4972 | }; |
| 4973 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4974 | class HNullCheck : public HExpression<1> { |
| 4975 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4976 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4977 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4978 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4979 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4980 | SetRawInputAt(0, value); |
| 4981 | } |
| 4982 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4983 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4984 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4985 | return true; |
| 4986 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4987 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4988 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4989 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4990 | bool CanThrow() const OVERRIDE { return true; } |
| 4991 | |
| 4992 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4993 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4994 | |
| 4995 | DECLARE_INSTRUCTION(NullCheck); |
| 4996 | |
| 4997 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4998 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4999 | }; |
| 5000 | |
| 5001 | class FieldInfo : public ValueObject { |
| 5002 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5003 | FieldInfo(MemberOffset field_offset, |
| 5004 | Primitive::Type field_type, |
| 5005 | bool is_volatile, |
| 5006 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5007 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5008 | const DexFile& dex_file, |
| 5009 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5010 | : field_offset_(field_offset), |
| 5011 | field_type_(field_type), |
| 5012 | is_volatile_(is_volatile), |
| 5013 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5014 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5015 | dex_file_(dex_file), |
| 5016 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5017 | |
| 5018 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5019 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5020 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5021 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5022 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5023 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5024 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5025 | |
| 5026 | private: |
| 5027 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5028 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5029 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5030 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5031 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5032 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5033 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5034 | }; |
| 5035 | |
| 5036 | class HInstanceFieldGet : public HExpression<1> { |
| 5037 | public: |
| 5038 | HInstanceFieldGet(HInstruction* value, |
| 5039 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5040 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5041 | bool is_volatile, |
| 5042 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5043 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5044 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5045 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5046 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5047 | : HExpression(field_type, |
| 5048 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5049 | dex_pc), |
| 5050 | field_info_(field_offset, |
| 5051 | field_type, |
| 5052 | is_volatile, |
| 5053 | field_idx, |
| 5054 | declaring_class_def_index, |
| 5055 | dex_file, |
| 5056 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5057 | SetRawInputAt(0, value); |
| 5058 | } |
| 5059 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5060 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5061 | |
| 5062 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5063 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 5064 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5065 | } |
| 5066 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5067 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5068 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5069 | } |
| 5070 | |
| 5071 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5072 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5073 | } |
| 5074 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5075 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5076 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5077 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5078 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5079 | |
| 5080 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5081 | |
| 5082 | private: |
| 5083 | const FieldInfo field_info_; |
| 5084 | |
| 5085 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5086 | }; |
| 5087 | |
| 5088 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 5089 | public: |
| 5090 | HInstanceFieldSet(HInstruction* object, |
| 5091 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5092 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5093 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5094 | bool is_volatile, |
| 5095 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5096 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5097 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5098 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5099 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5100 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5101 | dex_pc), |
| 5102 | field_info_(field_offset, |
| 5103 | field_type, |
| 5104 | is_volatile, |
| 5105 | field_idx, |
| 5106 | declaring_class_def_index, |
| 5107 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5108 | dex_cache) { |
| 5109 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5110 | SetRawInputAt(0, object); |
| 5111 | SetRawInputAt(1, value); |
| 5112 | } |
| 5113 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5114 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5115 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5116 | } |
| 5117 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5118 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5119 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5120 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5121 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5122 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5123 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5124 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5125 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5126 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5127 | |
| 5128 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5129 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5130 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5131 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5132 | "Too many packed fields."); |
| 5133 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5134 | const FieldInfo field_info_; |
| 5135 | |
| 5136 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5137 | }; |
| 5138 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5139 | class HArrayGet : public HExpression<2> { |
| 5140 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5141 | HArrayGet(HInstruction* array, |
| 5142 | HInstruction* index, |
| 5143 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5144 | uint32_t dex_pc, |
| 5145 | SideEffects additional_side_effects = SideEffects::None()) |
| 5146 | : HExpression(type, |
| 5147 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
David Brazdil | 2bd4c5c | 2015-11-04 22:48:45 +0000 | [diff] [blame] | 5148 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5149 | SetRawInputAt(0, array); |
| 5150 | SetRawInputAt(1, index); |
| 5151 | } |
| 5152 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5153 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5154 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5155 | return true; |
| 5156 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5157 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5158 | // TODO: We can be smarter here. |
| 5159 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5160 | // which generates the implicit null check. There are cases when these can be removed |
| 5161 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5162 | // implicit check here (as long as the address falls in the first page). |
| 5163 | return false; |
| 5164 | } |
| 5165 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5166 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5167 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5168 | if (kIsDebugBuild && result) { |
| 5169 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5170 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5171 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5172 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5173 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5174 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5175 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5176 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5177 | } |
| 5178 | } |
| 5179 | return result; |
| 5180 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5181 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5182 | HInstruction* GetArray() const { return InputAt(0); } |
| 5183 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5184 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5185 | DECLARE_INSTRUCTION(ArrayGet); |
| 5186 | |
| 5187 | private: |
| 5188 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5189 | }; |
| 5190 | |
| 5191 | class HArraySet : public HTemplateInstruction<3> { |
| 5192 | public: |
| 5193 | HArraySet(HInstruction* array, |
| 5194 | HInstruction* index, |
| 5195 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5196 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5197 | uint32_t dex_pc, |
| 5198 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5199 | : HTemplateInstruction( |
| 5200 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5201 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 5202 | additional_side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5203 | dex_pc) { |
| 5204 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5205 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5206 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5207 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5208 | SetRawInputAt(0, array); |
| 5209 | SetRawInputAt(1, index); |
| 5210 | SetRawInputAt(2, value); |
| 5211 | } |
| 5212 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5213 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5214 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5215 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5216 | } |
| 5217 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5218 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5219 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5220 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5221 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5222 | // TODO: Same as for ArrayGet. |
| 5223 | return false; |
| 5224 | } |
| 5225 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5226 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5227 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5228 | } |
| 5229 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5230 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5231 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5232 | } |
| 5233 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5234 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5235 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5236 | } |
| 5237 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5238 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5239 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5240 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5241 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5242 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5243 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5244 | HInstruction* GetArray() const { return InputAt(0); } |
| 5245 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5246 | HInstruction* GetValue() const { return InputAt(2); } |
| 5247 | |
| 5248 | Primitive::Type GetComponentType() const { |
| 5249 | // The Dex format does not type floating point index operations. Since the |
| 5250 | // `expected_component_type_` is set during building and can therefore not |
| 5251 | // be correct, we also check what is the value type. If it is a floating |
| 5252 | // point type, we must use that type. |
| 5253 | Primitive::Type value_type = GetValue()->GetType(); |
| 5254 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5255 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5256 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5257 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5258 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5259 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5260 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5261 | } |
| 5262 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5263 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5264 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5265 | } |
| 5266 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5267 | DECLARE_INSTRUCTION(ArraySet); |
| 5268 | |
| 5269 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5270 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5271 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5272 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5273 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5274 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5275 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5276 | // Cached information for the reference_type_info_ so that codegen |
| 5277 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5278 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5279 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5280 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5281 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5282 | using ExpectedComponentTypeField = |
| 5283 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5284 | |
| 5285 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5286 | }; |
| 5287 | |
| 5288 | class HArrayLength : public HExpression<1> { |
| 5289 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 5290 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5291 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5292 | // Note that arrays do not change length, so the instruction does not |
| 5293 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5294 | SetRawInputAt(0, array); |
| 5295 | } |
| 5296 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5297 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5298 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5299 | return true; |
| 5300 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5301 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5302 | return obj == InputAt(0); |
| 5303 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5304 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5305 | DECLARE_INSTRUCTION(ArrayLength); |
| 5306 | |
| 5307 | private: |
| 5308 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5309 | }; |
| 5310 | |
| 5311 | class HBoundsCheck : public HExpression<2> { |
| 5312 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5313 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5314 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5315 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5316 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5317 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 5318 | SetRawInputAt(0, index); |
| 5319 | SetRawInputAt(1, length); |
| 5320 | } |
| 5321 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5322 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5323 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5324 | return true; |
| 5325 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5326 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5327 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5328 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5329 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5330 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5331 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5332 | |
| 5333 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5334 | |
| 5335 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5336 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5337 | }; |
| 5338 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5339 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 5340 | public: |
| 5341 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5342 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5343 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5344 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5345 | return true; |
| 5346 | } |
| 5347 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5348 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5349 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5350 | |
| 5351 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5352 | |
| 5353 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5354 | // Only used for code generation, in order to share the same slow path between back edges |
| 5355 | // of a same loop. |
| 5356 | SlowPathCode* slow_path_; |
| 5357 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5358 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5359 | }; |
| 5360 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5361 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5362 | // It ensures that we can generate line number and local variables at this point. |
| 5363 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5364 | public: |
| 5365 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5366 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5367 | |
| 5368 | bool NeedsEnvironment() const OVERRIDE { |
| 5369 | return true; |
| 5370 | } |
| 5371 | |
| 5372 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5373 | |
| 5374 | private: |
| 5375 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5376 | }; |
| 5377 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5378 | /** |
| 5379 | * Instruction to load a Class object. |
| 5380 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5381 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5382 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5383 | HLoadClass(HCurrentMethod* current_method, |
| 5384 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5385 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5386 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5387 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5388 | bool needs_access_check, |
| 5389 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5390 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5391 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5392 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5393 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5394 | // Referrers class should not need access check. We never inline unverified |
| 5395 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5396 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5397 | |
| 5398 | SetPackedFlag<kFlagIsReferrersClass>(is_referrers_class); |
| 5399 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5400 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
| 5401 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5402 | SetRawInputAt(0, current_method); |
| 5403 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5404 | |
| 5405 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5406 | |
| 5407 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5408 | // Note that we don't need to test for generate_clinit_check_. |
| 5409 | // Whether or not we need to generate the clinit check is processed in |
| 5410 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5411 | return other->AsLoadClass()->type_index_ == type_index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5412 | other->AsLoadClass()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5413 | } |
| 5414 | |
| 5415 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5416 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5417 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5418 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5419 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5420 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5421 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5422 | } |
| 5423 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5424 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5425 | // The entrypoint the code generator is going to call does not do |
| 5426 | // clinit of the class. |
| 5427 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5428 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
| 5431 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5432 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5433 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5434 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5435 | } |
| 5436 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5437 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5438 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5439 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5440 | } |
| 5441 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5442 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5443 | return loaded_class_rti_; |
| 5444 | } |
| 5445 | |
| 5446 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5447 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5448 | DCHECK(rti.IsExact()); |
| 5449 | loaded_class_rti_ = rti; |
| 5450 | } |
| 5451 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5452 | const DexFile& GetDexFile() { return dex_file_; } |
| 5453 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5454 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5455 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5456 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5457 | return SideEffects::CanTriggerGC(); |
| 5458 | } |
| 5459 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5460 | bool IsReferrersClass() const { return GetPackedFlag<kFlagIsReferrersClass>(); } |
| 5461 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5462 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5463 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5464 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5465 | DECLARE_INSTRUCTION(LoadClass); |
| 5466 | |
| 5467 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5468 | static constexpr size_t kFlagIsReferrersClass = kNumberOfExpressionPackedBits; |
| 5469 | static constexpr size_t kFlagNeedsAccessCheck = kFlagIsReferrersClass + 1; |
| 5470 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5471 | // Whether this instruction must generate the initialization check. |
| 5472 | // Used for code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5473 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInDexCache + 1; |
| 5474 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagGenerateClInitCheck + 1; |
| 5475 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5476 | |
| 5477 | const uint16_t type_index_; |
| 5478 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5479 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5480 | ReferenceTypeInfo loaded_class_rti_; |
| 5481 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5482 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5483 | }; |
| 5484 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5485 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5486 | public: |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5487 | HLoadString(HCurrentMethod* current_method, |
| 5488 | uint32_t string_index, |
| 5489 | uint32_t dex_pc, |
| 5490 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5491 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5492 | string_index_(string_index) { |
| 5493 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5494 | SetRawInputAt(0, current_method); |
| 5495 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5496 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5497 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5498 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5499 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 5500 | return other->AsLoadString()->string_index_ == string_index_; |
| 5501 | } |
| 5502 | |
| 5503 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5504 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5505 | uint32_t GetStringIndex() const { return string_index_; } |
| 5506 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5507 | // Will call the runtime if the string is not already in the dex cache. |
| 5508 | bool NeedsEnvironment() const OVERRIDE { return !IsInDexCache(); } |
| 5509 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 5510 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5511 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5512 | bool CanThrow() const OVERRIDE { return !IsInDexCache(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5513 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5514 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5515 | return SideEffects::CanTriggerGC(); |
| 5516 | } |
| 5517 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5518 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5519 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5520 | DECLARE_INSTRUCTION(LoadString); |
| 5521 | |
| 5522 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5523 | static constexpr size_t kFlagIsInDexCache = kNumberOfExpressionPackedBits; |
| 5524 | static constexpr size_t kNumberOfLoadStringPackedBits = kFlagIsInDexCache + 1; |
| 5525 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5526 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5527 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5528 | |
| 5529 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5530 | }; |
| 5531 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5532 | /** |
| 5533 | * Performs an initialization check on its Class object input. |
| 5534 | */ |
| 5535 | class HClinitCheck : public HExpression<1> { |
| 5536 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5537 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5538 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5539 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5540 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5541 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5542 | SetRawInputAt(0, constant); |
| 5543 | } |
| 5544 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5545 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5546 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5547 | return true; |
| 5548 | } |
| 5549 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5550 | bool NeedsEnvironment() const OVERRIDE { |
| 5551 | // May call runtime to initialize the class. |
| 5552 | return true; |
| 5553 | } |
| 5554 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5555 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5556 | |
| 5557 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5558 | |
| 5559 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5560 | |
| 5561 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5562 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5563 | }; |
| 5564 | |
| 5565 | class HStaticFieldGet : public HExpression<1> { |
| 5566 | public: |
| 5567 | HStaticFieldGet(HInstruction* cls, |
| 5568 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5569 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5570 | bool is_volatile, |
| 5571 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5572 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5573 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5574 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5575 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5576 | : HExpression(field_type, |
| 5577 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5578 | dex_pc), |
| 5579 | field_info_(field_offset, |
| 5580 | field_type, |
| 5581 | is_volatile, |
| 5582 | field_idx, |
| 5583 | declaring_class_def_index, |
| 5584 | dex_file, |
| 5585 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5586 | SetRawInputAt(0, cls); |
| 5587 | } |
| 5588 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5589 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5590 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5591 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5592 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5593 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 5594 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5595 | } |
| 5596 | |
| 5597 | size_t ComputeHashCode() const OVERRIDE { |
| 5598 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5599 | } |
| 5600 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5601 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5602 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5603 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5604 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5605 | |
| 5606 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5607 | |
| 5608 | private: |
| 5609 | const FieldInfo field_info_; |
| 5610 | |
| 5611 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5612 | }; |
| 5613 | |
| 5614 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 5615 | public: |
| 5616 | HStaticFieldSet(HInstruction* cls, |
| 5617 | HInstruction* value, |
| 5618 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5619 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5620 | bool is_volatile, |
| 5621 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5622 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5623 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5624 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5625 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5626 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5627 | dex_pc), |
| 5628 | field_info_(field_offset, |
| 5629 | field_type, |
| 5630 | is_volatile, |
| 5631 | field_idx, |
| 5632 | declaring_class_def_index, |
| 5633 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5634 | dex_cache) { |
| 5635 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5636 | SetRawInputAt(0, cls); |
| 5637 | SetRawInputAt(1, value); |
| 5638 | } |
| 5639 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5640 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5641 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5642 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5643 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5644 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5645 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5646 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5647 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5648 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5649 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5650 | |
| 5651 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5652 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5653 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5654 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5655 | "Too many packed fields."); |
| 5656 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5657 | const FieldInfo field_info_; |
| 5658 | |
| 5659 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5660 | }; |
| 5661 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5662 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 5663 | public: |
| 5664 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5665 | Primitive::Type field_type, |
| 5666 | uint32_t field_index, |
| 5667 | uint32_t dex_pc) |
| 5668 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5669 | field_index_(field_index) { |
| 5670 | SetRawInputAt(0, obj); |
| 5671 | } |
| 5672 | |
| 5673 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5674 | bool CanThrow() const OVERRIDE { return true; } |
| 5675 | |
| 5676 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5677 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5678 | |
| 5679 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5680 | |
| 5681 | private: |
| 5682 | const uint32_t field_index_; |
| 5683 | |
| 5684 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5685 | }; |
| 5686 | |
| 5687 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 5688 | public: |
| 5689 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5690 | HInstruction* value, |
| 5691 | Primitive::Type field_type, |
| 5692 | uint32_t field_index, |
| 5693 | uint32_t dex_pc) |
| 5694 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5695 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5696 | SetPackedField<FieldTypeField>(field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5697 | DCHECK_EQ(field_type, value->GetType()); |
| 5698 | SetRawInputAt(0, obj); |
| 5699 | SetRawInputAt(1, value); |
| 5700 | } |
| 5701 | |
| 5702 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5703 | bool CanThrow() const OVERRIDE { return true; } |
| 5704 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5705 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5706 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5707 | |
| 5708 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5709 | |
| 5710 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5711 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5712 | static constexpr size_t kFieldFieldTypeSize = |
| 5713 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5714 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5715 | kFieldFieldType + kFieldFieldTypeSize; |
| 5716 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5717 | "Too many packed fields."); |
| 5718 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5719 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5720 | const uint32_t field_index_; |
| 5721 | |
| 5722 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5723 | }; |
| 5724 | |
| 5725 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5726 | public: |
| 5727 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5728 | uint32_t field_index, |
| 5729 | uint32_t dex_pc) |
| 5730 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5731 | field_index_(field_index) { |
| 5732 | } |
| 5733 | |
| 5734 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5735 | bool CanThrow() const OVERRIDE { return true; } |
| 5736 | |
| 5737 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5738 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5739 | |
| 5740 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5741 | |
| 5742 | private: |
| 5743 | const uint32_t field_index_; |
| 5744 | |
| 5745 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5746 | }; |
| 5747 | |
| 5748 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5749 | public: |
| 5750 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5751 | Primitive::Type field_type, |
| 5752 | uint32_t field_index, |
| 5753 | uint32_t dex_pc) |
| 5754 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5755 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5756 | SetPackedField<FieldTypeField>(field_type); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5757 | DCHECK_EQ(field_type, value->GetType()); |
| 5758 | SetRawInputAt(0, value); |
| 5759 | } |
| 5760 | |
| 5761 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5762 | bool CanThrow() const OVERRIDE { return true; } |
| 5763 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5764 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5765 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5766 | |
| 5767 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5768 | |
| 5769 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5770 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5771 | static constexpr size_t kFieldFieldTypeSize = |
| 5772 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5773 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5774 | kFieldFieldType + kFieldFieldTypeSize; |
| 5775 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5776 | "Too many packed fields."); |
| 5777 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5778 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5779 | const uint32_t field_index_; |
| 5780 | |
| 5781 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5782 | }; |
| 5783 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5784 | // Implement the move-exception DEX instruction. |
| 5785 | class HLoadException : public HExpression<0> { |
| 5786 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5787 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5788 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5789 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5790 | bool CanBeNull() const OVERRIDE { return false; } |
| 5791 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5792 | DECLARE_INSTRUCTION(LoadException); |
| 5793 | |
| 5794 | private: |
| 5795 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5796 | }; |
| 5797 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5798 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5799 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5800 | class HClearException : public HTemplateInstruction<0> { |
| 5801 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5802 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5803 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5804 | |
| 5805 | DECLARE_INSTRUCTION(ClearException); |
| 5806 | |
| 5807 | private: |
| 5808 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5809 | }; |
| 5810 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5811 | class HThrow : public HTemplateInstruction<1> { |
| 5812 | public: |
| 5813 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5814 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5815 | SetRawInputAt(0, exception); |
| 5816 | } |
| 5817 | |
| 5818 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5819 | |
| 5820 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5821 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5822 | bool CanThrow() const OVERRIDE { return true; } |
| 5823 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5824 | |
| 5825 | DECLARE_INSTRUCTION(Throw); |
| 5826 | |
| 5827 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5828 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5829 | }; |
| 5830 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5831 | /** |
| 5832 | * Implementation strategies for the code generator of a HInstanceOf |
| 5833 | * or `HCheckCast`. |
| 5834 | */ |
| 5835 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5836 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5837 | kExactCheck, // Can do a single class compare. |
| 5838 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5839 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5840 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5841 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5842 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 5843 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5844 | }; |
| 5845 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5846 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 5847 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5848 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5849 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5850 | HInstanceOf(HInstruction* object, |
| 5851 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5852 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5853 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5854 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5855 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5856 | dex_pc) { |
| 5857 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5858 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5859 | SetRawInputAt(0, object); |
| 5860 | SetRawInputAt(1, constant); |
| 5861 | } |
| 5862 | |
| 5863 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5864 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5865 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5866 | return true; |
| 5867 | } |
| 5868 | |
| 5869 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5870 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5871 | } |
| 5872 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5873 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5874 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 5875 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 5876 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 5877 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5878 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5879 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 5880 | // Mips currently does runtime calls for any other checks. |
| 5881 | return check_kind != TypeCheckKind::kExactCheck; |
| 5882 | } |
| 5883 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5884 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5885 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5886 | } |
| 5887 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5888 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5889 | |
| 5890 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5891 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 5892 | static constexpr size_t kFieldTypeCheckKindSize = |
| 5893 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 5894 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 5895 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 5896 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5897 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5898 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5899 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5900 | }; |
| 5901 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5902 | class HBoundType : public HExpression<1> { |
| 5903 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5904 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5905 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5906 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 5907 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 5908 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5909 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5910 | SetRawInputAt(0, input); |
| 5911 | } |
| 5912 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5913 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5914 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5915 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5916 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5917 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5918 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5919 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 5920 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5921 | } |
| 5922 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5923 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5924 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5925 | DECLARE_INSTRUCTION(BoundType); |
| 5926 | |
| 5927 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5928 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5929 | // is false then CanBeNull() cannot be true). |
| 5930 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 5931 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 5932 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 5933 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5934 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5935 | // 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] | 5936 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5937 | // It is used to bound the type in cases like: |
| 5938 | // if (x instanceof ClassX) { |
| 5939 | // // uper_bound_ will be ClassX |
| 5940 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 5941 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5942 | |
| 5943 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5944 | }; |
| 5945 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5946 | class HCheckCast : public HTemplateInstruction<2> { |
| 5947 | public: |
| 5948 | HCheckCast(HInstruction* object, |
| 5949 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5950 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5951 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5952 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 5953 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5954 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5955 | SetRawInputAt(0, object); |
| 5956 | SetRawInputAt(1, constant); |
| 5957 | } |
| 5958 | |
| 5959 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5960 | |
| 5961 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5962 | return true; |
| 5963 | } |
| 5964 | |
| 5965 | bool NeedsEnvironment() const OVERRIDE { |
| 5966 | // Instruction may throw a CheckCastError. |
| 5967 | return true; |
| 5968 | } |
| 5969 | |
| 5970 | bool CanThrow() const OVERRIDE { return true; } |
| 5971 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5972 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 5973 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 5974 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 5975 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5976 | |
| 5977 | DECLARE_INSTRUCTION(CheckCast); |
| 5978 | |
| 5979 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5980 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 5981 | static constexpr size_t kFieldTypeCheckKindSize = |
| 5982 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 5983 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 5984 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 5985 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5986 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5987 | |
| 5988 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5989 | }; |
| 5990 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5991 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5992 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5993 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5994 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5995 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 5996 | SetPackedField<BarrierKindField>(barrier_kind); |
| 5997 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5998 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5999 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6000 | |
| 6001 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6002 | |
| 6003 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6004 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6005 | static constexpr size_t kFieldBarrierKindSize = |
| 6006 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6007 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6008 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6009 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6010 | "Too many packed fields."); |
| 6011 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6012 | |
| 6013 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6014 | }; |
| 6015 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6016 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 6017 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6018 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6019 | kEnter, |
| 6020 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6021 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6022 | }; |
| 6023 | |
| 6024 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6025 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6026 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6027 | dex_pc) { |
| 6028 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6029 | SetRawInputAt(0, object); |
| 6030 | } |
| 6031 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6032 | // Instruction may go into runtime, so we need an environment. |
| 6033 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6034 | |
| 6035 | bool CanThrow() const OVERRIDE { |
| 6036 | // Verifier guarantees that monitor-exit cannot throw. |
| 6037 | // This is important because it allows the HGraphBuilder to remove |
| 6038 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6039 | return IsEnter(); |
| 6040 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6041 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6042 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6043 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6044 | |
| 6045 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6046 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6047 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6048 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6049 | static constexpr size_t kFieldOperationKindSize = |
| 6050 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6051 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6052 | kFieldOperationKind + kFieldOperationKindSize; |
| 6053 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6054 | "Too many packed fields."); |
| 6055 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6056 | |
| 6057 | private: |
| 6058 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6059 | }; |
| 6060 | |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6061 | class HSelect : public HExpression<3> { |
| 6062 | public: |
| 6063 | HSelect(HInstruction* condition, |
| 6064 | HInstruction* true_value, |
| 6065 | HInstruction* false_value, |
| 6066 | uint32_t dex_pc) |
| 6067 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6068 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6069 | |
| 6070 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6071 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6072 | // that architectures which implement HSelect as a conditional move also |
| 6073 | // will not need to invert the condition. |
| 6074 | SetRawInputAt(0, false_value); |
| 6075 | SetRawInputAt(1, true_value); |
| 6076 | SetRawInputAt(2, condition); |
| 6077 | } |
| 6078 | |
| 6079 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6080 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6081 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6082 | |
| 6083 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6084 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
| 6085 | |
| 6086 | bool CanBeNull() const OVERRIDE { |
| 6087 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6088 | } |
| 6089 | |
| 6090 | DECLARE_INSTRUCTION(Select); |
| 6091 | |
| 6092 | private: |
| 6093 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6094 | }; |
| 6095 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6096 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6097 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6098 | MoveOperands(Location source, |
| 6099 | Location destination, |
| 6100 | Primitive::Type type, |
| 6101 | HInstruction* instruction) |
| 6102 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6103 | |
| 6104 | Location GetSource() const { return source_; } |
| 6105 | Location GetDestination() const { return destination_; } |
| 6106 | |
| 6107 | void SetSource(Location value) { source_ = value; } |
| 6108 | void SetDestination(Location value) { destination_ = value; } |
| 6109 | |
| 6110 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6111 | // destination (but not the source). |
| 6112 | Location MarkPending() { |
| 6113 | DCHECK(!IsPending()); |
| 6114 | Location dest = destination_; |
| 6115 | destination_ = Location::NoLocation(); |
| 6116 | return dest; |
| 6117 | } |
| 6118 | |
| 6119 | void ClearPending(Location dest) { |
| 6120 | DCHECK(IsPending()); |
| 6121 | destination_ = dest; |
| 6122 | } |
| 6123 | |
| 6124 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6125 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6126 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | // True if this blocks a move from the given location. |
| 6130 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6131 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6132 | } |
| 6133 | |
| 6134 | // A move is redundant if it's been eliminated, if its source and |
| 6135 | // destination are the same, or if its destination is unneeded. |
| 6136 | bool IsRedundant() const { |
| 6137 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6138 | } |
| 6139 | |
| 6140 | // We clear both operands to indicate move that's been eliminated. |
| 6141 | void Eliminate() { |
| 6142 | source_ = destination_ = Location::NoLocation(); |
| 6143 | } |
| 6144 | |
| 6145 | bool IsEliminated() const { |
| 6146 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6147 | return source_.IsInvalid(); |
| 6148 | } |
| 6149 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6150 | Primitive::Type GetType() const { return type_; } |
| 6151 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6152 | bool Is64BitMove() const { |
| 6153 | return Primitive::Is64BitType(type_); |
| 6154 | } |
| 6155 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6156 | HInstruction* GetInstruction() const { return instruction_; } |
| 6157 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6158 | private: |
| 6159 | Location source_; |
| 6160 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6161 | // The type this move is for. |
| 6162 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6163 | // The instruction this move is assocatied with. Null when this move is |
| 6164 | // for moving an input in the expected locations of user (including a phi user). |
| 6165 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6166 | // in the same parallel move. |
| 6167 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6168 | }; |
| 6169 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6170 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6171 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6172 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6173 | |
| 6174 | class HParallelMove : public HTemplateInstruction<0> { |
| 6175 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6176 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6177 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6178 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6179 | moves_.reserve(kDefaultNumberOfMoves); |
| 6180 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6181 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6182 | void AddMove(Location source, |
| 6183 | Location destination, |
| 6184 | Primitive::Type type, |
| 6185 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6186 | DCHECK(source.IsValid()); |
| 6187 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6188 | if (kIsDebugBuild) { |
| 6189 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6190 | for (const MoveOperands& move : moves_) { |
| 6191 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6192 | // Special case the situation where the move is for the spill slot |
| 6193 | // of the instruction. |
| 6194 | if ((GetPrevious() == instruction) |
| 6195 | || ((GetPrevious() == nullptr) |
| 6196 | && instruction->IsPhi() |
| 6197 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6198 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6199 | << "Doing parallel moves for the same instruction."; |
| 6200 | } else { |
| 6201 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6202 | } |
| 6203 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6204 | } |
| 6205 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6206 | for (const MoveOperands& move : moves_) { |
| 6207 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6208 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6209 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6210 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6211 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6212 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6213 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6214 | } |
| 6215 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6216 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6217 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6218 | } |
| 6219 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6220 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6221 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6222 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6223 | |
| 6224 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6225 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6226 | |
| 6227 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6228 | }; |
| 6229 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6230 | } // namespace art |
| 6231 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6232 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6233 | #include "nodes_shared.h" |
| 6234 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6235 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6236 | #include "nodes_arm.h" |
| 6237 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6238 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6239 | #include "nodes_arm64.h" |
| 6240 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6241 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6242 | #include "nodes_x86.h" |
| 6243 | #endif |
| 6244 | |
| 6245 | namespace art { |
| 6246 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6247 | class HGraphVisitor : public ValueObject { |
| 6248 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6249 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6250 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6251 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6252 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6253 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6254 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6255 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6256 | void VisitInsertionOrder(); |
| 6257 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6258 | // Visit the graph following dominator tree reverse post-order. |
| 6259 | void VisitReversePostOrder(); |
| 6260 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6261 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6262 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6263 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6264 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6265 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6266 | |
| 6267 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6268 | |
| 6269 | #undef DECLARE_VISIT_INSTRUCTION |
| 6270 | |
| 6271 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6272 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6273 | |
| 6274 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6275 | }; |
| 6276 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6277 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6278 | public: |
| 6279 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6280 | virtual ~HGraphDelegateVisitor() {} |
| 6281 | |
| 6282 | // Visit functions that delegate to to super class. |
| 6283 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6284 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6285 | |
| 6286 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6287 | |
| 6288 | #undef DECLARE_VISIT_INSTRUCTION |
| 6289 | |
| 6290 | private: |
| 6291 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6292 | }; |
| 6293 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6294 | class HInsertionOrderIterator : public ValueObject { |
| 6295 | public: |
| 6296 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6297 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6298 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6299 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6300 | void Advance() { ++index_; } |
| 6301 | |
| 6302 | private: |
| 6303 | const HGraph& graph_; |
| 6304 | size_t index_; |
| 6305 | |
| 6306 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6307 | }; |
| 6308 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6309 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6310 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6311 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6312 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6313 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6314 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6315 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6316 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6317 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6318 | void Advance() { ++index_; } |
| 6319 | |
| 6320 | private: |
| 6321 | const HGraph& graph_; |
| 6322 | size_t index_; |
| 6323 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6324 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6325 | }; |
| 6326 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6327 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6328 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6329 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6330 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6331 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6332 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6333 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6334 | |
| 6335 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6336 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6337 | void Advance() { --index_; } |
| 6338 | |
| 6339 | private: |
| 6340 | const HGraph& graph_; |
| 6341 | size_t index_; |
| 6342 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6343 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6344 | }; |
| 6345 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6346 | class HLinearPostOrderIterator : public ValueObject { |
| 6347 | public: |
| 6348 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6349 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6350 | |
| 6351 | bool Done() const { return index_ == 0; } |
| 6352 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6353 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6354 | |
| 6355 | void Advance() { |
| 6356 | --index_; |
| 6357 | DCHECK_GE(index_, 0U); |
| 6358 | } |
| 6359 | |
| 6360 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6361 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6362 | size_t index_; |
| 6363 | |
| 6364 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 6365 | }; |
| 6366 | |
| 6367 | class HLinearOrderIterator : public ValueObject { |
| 6368 | public: |
| 6369 | explicit HLinearOrderIterator(const HGraph& graph) |
| 6370 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 6371 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6372 | bool Done() const { return index_ == order_.size(); } |
| 6373 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6374 | void Advance() { ++index_; } |
| 6375 | |
| 6376 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6377 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6378 | size_t index_; |
| 6379 | |
| 6380 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 6381 | }; |
| 6382 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6383 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6384 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6385 | // block id. |
| 6386 | class HBlocksInLoopIterator : public ValueObject { |
| 6387 | public: |
| 6388 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6389 | : blocks_in_loop_(info.GetBlocks()), |
| 6390 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6391 | index_(0) { |
| 6392 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6393 | Advance(); |
| 6394 | } |
| 6395 | } |
| 6396 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6397 | bool Done() const { return index_ == blocks_.size(); } |
| 6398 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6399 | void Advance() { |
| 6400 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6401 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6402 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6403 | break; |
| 6404 | } |
| 6405 | } |
| 6406 | } |
| 6407 | |
| 6408 | private: |
| 6409 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6410 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6411 | size_t index_; |
| 6412 | |
| 6413 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6414 | }; |
| 6415 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6416 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6417 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6418 | // post order. |
| 6419 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6420 | public: |
| 6421 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6422 | : blocks_in_loop_(info.GetBlocks()), |
| 6423 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6424 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6425 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6426 | Advance(); |
| 6427 | } |
| 6428 | } |
| 6429 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6430 | bool Done() const { return index_ == blocks_.size(); } |
| 6431 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6432 | void Advance() { |
| 6433 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6434 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6435 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6436 | break; |
| 6437 | } |
| 6438 | } |
| 6439 | } |
| 6440 | |
| 6441 | private: |
| 6442 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6443 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6444 | size_t index_; |
| 6445 | |
| 6446 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6447 | }; |
| 6448 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6449 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6450 | if (constant->IsIntConstant()) { |
| 6451 | return constant->AsIntConstant()->GetValue(); |
| 6452 | } else if (constant->IsLongConstant()) { |
| 6453 | return constant->AsLongConstant()->GetValue(); |
| 6454 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6455 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6456 | return 0; |
| 6457 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6458 | } |
| 6459 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6460 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6461 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6462 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6463 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6464 | // times and provide different class resolution but no two class loaders should ever |
| 6465 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6466 | // all sorts of weird failures. |
| 6467 | return &lhs == &rhs; |
| 6468 | } |
| 6469 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6470 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6471 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6472 | inline const H##type* HInstruction::As##type() const { \ |
| 6473 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6474 | } \ |
| 6475 | inline H##type* HInstruction::As##type() { \ |
| 6476 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6477 | } |
| 6478 | |
| 6479 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6480 | #undef INSTRUCTION_TYPE_CHECK |
| 6481 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 6482 | class SwitchTable : public ValueObject { |
| 6483 | public: |
| 6484 | SwitchTable(const Instruction& instruction, uint32_t dex_pc, bool sparse) |
| 6485 | : instruction_(instruction), dex_pc_(dex_pc), sparse_(sparse) { |
| 6486 | int32_t table_offset = instruction.VRegB_31t(); |
| 6487 | const uint16_t* table = reinterpret_cast<const uint16_t*>(&instruction) + table_offset; |
| 6488 | if (sparse) { |
| 6489 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature)); |
| 6490 | } else { |
| 6491 | CHECK_EQ(table[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature)); |
| 6492 | } |
| 6493 | num_entries_ = table[1]; |
| 6494 | values_ = reinterpret_cast<const int32_t*>(&table[2]); |
| 6495 | } |
| 6496 | |
| 6497 | uint16_t GetNumEntries() const { |
| 6498 | return num_entries_; |
| 6499 | } |
| 6500 | |
| 6501 | void CheckIndex(size_t index) const { |
| 6502 | if (sparse_) { |
| 6503 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6504 | DCHECK_LT(index, 2 * static_cast<size_t>(num_entries_)); |
| 6505 | } else { |
| 6506 | // In a packed table, we have the starting key and num_entries_ values. |
| 6507 | DCHECK_LT(index, 1 + static_cast<size_t>(num_entries_)); |
| 6508 | } |
| 6509 | } |
| 6510 | |
| 6511 | int32_t GetEntryAt(size_t index) const { |
| 6512 | CheckIndex(index); |
| 6513 | return values_[index]; |
| 6514 | } |
| 6515 | |
| 6516 | uint32_t GetDexPcForIndex(size_t index) const { |
| 6517 | CheckIndex(index); |
| 6518 | return dex_pc_ + |
| 6519 | (reinterpret_cast<const int16_t*>(values_ + index) - |
| 6520 | reinterpret_cast<const int16_t*>(&instruction_)); |
| 6521 | } |
| 6522 | |
| 6523 | // Index of the first value in the table. |
| 6524 | size_t GetFirstValueIndex() const { |
| 6525 | if (sparse_) { |
| 6526 | // In a sparse table, we have num_entries_ keys and num_entries_ values, in that order. |
| 6527 | return num_entries_; |
| 6528 | } else { |
| 6529 | // In a packed table, we have the starting key and num_entries_ values. |
| 6530 | return 1; |
| 6531 | } |
| 6532 | } |
| 6533 | |
| 6534 | private: |
| 6535 | const Instruction& instruction_; |
| 6536 | const uint32_t dex_pc_; |
| 6537 | |
| 6538 | // Whether this is a sparse-switch table (or a packed-switch one). |
| 6539 | const bool sparse_; |
| 6540 | |
| 6541 | // This can't be const as it needs to be computed off of the given instruction, and complicated |
| 6542 | // expressions in the initializer list seemed very ugly. |
| 6543 | uint16_t num_entries_; |
| 6544 | |
| 6545 | const int32_t* values_; |
| 6546 | |
| 6547 | DISALLOW_COPY_AND_ASSIGN(SwitchTable); |
| 6548 | }; |
| 6549 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6550 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6551 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6552 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6553 | size_t number_of_new_blocks, |
| 6554 | size_t after) { |
| 6555 | DCHECK_LT(after, blocks->size()); |
| 6556 | size_t old_size = blocks->size(); |
| 6557 | size_t new_size = old_size + number_of_new_blocks; |
| 6558 | blocks->resize(new_size); |
| 6559 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6560 | } |
| 6561 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6562 | } // namespace art |
| 6563 | |
| 6564 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |