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" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 39 | #include "utils/intrusive_forward_list.h" |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 40 | #include "utils/transform_array_ref.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 41 | |
| 42 | namespace art { |
| 43 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 44 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 45 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 46 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 47 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 48 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 49 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 50 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 51 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 52 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 53 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 54 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 55 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 56 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 57 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 58 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 59 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 60 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 61 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 62 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 63 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 64 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 65 | namespace mirror { |
| 66 | class DexCache; |
| 67 | } // namespace mirror |
| 68 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 69 | static const int kDefaultNumberOfBlocks = 8; |
| 70 | static const int kDefaultNumberOfSuccessors = 2; |
| 71 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 72 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 73 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 74 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 75 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 76 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 77 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 78 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 79 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 80 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 81 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 82 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 83 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 84 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 85 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 86 | static constexpr uint32_t kNoDexPc = -1; |
| 87 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 88 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 89 | // All types. |
| 90 | kCondEQ, // == |
| 91 | kCondNE, // != |
| 92 | // Signed integers and floating-point numbers. |
| 93 | kCondLT, // < |
| 94 | kCondLE, // <= |
| 95 | kCondGT, // > |
| 96 | kCondGE, // >= |
| 97 | // Unsigned integers. |
| 98 | kCondB, // < |
| 99 | kCondBE, // <= |
| 100 | kCondA, // > |
| 101 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 104 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 105 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 106 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 107 | kAnalysisFailThrowCatchLoop, |
| 108 | kAnalysisFailAmbiguousArrayOp, |
| 109 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 112 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 113 | public: |
| 114 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 115 | |
| 116 | void AddInstruction(HInstruction* instruction); |
| 117 | void RemoveInstruction(HInstruction* instruction); |
| 118 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 119 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 120 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 121 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 122 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 123 | // Return true if this list contains `instruction`. |
| 124 | bool Contains(HInstruction* instruction) const; |
| 125 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 126 | // Return true if `instruction1` is found before `instruction2` in |
| 127 | // this instruction list and false otherwise. Abort if none |
| 128 | // of these instructions is found. |
| 129 | bool FoundBefore(const HInstruction* instruction1, |
| 130 | const HInstruction* instruction2) const; |
| 131 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 132 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 133 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 134 | |
| 135 | // Update the block of all instructions to be `block`. |
| 136 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 137 | |
| 138 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 139 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 140 | void Add(const HInstructionList& instruction_list); |
| 141 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 142 | // Return the number of instructions in the list. This is an expensive operation. |
| 143 | size_t CountSize() const; |
| 144 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 145 | private: |
| 146 | HInstruction* first_instruction_; |
| 147 | HInstruction* last_instruction_; |
| 148 | |
| 149 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 150 | friend class HGraph; |
| 151 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 152 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 153 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 154 | |
| 155 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 156 | }; |
| 157 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 158 | class ReferenceTypeInfo : ValueObject { |
| 159 | public: |
| 160 | typedef Handle<mirror::Class> TypeHandle; |
| 161 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 162 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 163 | |
| 164 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 165 | return ReferenceTypeInfo(type_handle, is_exact); |
| 166 | } |
| 167 | |
| 168 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 169 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 170 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 171 | return handle.GetReference() != nullptr; |
| 172 | } |
| 173 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 174 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 175 | return IsValidHandle(type_handle_); |
| 176 | } |
| 177 | |
| 178 | bool IsExact() const { return is_exact_; } |
| 179 | |
| 180 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 181 | DCHECK(IsValid()); |
| 182 | return GetTypeHandle()->IsObjectClass(); |
| 183 | } |
| 184 | |
| 185 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 186 | DCHECK(IsValid()); |
| 187 | return GetTypeHandle()->IsStringClass(); |
| 188 | } |
| 189 | |
| 190 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 191 | DCHECK(IsValid()); |
| 192 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 193 | } |
| 194 | |
| 195 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 196 | DCHECK(IsValid()); |
| 197 | return GetTypeHandle()->IsInterface(); |
| 198 | } |
| 199 | |
| 200 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 201 | DCHECK(IsValid()); |
| 202 | return GetTypeHandle()->IsArrayClass(); |
| 203 | } |
| 204 | |
| 205 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 206 | DCHECK(IsValid()); |
| 207 | return GetTypeHandle()->IsPrimitiveArray(); |
| 208 | } |
| 209 | |
| 210 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 211 | DCHECK(IsValid()); |
| 212 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 213 | } |
| 214 | |
| 215 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 216 | DCHECK(IsValid()); |
| 217 | if (!IsExact()) return false; |
| 218 | if (!IsArrayClass()) return false; |
| 219 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 220 | } |
| 221 | |
| 222 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 223 | DCHECK(IsValid()); |
| 224 | if (!IsExact()) return false; |
| 225 | if (!IsArrayClass()) return false; |
| 226 | if (!rti.IsArrayClass()) return false; |
| 227 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 228 | rti.GetTypeHandle()->GetComponentType()); |
| 229 | } |
| 230 | |
| 231 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 232 | |
| 233 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 234 | DCHECK(IsValid()); |
| 235 | DCHECK(rti.IsValid()); |
| 236 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 237 | } |
| 238 | |
| 239 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 240 | DCHECK(IsValid()); |
| 241 | DCHECK(rti.IsValid()); |
| 242 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 243 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 244 | } |
| 245 | |
| 246 | // Returns true if the type information provide the same amount of details. |
| 247 | // Note that it does not mean that the instructions have the same actual type |
| 248 | // (because the type can be the result of a merge). |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 249 | bool IsEqual(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 250 | if (!IsValid() && !rti.IsValid()) { |
| 251 | // Invalid types are equal. |
| 252 | return true; |
| 253 | } |
| 254 | if (!IsValid() || !rti.IsValid()) { |
| 255 | // One is valid, the other not. |
| 256 | return false; |
| 257 | } |
| 258 | return IsExact() == rti.IsExact() |
| 259 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 260 | } |
| 261 | |
| 262 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 263 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 264 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 265 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 266 | |
| 267 | // The class of the object. |
| 268 | TypeHandle type_handle_; |
| 269 | // Whether or not the type is exact or a superclass of the actual type. |
| 270 | // Whether or not we have any information about this type. |
| 271 | bool is_exact_; |
| 272 | }; |
| 273 | |
| 274 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 275 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 276 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 277 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 278 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 279 | HGraph(ArenaAllocator* arena, |
| 280 | const DexFile& dex_file, |
| 281 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 282 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 283 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 284 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 285 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 286 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 287 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 288 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 289 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 290 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 291 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 292 | entry_block_(nullptr), |
| 293 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 294 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 295 | number_of_vregs_(0), |
| 296 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 297 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 298 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 299 | has_try_catch_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 300 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 301 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 302 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 303 | dex_file_(dex_file), |
| 304 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 305 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 306 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 307 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 308 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 309 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 310 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 311 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 312 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 313 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 314 | cached_current_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 315 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| 316 | osr_(osr) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 317 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 318 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 319 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 320 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
| 321 | void InitializeInexactObjectRTI(StackHandleScopeCollection* handles); |
| 322 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 323 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 324 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 325 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 326 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 327 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 328 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 329 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 330 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 331 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 332 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 333 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 334 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 335 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 336 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 337 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 338 | void ComputeDominanceInformation(); |
| 339 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 340 | void ClearLoopInformation(); |
| 341 | void FindBackEdges(ArenaBitVector* visited); |
| 342 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 343 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 344 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 345 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 346 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 347 | // 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] | 348 | // 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] | 349 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 350 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 351 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 352 | // order and loop information. |
| 353 | void ComputeTryBlockInformation(); |
| 354 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 355 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 356 | // Returns the instruction to replace the invoke expression or null if the |
| 357 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 358 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 359 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 360 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 361 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 362 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 363 | // should be the new back edge. |
| 364 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 365 | HBasicBlock* reference, |
| 366 | bool replace_if_back_edge); |
| 367 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 368 | // Need to add a couple of blocks to test if the loop body is entered and |
| 369 | // put deoptimization instructions, etc. |
| 370 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 371 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 372 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 373 | // other blocks and has no instructions or phis. |
| 374 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 375 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 376 | // Splits the edge between `block` and `successor` while preserving the |
| 377 | // indices in the predecessor/successor lists. If there are multiple edges |
| 378 | // between the blocks, the lowest indices are used. |
| 379 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 380 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 381 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 382 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 383 | void SimplifyLoop(HBasicBlock* header); |
| 384 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 385 | int32_t GetNextInstructionId() { |
| 386 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 387 | return current_instruction_id_++; |
| 388 | } |
| 389 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 390 | int32_t GetCurrentInstructionId() const { |
| 391 | return current_instruction_id_; |
| 392 | } |
| 393 | |
| 394 | void SetCurrentInstructionId(int32_t id) { |
David Brazdil | 3f52306 | 2016-02-29 16:53:33 +0000 | [diff] [blame] | 395 | DCHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 396 | current_instruction_id_ = id; |
| 397 | } |
| 398 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 399 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 400 | return maximum_number_of_out_vregs_; |
| 401 | } |
| 402 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 403 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 404 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 407 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 408 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 409 | } |
| 410 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 411 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 412 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 413 | } |
| 414 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 415 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 416 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 417 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 418 | } |
| 419 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 420 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 421 | number_of_vregs_ = number_of_vregs; |
| 422 | } |
| 423 | |
| 424 | uint16_t GetNumberOfVRegs() const { |
| 425 | return number_of_vregs_; |
| 426 | } |
| 427 | |
| 428 | void SetNumberOfInVRegs(uint16_t value) { |
| 429 | number_of_in_vregs_ = value; |
| 430 | } |
| 431 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 432 | uint16_t GetNumberOfInVRegs() const { |
| 433 | return number_of_in_vregs_; |
| 434 | } |
| 435 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 436 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 437 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 438 | return number_of_vregs_ - number_of_in_vregs_; |
| 439 | } |
| 440 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 441 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 442 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 443 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 444 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 445 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 446 | return linear_order_; |
| 447 | } |
| 448 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 449 | bool HasBoundsChecks() const { |
| 450 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 453 | void SetHasBoundsChecks(bool value) { |
| 454 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 455 | } |
| 456 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 457 | bool ShouldGenerateConstructorBarrier() const { |
| 458 | return should_generate_constructor_barrier_; |
| 459 | } |
| 460 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 461 | bool IsDebuggable() const { return debuggable_; } |
| 462 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 463 | // 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] | 464 | // already, it is created and inserted into the graph. This method is only for |
| 465 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 466 | 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] | 467 | |
| 468 | // TODO: This is problematic for the consistency of reference type propagation |
| 469 | // because it can be created anytime after the pass and thus it will be left |
| 470 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 471 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 472 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 473 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 474 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 475 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 476 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 477 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 478 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 479 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 480 | 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] | 481 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 482 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 483 | 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] | 484 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 485 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 486 | HCurrentMethod* GetCurrentMethod(); |
| 487 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 488 | const DexFile& GetDexFile() const { |
| 489 | return dex_file_; |
| 490 | } |
| 491 | |
| 492 | uint32_t GetMethodIdx() const { |
| 493 | return method_idx_; |
| 494 | } |
| 495 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 496 | InvokeType GetInvokeType() const { |
| 497 | return invoke_type_; |
| 498 | } |
| 499 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 500 | InstructionSet GetInstructionSet() const { |
| 501 | return instruction_set_; |
| 502 | } |
| 503 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 504 | bool IsCompilingOsr() const { return osr_; } |
| 505 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 506 | bool HasTryCatch() const { return has_try_catch_; } |
| 507 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 508 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 509 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 510 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 511 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 512 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 513 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 514 | |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 515 | // Returns an instruction with the opposite boolean value from 'cond'. |
| 516 | // The instruction has been inserted into the graph, either as a constant, or |
| 517 | // before cursor. |
| 518 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 519 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 520 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 521 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 522 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 523 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 524 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 525 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 526 | template <class InstructionType, typename ValueType> |
| 527 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 528 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 529 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 530 | // Try to find an existing constant of the given value. |
| 531 | InstructionType* constant = nullptr; |
| 532 | auto cached_constant = cache->find(value); |
| 533 | if (cached_constant != cache->end()) { |
| 534 | constant = cached_constant->second; |
| 535 | } |
| 536 | |
| 537 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 538 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 539 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 540 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 541 | cache->Overwrite(value, constant); |
| 542 | InsertConstant(constant); |
| 543 | } |
| 544 | return constant; |
| 545 | } |
| 546 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 547 | void InsertConstant(HConstant* instruction); |
| 548 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 549 | // Cache a float constant into the graph. This method should only be |
| 550 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 551 | void CacheFloatConstant(HFloatConstant* constant); |
| 552 | |
| 553 | // See CacheFloatConstant comment. |
| 554 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 555 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 556 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 557 | |
| 558 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 559 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 560 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 561 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 562 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 563 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 564 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 565 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 566 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 567 | HBasicBlock* entry_block_; |
| 568 | HBasicBlock* exit_block_; |
| 569 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 570 | // 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] | 571 | uint16_t maximum_number_of_out_vregs_; |
| 572 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 573 | // The number of virtual registers in this method. Contains the parameters. |
| 574 | uint16_t number_of_vregs_; |
| 575 | |
| 576 | // The number of virtual registers used by parameters of this method. |
| 577 | uint16_t number_of_in_vregs_; |
| 578 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 579 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 580 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 581 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 582 | // Has bounds checks. We can totally skip BCE if it's false. |
| 583 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 584 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 585 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 586 | // try/catch-related passes if false. |
| 587 | bool has_try_catch_; |
| 588 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 589 | // Flag whether there are any irreducible loops in the graph. |
| 590 | bool has_irreducible_loops_; |
| 591 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 592 | // Indicates whether the graph should be compiled in a way that |
| 593 | // ensures full debuggability. If false, we can apply more |
| 594 | // aggressive optimizations that may limit the level of debugging. |
| 595 | const bool debuggable_; |
| 596 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 597 | // 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] | 598 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 599 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 600 | // The dex file from which the method is from. |
| 601 | const DexFile& dex_file_; |
| 602 | |
| 603 | // The method index in the dex file. |
| 604 | const uint32_t method_idx_; |
| 605 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 606 | // If inlined, this encodes how the callee is being invoked. |
| 607 | const InvokeType invoke_type_; |
| 608 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 609 | // Whether the graph has been transformed to SSA form. Only used |
| 610 | // in debug mode to ensure we are not using properties only valid |
| 611 | // for non-SSA form (like the number of temporaries). |
| 612 | bool in_ssa_form_; |
| 613 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 614 | const bool should_generate_constructor_barrier_; |
| 615 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 616 | const InstructionSet instruction_set_; |
| 617 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 618 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 619 | HNullConstant* cached_null_constant_; |
| 620 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 621 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 622 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 623 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 624 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 625 | HCurrentMethod* cached_current_method_; |
| 626 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 627 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 628 | // for example for methods whose declaring class could not be resolved |
| 629 | // (such as when the superclass could not be found). |
| 630 | ArtMethod* art_method_; |
| 631 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 632 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 633 | // collection pointer to passes which may create NullConstant. |
| 634 | ReferenceTypeInfo inexact_object_rti_; |
| 635 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 636 | // Whether we are compiling this graph for on stack replacement: this will |
| 637 | // make all loops seen as irreducible and emit special stack maps to mark |
| 638 | // compiled code entries which the interpreter can directly jump to. |
| 639 | const bool osr_; |
| 640 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 641 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 642 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 643 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 644 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 645 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 646 | }; |
| 647 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 648 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 649 | public: |
| 650 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 651 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 652 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 653 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 654 | contains_irreducible_loop_(false), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 655 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 656 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | f6a35de | 2016-03-21 12:01:50 +0000 | [diff] [blame] | 657 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true, kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 658 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 659 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 660 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 661 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 662 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 663 | |
| 664 | void Dump(std::ostream& os); |
| 665 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 666 | HBasicBlock* GetHeader() const { |
| 667 | return header_; |
| 668 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 669 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 670 | void SetHeader(HBasicBlock* block) { |
| 671 | header_ = block; |
| 672 | } |
| 673 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 674 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 675 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 676 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 677 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 678 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 679 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 682 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 683 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 684 | } |
| 685 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 686 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 687 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 688 | } |
| 689 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 690 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 691 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 692 | } |
| 693 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 694 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 695 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 696 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 697 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 700 | // Returns the lifetime position of the back edge that has the |
| 701 | // greatest lifetime position. |
| 702 | size_t GetLifetimeEnd() const; |
| 703 | |
| 704 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 705 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 708 | // Finds blocks that are part of this loop. |
| 709 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 710 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 711 | // Returns whether this loop information contains `block`. |
| 712 | // Note that this loop information *must* be populated before entering this function. |
| 713 | bool Contains(const HBasicBlock& block) const; |
| 714 | |
| 715 | // Returns whether this loop information is an inner loop of `other`. |
| 716 | // Note that `other` *must* be populated before entering this function. |
| 717 | bool IsIn(const HLoopInformation& other) const; |
| 718 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 719 | // Returns true if instruction is not defined within this loop. |
| 720 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 721 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 722 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 723 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 724 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 725 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 726 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 727 | void ClearAllBlocks() { |
| 728 | blocks_.ClearAllBits(); |
| 729 | } |
| 730 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 731 | bool HasBackEdgeNotDominatedByHeader() const; |
| 732 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 733 | bool IsPopulated() const { |
| 734 | return blocks_.GetHighestBitSet() != -1; |
| 735 | } |
| 736 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 737 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 738 | // Internal recursive implementation of `Populate`. |
| 739 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 740 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 741 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 742 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 743 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 744 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 745 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 746 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 747 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 748 | |
| 749 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 750 | }; |
| 751 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 752 | // Stores try/catch information for basic blocks. |
| 753 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 754 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 755 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 756 | public: |
| 757 | // Try block information constructor. |
| 758 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 759 | : try_entry_(&try_entry), |
| 760 | catch_dex_file_(nullptr), |
| 761 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 762 | DCHECK(try_entry_ != nullptr); |
| 763 | } |
| 764 | |
| 765 | // Catch block information constructor. |
| 766 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 767 | : try_entry_(nullptr), |
| 768 | catch_dex_file_(&dex_file), |
| 769 | catch_type_index_(catch_type_index) {} |
| 770 | |
| 771 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 772 | |
| 773 | const HTryBoundary& GetTryEntry() const { |
| 774 | DCHECK(IsTryBlock()); |
| 775 | return *try_entry_; |
| 776 | } |
| 777 | |
| 778 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 779 | |
| 780 | bool IsCatchAllTypeIndex() const { |
| 781 | DCHECK(IsCatchBlock()); |
| 782 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 783 | } |
| 784 | |
| 785 | uint16_t GetCatchTypeIndex() const { |
| 786 | DCHECK(IsCatchBlock()); |
| 787 | return catch_type_index_; |
| 788 | } |
| 789 | |
| 790 | const DexFile& GetCatchDexFile() const { |
| 791 | DCHECK(IsCatchBlock()); |
| 792 | return *catch_dex_file_; |
| 793 | } |
| 794 | |
| 795 | private: |
| 796 | // One of possibly several TryBoundary instructions entering the block's try. |
| 797 | // Only set for try blocks. |
| 798 | const HTryBoundary* try_entry_; |
| 799 | |
| 800 | // Exception type information. Only set for catch blocks. |
| 801 | const DexFile* catch_dex_file_; |
| 802 | const uint16_t catch_type_index_; |
| 803 | }; |
| 804 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 805 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 806 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 807 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 808 | // A block in a method. Contains the list of instructions represented |
| 809 | // as a double linked list. Each block knows its predecessors and |
| 810 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 811 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 812 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 813 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 814 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 815 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 816 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 817 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 818 | loop_information_(nullptr), |
| 819 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 820 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 821 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 822 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 823 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 824 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 825 | try_catch_information_(nullptr) { |
| 826 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 827 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 828 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 829 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 830 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 831 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 832 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 835 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 836 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 837 | } |
| 838 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 839 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 840 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 841 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 842 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 843 | return ContainsElement(successors_, block, start_from); |
| 844 | } |
| 845 | |
| 846 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 847 | return dominated_blocks_; |
| 848 | } |
| 849 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 850 | bool IsEntryBlock() const { |
| 851 | return graph_->GetEntryBlock() == this; |
| 852 | } |
| 853 | |
| 854 | bool IsExitBlock() const { |
| 855 | return graph_->GetExitBlock() == this; |
| 856 | } |
| 857 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 858 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 859 | bool IsSingleTryBoundary() const; |
| 860 | |
| 861 | // Returns true if this block emits nothing but a jump. |
| 862 | bool IsSingleJump() const { |
| 863 | HLoopInformation* loop_info = GetLoopInformation(); |
| 864 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 865 | // Back edges generate a suspend check. |
| 866 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 867 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 868 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 869 | void AddBackEdge(HBasicBlock* back_edge) { |
| 870 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 871 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 872 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 873 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 874 | loop_information_->AddBackEdge(back_edge); |
| 875 | } |
| 876 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 877 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 878 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 879 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 880 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 881 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 882 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 883 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 884 | HBasicBlock* GetDominator() const { return dominator_; } |
| 885 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 886 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 887 | |
| 888 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 889 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 890 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 891 | |
| 892 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 893 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 894 | } |
| 895 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 896 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 897 | |
| 898 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 899 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 902 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 903 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 904 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 905 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 906 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 907 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 908 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 909 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 910 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 911 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 912 | successors_.push_back(block); |
| 913 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 914 | } |
| 915 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 916 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 917 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 918 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 919 | new_block->predecessors_.push_back(this); |
| 920 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 923 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 924 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 925 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 926 | new_block->successors_.push_back(this); |
| 927 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 930 | // Insert `this` between `predecessor` and `successor. This method |
| 931 | // preserves the indicies, and will update the first edge found between |
| 932 | // `predecessor` and `successor`. |
| 933 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 934 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 935 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 936 | successor->predecessors_[predecessor_index] = this; |
| 937 | predecessor->successors_[successor_index] = this; |
| 938 | successors_.push_back(successor); |
| 939 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 940 | } |
| 941 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 942 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 943 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 944 | } |
| 945 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 946 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 947 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 950 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 951 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 955 | predecessors_.push_back(block); |
| 956 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 957 | } |
| 958 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 959 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 960 | DCHECK_EQ(predecessors_.size(), 2u); |
| 961 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 962 | } |
| 963 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 964 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 965 | DCHECK_EQ(successors_.size(), 2u); |
| 966 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 967 | } |
| 968 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 969 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 970 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 971 | } |
| 972 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 973 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 974 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 975 | } |
| 976 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 977 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 978 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 979 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 983 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 984 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | // Returns whether the first occurrence of `predecessor` in the list of |
| 988 | // predecessors is at index `idx`. |
| 989 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 990 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 991 | return GetPredecessorIndexOf(predecessor) == idx; |
| 992 | } |
| 993 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 994 | // Create a new block between this block and its predecessors. The new block |
| 995 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 996 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 997 | // loop and try/catch information are not updated. |
| 998 | HBasicBlock* CreateImmediateDominator(); |
| 999 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1000 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1001 | // created, latter block. Note that this method will add the block to the |
| 1002 | // graph, create a Goto at the end of the former block and will create an edge |
| 1003 | // 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] | 1004 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1005 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1006 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1007 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1008 | // created block. Note that this method just updates raw block information, |
| 1009 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1010 | // update the graph, reverse post order, loop information, nor make sure the |
| 1011 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1012 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1013 | |
| 1014 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1015 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1016 | |
| 1017 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1018 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1019 | // that this method does not update the graph, reverse post order, loop |
| 1020 | // information, nor make sure the blocks are consistent (for example ending |
| 1021 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1022 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1023 | |
| 1024 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1025 | // of `this` are moved to `other`. |
| 1026 | // Note that this method does not update the graph, reverse post order, loop |
| 1027 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1028 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1029 | void ReplaceWith(HBasicBlock* other); |
| 1030 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1031 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1032 | // order, links to predecessors, successors, dominators and deletes the block |
| 1033 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1034 | // predecessor of `other` and vice versa. |
| 1035 | void MergeWith(HBasicBlock* other); |
| 1036 | |
| 1037 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1038 | // removes it from all loops it is included in and eventually from the graph. |
| 1039 | // The block must not dominate any other block. Predecessors and successors |
| 1040 | // are safely updated. |
| 1041 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1042 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1043 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1044 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1045 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1046 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1047 | // Replace instruction `initial` with `replacement` within this block. |
| 1048 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1049 | HInstruction* replacement); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1050 | void MoveInstructionBefore(HInstruction* insn, HInstruction* cursor); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1051 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1052 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1053 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1054 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1055 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1056 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1057 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1058 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1059 | |
| 1060 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1061 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1064 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1065 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1066 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1067 | } |
| 1068 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1069 | bool IsFirstPredecessorBackEdge() const { |
| 1070 | DCHECK(IsLoopHeader()); |
| 1071 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1072 | } |
| 1073 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1074 | HLoopInformation* GetLoopInformation() const { |
| 1075 | return loop_information_; |
| 1076 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1077 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1078 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1079 | // 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] | 1080 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1081 | void SetInLoop(HLoopInformation* info) { |
| 1082 | if (IsLoopHeader()) { |
| 1083 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1084 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1085 | loop_information_ = info; |
| 1086 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1087 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1088 | // Note that a non loop header having a loop information means this loop information |
| 1089 | // has already been populated |
| 1090 | loop_information_ = info; |
| 1091 | } else { |
| 1092 | // Block is part of an inner loop. Do not update the loop information. |
| 1093 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1094 | // at this point, because this method is being called while populating `info`. |
| 1095 | } |
| 1096 | } |
| 1097 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1098 | // Raw update of the loop information. |
| 1099 | void SetLoopInformation(HLoopInformation* info) { |
| 1100 | loop_information_ = info; |
| 1101 | } |
| 1102 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1103 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1104 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1105 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1106 | |
| 1107 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1108 | try_catch_information_ = try_catch_information; |
| 1109 | } |
| 1110 | |
| 1111 | bool IsTryBlock() const { |
| 1112 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1113 | } |
| 1114 | |
| 1115 | bool IsCatchBlock() const { |
| 1116 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1117 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1118 | |
| 1119 | // Returns the try entry that this block's successors should have. They will |
| 1120 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1121 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1122 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1123 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1124 | bool HasThrowingInstructions() const; |
| 1125 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1126 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1127 | bool Dominates(HBasicBlock* block) const; |
| 1128 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1129 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1130 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1131 | |
| 1132 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1133 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1134 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1135 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1136 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1137 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1138 | bool HasSinglePhi() const; |
| 1139 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1140 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1141 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1142 | ArenaVector<HBasicBlock*> predecessors_; |
| 1143 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1144 | HInstructionList instructions_; |
| 1145 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1146 | HLoopInformation* loop_information_; |
| 1147 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1148 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1149 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1150 | // The dex program counter of the first instruction of this block. |
| 1151 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1152 | size_t lifetime_start_; |
| 1153 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1154 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1155 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1156 | friend class HGraph; |
| 1157 | friend class HInstruction; |
| 1158 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1159 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1160 | }; |
| 1161 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1162 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1163 | // from the innermost to the outermost. |
| 1164 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1165 | public: |
| 1166 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1167 | : current_(block.GetLoopInformation()) {} |
| 1168 | |
| 1169 | bool Done() const { return current_ == nullptr; } |
| 1170 | |
| 1171 | void Advance() { |
| 1172 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1173 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | HLoopInformation* Current() const { |
| 1177 | DCHECK(!Done()); |
| 1178 | return current_; |
| 1179 | } |
| 1180 | |
| 1181 | private: |
| 1182 | HLoopInformation* current_; |
| 1183 | |
| 1184 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1185 | }; |
| 1186 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1187 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1188 | M(Above, Condition) \ |
| 1189 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1190 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1191 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1192 | M(ArrayGet, Instruction) \ |
| 1193 | M(ArrayLength, Instruction) \ |
| 1194 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1195 | M(Below, Condition) \ |
| 1196 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1197 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1198 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1199 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1200 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1201 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1202 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1203 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1204 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1205 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1206 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1207 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1208 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1209 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1210 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1211 | M(Exit, Instruction) \ |
| 1212 | M(FloatConstant, Constant) \ |
| 1213 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1214 | M(GreaterThan, Condition) \ |
| 1215 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1216 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1217 | M(InstanceFieldGet, Instruction) \ |
| 1218 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1219 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1220 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1221 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1222 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1223 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1224 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1225 | M(LessThan, Condition) \ |
| 1226 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1227 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1228 | M(LoadException, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1229 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1230 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1231 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1232 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1233 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1234 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1235 | M(Neg, UnaryOperation) \ |
| 1236 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1237 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1238 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1239 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1240 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1241 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1242 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1243 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1244 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1245 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1246 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1247 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1248 | M(Return, Instruction) \ |
| 1249 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1250 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1251 | M(Shl, BinaryOperation) \ |
| 1252 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1253 | M(StaticFieldGet, Instruction) \ |
| 1254 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1255 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1256 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1257 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1258 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1259 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1260 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1261 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1262 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1263 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1264 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1265 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1266 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1267 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1268 | /* |
| 1269 | * Instructions, shared across several (not all) architectures. |
| 1270 | */ |
| 1271 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1272 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1273 | #else |
| 1274 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1275 | M(BitwiseNegatedRight, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1276 | M(MultiplyAccumulate, Instruction) |
| 1277 | #endif |
| 1278 | |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1279 | #ifndef ART_ENABLE_CODEGEN_arm |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1280 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 1281 | #else |
| 1282 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1283 | M(ArmDexCacheArraysBase, Instruction) |
| 1284 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1285 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1286 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1287 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1288 | #else |
| 1289 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | 8626b74 | 2015-11-25 16:28:08 +0000 | [diff] [blame] | 1290 | M(Arm64DataProcWithShifterOp, Instruction) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1291 | M(Arm64IntermediateAddress, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1292 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1293 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1294 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1295 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1296 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1297 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1298 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1299 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1300 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1301 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1302 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1303 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1304 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1305 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1306 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1307 | |
| 1308 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1309 | |
| 1310 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1311 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1312 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1313 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1314 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1315 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1316 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1317 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1318 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1319 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1320 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1321 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1322 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1323 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1324 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1325 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1326 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1327 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1328 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1329 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1330 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1331 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1332 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1333 | #undef FORWARD_DECLARATION |
| 1334 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 1335 | #define DECLARE_INSTRUCTION(type) \ |
| 1336 | InstructionKind GetKindInternal() const OVERRIDE { return k##type; } \ |
| 1337 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1338 | bool InstructionTypeEquals(const HInstruction* other) const OVERRIDE { \ |
| 1339 | return other->Is##type(); \ |
| 1340 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1341 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1342 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1343 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| 1344 | bool Is##type() const { return As##type() != nullptr; } \ |
| 1345 | const H##type* As##type() const { return this; } \ |
| 1346 | H##type* As##type() { return this; } |
| 1347 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1348 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1349 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1350 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1351 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1352 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1353 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1354 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1355 | // Hook for the IntrusiveForwardList<>. |
| 1356 | // TODO: Hide this better. |
| 1357 | IntrusiveForwardListHook hook; |
| 1358 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1359 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1360 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1361 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1362 | |
| 1363 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1364 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1365 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1366 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1367 | |
| 1368 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1369 | }; |
| 1370 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1371 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1372 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1373 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1374 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1375 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1376 | // by the used instructions. |
| 1377 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1378 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1379 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1380 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1381 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1382 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1383 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1384 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1385 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1386 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1387 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1391 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1392 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1393 | |
| 1394 | private: |
| 1395 | // Instruction used by the user. |
| 1396 | HInstruction* instruction_; |
| 1397 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1398 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1399 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1400 | }; |
| 1401 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1402 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1403 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1404 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1405 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1406 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1407 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1408 | * modify the value of a reference field read [although it may modify the |
| 1409 | * reference fetch prior to reading the field, which is represented by its own |
| 1410 | * write/read dependence]). The analysis makes conservative points-to |
| 1411 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1412 | * the same, and any reference read depends on any reference read without |
| 1413 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1414 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1415 | * The internal representation uses 38-bit and is described in the table below. |
| 1416 | * The first line indicates the side effect, and for field/array accesses the |
| 1417 | * second line indicates the type of the access (in the order of the |
| 1418 | * Primitive::Type enum). |
| 1419 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1420 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1421 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1422 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1423 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1424 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1425 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1426 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1427 | * |
| 1428 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1429 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1430 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1431 | class SideEffects : public ValueObject { |
| 1432 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1433 | SideEffects() : flags_(0) {} |
| 1434 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1435 | static SideEffects None() { |
| 1436 | return SideEffects(0); |
| 1437 | } |
| 1438 | |
| 1439 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1440 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1441 | } |
| 1442 | |
| 1443 | static SideEffects AllChanges() { |
| 1444 | return SideEffects(kAllChangeBits); |
| 1445 | } |
| 1446 | |
| 1447 | static SideEffects AllDependencies() { |
| 1448 | return SideEffects(kAllDependOnBits); |
| 1449 | } |
| 1450 | |
| 1451 | static SideEffects AllExceptGCDependency() { |
| 1452 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1453 | } |
| 1454 | |
| 1455 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1456 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1457 | } |
| 1458 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1459 | static SideEffects AllWrites() { |
| 1460 | return SideEffects(kAllWrites); |
| 1461 | } |
| 1462 | |
| 1463 | static SideEffects AllReads() { |
| 1464 | return SideEffects(kAllReads); |
| 1465 | } |
| 1466 | |
| 1467 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1468 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1469 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1470 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1473 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1474 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1475 | } |
| 1476 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1477 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1478 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1479 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1480 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1484 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1485 | } |
| 1486 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1487 | static SideEffects CanTriggerGC() { |
| 1488 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1489 | } |
| 1490 | |
| 1491 | static SideEffects DependsOnGC() { |
| 1492 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1493 | } |
| 1494 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1495 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1496 | SideEffects Union(SideEffects other) const { |
| 1497 | return SideEffects(flags_ | other.flags_); |
| 1498 | } |
| 1499 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1500 | SideEffects Exclusion(SideEffects other) const { |
| 1501 | return SideEffects(flags_ & ~other.flags_); |
| 1502 | } |
| 1503 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1504 | void Add(SideEffects other) { |
| 1505 | flags_ |= other.flags_; |
| 1506 | } |
| 1507 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1508 | bool Includes(SideEffects other) const { |
| 1509 | return (other.flags_ & flags_) == other.flags_; |
| 1510 | } |
| 1511 | |
| 1512 | bool HasSideEffects() const { |
| 1513 | return (flags_ & kAllChangeBits); |
| 1514 | } |
| 1515 | |
| 1516 | bool HasDependencies() const { |
| 1517 | return (flags_ & kAllDependOnBits); |
| 1518 | } |
| 1519 | |
| 1520 | // Returns true if there are no side effects or dependencies. |
| 1521 | bool DoesNothing() const { |
| 1522 | return flags_ == 0; |
| 1523 | } |
| 1524 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1525 | // Returns true if something is written. |
| 1526 | bool DoesAnyWrite() const { |
| 1527 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1528 | } |
| 1529 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1530 | // Returns true if something is read. |
| 1531 | bool DoesAnyRead() const { |
| 1532 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1533 | } |
| 1534 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1535 | // Returns true if potentially everything is written and read |
| 1536 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1537 | bool DoesAllReadWrite() const { |
| 1538 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1539 | } |
| 1540 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1541 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1542 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1545 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1546 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1547 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1548 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1552 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1553 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1554 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1555 | for (int s = kLastBit; s >= 0; s--) { |
| 1556 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1557 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1558 | // This is a bit for the GC side effect. |
| 1559 | if (current_bit_is_set) { |
| 1560 | flags += "GC"; |
| 1561 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1562 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1563 | } else { |
| 1564 | // This is a bit for the array/field analysis. |
| 1565 | // The underscore character stands for the 'can trigger GC' bit. |
| 1566 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1567 | if (current_bit_is_set) { |
| 1568 | flags += kDebug[s]; |
| 1569 | } |
| 1570 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1571 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1572 | flags += "|"; |
| 1573 | } |
| 1574 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1575 | } |
| 1576 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1577 | } |
| 1578 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1579 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1580 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1581 | private: |
| 1582 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1583 | |
| 1584 | static constexpr int kFieldWriteOffset = 0; |
| 1585 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1586 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1587 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1588 | |
| 1589 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1590 | |
| 1591 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1592 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1593 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1594 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1595 | |
| 1596 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1597 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1598 | |
| 1599 | // Aliases. |
| 1600 | |
| 1601 | static_assert(kChangeBits == kDependOnBits, |
| 1602 | "the 'change' bits should match the 'depend on' bits."); |
| 1603 | |
| 1604 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1605 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1606 | static constexpr uint64_t kAllWrites = |
| 1607 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1608 | static constexpr uint64_t kAllReads = |
| 1609 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1610 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1611 | // Translates type to bit flag. |
| 1612 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1613 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1614 | const uint64_t one = 1; |
| 1615 | const int shift = type; // 0-based consecutive enum |
| 1616 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1617 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1618 | return one << (type + offset); |
| 1619 | } |
| 1620 | |
| 1621 | // Private constructor on direct flags value. |
| 1622 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1623 | |
| 1624 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1625 | }; |
| 1626 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1627 | // 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] | 1628 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1629 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1630 | HEnvironment(ArenaAllocator* arena, |
| 1631 | size_t number_of_vregs, |
| 1632 | const DexFile& dex_file, |
| 1633 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1634 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1635 | InvokeType invoke_type, |
| 1636 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1637 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1638 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1639 | parent_(nullptr), |
| 1640 | dex_file_(dex_file), |
| 1641 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1642 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1643 | invoke_type_(invoke_type), |
| 1644 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1645 | } |
| 1646 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1647 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1648 | : HEnvironment(arena, |
| 1649 | to_copy.Size(), |
| 1650 | to_copy.GetDexFile(), |
| 1651 | to_copy.GetMethodIdx(), |
| 1652 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1653 | to_copy.GetInvokeType(), |
| 1654 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1655 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1656 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1657 | if (parent_ != nullptr) { |
| 1658 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1659 | } else { |
| 1660 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1661 | parent_->CopyFrom(parent); |
| 1662 | if (parent->GetParent() != nullptr) { |
| 1663 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1664 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1665 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1668 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1669 | void CopyFrom(HEnvironment* environment); |
| 1670 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1671 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1672 | // input to the loop phi instead. This is for inserting instructions that |
| 1673 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1674 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1675 | |
| 1676 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1677 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1681 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1684 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1685 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1686 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1687 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1688 | HEnvironment* GetParent() const { return parent_; } |
| 1689 | |
| 1690 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1691 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1695 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | uint32_t GetDexPc() const { |
| 1699 | return dex_pc_; |
| 1700 | } |
| 1701 | |
| 1702 | uint32_t GetMethodIdx() const { |
| 1703 | return method_idx_; |
| 1704 | } |
| 1705 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1706 | InvokeType GetInvokeType() const { |
| 1707 | return invoke_type_; |
| 1708 | } |
| 1709 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1710 | const DexFile& GetDexFile() const { |
| 1711 | return dex_file_; |
| 1712 | } |
| 1713 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1714 | HInstruction* GetHolder() const { |
| 1715 | return holder_; |
| 1716 | } |
| 1717 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1718 | |
| 1719 | bool IsFromInlinedInvoke() const { |
| 1720 | return GetParent() != nullptr; |
| 1721 | } |
| 1722 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1723 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1724 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1725 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1726 | HEnvironment* parent_; |
| 1727 | const DexFile& dex_file_; |
| 1728 | const uint32_t method_idx_; |
| 1729 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1730 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1731 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1732 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1733 | HInstruction* const holder_; |
| 1734 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1735 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1736 | |
| 1737 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1738 | }; |
| 1739 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1740 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1741 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1742 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1743 | : previous_(nullptr), |
| 1744 | next_(nullptr), |
| 1745 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1746 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1747 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1748 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1749 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1750 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1751 | locations_(nullptr), |
| 1752 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1753 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1754 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1755 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| 1756 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 1757 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1758 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1759 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1760 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1761 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1762 | enum InstructionKind { |
| 1763 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1764 | }; |
| 1765 | #undef DECLARE_KIND |
| 1766 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1767 | HInstruction* GetNext() const { return next_; } |
| 1768 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1769 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1770 | HInstruction* GetNextDisregardingMoves() const; |
| 1771 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1772 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1773 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1774 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1775 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1776 | bool IsInBlock() const { return block_ != nullptr; } |
| 1777 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1778 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 1779 | bool IsIrreducibleLoopHeaderPhi() const { |
| 1780 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 1781 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1782 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 1783 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 1784 | |
| 1785 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 1786 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 1787 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 1788 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 1789 | } |
| 1790 | |
| 1791 | auto GetInputs() { |
| 1792 | return MakeTransformArrayRef( |
| 1793 | GetInputRecords(), |
| 1794 | [](HUserRecord<HInstruction*>& record) -> HInstruction* { |
| 1795 | return record.GetInstruction(); |
| 1796 | }); |
| 1797 | } |
| 1798 | |
| 1799 | auto GetInputs() const { |
| 1800 | return MakeTransformArrayRef( |
| 1801 | GetInputRecords(), |
| 1802 | [](const HUserRecord<HInstruction*>& record) -> const HInstruction* { |
| 1803 | return record.GetInstruction(); |
| 1804 | }); |
| 1805 | } |
| 1806 | |
| 1807 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1808 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1809 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 1810 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1811 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1812 | } |
| 1813 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1814 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1815 | virtual const char* DebugName() const = 0; |
| 1816 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1817 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
| 1818 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1819 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1820 | |
| 1821 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1822 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1823 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1824 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1825 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1826 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1827 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1828 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1829 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1830 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1831 | // Does not apply for all instructions, but having this at top level greatly |
| 1832 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1833 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1834 | virtual bool CanBeNull() const { |
| 1835 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1836 | return true; |
| 1837 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1838 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1839 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1840 | return false; |
| 1841 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1842 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 1843 | virtual bool IsActualObject() const { |
| 1844 | return GetType() == Primitive::kPrimNot; |
| 1845 | } |
| 1846 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1847 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1848 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1849 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1850 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 1851 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 1852 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1853 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1854 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1855 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1856 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1857 | // Note: fixup_end remains valid across push_front(). |
| 1858 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 1859 | HUseListNode<HInstruction*>* new_node = |
| 1860 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HInstruction*>(user, index); |
| 1861 | uses_.push_front(*new_node); |
| 1862 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1865 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1866 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1867 | // Note: env_fixup_end remains valid across push_front(). |
| 1868 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 1869 | HUseListNode<HEnvironment*>* new_node = |
| 1870 | new (GetBlock()->GetGraph()->GetArena()) HUseListNode<HEnvironment*>(user, index); |
| 1871 | env_uses_.push_front(*new_node); |
| 1872 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1873 | } |
| 1874 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1875 | void RemoveAsUserOfInput(size_t input) { |
| 1876 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1877 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1878 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1879 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1880 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1881 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 1882 | void RemoveAsUserOfAllInputs() { |
| 1883 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 1884 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 1885 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 1886 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 1887 | } |
| 1888 | } |
| 1889 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1890 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1891 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1892 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1893 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 1894 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 1895 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1896 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1897 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1898 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1899 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1900 | // Does this instruction strictly dominate `other_instruction`? |
| 1901 | // Returns false if this instruction and `other_instruction` are the same. |
| 1902 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1903 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1904 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1905 | int GetId() const { return id_; } |
| 1906 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1907 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1908 | int GetSsaIndex() const { return ssa_index_; } |
| 1909 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1910 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1911 | |
| 1912 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1913 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1914 | // Set the `environment_` field. Raw because this method does not |
| 1915 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1916 | void SetRawEnvironment(HEnvironment* environment) { |
| 1917 | DCHECK(environment_ == nullptr); |
| 1918 | DCHECK_EQ(environment->GetHolder(), this); |
| 1919 | environment_ = environment; |
| 1920 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1921 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 1922 | void RemoveEnvironment(); |
| 1923 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1924 | // Set the environment of this instruction, copying it from `environment`. While |
| 1925 | // copying, the uses lists are being updated. |
| 1926 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1927 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1928 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1929 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1930 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1931 | if (environment->GetParent() != nullptr) { |
| 1932 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1933 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1934 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1935 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1936 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1937 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1938 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1939 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1940 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1941 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1942 | if (environment->GetParent() != nullptr) { |
| 1943 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1944 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1947 | // Returns the number of entries in the environment. Typically, that is the |
| 1948 | // number of dex registers in a method. It could be more in case of inlining. |
| 1949 | size_t EnvironmentSize() const; |
| 1950 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1951 | LocationSummary* GetLocations() const { return locations_; } |
| 1952 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1953 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1954 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1955 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1956 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1957 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1958 | // uses of this instruction by `other` are *not* updated. |
| 1959 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1960 | ReplaceWith(other); |
| 1961 | other->ReplaceInput(this, use_index); |
| 1962 | } |
| 1963 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1964 | // Move `this` instruction before `cursor`. |
| 1965 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1966 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 1967 | // Move `this` before its first user and out of any loops. If there is no |
| 1968 | // out-of-loop user that dominates all other users, move the instruction |
| 1969 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 1970 | // |
| 1971 | // This can be used only on non-throwing instructions with no side effects that |
| 1972 | // have at least one use but no environment uses. |
| 1973 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 1974 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1975 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1976 | bool Is##type() const; \ |
| 1977 | const H##type* As##type() const; \ |
| 1978 | H##type* As##type(); |
| 1979 | |
| 1980 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1981 | #undef INSTRUCTION_TYPE_CHECK |
| 1982 | |
| 1983 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1984 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1985 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1986 | virtual H##type* As##type() { return nullptr; } |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1987 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1988 | #undef INSTRUCTION_TYPE_CHECK |
| 1989 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1990 | // Returns whether the instruction can be moved within the graph. |
| 1991 | virtual bool CanBeMoved() const { return false; } |
| 1992 | |
| 1993 | // Returns whether the two instructions are of the same kind. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 1994 | virtual bool InstructionTypeEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1995 | return false; |
| 1996 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1997 | |
| 1998 | // Returns whether any data encoded in the two instructions is equal. |
| 1999 | // This method does not look at the inputs. Both instructions must be |
| 2000 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2001 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2002 | return false; |
| 2003 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2004 | |
| 2005 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2006 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2007 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2008 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2009 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2010 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2011 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2012 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2013 | // apply the strong requirement for virtual functions, preventing optimizations. |
| 2014 | InstructionKind GetKind() const PURE; |
| 2015 | virtual InstructionKind GetKindInternal() const = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2016 | |
| 2017 | virtual size_t ComputeHashCode() const { |
| 2018 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2019 | for (const HInstruction* input : GetInputs()) { |
| 2020 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2021 | } |
| 2022 | return result; |
| 2023 | } |
| 2024 | |
| 2025 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2026 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2027 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2028 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2029 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2030 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2031 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2032 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2033 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2034 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2035 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2036 | |
| 2037 | // Returns whether the code generation of the instruction will require to have access |
| 2038 | // to the current method. Such instructions are: |
| 2039 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2040 | // to walk the stack and have the current method stored at a specific stack address. |
| 2041 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 2042 | // fields of the current method. |
| 2043 | bool NeedsCurrentMethod() const { |
| 2044 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 2045 | } |
| 2046 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2047 | // Returns whether the code generation of the instruction will require to have access |
| 2048 | // to the dex cache of the current method's declaring class via the current method. |
| 2049 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2050 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2051 | // Does this instruction have any use in an environment before |
| 2052 | // control flow hits 'other'? |
| 2053 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2054 | |
| 2055 | // Remove all references to environment uses of this instruction. |
| 2056 | // The caller must ensure that this is safe to do. |
| 2057 | void RemoveEnvironmentUsers(); |
| 2058 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2059 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2060 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2061 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2062 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2063 | // If set, the machine code for this instruction is assumed to be generated by |
| 2064 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2065 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2066 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| 2067 | static constexpr size_t kNumberOfGenericPackedBits = kFlagReferenceTypeIsExact + 1; |
| 2068 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2069 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2070 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2071 | return GetInputRecords()[i]; |
| 2072 | } |
| 2073 | |
| 2074 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2075 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2076 | input_records[index] = input; |
| 2077 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2078 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2079 | uint32_t GetPackedFields() const { |
| 2080 | return packed_fields_; |
| 2081 | } |
| 2082 | |
| 2083 | template <size_t flag> |
| 2084 | bool GetPackedFlag() const { |
| 2085 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2086 | } |
| 2087 | |
| 2088 | template <size_t flag> |
| 2089 | void SetPackedFlag(bool value = true) { |
| 2090 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2091 | } |
| 2092 | |
| 2093 | template <typename BitFieldType> |
| 2094 | typename BitFieldType::value_type GetPackedField() const { |
| 2095 | return BitFieldType::Decode(packed_fields_); |
| 2096 | } |
| 2097 | |
| 2098 | template <typename BitFieldType> |
| 2099 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2100 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2101 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2102 | } |
| 2103 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2104 | private: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2105 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2106 | auto before_use_node = uses_.before_begin(); |
| 2107 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2108 | HInstruction* user = use_node->GetUser(); |
| 2109 | size_t input_index = use_node->GetIndex(); |
| 2110 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2111 | before_use_node = use_node; |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2116 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2117 | if (next != uses_.end()) { |
| 2118 | HInstruction* next_user = next->GetUser(); |
| 2119 | size_t next_index = next->GetIndex(); |
| 2120 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2121 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2126 | auto before_env_use_node = env_uses_.before_begin(); |
| 2127 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2128 | HEnvironment* user = env_use_node->GetUser(); |
| 2129 | size_t input_index = env_use_node->GetIndex(); |
| 2130 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2131 | before_env_use_node = env_use_node; |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2136 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2137 | if (next != env_uses_.end()) { |
| 2138 | HEnvironment* next_user = next->GetUser(); |
| 2139 | size_t next_index = next->GetIndex(); |
| 2140 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2141 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2142 | } |
| 2143 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2144 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2145 | HInstruction* previous_; |
| 2146 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2147 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2148 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2149 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2150 | // An instruction gets an id when it is added to the graph. |
| 2151 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2152 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2153 | int id_; |
| 2154 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2155 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2156 | int ssa_index_; |
| 2157 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2158 | // Packed fields. |
| 2159 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2160 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2161 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2162 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2163 | |
| 2164 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2165 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2166 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2167 | // The environment associated with this instruction. Not null if the instruction |
| 2168 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2169 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2170 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2171 | // Set by the code generator. |
| 2172 | LocationSummary* locations_; |
| 2173 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2174 | // Set by the liveness analysis. |
| 2175 | LiveInterval* live_interval_; |
| 2176 | |
| 2177 | // Set by the liveness analysis, this is the position in a linear |
| 2178 | // order of blocks where this instruction's live interval start. |
| 2179 | size_t lifetime_position_; |
| 2180 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2181 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2182 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2183 | // The reference handle part of the reference type info. |
| 2184 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2185 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2186 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2187 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2188 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2189 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2190 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2191 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2192 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2193 | |
| 2194 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2195 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2196 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2197 | |
| 2198 | class HInstructionIterator : public ValueObject { |
| 2199 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2200 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2201 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2202 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2203 | } |
| 2204 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2205 | bool Done() const { return instruction_ == nullptr; } |
| 2206 | HInstruction* Current() const { return instruction_; } |
| 2207 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2208 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2209 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | private: |
| 2213 | HInstruction* instruction_; |
| 2214 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2215 | |
| 2216 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2217 | }; |
| 2218 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2219 | class HBackwardInstructionIterator : public ValueObject { |
| 2220 | public: |
| 2221 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2222 | : instruction_(instructions.last_instruction_) { |
| 2223 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2224 | } |
| 2225 | |
| 2226 | bool Done() const { return instruction_ == nullptr; } |
| 2227 | HInstruction* Current() const { return instruction_; } |
| 2228 | void Advance() { |
| 2229 | instruction_ = next_; |
| 2230 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2231 | } |
| 2232 | |
| 2233 | private: |
| 2234 | HInstruction* instruction_; |
| 2235 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2236 | |
| 2237 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2238 | }; |
| 2239 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2240 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2241 | class HTemplateInstruction: public HInstruction { |
| 2242 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2243 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2244 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2245 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2246 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2247 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2248 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2249 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2252 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2253 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2254 | |
| 2255 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2256 | }; |
| 2257 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2258 | // HTemplateInstruction specialization for N=0. |
| 2259 | template<> |
| 2260 | class HTemplateInstruction<0>: public HInstruction { |
| 2261 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2262 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2263 | : HInstruction(side_effects, dex_pc) {} |
| 2264 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2265 | virtual ~HTemplateInstruction() {} |
| 2266 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2267 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2268 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2269 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | private: |
| 2273 | friend class SsaBuilder; |
| 2274 | }; |
| 2275 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2276 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2277 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2278 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2279 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2280 | : HTemplateInstruction<N>(side_effects, dex_pc) { |
| 2281 | this->template SetPackedField<TypeField>(type); |
| 2282 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2283 | virtual ~HExpression() {} |
| 2284 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2285 | Primitive::Type GetType() const OVERRIDE { |
| 2286 | return TypeField::Decode(this->GetPackedFields()); |
| 2287 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2288 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2289 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2290 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2291 | static constexpr size_t kFieldTypeSize = |
| 2292 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2293 | static constexpr size_t kNumberOfExpressionPackedBits = kFieldType + kFieldTypeSize; |
| 2294 | static_assert(kNumberOfExpressionPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 2295 | "Too many packed fields."); |
| 2296 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2297 | }; |
| 2298 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2299 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2300 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2301 | class HReturnVoid FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2302 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2303 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2304 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2305 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2306 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2307 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2308 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2309 | |
| 2310 | private: |
| 2311 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2312 | }; |
| 2313 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2314 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2315 | // instruction that branches to the exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2316 | class HReturn FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2317 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2318 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2319 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2320 | SetRawInputAt(0, value); |
| 2321 | } |
| 2322 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2323 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2324 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2325 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2326 | |
| 2327 | private: |
| 2328 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2329 | }; |
| 2330 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2331 | class HPhi FINAL : public HInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2332 | public: |
| 2333 | HPhi(ArenaAllocator* arena, |
| 2334 | uint32_t reg_number, |
| 2335 | size_t number_of_inputs, |
| 2336 | Primitive::Type type, |
| 2337 | uint32_t dex_pc = kNoDexPc) |
| 2338 | : HInstruction(SideEffects::None(), dex_pc), |
| 2339 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
| 2340 | reg_number_(reg_number) { |
| 2341 | SetPackedField<TypeField>(ToPhiType(type)); |
| 2342 | DCHECK_NE(GetType(), Primitive::kPrimVoid); |
| 2343 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2344 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2345 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2346 | SetPackedFlag<kFlagIsLive>(true); |
| 2347 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2348 | } |
| 2349 | |
| 2350 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 2351 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 2352 | return Primitive::PrimitiveKind(type); |
| 2353 | } |
| 2354 | |
| 2355 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2356 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2357 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2358 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2359 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2360 | } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2361 | |
| 2362 | void AddInput(HInstruction* input); |
| 2363 | void RemoveInputAt(size_t index); |
| 2364 | |
| 2365 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<TypeField>(); } |
| 2366 | void SetType(Primitive::Type new_type) { |
| 2367 | // Make sure that only valid type changes occur. The following are allowed: |
| 2368 | // (1) int -> float/ref (primitive type propagation), |
| 2369 | // (2) long -> double (primitive type propagation). |
| 2370 | DCHECK(GetType() == new_type || |
| 2371 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimFloat) || |
| 2372 | (GetType() == Primitive::kPrimInt && new_type == Primitive::kPrimNot) || |
| 2373 | (GetType() == Primitive::kPrimLong && new_type == Primitive::kPrimDouble)); |
| 2374 | SetPackedField<TypeField>(new_type); |
| 2375 | } |
| 2376 | |
| 2377 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2378 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2379 | |
| 2380 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2381 | |
| 2382 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2383 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2384 | bool IsDead() const { return !IsLive(); } |
| 2385 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2386 | |
| 2387 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 2388 | return other != nullptr |
| 2389 | && other->IsPhi() |
| 2390 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2391 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2392 | } |
| 2393 | |
| 2394 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2395 | // An equivalent phi is a phi having the same dex register and type. |
| 2396 | // It assumes that phis with the same dex register are adjacent. |
| 2397 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2398 | HInstruction* next = GetNext(); |
| 2399 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2400 | if (next->GetType() == GetType()) { |
| 2401 | return next->AsPhi(); |
| 2402 | } |
| 2403 | next = next->GetNext(); |
| 2404 | } |
| 2405 | return nullptr; |
| 2406 | } |
| 2407 | |
| 2408 | DECLARE_INSTRUCTION(Phi); |
| 2409 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2410 | private: |
| 2411 | static constexpr size_t kFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 2412 | static constexpr size_t kFieldTypeSize = |
| 2413 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 2414 | static constexpr size_t kFlagIsLive = kFieldType + kFieldTypeSize; |
| 2415 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2416 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2417 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 2418 | using TypeField = BitField<Primitive::Type, kFieldType, kFieldTypeSize>; |
| 2419 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2420 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2421 | const uint32_t reg_number_; |
| 2422 | |
| 2423 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 2424 | }; |
| 2425 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2426 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2427 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2428 | // exit block. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2429 | class HExit FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2430 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2431 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2432 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2433 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2434 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2435 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2436 | |
| 2437 | private: |
| 2438 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2439 | }; |
| 2440 | |
| 2441 | // Jumps from one block to another. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2442 | class HGoto FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2443 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2444 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2445 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2446 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2447 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2448 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2449 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2452 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2453 | |
| 2454 | private: |
| 2455 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2456 | }; |
| 2457 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2458 | class HConstant : public HExpression<0> { |
| 2459 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2460 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2461 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2462 | |
| 2463 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2464 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2465 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2466 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2467 | // Is this constant 0 in the arithmetic sense? |
| 2468 | virtual bool IsArithmeticZero() const { return false; } |
| 2469 | // Is this constant a 0-bit pattern? |
| 2470 | virtual bool IsZeroBitPattern() const { return false; } |
| 2471 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2472 | virtual bool IsOne() const { return false; } |
| 2473 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2474 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2475 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2476 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2477 | |
| 2478 | private: |
| 2479 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2480 | }; |
| 2481 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2482 | class HNullConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2483 | public: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2484 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2485 | return true; |
| 2486 | } |
| 2487 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2488 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2489 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2490 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2491 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2492 | // The null constant representation is a 0-bit pattern. |
| 2493 | virtual bool IsZeroBitPattern() const { return true; } |
| 2494 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2495 | DECLARE_INSTRUCTION(NullConstant); |
| 2496 | |
| 2497 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2498 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2499 | |
| 2500 | friend class HGraph; |
| 2501 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2502 | }; |
| 2503 | |
| 2504 | // Constants of the type int. Those can be from Dex instructions, or |
| 2505 | // synthesized (for example with the if-eqz instruction). |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2506 | class HIntConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2507 | public: |
| 2508 | int32_t GetValue() const { return value_; } |
| 2509 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2510 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2511 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2512 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2513 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2514 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2515 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2516 | return other->AsIntConstant()->value_ == value_; |
| 2517 | } |
| 2518 | |
| 2519 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2520 | |
| 2521 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2522 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2523 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2524 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2525 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2526 | // Integer constants are used to encode Boolean values as well, |
| 2527 | // where 1 means true and 0 means false. |
| 2528 | bool IsTrue() const { return GetValue() == 1; } |
| 2529 | bool IsFalse() const { return GetValue() == 0; } |
| 2530 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2531 | DECLARE_INSTRUCTION(IntConstant); |
| 2532 | |
| 2533 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2534 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2535 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2536 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2537 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2538 | |
| 2539 | const int32_t value_; |
| 2540 | |
| 2541 | friend class HGraph; |
| 2542 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2543 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2544 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2545 | }; |
| 2546 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2547 | class HLongConstant FINAL : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2548 | public: |
| 2549 | int64_t GetValue() const { return value_; } |
| 2550 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2551 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2552 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2553 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2554 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2555 | return other->AsLongConstant()->value_ == value_; |
| 2556 | } |
| 2557 | |
| 2558 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2559 | |
| 2560 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2561 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2562 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2563 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2564 | |
| 2565 | DECLARE_INSTRUCTION(LongConstant); |
| 2566 | |
| 2567 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2568 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2569 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2570 | |
| 2571 | const int64_t value_; |
| 2572 | |
| 2573 | friend class HGraph; |
| 2574 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2575 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2576 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2577 | class HFloatConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2578 | public: |
| 2579 | float GetValue() const { return value_; } |
| 2580 | |
| 2581 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2582 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2583 | } |
| 2584 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2585 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2586 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 2587 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2588 | } |
| 2589 | |
| 2590 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2591 | |
| 2592 | bool IsMinusOne() const OVERRIDE { |
| 2593 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 2594 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2595 | bool IsArithmeticZero() const OVERRIDE { |
| 2596 | return std::fpclassify(value_) == FP_ZERO; |
| 2597 | } |
| 2598 | bool IsArithmeticPositiveZero() const { |
| 2599 | return IsArithmeticZero() && !std::signbit(value_); |
| 2600 | } |
| 2601 | bool IsArithmeticNegativeZero() const { |
| 2602 | return IsArithmeticZero() && std::signbit(value_); |
| 2603 | } |
| 2604 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2605 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(0.0f); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2606 | } |
| 2607 | bool IsOne() const OVERRIDE { |
| 2608 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2609 | } |
| 2610 | bool IsNaN() const { |
| 2611 | return std::isnan(value_); |
| 2612 | } |
| 2613 | |
| 2614 | DECLARE_INSTRUCTION(FloatConstant); |
| 2615 | |
| 2616 | private: |
| 2617 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2618 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2619 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2620 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
| 2621 | |
| 2622 | const float value_; |
| 2623 | |
| 2624 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2625 | friend class SsaBuilder; |
| 2626 | friend class HGraph; |
| 2627 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2628 | }; |
| 2629 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2630 | class HDoubleConstant FINAL : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2631 | public: |
| 2632 | double GetValue() const { return value_; } |
| 2633 | |
| 2634 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2635 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2636 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2637 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 2638 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 2639 | } |
| 2640 | |
| 2641 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2642 | |
| 2643 | bool IsMinusOne() const OVERRIDE { |
| 2644 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 2645 | } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2646 | bool IsArithmeticZero() const OVERRIDE { |
| 2647 | return std::fpclassify(value_) == FP_ZERO; |
| 2648 | } |
| 2649 | bool IsArithmeticPositiveZero() const { |
| 2650 | return IsArithmeticZero() && !std::signbit(value_); |
| 2651 | } |
| 2652 | bool IsArithmeticNegativeZero() const { |
| 2653 | return IsArithmeticZero() && std::signbit(value_); |
| 2654 | } |
| 2655 | bool IsZeroBitPattern() const OVERRIDE { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 2656 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((0.0)); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2657 | } |
| 2658 | bool IsOne() const OVERRIDE { |
| 2659 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2660 | } |
| 2661 | bool IsNaN() const { |
| 2662 | return std::isnan(value_); |
| 2663 | } |
| 2664 | |
| 2665 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2666 | |
| 2667 | private: |
| 2668 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2669 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2670 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2671 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
| 2672 | |
| 2673 | const double value_; |
| 2674 | |
| 2675 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 2676 | friend class SsaBuilder; |
| 2677 | friend class HGraph; |
| 2678 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2679 | }; |
| 2680 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2681 | // Conditional branch. A block ending with an HIf instruction must have |
| 2682 | // two successors. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2683 | class HIf FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2684 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2685 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2686 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2687 | SetRawInputAt(0, input); |
| 2688 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2689 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2690 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2691 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2692 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2693 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2697 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2698 | } |
| 2699 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2700 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2701 | |
| 2702 | private: |
| 2703 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2704 | }; |
| 2705 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2706 | |
| 2707 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2708 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2709 | // non-exceptional control flow. |
| 2710 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2711 | // higher indices in no particular order. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2712 | class HTryBoundary FINAL : public HTemplateInstruction<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2713 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2714 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2715 | kEntry, |
| 2716 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2717 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2718 | }; |
| 2719 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2720 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2721 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
| 2722 | SetPackedField<BoundaryKindField>(kind); |
| 2723 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2724 | |
| 2725 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2726 | |
| 2727 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2728 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2729 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 2730 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 2731 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 2732 | } |
| 2733 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2734 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2735 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2736 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2737 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2738 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | // If not present already, adds `handler` to its block's list of exception |
| 2742 | // handlers. |
| 2743 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2744 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2745 | GetBlock()->AddSuccessor(handler); |
| 2746 | } |
| 2747 | } |
| 2748 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2749 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 2750 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2751 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2752 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2753 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2754 | DECLARE_INSTRUCTION(TryBoundary); |
| 2755 | |
| 2756 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2757 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 2758 | static constexpr size_t kFieldBoundaryKindSize = |
| 2759 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 2760 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 2761 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 2762 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 2763 | "Too many packed fields."); |
| 2764 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2765 | |
| 2766 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2767 | }; |
| 2768 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2769 | // Deoptimize to interpreter, upon checking a condition. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2770 | class HDeoptimize FINAL : public HTemplateInstruction<1> { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2771 | public: |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2772 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 2773 | // at the point of the `HDeoptimize`. |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2774 | HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
Nicolas Geoffray | 1cde058 | 2016-01-13 13:56:20 +0000 | [diff] [blame] | 2775 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2776 | SetRawInputAt(0, cond); |
| 2777 | } |
| 2778 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2779 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2780 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 2781 | return true; |
| 2782 | } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2783 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2784 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2785 | |
| 2786 | DECLARE_INSTRUCTION(Deoptimize); |
| 2787 | |
| 2788 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2789 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2790 | }; |
| 2791 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2792 | // Represents the ArtMethod that was passed as a first argument to |
| 2793 | // the method. It is used by instructions that depend on it, like |
| 2794 | // instructions that work with the dex cache. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2795 | class HCurrentMethod FINAL : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2796 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2797 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2798 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2799 | |
| 2800 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2801 | |
| 2802 | private: |
| 2803 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2804 | }; |
| 2805 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2806 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 2807 | // of a class. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2808 | class HClassTableGet FINAL : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2809 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2810 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2811 | kVTable, |
| 2812 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2813 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2814 | }; |
| 2815 | HClassTableGet(HInstruction* cls, |
| 2816 | Primitive::Type type, |
| 2817 | TableKind kind, |
| 2818 | size_t index, |
| 2819 | uint32_t dex_pc) |
| 2820 | : HExpression(type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2821 | index_(index) { |
| 2822 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2823 | SetRawInputAt(0, cls); |
| 2824 | } |
| 2825 | |
| 2826 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2827 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2828 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2829 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2830 | } |
| 2831 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2832 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2833 | size_t GetIndex() const { return index_; } |
| 2834 | |
| 2835 | DECLARE_INSTRUCTION(ClassTableGet); |
| 2836 | |
| 2837 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2838 | static constexpr size_t kFieldTableKind = kNumberOfExpressionPackedBits; |
| 2839 | static constexpr size_t kFieldTableKindSize = |
| 2840 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 2841 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 2842 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 2843 | "Too many packed fields."); |
| 2844 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 2845 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2846 | // The index of the ArtMethod in the table. |
| 2847 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 2848 | |
| 2849 | DISALLOW_COPY_AND_ASSIGN(HClassTableGet); |
| 2850 | }; |
| 2851 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2852 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2853 | // have one successor for each entry in the switch table, and the final successor |
| 2854 | // will be the block containing the next Dex opcode. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2855 | class HPackedSwitch FINAL : public HTemplateInstruction<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2856 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2857 | HPackedSwitch(int32_t start_value, |
| 2858 | uint32_t num_entries, |
| 2859 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2860 | uint32_t dex_pc = kNoDexPc) |
| 2861 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2862 | start_value_(start_value), |
| 2863 | num_entries_(num_entries) { |
| 2864 | SetRawInputAt(0, input); |
| 2865 | } |
| 2866 | |
| 2867 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2868 | |
| 2869 | int32_t GetStartValue() const { return start_value_; } |
| 2870 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2871 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2872 | |
| 2873 | HBasicBlock* GetDefaultBlock() const { |
| 2874 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2875 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2876 | } |
| 2877 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2878 | |
| 2879 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2880 | const int32_t start_value_; |
| 2881 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2882 | |
| 2883 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2884 | }; |
| 2885 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2886 | class HUnaryOperation : public HExpression<1> { |
| 2887 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2888 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2889 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2890 | SetRawInputAt(0, input); |
| 2891 | } |
| 2892 | |
| 2893 | HInstruction* GetInput() const { return InputAt(0); } |
| 2894 | Primitive::Type GetResultType() const { return GetType(); } |
| 2895 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2896 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2897 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2898 | return true; |
| 2899 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2900 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2901 | // Try to statically evaluate `this` and return a HConstant |
| 2902 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2903 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2904 | HConstant* TryStaticEvaluation() const; |
| 2905 | |
| 2906 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2907 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2908 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2909 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 2910 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2911 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2912 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2913 | |
| 2914 | private: |
| 2915 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2916 | }; |
| 2917 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2918 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2919 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2920 | HBinaryOperation(Primitive::Type result_type, |
| 2921 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2922 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2923 | SideEffects side_effects = SideEffects::None(), |
| 2924 | uint32_t dex_pc = kNoDexPc) |
| 2925 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2926 | SetRawInputAt(0, left); |
| 2927 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2930 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2931 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2932 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2933 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2934 | virtual bool IsCommutative() const { return false; } |
| 2935 | |
| 2936 | // Put constant on the right. |
| 2937 | // Returns whether order is changed. |
| 2938 | bool OrderInputsWithConstantOnTheRight() { |
| 2939 | HInstruction* left = InputAt(0); |
| 2940 | HInstruction* right = InputAt(1); |
| 2941 | if (left->IsConstant() && !right->IsConstant()) { |
| 2942 | ReplaceInput(right, 0); |
| 2943 | ReplaceInput(left, 1); |
| 2944 | return true; |
| 2945 | } |
| 2946 | return false; |
| 2947 | } |
| 2948 | |
| 2949 | // Order inputs by instruction id, but favor constant on the right side. |
| 2950 | // This helps GVN for commutative ops. |
| 2951 | void OrderInputs() { |
| 2952 | DCHECK(IsCommutative()); |
| 2953 | HInstruction* left = InputAt(0); |
| 2954 | HInstruction* right = InputAt(1); |
| 2955 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2956 | return; |
| 2957 | } |
| 2958 | if (OrderInputsWithConstantOnTheRight()) { |
| 2959 | return; |
| 2960 | } |
| 2961 | // Order according to instruction id. |
| 2962 | if (left->GetId() > right->GetId()) { |
| 2963 | ReplaceInput(right, 0); |
| 2964 | ReplaceInput(left, 1); |
| 2965 | } |
| 2966 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2967 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2968 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 2969 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2970 | return true; |
| 2971 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2972 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2973 | // Try to statically evaluate `this` and return a HConstant |
| 2974 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2975 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2976 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2977 | |
| 2978 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2979 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 2980 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2981 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 2982 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2983 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2984 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2985 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2986 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2987 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 2988 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 2989 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2990 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2991 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 2992 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2993 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2994 | // 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] | 2995 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2996 | HConstant* GetConstantRight() const; |
| 2997 | |
| 2998 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2999 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3000 | HInstruction* GetLeastConstantLeft() const; |
| 3001 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3002 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3003 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3004 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3005 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 3006 | }; |
| 3007 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3008 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3009 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3010 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3011 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3012 | kGtBias, // return 1 for NaN comparisons |
| 3013 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3014 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3015 | }; |
| 3016 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3017 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3018 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3019 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3020 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3021 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3022 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc) { |
| 3023 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3024 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3025 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3026 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3027 | // `instruction`, and disregard moves in between. |
| 3028 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3029 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3030 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3031 | |
| 3032 | virtual IfCondition GetCondition() const = 0; |
| 3033 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3034 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3035 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3036 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3037 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3038 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3039 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3040 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3041 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 3042 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3043 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3044 | } |
| 3045 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3046 | bool IsFPConditionTrueIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3047 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3048 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3049 | if (if_cond == kCondNE) { |
| 3050 | return true; |
| 3051 | } else if (if_cond == kCondEQ) { |
| 3052 | return false; |
| 3053 | } |
| 3054 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3055 | } |
| 3056 | |
| 3057 | bool IsFPConditionFalseIfNaN() const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3058 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3059 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3060 | if (if_cond == kCondEQ) { |
| 3061 | return true; |
| 3062 | } else if (if_cond == kCondNE) { |
| 3063 | return false; |
| 3064 | } |
| 3065 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3066 | } |
| 3067 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3068 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3069 | // Needed if we merge a HCompare into a HCondition. |
| 3070 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3071 | static constexpr size_t kFieldComparisonBiasSize = |
| 3072 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3073 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3074 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3075 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3076 | using ComparisonBiasField = |
| 3077 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3078 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3079 | template <typename T> |
| 3080 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3081 | |
| 3082 | template <typename T> |
| 3083 | int32_t CompareFP(T x, T y) const { |
| 3084 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3085 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3086 | // Handle the bias. |
| 3087 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3088 | } |
| 3089 | |
| 3090 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3091 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3092 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3093 | } |
| 3094 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3095 | private: |
| 3096 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 3097 | }; |
| 3098 | |
| 3099 | // Instruction to check if two inputs are equal to each other. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3100 | class HEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3101 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3102 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3103 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3104 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3105 | bool IsCommutative() const OVERRIDE { return true; } |
| 3106 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3107 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3108 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3109 | return MakeConstantCondition(true, GetDexPc()); |
| 3110 | } |
| 3111 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3112 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3113 | } |
| 3114 | // In the following Evaluate methods, a HCompare instruction has |
| 3115 | // been merged into this HEqual instruction; evaluate it as |
| 3116 | // `Compare(x, y) == 0`. |
| 3117 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3118 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3119 | GetDexPc()); |
| 3120 | } |
| 3121 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3122 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3123 | } |
| 3124 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3125 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3126 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3127 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3128 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3129 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3130 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3131 | return kCondEQ; |
| 3132 | } |
| 3133 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3134 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3135 | return kCondNE; |
| 3136 | } |
| 3137 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3138 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3139 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 3140 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3141 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 3142 | }; |
| 3143 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3144 | class HNotEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3145 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3146 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3147 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3148 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3149 | bool IsCommutative() const OVERRIDE { return true; } |
| 3150 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3151 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3152 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3153 | return MakeConstantCondition(false, GetDexPc()); |
| 3154 | } |
| 3155 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3156 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3157 | } |
| 3158 | // In the following Evaluate methods, a HCompare instruction has |
| 3159 | // been merged into this HNotEqual instruction; evaluate it as |
| 3160 | // `Compare(x, y) != 0`. |
| 3161 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3162 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3163 | } |
| 3164 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3165 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3166 | } |
| 3167 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3168 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3169 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3170 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3171 | DECLARE_INSTRUCTION(NotEqual); |
| 3172 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3173 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3174 | return kCondNE; |
| 3175 | } |
| 3176 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3177 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3178 | return kCondEQ; |
| 3179 | } |
| 3180 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3181 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3182 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 3183 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3184 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 3185 | }; |
| 3186 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3187 | class HLessThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3188 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3189 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3190 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3191 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3192 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3193 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3194 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3195 | // In the following Evaluate methods, a HCompare instruction has |
| 3196 | // been merged into this HLessThan instruction; evaluate it as |
| 3197 | // `Compare(x, y) < 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3198 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3199 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3200 | } |
| 3201 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3202 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3203 | } |
| 3204 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3205 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3206 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3207 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3208 | DECLARE_INSTRUCTION(LessThan); |
| 3209 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3210 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3211 | return kCondLT; |
| 3212 | } |
| 3213 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3214 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3215 | return kCondGE; |
| 3216 | } |
| 3217 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3218 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3219 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 3220 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3221 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 3222 | }; |
| 3223 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3224 | class HLessThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3225 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3226 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3227 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3228 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3229 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3230 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3231 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3232 | // In the following Evaluate methods, a HCompare instruction has |
| 3233 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3234 | // `Compare(x, y) <= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3235 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3236 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3237 | } |
| 3238 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3239 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3240 | } |
| 3241 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3242 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3243 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3244 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3245 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3246 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3247 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3248 | return kCondLE; |
| 3249 | } |
| 3250 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3251 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3252 | return kCondGT; |
| 3253 | } |
| 3254 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3255 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3256 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 3257 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3258 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 3259 | }; |
| 3260 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3261 | class HGreaterThan FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3262 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3263 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3264 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3265 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3266 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3267 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3268 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3269 | // In the following Evaluate methods, a HCompare instruction has |
| 3270 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3271 | // `Compare(x, y) > 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3272 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3273 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3274 | } |
| 3275 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3276 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3277 | } |
| 3278 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3279 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3280 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3281 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3282 | DECLARE_INSTRUCTION(GreaterThan); |
| 3283 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3284 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3285 | return kCondGT; |
| 3286 | } |
| 3287 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3288 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3289 | return kCondLE; |
| 3290 | } |
| 3291 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3292 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3293 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 3294 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3295 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 3296 | }; |
| 3297 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3298 | class HGreaterThanOrEqual FINAL : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3299 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3300 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3301 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3302 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3303 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3304 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3305 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3306 | // In the following Evaluate methods, a HCompare instruction has |
| 3307 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3308 | // `Compare(x, y) >= 0`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3309 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3310 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3311 | } |
| 3312 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3313 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3314 | } |
| 3315 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3316 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3317 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3318 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3319 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3320 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3321 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3322 | return kCondGE; |
| 3323 | } |
| 3324 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3325 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3326 | return kCondLT; |
| 3327 | } |
| 3328 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3329 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3330 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 3331 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3332 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 3333 | }; |
| 3334 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3335 | class HBelow FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3336 | public: |
| 3337 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3338 | : HCondition(first, second, dex_pc) {} |
| 3339 | |
| 3340 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3341 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3342 | } |
| 3343 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3344 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3345 | } |
| 3346 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3347 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3348 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3349 | UNREACHABLE(); |
| 3350 | } |
| 3351 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3352 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3353 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3354 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
| 3357 | DECLARE_INSTRUCTION(Below); |
| 3358 | |
| 3359 | IfCondition GetCondition() const OVERRIDE { |
| 3360 | return kCondB; |
| 3361 | } |
| 3362 | |
| 3363 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3364 | return kCondAE; |
| 3365 | } |
| 3366 | |
| 3367 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3368 | template <typename T> bool Compute(T x, T y) const { |
| 3369 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3370 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3371 | |
| 3372 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 3373 | }; |
| 3374 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3375 | class HBelowOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3376 | public: |
| 3377 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3378 | : HCondition(first, second, dex_pc) {} |
| 3379 | |
| 3380 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3381 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3382 | } |
| 3383 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3384 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3385 | } |
| 3386 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3387 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3388 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3389 | UNREACHABLE(); |
| 3390 | } |
| 3391 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3392 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3393 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3394 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3398 | |
| 3399 | IfCondition GetCondition() const OVERRIDE { |
| 3400 | return kCondBE; |
| 3401 | } |
| 3402 | |
| 3403 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3404 | return kCondA; |
| 3405 | } |
| 3406 | |
| 3407 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3408 | template <typename T> bool Compute(T x, T y) const { |
| 3409 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3410 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3411 | |
| 3412 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 3413 | }; |
| 3414 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3415 | class HAbove FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3416 | public: |
| 3417 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3418 | : HCondition(first, second, dex_pc) {} |
| 3419 | |
| 3420 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3421 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3422 | } |
| 3423 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3424 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3425 | } |
| 3426 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3427 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3428 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3429 | UNREACHABLE(); |
| 3430 | } |
| 3431 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3432 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3433 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3434 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | DECLARE_INSTRUCTION(Above); |
| 3438 | |
| 3439 | IfCondition GetCondition() const OVERRIDE { |
| 3440 | return kCondA; |
| 3441 | } |
| 3442 | |
| 3443 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3444 | return kCondBE; |
| 3445 | } |
| 3446 | |
| 3447 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3448 | template <typename T> bool Compute(T x, T y) const { |
| 3449 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 3450 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3451 | |
| 3452 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 3453 | }; |
| 3454 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3455 | class HAboveOrEqual FINAL : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3456 | public: |
| 3457 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 3458 | : HCondition(first, second, dex_pc) {} |
| 3459 | |
| 3460 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3461 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3462 | } |
| 3463 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3464 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3465 | } |
| 3466 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3467 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3468 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3469 | UNREACHABLE(); |
| 3470 | } |
| 3471 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3472 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3473 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3474 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 3478 | |
| 3479 | IfCondition GetCondition() const OVERRIDE { |
| 3480 | return kCondAE; |
| 3481 | } |
| 3482 | |
| 3483 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3484 | return kCondB; |
| 3485 | } |
| 3486 | |
| 3487 | private: |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3488 | template <typename T> bool Compute(T x, T y) const { |
| 3489 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 3490 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3491 | |
| 3492 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 3493 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3494 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3495 | // Instruction to check how two inputs compare to each other. |
| 3496 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3497 | class HCompare FINAL : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3498 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3499 | // Note that `comparison_type` is the type of comparison performed |
| 3500 | // between the comparison's inputs, not the type of the instantiated |
| 3501 | // HCompare instruction (which is always Primitive::kPrimInt). |
| 3502 | HCompare(Primitive::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3503 | HInstruction* first, |
| 3504 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3505 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3506 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3507 | : HBinaryOperation(Primitive::kPrimInt, |
| 3508 | first, |
| 3509 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 3510 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3511 | dex_pc) { |
| 3512 | SetPackedField<ComparisonBiasField>(bias); |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 3513 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(first->GetType())); |
| 3514 | DCHECK_EQ(comparison_type, Primitive::PrimitiveKind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3517 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3518 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3519 | |
| 3520 | template <typename T> |
| 3521 | int32_t ComputeFP(T x, T y) const { |
| 3522 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| 3523 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3524 | // Handle the bias. |
| 3525 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 3526 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3527 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3528 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3529 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 3530 | // reach this code path when processing a freshly built HIR |
| 3531 | // graph. However HCompare integer instructions can be synthesized |
| 3532 | // by the instruction simplifier to implement IntegerCompare and |
| 3533 | // IntegerSignum intrinsics, so we have to handle this case. |
| 3534 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3535 | } |
| 3536 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3537 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3538 | } |
| 3539 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3540 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3541 | } |
| 3542 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3543 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3544 | } |
| 3545 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 3546 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3547 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3550 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3551 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3552 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3553 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3554 | bool IsGtBias() const { |
| 3555 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3556 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3557 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3558 | |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 3559 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type ATTRIBUTE_UNUSED) { |
| 3560 | // Comparisons do not require a runtime call in any back end. |
| 3561 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3562 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3563 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3564 | DECLARE_INSTRUCTION(Compare); |
| 3565 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3566 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3567 | static constexpr size_t kFieldComparisonBias = kNumberOfExpressionPackedBits; |
| 3568 | static constexpr size_t kFieldComparisonBiasSize = |
| 3569 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3570 | static constexpr size_t kNumberOfComparePackedBits = |
| 3571 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3572 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3573 | using ComparisonBiasField = |
| 3574 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3575 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3576 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 3577 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 3578 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 3579 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3580 | } |
| 3581 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3582 | private: |
| 3583 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3584 | }; |
| 3585 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3586 | class HNewInstance FINAL : public HExpression<2> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3587 | public: |
| 3588 | HNewInstance(HInstruction* cls, |
| 3589 | HCurrentMethod* current_method, |
| 3590 | uint32_t dex_pc, |
| 3591 | uint16_t type_index, |
| 3592 | const DexFile& dex_file, |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3593 | bool needs_access_check, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3594 | bool finalizable, |
| 3595 | QuickEntrypointEnum entrypoint) |
| 3596 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
| 3597 | type_index_(type_index), |
| 3598 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3599 | entrypoint_(entrypoint) { |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3600 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3601 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3602 | SetRawInputAt(0, cls); |
| 3603 | SetRawInputAt(1, current_method); |
| 3604 | } |
| 3605 | |
| 3606 | uint16_t GetTypeIndex() const { return type_index_; } |
| 3607 | const DexFile& GetDexFile() const { return dex_file_; } |
| 3608 | |
| 3609 | // Calls runtime so needs an environment. |
| 3610 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3611 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3612 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 3613 | bool CanThrow() const OVERRIDE { return true; } |
| 3614 | |
| 3615 | // Needs to call into runtime to make sure it's instantiable/accessible. |
| 3616 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3617 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3618 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3619 | |
| 3620 | bool CanBeNull() const OVERRIDE { return false; } |
| 3621 | |
| 3622 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3623 | |
| 3624 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 3625 | entrypoint_ = entrypoint; |
| 3626 | } |
| 3627 | |
| 3628 | bool IsStringAlloc() const; |
| 3629 | |
| 3630 | DECLARE_INSTRUCTION(NewInstance); |
| 3631 | |
| 3632 | private: |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 3633 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfExpressionPackedBits; |
| 3634 | static constexpr size_t kFlagFinalizable = kFlagNeedsAccessCheck + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3635 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 3636 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 3637 | "Too many packed fields."); |
| 3638 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3639 | const uint16_t type_index_; |
| 3640 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3641 | QuickEntrypointEnum entrypoint_; |
| 3642 | |
| 3643 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3644 | }; |
| 3645 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3646 | enum class Intrinsics { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3647 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache, SideEffects, Exceptions) \ |
| 3648 | k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3649 | #include "intrinsics_list.h" |
| 3650 | kNone, |
| 3651 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3652 | #undef INTRINSICS_LIST |
| 3653 | #undef OPTIMIZING_INTRINSICS |
| 3654 | }; |
| 3655 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3656 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3657 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3658 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3659 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3660 | }; |
| 3661 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3662 | enum IntrinsicSideEffects { |
| 3663 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 3664 | kReadSideEffects, // Intrinsic may read heap memory. |
| 3665 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 3666 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 3667 | }; |
| 3668 | |
| 3669 | enum IntrinsicExceptions { |
| 3670 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 3671 | kCanThrow // Intrinsic may throw exceptions. |
| 3672 | }; |
| 3673 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3674 | class HInvoke : public HInstruction { |
| 3675 | public: |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3676 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3677 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 3678 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3679 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3680 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 3681 | } |
| 3682 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3683 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3684 | SetRawInputAt(index, argument); |
| 3685 | } |
| 3686 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3687 | // Return the number of arguments. This number can be lower than |
| 3688 | // the number of inputs returned by InputCount(), as some invoke |
| 3689 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3690 | // inputs at the end of their list of inputs. |
| 3691 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3692 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3693 | Primitive::Type GetType() const OVERRIDE { return GetPackedField<ReturnTypeField>(); } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3694 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3695 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3696 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3697 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3698 | InvokeType GetOriginalInvokeType() const { |
| 3699 | return GetPackedField<OriginalInvokeTypeField>(); |
| 3700 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3701 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3702 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3703 | return intrinsic_; |
| 3704 | } |
| 3705 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3706 | void SetIntrinsic(Intrinsics intrinsic, |
| 3707 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 3708 | IntrinsicSideEffects side_effects, |
| 3709 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3710 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3711 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 3712 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3713 | } |
| 3714 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3715 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3716 | |
| 3717 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic(); } |
| 3718 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 3719 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3720 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 3721 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3722 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3723 | uint32_t* GetIntrinsicOptimizations() { |
| 3724 | return &intrinsic_optimizations_; |
| 3725 | } |
| 3726 | |
| 3727 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3728 | return &intrinsic_optimizations_; |
| 3729 | } |
| 3730 | |
| 3731 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3732 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3733 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3734 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3735 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3736 | static constexpr size_t kFieldOriginalInvokeType = kNumberOfGenericPackedBits; |
| 3737 | static constexpr size_t kFieldOriginalInvokeTypeSize = |
| 3738 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 3739 | static constexpr size_t kFieldReturnType = |
| 3740 | kFieldOriginalInvokeType + kFieldOriginalInvokeTypeSize; |
| 3741 | static constexpr size_t kFieldReturnTypeSize = |
| 3742 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 3743 | static constexpr size_t kFlagCanThrow = kFieldReturnType + kFieldReturnTypeSize; |
| 3744 | static constexpr size_t kNumberOfInvokePackedBits = kFlagCanThrow + 1; |
| 3745 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3746 | using OriginalInvokeTypeField = |
| 3747 | BitField<InvokeType, kFieldOriginalInvokeType, kFieldOriginalInvokeTypeSize>; |
| 3748 | using ReturnTypeField = BitField<Primitive::Type, kFieldReturnType, kFieldReturnTypeSize>; |
| 3749 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3750 | HInvoke(ArenaAllocator* arena, |
| 3751 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3752 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3753 | Primitive::Type return_type, |
| 3754 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3755 | uint32_t dex_method_index, |
| 3756 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3757 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3758 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3759 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3760 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3761 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3762 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3763 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3764 | intrinsic_optimizations_(0) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3765 | SetPackedField<ReturnTypeField>(return_type); |
| 3766 | SetPackedField<OriginalInvokeTypeField>(original_invoke_type); |
| 3767 | SetPackedFlag<kFlagCanThrow>(true); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3768 | } |
| 3769 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3770 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 3771 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3772 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3773 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3774 | const uint32_t dex_method_index_; |
| 3775 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3776 | |
| 3777 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3778 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3779 | |
| 3780 | private: |
| 3781 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3782 | }; |
| 3783 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3784 | class HInvokeUnresolved FINAL : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3785 | public: |
| 3786 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3787 | uint32_t number_of_arguments, |
| 3788 | Primitive::Type return_type, |
| 3789 | uint32_t dex_pc, |
| 3790 | uint32_t dex_method_index, |
| 3791 | InvokeType invoke_type) |
| 3792 | : HInvoke(arena, |
| 3793 | number_of_arguments, |
| 3794 | 0u /* number_of_other_inputs */, |
| 3795 | return_type, |
| 3796 | dex_pc, |
| 3797 | dex_method_index, |
| 3798 | invoke_type) { |
| 3799 | } |
| 3800 | |
| 3801 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3802 | |
| 3803 | private: |
| 3804 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3805 | }; |
| 3806 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3807 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3808 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3809 | // Requirements of this method call regarding the class |
| 3810 | // initialization (clinit) check of its declaring class. |
| 3811 | enum class ClinitCheckRequirement { |
| 3812 | kNone, // Class already initialized. |
| 3813 | kExplicit, // Static call having explicit clinit check as last input. |
| 3814 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3815 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3816 | }; |
| 3817 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3818 | // Determines how to load the target ArtMethod*. |
| 3819 | enum class MethodLoadKind { |
| 3820 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3821 | kStringInit, |
| 3822 | |
| 3823 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3824 | kRecursive, |
| 3825 | |
| 3826 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3827 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3828 | kDirectAddress, |
| 3829 | |
| 3830 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3831 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3832 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3833 | // the image relocatable or not. |
| 3834 | kDirectAddressWithFixup, |
| 3835 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3836 | // 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] | 3837 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3838 | // may cause class initialization (the entry may point to a resolution method), |
| 3839 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3840 | kDexCachePcRelative, |
| 3841 | |
| 3842 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3843 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3844 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3845 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3846 | kDexCacheViaMethod, |
| 3847 | }; |
| 3848 | |
| 3849 | // Determines the location of the code pointer. |
| 3850 | enum class CodePtrLocation { |
| 3851 | // Recursive call, use local PC-relative call instruction. |
| 3852 | kCallSelf, |
| 3853 | |
| 3854 | // Use PC-relative call instruction patched at link time. |
| 3855 | // Used for calls within an oat file, boot->boot or app->app. |
| 3856 | kCallPCRelative, |
| 3857 | |
| 3858 | // Call to a known target address, embed the direct address in code. |
| 3859 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3860 | kCallDirect, |
| 3861 | |
| 3862 | // Call to a target address that will be known at link time, embed the direct |
| 3863 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3864 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3865 | // the image relocatable or not. |
| 3866 | kCallDirectWithFixup, |
| 3867 | |
| 3868 | // Use code pointer from the ArtMethod*. |
| 3869 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3870 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3871 | kCallArtMethod, |
| 3872 | }; |
| 3873 | |
| 3874 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3875 | MethodLoadKind method_load_kind; |
| 3876 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3877 | // The method load data holds |
| 3878 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3879 | // Note that there are multiple string init methods, each having its own offset. |
| 3880 | // - the method address for kDirectAddress |
| 3881 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3882 | uint64_t method_load_data; |
| 3883 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3884 | }; |
| 3885 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3886 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3887 | uint32_t number_of_arguments, |
| 3888 | Primitive::Type return_type, |
| 3889 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3890 | uint32_t method_index, |
| 3891 | MethodReference target_method, |
| 3892 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3893 | InvokeType original_invoke_type, |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3894 | InvokeType optimized_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3895 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3896 | : HInvoke(arena, |
| 3897 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3898 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 3899 | // potentially one other if the clinit check is explicit, and potentially |
| 3900 | // one other if the method is a string factory. |
| 3901 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 3902 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3903 | return_type, |
| 3904 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3905 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3906 | original_invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3907 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3908 | dispatch_info_(dispatch_info) { |
| 3909 | SetPackedField<OptimizedInvokeTypeField>(optimized_invoke_type); |
| 3910 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 3911 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3912 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3913 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3914 | bool had_current_method_input = HasCurrentMethodInput(); |
| 3915 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 3916 | |
| 3917 | // Using the current method is the default and once we find a better |
| 3918 | // method load kind, we should not go back to using the current method. |
| 3919 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 3920 | |
| 3921 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3922 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 3923 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3924 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3925 | dispatch_info_ = dispatch_info; |
| 3926 | } |
| 3927 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3928 | void AddSpecialInput(HInstruction* input) { |
| 3929 | // We allow only one special input. |
| 3930 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 3931 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3932 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 3933 | InsertInputAt(GetSpecialInputIndex(), input); |
| 3934 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3935 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 3936 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 3937 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 3938 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 3939 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 3940 | DCHECK(!input_records.empty()); |
| 3941 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 3942 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 3943 | // Note: `last_input` may be null during arguments setup. |
| 3944 | if (last_input != nullptr) { |
| 3945 | // `last_input` is the last input of a static invoke marked as having |
| 3946 | // an explicit clinit check. It must either be: |
| 3947 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3948 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3949 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 3950 | } |
| 3951 | } |
| 3952 | return input_records; |
| 3953 | } |
| 3954 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3955 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3956 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3957 | // TODO: for intrinsics we can generate implicit null checks. |
| 3958 | return false; |
| 3959 | } |
| 3960 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3961 | bool CanBeNull() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3962 | return GetPackedField<ReturnTypeField>() == Primitive::kPrimNot && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3965 | // Get the index of the special input, if any. |
| 3966 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 3967 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 3968 | // method pointer; otherwise there may be one platform-specific special input, |
| 3969 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3970 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 3971 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3972 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3973 | InvokeType GetOptimizedInvokeType() const { |
| 3974 | return GetPackedField<OptimizedInvokeTypeField>(); |
| 3975 | } |
| 3976 | |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3977 | void SetOptimizedInvokeType(InvokeType invoke_type) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3978 | SetPackedField<OptimizedInvokeTypeField>(invoke_type); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 3979 | } |
| 3980 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3981 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3982 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3983 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3984 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3985 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3986 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 3987 | bool HasPcRelativeDexCache() const { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3988 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3989 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3990 | bool HasCurrentMethodInput() const { |
| 3991 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 3992 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3993 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3994 | return true; |
| 3995 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 3996 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 3997 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 3998 | return false; |
| 3999 | } |
| 4000 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4001 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 4002 | MethodReference GetTargetMethod() const { return target_method_; } |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4003 | void SetTargetMethod(MethodReference method) { target_method_ = method; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4004 | |
| 4005 | int32_t GetStringInitOffset() const { |
| 4006 | DCHECK(IsStringInit()); |
| 4007 | return dispatch_info_.method_load_data; |
| 4008 | } |
| 4009 | |
| 4010 | uint64_t GetMethodAddress() const { |
| 4011 | DCHECK(HasMethodAddress()); |
| 4012 | return dispatch_info_.method_load_data; |
| 4013 | } |
| 4014 | |
| 4015 | uint32_t GetDexCacheArrayOffset() const { |
Vladimir Marko | 0f7dca4 | 2015-11-02 14:36:43 +0000 | [diff] [blame] | 4016 | DCHECK(HasPcRelativeDexCache()); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4017 | return dispatch_info_.method_load_data; |
| 4018 | } |
| 4019 | |
| 4020 | uint64_t GetDirectCodePtr() const { |
| 4021 | DCHECK(HasDirectCodePtr()); |
| 4022 | return dispatch_info_.direct_code_ptr; |
| 4023 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4024 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4025 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4026 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4027 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4028 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4029 | // Is this instruction a call to a static method? |
| 4030 | bool IsStatic() const { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 4031 | return GetOriginalInvokeType() == kStatic; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4032 | } |
| 4033 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4034 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4035 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4036 | // instruction; only relevant for static calls with explicit clinit check. |
| 4037 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4038 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 4039 | size_t last_input_index = inputs_.size() - 1u; |
| 4040 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4041 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4042 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4043 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4044 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4045 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4046 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4047 | } |
| 4048 | |
| 4049 | // 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] | 4050 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4051 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4052 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | // Is this a call to a static method whose declaring class has an |
| 4056 | // implicit intialization check requirement? |
| 4057 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4058 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4059 | } |
| 4060 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4061 | // Does this method load kind need the current method as an input? |
| 4062 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| 4063 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kDexCacheViaMethod; |
| 4064 | } |
| 4065 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4066 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4067 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4068 | protected: |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4069 | void InsertInputAt(size_t index, HInstruction* input); |
| 4070 | void RemoveInputAt(size_t index); |
| 4071 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4072 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4073 | static constexpr size_t kFieldOptimizedInvokeType = kNumberOfInvokePackedBits; |
| 4074 | static constexpr size_t kFieldOptimizedInvokeTypeSize = |
| 4075 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| 4076 | static constexpr size_t kFieldClinitCheckRequirement = |
| 4077 | kFieldOptimizedInvokeType + kFieldOptimizedInvokeTypeSize; |
| 4078 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4079 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4080 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4081 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4082 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4083 | "Too many packed fields."); |
| 4084 | using OptimizedInvokeTypeField = |
| 4085 | BitField<InvokeType, kFieldOptimizedInvokeType, kFieldOptimizedInvokeTypeSize>; |
| 4086 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4087 | kFieldClinitCheckRequirement, |
| 4088 | kFieldClinitCheckRequirementSize>; |
| 4089 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4090 | // The target method may refer to different dex file or method index than the original |
| 4091 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 4092 | // in derived class to increase visibility. |
| 4093 | MethodReference target_method_; |
| 4094 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4095 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4096 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4097 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4098 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4099 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4100 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4101 | class HInvokeVirtual FINAL : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4102 | public: |
| 4103 | HInvokeVirtual(ArenaAllocator* arena, |
| 4104 | uint32_t number_of_arguments, |
| 4105 | Primitive::Type return_type, |
| 4106 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4107 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4108 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4109 | : HInvoke(arena, number_of_arguments, 0u, return_type, dex_pc, dex_method_index, kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4110 | vtable_index_(vtable_index) {} |
| 4111 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4112 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4113 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4114 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4115 | } |
| 4116 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4117 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4118 | |
| 4119 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4120 | |
| 4121 | private: |
| 4122 | const uint32_t vtable_index_; |
| 4123 | |
| 4124 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 4125 | }; |
| 4126 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4127 | class HInvokeInterface FINAL : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4128 | public: |
| 4129 | HInvokeInterface(ArenaAllocator* arena, |
| 4130 | uint32_t number_of_arguments, |
| 4131 | Primitive::Type return_type, |
| 4132 | uint32_t dex_pc, |
| 4133 | uint32_t dex_method_index, |
| 4134 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4135 | : 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] | 4136 | imt_index_(imt_index) {} |
| 4137 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4138 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4139 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4140 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4141 | } |
| 4142 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4143 | uint32_t GetImtIndex() const { return imt_index_; } |
| 4144 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4145 | |
| 4146 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4147 | |
| 4148 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4149 | const uint32_t imt_index_; |
| 4150 | |
| 4151 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 4152 | }; |
| 4153 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4154 | class HNeg FINAL : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4155 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4156 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4157 | : HUnaryOperation(result_type, input, dex_pc) { |
| 4158 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(input->GetType())); |
| 4159 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4160 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4161 | template <typename T> T Compute(T x) const { return -x; } |
| 4162 | |
| 4163 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4164 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4165 | } |
| 4166 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4167 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4168 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4169 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4170 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4171 | } |
| 4172 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4173 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4174 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4175 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4176 | DECLARE_INSTRUCTION(Neg); |
| 4177 | |
| 4178 | private: |
| 4179 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 4180 | }; |
| 4181 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4182 | class HNewArray FINAL : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4183 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4184 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4185 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4186 | uint32_t dex_pc, |
| 4187 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4188 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4189 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4190 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4191 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4192 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4193 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4194 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 4195 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4196 | } |
| 4197 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4198 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4199 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4200 | |
| 4201 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4202 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4203 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4204 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4205 | bool CanThrow() const OVERRIDE { return true; } |
| 4206 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4207 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4208 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4209 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4210 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4211 | DECLARE_INSTRUCTION(NewArray); |
| 4212 | |
| 4213 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4214 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 4215 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4216 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4217 | |
| 4218 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 4219 | }; |
| 4220 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4221 | class HAdd FINAL : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4222 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4223 | HAdd(Primitive::Type result_type, |
| 4224 | HInstruction* left, |
| 4225 | HInstruction* right, |
| 4226 | uint32_t dex_pc = kNoDexPc) |
| 4227 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4228 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4229 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4230 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4231 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 4232 | |
| 4233 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4234 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4235 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4236 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4237 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4238 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4239 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4240 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4241 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4242 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4243 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4244 | } |
| 4245 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4246 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4247 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4248 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4249 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4250 | DECLARE_INSTRUCTION(Add); |
| 4251 | |
| 4252 | private: |
| 4253 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 4254 | }; |
| 4255 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4256 | class HSub FINAL : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4257 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4258 | HSub(Primitive::Type result_type, |
| 4259 | HInstruction* left, |
| 4260 | HInstruction* right, |
| 4261 | uint32_t dex_pc = kNoDexPc) |
| 4262 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4263 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4264 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 4265 | |
| 4266 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4267 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4268 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4269 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4270 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4271 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4272 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4273 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4274 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4275 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4276 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4277 | } |
| 4278 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4279 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4280 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4281 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4282 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4283 | DECLARE_INSTRUCTION(Sub); |
| 4284 | |
| 4285 | private: |
| 4286 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 4287 | }; |
| 4288 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4289 | class HMul FINAL : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4290 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4291 | HMul(Primitive::Type result_type, |
| 4292 | HInstruction* left, |
| 4293 | HInstruction* right, |
| 4294 | uint32_t dex_pc = kNoDexPc) |
| 4295 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4296 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4297 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4298 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4299 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 4300 | |
| 4301 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4302 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4303 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4304 | } |
| 4305 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4306 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4307 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4308 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4309 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4310 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4311 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4312 | } |
| 4313 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4314 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4315 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4316 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4317 | |
| 4318 | DECLARE_INSTRUCTION(Mul); |
| 4319 | |
| 4320 | private: |
| 4321 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 4322 | }; |
| 4323 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4324 | class HDiv FINAL : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4325 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4326 | HDiv(Primitive::Type result_type, |
| 4327 | HInstruction* left, |
| 4328 | HInstruction* right, |
| 4329 | uint32_t dex_pc) |
| 4330 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4331 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4332 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4333 | T ComputeIntegral(T x, T y) const { |
| 4334 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4335 | // Our graph structure ensures we never have 0 for `y` during |
| 4336 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4337 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4338 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4339 | return (y == -1) ? -x : x / y; |
| 4340 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4341 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4342 | template <typename T> |
| 4343 | T ComputeFP(T x, T y) const { |
| 4344 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4345 | return x / y; |
| 4346 | } |
| 4347 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4348 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4349 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4350 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4351 | } |
| 4352 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4353 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4354 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4355 | } |
| 4356 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4357 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4358 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4359 | } |
| 4360 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4361 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4362 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4363 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4364 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4365 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4366 | // The generated code can use a runtime call. |
| 4367 | return SideEffects::CanTriggerGC(); |
| 4368 | } |
| 4369 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4370 | DECLARE_INSTRUCTION(Div); |
| 4371 | |
| 4372 | private: |
| 4373 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 4374 | }; |
| 4375 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4376 | class HRem FINAL : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4377 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4378 | HRem(Primitive::Type result_type, |
| 4379 | HInstruction* left, |
| 4380 | HInstruction* right, |
| 4381 | uint32_t dex_pc) |
| 4382 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4383 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4384 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4385 | T ComputeIntegral(T x, T y) const { |
| 4386 | DCHECK(!Primitive::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4387 | // Our graph structure ensures we never have 0 for `y` during |
| 4388 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4389 | DCHECK_NE(y, 0); |
| 4390 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 4391 | return (y == -1) ? 0 : x % y; |
| 4392 | } |
| 4393 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4394 | template <typename T> |
| 4395 | T ComputeFP(T x, T y) const { |
| 4396 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 4397 | return std::fmod(x, y); |
| 4398 | } |
| 4399 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4400 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4401 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4402 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4403 | } |
| 4404 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4405 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4406 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4407 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4408 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4409 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4410 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4411 | } |
| 4412 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4413 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4414 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4415 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4416 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4417 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4418 | return SideEffects::CanTriggerGC(); |
| 4419 | } |
| 4420 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4421 | DECLARE_INSTRUCTION(Rem); |
| 4422 | |
| 4423 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4424 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 4425 | }; |
| 4426 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4427 | class HDivZeroCheck FINAL : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4428 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4429 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| 4430 | // constructor. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4431 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 4432 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4433 | SetRawInputAt(0, value); |
| 4434 | } |
| 4435 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 4436 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 4437 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4438 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4439 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 4440 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4441 | return true; |
| 4442 | } |
| 4443 | |
| 4444 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4445 | bool CanThrow() const OVERRIDE { return true; } |
| 4446 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4447 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 4448 | |
| 4449 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 4450 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 4451 | }; |
| 4452 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4453 | class HShl FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4454 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4455 | HShl(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4456 | HInstruction* value, |
| 4457 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4458 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4459 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4460 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4461 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4462 | } |
| 4463 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4464 | template <typename T> |
| 4465 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4466 | return value << (distance & max_shift_distance); |
| 4467 | } |
| 4468 | |
| 4469 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4470 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4471 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4472 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4473 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4474 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4475 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4476 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4477 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4478 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4479 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4480 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4481 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4482 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4483 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4484 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4485 | UNREACHABLE(); |
| 4486 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4487 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4488 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4489 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4490 | UNREACHABLE(); |
| 4491 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4492 | |
| 4493 | DECLARE_INSTRUCTION(Shl); |
| 4494 | |
| 4495 | private: |
| 4496 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 4497 | }; |
| 4498 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4499 | class HShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4500 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4501 | HShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4502 | HInstruction* value, |
| 4503 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4504 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4505 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4506 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4507 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4508 | } |
| 4509 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4510 | template <typename T> |
| 4511 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4512 | return value >> (distance & max_shift_distance); |
| 4513 | } |
| 4514 | |
| 4515 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4516 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4517 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4518 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4519 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4520 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4521 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4522 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4523 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4524 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4525 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4526 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4527 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4528 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4529 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4530 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4531 | UNREACHABLE(); |
| 4532 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4533 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4534 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4535 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4536 | UNREACHABLE(); |
| 4537 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4538 | |
| 4539 | DECLARE_INSTRUCTION(Shr); |
| 4540 | |
| 4541 | private: |
| 4542 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 4543 | }; |
| 4544 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4545 | class HUShr FINAL : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4546 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4547 | HUShr(Primitive::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4548 | HInstruction* value, |
| 4549 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4550 | uint32_t dex_pc = kNoDexPc) |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4551 | : HBinaryOperation(result_type, value, distance, SideEffects::None(), dex_pc) { |
| 4552 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4553 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4554 | } |
| 4555 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4556 | template <typename T> |
| 4557 | T Compute(T value, int32_t distance, int32_t max_shift_distance) const { |
| 4558 | typedef typename std::make_unsigned<T>::type V; |
| 4559 | V ux = static_cast<V>(value); |
| 4560 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 4561 | } |
| 4562 | |
| 4563 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4564 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4565 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4566 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4567 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4568 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4569 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4570 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4571 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4572 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4573 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4574 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4575 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4576 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4577 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4578 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4579 | UNREACHABLE(); |
| 4580 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4581 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4582 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4583 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4584 | UNREACHABLE(); |
| 4585 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 4586 | |
| 4587 | DECLARE_INSTRUCTION(UShr); |
| 4588 | |
| 4589 | private: |
| 4590 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 4591 | }; |
| 4592 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4593 | class HAnd FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4594 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4595 | HAnd(Primitive::Type result_type, |
| 4596 | HInstruction* left, |
| 4597 | HInstruction* right, |
| 4598 | uint32_t dex_pc = kNoDexPc) |
| 4599 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4600 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4601 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4602 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4603 | 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] | 4604 | |
| 4605 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4606 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4607 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4608 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4609 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4610 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4611 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4612 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4613 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4614 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4615 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4616 | UNREACHABLE(); |
| 4617 | } |
| 4618 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4619 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4620 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4621 | UNREACHABLE(); |
| 4622 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4623 | |
| 4624 | DECLARE_INSTRUCTION(And); |
| 4625 | |
| 4626 | private: |
| 4627 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4628 | }; |
| 4629 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4630 | class HOr FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4631 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4632 | HOr(Primitive::Type result_type, |
| 4633 | HInstruction* left, |
| 4634 | HInstruction* right, |
| 4635 | uint32_t dex_pc = kNoDexPc) |
| 4636 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4637 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4638 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4639 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4640 | 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] | 4641 | |
| 4642 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4643 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4644 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4645 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4646 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4647 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4648 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4649 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4650 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4651 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4652 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4653 | UNREACHABLE(); |
| 4654 | } |
| 4655 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4656 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4657 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4658 | UNREACHABLE(); |
| 4659 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4660 | |
| 4661 | DECLARE_INSTRUCTION(Or); |
| 4662 | |
| 4663 | private: |
| 4664 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4665 | }; |
| 4666 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4667 | class HXor FINAL : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4668 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4669 | HXor(Primitive::Type result_type, |
| 4670 | HInstruction* left, |
| 4671 | HInstruction* right, |
| 4672 | uint32_t dex_pc = kNoDexPc) |
| 4673 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4674 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4675 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4676 | |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 4677 | 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] | 4678 | |
| 4679 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4680 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4681 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4682 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4683 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4684 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4685 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4686 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4687 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4688 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4689 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4690 | UNREACHABLE(); |
| 4691 | } |
| 4692 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4693 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4694 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4695 | UNREACHABLE(); |
| 4696 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4697 | |
| 4698 | DECLARE_INSTRUCTION(Xor); |
| 4699 | |
| 4700 | private: |
| 4701 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4702 | }; |
| 4703 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4704 | class HRor FINAL : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4705 | public: |
| 4706 | HRor(Primitive::Type result_type, HInstruction* value, HInstruction* distance) |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4707 | : HBinaryOperation(result_type, value, distance) { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4708 | DCHECK_EQ(result_type, Primitive::PrimitiveKind(value->GetType())); |
| 4709 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 4710 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4711 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4712 | template <typename T> |
| 4713 | T Compute(T value, int32_t distance, int32_t max_shift_value) const { |
| 4714 | typedef typename std::make_unsigned<T>::type V; |
| 4715 | V ux = static_cast<V>(value); |
| 4716 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4717 | return static_cast<T>(ux); |
| 4718 | } else { |
| 4719 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4720 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 4721 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4722 | } |
| 4723 | } |
| 4724 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4725 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4726 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4727 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4728 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4729 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4730 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4731 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4732 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4733 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 4734 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4735 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 4736 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4737 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4738 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 4739 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4740 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4741 | UNREACHABLE(); |
| 4742 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 4743 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 4744 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4745 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4746 | UNREACHABLE(); |
| 4747 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 4748 | |
| 4749 | DECLARE_INSTRUCTION(Ror); |
| 4750 | |
| 4751 | private: |
| 4752 | DISALLOW_COPY_AND_ASSIGN(HRor); |
| 4753 | }; |
| 4754 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4755 | // The value of a parameter in this method. Its location depends on |
| 4756 | // the calling convention. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4757 | class HParameterValue FINAL : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4758 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4759 | HParameterValue(const DexFile& dex_file, |
| 4760 | uint16_t type_index, |
| 4761 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4762 | Primitive::Type parameter_type, |
| 4763 | bool is_this = false) |
| 4764 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4765 | dex_file_(dex_file), |
| 4766 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4767 | index_(index) { |
| 4768 | SetPackedFlag<kFlagIsThis>(is_this); |
| 4769 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 4770 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4771 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4772 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4773 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4774 | uint8_t GetIndex() const { return index_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4775 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4776 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4777 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 4778 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4779 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4780 | DECLARE_INSTRUCTION(ParameterValue); |
| 4781 | |
| 4782 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4783 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4784 | static constexpr size_t kFlagIsThis = kNumberOfExpressionPackedBits; |
| 4785 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 4786 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 4787 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 4788 | "Too many packed fields."); |
| 4789 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4790 | const DexFile& dex_file_; |
| 4791 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4792 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4793 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4794 | const uint8_t index_; |
| 4795 | |
| 4796 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4797 | }; |
| 4798 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4799 | class HNot FINAL : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4800 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4801 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4802 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4803 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4804 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 4805 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4806 | return true; |
| 4807 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4808 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4809 | template <typename T> T Compute(T x) const { return ~x; } |
| 4810 | |
| 4811 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4812 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4813 | } |
| 4814 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4815 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4816 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4817 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4818 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4819 | UNREACHABLE(); |
| 4820 | } |
| 4821 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4822 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4823 | UNREACHABLE(); |
| 4824 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4825 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4826 | DECLARE_INSTRUCTION(Not); |
| 4827 | |
| 4828 | private: |
| 4829 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4830 | }; |
| 4831 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4832 | class HBooleanNot FINAL : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4833 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4834 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4835 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4836 | |
| 4837 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 4838 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4839 | return true; |
| 4840 | } |
| 4841 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4842 | template <typename T> bool Compute(T x) const { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4843 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4844 | return !x; |
| 4845 | } |
| 4846 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4847 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4848 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4849 | } |
| 4850 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4851 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4852 | UNREACHABLE(); |
| 4853 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4854 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4855 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4856 | UNREACHABLE(); |
| 4857 | } |
| 4858 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4859 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4860 | UNREACHABLE(); |
| 4861 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4862 | |
| 4863 | DECLARE_INSTRUCTION(BooleanNot); |
| 4864 | |
| 4865 | private: |
| 4866 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4867 | }; |
| 4868 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4869 | class HTypeConversion FINAL : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4870 | public: |
| 4871 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4872 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4873 | : HExpression(result_type, |
| 4874 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4875 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4876 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 4877 | // Invariant: We should never generate a conversion to a Boolean value. |
| 4878 | DCHECK_NE(Primitive::kPrimBoolean, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4879 | } |
| 4880 | |
| 4881 | HInstruction* GetInput() const { return InputAt(0); } |
| 4882 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4883 | Primitive::Type GetResultType() const { return GetType(); } |
| 4884 | |
| 4885 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 4886 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4887 | return true; |
| 4888 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4889 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4890 | // Try to statically evaluate the conversion and return a HConstant |
| 4891 | // containing the result. If the input cannot be converted, return nullptr. |
| 4892 | HConstant* TryStaticEvaluation() const; |
| 4893 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4894 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4895 | Primitive::Type result_type) { |
| 4896 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4897 | // in the compilation process we do not know what architecture we will |
| 4898 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4899 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4900 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4901 | return SideEffects::CanTriggerGC(); |
| 4902 | } |
| 4903 | return SideEffects::None(); |
| 4904 | } |
| 4905 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4906 | DECLARE_INSTRUCTION(TypeConversion); |
| 4907 | |
| 4908 | private: |
| 4909 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4910 | }; |
| 4911 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4912 | static constexpr uint32_t kNoRegNumber = -1; |
| 4913 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4914 | class HNullCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4915 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4916 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| 4917 | // constructor. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4918 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 4919 | : HExpression(value->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4920 | SetRawInputAt(0, value); |
| 4921 | } |
| 4922 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4923 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 4924 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4925 | return true; |
| 4926 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4927 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4928 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4929 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4930 | bool CanThrow() const OVERRIDE { return true; } |
| 4931 | |
| 4932 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4933 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4934 | |
| 4935 | DECLARE_INSTRUCTION(NullCheck); |
| 4936 | |
| 4937 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4938 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4939 | }; |
| 4940 | |
| 4941 | class FieldInfo : public ValueObject { |
| 4942 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4943 | FieldInfo(MemberOffset field_offset, |
| 4944 | Primitive::Type field_type, |
| 4945 | bool is_volatile, |
| 4946 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4947 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4948 | const DexFile& dex_file, |
| 4949 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4950 | : field_offset_(field_offset), |
| 4951 | field_type_(field_type), |
| 4952 | is_volatile_(is_volatile), |
| 4953 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4954 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4955 | dex_file_(dex_file), |
| 4956 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4957 | |
| 4958 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4959 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4960 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4961 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4962 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4963 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4964 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4965 | |
| 4966 | private: |
| 4967 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4968 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4969 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4970 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4971 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4972 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4973 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4974 | }; |
| 4975 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4976 | class HInstanceFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4977 | public: |
| 4978 | HInstanceFieldGet(HInstruction* value, |
| 4979 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4980 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4981 | bool is_volatile, |
| 4982 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4983 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4984 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4985 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4986 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4987 | : HExpression(field_type, |
| 4988 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4989 | dex_pc), |
| 4990 | field_info_(field_offset, |
| 4991 | field_type, |
| 4992 | is_volatile, |
| 4993 | field_idx, |
| 4994 | declaring_class_def_index, |
| 4995 | dex_file, |
| 4996 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4997 | SetRawInputAt(0, value); |
| 4998 | } |
| 4999 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5000 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5001 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5002 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5003 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5004 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5005 | } |
| 5006 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5007 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5008 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5012 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5013 | } |
| 5014 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5015 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5016 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5017 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5018 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5019 | |
| 5020 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5021 | |
| 5022 | private: |
| 5023 | const FieldInfo field_info_; |
| 5024 | |
| 5025 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 5026 | }; |
| 5027 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5028 | class HInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5029 | public: |
| 5030 | HInstanceFieldSet(HInstruction* object, |
| 5031 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5032 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5033 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5034 | bool is_volatile, |
| 5035 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5036 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5037 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5038 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5039 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5040 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5041 | dex_pc), |
| 5042 | field_info_(field_offset, |
| 5043 | field_type, |
| 5044 | is_volatile, |
| 5045 | field_idx, |
| 5046 | declaring_class_def_index, |
| 5047 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5048 | dex_cache) { |
| 5049 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5050 | SetRawInputAt(0, object); |
| 5051 | SetRawInputAt(1, value); |
| 5052 | } |
| 5053 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5054 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5055 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5056 | } |
| 5057 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5058 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5059 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5060 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5061 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5062 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5063 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5064 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5065 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5066 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5067 | |
| 5068 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5069 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5070 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5071 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5072 | "Too many packed fields."); |
| 5073 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5074 | const FieldInfo field_info_; |
| 5075 | |
| 5076 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 5077 | }; |
| 5078 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5079 | class HArrayGet FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5080 | public: |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5081 | HArrayGet(HInstruction* array, HInstruction* index, Primitive::Type type, uint32_t dex_pc) |
| 5082 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5083 | SetRawInputAt(0, array); |
| 5084 | SetRawInputAt(1, index); |
| 5085 | } |
| 5086 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5087 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5088 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5089 | return true; |
| 5090 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5091 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5092 | // TODO: We can be smarter here. |
| 5093 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 5094 | // which generates the implicit null check. There are cases when these can be removed |
| 5095 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 5096 | // implicit check here (as long as the address falls in the first page). |
| 5097 | return false; |
| 5098 | } |
| 5099 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5100 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5101 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5102 | if (kIsDebugBuild && result) { |
| 5103 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5104 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5105 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| 5106 | if (Primitive::IsIntOrLongType(GetType())) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5107 | DCHECK(Primitive::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5108 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5109 | DCHECK(Primitive::IsFloatingPointType(GetType())) << GetType(); |
| 5110 | DCHECK(Primitive::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5111 | } |
| 5112 | } |
| 5113 | return result; |
| 5114 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5115 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5116 | HInstruction* GetArray() const { return InputAt(0); } |
| 5117 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5118 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5119 | DECLARE_INSTRUCTION(ArrayGet); |
| 5120 | |
| 5121 | private: |
| 5122 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 5123 | }; |
| 5124 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5125 | class HArraySet FINAL : public HTemplateInstruction<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5126 | public: |
| 5127 | HArraySet(HInstruction* array, |
| 5128 | HInstruction* index, |
| 5129 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5130 | Primitive::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5131 | uint32_t dex_pc) |
| 5132 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5133 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| 5134 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == Primitive::kPrimNot); |
| 5135 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5136 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5137 | SetRawInputAt(0, array); |
| 5138 | SetRawInputAt(1, index); |
| 5139 | SetRawInputAt(2, value); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5140 | // Make a best guess now, may be refined during SSA building. |
| 5141 | ComputeSideEffects(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5142 | } |
| 5143 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5144 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5145 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5146 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5147 | } |
| 5148 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5149 | // Can throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5150 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5151 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5152 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5153 | // TODO: Same as for ArrayGet. |
| 5154 | return false; |
| 5155 | } |
| 5156 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5157 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5158 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5159 | } |
| 5160 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5161 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5162 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5163 | } |
| 5164 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5165 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5166 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5167 | } |
| 5168 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5169 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5170 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5171 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5172 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5173 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5174 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5175 | HInstruction* GetArray() const { return InputAt(0); } |
| 5176 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5177 | HInstruction* GetValue() const { return InputAt(2); } |
| 5178 | |
| 5179 | Primitive::Type GetComponentType() const { |
| 5180 | // The Dex format does not type floating point index operations. Since the |
| 5181 | // `expected_component_type_` is set during building and can therefore not |
| 5182 | // be correct, we also check what is the value type. If it is a floating |
| 5183 | // point type, we must use that type. |
| 5184 | Primitive::Type value_type = GetValue()->GetType(); |
| 5185 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 5186 | ? value_type |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5187 | : GetRawExpectedComponentType(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5188 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 5189 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5190 | Primitive::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5191 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5192 | } |
| 5193 | |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5194 | void ComputeSideEffects() { |
| 5195 | Primitive::Type type = GetComponentType(); |
| 5196 | SetSideEffects(SideEffects::ArrayWriteOfType(type).Union( |
| 5197 | SideEffectsForArchRuntimeCalls(type))); |
| 5198 | } |
| 5199 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5200 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 5201 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 5202 | } |
| 5203 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5204 | DECLARE_INSTRUCTION(ArraySet); |
| 5205 | |
| 5206 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5207 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 5208 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| 5209 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5210 | static constexpr size_t kFlagNeedsTypeCheck = |
| 5211 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 5212 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5213 | // Cached information for the reference_type_info_ so that codegen |
| 5214 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5215 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 5216 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 5217 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 5218 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5219 | using ExpectedComponentTypeField = |
| 5220 | BitField<Primitive::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5221 | |
| 5222 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 5223 | }; |
| 5224 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5225 | class HArrayLength FINAL : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5226 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 5227 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5228 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5229 | // Note that arrays do not change length, so the instruction does not |
| 5230 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5231 | SetRawInputAt(0, array); |
| 5232 | } |
| 5233 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5234 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5235 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5236 | return true; |
| 5237 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5238 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 5239 | return obj == InputAt(0); |
| 5240 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5241 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5242 | void MarkAsStringLength() { SetPackedFlag<kFlagIsStringLength>(); } |
| 5243 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 5244 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5245 | DECLARE_INSTRUCTION(ArrayLength); |
| 5246 | |
| 5247 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 5248 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 5249 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 5250 | // determine whether a particular HArrayLength is actually a String.length() by |
| 5251 | // looking at the type of the input but that requires holding the mutator lock, so |
| 5252 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| 5253 | static constexpr size_t kFlagIsStringLength = kNumberOfExpressionPackedBits; |
| 5254 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 5255 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5256 | "Too many packed fields."); |
| 5257 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5258 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 5259 | }; |
| 5260 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5261 | class HBoundsCheck FINAL : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5262 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5263 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| 5264 | // constructor. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5265 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5266 | : HExpression(index->GetType(), SideEffects::CanTriggerGC(), dex_pc) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5267 | DCHECK_EQ(Primitive::kPrimInt, Primitive::PrimitiveKind(index->GetType())); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5268 | SetRawInputAt(0, index); |
| 5269 | SetRawInputAt(1, length); |
| 5270 | } |
| 5271 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5272 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5273 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5274 | return true; |
| 5275 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5276 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5277 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5278 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5279 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5280 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5281 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5282 | |
| 5283 | DECLARE_INSTRUCTION(BoundsCheck); |
| 5284 | |
| 5285 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5286 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 5287 | }; |
| 5288 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5289 | class HSuspendCheck FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5290 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 5291 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5292 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5293 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5294 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5295 | return true; |
| 5296 | } |
| 5297 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5298 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 5299 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5300 | |
| 5301 | DECLARE_INSTRUCTION(SuspendCheck); |
| 5302 | |
| 5303 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 5304 | // Only used for code generation, in order to share the same slow path between back edges |
| 5305 | // of a same loop. |
| 5306 | SlowPathCode* slow_path_; |
| 5307 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 5308 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 5309 | }; |
| 5310 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 5311 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 5312 | // It ensures that we can generate line number and local variables at this point. |
| 5313 | class HNativeDebugInfo : public HTemplateInstruction<0> { |
| 5314 | public: |
| 5315 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| 5316 | : HTemplateInstruction<0>(SideEffects::None(), dex_pc) {} |
| 5317 | |
| 5318 | bool NeedsEnvironment() const OVERRIDE { |
| 5319 | return true; |
| 5320 | } |
| 5321 | |
| 5322 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 5323 | |
| 5324 | private: |
| 5325 | DISALLOW_COPY_AND_ASSIGN(HNativeDebugInfo); |
| 5326 | }; |
| 5327 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5328 | /** |
| 5329 | * Instruction to load a Class object. |
| 5330 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5331 | class HLoadClass FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5332 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5333 | HLoadClass(HCurrentMethod* current_method, |
| 5334 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5335 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5336 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5337 | uint32_t dex_pc, |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5338 | bool needs_access_check, |
| 5339 | bool is_in_dex_cache) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5340 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5341 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5342 | dex_file_(dex_file), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5343 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5344 | // Referrers class should not need access check. We never inline unverified |
| 5345 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5346 | DCHECK(!is_referrers_class || !needs_access_check); |
| 5347 | |
| 5348 | SetPackedFlag<kFlagIsReferrersClass>(is_referrers_class); |
| 5349 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| 5350 | SetPackedFlag<kFlagIsInDexCache>(is_in_dex_cache); |
| 5351 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 5352 | SetRawInputAt(0, current_method); |
| 5353 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5354 | |
| 5355 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5356 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5357 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 5358 | // Note that we don't need to test for generate_clinit_check_. |
| 5359 | // Whether or not we need to generate the clinit check is processed in |
| 5360 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 5361 | return other->AsLoadClass()->type_index_ == type_index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5362 | other->AsLoadClass()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 5366 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5367 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 5368 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5369 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5370 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5371 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5372 | } |
| 5373 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 5374 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 5375 | // The entrypoint the code generator is going to call does not do |
| 5376 | // clinit of the class. |
| 5377 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5378 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5379 | } |
| 5380 | |
| 5381 | bool CanCallRuntime() const { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5382 | return MustGenerateClinitCheck() || |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5383 | (!IsReferrersClass() && !IsInDexCache()) || |
| 5384 | NeedsAccessCheck(); |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5385 | } |
| 5386 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5387 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5388 | bool CanThrow() const OVERRIDE { |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 5389 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5390 | } |
| 5391 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5392 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 5393 | return loaded_class_rti_; |
| 5394 | } |
| 5395 | |
| 5396 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 5397 | // Make sure we only set exact types (the loaded class should never be merged). |
| 5398 | DCHECK(rti.IsExact()); |
| 5399 | loaded_class_rti_ = rti; |
| 5400 | } |
| 5401 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 5402 | const DexFile& GetDexFile() { return dex_file_; } |
| 5403 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5404 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !IsReferrersClass(); } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 5405 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5406 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5407 | return SideEffects::CanTriggerGC(); |
| 5408 | } |
| 5409 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5410 | bool IsReferrersClass() const { return GetPackedFlag<kFlagIsReferrersClass>(); } |
| 5411 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| 5412 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5413 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 5414 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5415 | DECLARE_INSTRUCTION(LoadClass); |
| 5416 | |
| 5417 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5418 | static constexpr size_t kFlagIsReferrersClass = kNumberOfExpressionPackedBits; |
| 5419 | static constexpr size_t kFlagNeedsAccessCheck = kFlagIsReferrersClass + 1; |
| 5420 | static constexpr size_t kFlagIsInDexCache = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5421 | // Whether this instruction must generate the initialization check. |
| 5422 | // Used for code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5423 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInDexCache + 1; |
| 5424 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagGenerateClInitCheck + 1; |
| 5425 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
| 5426 | |
| 5427 | const uint16_t type_index_; |
| 5428 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5429 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 5430 | ReferenceTypeInfo loaded_class_rti_; |
| 5431 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5432 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 5433 | }; |
| 5434 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5435 | class HLoadString FINAL : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5436 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5437 | // Determines how to load the String. |
| 5438 | enum class LoadKind { |
| 5439 | // Use boot image String* address that will be known at link time. |
| 5440 | // Used for boot image strings referenced by boot image code in non-PIC mode. |
| 5441 | kBootImageLinkTimeAddress, |
| 5442 | |
| 5443 | // Use PC-relative boot image String* address that will be known at link time. |
| 5444 | // Used for boot image strings referenced by boot image code in PIC mode. |
| 5445 | kBootImageLinkTimePcRelative, |
| 5446 | |
| 5447 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 5448 | // Used for boot image strings referenced by apps in AOT- and JIT-compiled code. |
| 5449 | // Note: codegen needs to emit a linker patch if indicated by compiler options' |
| 5450 | // GetIncludePatchInformation(). |
| 5451 | kBootImageAddress, |
| 5452 | |
| 5453 | // Load from the resolved strings array at an absolute address. |
| 5454 | // Used for strings outside the boot image referenced by JIT-compiled code. |
| 5455 | kDexCacheAddress, |
| 5456 | |
| 5457 | // Load from resolved strings array in the dex cache using a PC-relative load. |
| 5458 | // Used for strings outside boot image when we know that we can access |
| 5459 | // the dex cache arrays using a PC-relative load. |
| 5460 | kDexCachePcRelative, |
| 5461 | |
| 5462 | // Load from resolved strings array accessed through the class loaded from |
| 5463 | // the compiled method's own ArtMethod*. This is the default access type when |
| 5464 | // all other types are unavailable. |
| 5465 | kDexCacheViaMethod, |
| 5466 | |
| 5467 | kLast = kDexCacheViaMethod |
| 5468 | }; |
| 5469 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 5470 | HLoadString(HCurrentMethod* current_method, |
| 5471 | uint32_t string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5472 | const DexFile& dex_file, |
| 5473 | uint32_t dex_pc) |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5474 | : HInstruction(SideEffectsForArchRuntimeCalls(), dex_pc), |
| 5475 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5476 | string_index_(string_index) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5477 | SetPackedFlag<kFlagIsInDexCache>(false); |
| 5478 | SetPackedField<LoadKindField>(LoadKind::kDexCacheViaMethod); |
| 5479 | load_data_.ref.dex_file = &dex_file; |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 5480 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5481 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5482 | void SetLoadKindWithAddress(LoadKind load_kind, uint64_t address) { |
| 5483 | DCHECK(HasAddress(load_kind)); |
| 5484 | load_data_.address = address; |
| 5485 | SetLoadKindInternal(load_kind); |
| 5486 | } |
| 5487 | |
| 5488 | void SetLoadKindWithStringReference(LoadKind load_kind, |
| 5489 | const DexFile& dex_file, |
| 5490 | uint32_t string_index) { |
| 5491 | DCHECK(HasStringReference(load_kind)); |
| 5492 | load_data_.ref.dex_file = &dex_file; |
| 5493 | string_index_ = string_index; |
| 5494 | SetLoadKindInternal(load_kind); |
| 5495 | } |
| 5496 | |
| 5497 | void SetLoadKindWithDexCacheReference(LoadKind load_kind, |
| 5498 | const DexFile& dex_file, |
| 5499 | uint32_t element_index) { |
| 5500 | DCHECK(HasDexCacheReference(load_kind)); |
| 5501 | load_data_.ref.dex_file = &dex_file; |
| 5502 | load_data_.ref.dex_cache_element_index = element_index; |
| 5503 | SetLoadKindInternal(load_kind); |
| 5504 | } |
| 5505 | |
| 5506 | LoadKind GetLoadKind() const { |
| 5507 | return GetPackedField<LoadKindField>(); |
| 5508 | } |
| 5509 | |
| 5510 | const DexFile& GetDexFile() const; |
| 5511 | |
| 5512 | uint32_t GetStringIndex() const { |
| 5513 | DCHECK(HasStringReference(GetLoadKind()) || /* For slow paths. */ !IsInDexCache()); |
| 5514 | return string_index_; |
| 5515 | } |
| 5516 | |
| 5517 | uint32_t GetDexCacheElementOffset() const; |
| 5518 | |
| 5519 | uint64_t GetAddress() const { |
| 5520 | DCHECK(HasAddress(GetLoadKind())); |
| 5521 | return load_data_.address; |
| 5522 | } |
| 5523 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5524 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5525 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5526 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5527 | |
| 5528 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 5529 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5530 | // Will call the runtime if we need to load the string through |
| 5531 | // the dex cache and the string is not guaranteed to be there yet. |
| 5532 | bool NeedsEnvironment() const OVERRIDE { |
| 5533 | LoadKind load_kind = GetLoadKind(); |
| 5534 | if (load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5535 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5536 | load_kind == LoadKind::kBootImageAddress) { |
| 5537 | return false; |
| 5538 | } |
| 5539 | return !IsInDexCache(); |
| 5540 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5541 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5542 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 5543 | return GetLoadKind() == LoadKind::kDexCacheViaMethod; |
| 5544 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5545 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 5546 | bool CanBeNull() const OVERRIDE { return false; } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5547 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5548 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5549 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 5550 | return SideEffects::CanTriggerGC(); |
| 5551 | } |
| 5552 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5553 | bool IsInDexCache() const { return GetPackedFlag<kFlagIsInDexCache>(); } |
| 5554 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5555 | void MarkInDexCache() { |
| 5556 | SetPackedFlag<kFlagIsInDexCache>(true); |
| 5557 | DCHECK(!NeedsEnvironment()); |
| 5558 | RemoveEnvironment(); |
Vladimir Marko | ace7a00 | 2016-04-05 11:18:49 +0100 | [diff] [blame] | 5559 | SetSideEffects(SideEffects::None()); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5562 | void AddSpecialInput(HInstruction* special_input); |
| 5563 | |
| 5564 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 5565 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 5566 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 5567 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5568 | } |
| 5569 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5570 | Primitive::Type GetType() const OVERRIDE { |
| 5571 | return Primitive::kPrimNot; |
| 5572 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5573 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5574 | DECLARE_INSTRUCTION(LoadString); |
| 5575 | |
| 5576 | private: |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5577 | static constexpr size_t kFlagIsInDexCache = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5578 | static constexpr size_t kFieldLoadKind = kFlagIsInDexCache + 1; |
| 5579 | static constexpr size_t kFieldLoadKindSize = |
| 5580 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 5581 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5582 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5583 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5584 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5585 | static bool HasStringReference(LoadKind load_kind) { |
| 5586 | return load_kind == LoadKind::kBootImageLinkTimeAddress || |
| 5587 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| 5588 | load_kind == LoadKind::kDexCacheViaMethod; |
| 5589 | } |
| 5590 | |
| 5591 | static bool HasAddress(LoadKind load_kind) { |
| 5592 | return load_kind == LoadKind::kBootImageAddress || load_kind == LoadKind::kDexCacheAddress; |
| 5593 | } |
| 5594 | |
| 5595 | static bool HasDexCacheReference(LoadKind load_kind) { |
| 5596 | return load_kind == LoadKind::kDexCachePcRelative; |
| 5597 | } |
| 5598 | |
| 5599 | void SetLoadKindInternal(LoadKind load_kind); |
| 5600 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5601 | HUserRecord<HInstruction*> special_input_; |
| 5602 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5603 | // String index serves also as the hash code and it's also needed for slow-paths, |
| 5604 | // so it must not be overwritten with other load data. |
| 5605 | uint32_t string_index_; |
| 5606 | |
| 5607 | union { |
| 5608 | struct { |
| 5609 | const DexFile* dex_file; // For string reference and dex cache reference. |
| 5610 | uint32_t dex_cache_element_index; // Only for dex cache reference. |
| 5611 | } ref; |
| 5612 | uint64_t address; // Up to 64-bit, needed for kDexCacheAddress on 64-bit targets. |
| 5613 | } load_data_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5614 | |
| 5615 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 5616 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5617 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 5618 | |
| 5619 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5620 | inline const DexFile& HLoadString::GetDexFile() const { |
| 5621 | DCHECK(HasStringReference(GetLoadKind()) || HasDexCacheReference(GetLoadKind())) |
| 5622 | << GetLoadKind(); |
| 5623 | return *load_data_.ref.dex_file; |
| 5624 | } |
| 5625 | |
| 5626 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5627 | inline uint32_t HLoadString::GetDexCacheElementOffset() const { |
| 5628 | DCHECK(HasDexCacheReference(GetLoadKind())) << GetLoadKind(); |
| 5629 | return load_data_.ref.dex_cache_element_index; |
| 5630 | } |
| 5631 | |
| 5632 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| 5633 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
| 5634 | // The special input is used for PC-relative loads on some architectures. |
| 5635 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 5636 | GetLoadKind() == LoadKind::kDexCachePcRelative) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5637 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 5638 | // so use the GetInputRecords() from the base class to set the input record. |
| 5639 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 5640 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 5641 | special_input->AddUseAt(this, 0); |
| 5642 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 5643 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5644 | /** |
| 5645 | * Performs an initialization check on its Class object input. |
| 5646 | */ |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5647 | class HClinitCheck FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5648 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 5649 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 5650 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5651 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5652 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 5653 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5654 | SetRawInputAt(0, constant); |
| 5655 | } |
| 5656 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5657 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5658 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 5659 | return true; |
| 5660 | } |
| 5661 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5662 | bool NeedsEnvironment() const OVERRIDE { |
| 5663 | // May call runtime to initialize the class. |
| 5664 | return true; |
| 5665 | } |
| 5666 | |
Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 5667 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5668 | |
| 5669 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 5670 | |
| 5671 | DECLARE_INSTRUCTION(ClinitCheck); |
| 5672 | |
| 5673 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5674 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 5675 | }; |
| 5676 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5677 | class HStaticFieldGet FINAL : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5678 | public: |
| 5679 | HStaticFieldGet(HInstruction* cls, |
| 5680 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5681 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5682 | bool is_volatile, |
| 5683 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5684 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5685 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5686 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5687 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5688 | : HExpression(field_type, |
| 5689 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5690 | dex_pc), |
| 5691 | field_info_(field_offset, |
| 5692 | field_type, |
| 5693 | is_volatile, |
| 5694 | field_idx, |
| 5695 | declaring_class_def_index, |
| 5696 | dex_file, |
| 5697 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5698 | SetRawInputAt(0, cls); |
| 5699 | } |
| 5700 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5701 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5702 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5703 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5704 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5705 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5706 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | size_t ComputeHashCode() const OVERRIDE { |
| 5710 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5711 | } |
| 5712 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5713 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5714 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5715 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5716 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5717 | |
| 5718 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 5719 | |
| 5720 | private: |
| 5721 | const FieldInfo field_info_; |
| 5722 | |
| 5723 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 5724 | }; |
| 5725 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5726 | class HStaticFieldSet FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5727 | public: |
| 5728 | HStaticFieldSet(HInstruction* cls, |
| 5729 | HInstruction* value, |
| 5730 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5731 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5732 | bool is_volatile, |
| 5733 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5734 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5735 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5736 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5737 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5738 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5739 | dex_pc), |
| 5740 | field_info_(field_offset, |
| 5741 | field_type, |
| 5742 | is_volatile, |
| 5743 | field_idx, |
| 5744 | declaring_class_def_index, |
| 5745 | dex_file, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5746 | dex_cache) { |
| 5747 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5748 | SetRawInputAt(0, cls); |
| 5749 | SetRawInputAt(1, value); |
| 5750 | } |
| 5751 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5752 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5753 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 5754 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5755 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5756 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5757 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5758 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5759 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5760 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5761 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 5762 | |
| 5763 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5764 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5765 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5766 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5767 | "Too many packed fields."); |
| 5768 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 5769 | const FieldInfo field_info_; |
| 5770 | |
| 5771 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 5772 | }; |
| 5773 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5774 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5775 | public: |
| 5776 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 5777 | Primitive::Type field_type, |
| 5778 | uint32_t field_index, |
| 5779 | uint32_t dex_pc) |
| 5780 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5781 | field_index_(field_index) { |
| 5782 | SetRawInputAt(0, obj); |
| 5783 | } |
| 5784 | |
| 5785 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5786 | bool CanThrow() const OVERRIDE { return true; } |
| 5787 | |
| 5788 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5789 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5790 | |
| 5791 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 5792 | |
| 5793 | private: |
| 5794 | const uint32_t field_index_; |
| 5795 | |
| 5796 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 5797 | }; |
| 5798 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5799 | class HUnresolvedInstanceFieldSet FINAL : public HTemplateInstruction<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5800 | public: |
| 5801 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 5802 | HInstruction* value, |
| 5803 | Primitive::Type field_type, |
| 5804 | uint32_t field_index, |
| 5805 | uint32_t dex_pc) |
| 5806 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5807 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5808 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5809 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5810 | SetRawInputAt(0, obj); |
| 5811 | SetRawInputAt(1, value); |
| 5812 | } |
| 5813 | |
| 5814 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5815 | bool CanThrow() const OVERRIDE { return true; } |
| 5816 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5817 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5818 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5819 | |
| 5820 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5821 | |
| 5822 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5823 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5824 | static constexpr size_t kFieldFieldTypeSize = |
| 5825 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5826 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5827 | kFieldFieldType + kFieldFieldTypeSize; |
| 5828 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5829 | "Too many packed fields."); |
| 5830 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5831 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5832 | const uint32_t field_index_; |
| 5833 | |
| 5834 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5835 | }; |
| 5836 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5837 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5838 | public: |
| 5839 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5840 | uint32_t field_index, |
| 5841 | uint32_t dex_pc) |
| 5842 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5843 | field_index_(field_index) { |
| 5844 | } |
| 5845 | |
| 5846 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5847 | bool CanThrow() const OVERRIDE { return true; } |
| 5848 | |
| 5849 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5850 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5851 | |
| 5852 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5853 | |
| 5854 | private: |
| 5855 | const uint32_t field_index_; |
| 5856 | |
| 5857 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5858 | }; |
| 5859 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5860 | class HUnresolvedStaticFieldSet FINAL : public HTemplateInstruction<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5861 | public: |
| 5862 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5863 | Primitive::Type field_type, |
| 5864 | uint32_t field_index, |
| 5865 | uint32_t dex_pc) |
| 5866 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5867 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5868 | SetPackedField<FieldTypeField>(field_type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 5869 | DCHECK_EQ(Primitive::PrimitiveKind(field_type), Primitive::PrimitiveKind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5870 | SetRawInputAt(0, value); |
| 5871 | } |
| 5872 | |
| 5873 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5874 | bool CanThrow() const OVERRIDE { return true; } |
| 5875 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5876 | Primitive::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5877 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5878 | |
| 5879 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5880 | |
| 5881 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5882 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 5883 | static constexpr size_t kFieldFieldTypeSize = |
| 5884 | MinimumBitsToStore(static_cast<size_t>(Primitive::kPrimLast)); |
| 5885 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 5886 | kFieldFieldType + kFieldFieldTypeSize; |
| 5887 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5888 | "Too many packed fields."); |
| 5889 | using FieldTypeField = BitField<Primitive::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| 5890 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 5891 | const uint32_t field_index_; |
| 5892 | |
| 5893 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5894 | }; |
| 5895 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5896 | // Implement the move-exception DEX instruction. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5897 | class HLoadException FINAL : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5898 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5899 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5900 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5901 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5902 | bool CanBeNull() const OVERRIDE { return false; } |
| 5903 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5904 | DECLARE_INSTRUCTION(LoadException); |
| 5905 | |
| 5906 | private: |
| 5907 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5908 | }; |
| 5909 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5910 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5911 | // Must not be removed because the runtime expects the TLS to get cleared. |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5912 | class HClearException FINAL : public HTemplateInstruction<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5913 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5914 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5915 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5916 | |
| 5917 | DECLARE_INSTRUCTION(ClearException); |
| 5918 | |
| 5919 | private: |
| 5920 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5921 | }; |
| 5922 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5923 | class HThrow FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5924 | public: |
| 5925 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5926 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5927 | SetRawInputAt(0, exception); |
| 5928 | } |
| 5929 | |
| 5930 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5931 | |
| 5932 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5933 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5934 | bool CanThrow() const OVERRIDE { return true; } |
| 5935 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5936 | |
| 5937 | DECLARE_INSTRUCTION(Throw); |
| 5938 | |
| 5939 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5940 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5941 | }; |
| 5942 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5943 | /** |
| 5944 | * Implementation strategies for the code generator of a HInstanceOf |
| 5945 | * or `HCheckCast`. |
| 5946 | */ |
| 5947 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5948 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5949 | kExactCheck, // Can do a single class compare. |
| 5950 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5951 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5952 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5953 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5954 | kArrayCheck, // No optimization yet when checking against a generic array. |
| 5955 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5956 | }; |
| 5957 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 5958 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 5959 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5960 | class HInstanceOf FINAL : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5961 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5962 | HInstanceOf(HInstruction* object, |
| 5963 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5964 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5965 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5966 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5967 | SideEffectsForArchRuntimeCalls(check_kind), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5968 | dex_pc) { |
| 5969 | SetPackedField<TypeCheckKindField>(check_kind); |
| 5970 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5971 | SetRawInputAt(0, object); |
| 5972 | SetRawInputAt(1, constant); |
| 5973 | } |
| 5974 | |
| 5975 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5976 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 5977 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5978 | return true; |
| 5979 | } |
| 5980 | |
| 5981 | bool NeedsEnvironment() const OVERRIDE { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5982 | return CanCallRuntime(GetTypeCheckKind()); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5983 | } |
| 5984 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5985 | // Used only in code generation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5986 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 5987 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 5988 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 5989 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5990 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5991 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 5992 | // Mips currently does runtime calls for any other checks. |
| 5993 | return check_kind != TypeCheckKind::kExactCheck; |
| 5994 | } |
| 5995 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5996 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5997 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5998 | } |
| 5999 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6000 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6001 | |
| 6002 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6003 | static constexpr size_t kFieldTypeCheckKind = kNumberOfExpressionPackedBits; |
| 6004 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6005 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6006 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6007 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagMustDoNullCheck + 1; |
| 6008 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6009 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6010 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6011 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 6012 | }; |
| 6013 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6014 | class HBoundType FINAL : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6015 | public: |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6016 | HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6017 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6018 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 6019 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 6020 | SetPackedFlag<kFlagCanBeNull>(true); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 6021 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6022 | SetRawInputAt(0, input); |
| 6023 | } |
| 6024 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6025 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6026 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6027 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6028 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6029 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6030 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6031 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 6032 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6033 | } |
| 6034 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6035 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 6036 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6037 | DECLARE_INSTRUCTION(BoundType); |
| 6038 | |
| 6039 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6040 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 6041 | // is false then CanBeNull() cannot be true). |
| 6042 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfExpressionPackedBits; |
| 6043 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 6044 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 6045 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6046 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6047 | // 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] | 6048 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 6049 | // It is used to bound the type in cases like: |
| 6050 | // if (x instanceof ClassX) { |
| 6051 | // // uper_bound_ will be ClassX |
| 6052 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 6053 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 6054 | |
| 6055 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 6056 | }; |
| 6057 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6058 | class HCheckCast FINAL : public HTemplateInstruction<2> { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6059 | public: |
| 6060 | HCheckCast(HInstruction* object, |
| 6061 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 6062 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6063 | uint32_t dex_pc) |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6064 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
| 6065 | SetPackedField<TypeCheckKindField>(check_kind); |
| 6066 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6067 | SetRawInputAt(0, object); |
| 6068 | SetRawInputAt(1, constant); |
| 6069 | } |
| 6070 | |
| 6071 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6072 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 6073 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6074 | return true; |
| 6075 | } |
| 6076 | |
| 6077 | bool NeedsEnvironment() const OVERRIDE { |
| 6078 | // Instruction may throw a CheckCastError. |
| 6079 | return true; |
| 6080 | } |
| 6081 | |
| 6082 | bool CanThrow() const OVERRIDE { return true; } |
| 6083 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6084 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 6085 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 6086 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 6087 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6088 | |
| 6089 | DECLARE_INSTRUCTION(CheckCast); |
| 6090 | |
| 6091 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6092 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 6093 | static constexpr size_t kFieldTypeCheckKindSize = |
| 6094 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 6095 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 6096 | static constexpr size_t kNumberOfCheckCastPackedBits = kFlagMustDoNullCheck + 1; |
| 6097 | static_assert(kNumberOfCheckCastPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6098 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 6099 | |
| 6100 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 6101 | }; |
| 6102 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6103 | class HMemoryBarrier FINAL : public HTemplateInstruction<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6104 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6105 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 6106 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6107 | SideEffects::AllWritesAndReads(), dex_pc) { // Assume write/read on all fields/arrays. |
| 6108 | SetPackedField<BarrierKindField>(barrier_kind); |
| 6109 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6110 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6111 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6112 | |
| 6113 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 6114 | |
| 6115 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6116 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 6117 | static constexpr size_t kFieldBarrierKindSize = |
| 6118 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 6119 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 6120 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 6121 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 6122 | "Too many packed fields."); |
| 6123 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 6124 | |
| 6125 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 6126 | }; |
| 6127 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6128 | class HMonitorOperation FINAL : public HTemplateInstruction<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6129 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6130 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6131 | kEnter, |
| 6132 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6133 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6134 | }; |
| 6135 | |
| 6136 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6137 | : HTemplateInstruction( |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6138 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 6139 | dex_pc) { |
| 6140 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6141 | SetRawInputAt(0, object); |
| 6142 | } |
| 6143 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6144 | // Instruction may go into runtime, so we need an environment. |
| 6145 | bool NeedsEnvironment() const OVERRIDE { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 6146 | |
| 6147 | bool CanThrow() const OVERRIDE { |
| 6148 | // Verifier guarantees that monitor-exit cannot throw. |
| 6149 | // This is important because it allows the HGraphBuilder to remove |
| 6150 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 6151 | return IsEnter(); |
| 6152 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6153 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6154 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 6155 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6156 | |
| 6157 | DECLARE_INSTRUCTION(MonitorOperation); |
| 6158 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6159 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6160 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 6161 | static constexpr size_t kFieldOperationKindSize = |
| 6162 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 6163 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 6164 | kFieldOperationKind + kFieldOperationKindSize; |
| 6165 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6166 | "Too many packed fields."); |
| 6167 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 6168 | |
| 6169 | private: |
| 6170 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 6171 | }; |
| 6172 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6173 | class HSelect FINAL : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6174 | public: |
| 6175 | HSelect(HInstruction* condition, |
| 6176 | HInstruction* true_value, |
| 6177 | HInstruction* false_value, |
| 6178 | uint32_t dex_pc) |
| 6179 | : HExpression(HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| 6180 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 6181 | |
| 6182 | // First input must be `true_value` or `false_value` to allow codegens to |
| 6183 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 6184 | // that architectures which implement HSelect as a conditional move also |
| 6185 | // will not need to invert the condition. |
| 6186 | SetRawInputAt(0, false_value); |
| 6187 | SetRawInputAt(1, true_value); |
| 6188 | SetRawInputAt(2, condition); |
| 6189 | } |
| 6190 | |
| 6191 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 6192 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 6193 | HInstruction* GetCondition() const { return InputAt(2); } |
| 6194 | |
| 6195 | bool CanBeMoved() const OVERRIDE { return true; } |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame^] | 6196 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 6197 | return true; |
| 6198 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 6199 | |
| 6200 | bool CanBeNull() const OVERRIDE { |
| 6201 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 6202 | } |
| 6203 | |
| 6204 | DECLARE_INSTRUCTION(Select); |
| 6205 | |
| 6206 | private: |
| 6207 | DISALLOW_COPY_AND_ASSIGN(HSelect); |
| 6208 | }; |
| 6209 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 6210 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6211 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6212 | MoveOperands(Location source, |
| 6213 | Location destination, |
| 6214 | Primitive::Type type, |
| 6215 | HInstruction* instruction) |
| 6216 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6217 | |
| 6218 | Location GetSource() const { return source_; } |
| 6219 | Location GetDestination() const { return destination_; } |
| 6220 | |
| 6221 | void SetSource(Location value) { source_ = value; } |
| 6222 | void SetDestination(Location value) { destination_ = value; } |
| 6223 | |
| 6224 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 6225 | // destination (but not the source). |
| 6226 | Location MarkPending() { |
| 6227 | DCHECK(!IsPending()); |
| 6228 | Location dest = destination_; |
| 6229 | destination_ = Location::NoLocation(); |
| 6230 | return dest; |
| 6231 | } |
| 6232 | |
| 6233 | void ClearPending(Location dest) { |
| 6234 | DCHECK(IsPending()); |
| 6235 | destination_ = dest; |
| 6236 | } |
| 6237 | |
| 6238 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6239 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 6240 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6241 | } |
| 6242 | |
| 6243 | // True if this blocks a move from the given location. |
| 6244 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 6245 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | // A move is redundant if it's been eliminated, if its source and |
| 6249 | // destination are the same, or if its destination is unneeded. |
| 6250 | bool IsRedundant() const { |
| 6251 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 6252 | } |
| 6253 | |
| 6254 | // We clear both operands to indicate move that's been eliminated. |
| 6255 | void Eliminate() { |
| 6256 | source_ = destination_ = Location::NoLocation(); |
| 6257 | } |
| 6258 | |
| 6259 | bool IsEliminated() const { |
| 6260 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 6261 | return source_.IsInvalid(); |
| 6262 | } |
| 6263 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 6264 | Primitive::Type GetType() const { return type_; } |
| 6265 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6266 | bool Is64BitMove() const { |
| 6267 | return Primitive::Is64BitType(type_); |
| 6268 | } |
| 6269 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6270 | HInstruction* GetInstruction() const { return instruction_; } |
| 6271 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6272 | private: |
| 6273 | Location source_; |
| 6274 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6275 | // The type this move is for. |
| 6276 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6277 | // The instruction this move is assocatied with. Null when this move is |
| 6278 | // for moving an input in the expected locations of user (including a phi user). |
| 6279 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 6280 | // in the same parallel move. |
| 6281 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6282 | }; |
| 6283 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 6284 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 6285 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6286 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 6287 | |
Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6288 | class HParallelMove FINAL : public HTemplateInstruction<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6289 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6290 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6291 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 6292 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 6293 | moves_.reserve(kDefaultNumberOfMoves); |
| 6294 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6295 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 6296 | void AddMove(Location source, |
| 6297 | Location destination, |
| 6298 | Primitive::Type type, |
| 6299 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 6300 | DCHECK(source.IsValid()); |
| 6301 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6302 | if (kIsDebugBuild) { |
| 6303 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6304 | for (const MoveOperands& move : moves_) { |
| 6305 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6306 | // Special case the situation where the move is for the spill slot |
| 6307 | // of the instruction. |
| 6308 | if ((GetPrevious() == instruction) |
| 6309 | || ((GetPrevious() == nullptr) |
| 6310 | && instruction->IsPhi() |
| 6311 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6312 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 6313 | << "Doing parallel moves for the same instruction."; |
| 6314 | } else { |
| 6315 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 6316 | } |
| 6317 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 6318 | } |
| 6319 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6320 | for (const MoveOperands& move : moves_) { |
| 6321 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6322 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6323 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 6324 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 6325 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 6326 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6327 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6328 | } |
| 6329 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6330 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6331 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6332 | } |
| 6333 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6334 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6335 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 6336 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6337 | |
| 6338 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 6339 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 6340 | |
| 6341 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 6342 | }; |
| 6343 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6344 | } // namespace art |
| 6345 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 6346 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 6347 | #include "nodes_shared.h" |
| 6348 | #endif |
Vladimir Marko | b4536b7 | 2015-11-24 13:45:23 +0000 | [diff] [blame] | 6349 | #ifdef ART_ENABLE_CODEGEN_arm |
| 6350 | #include "nodes_arm.h" |
| 6351 | #endif |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6352 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 6353 | #include "nodes_arm64.h" |
| 6354 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 6355 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 6356 | #include "nodes_x86.h" |
| 6357 | #endif |
| 6358 | |
| 6359 | namespace art { |
| 6360 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6361 | class HGraphVisitor : public ValueObject { |
| 6362 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 6363 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 6364 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6365 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 6366 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6367 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 6368 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6369 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6370 | void VisitInsertionOrder(); |
| 6371 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 6372 | // Visit the graph following dominator tree reverse post-order. |
| 6373 | void VisitReversePostOrder(); |
| 6374 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 6375 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 6376 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6377 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6378 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6379 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 6380 | |
| 6381 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6382 | |
| 6383 | #undef DECLARE_VISIT_INSTRUCTION |
| 6384 | |
| 6385 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 6386 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6387 | |
| 6388 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 6389 | }; |
| 6390 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6391 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 6392 | public: |
| 6393 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 6394 | virtual ~HGraphDelegateVisitor() {} |
| 6395 | |
| 6396 | // Visit functions that delegate to to super class. |
| 6397 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6398 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 6399 | |
| 6400 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 6401 | |
| 6402 | #undef DECLARE_VISIT_INSTRUCTION |
| 6403 | |
| 6404 | private: |
| 6405 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 6406 | }; |
| 6407 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6408 | class HInsertionOrderIterator : public ValueObject { |
| 6409 | public: |
| 6410 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 6411 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6412 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 6413 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6414 | void Advance() { ++index_; } |
| 6415 | |
| 6416 | private: |
| 6417 | const HGraph& graph_; |
| 6418 | size_t index_; |
| 6419 | |
| 6420 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 6421 | }; |
| 6422 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6423 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6424 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6425 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 6426 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6427 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6428 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6429 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6430 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 6431 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6432 | void Advance() { ++index_; } |
| 6433 | |
| 6434 | private: |
| 6435 | const HGraph& graph_; |
| 6436 | size_t index_; |
| 6437 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6438 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6439 | }; |
| 6440 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6441 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6442 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6443 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6444 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6445 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6446 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 6447 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6448 | |
| 6449 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6450 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6451 | void Advance() { --index_; } |
| 6452 | |
| 6453 | private: |
| 6454 | const HGraph& graph_; |
| 6455 | size_t index_; |
| 6456 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 6457 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 6458 | }; |
| 6459 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6460 | class HLinearPostOrderIterator : public ValueObject { |
| 6461 | public: |
| 6462 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6463 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6464 | |
| 6465 | bool Done() const { return index_ == 0; } |
| 6466 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6467 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6468 | |
| 6469 | void Advance() { |
| 6470 | --index_; |
| 6471 | DCHECK_GE(index_, 0U); |
| 6472 | } |
| 6473 | |
| 6474 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6475 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6476 | size_t index_; |
| 6477 | |
| 6478 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 6479 | }; |
| 6480 | |
| 6481 | class HLinearOrderIterator : public ValueObject { |
| 6482 | public: |
| 6483 | explicit HLinearOrderIterator(const HGraph& graph) |
| 6484 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 6485 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6486 | bool Done() const { return index_ == order_.size(); } |
| 6487 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6488 | void Advance() { ++index_; } |
| 6489 | |
| 6490 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6491 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 6492 | size_t index_; |
| 6493 | |
| 6494 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 6495 | }; |
| 6496 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6497 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6498 | // of an inner loop. The order in which the blocks are iterated is on their |
| 6499 | // block id. |
| 6500 | class HBlocksInLoopIterator : public ValueObject { |
| 6501 | public: |
| 6502 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 6503 | : blocks_in_loop_(info.GetBlocks()), |
| 6504 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 6505 | index_(0) { |
| 6506 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 6507 | Advance(); |
| 6508 | } |
| 6509 | } |
| 6510 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6511 | bool Done() const { return index_ == blocks_.size(); } |
| 6512 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6513 | void Advance() { |
| 6514 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6515 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6516 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 6517 | break; |
| 6518 | } |
| 6519 | } |
| 6520 | } |
| 6521 | |
| 6522 | private: |
| 6523 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6524 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6525 | size_t index_; |
| 6526 | |
| 6527 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 6528 | }; |
| 6529 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6530 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 6531 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 6532 | // post order. |
| 6533 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 6534 | public: |
| 6535 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 6536 | : blocks_in_loop_(info.GetBlocks()), |
| 6537 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 6538 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6539 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6540 | Advance(); |
| 6541 | } |
| 6542 | } |
| 6543 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6544 | bool Done() const { return index_ == blocks_.size(); } |
| 6545 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6546 | void Advance() { |
| 6547 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6548 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 6549 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6550 | break; |
| 6551 | } |
| 6552 | } |
| 6553 | } |
| 6554 | |
| 6555 | private: |
| 6556 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 6557 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 6558 | size_t index_; |
| 6559 | |
| 6560 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 6561 | }; |
| 6562 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6563 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6564 | if (constant->IsIntConstant()) { |
| 6565 | return constant->AsIntConstant()->GetValue(); |
| 6566 | } else if (constant->IsLongConstant()) { |
| 6567 | return constant->AsLongConstant()->GetValue(); |
| 6568 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 6569 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 6570 | return 0; |
| 6571 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 6572 | } |
| 6573 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 6574 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 6575 | // For the purposes of the compiler, the dex files must actually be the same object |
| 6576 | // if we want to safely treat them as the same. This is especially important for JIT |
| 6577 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 6578 | // times and provide different class resolution but no two class loaders should ever |
| 6579 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 6580 | // all sorts of weird failures. |
| 6581 | return &lhs == &rhs; |
| 6582 | } |
| 6583 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 6584 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 6585 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } \ |
| 6586 | inline const H##type* HInstruction::As##type() const { \ |
| 6587 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 6588 | } \ |
| 6589 | inline H##type* HInstruction::As##type() { \ |
| 6590 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 6591 | } |
| 6592 | |
| 6593 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 6594 | #undef INSTRUCTION_TYPE_CHECK |
| 6595 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 6596 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 6597 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 6598 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 6599 | size_t number_of_new_blocks, |
| 6600 | size_t after) { |
| 6601 | DCHECK_LT(after, blocks->size()); |
| 6602 | size_t old_size = blocks->size(); |
| 6603 | size_t new_size = old_size + number_of_new_blocks; |
| 6604 | blocks->resize(new_size); |
| 6605 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 6606 | } |
| 6607 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 6608 | } // namespace art |
| 6609 | |
| 6610 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |