| 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" |
| David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 27 | #include "base/array_ref.h" |
| Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 28 | #include "base/iteration_range.h" |
| David Sehr | c431b9d | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 29 | #include "base/quasi_atomic.h" |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 30 | #include "base/stl_util.h" |
| David Brazdil | d9c9037 | 2016-09-14 16:53:55 +0100 | [diff] [blame] | 31 | #include "base/transform_array_ref.h" |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 32 | #include "data_type.h" |
| Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 33 | #include "deoptimization_kind.h" |
| David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 34 | #include "dex/dex_file.h" |
| 35 | #include "dex/dex_file_types.h" |
| David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 36 | #include "dex/invoke_type.h" |
| David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 37 | #include "dex/method_reference.h" |
| Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 38 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 39 | #include "handle.h" |
| 40 | #include "handle_scope.h" |
| Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 41 | #include "intrinsics_enum.h" |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 42 | #include "locations.h" |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 43 | #include "mirror/class.h" |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 44 | #include "mirror/method_type.h" |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 45 | #include "offsets.h" |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 46 | #include "utils/intrusive_forward_list.h" |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 47 | |
| 48 | namespace art { |
| 49 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 50 | class ArenaStack; |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 51 | class GraphChecker; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 52 | class HBasicBlock; |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 53 | class HConstructorFence; |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 54 | class HCurrentMethod; |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 55 | class HDoubleConstant; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 56 | class HEnvironment; |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 57 | class HFloatConstant; |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 58 | class HGraphBuilder; |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 59 | class HGraphVisitor; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 60 | class HInstruction; |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 61 | class HIntConstant; |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 62 | class HInvoke; |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 63 | class HLongConstant; |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 64 | class HNullConstant; |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 65 | class HParameterValue; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 66 | class HPhi; |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 67 | class HSuspendCheck; |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 68 | class HTryBoundary; |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 69 | class LiveInterval; |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 70 | class LocationSummary; |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 71 | class SlowPathCode; |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 72 | class SsaBuilder; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 73 | |
| Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 74 | namespace mirror { |
| 75 | class DexCache; |
| 76 | } // namespace mirror |
| 77 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 78 | static const int kDefaultNumberOfBlocks = 8; |
| 79 | static const int kDefaultNumberOfSuccessors = 2; |
| 80 | static const int kDefaultNumberOfPredecessors = 2; |
| David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 81 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 82 | static const int kDefaultNumberOfDominatedBlocks = 1; |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 83 | static const int kDefaultNumberOfBackEdges = 1; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 84 | |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 85 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 86 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 87 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 88 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 89 | |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 90 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 91 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 92 | |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 93 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 94 | |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 95 | static constexpr uint32_t kNoDexPc = -1; |
| 96 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 97 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 98 | // For the purposes of the compiler, the dex files must actually be the same object |
| 99 | // if we want to safely treat them as the same. This is especially important for JIT |
| 100 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 101 | // times and provide different class resolution but no two class loaders should ever |
| 102 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 103 | // all sorts of weird failures. |
| 104 | return &lhs == &rhs; |
| 105 | } |
| 106 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 107 | enum IfCondition { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 108 | // All types. |
| 109 | kCondEQ, // == |
| 110 | kCondNE, // != |
| 111 | // Signed integers and floating-point numbers. |
| 112 | kCondLT, // < |
| 113 | kCondLE, // <= |
| 114 | kCondGT, // > |
| 115 | kCondGE, // >= |
| 116 | // Unsigned integers. |
| 117 | kCondB, // < |
| 118 | kCondBE, // <= |
| 119 | kCondA, // > |
| 120 | kCondAE, // >= |
| Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 121 | // First and last aliases. |
| 122 | kCondFirst = kCondEQ, |
| 123 | kCondLast = kCondAE, |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 126 | enum GraphAnalysisResult { |
| David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 127 | kAnalysisSkipped, |
| David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 128 | kAnalysisInvalidBytecode, |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 129 | kAnalysisFailThrowCatchLoop, |
| 130 | kAnalysisFailAmbiguousArrayOp, |
| 131 | kAnalysisSuccess, |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 134 | template <typename T> |
| 135 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 136 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 137 | } |
| 138 | |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 139 | class HInstructionList : public ValueObject { |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 140 | public: |
| 141 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 142 | |
| 143 | void AddInstruction(HInstruction* instruction); |
| 144 | void RemoveInstruction(HInstruction* instruction); |
| 145 | |
| David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 146 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 147 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 148 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 149 | |
| Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 150 | // Return true if this list contains `instruction`. |
| 151 | bool Contains(HInstruction* instruction) const; |
| 152 | |
| Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 153 | // Return true if `instruction1` is found before `instruction2` in |
| 154 | // this instruction list and false otherwise. Abort if none |
| 155 | // of these instructions is found. |
| 156 | bool FoundBefore(const HInstruction* instruction1, |
| 157 | const HInstruction* instruction2) const; |
| 158 | |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 159 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 160 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 161 | |
| 162 | // Update the block of all instructions to be `block`. |
| 163 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 164 | |
| 165 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 166 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 167 | void Add(const HInstructionList& instruction_list); |
| 168 | |
| David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 169 | // Return the number of instructions in the list. This is an expensive operation. |
| 170 | size_t CountSize() const; |
| 171 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 172 | private: |
| 173 | HInstruction* first_instruction_; |
| 174 | HInstruction* last_instruction_; |
| 175 | |
| 176 | friend class HBasicBlock; |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 177 | friend class HGraph; |
| 178 | friend class HInstruction; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 179 | friend class HInstructionIterator; |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 180 | friend class HInstructionIteratorHandleChanges; |
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 181 | friend class HBackwardInstructionIterator; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 182 | |
| 183 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 184 | }; |
| 185 | |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 186 | class ReferenceTypeInfo : ValueObject { |
| 187 | public: |
| 188 | typedef Handle<mirror::Class> TypeHandle; |
| 189 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 190 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 191 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 192 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 193 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 194 | } |
| 195 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 196 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 197 | return ReferenceTypeInfo(type_handle, is_exact); |
| 198 | } |
| 199 | |
| 200 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 201 | |
| Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 202 | static bool IsValidHandle(TypeHandle handle) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 203 | return handle.GetReference() != nullptr; |
| 204 | } |
| 205 | |
| Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 206 | bool IsValid() const { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 207 | return IsValidHandle(type_handle_); |
| 208 | } |
| 209 | |
| 210 | bool IsExact() const { return is_exact_; } |
| 211 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 212 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 213 | DCHECK(IsValid()); |
| 214 | return GetTypeHandle()->IsObjectClass(); |
| 215 | } |
| 216 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 217 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 218 | DCHECK(IsValid()); |
| 219 | return GetTypeHandle()->IsStringClass(); |
| 220 | } |
| 221 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 222 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 223 | DCHECK(IsValid()); |
| 224 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 225 | } |
| 226 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 227 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 228 | DCHECK(IsValid()); |
| 229 | return GetTypeHandle()->IsInterface(); |
| 230 | } |
| 231 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 232 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 233 | DCHECK(IsValid()); |
| 234 | return GetTypeHandle()->IsArrayClass(); |
| 235 | } |
| 236 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 237 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 238 | DCHECK(IsValid()); |
| 239 | return GetTypeHandle()->IsPrimitiveArray(); |
| 240 | } |
| 241 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 242 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 243 | DCHECK(IsValid()); |
| 244 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 245 | } |
| 246 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 247 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 248 | DCHECK(IsValid()); |
| 249 | if (!IsExact()) return false; |
| 250 | if (!IsArrayClass()) return false; |
| 251 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 252 | } |
| 253 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 254 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 255 | DCHECK(IsValid()); |
| 256 | if (!IsExact()) return false; |
| 257 | if (!IsArrayClass()) return false; |
| 258 | if (!rti.IsArrayClass()) return false; |
| 259 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 260 | rti.GetTypeHandle()->GetComponentType()); |
| 261 | } |
| 262 | |
| 263 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 264 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 265 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 266 | DCHECK(IsValid()); |
| 267 | DCHECK(rti.IsValid()); |
| 268 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 269 | } |
| 270 | |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 271 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 272 | DCHECK(IsValid()); |
| 273 | DCHECK(rti.IsValid()); |
| 274 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 275 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 276 | } |
| 277 | |
| 278 | // Returns true if the type information provide the same amount of details. |
| 279 | // Note that it does not mean that the instructions have the same actual type |
| 280 | // (because the type can be the result of a merge). |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 281 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 282 | if (!IsValid() && !rti.IsValid()) { |
| 283 | // Invalid types are equal. |
| 284 | return true; |
| 285 | } |
| 286 | if (!IsValid() || !rti.IsValid()) { |
| 287 | // One is valid, the other not. |
| 288 | return false; |
| 289 | } |
| 290 | return IsExact() == rti.IsExact() |
| 291 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 292 | } |
| 293 | |
| 294 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 295 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 296 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 297 | : type_handle_(type_handle), is_exact_(is_exact) { } |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 298 | |
| 299 | // The class of the object. |
| 300 | TypeHandle type_handle_; |
| 301 | // Whether or not the type is exact or a superclass of the actual type. |
| 302 | // Whether or not we have any information about this type. |
| 303 | bool is_exact_; |
| 304 | }; |
| 305 | |
| 306 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 307 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 308 | // Control-flow graph of a method. Contains a list of basic blocks. |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 309 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 310 | public: |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 311 | HGraph(ArenaAllocator* allocator, |
| 312 | ArenaStack* arena_stack, |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 313 | const DexFile& dex_file, |
| 314 | uint32_t method_idx, |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 315 | InstructionSet instruction_set, |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 316 | InvokeType invoke_type = kInvalidInvokeType, |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 317 | bool debuggable = false, |
| Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 318 | bool osr = false, |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 319 | int start_instruction_id = 0) |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 320 | : allocator_(allocator), |
| 321 | arena_stack_(arena_stack), |
| 322 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 323 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 324 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 325 | entry_block_(nullptr), |
| 326 | exit_block_(nullptr), |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 327 | maximum_number_of_out_vregs_(0), |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 328 | number_of_vregs_(0), |
| 329 | number_of_in_vregs_(0), |
| Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 330 | temporaries_vreg_slots_(0), |
| Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 331 | has_bounds_checks_(false), |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 332 | has_try_catch_(false), |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 333 | has_simd_(false), |
| Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 334 | has_loops_(false), |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 335 | has_irreducible_loops_(false), |
| Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 336 | debuggable_(debuggable), |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 337 | current_instruction_id_(start_instruction_id), |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 338 | dex_file_(dex_file), |
| 339 | method_idx_(method_idx), |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 340 | invoke_type_(invoke_type), |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 341 | in_ssa_form_(false), |
| Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 342 | number_of_cha_guards_(0), |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 343 | instruction_set_(instruction_set), |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 344 | cached_null_constant_(nullptr), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 345 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 346 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 347 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 348 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 349 | cached_current_method_(nullptr), |
| Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 350 | art_method_(nullptr), |
| Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 351 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 352 | osr_(osr), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 353 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 354 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 355 | } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 356 | |
| David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 357 | // Acquires and stores RTI of inexact Object to be used when creating HNullConstant. |
| Mathieu Chartier | e8a3c57 | 2016-10-11 16:52:17 -0700 | [diff] [blame] | 358 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
| David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 359 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 360 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 361 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 362 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 363 | |
| David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 364 | bool IsInSsaForm() const { return in_ssa_form_; } |
| David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 365 | void SetInSsaForm() { in_ssa_form_ = true; } |
| David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 366 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 367 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 368 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
| David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 369 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 370 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 371 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 372 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 373 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 374 | void AddBlock(HBasicBlock* block); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 375 | |
| Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 376 | void ComputeDominanceInformation(); |
| 377 | void ClearDominanceInformation(); |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 378 | void ClearLoopInformation(); |
| 379 | void FindBackEdges(ArenaBitVector* visited); |
| 380 | GraphAnalysisResult BuildDominatorTree(); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 381 | void SimplifyCFG(); |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 382 | void SimplifyCatchBlocks(); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 383 | |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 384 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 385 | // 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] | 386 | // 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] | 387 | GraphAnalysisResult AnalyzeLoops() const; |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 388 | |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 389 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 390 | // order and loop information. |
| 391 | void ComputeTryBlockInformation(); |
| 392 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 393 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
| Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 394 | // Returns the instruction to replace the invoke expression or null if the |
| 395 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 396 | // and removing the invoke instruction. |
| Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 397 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 398 | |
| Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 399 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 400 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 401 | // should be the new back edge. |
| 402 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 403 | HBasicBlock* reference, |
| 404 | bool replace_if_back_edge); |
| 405 | |
| Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 406 | // Need to add a couple of blocks to test if the loop body is entered and |
| 407 | // put deoptimization instructions, etc. |
| 408 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 409 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 410 | // Adds a new loop directly after the loop with the given header and exit. |
| 411 | // Returns the new preheader. |
| 412 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 413 | HBasicBlock* body, |
| 414 | HBasicBlock* exit); |
| 415 | |
| David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 416 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 417 | // other blocks and has no instructions or phis. |
| 418 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 419 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 420 | // Splits the edge between `block` and `successor` while preserving the |
| 421 | // indices in the predecessor/successor lists. If there are multiple edges |
| 422 | // between the blocks, the lowest indices are used. |
| 423 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 424 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 425 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 426 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 427 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
| Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 428 | |
| 429 | // Transform a loop into a format with a single preheader. |
| 430 | // |
| 431 | // Each phi in the header should be split: original one in the header should only hold |
| 432 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 433 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 434 | // |
| 435 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 436 | // that no longer have this property. |
| 437 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 438 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 439 | void SimplifyLoop(HBasicBlock* header); |
| 440 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 441 | int32_t GetNextInstructionId() { |
| Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 442 | CHECK_NE(current_instruction_id_, INT32_MAX); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 443 | return current_instruction_id_++; |
| 444 | } |
| 445 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 446 | int32_t GetCurrentInstructionId() const { |
| 447 | return current_instruction_id_; |
| 448 | } |
| 449 | |
| 450 | void SetCurrentInstructionId(int32_t id) { |
| Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 451 | CHECK_GE(id, current_instruction_id_); |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 452 | current_instruction_id_ = id; |
| 453 | } |
| 454 | |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 455 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 456 | return maximum_number_of_out_vregs_; |
| 457 | } |
| 458 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 459 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 460 | maximum_number_of_out_vregs_ = new_value; |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 461 | } |
| 462 | |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 463 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 464 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 465 | } |
| 466 | |
| Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 467 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 468 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 469 | } |
| 470 | |
| Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 471 | size_t GetTemporariesVRegSlots() const { |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 472 | DCHECK(!in_ssa_form_); |
| Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 473 | return temporaries_vreg_slots_; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 474 | } |
| 475 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 476 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 477 | number_of_vregs_ = number_of_vregs; |
| 478 | } |
| 479 | |
| 480 | uint16_t GetNumberOfVRegs() const { |
| 481 | return number_of_vregs_; |
| 482 | } |
| 483 | |
| 484 | void SetNumberOfInVRegs(uint16_t value) { |
| 485 | number_of_in_vregs_ = value; |
| 486 | } |
| 487 | |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 488 | uint16_t GetNumberOfInVRegs() const { |
| 489 | return number_of_in_vregs_; |
| 490 | } |
| 491 | |
| Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 492 | uint16_t GetNumberOfLocalVRegs() const { |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 493 | DCHECK(!in_ssa_form_); |
| Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 494 | return number_of_vregs_ - number_of_in_vregs_; |
| 495 | } |
| 496 | |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 497 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 498 | return reverse_post_order_; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 499 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 500 | |
| Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 501 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 502 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 503 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 504 | } |
| 505 | |
| 506 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 507 | return ReverseRange(GetReversePostOrder()); |
| 508 | } |
| 509 | |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 510 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
| Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 511 | return linear_order_; |
| 512 | } |
| 513 | |
| Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 514 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 515 | return ReverseRange(GetLinearOrder()); |
| 516 | } |
| 517 | |
| Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 518 | bool HasBoundsChecks() const { |
| 519 | return has_bounds_checks_; |
| Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 520 | } |
| 521 | |
| Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 522 | void SetHasBoundsChecks(bool value) { |
| 523 | has_bounds_checks_ = value; |
| Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 526 | bool IsDebuggable() const { return debuggable_; } |
| 527 | |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 528 | // 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] | 529 | // already, it is created and inserted into the graph. This method is only for |
| 530 | // integral types. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 531 | HConstant* GetConstant(DataType::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
| Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 532 | |
| 533 | // TODO: This is problematic for the consistency of reference type propagation |
| 534 | // because it can be created anytime after the pass and thus it will be left |
| 535 | // with an invalid type. |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 536 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
| Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 537 | |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 538 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 539 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 540 | } |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 541 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 542 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 543 | } |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 544 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 545 | 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] | 546 | } |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 547 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 548 | 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] | 549 | } |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 550 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 551 | HCurrentMethod* GetCurrentMethod(); |
| 552 | |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 553 | const DexFile& GetDexFile() const { |
| 554 | return dex_file_; |
| 555 | } |
| 556 | |
| 557 | uint32_t GetMethodIdx() const { |
| 558 | return method_idx_; |
| 559 | } |
| 560 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 561 | // Get the method name (without the signature), e.g. "<init>" |
| 562 | const char* GetMethodName() const; |
| 563 | |
| 564 | // Get the pretty method name (class + name + optionally signature). |
| 565 | std::string PrettyMethod(bool with_signature = true) const; |
| 566 | |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 567 | InvokeType GetInvokeType() const { |
| 568 | return invoke_type_; |
| 569 | } |
| 570 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 571 | InstructionSet GetInstructionSet() const { |
| 572 | return instruction_set_; |
| 573 | } |
| 574 | |
| Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 575 | bool IsCompilingOsr() const { return osr_; } |
| 576 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 577 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 578 | return cha_single_implementation_list_; |
| 579 | } |
| 580 | |
| 581 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 582 | cha_single_implementation_list_.insert(method); |
| 583 | } |
| 584 | |
| 585 | bool HasShouldDeoptimizeFlag() const { |
| Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 586 | return number_of_cha_guards_ != 0; |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 589 | bool HasTryCatch() const { return has_try_catch_; } |
| 590 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
| David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 591 | |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 592 | bool HasSIMD() const { return has_simd_; } |
| 593 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 594 | |
| Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 595 | bool HasLoops() const { return has_loops_; } |
| 596 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 597 | |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 598 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 599 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 600 | |
| Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 601 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 602 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 603 | |
| Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 604 | // Returns an instruction with the opposite Boolean value from 'cond'. |
| Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 605 | // The instruction has been inserted into the graph, either as a constant, or |
| 606 | // before cursor. |
| 607 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 608 | |
| Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 609 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 610 | |
| Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 611 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 612 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 613 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 614 | |
| David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 615 | private: |
| Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 616 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
| Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 617 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 618 | |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 619 | template <class InstructionType, typename ValueType> |
| 620 | InstructionType* CreateConstant(ValueType value, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 621 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 622 | uint32_t dex_pc = kNoDexPc) { |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 623 | // Try to find an existing constant of the given value. |
| 624 | InstructionType* constant = nullptr; |
| 625 | auto cached_constant = cache->find(value); |
| 626 | if (cached_constant != cache->end()) { |
| 627 | constant = cached_constant->second; |
| 628 | } |
| 629 | |
| 630 | // If not found or previously deleted, create and cache a new instruction. |
| Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 631 | // Don't bother reviving a previously deleted instruction, for simplicity. |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 632 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 633 | constant = new (allocator_) InstructionType(value, dex_pc); |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 634 | cache->Overwrite(value, constant); |
| 635 | InsertConstant(constant); |
| 636 | } |
| 637 | return constant; |
| 638 | } |
| 639 | |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 640 | void InsertConstant(HConstant* instruction); |
| 641 | |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 642 | // Cache a float constant into the graph. This method should only be |
| 643 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 644 | void CacheFloatConstant(HFloatConstant* constant); |
| 645 | |
| 646 | // See CacheFloatConstant comment. |
| 647 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 648 | |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 649 | ArenaAllocator* const allocator_; |
| 650 | ArenaStack* const arena_stack_; |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 651 | |
| 652 | // List of blocks in insertion order. |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 653 | ArenaVector<HBasicBlock*> blocks_; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 654 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 655 | // List of blocks to perform a reverse post order tree traversal. |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 656 | ArenaVector<HBasicBlock*> reverse_post_order_; |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 657 | |
| Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 658 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 659 | // post order, this order is not incrementally kept up-to-date. |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 660 | ArenaVector<HBasicBlock*> linear_order_; |
| Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 661 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 662 | HBasicBlock* entry_block_; |
| 663 | HBasicBlock* exit_block_; |
| 664 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 665 | // 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] | 666 | uint16_t maximum_number_of_out_vregs_; |
| 667 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 668 | // The number of virtual registers in this method. Contains the parameters. |
| 669 | uint16_t number_of_vregs_; |
| 670 | |
| 671 | // The number of virtual registers used by parameters of this method. |
| 672 | uint16_t number_of_in_vregs_; |
| 673 | |
| Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 674 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 675 | size_t temporaries_vreg_slots_; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 676 | |
| Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 677 | // Flag whether there are bounds checks in the graph. We can skip |
| 678 | // BCE if it's false. It's only best effort to keep it up to date in |
| 679 | // the presence of code elimination so there might be false positives. |
| Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 680 | bool has_bounds_checks_; |
| Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 681 | |
| Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 682 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 683 | // try/catch-related passes if it's false. It's only best effort to keep |
| 684 | // it up to date in the presence of code elimination so there might be |
| 685 | // false positives. |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 686 | bool has_try_catch_; |
| 687 | |
| Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 688 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 689 | // code generators may have to be more careful spilling the wider |
| 690 | // contents of SIMD registers. |
| 691 | bool has_simd_; |
| 692 | |
| Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 693 | // Flag whether there are any loops in the graph. We can skip loop |
| 694 | // optimization if it's false. It's only best effort to keep it up |
| 695 | // to date in the presence of code elimination so there might be false |
| 696 | // positives. |
| 697 | bool has_loops_; |
| 698 | |
| 699 | // Flag whether there are any irreducible loops in the graph. It's only |
| 700 | // best effort to keep it up to date in the presence of code elimination |
| 701 | // so there might be false positives. |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 702 | bool has_irreducible_loops_; |
| 703 | |
| Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 704 | // Indicates whether the graph should be compiled in a way that |
| 705 | // ensures full debuggability. If false, we can apply more |
| 706 | // aggressive optimizations that may limit the level of debugging. |
| 707 | const bool debuggable_; |
| 708 | |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 709 | // 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] | 710 | int32_t current_instruction_id_; |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 711 | |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 712 | // The dex file from which the method is from. |
| 713 | const DexFile& dex_file_; |
| 714 | |
| 715 | // The method index in the dex file. |
| 716 | const uint32_t method_idx_; |
| 717 | |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 718 | // If inlined, this encodes how the callee is being invoked. |
| 719 | const InvokeType invoke_type_; |
| 720 | |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 721 | // Whether the graph has been transformed to SSA form. Only used |
| 722 | // in debug mode to ensure we are not using properties only valid |
| 723 | // for non-SSA form (like the number of temporaries). |
| 724 | bool in_ssa_form_; |
| 725 | |
| Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 726 | // Number of CHA guards in the graph. Used to short-circuit the |
| 727 | // CHA guard optimization pass when there is no CHA guard left. |
| 728 | uint32_t number_of_cha_guards_; |
| 729 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 730 | const InstructionSet instruction_set_; |
| 731 | |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 732 | // Cached constants. |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 733 | HNullConstant* cached_null_constant_; |
| 734 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 735 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 736 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 737 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 738 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 739 | HCurrentMethod* cached_current_method_; |
| 740 | |
| Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 741 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 742 | // for example for methods whose declaring class could not be resolved |
| 743 | // (such as when the superclass could not be found). |
| 744 | ArtMethod* art_method_; |
| 745 | |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 746 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 747 | // collection pointer to passes which may create NullConstant. |
| 748 | ReferenceTypeInfo inexact_object_rti_; |
| 749 | |
| Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 750 | // Whether we are compiling this graph for on stack replacement: this will |
| 751 | // make all loops seen as irreducible and emit special stack maps to mark |
| 752 | // compiled code entries which the interpreter can directly jump to. |
| 753 | const bool osr_; |
| 754 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 755 | // List of methods that are assumed to have single implementation. |
| 756 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 757 | |
| Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 758 | friend class SsaBuilder; // For caching constants. |
| Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 759 | friend class SsaLivenessAnalysis; // For the linear order. |
| Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 760 | friend class HInliner; // For the reverse post order. |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 761 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 762 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 763 | }; |
| 764 | |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 765 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 766 | public: |
| 767 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 768 | : header_(header), |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 769 | suspend_check_(nullptr), |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 770 | irreducible_(false), |
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 771 | contains_irreducible_loop_(false), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 772 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
| Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 773 | // Make bit vector growable, as the number of blocks may change. |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 774 | blocks_(graph->GetAllocator(), |
| 775 | graph->GetBlocks().size(), |
| 776 | true, |
| 777 | kArenaAllocLoopInfoBackEdges) { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 778 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 779 | } |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 780 | |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 781 | bool IsIrreducible() const { return irreducible_; } |
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 782 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 783 | |
| 784 | void Dump(std::ostream& os); |
| 785 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 786 | HBasicBlock* GetHeader() const { |
| 787 | return header_; |
| 788 | } |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 789 | |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 790 | void SetHeader(HBasicBlock* block) { |
| 791 | header_ = block; |
| 792 | } |
| 793 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 794 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 795 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 796 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 797 | |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 798 | void AddBackEdge(HBasicBlock* back_edge) { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 799 | back_edges_.push_back(back_edge); |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 802 | void RemoveBackEdge(HBasicBlock* back_edge) { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 803 | RemoveElement(back_edges_, back_edge); |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 804 | } |
| 805 | |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 806 | bool IsBackEdge(const HBasicBlock& block) const { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 807 | return ContainsElement(back_edges_, &block); |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 808 | } |
| 809 | |
| Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 810 | size_t NumberOfBackEdges() const { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 811 | return back_edges_.size(); |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 814 | HBasicBlock* GetPreHeader() const; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 815 | |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 816 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 817 | return back_edges_; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 818 | } |
| 819 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 820 | // Returns the lifetime position of the back edge that has the |
| 821 | // greatest lifetime position. |
| 822 | size_t GetLifetimeEnd() const; |
| 823 | |
| 824 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 825 | ReplaceElement(back_edges_, existing, new_back_edge); |
| Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 826 | } |
| 827 | |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 828 | // Finds blocks that are part of this loop. |
| 829 | void Populate(); |
| David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 830 | |
| Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 831 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 832 | // population of the inner loop is updated. |
| 833 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 834 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 835 | // Returns whether this loop information contains `block`. |
| 836 | // Note that this loop information *must* be populated before entering this function. |
| 837 | bool Contains(const HBasicBlock& block) const; |
| 838 | |
| 839 | // Returns whether this loop information is an inner loop of `other`. |
| 840 | // Note that `other` *must* be populated before entering this function. |
| 841 | bool IsIn(const HLoopInformation& other) const; |
| 842 | |
| Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 843 | // Returns true if instruction is not defined within this loop. |
| 844 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
| Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 845 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 846 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 847 | |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 848 | void Add(HBasicBlock* block); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 849 | void Remove(HBasicBlock* block); |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 850 | |
| Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 851 | void ClearAllBlocks() { |
| 852 | blocks_.ClearAllBits(); |
| 853 | } |
| 854 | |
| David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 855 | bool HasBackEdgeNotDominatedByHeader() const; |
| 856 | |
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 857 | bool IsPopulated() const { |
| 858 | return blocks_.GetHighestBitSet() != -1; |
| 859 | } |
| 860 | |
| Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 861 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 862 | |
| David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 863 | bool HasExitEdge() const; |
| 864 | |
| Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 865 | // Resets back edge and blocks-in-loop data. |
| 866 | void ResetBasicBlockData() { |
| 867 | back_edges_.clear(); |
| 868 | ClearAllBlocks(); |
| 869 | } |
| 870 | |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 871 | private: |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 872 | // Internal recursive implementation of `Populate`. |
| 873 | void PopulateRecursive(HBasicBlock* block); |
| David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 874 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 875 | |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 876 | HBasicBlock* header_; |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 877 | HSuspendCheck* suspend_check_; |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 878 | bool irreducible_; |
| Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 879 | bool contains_irreducible_loop_; |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 880 | ArenaVector<HBasicBlock*> back_edges_; |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 881 | ArenaBitVector blocks_; |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 882 | |
| 883 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 884 | }; |
| 885 | |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 886 | // Stores try/catch information for basic blocks. |
| 887 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 888 | // be try blocks. |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 889 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 890 | public: |
| 891 | // Try block information constructor. |
| 892 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 893 | : try_entry_(&try_entry), |
| 894 | catch_dex_file_(nullptr), |
| 895 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 896 | DCHECK(try_entry_ != nullptr); |
| 897 | } |
| 898 | |
| 899 | // Catch block information constructor. |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 900 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 901 | : try_entry_(nullptr), |
| 902 | catch_dex_file_(&dex_file), |
| 903 | catch_type_index_(catch_type_index) {} |
| 904 | |
| 905 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 906 | |
| 907 | const HTryBoundary& GetTryEntry() const { |
| 908 | DCHECK(IsTryBlock()); |
| 909 | return *try_entry_; |
| 910 | } |
| 911 | |
| 912 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 913 | |
| 914 | bool IsCatchAllTypeIndex() const { |
| 915 | DCHECK(IsCatchBlock()); |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 916 | return !catch_type_index_.IsValid(); |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 917 | } |
| 918 | |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 919 | dex::TypeIndex GetCatchTypeIndex() const { |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 920 | DCHECK(IsCatchBlock()); |
| 921 | return catch_type_index_; |
| 922 | } |
| 923 | |
| 924 | const DexFile& GetCatchDexFile() const { |
| 925 | DCHECK(IsCatchBlock()); |
| 926 | return *catch_dex_file_; |
| 927 | } |
| 928 | |
| 929 | private: |
| 930 | // One of possibly several TryBoundary instructions entering the block's try. |
| 931 | // Only set for try blocks. |
| 932 | const HTryBoundary* try_entry_; |
| 933 | |
| 934 | // Exception type information. Only set for catch blocks. |
| 935 | const DexFile* catch_dex_file_; |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 936 | const dex::TypeIndex catch_type_index_; |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 937 | }; |
| 938 | |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 939 | static constexpr size_t kNoLifetime = -1; |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 940 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 941 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 942 | // A block in a method. Contains the list of instructions represented |
| 943 | // as a double linked list. Each block knows its predecessors and |
| 944 | // successors. |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 945 | |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 946 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 947 | public: |
| Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 948 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 949 | : graph_(graph), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 950 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 951 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 952 | loop_information_(nullptr), |
| 953 | dominator_(nullptr), |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 954 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 955 | block_id_(kInvalidBlockId), |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 956 | dex_pc_(dex_pc), |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 957 | lifetime_start_(kNoLifetime), |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 958 | lifetime_end_(kNoLifetime), |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 959 | try_catch_information_(nullptr) { |
| 960 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 961 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 962 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 963 | } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 964 | |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 965 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 966 | return predecessors_; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 969 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 970 | return successors_; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 973 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 974 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 975 | |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 976 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 977 | return ContainsElement(successors_, block, start_from); |
| 978 | } |
| 979 | |
| 980 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 981 | return dominated_blocks_; |
| 982 | } |
| 983 | |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 984 | bool IsEntryBlock() const { |
| 985 | return graph_->GetEntryBlock() == this; |
| 986 | } |
| 987 | |
| 988 | bool IsExitBlock() const { |
| 989 | return graph_->GetExitBlock() == this; |
| 990 | } |
| 991 | |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 992 | bool IsSingleGoto() const; |
| Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 993 | bool IsSingleReturn() const; |
| Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 994 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 995 | bool IsSingleTryBoundary() const; |
| 996 | |
| 997 | // Returns true if this block emits nothing but a jump. |
| 998 | bool IsSingleJump() const { |
| 999 | HLoopInformation* loop_info = GetLoopInformation(); |
| 1000 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 1001 | // Back edges generate a suspend check. |
| 1002 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1003 | } |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1004 | |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1005 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1006 | if (loop_information_ == nullptr) { |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1007 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1008 | } |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1009 | DCHECK_EQ(loop_information_->GetHeader(), this); |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1010 | loop_information_->AddBackEdge(back_edge); |
| 1011 | } |
| 1012 | |
| Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1013 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1014 | // created loop info with it. |
| 1015 | // |
| 1016 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1017 | // info for all blocks during back edges recalculation. |
| 1018 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1019 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1020 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1021 | } |
| 1022 | loop_information_->AddBackEdge(back_edge); |
| 1023 | } |
| 1024 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1025 | HGraph* GetGraph() const { return graph_; } |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1026 | void SetGraph(HGraph* graph) { graph_ = graph; } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1027 | |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1028 | uint32_t GetBlockId() const { return block_id_; } |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1029 | void SetBlockId(int id) { block_id_ = id; } |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1030 | uint32_t GetDexPc() const { return dex_pc_; } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1031 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1032 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1033 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1034 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1035 | |
| 1036 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1037 | RemoveElement(dominated_blocks_, block); |
| Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1038 | } |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1039 | |
| 1040 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1041 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1042 | } |
| 1043 | |
| Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1044 | void ClearDominanceInformation(); |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1045 | |
| 1046 | int NumberOfBackEdges() const { |
| Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1047 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1050 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1051 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
| Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1052 | const HInstructionList& GetInstructions() const { return instructions_; } |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1053 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
| David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1054 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1055 | const HInstructionList& GetPhis() const { return phis_; } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1056 | |
| Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1057 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1058 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1059 | void AddSuccessor(HBasicBlock* block) { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1060 | successors_.push_back(block); |
| 1061 | block->predecessors_.push_back(this); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1064 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1065 | size_t successor_index = GetSuccessorIndexOf(existing); |
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1066 | existing->RemovePredecessor(this); |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1067 | new_block->predecessors_.push_back(this); |
| 1068 | successors_[successor_index] = new_block; |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1071 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1072 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1073 | existing->RemoveSuccessor(this); |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1074 | new_block->successors_.push_back(this); |
| 1075 | predecessors_[predecessor_index] = new_block; |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1078 | // Insert `this` between `predecessor` and `successor. This method |
| 1079 | // preserves the indicies, and will update the first edge found between |
| 1080 | // `predecessor` and `successor`. |
| 1081 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1082 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
| Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1083 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1084 | successor->predecessors_[predecessor_index] = this; |
| 1085 | predecessor->successors_[successor_index] = this; |
| 1086 | successors_.push_back(successor); |
| 1087 | predecessors_.push_back(predecessor); |
| Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1088 | } |
| 1089 | |
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1090 | void RemovePredecessor(HBasicBlock* block) { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1091 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1094 | void RemoveSuccessor(HBasicBlock* block) { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1095 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1098 | void ClearAllPredecessors() { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1099 | predecessors_.clear(); |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | void AddPredecessor(HBasicBlock* block) { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1103 | predecessors_.push_back(block); |
| 1104 | block->successors_.push_back(this); |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1105 | } |
| 1106 | |
| Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1107 | void SwapPredecessors() { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1108 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1109 | std::swap(predecessors_[0], predecessors_[1]); |
| Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1110 | } |
| 1111 | |
| David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1112 | void SwapSuccessors() { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1113 | DCHECK_EQ(successors_.size(), 2u); |
| 1114 | std::swap(successors_[0], successors_[1]); |
| David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1115 | } |
| 1116 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1117 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1118 | return IndexOfElement(predecessors_, predecessor); |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1119 | } |
| 1120 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1121 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1122 | return IndexOfElement(successors_, successor); |
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1123 | } |
| 1124 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1125 | HBasicBlock* GetSinglePredecessor() const { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1126 | DCHECK_EQ(GetPredecessors().size(), 1u); |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1127 | return GetPredecessors()[0]; |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | HBasicBlock* GetSingleSuccessor() const { |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1131 | DCHECK_EQ(GetSuccessors().size(), 1u); |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1132 | return GetSuccessors()[0]; |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1136 | // predecessors is at index `idx`. |
| 1137 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1138 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1139 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1140 | } |
| 1141 | |
| David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1142 | // Create a new block between this block and its predecessors. The new block |
| 1143 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1144 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1145 | // loop and try/catch information are not updated. |
| 1146 | HBasicBlock* CreateImmediateDominator(); |
| 1147 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1148 | // Split the block into two blocks just before `cursor`. Returns the newly |
| David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1149 | // created, latter block. Note that this method will add the block to the |
| 1150 | // graph, create a Goto at the end of the former block and will create an edge |
| 1151 | // 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] | 1152 | // loop and try/catch information. |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1153 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1154 | |
| Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1155 | // Split the block into two blocks just before `cursor`. Returns the newly |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1156 | // created block. Note that this method just updates raw block information, |
| 1157 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1158 | // update the graph, reverse post order, loop information, nor make sure the |
| 1159 | // blocks are consistent (for example ending with a control flow instruction). |
| Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1160 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1161 | |
| 1162 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1163 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1164 | |
| 1165 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1166 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1167 | // that this method does not update the graph, reverse post order, loop |
| 1168 | // information, nor make sure the blocks are consistent (for example ending |
| 1169 | // with a control flow instruction). |
| David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1170 | void MergeWithInlined(HBasicBlock* other); |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1171 | |
| 1172 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1173 | // of `this` are moved to `other`. |
| 1174 | // Note that this method does not update the graph, reverse post order, loop |
| 1175 | // information, nor make sure the blocks are consistent (for example ending |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1176 | // with a control flow instruction). |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1177 | void ReplaceWith(HBasicBlock* other); |
| 1178 | |
| Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1179 | // Merges the instructions of `other` at the end of `this`. |
| 1180 | void MergeInstructionsWith(HBasicBlock* other); |
| 1181 | |
| David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1182 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1183 | // order, links to predecessors, successors, dominators and deletes the block |
| 1184 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1185 | // predecessor of `other` and vice versa. |
| 1186 | void MergeWith(HBasicBlock* other); |
| 1187 | |
| 1188 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1189 | // removes it from all loops it is included in and eventually from the graph. |
| 1190 | // The block must not dominate any other block. Predecessors and successors |
| 1191 | // are safely updated. |
| 1192 | void DisconnectAndDelete(); |
| David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1193 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1194 | void AddInstruction(HInstruction* instruction); |
| Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1195 | // Insert `instruction` before/after an existing instruction `cursor`. |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1196 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1197 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1198 | // Replace phi `initial` with `replacement` within this block. |
| 1199 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
| Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1200 | // Replace instruction `initial` with `replacement` within this block. |
| 1201 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1202 | HInstruction* replacement); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1203 | void AddPhi(HPhi* phi); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1204 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1205 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1206 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1207 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1208 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1209 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
| David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1210 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1211 | |
| 1212 | bool IsLoopHeader() const { |
| David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1213 | return IsInLoop() && (loop_information_->GetHeader() == this); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
| Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1216 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1217 | DCHECK(IsLoopHeader()); |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1218 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
| Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1219 | } |
| 1220 | |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1221 | bool IsFirstPredecessorBackEdge() const { |
| 1222 | DCHECK(IsLoopHeader()); |
| 1223 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1224 | } |
| 1225 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1226 | HLoopInformation* GetLoopInformation() const { |
| 1227 | return loop_information_; |
| 1228 | } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1229 | |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1230 | // Set the loop_information_ on this block. Overrides the current |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1231 | // 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] | 1232 | // Note that this method is called while creating the loop information. |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1233 | void SetInLoop(HLoopInformation* info) { |
| 1234 | if (IsLoopHeader()) { |
| 1235 | // Nothing to do. This just means `info` is an outer loop. |
| David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1236 | } else if (!IsInLoop()) { |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1237 | loop_information_ = info; |
| 1238 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1239 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1240 | // Note that a non loop header having a loop information means this loop information |
| 1241 | // has already been populated |
| 1242 | loop_information_ = info; |
| 1243 | } else { |
| 1244 | // Block is part of an inner loop. Do not update the loop information. |
| 1245 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1246 | // at this point, because this method is being called while populating `info`. |
| 1247 | } |
| 1248 | } |
| 1249 | |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1250 | // Raw update of the loop information. |
| 1251 | void SetLoopInformation(HLoopInformation* info) { |
| 1252 | loop_information_ = info; |
| 1253 | } |
| 1254 | |
| Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1255 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1256 | |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1257 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1258 | |
| 1259 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1260 | try_catch_information_ = try_catch_information; |
| 1261 | } |
| 1262 | |
| 1263 | bool IsTryBlock() const { |
| 1264 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1265 | } |
| 1266 | |
| 1267 | bool IsCatchBlock() const { |
| 1268 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1269 | } |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1270 | |
| 1271 | // Returns the try entry that this block's successors should have. They will |
| 1272 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1273 | // the appropriate try entry will be returned. |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1274 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1275 | |
| Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 1276 | bool HasThrowingInstructions() const; |
| 1277 | |
| David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1278 | // Returns whether this block dominates the blocked passed as parameter. |
| Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1279 | bool Dominates(HBasicBlock* block) const; |
| 1280 | |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1281 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1282 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1283 | |
| 1284 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1285 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1286 | |
| David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1287 | bool EndsWithControlFlowInstruction() const; |
| Aart Bik | 4dc09e7 | 2018-05-11 14:40:31 -0700 | [diff] [blame] | 1288 | bool EndsWithReturn() const; |
| David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1289 | bool EndsWithIf() const; |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1290 | bool EndsWithTryBoundary() const; |
| David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1291 | bool HasSinglePhi() const; |
| 1292 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1293 | private: |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1294 | HGraph* graph_; |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1295 | ArenaVector<HBasicBlock*> predecessors_; |
| 1296 | ArenaVector<HBasicBlock*> successors_; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1297 | HInstructionList instructions_; |
| 1298 | HInstructionList phis_; |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1299 | HLoopInformation* loop_information_; |
| 1300 | HBasicBlock* dominator_; |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1301 | ArenaVector<HBasicBlock*> dominated_blocks_; |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1302 | uint32_t block_id_; |
| Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1303 | // The dex program counter of the first instruction of this block. |
| 1304 | const uint32_t dex_pc_; |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1305 | size_t lifetime_start_; |
| 1306 | size_t lifetime_end_; |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1307 | TryCatchInformation* try_catch_information_; |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1308 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1309 | friend class HGraph; |
| 1310 | friend class HInstruction; |
| 1311 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1312 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1313 | }; |
| 1314 | |
| David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1315 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1316 | // from the innermost to the outermost. |
| 1317 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1318 | public: |
| 1319 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1320 | : current_(block.GetLoopInformation()) {} |
| 1321 | |
| 1322 | bool Done() const { return current_ == nullptr; } |
| 1323 | |
| 1324 | void Advance() { |
| 1325 | DCHECK(!Done()); |
| David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1326 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
| David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | HLoopInformation* Current() const { |
| 1330 | DCHECK(!Done()); |
| 1331 | return current_; |
| 1332 | } |
| 1333 | |
| 1334 | private: |
| 1335 | HLoopInformation* current_; |
| 1336 | |
| 1337 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1338 | }; |
| 1339 | |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1340 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1341 | M(Above, Condition) \ |
| 1342 | M(AboveOrEqual, Condition) \ |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 1343 | M(Abs, UnaryOperation) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1344 | M(Add, BinaryOperation) \ |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1345 | M(And, BinaryOperation) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1346 | M(ArrayGet, Instruction) \ |
| 1347 | M(ArrayLength, Instruction) \ |
| 1348 | M(ArraySet, Instruction) \ |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1349 | M(Below, Condition) \ |
| 1350 | M(BelowOrEqual, Condition) \ |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1351 | M(BooleanNot, UnaryOperation) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1352 | M(BoundsCheck, Instruction) \ |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1353 | M(BoundType, Instruction) \ |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1354 | M(CheckCast, Instruction) \ |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1355 | M(ClassTableGet, Instruction) \ |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1356 | M(ClearException, Instruction) \ |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1357 | M(ClinitCheck, Instruction) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1358 | M(Compare, BinaryOperation) \ |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1359 | M(ConstructorFence, Instruction) \ |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1360 | M(CurrentMethod, Instruction) \ |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1361 | M(ShouldDeoptimizeFlag, Instruction) \ |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1362 | M(Deoptimize, Instruction) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1363 | M(Div, BinaryOperation) \ |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1364 | M(DivZeroCheck, Instruction) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1365 | M(DoubleConstant, Constant) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1366 | M(Equal, Condition) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1367 | M(Exit, Instruction) \ |
| 1368 | M(FloatConstant, Constant) \ |
| 1369 | M(Goto, Instruction) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1370 | M(GreaterThan, Condition) \ |
| 1371 | M(GreaterThanOrEqual, Condition) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1372 | M(If, Instruction) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1373 | M(InstanceFieldGet, Instruction) \ |
| 1374 | M(InstanceFieldSet, Instruction) \ |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1375 | M(InstanceOf, Instruction) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1376 | M(IntConstant, Constant) \ |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1377 | M(IntermediateAddress, Instruction) \ |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1378 | M(InvokeUnresolved, Invoke) \ |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1379 | M(InvokeInterface, Invoke) \ |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1380 | M(InvokeStaticOrDirect, Invoke) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1381 | M(InvokeVirtual, Invoke) \ |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1382 | M(InvokePolymorphic, Invoke) \ |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1383 | M(InvokeCustom, Invoke) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1384 | M(LessThan, Condition) \ |
| 1385 | M(LessThanOrEqual, Condition) \ |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1386 | M(LoadClass, Instruction) \ |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1387 | M(LoadException, Instruction) \ |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 1388 | M(LoadMethodHandle, Instruction) \ |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 1389 | M(LoadMethodType, Instruction) \ |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1390 | M(LoadString, Instruction) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1391 | M(LongConstant, Constant) \ |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1392 | M(Max, Instruction) \ |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1393 | M(MemoryBarrier, Instruction) \ |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1394 | M(Min, BinaryOperation) \ |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1395 | M(MonitorOperation, Instruction) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1396 | M(Mul, BinaryOperation) \ |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1397 | M(NativeDebugInfo, Instruction) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1398 | M(Neg, UnaryOperation) \ |
| 1399 | M(NewArray, Instruction) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1400 | M(NewInstance, Instruction) \ |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1401 | M(Not, UnaryOperation) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1402 | M(NotEqual, Condition) \ |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1403 | M(NullConstant, Instruction) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1404 | M(NullCheck, Instruction) \ |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1405 | M(Or, BinaryOperation) \ |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1406 | M(PackedSwitch, Instruction) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1407 | M(ParallelMove, Instruction) \ |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1408 | M(ParameterValue, Instruction) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1409 | M(Phi, Instruction) \ |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1410 | M(Rem, BinaryOperation) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1411 | M(Return, Instruction) \ |
| 1412 | M(ReturnVoid, Instruction) \ |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1413 | M(Ror, BinaryOperation) \ |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1414 | M(Shl, BinaryOperation) \ |
| 1415 | M(Shr, BinaryOperation) \ |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1416 | M(StaticFieldGet, Instruction) \ |
| 1417 | M(StaticFieldSet, Instruction) \ |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1418 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1419 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1420 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1421 | M(UnresolvedStaticFieldSet, Instruction) \ |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1422 | M(Select, Instruction) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1423 | M(Sub, BinaryOperation) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1424 | M(SuspendCheck, Instruction) \ |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1425 | M(Throw, Instruction) \ |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1426 | M(TryBoundary, Instruction) \ |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1427 | M(TypeConversion, Instruction) \ |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1428 | M(UShr, BinaryOperation) \ |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1429 | M(Xor, BinaryOperation) \ |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1430 | M(VecReplicateScalar, VecUnaryOperation) \ |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1431 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1432 | M(VecReduce, VecUnaryOperation) \ |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1433 | M(VecCnv, VecUnaryOperation) \ |
| 1434 | M(VecNeg, VecUnaryOperation) \ |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1435 | M(VecAbs, VecUnaryOperation) \ |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1436 | M(VecNot, VecUnaryOperation) \ |
| 1437 | M(VecAdd, VecBinaryOperation) \ |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1438 | M(VecHalvingAdd, VecBinaryOperation) \ |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1439 | M(VecSub, VecBinaryOperation) \ |
| 1440 | M(VecMul, VecBinaryOperation) \ |
| 1441 | M(VecDiv, VecBinaryOperation) \ |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1442 | M(VecMin, VecBinaryOperation) \ |
| 1443 | M(VecMax, VecBinaryOperation) \ |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1444 | M(VecAnd, VecBinaryOperation) \ |
| 1445 | M(VecAndNot, VecBinaryOperation) \ |
| 1446 | M(VecOr, VecBinaryOperation) \ |
| 1447 | M(VecXor, VecBinaryOperation) \ |
| Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1448 | M(VecSaturationAdd, VecBinaryOperation) \ |
| 1449 | M(VecSaturationSub, VecBinaryOperation) \ |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1450 | M(VecShl, VecBinaryOperation) \ |
| 1451 | M(VecShr, VecBinaryOperation) \ |
| 1452 | M(VecUShr, VecBinaryOperation) \ |
| Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1453 | M(VecSetScalars, VecOperation) \ |
| Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1454 | M(VecMultiplyAccumulate, VecOperation) \ |
| Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1455 | M(VecSADAccumulate, VecOperation) \ |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1456 | M(VecLoad, VecMemoryOperation) \ |
| 1457 | M(VecStore, VecMemoryOperation) \ |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1458 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1459 | /* |
| 1460 | * Instructions, shared across several (not all) architectures. |
| 1461 | */ |
| 1462 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1463 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1464 | #else |
| 1465 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
| Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1466 | M(BitwiseNegatedRight, Instruction) \ |
| Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1467 | M(DataProcWithShifterOp, Instruction) \ |
| Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1468 | M(MultiplyAccumulate, Instruction) \ |
| Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1469 | M(IntermediateAddressIndex, Instruction) |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1470 | #endif |
| 1471 | |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1472 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1473 | |
| 1474 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1475 | |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1476 | #ifndef ART_ENABLE_CODEGEN_mips |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1477 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1478 | #else |
| 1479 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1480 | M(MipsComputeBaseMethodAddress, Instruction) \ |
| Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 1481 | M(MipsPackedSwitch, Instruction) \ |
| 1482 | M(IntermediateArrayAddressIndex, Instruction) |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1483 | #endif |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1484 | |
| Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1485 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1486 | |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1487 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1488 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1489 | #else |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1490 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1491 | M(X86ComputeBaseMethodAddress, Instruction) \ |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1492 | M(X86LoadFromConstantTable, Instruction) \ |
| Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1493 | M(X86FPNeg, Instruction) \ |
| Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1494 | M(X86PackedSwitch, Instruction) |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1495 | #endif |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1496 | |
| 1497 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1498 | |
| 1499 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1500 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1501 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1502 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1503 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
| Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1504 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1505 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
| Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1506 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1507 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1508 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1509 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1510 | M(Condition, BinaryOperation) \ |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1511 | M(Constant, Instruction) \ |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1512 | M(UnaryOperation, Instruction) \ |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1513 | M(BinaryOperation, Instruction) \ |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1514 | M(Invoke, Instruction) \ |
| 1515 | M(VecOperation, Instruction) \ |
| 1516 | M(VecUnaryOperation, VecOperation) \ |
| 1517 | M(VecBinaryOperation, VecOperation) \ |
| 1518 | M(VecMemoryOperation, VecOperation) |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1519 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1520 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1521 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1522 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1523 | |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1524 | #define FORWARD_DECLARATION(type, super) class H##type; |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1525 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1526 | #undef FORWARD_DECLARATION |
| 1527 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1528 | #define DECLARE_INSTRUCTION(type) \ |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1529 | private: \ |
| 1530 | H##type& operator=(const H##type&) = delete; \ |
| 1531 | public: \ |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1532 | const char* DebugName() const OVERRIDE { return #type; } \ |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1533 | HInstruction* Clone(ArenaAllocator* arena) const OVERRIDE { \ |
| 1534 | DCHECK(IsClonable()); \ |
| 1535 | return new (arena) H##type(*this->As##type()); \ |
| 1536 | } \ |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1537 | void Accept(HGraphVisitor* visitor) OVERRIDE |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1538 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1539 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1540 | private: \ |
| 1541 | H##type& operator=(const H##type&) = delete; \ |
| Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 1542 | public: |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1543 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1544 | #define DEFAULT_COPY_CONSTRUCTOR(type) \ |
| 1545 | explicit H##type(const H##type& other) = default; |
| 1546 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1547 | template <typename T> |
| Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1548 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1549 | public IntrusiveForwardListNode<HUseListNode<T>> { |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1550 | public: |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1551 | // Get the instruction which has this use as one of the inputs. |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1552 | T GetUser() const { return user_; } |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1553 | // Get the position of the input record that this use corresponds to. |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1554 | size_t GetIndex() const { return index_; } |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1555 | // Set the position of the input record that this use corresponds to. |
| Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1556 | void SetIndex(size_t index) { index_ = index; } |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1557 | |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1558 | private: |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1559 | HUseListNode(T user, size_t index) |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1560 | : user_(user), index_(index) {} |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1561 | |
| 1562 | T const user_; |
| Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1563 | size_t index_; |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1564 | |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1565 | friend class HInstruction; |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1566 | |
| 1567 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1568 | }; |
| 1569 | |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1570 | template <typename T> |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1571 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1572 | |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1573 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1574 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1575 | // by the used instructions. |
| 1576 | template <typename T> |
| Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1577 | class HUserRecord : public ValueObject { |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1578 | public: |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1579 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1580 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1581 | |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1582 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1583 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1584 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1585 | : instruction_(instruction), before_use_node_(before_use_node) { |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1586 | DCHECK(instruction_ != nullptr); |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | HInstruction* GetInstruction() const { return instruction_; } |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1590 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1591 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1592 | |
| 1593 | private: |
| 1594 | // Instruction used by the user. |
| 1595 | HInstruction* instruction_; |
| 1596 | |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1597 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1598 | typename HUseList<T>::iterator before_use_node_; |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1599 | }; |
| 1600 | |
| Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1601 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1602 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1603 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1604 | struct HInputExtractor { |
| 1605 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1606 | return record.GetInstruction(); |
| 1607 | } |
| 1608 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1609 | return record.GetInstruction(); |
| 1610 | } |
| 1611 | }; |
| 1612 | |
| 1613 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1614 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1615 | |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1616 | /** |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1617 | * Side-effects representation. |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1618 | * |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1619 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1620 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1621 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1622 | * modify the value of a reference field read [although it may modify the |
| 1623 | * reference fetch prior to reading the field, which is represented by its own |
| 1624 | * write/read dependence]). The analysis makes conservative points-to |
| 1625 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1626 | * the same, and any reference read depends on any reference read without |
| 1627 | * further regard of its type). |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1628 | * |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 1629 | * kDependsOnGCBit is defined in the following way: instructions with kDependsOnGCBit must not be |
| 1630 | * alive across the point where garbage collection might happen. |
| 1631 | * |
| 1632 | * Note: Instructions with kCanTriggerGCBit do not depend on each other. |
| 1633 | * |
| 1634 | * kCanTriggerGCBit must be used for instructions for which GC might happen on the path across |
| 1635 | * those instructions from the compiler perspective (between this instruction and the next one |
| 1636 | * in the IR). |
| 1637 | * |
| 1638 | * Note: Instructions which can cause GC only on a fatal slow path do not need |
| 1639 | * kCanTriggerGCBit as the execution never returns to the instruction next to the exceptional |
| 1640 | * one. However the execution may return to compiled code if there is a catch block in the |
| 1641 | * current method; for this purpose the TryBoundary exit instruction has kCanTriggerGCBit |
| 1642 | * set. |
| 1643 | * |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1644 | * The internal representation uses 38-bit and is described in the table below. |
| 1645 | * The first line indicates the side effect, and for field/array accesses the |
| 1646 | * second line indicates the type of the access (in the order of the |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1647 | * DataType::Type enum). |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1648 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1649 | * vertically). |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1650 | * |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1651 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1652 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1653 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1654 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1655 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1656 | * |
| 1657 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1658 | * bits, while 'dependency' bits are most significant bits. |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1659 | */ |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1660 | class SideEffects : public ValueObject { |
| 1661 | public: |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1662 | SideEffects() : flags_(0) {} |
| 1663 | |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1664 | static SideEffects None() { |
| 1665 | return SideEffects(0); |
| 1666 | } |
| 1667 | |
| 1668 | static SideEffects All() { |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1669 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1670 | } |
| 1671 | |
| 1672 | static SideEffects AllChanges() { |
| 1673 | return SideEffects(kAllChangeBits); |
| 1674 | } |
| 1675 | |
| 1676 | static SideEffects AllDependencies() { |
| 1677 | return SideEffects(kAllDependOnBits); |
| 1678 | } |
| 1679 | |
| 1680 | static SideEffects AllExceptGCDependency() { |
| 1681 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1682 | } |
| 1683 | |
| 1684 | static SideEffects AllWritesAndReads() { |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1685 | return SideEffects(kAllWrites | kAllReads); |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1686 | } |
| 1687 | |
| Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1688 | static SideEffects AllWrites() { |
| 1689 | return SideEffects(kAllWrites); |
| 1690 | } |
| 1691 | |
| 1692 | static SideEffects AllReads() { |
| 1693 | return SideEffects(kAllReads); |
| 1694 | } |
| 1695 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1696 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
| Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1697 | return is_volatile |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1698 | ? AllWritesAndReads() |
| Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1699 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1700 | } |
| 1701 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1702 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
| Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1703 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1704 | } |
| 1705 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1706 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
| Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1707 | return is_volatile |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1708 | ? AllWritesAndReads() |
| Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1709 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1710 | } |
| 1711 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1712 | static SideEffects ArrayReadOfType(DataType::Type type) { |
| Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1713 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 1716 | // Returns whether GC might happen across this instruction from the compiler perspective so |
| 1717 | // the next instruction in the IR would see that. |
| 1718 | // |
| 1719 | // See the SideEffect class comments. |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1720 | static SideEffects CanTriggerGC() { |
| 1721 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1722 | } |
| 1723 | |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 1724 | // Returns whether the instruction must not be alive across a GC point. |
| 1725 | // |
| 1726 | // See the SideEffect class comments. |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1727 | static SideEffects DependsOnGC() { |
| 1728 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1729 | } |
| 1730 | |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1731 | // Combines the side-effects of this and the other. |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1732 | SideEffects Union(SideEffects other) const { |
| 1733 | return SideEffects(flags_ | other.flags_); |
| 1734 | } |
| 1735 | |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1736 | SideEffects Exclusion(SideEffects other) const { |
| 1737 | return SideEffects(flags_ & ~other.flags_); |
| 1738 | } |
| 1739 | |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1740 | void Add(SideEffects other) { |
| 1741 | flags_ |= other.flags_; |
| 1742 | } |
| 1743 | |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1744 | bool Includes(SideEffects other) const { |
| 1745 | return (other.flags_ & flags_) == other.flags_; |
| 1746 | } |
| 1747 | |
| 1748 | bool HasSideEffects() const { |
| 1749 | return (flags_ & kAllChangeBits); |
| 1750 | } |
| 1751 | |
| 1752 | bool HasDependencies() const { |
| 1753 | return (flags_ & kAllDependOnBits); |
| 1754 | } |
| 1755 | |
| 1756 | // Returns true if there are no side effects or dependencies. |
| 1757 | bool DoesNothing() const { |
| 1758 | return flags_ == 0; |
| 1759 | } |
| 1760 | |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1761 | // Returns true if something is written. |
| 1762 | bool DoesAnyWrite() const { |
| 1763 | return (flags_ & kAllWrites); |
| Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1764 | } |
| 1765 | |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1766 | // Returns true if something is read. |
| 1767 | bool DoesAnyRead() const { |
| 1768 | return (flags_ & kAllReads); |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1769 | } |
| 1770 | |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1771 | // Returns true if potentially everything is written and read |
| 1772 | // (every type and every kind of access). |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1773 | bool DoesAllReadWrite() const { |
| 1774 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1775 | } |
| 1776 | |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1777 | bool DoesAll() const { |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1778 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1781 | // Returns true if `this` may read something written by `other`. |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1782 | bool MayDependOn(SideEffects other) const { |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1783 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1784 | return (other.flags_ & depends_on_flags); |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | // Returns string representation of flags (for debugging only). |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1788 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1789 | std::string ToString() const { |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1790 | std::string flags = "|"; |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1791 | for (int s = kLastBit; s >= 0; s--) { |
| 1792 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1793 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1794 | // This is a bit for the GC side effect. |
| 1795 | if (current_bit_is_set) { |
| 1796 | flags += "GC"; |
| 1797 | } |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1798 | flags += "|"; |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1799 | } else { |
| 1800 | // This is a bit for the array/field analysis. |
| 1801 | // The underscore character stands for the 'can trigger GC' bit. |
| 1802 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1803 | if (current_bit_is_set) { |
| 1804 | flags += kDebug[s]; |
| 1805 | } |
| 1806 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1807 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1808 | flags += "|"; |
| 1809 | } |
| 1810 | } |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1811 | } |
| 1812 | return flags; |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1813 | } |
| 1814 | |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1815 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1816 | |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1817 | private: |
| 1818 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1819 | |
| 1820 | static constexpr int kFieldWriteOffset = 0; |
| 1821 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1822 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1823 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1824 | |
| 1825 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1826 | |
| 1827 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1828 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1829 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1830 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1831 | |
| 1832 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1833 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1834 | |
| 1835 | // Aliases. |
| 1836 | |
| 1837 | static_assert(kChangeBits == kDependOnBits, |
| 1838 | "the 'change' bits should match the 'depend on' bits."); |
| 1839 | |
| 1840 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1841 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1842 | static constexpr uint64_t kAllWrites = |
| 1843 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1844 | static constexpr uint64_t kAllReads = |
| 1845 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1846 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1847 | // Translates type to bit flag. The type must correspond to a Java type. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1848 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1849 | int shift; |
| 1850 | switch (type) { |
| 1851 | case DataType::Type::kReference: shift = 0; break; |
| 1852 | case DataType::Type::kBool: shift = 1; break; |
| 1853 | case DataType::Type::kInt8: shift = 2; break; |
| 1854 | case DataType::Type::kUint16: shift = 3; break; |
| 1855 | case DataType::Type::kInt16: shift = 4; break; |
| 1856 | case DataType::Type::kInt32: shift = 5; break; |
| 1857 | case DataType::Type::kInt64: shift = 6; break; |
| 1858 | case DataType::Type::kFloat32: shift = 7; break; |
| 1859 | case DataType::Type::kFloat64: shift = 8; break; |
| 1860 | default: |
| 1861 | LOG(FATAL) << "Unexpected data type " << type; |
| 1862 | UNREACHABLE(); |
| 1863 | } |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1864 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1865 | DCHECK_LT(shift, kArrayWriteOffset); |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1866 | return UINT64_C(1) << (shift + offset); |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | // Private constructor on direct flags value. |
| 1870 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1871 | |
| 1872 | uint64_t flags_; |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1873 | }; |
| 1874 | |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1875 | // 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] | 1876 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1877 | public: |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1878 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1879 | size_t number_of_vregs, |
| 1880 | ArtMethod* method, |
| 1881 | uint32_t dex_pc, |
| 1882 | HInstruction* holder) |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1883 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1884 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1885 | parent_(nullptr), |
| Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1886 | method_(method), |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1887 | dex_pc_(dex_pc), |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1888 | holder_(holder) { |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1889 | } |
| 1890 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1891 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 1892 | const HEnvironment& to_copy, |
| 1893 | HInstruction* holder) |
| 1894 | : HEnvironment(allocator, |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1895 | to_copy.Size(), |
| Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1896 | to_copy.GetMethod(), |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1897 | to_copy.GetDexPc(), |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1898 | holder) {} |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1899 | |
| Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1900 | void AllocateLocations() { |
| 1901 | DCHECK(locations_.empty()); |
| 1902 | locations_.resize(vregs_.size()); |
| 1903 | } |
| 1904 | |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1905 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1906 | if (parent_ != nullptr) { |
| 1907 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1908 | } else { |
| 1909 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1910 | parent_->CopyFrom(parent); |
| 1911 | if (parent->GetParent() != nullptr) { |
| 1912 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1913 | } |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1914 | } |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1915 | } |
| 1916 | |
| Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 1917 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
| Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1918 | void CopyFrom(HEnvironment* environment); |
| 1919 | |
| Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1920 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1921 | // input to the loop phi instead. This is for inserting instructions that |
| 1922 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1923 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1924 | |
| 1925 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1926 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | HInstruction* GetInstructionAt(size_t index) const { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1930 | return vregs_[index].GetInstruction(); |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1933 | void RemoveAsUserOfInput(size_t index) const; |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1934 | |
| Artem Serov | ca210e3 | 2017-12-15 13:43:20 +0000 | [diff] [blame] | 1935 | // Replaces the input at the position 'index' with the replacement; the replacement and old |
| 1936 | // input instructions' env_uses_ lists are adjusted. The function works similar to |
| 1937 | // HInstruction::ReplaceInput. |
| 1938 | void ReplaceInput(HInstruction* replacement, size_t index); |
| 1939 | |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1940 | size_t Size() const { return vregs_.size(); } |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1941 | |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1942 | HEnvironment* GetParent() const { return parent_; } |
| 1943 | |
| 1944 | void SetLocationAt(size_t index, Location location) { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1945 | locations_[index] = location; |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | Location GetLocationAt(size_t index) const { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1949 | return locations_[index]; |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | uint32_t GetDexPc() const { |
| 1953 | return dex_pc_; |
| 1954 | } |
| 1955 | |
| Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1956 | ArtMethod* GetMethod() const { |
| 1957 | return method_; |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1958 | } |
| 1959 | |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1960 | HInstruction* GetHolder() const { |
| 1961 | return holder_; |
| 1962 | } |
| 1963 | |
| Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1964 | |
| 1965 | bool IsFromInlinedInvoke() const { |
| 1966 | return GetParent() != nullptr; |
| 1967 | } |
| 1968 | |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1969 | private: |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1970 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1971 | ArenaVector<Location> locations_; |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1972 | HEnvironment* parent_; |
| Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1973 | ArtMethod* method_; |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1974 | const uint32_t dex_pc_; |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1975 | |
| Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1976 | // The instruction that holds this environment. |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1977 | HInstruction* const holder_; |
| 1978 | |
| Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1979 | friend class HInstruction; |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1980 | |
| 1981 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1982 | }; |
| 1983 | |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1984 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1985 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1986 | #define DECLARE_KIND(type, super) k##type, |
| 1987 | enum InstructionKind { |
| Vladimir Marko | e394622 | 2018-05-04 14:18:47 +0100 | [diff] [blame] | 1988 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1989 | kLastInstructionKind |
| 1990 | }; |
| 1991 | #undef DECLARE_KIND |
| 1992 | |
| 1993 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 1994 | : HInstruction(kind, DataType::Type::kVoid, side_effects, dex_pc) {} |
| 1995 | |
| 1996 | HInstruction(InstructionKind kind, DataType::Type type, SideEffects side_effects, uint32_t dex_pc) |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1997 | : previous_(nullptr), |
| 1998 | next_(nullptr), |
| 1999 | block_(nullptr), |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2000 | dex_pc_(dex_pc), |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2001 | id_(-1), |
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2002 | ssa_index_(-1), |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2003 | packed_fields_(0u), |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2004 | environment_(nullptr), |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2005 | locations_(nullptr), |
| 2006 | live_interval_(nullptr), |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2007 | lifetime_position_(kNoLifetime), |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 2008 | side_effects_(side_effects), |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2009 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2010 | SetPackedField<InstructionKindField>(kind); |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2011 | SetPackedField<TypeField>(type); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2012 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 2013 | } |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2014 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2015 | virtual ~HInstruction() {} |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2016 | |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2017 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2018 | HInstruction* GetNext() const { return next_; } |
| 2019 | HInstruction* GetPrevious() const { return previous_; } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2020 | |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2021 | HInstruction* GetNextDisregardingMoves() const; |
| 2022 | HInstruction* GetPreviousDisregardingMoves() const; |
| 2023 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2024 | HBasicBlock* GetBlock() const { return block_; } |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2025 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2026 | void SetBlock(HBasicBlock* block) { block_ = block; } |
| Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2027 | bool IsInBlock() const { return block_ != nullptr; } |
| 2028 | bool IsInLoop() const { return block_->IsInLoop(); } |
| Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 2029 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 2030 | bool IsIrreducibleLoopHeaderPhi() const { |
| 2031 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 2032 | } |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2033 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2034 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2035 | |
| 2036 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2037 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2038 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2039 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2040 | } |
| 2041 | |
| Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2042 | HInputsRef GetInputs() { |
| 2043 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2044 | } |
| 2045 | |
| Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2046 | HConstInputsRef GetInputs() const { |
| 2047 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2048 | } |
| 2049 | |
| 2050 | size_t InputCount() const { return GetInputRecords().size(); } |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2051 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2052 | |
| Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2053 | bool HasInput(HInstruction* input) const { |
| 2054 | for (const HInstruction* i : GetInputs()) { |
| 2055 | if (i == input) { |
| 2056 | return true; |
| 2057 | } |
| 2058 | } |
| 2059 | return false; |
| 2060 | } |
| 2061 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2062 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2063 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2064 | } |
| 2065 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2066 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2067 | virtual const char* DebugName() const = 0; |
| 2068 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2069 | DataType::Type GetType() const { |
| 2070 | return TypeField::Decode(GetPackedFields()); |
| 2071 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2072 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2073 | virtual bool NeedsEnvironment() const { return false; } |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2074 | |
| 2075 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2076 | |
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2077 | virtual bool IsControlFlow() const { return false; } |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2078 | |
| Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2079 | // Can the instruction throw? |
| 2080 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2081 | // could throw OOME, but it is still OK to remove them if they are unused. |
| Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 2082 | virtual bool CanThrow() const { return false; } |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2083 | |
| 2084 | // Does the instruction always throw an exception unconditionally? |
| 2085 | virtual bool AlwaysThrows() const { return false; } |
| 2086 | |
| David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2087 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2088 | |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2089 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2090 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2091 | |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2092 | // Does not apply for all instructions, but having this at top level greatly |
| 2093 | // simplifies the null check elimination. |
| Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2094 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2095 | virtual bool CanBeNull() const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2096 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
| Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2097 | return true; |
| 2098 | } |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2099 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2100 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2101 | return false; |
| 2102 | } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2103 | |
| Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2104 | virtual bool IsActualObject() const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2105 | return GetType() == DataType::Type::kReference; |
| Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2106 | } |
| 2107 | |
| Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2108 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2109 | |
| Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2110 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2111 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2112 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
| Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2113 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
| Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2114 | } |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2115 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2116 | void AddUseAt(HInstruction* user, size_t index) { |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2117 | DCHECK(user != nullptr); |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2118 | // Note: fixup_end remains valid across push_front(). |
| 2119 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 2120 | HUseListNode<HInstruction*>* new_node = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2121 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HInstruction*>(user, index); |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2122 | uses_.push_front(*new_node); |
| 2123 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2126 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
| Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2127 | DCHECK(user != nullptr); |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2128 | // Note: env_fixup_end remains valid across push_front(). |
| 2129 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2130 | HUseListNode<HEnvironment*>* new_node = |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2131 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2132 | env_uses_.push_front(*new_node); |
| 2133 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2134 | } |
| 2135 | |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2136 | void RemoveAsUserOfInput(size_t input) { |
| 2137 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2138 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2139 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2140 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2141 | } |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2142 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2143 | void RemoveAsUserOfAllInputs() { |
| 2144 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2145 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2146 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2147 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2148 | } |
| 2149 | } |
| 2150 | |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2151 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2152 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2153 | |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2154 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2155 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2156 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
| Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2157 | bool HasOnlyOneNonEnvironmentUse() const { |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2158 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
| Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2159 | } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2160 | |
| Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2161 | bool IsRemovable() const { |
| Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2162 | return |
| Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2163 | !DoesAnyWrite() && |
| Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2164 | !CanThrow() && |
| 2165 | !IsSuspendCheck() && |
| 2166 | !IsControlFlow() && |
| 2167 | !IsNativeDebugInfo() && |
| 2168 | !IsParameterValue() && |
| Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2169 | // If we added an explicit barrier then we should keep it. |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2170 | !IsMemoryBarrier() && |
| 2171 | !IsConstructorFence(); |
| Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
| Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2174 | bool IsDeadAndRemovable() const { |
| 2175 | return IsRemovable() && !HasUses(); |
| 2176 | } |
| 2177 | |
| Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2178 | // Does this instruction strictly dominate `other_instruction`? |
| 2179 | // Returns false if this instruction and `other_instruction` are the same. |
| 2180 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2181 | bool StrictlyDominates(HInstruction* other_instruction) const; |
| Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2182 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2183 | int GetId() const { return id_; } |
| 2184 | void SetId(int id) { id_ = id; } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2185 | |
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2186 | int GetSsaIndex() const { return ssa_index_; } |
| 2187 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2188 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2189 | |
| 2190 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2191 | HEnvironment* GetEnvironment() const { return environment_; } |
| Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2192 | // Set the `environment_` field. Raw because this method does not |
| 2193 | // update the uses lists. |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2194 | void SetRawEnvironment(HEnvironment* environment) { |
| 2195 | DCHECK(environment_ == nullptr); |
| 2196 | DCHECK_EQ(environment->GetHolder(), this); |
| 2197 | environment_ = environment; |
| 2198 | } |
| Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2199 | |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2200 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2201 | DCHECK(environment_ != nullptr); |
| 2202 | DCHECK_EQ(environment->GetHolder(), this); |
| 2203 | DCHECK(environment->GetParent() == nullptr); |
| 2204 | environment->parent_ = environment_; |
| 2205 | environment_ = environment; |
| 2206 | } |
| 2207 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2208 | void RemoveEnvironment(); |
| 2209 | |
| Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2210 | // Set the environment of this instruction, copying it from `environment`. While |
| 2211 | // copying, the uses lists are being updated. |
| 2212 | void CopyEnvironmentFrom(HEnvironment* environment) { |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2213 | DCHECK(environment_ == nullptr); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2214 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2215 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
| Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2216 | environment_->CopyFrom(environment); |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2217 | if (environment->GetParent() != nullptr) { |
| 2218 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2219 | } |
| Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2220 | } |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2221 | |
| Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2222 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2223 | HBasicBlock* block) { |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2224 | DCHECK(environment_ == nullptr); |
| Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2225 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2226 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2227 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
| Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2228 | if (environment->GetParent() != nullptr) { |
| 2229 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2230 | } |
| Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2231 | } |
| 2232 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2233 | // Returns the number of entries in the environment. Typically, that is the |
| 2234 | // number of dex registers in a method. It could be more in case of inlining. |
| 2235 | size_t EnvironmentSize() const; |
| 2236 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2237 | LocationSummary* GetLocations() const { return locations_; } |
| 2238 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2239 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2240 | void ReplaceWith(HInstruction* instruction); |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2241 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
| Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 2242 | void ReplaceEnvUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2243 | void ReplaceInput(HInstruction* replacement, size_t index); |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2244 | |
| Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2245 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2246 | // uses of this instruction by `other` are *not* updated. |
| 2247 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2248 | ReplaceWith(other); |
| 2249 | other->ReplaceInput(this, use_index); |
| 2250 | } |
| 2251 | |
| Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2252 | // Move `this` instruction before `cursor` |
| 2253 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2254 | |
| Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2255 | // Move `this` before its first user and out of any loops. If there is no |
| 2256 | // out-of-loop user that dominates all other users, move the instruction |
| 2257 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2258 | // |
| 2259 | // This can be used only on non-throwing instructions with no side effects that |
| 2260 | // have at least one use but no environment uses. |
| 2261 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2262 | |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2263 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2264 | bool Is##type() const; |
| 2265 | |
| 2266 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2267 | #undef INSTRUCTION_TYPE_CHECK |
| 2268 | |
| 2269 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2270 | const H##type* As##type() const; \ |
| 2271 | H##type* As##type(); |
| 2272 | |
| Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2273 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 2274 | #undef INSTRUCTION_TYPE_CAST |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2275 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2276 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2277 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2278 | // the instruction then the behaviour of this function is undefined. |
| 2279 | // |
| 2280 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2281 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2282 | // copied. |
| 2283 | // |
| 2284 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2285 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2286 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2287 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2288 | DebugName() << " " << GetId(); |
| 2289 | UNREACHABLE(); |
| 2290 | } |
| 2291 | |
| 2292 | // Return whether instruction can be cloned (copied). |
| 2293 | virtual bool IsClonable() const { return false; } |
| 2294 | |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2295 | // Returns whether the instruction can be moved within the graph. |
| Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2296 | // TODO: this method is used by LICM and GVN with possibly different |
| 2297 | // meanings? split and rename? |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2298 | virtual bool CanBeMoved() const { return false; } |
| 2299 | |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2300 | // Returns whether any data encoded in the two instructions is equal. |
| 2301 | // This method does not look at the inputs. Both instructions must be |
| 2302 | // of the same type, otherwise the method has undefined behavior. |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2303 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2304 | return false; |
| 2305 | } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2306 | |
| 2307 | // Returns whether two instructions are equal, that is: |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2308 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2309 | // 2) Their inputs are identical. |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2310 | bool Equals(const HInstruction* other) const; |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2311 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2312 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2313 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2314 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2315 | // apply the strong requirement for virtual functions, preventing optimizations. |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2316 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2317 | |
| 2318 | virtual size_t ComputeHashCode() const { |
| 2319 | size_t result = GetKind(); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2320 | for (const HInstruction* input : GetInputs()) { |
| 2321 | result = (result * 31) + input->GetId(); |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2322 | } |
| 2323 | return result; |
| 2324 | } |
| 2325 | |
| 2326 | SideEffects GetSideEffects() const { return side_effects_; } |
| Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2327 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2328 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2329 | |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2330 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2331 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2332 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2333 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2334 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2335 | |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2336 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2337 | |
| 2338 | // Returns whether the code generation of the instruction will require to have access |
| 2339 | // to the current method. Such instructions are: |
| 2340 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2341 | // to walk the stack and have the current method stored at a specific stack address. |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2342 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2343 | // to access the dex cache. |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2344 | bool NeedsCurrentMethod() const { |
| Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2345 | return NeedsEnvironment() || IsCurrentMethod(); |
| Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2346 | } |
| 2347 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2348 | // Returns whether the code generation of the instruction will require to have access |
| 2349 | // to the dex cache of the current method's declaring class via the current method. |
| 2350 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
| Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2351 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2352 | // Does this instruction have any use in an environment before |
| 2353 | // control flow hits 'other'? |
| 2354 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2355 | |
| 2356 | // Remove all references to environment uses of this instruction. |
| 2357 | // The caller must ensure that this is safe to do. |
| 2358 | void RemoveEnvironmentUsers(); |
| 2359 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2360 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2361 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2362 | |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2363 | protected: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2364 | // If set, the machine code for this instruction is assumed to be generated by |
| 2365 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2366 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2367 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2368 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2369 | static constexpr size_t kFieldInstructionKindSize = |
| 2370 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2371 | static constexpr size_t kFieldType = |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2372 | kFieldInstructionKind + kFieldInstructionKindSize; |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2373 | static constexpr size_t kFieldTypeSize = |
| 2374 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| 2375 | static constexpr size_t kNumberOfGenericPackedBits = kFieldType + kFieldTypeSize; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2376 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2377 | |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2378 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2379 | "Too many generic packed fields"); |
| 2380 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2381 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
| 2382 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2383 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2384 | return GetInputRecords()[i]; |
| 2385 | } |
| 2386 | |
| 2387 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2388 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2389 | input_records[index] = input; |
| 2390 | } |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2391 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2392 | uint32_t GetPackedFields() const { |
| 2393 | return packed_fields_; |
| 2394 | } |
| 2395 | |
| 2396 | template <size_t flag> |
| 2397 | bool GetPackedFlag() const { |
| 2398 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2399 | } |
| 2400 | |
| 2401 | template <size_t flag> |
| 2402 | void SetPackedFlag(bool value = true) { |
| 2403 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2404 | } |
| 2405 | |
| 2406 | template <typename BitFieldType> |
| 2407 | typename BitFieldType::value_type GetPackedField() const { |
| 2408 | return BitFieldType::Decode(packed_fields_); |
| 2409 | } |
| 2410 | |
| 2411 | template <typename BitFieldType> |
| 2412 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2413 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2414 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2415 | } |
| 2416 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2417 | // Copy construction for the instruction (used for Clone function). |
| 2418 | // |
| 2419 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2420 | // prepare_for_register_allocator are not copied (set to default values). |
| 2421 | // |
| 2422 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2423 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2424 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2425 | // for copying them). |
| 2426 | explicit HInstruction(const HInstruction& other) |
| 2427 | : previous_(nullptr), |
| 2428 | next_(nullptr), |
| 2429 | block_(nullptr), |
| 2430 | dex_pc_(other.dex_pc_), |
| 2431 | id_(-1), |
| 2432 | ssa_index_(-1), |
| 2433 | packed_fields_(other.packed_fields_), |
| 2434 | environment_(nullptr), |
| 2435 | locations_(nullptr), |
| 2436 | live_interval_(nullptr), |
| 2437 | lifetime_position_(kNoLifetime), |
| 2438 | side_effects_(other.side_effects_), |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2439 | reference_type_handle_(other.reference_type_handle_) { |
| 2440 | } |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2441 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2442 | private: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2443 | using InstructionKindField = |
| 2444 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2445 | |
| Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2446 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2447 | auto before_use_node = uses_.before_begin(); |
| 2448 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2449 | HInstruction* user = use_node->GetUser(); |
| 2450 | size_t input_index = use_node->GetIndex(); |
| 2451 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2452 | before_use_node = use_node; |
| 2453 | } |
| 2454 | } |
| 2455 | |
| 2456 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2457 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2458 | if (next != uses_.end()) { |
| 2459 | HInstruction* next_user = next->GetUser(); |
| 2460 | size_t next_index = next->GetIndex(); |
| 2461 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2462 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2467 | auto before_env_use_node = env_uses_.before_begin(); |
| 2468 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2469 | HEnvironment* user = env_use_node->GetUser(); |
| 2470 | size_t input_index = env_use_node->GetIndex(); |
| 2471 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2472 | before_env_use_node = env_use_node; |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2477 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2478 | if (next != env_uses_.end()) { |
| 2479 | HEnvironment* next_user = next->GetUser(); |
| 2480 | size_t next_index = next->GetIndex(); |
| 2481 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2482 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2483 | } |
| 2484 | } |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2485 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2486 | HInstruction* previous_; |
| 2487 | HInstruction* next_; |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2488 | HBasicBlock* block_; |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2489 | const uint32_t dex_pc_; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2490 | |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2491 | // An instruction gets an id when it is added to the graph. |
| 2492 | // It reflects creation order. A negative id means the instruction |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2493 | // has not been added to the graph. |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2494 | int id_; |
| 2495 | |
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2496 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2497 | int ssa_index_; |
| 2498 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2499 | // Packed fields. |
| 2500 | uint32_t packed_fields_; |
| David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2501 | |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2502 | // List of instructions that have this instruction as input. |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2503 | HUseList<HInstruction*> uses_; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2504 | |
| 2505 | // List of environments that contain this instruction. |
| David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2506 | HUseList<HEnvironment*> env_uses_; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2507 | |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2508 | // The environment associated with this instruction. Not null if the instruction |
| 2509 | // might jump out of the method. |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2510 | HEnvironment* environment_; |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2511 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2512 | // Set by the code generator. |
| 2513 | LocationSummary* locations_; |
| 2514 | |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2515 | // Set by the liveness analysis. |
| 2516 | LiveInterval* live_interval_; |
| 2517 | |
| 2518 | // Set by the liveness analysis, this is the position in a linear |
| 2519 | // order of blocks where this instruction's live interval start. |
| 2520 | size_t lifetime_position_; |
| 2521 | |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2522 | SideEffects side_effects_; |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2523 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2524 | // The reference handle part of the reference type info. |
| 2525 | // The IsExact() flag is stored in packed fields. |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2526 | // TODO: for primitive types this should be marked as invalid. |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2527 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2528 | |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2529 | friend class GraphChecker; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2530 | friend class HBasicBlock; |
| David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2531 | friend class HEnvironment; |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2532 | friend class HGraph; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2533 | friend class HInstructionList; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2534 | }; |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2535 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2536 | |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2537 | // Iterates over the instructions, while preserving the next instruction |
| 2538 | // in case the current instruction gets removed from the list by the user |
| 2539 | // of this iterator. |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2540 | class HInstructionIterator : public ValueObject { |
| 2541 | public: |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2542 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2543 | : instruction_(instructions.first_instruction_) { |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2544 | next_ = Done() ? nullptr : instruction_->GetNext(); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2545 | } |
| 2546 | |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2547 | bool Done() const { return instruction_ == nullptr; } |
| 2548 | HInstruction* Current() const { return instruction_; } |
| 2549 | void Advance() { |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2550 | instruction_ = next_; |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2551 | next_ = Done() ? nullptr : instruction_->GetNext(); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | private: |
| 2555 | HInstruction* instruction_; |
| 2556 | HInstruction* next_; |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2557 | |
| 2558 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2559 | }; |
| 2560 | |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2561 | // Iterates over the instructions without saving the next instruction, |
| 2562 | // therefore handling changes in the graph potentially made by the user |
| 2563 | // of this iterator. |
| 2564 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2565 | public: |
| 2566 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2567 | : instruction_(instructions.first_instruction_) { |
| 2568 | } |
| 2569 | |
| 2570 | bool Done() const { return instruction_ == nullptr; } |
| 2571 | HInstruction* Current() const { return instruction_; } |
| 2572 | void Advance() { |
| 2573 | instruction_ = instruction_->GetNext(); |
| 2574 | } |
| 2575 | |
| 2576 | private: |
| 2577 | HInstruction* instruction_; |
| 2578 | |
| 2579 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2580 | }; |
| 2581 | |
| 2582 | |
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2583 | class HBackwardInstructionIterator : public ValueObject { |
| 2584 | public: |
| 2585 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2586 | : instruction_(instructions.last_instruction_) { |
| 2587 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2588 | } |
| 2589 | |
| 2590 | bool Done() const { return instruction_ == nullptr; } |
| 2591 | HInstruction* Current() const { return instruction_; } |
| 2592 | void Advance() { |
| 2593 | instruction_ = next_; |
| 2594 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2595 | } |
| 2596 | |
| 2597 | private: |
| 2598 | HInstruction* instruction_; |
| 2599 | HInstruction* next_; |
| Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2600 | |
| 2601 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
| Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2602 | }; |
| 2603 | |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2604 | class HVariableInputSizeInstruction : public HInstruction { |
| 2605 | public: |
| Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2606 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2607 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 2608 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2609 | } |
| 2610 | |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2611 | void AddInput(HInstruction* input); |
| 2612 | void InsertInputAt(size_t index, HInstruction* input); |
| 2613 | void RemoveInputAt(size_t index); |
| 2614 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2615 | // Removes all the inputs. |
| 2616 | // Also removes this instructions from each input's use list |
| 2617 | // (for non-environment uses only). |
| 2618 | void RemoveAllInputs(); |
| 2619 | |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2620 | protected: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2621 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2622 | SideEffects side_effects, |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2623 | uint32_t dex_pc, |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2624 | ArenaAllocator* allocator, |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2625 | size_t number_of_inputs, |
| 2626 | ArenaAllocKind kind) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2627 | : HInstruction(inst_kind, side_effects, dex_pc), |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2628 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2629 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2630 | DataType::Type type, |
| 2631 | SideEffects side_effects, |
| 2632 | uint32_t dex_pc, |
| 2633 | ArenaAllocator* allocator, |
| 2634 | size_t number_of_inputs, |
| 2635 | ArenaAllocKind kind) |
| 2636 | : HInstruction(inst_kind, type, side_effects, dex_pc), |
| 2637 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2638 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2639 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2640 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2641 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2642 | }; |
| 2643 | |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2644 | template<size_t N> |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2645 | class HExpression : public HInstruction { |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2646 | public: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2647 | HExpression<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2648 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2649 | HExpression<N>(InstructionKind kind, |
| 2650 | DataType::Type type, |
| 2651 | SideEffects side_effects, |
| 2652 | uint32_t dex_pc) |
| 2653 | : HInstruction(kind, type, side_effects, dex_pc), inputs_() {} |
| 2654 | virtual ~HExpression() {} |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2655 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2656 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2657 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2658 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2661 | protected: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2662 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2663 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2664 | private: |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2665 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2666 | |
| 2667 | friend class SsaBuilder; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2668 | }; |
| 2669 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2670 | // HExpression specialization for N=0. |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2671 | template<> |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2672 | class HExpression<0> : public HInstruction { |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2673 | public: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2674 | using HInstruction::HInstruction; |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2675 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2676 | virtual ~HExpression() {} |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2677 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2678 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 2679 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 2680 | return ArrayRef<HUserRecord<HInstruction*>>(); |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2681 | } |
| 2682 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2683 | protected: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2684 | DEFAULT_COPY_CONSTRUCTOR(Expression<0>); |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2685 | |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2686 | private: |
| 2687 | friend class SsaBuilder; |
| 2688 | }; |
| 2689 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2690 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2691 | // instruction that branches to the exit block. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2692 | class HReturnVoid FINAL : public HExpression<0> { |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2693 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2694 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2695 | : HExpression(kReturnVoid, SideEffects::None(), dex_pc) { |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2696 | } |
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2697 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2698 | bool IsControlFlow() const OVERRIDE { return true; } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2699 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2700 | DECLARE_INSTRUCTION(ReturnVoid); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2701 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2702 | protected: |
| 2703 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2704 | }; |
| 2705 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2706 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2707 | // instruction that branches to the exit block. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2708 | class HReturn FINAL : public HExpression<1> { |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2709 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2710 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2711 | : HExpression(kReturn, SideEffects::None(), dex_pc) { |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2712 | SetRawInputAt(0, value); |
| 2713 | } |
| 2714 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2715 | bool IsControlFlow() const OVERRIDE { return true; } |
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2716 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2717 | DECLARE_INSTRUCTION(Return); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2718 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2719 | protected: |
| 2720 | DEFAULT_COPY_CONSTRUCTOR(Return); |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2721 | }; |
| 2722 | |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2723 | class HPhi FINAL : public HVariableInputSizeInstruction { |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2724 | public: |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2725 | HPhi(ArenaAllocator* allocator, |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2726 | uint32_t reg_number, |
| 2727 | size_t number_of_inputs, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2728 | DataType::Type type, |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2729 | uint32_t dex_pc = kNoDexPc) |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2730 | : HVariableInputSizeInstruction( |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2731 | kPhi, |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2732 | ToPhiType(type), |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2733 | SideEffects::None(), |
| 2734 | dex_pc, |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2735 | allocator, |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2736 | number_of_inputs, |
| 2737 | kArenaAllocPhiInputs), |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2738 | reg_number_(reg_number) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2739 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2740 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2741 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2742 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2743 | SetPackedFlag<kFlagIsLive>(true); |
| 2744 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2745 | } |
| 2746 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2747 | bool IsClonable() const OVERRIDE { return true; } |
| 2748 | |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2749 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2750 | static DataType::Type ToPhiType(DataType::Type type) { |
| 2751 | return DataType::Kind(type); |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2755 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2756 | void SetType(DataType::Type new_type) { |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2757 | // Make sure that only valid type changes occur. The following are allowed: |
| 2758 | // (1) int -> float/ref (primitive type propagation), |
| 2759 | // (2) long -> double (primitive type propagation). |
| 2760 | DCHECK(GetType() == new_type || |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2761 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 2762 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 2763 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2764 | SetPackedField<TypeField>(new_type); |
| 2765 | } |
| 2766 | |
| 2767 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 2768 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2769 | |
| 2770 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2771 | |
| 2772 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2773 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2774 | bool IsDead() const { return !IsLive(); } |
| 2775 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2776 | |
| Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2777 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2778 | return other != nullptr |
| 2779 | && other->IsPhi() |
| 2780 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2781 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2782 | } |
| 2783 | |
| Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2784 | bool HasEquivalentPhi() const { |
| 2785 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2786 | return true; |
| 2787 | } |
| 2788 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2789 | return true; |
| 2790 | } |
| 2791 | return false; |
| 2792 | } |
| 2793 | |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2794 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2795 | // An equivalent phi is a phi having the same dex register and type. |
| 2796 | // It assumes that phis with the same dex register are adjacent. |
| 2797 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2798 | HInstruction* next = GetNext(); |
| 2799 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2800 | if (next->GetType() == GetType()) { |
| 2801 | return next->AsPhi(); |
| 2802 | } |
| 2803 | next = next->GetNext(); |
| 2804 | } |
| 2805 | return nullptr; |
| 2806 | } |
| 2807 | |
| 2808 | DECLARE_INSTRUCTION(Phi); |
| 2809 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2810 | protected: |
| 2811 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 2812 | |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2813 | private: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2814 | static constexpr size_t kFlagIsLive = HInstruction::kNumberOfGenericPackedBits; |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2815 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2816 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2817 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2818 | |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2819 | const uint32_t reg_number_; |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2820 | }; |
| 2821 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2822 | // The exit instruction is the only instruction of the exit block. |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2823 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2824 | // exit block. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2825 | class HExit FINAL : public HExpression<0> { |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2826 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2827 | explicit HExit(uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2828 | : HExpression(kExit, SideEffects::None(), dex_pc) { |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2829 | } |
| Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2830 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2831 | bool IsControlFlow() const OVERRIDE { return true; } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2832 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2833 | DECLARE_INSTRUCTION(Exit); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2834 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2835 | protected: |
| 2836 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2837 | }; |
| 2838 | |
| 2839 | // Jumps from one block to another. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2840 | class HGoto FINAL : public HExpression<0> { |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2841 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2842 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2843 | : HExpression(kGoto, SideEffects::None(), dex_pc) { |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2844 | } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2845 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2846 | bool IsClonable() const OVERRIDE { return true; } |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2847 | bool IsControlFlow() const OVERRIDE { return true; } |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2848 | |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2849 | HBasicBlock* GetSuccessor() const { |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2850 | return GetBlock()->GetSingleSuccessor(); |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2853 | DECLARE_INSTRUCTION(Goto); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2854 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2855 | protected: |
| 2856 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2857 | }; |
| 2858 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2859 | class HConstant : public HExpression<0> { |
| 2860 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2861 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 2862 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 2863 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2864 | |
| 2865 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2866 | |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2867 | // Is this constant -1 in the arithmetic sense? |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2868 | virtual bool IsMinusOne() const { return false; } |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2869 | // Is this constant 0 in the arithmetic sense? |
| 2870 | virtual bool IsArithmeticZero() const { return false; } |
| 2871 | // Is this constant a 0-bit pattern? |
| 2872 | virtual bool IsZeroBitPattern() const { return false; } |
| 2873 | // Is this constant 1 in the arithmetic sense? |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2874 | virtual bool IsOne() const { return false; } |
| 2875 | |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2876 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2877 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2878 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2879 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2880 | protected: |
| 2881 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2882 | }; |
| 2883 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2884 | class HNullConstant FINAL : public HConstant { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2885 | public: |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2886 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2887 | return true; |
| 2888 | } |
| 2889 | |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2890 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2891 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2892 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2893 | |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2894 | // The null constant representation is a 0-bit pattern. |
| 2895 | virtual bool IsZeroBitPattern() const { return true; } |
| 2896 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2897 | DECLARE_INSTRUCTION(NullConstant); |
| 2898 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2899 | protected: |
| 2900 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 2901 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2902 | private: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2903 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2904 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 2905 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2906 | |
| 2907 | friend class HGraph; |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2908 | }; |
| 2909 | |
| 2910 | // Constants of the type int. Those can be from Dex instructions, or |
| 2911 | // synthesized (for example with the if-eqz instruction). |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2912 | class HIntConstant FINAL : public HConstant { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2913 | public: |
| 2914 | int32_t GetValue() const { return value_; } |
| 2915 | |
| David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2916 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2917 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2918 | } |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2919 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2920 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2921 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2922 | return other->AsIntConstant()->value_ == value_; |
| 2923 | } |
| 2924 | |
| 2925 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2926 | |
| 2927 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2928 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2929 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2930 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2931 | |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2932 | // Integer constants are used to encode Boolean values as well, |
| 2933 | // where 1 means true and 0 means false. |
| 2934 | bool IsTrue() const { return GetValue() == 1; } |
| 2935 | bool IsFalse() const { return GetValue() == 0; } |
| 2936 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2937 | DECLARE_INSTRUCTION(IntConstant); |
| 2938 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2939 | protected: |
| 2940 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 2941 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2942 | private: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2943 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2944 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 2945 | } |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2946 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2947 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 2948 | value_(value ? 1 : 0) { |
| 2949 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2950 | |
| 2951 | const int32_t value_; |
| 2952 | |
| 2953 | friend class HGraph; |
| 2954 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2955 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2956 | }; |
| 2957 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2958 | class HLongConstant FINAL : public HConstant { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2959 | public: |
| 2960 | int64_t GetValue() const { return value_; } |
| 2961 | |
| David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2962 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2963 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2964 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2965 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2966 | return other->AsLongConstant()->value_ == value_; |
| 2967 | } |
| 2968 | |
| 2969 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2970 | |
| 2971 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2972 | bool IsArithmeticZero() const OVERRIDE { return GetValue() == 0; } |
| 2973 | bool IsZeroBitPattern() const OVERRIDE { return GetValue() == 0; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2974 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2975 | |
| 2976 | DECLARE_INSTRUCTION(LongConstant); |
| 2977 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2978 | protected: |
| 2979 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 2980 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2981 | private: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2982 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2983 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 2984 | value_(value) { |
| 2985 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2986 | |
| 2987 | const int64_t value_; |
| 2988 | |
| 2989 | friend class HGraph; |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2990 | }; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2991 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 2992 | class HFloatConstant FINAL : public HConstant { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2993 | public: |
| 2994 | float GetValue() const { return value_; } |
| 2995 | |
| 2996 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2997 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2998 | } |
| 2999 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3000 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3001 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 3002 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3003 | } |
| 3004 | |
| 3005 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 3006 | |
| 3007 | bool IsMinusOne() const OVERRIDE { |
| 3008 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 3009 | } |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3010 | bool IsArithmeticZero() const OVERRIDE { |
| 3011 | return std::fpclassify(value_) == FP_ZERO; |
| 3012 | } |
| 3013 | bool IsArithmeticPositiveZero() const { |
| 3014 | return IsArithmeticZero() && !std::signbit(value_); |
| 3015 | } |
| 3016 | bool IsArithmeticNegativeZero() const { |
| 3017 | return IsArithmeticZero() && std::signbit(value_); |
| 3018 | } |
| 3019 | bool IsZeroBitPattern() const OVERRIDE { |
| Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3020 | 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] | 3021 | } |
| 3022 | bool IsOne() const OVERRIDE { |
| 3023 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3024 | } |
| 3025 | bool IsNaN() const { |
| 3026 | return std::isnan(value_); |
| 3027 | } |
| 3028 | |
| 3029 | DECLARE_INSTRUCTION(FloatConstant); |
| 3030 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3031 | protected: |
| 3032 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3033 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3034 | private: |
| 3035 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3036 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3037 | value_(value) { |
| 3038 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3039 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3040 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3041 | value_(bit_cast<float, int32_t>(value)) { |
| 3042 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3043 | |
| 3044 | const float value_; |
| 3045 | |
| 3046 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3047 | friend class SsaBuilder; |
| 3048 | friend class HGraph; |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3049 | }; |
| 3050 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3051 | class HDoubleConstant FINAL : public HConstant { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3052 | public: |
| 3053 | double GetValue() const { return value_; } |
| 3054 | |
| 3055 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3056 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3057 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3058 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 3059 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3060 | } |
| 3061 | |
| 3062 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 3063 | |
| 3064 | bool IsMinusOne() const OVERRIDE { |
| 3065 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3066 | } |
| Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3067 | bool IsArithmeticZero() const OVERRIDE { |
| 3068 | return std::fpclassify(value_) == FP_ZERO; |
| 3069 | } |
| 3070 | bool IsArithmeticPositiveZero() const { |
| 3071 | return IsArithmeticZero() && !std::signbit(value_); |
| 3072 | } |
| 3073 | bool IsArithmeticNegativeZero() const { |
| 3074 | return IsArithmeticZero() && std::signbit(value_); |
| 3075 | } |
| 3076 | bool IsZeroBitPattern() const OVERRIDE { |
| Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3077 | 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] | 3078 | } |
| 3079 | bool IsOne() const OVERRIDE { |
| 3080 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3081 | } |
| 3082 | bool IsNaN() const { |
| 3083 | return std::isnan(value_); |
| 3084 | } |
| 3085 | |
| 3086 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3087 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3088 | protected: |
| 3089 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3090 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3091 | private: |
| 3092 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3093 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3094 | value_(value) { |
| 3095 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3096 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3097 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3098 | value_(bit_cast<double, int64_t>(value)) { |
| 3099 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3100 | |
| 3101 | const double value_; |
| 3102 | |
| 3103 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3104 | friend class SsaBuilder; |
| 3105 | friend class HGraph; |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3106 | }; |
| 3107 | |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3108 | // Conditional branch. A block ending with an HIf instruction must have |
| 3109 | // two successors. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3110 | class HIf FINAL : public HExpression<1> { |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3111 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3112 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3113 | : HExpression(kIf, SideEffects::None(), dex_pc) { |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3114 | SetRawInputAt(0, input); |
| 3115 | } |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3116 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3117 | bool IsClonable() const OVERRIDE { return true; } |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 3118 | bool IsControlFlow() const OVERRIDE { return true; } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3119 | |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3120 | HBasicBlock* IfTrueSuccessor() const { |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3121 | return GetBlock()->GetSuccessors()[0]; |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | HBasicBlock* IfFalseSuccessor() const { |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3125 | return GetBlock()->GetSuccessors()[1]; |
| Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3126 | } |
| 3127 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3128 | DECLARE_INSTRUCTION(If); |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3129 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3130 | protected: |
| 3131 | DEFAULT_COPY_CONSTRUCTOR(If); |
| Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3132 | }; |
| 3133 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3134 | |
| 3135 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3136 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3137 | // non-exceptional control flow. |
| 3138 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3139 | // higher indices in no particular order. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3140 | class HTryBoundary FINAL : public HExpression<0> { |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3141 | public: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3142 | enum class BoundaryKind { |
| David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3143 | kEntry, |
| 3144 | kExit, |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3145 | kLast = kExit |
| David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3146 | }; |
| 3147 | |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 3148 | // SideEffects::CanTriggerGC prevents instructions with SideEffects::DependOnGC to be alive |
| 3149 | // across the catch block entering edges as GC might happen during throwing an exception. |
| 3150 | // TryBoundary with BoundaryKind::kExit is conservatively used for that as there is no |
| 3151 | // HInstruction which a catch block must start from. |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3152 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 3153 | : HExpression(kTryBoundary, |
| 3154 | (kind == BoundaryKind::kExit) ? SideEffects::CanTriggerGC() |
| 3155 | : SideEffects::None(), |
| 3156 | dex_pc) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3157 | SetPackedField<BoundaryKindField>(kind); |
| 3158 | } |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3159 | |
| 3160 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3161 | |
| 3162 | // Returns the block's non-exceptional successor (index zero). |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3163 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3164 | |
| David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3165 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3166 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3167 | } |
| 3168 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3169 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3170 | // successors). |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3171 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3172 | DCHECK(handler.IsCatchBlock()); |
| Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3173 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | // If not present already, adds `handler` to its block's list of exception |
| 3177 | // handlers. |
| 3178 | void AddExceptionHandler(HBasicBlock* handler) { |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3179 | if (!HasExceptionHandler(*handler)) { |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3180 | GetBlock()->AddSuccessor(handler); |
| 3181 | } |
| 3182 | } |
| 3183 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3184 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3185 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3186 | |
| David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3187 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3188 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3189 | DECLARE_INSTRUCTION(TryBoundary); |
| 3190 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3191 | protected: |
| 3192 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3193 | |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3194 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3195 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3196 | static constexpr size_t kFieldBoundaryKindSize = |
| 3197 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3198 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3199 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3200 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3201 | "Too many packed fields."); |
| 3202 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
| David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3203 | }; |
| 3204 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3205 | // Deoptimize to interpreter, upon checking a condition. |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3206 | class HDeoptimize FINAL : public HVariableInputSizeInstruction { |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3207 | public: |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3208 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3209 | // across. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3210 | HDeoptimize(ArenaAllocator* allocator, |
| 3211 | HInstruction* cond, |
| 3212 | DeoptimizationKind kind, |
| 3213 | uint32_t dex_pc) |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3214 | : HVariableInputSizeInstruction( |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3215 | kDeoptimize, |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3216 | SideEffects::All(), |
| 3217 | dex_pc, |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3218 | allocator, |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3219 | /* number_of_inputs */ 1, |
| 3220 | kArenaAllocMisc) { |
| 3221 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3222 | SetPackedField<DeoptimizeKindField>(kind); |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3223 | SetRawInputAt(0, cond); |
| 3224 | } |
| 3225 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3226 | bool IsClonable() const OVERRIDE { return true; } |
| 3227 | |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3228 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3229 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3230 | // instead of `guard`. |
| 3231 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3232 | // at the point of the `HDeoptimize`. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3233 | HDeoptimize(ArenaAllocator* allocator, |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3234 | HInstruction* cond, |
| 3235 | HInstruction* guard, |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3236 | DeoptimizationKind kind, |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3237 | uint32_t dex_pc) |
| 3238 | : HVariableInputSizeInstruction( |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3239 | kDeoptimize, |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3240 | guard->GetType(), |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3241 | SideEffects::CanTriggerGC(), |
| 3242 | dex_pc, |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3243 | allocator, |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3244 | /* number_of_inputs */ 2, |
| 3245 | kArenaAllocMisc) { |
| 3246 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3247 | SetPackedField<DeoptimizeKindField>(kind); |
| 3248 | SetRawInputAt(0, cond); |
| 3249 | SetRawInputAt(1, guard); |
| Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3250 | } |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3251 | |
| 3252 | bool CanBeMoved() const OVERRIDE { return GetPackedFlag<kFieldCanBeMoved>(); } |
| 3253 | |
| 3254 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 3255 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3256 | } |
| 3257 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3258 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3259 | |
| Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 3260 | bool CanThrow() const OVERRIDE { return true; } |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3261 | |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3262 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3263 | |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3264 | bool GuardsAnInput() const { |
| 3265 | return InputCount() == 2; |
| 3266 | } |
| 3267 | |
| 3268 | HInstruction* GuardedInput() const { |
| 3269 | DCHECK(GuardsAnInput()); |
| 3270 | return InputAt(1); |
| 3271 | } |
| 3272 | |
| 3273 | void RemoveGuard() { |
| 3274 | RemoveInputAt(1); |
| 3275 | } |
| 3276 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3277 | DECLARE_INSTRUCTION(Deoptimize); |
| 3278 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3279 | protected: |
| 3280 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3281 | |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3282 | private: |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3283 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3284 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3285 | static constexpr size_t kFieldDeoptimizeKindSize = |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3286 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
| Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3287 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3288 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3289 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3290 | "Too many packed fields."); |
| Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3291 | using DeoptimizeKindField = |
| 3292 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3293 | }; |
| 3294 | |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3295 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3296 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3297 | // if it's true, starts to do deoptimization. |
| 3298 | // It has a 4-byte slot on stack. |
| 3299 | // TODO: allocate a register for this flag. |
| Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3300 | class HShouldDeoptimizeFlag FINAL : public HVariableInputSizeInstruction { |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3301 | public: |
| Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3302 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3303 | // with regard to other passes. |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3304 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3305 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3306 | DataType::Type::kInt32, |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3307 | SideEffects::None(), |
| 3308 | dex_pc, |
| 3309 | allocator, |
| 3310 | 0, |
| 3311 | kArenaAllocCHA) { |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
| Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3314 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3315 | // further guard elimination/motion since a guard might have been used for justification |
| 3316 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3317 | // to avoid other optimizations trying to move it. |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3318 | bool CanBeMoved() const OVERRIDE { return false; } |
| 3319 | |
| 3320 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3321 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3322 | protected: |
| 3323 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
| Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3324 | }; |
| 3325 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3326 | // Represents the ArtMethod that was passed as a first argument to |
| 3327 | // the method. It is used by instructions that depend on it, like |
| 3328 | // instructions that work with the dex cache. |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3329 | class HCurrentMethod FINAL : public HExpression<0> { |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3330 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3331 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3332 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3333 | } |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3334 | |
| 3335 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3336 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3337 | protected: |
| 3338 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3339 | }; |
| 3340 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3341 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3342 | // of a class. |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3343 | class HClassTableGet FINAL : public HExpression<1> { |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3344 | public: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3345 | enum class TableKind { |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3346 | kVTable, |
| 3347 | kIMTable, |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3348 | kLast = kIMTable |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3349 | }; |
| 3350 | HClassTableGet(HInstruction* cls, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3351 | DataType::Type type, |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3352 | TableKind kind, |
| 3353 | size_t index, |
| 3354 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3355 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3356 | index_(index) { |
| 3357 | SetPackedField<TableKindField>(kind); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3358 | SetRawInputAt(0, cls); |
| 3359 | } |
| 3360 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3361 | bool IsClonable() const OVERRIDE { return true; } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3362 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3363 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3364 | return other->AsClassTableGet()->GetIndex() == index_ && |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3365 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3366 | } |
| 3367 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3368 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3369 | size_t GetIndex() const { return index_; } |
| 3370 | |
| 3371 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3372 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3373 | protected: |
| 3374 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3375 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3376 | private: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3377 | static constexpr size_t kFieldTableKind = kNumberOfGenericPackedBits; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3378 | static constexpr size_t kFieldTableKindSize = |
| 3379 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3380 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3381 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3382 | "Too many packed fields."); |
| 3383 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3384 | |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3385 | // The index of the ArtMethod in the table. |
| 3386 | const size_t index_; |
| Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3387 | }; |
| 3388 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3389 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3390 | // have one successor for each entry in the switch table, and the final successor |
| 3391 | // will be the block containing the next Dex opcode. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3392 | class HPackedSwitch FINAL : public HExpression<1> { |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3393 | public: |
| Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3394 | HPackedSwitch(int32_t start_value, |
| 3395 | uint32_t num_entries, |
| 3396 | HInstruction* input, |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3397 | uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3398 | : HExpression(kPackedSwitch, SideEffects::None(), dex_pc), |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3399 | start_value_(start_value), |
| 3400 | num_entries_(num_entries) { |
| 3401 | SetRawInputAt(0, input); |
| 3402 | } |
| 3403 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3404 | bool IsClonable() const OVERRIDE { return true; } |
| 3405 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3406 | bool IsControlFlow() const OVERRIDE { return true; } |
| 3407 | |
| 3408 | int32_t GetStartValue() const { return start_value_; } |
| 3409 | |
| Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3410 | uint32_t GetNumEntries() const { return num_entries_; } |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3411 | |
| 3412 | HBasicBlock* GetDefaultBlock() const { |
| 3413 | // Last entry is the default block. |
| Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3414 | return GetBlock()->GetSuccessors()[num_entries_]; |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3415 | } |
| 3416 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3417 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3418 | protected: |
| 3419 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3420 | |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3421 | private: |
| Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3422 | const int32_t start_value_; |
| 3423 | const uint32_t num_entries_; |
| Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3424 | }; |
| 3425 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3426 | class HUnaryOperation : public HExpression<1> { |
| 3427 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3428 | HUnaryOperation(InstructionKind kind, |
| 3429 | DataType::Type result_type, |
| 3430 | HInstruction* input, |
| 3431 | uint32_t dex_pc = kNoDexPc) |
| 3432 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3433 | SetRawInputAt(0, input); |
| 3434 | } |
| 3435 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3436 | // All of the UnaryOperation instructions are clonable. |
| 3437 | bool IsClonable() const OVERRIDE { return true; } |
| 3438 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3439 | HInstruction* GetInput() const { return InputAt(0); } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3440 | DataType::Type GetResultType() const { return GetType(); } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3441 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3442 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3443 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3444 | return true; |
| 3445 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3446 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3447 | // Try to statically evaluate `this` and return a HConstant |
| 3448 | // containing the result of this evaluation. If `this` cannot |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3449 | // be evaluated as a constant, return null. |
| Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3450 | HConstant* TryStaticEvaluation() const; |
| 3451 | |
| 3452 | // Apply this operation to `x`. |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3453 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3454 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3455 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3456 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
| Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3457 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3458 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3459 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3460 | protected: |
| 3461 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3462 | }; |
| 3463 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3464 | class HBinaryOperation : public HExpression<2> { |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3465 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3466 | HBinaryOperation(InstructionKind kind, |
| 3467 | DataType::Type result_type, |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3468 | HInstruction* left, |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3469 | HInstruction* right, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3470 | SideEffects side_effects = SideEffects::None(), |
| 3471 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3472 | : HExpression(kind, result_type, side_effects, dex_pc) { |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3473 | SetRawInputAt(0, left); |
| 3474 | SetRawInputAt(1, right); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3477 | // All of the BinaryOperation instructions are clonable. |
| 3478 | bool IsClonable() const OVERRIDE { return true; } |
| 3479 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3480 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3481 | HInstruction* GetRight() const { return InputAt(1); } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3482 | DataType::Type GetResultType() const { return GetType(); } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3483 | |
| Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3484 | virtual bool IsCommutative() const { return false; } |
| 3485 | |
| 3486 | // Put constant on the right. |
| 3487 | // Returns whether order is changed. |
| 3488 | bool OrderInputsWithConstantOnTheRight() { |
| 3489 | HInstruction* left = InputAt(0); |
| 3490 | HInstruction* right = InputAt(1); |
| 3491 | if (left->IsConstant() && !right->IsConstant()) { |
| 3492 | ReplaceInput(right, 0); |
| 3493 | ReplaceInput(left, 1); |
| 3494 | return true; |
| 3495 | } |
| 3496 | return false; |
| 3497 | } |
| 3498 | |
| 3499 | // Order inputs by instruction id, but favor constant on the right side. |
| 3500 | // This helps GVN for commutative ops. |
| 3501 | void OrderInputs() { |
| 3502 | DCHECK(IsCommutative()); |
| 3503 | HInstruction* left = InputAt(0); |
| 3504 | HInstruction* right = InputAt(1); |
| 3505 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3506 | return; |
| 3507 | } |
| 3508 | if (OrderInputsWithConstantOnTheRight()) { |
| 3509 | return; |
| 3510 | } |
| 3511 | // Order according to instruction id. |
| 3512 | if (left->GetId() > right->GetId()) { |
| 3513 | ReplaceInput(right, 0); |
| 3514 | ReplaceInput(left, 1); |
| 3515 | } |
| 3516 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3517 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3518 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3519 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3520 | return true; |
| 3521 | } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3522 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3523 | // Try to statically evaluate `this` and return a HConstant |
| 3524 | // containing the result of this evaluation. If `this` cannot |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3525 | // be evaluated as a constant, return null. |
| Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3526 | HConstant* TryStaticEvaluation() const; |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3527 | |
| 3528 | // Apply this operation to `x` and `y`. |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3529 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3530 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
| Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3531 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3532 | UNREACHABLE(); |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3533 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3534 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3535 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3536 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3537 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3538 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3539 | UNREACHABLE(); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3540 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3541 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3542 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3543 | |
| Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3544 | // 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] | 3545 | // constant, or null. |
| Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3546 | HConstant* GetConstantRight() const; |
| 3547 | |
| 3548 | // If `GetConstantRight()` returns one of the input, this returns the other |
| Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3549 | // one. Otherwise it returns null. |
| Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3550 | HInstruction* GetLeastConstantLeft() const; |
| 3551 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3552 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
| Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3553 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3554 | protected: |
| 3555 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3556 | }; |
| 3557 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3558 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3559 | // comparisons are treated: |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3560 | enum class ComparisonBias { |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3561 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3562 | kGtBias, // return 1 for NaN comparisons |
| 3563 | kLtBias, // return -1 for NaN comparisons |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3564 | kLast = kLtBias |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3565 | }; |
| 3566 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3567 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3568 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3569 | class HCondition : public HBinaryOperation { |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3570 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3571 | HCondition(InstructionKind kind, |
| 3572 | HInstruction* first, |
| 3573 | HInstruction* second, |
| 3574 | uint32_t dex_pc = kNoDexPc) |
| 3575 | : HBinaryOperation(kind, |
| 3576 | DataType::Type::kBool, |
| 3577 | first, |
| 3578 | second, |
| 3579 | SideEffects::None(), |
| 3580 | dex_pc) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3581 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3582 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3583 | |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3584 | // For code generation purposes, returns whether this instruction is just before |
| Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3585 | // `instruction`, and disregard moves in between. |
| 3586 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
| Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3587 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3588 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3589 | |
| 3590 | virtual IfCondition GetCondition() const = 0; |
| 3591 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3592 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3593 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3594 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
| Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3595 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3596 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3597 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3598 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3599 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 3600 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3601 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3602 | } |
| 3603 | |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3604 | bool IsFPConditionTrueIfNaN() const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3605 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3606 | IfCondition if_cond = GetCondition(); |
| Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3607 | if (if_cond == kCondNE) { |
| 3608 | return true; |
| 3609 | } else if (if_cond == kCondEQ) { |
| 3610 | return false; |
| 3611 | } |
| 3612 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3613 | } |
| 3614 | |
| 3615 | bool IsFPConditionFalseIfNaN() const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3616 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3617 | IfCondition if_cond = GetCondition(); |
| Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3618 | if (if_cond == kCondEQ) { |
| 3619 | return true; |
| 3620 | } else if (if_cond == kCondNE) { |
| 3621 | return false; |
| 3622 | } |
| 3623 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
| Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3624 | } |
| 3625 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3626 | protected: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3627 | // Needed if we merge a HCompare into a HCondition. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3628 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3629 | static constexpr size_t kFieldComparisonBiasSize = |
| 3630 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3631 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3632 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3633 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3634 | using ComparisonBiasField = |
| 3635 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3636 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3637 | template <typename T> |
| 3638 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3639 | |
| 3640 | template <typename T> |
| 3641 | int32_t CompareFP(T x, T y) const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3642 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3643 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3644 | // Handle the bias. |
| 3645 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3646 | } |
| 3647 | |
| 3648 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3649 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3650 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3651 | } |
| 3652 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3653 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3654 | }; |
| 3655 | |
| 3656 | // Instruction to check if two inputs are equal to each other. |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3657 | class HEqual FINAL : public HCondition { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3658 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3659 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3660 | : HCondition(kEqual, first, second, dex_pc) { |
| 3661 | } |
| Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3662 | |
| Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3663 | bool IsCommutative() const OVERRIDE { return true; } |
| 3664 | |
| Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3665 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3666 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3667 | return MakeConstantCondition(true, GetDexPc()); |
| 3668 | } |
| 3669 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3670 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3671 | } |
| 3672 | // In the following Evaluate methods, a HCompare instruction has |
| 3673 | // been merged into this HEqual instruction; evaluate it as |
| 3674 | // `Compare(x, y) == 0`. |
| 3675 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3676 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3677 | GetDexPc()); |
| 3678 | } |
| 3679 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3680 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3681 | } |
| 3682 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3683 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3684 | } |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3685 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3686 | DECLARE_INSTRUCTION(Equal); |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3687 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3688 | IfCondition GetCondition() const OVERRIDE { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3689 | return kCondEQ; |
| 3690 | } |
| 3691 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3692 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3693 | return kCondNE; |
| 3694 | } |
| 3695 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3696 | protected: |
| 3697 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 3698 | |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3699 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3700 | template <typename T> static bool Compute(T x, T y) { return x == y; } |
| Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3701 | }; |
| 3702 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3703 | class HNotEqual FINAL : public HCondition { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3704 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3705 | HNotEqual(HInstruction* first, HInstruction* second, |
| 3706 | uint32_t dex_pc = kNoDexPc) |
| 3707 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 3708 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3709 | |
| Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3710 | bool IsCommutative() const OVERRIDE { return true; } |
| 3711 | |
| Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3712 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3713 | HNullConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3714 | return MakeConstantCondition(false, GetDexPc()); |
| 3715 | } |
| 3716 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3717 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3718 | } |
| 3719 | // In the following Evaluate methods, a HCompare instruction has |
| 3720 | // been merged into this HNotEqual instruction; evaluate it as |
| 3721 | // `Compare(x, y) != 0`. |
| 3722 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3723 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3724 | } |
| 3725 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3726 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3727 | } |
| 3728 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3729 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3730 | } |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3731 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3732 | DECLARE_INSTRUCTION(NotEqual); |
| 3733 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3734 | IfCondition GetCondition() const OVERRIDE { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3735 | return kCondNE; |
| 3736 | } |
| 3737 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3738 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3739 | return kCondEQ; |
| 3740 | } |
| 3741 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3742 | protected: |
| 3743 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 3744 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3745 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3746 | template <typename T> static bool Compute(T x, T y) { return x != y; } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3747 | }; |
| 3748 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3749 | class HLessThan FINAL : public HCondition { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3750 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3751 | HLessThan(HInstruction* first, HInstruction* second, |
| 3752 | uint32_t dex_pc = kNoDexPc) |
| 3753 | : HCondition(kLessThan, first, second, dex_pc) { |
| 3754 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3755 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3756 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3757 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3758 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3759 | // In the following Evaluate methods, a HCompare instruction has |
| 3760 | // been merged into this HLessThan instruction; evaluate it as |
| 3761 | // `Compare(x, y) < 0`. |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3762 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3763 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3764 | } |
| 3765 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3766 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3767 | } |
| 3768 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3769 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3770 | } |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3771 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3772 | DECLARE_INSTRUCTION(LessThan); |
| 3773 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3774 | IfCondition GetCondition() const OVERRIDE { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3775 | return kCondLT; |
| 3776 | } |
| 3777 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3778 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3779 | return kCondGE; |
| 3780 | } |
| 3781 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3782 | protected: |
| 3783 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 3784 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3785 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3786 | template <typename T> static bool Compute(T x, T y) { return x < y; } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3787 | }; |
| 3788 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3789 | class HLessThanOrEqual FINAL : public HCondition { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3790 | public: |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3791 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 3792 | uint32_t dex_pc = kNoDexPc) |
| 3793 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 3794 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3795 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3796 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3797 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3798 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3799 | // In the following Evaluate methods, a HCompare instruction has |
| 3800 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3801 | // `Compare(x, y) <= 0`. |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3802 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3803 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3804 | } |
| 3805 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3806 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3807 | } |
| 3808 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3809 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3810 | } |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3811 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3812 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3813 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3814 | IfCondition GetCondition() const OVERRIDE { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3815 | return kCondLE; |
| 3816 | } |
| 3817 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3818 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3819 | return kCondGT; |
| 3820 | } |
| 3821 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3822 | protected: |
| 3823 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 3824 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3825 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3826 | template <typename T> static bool Compute(T x, T y) { return x <= y; } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3827 | }; |
| 3828 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3829 | class HGreaterThan FINAL : public HCondition { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3830 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3831 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3832 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 3833 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3834 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3835 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3836 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3837 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3838 | // In the following Evaluate methods, a HCompare instruction has |
| 3839 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3840 | // `Compare(x, y) > 0`. |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3841 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3842 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3843 | } |
| 3844 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3845 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3846 | } |
| 3847 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3848 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3849 | } |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3850 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3851 | DECLARE_INSTRUCTION(GreaterThan); |
| 3852 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3853 | IfCondition GetCondition() const OVERRIDE { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3854 | return kCondGT; |
| 3855 | } |
| 3856 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3857 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3858 | return kCondLE; |
| 3859 | } |
| 3860 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3861 | protected: |
| 3862 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 3863 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3864 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3865 | template <typename T> static bool Compute(T x, T y) { return x > y; } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3866 | }; |
| 3867 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3868 | class HGreaterThanOrEqual FINAL : public HCondition { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3869 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3870 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3871 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 3872 | } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3873 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3874 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3875 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3876 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3877 | // In the following Evaluate methods, a HCompare instruction has |
| 3878 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3879 | // `Compare(x, y) >= 0`. |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3880 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3881 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3882 | } |
| 3883 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 3884 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3885 | } |
| 3886 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 3887 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3888 | } |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3889 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3890 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3891 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3892 | IfCondition GetCondition() const OVERRIDE { |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3893 | return kCondGE; |
| 3894 | } |
| 3895 | |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3896 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3897 | return kCondLT; |
| 3898 | } |
| 3899 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3900 | protected: |
| 3901 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 3902 | |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3903 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3904 | template <typename T> static bool Compute(T x, T y) { return x >= y; } |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3905 | }; |
| 3906 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3907 | class HBelow FINAL : public HCondition { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3908 | public: |
| 3909 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3910 | : HCondition(kBelow, first, second, dex_pc) { |
| 3911 | } |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3912 | |
| 3913 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3914 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3915 | } |
| 3916 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3917 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3918 | } |
| 3919 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3920 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3921 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3922 | UNREACHABLE(); |
| 3923 | } |
| 3924 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3925 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3926 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3927 | UNREACHABLE(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3928 | } |
| 3929 | |
| 3930 | DECLARE_INSTRUCTION(Below); |
| 3931 | |
| 3932 | IfCondition GetCondition() const OVERRIDE { |
| 3933 | return kCondB; |
| 3934 | } |
| 3935 | |
| 3936 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3937 | return kCondAE; |
| 3938 | } |
| 3939 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3940 | protected: |
| 3941 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 3942 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3943 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3944 | template <typename T> static bool Compute(T x, T y) { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3945 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3946 | } |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3947 | }; |
| 3948 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3949 | class HBelowOrEqual FINAL : public HCondition { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3950 | public: |
| 3951 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3952 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 3953 | } |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3954 | |
| 3955 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3956 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3957 | } |
| 3958 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3959 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3960 | } |
| 3961 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 3962 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3963 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3964 | UNREACHABLE(); |
| 3965 | } |
| 3966 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 3967 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3968 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3969 | UNREACHABLE(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3970 | } |
| 3971 | |
| 3972 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3973 | |
| 3974 | IfCondition GetCondition() const OVERRIDE { |
| 3975 | return kCondBE; |
| 3976 | } |
| 3977 | |
| 3978 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 3979 | return kCondA; |
| 3980 | } |
| 3981 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3982 | protected: |
| 3983 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 3984 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3985 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3986 | template <typename T> static bool Compute(T x, T y) { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3987 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 3988 | } |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3989 | }; |
| 3990 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 3991 | class HAbove FINAL : public HCondition { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3992 | public: |
| 3993 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3994 | : HCondition(kAbove, first, second, dex_pc) { |
| 3995 | } |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3996 | |
| 3997 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3998 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3999 | } |
| 4000 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4001 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4002 | } |
| 4003 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4004 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4005 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4006 | UNREACHABLE(); |
| 4007 | } |
| 4008 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4009 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4010 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4011 | UNREACHABLE(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4012 | } |
| 4013 | |
| 4014 | DECLARE_INSTRUCTION(Above); |
| 4015 | |
| 4016 | IfCondition GetCondition() const OVERRIDE { |
| 4017 | return kCondA; |
| 4018 | } |
| 4019 | |
| 4020 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 4021 | return kCondBE; |
| 4022 | } |
| 4023 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4024 | protected: |
| 4025 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 4026 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4027 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4028 | template <typename T> static bool Compute(T x, T y) { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4029 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4030 | } |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4031 | }; |
| 4032 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4033 | class HAboveOrEqual FINAL : public HCondition { |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4034 | public: |
| 4035 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4036 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4037 | } |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4038 | |
| 4039 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4040 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4041 | } |
| 4042 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4043 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4044 | } |
| 4045 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 4046 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4047 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4048 | UNREACHABLE(); |
| 4049 | } |
| 4050 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 4051 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4052 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4053 | UNREACHABLE(); |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4057 | |
| 4058 | IfCondition GetCondition() const OVERRIDE { |
| 4059 | return kCondAE; |
| 4060 | } |
| 4061 | |
| 4062 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 4063 | return kCondB; |
| 4064 | } |
| 4065 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4066 | protected: |
| 4067 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4068 | |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4069 | private: |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4070 | template <typename T> static bool Compute(T x, T y) { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4071 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4072 | } |
| Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4073 | }; |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4074 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4075 | // Instruction to check how two inputs compare to each other. |
| 4076 | // 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] | 4077 | class HCompare FINAL : public HBinaryOperation { |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4078 | public: |
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4079 | // Note that `comparison_type` is the type of comparison performed |
| 4080 | // between the comparison's inputs, not the type of the instantiated |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4081 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4082 | HCompare(DataType::Type comparison_type, |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4083 | HInstruction* first, |
| 4084 | HInstruction* second, |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4085 | ComparisonBias bias, |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4086 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4087 | : HBinaryOperation(kCompare, |
| 4088 | DataType::Type::kInt32, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4089 | first, |
| 4090 | second, |
| Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4091 | SideEffectsForArchRuntimeCalls(comparison_type), |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4092 | dex_pc) { |
| 4093 | SetPackedField<ComparisonBiasField>(bias); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4094 | DCHECK_EQ(comparison_type, DataType::Kind(first->GetType())); |
| 4095 | DCHECK_EQ(comparison_type, DataType::Kind(second->GetType())); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4096 | } |
| 4097 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4098 | template <typename T> |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4099 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4100 | |
| 4101 | template <typename T> |
| 4102 | int32_t ComputeFP(T x, T y) const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4103 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4104 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4105 | // Handle the bias. |
| 4106 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4107 | } |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4108 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4109 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4110 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4111 | // reach this code path when processing a freshly built HIR |
| 4112 | // graph. However HCompare integer instructions can be synthesized |
| 4113 | // by the instruction simplifier to implement IntegerCompare and |
| 4114 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4115 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4116 | } |
| 4117 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4118 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4119 | } |
| 4120 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4121 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4122 | } |
| 4123 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4124 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4125 | } |
| 4126 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4127 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4128 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
| Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4129 | } |
| 4130 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4131 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4132 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4133 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4134 | // Only meaningful for floating-point comparisons. |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4135 | bool IsGtBias() const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4136 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4137 | return GetBias() == ComparisonBias::kGtBias; |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4138 | } |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4139 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4140 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
| Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4141 | // Comparisons do not require a runtime call in any back end. |
| 4142 | return SideEffects::None(); |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4143 | } |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4144 | |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4145 | DECLARE_INSTRUCTION(Compare); |
| 4146 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4147 | protected: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4148 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4149 | static constexpr size_t kFieldComparisonBiasSize = |
| 4150 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4151 | static constexpr size_t kNumberOfComparePackedBits = |
| 4152 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4153 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4154 | using ComparisonBiasField = |
| 4155 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4156 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4157 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4158 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4159 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4160 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4161 | } |
| 4162 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4163 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
| Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4164 | }; |
| 4165 | |
| Nicolas Geoffray | 2b615ba | 2017-01-06 14:40:07 +0000 | [diff] [blame] | 4166 | class HNewInstance FINAL : public HExpression<1> { |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4167 | public: |
| 4168 | HNewInstance(HInstruction* cls, |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4169 | uint32_t dex_pc, |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4170 | dex::TypeIndex type_index, |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4171 | const DexFile& dex_file, |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4172 | bool finalizable, |
| 4173 | QuickEntrypointEnum entrypoint) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4174 | : HExpression(kNewInstance, |
| 4175 | DataType::Type::kReference, |
| 4176 | SideEffects::CanTriggerGC(), |
| 4177 | dex_pc), |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4178 | type_index_(type_index), |
| 4179 | dex_file_(dex_file), |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4180 | entrypoint_(entrypoint) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4181 | SetPackedFlag<kFlagFinalizable>(finalizable); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4182 | SetRawInputAt(0, cls); |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4183 | } |
| 4184 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4185 | bool IsClonable() const OVERRIDE { return true; } |
| 4186 | |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4187 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4188 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4189 | |
| 4190 | // Calls runtime so needs an environment. |
| 4191 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4192 | |
| Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4193 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
| 4194 | bool CanThrow() const OVERRIDE { return true; } |
| 4195 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4196 | bool NeedsChecks() const { |
| 4197 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4198 | } |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4199 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4200 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4201 | |
| 4202 | bool CanBeNull() const OVERRIDE { return false; } |
| 4203 | |
| 4204 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4205 | |
| 4206 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4207 | entrypoint_ = entrypoint; |
| 4208 | } |
| 4209 | |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4210 | HLoadClass* GetLoadClass() const { |
| 4211 | HInstruction* input = InputAt(0); |
| 4212 | if (input->IsClinitCheck()) { |
| 4213 | input = input->InputAt(0); |
| 4214 | } |
| 4215 | DCHECK(input->IsLoadClass()); |
| 4216 | return input->AsLoadClass(); |
| 4217 | } |
| 4218 | |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4219 | bool IsStringAlloc() const; |
| 4220 | |
| 4221 | DECLARE_INSTRUCTION(NewInstance); |
| 4222 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4223 | protected: |
| 4224 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4225 | |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4226 | private: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4227 | static constexpr size_t kFlagFinalizable = kNumberOfGenericPackedBits; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4228 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 4229 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4230 | "Too many packed fields."); |
| 4231 | |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4232 | const dex::TypeIndex type_index_; |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4233 | const DexFile& dex_file_; |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4234 | QuickEntrypointEnum entrypoint_; |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4235 | }; |
| 4236 | |
| Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 4237 | enum IntrinsicNeedsEnvironmentOrCache { |
| 4238 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 4239 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
| agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4240 | }; |
| 4241 | |
| Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4242 | enum IntrinsicSideEffects { |
| 4243 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4244 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4245 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4246 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4247 | }; |
| 4248 | |
| 4249 | enum IntrinsicExceptions { |
| 4250 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4251 | kCanThrow // Intrinsic may throw exceptions. |
| 4252 | }; |
| 4253 | |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4254 | class HInvoke : public HVariableInputSizeInstruction { |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4255 | public: |
| Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4256 | bool NeedsEnvironment() const OVERRIDE; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4257 | |
| Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4258 | void SetArgumentAt(size_t index, HInstruction* argument) { |
| Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4259 | SetRawInputAt(index, argument); |
| 4260 | } |
| 4261 | |
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4262 | // Return the number of arguments. This number can be lower than |
| 4263 | // the number of inputs returned by InputCount(), as some invoke |
| 4264 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4265 | // inputs at the end of their list of inputs. |
| 4266 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4267 | |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4268 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4269 | |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4270 | InvokeType GetInvokeType() const { |
| 4271 | return GetPackedField<InvokeTypeField>(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4272 | } |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4273 | |
| Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4274 | Intrinsics GetIntrinsic() const { |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4275 | return intrinsic_; |
| 4276 | } |
| 4277 | |
| Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4278 | void SetIntrinsic(Intrinsics intrinsic, |
| 4279 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4280 | IntrinsicSideEffects side_effects, |
| 4281 | IntrinsicExceptions exceptions); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4282 | |
| Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4283 | bool IsFromInlinedInvoke() const { |
| Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4284 | return GetEnvironment()->IsFromInlinedInvoke(); |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4285 | } |
| 4286 | |
| Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4287 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4288 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4289 | bool CanThrow() const OVERRIDE { return GetPackedFlag<kFlagCanThrow>(); } |
| Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4290 | |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4291 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4292 | |
| 4293 | bool AlwaysThrows() const OVERRIDE { return GetPackedFlag<kFlagAlwaysThrows>(); } |
| 4294 | |
| Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4295 | bool CanBeMoved() const OVERRIDE { return IsIntrinsic() && !DoesAnyWrite(); } |
| Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4296 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4297 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4298 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4299 | } |
| Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4300 | |
| Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4301 | uint32_t* GetIntrinsicOptimizations() { |
| 4302 | return &intrinsic_optimizations_; |
| 4303 | } |
| 4304 | |
| 4305 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4306 | return &intrinsic_optimizations_; |
| 4307 | } |
| 4308 | |
| 4309 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4310 | |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4311 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
| Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4312 | void SetResolvedMethod(ArtMethod* method) { resolved_method_ = method; } |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4313 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4314 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4315 | |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4316 | protected: |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4317 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4318 | static constexpr size_t kFieldInvokeTypeSize = |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4319 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4320 | static constexpr size_t kFlagCanThrow = kFieldInvokeType + kFieldInvokeTypeSize; |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4321 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4322 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4323 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4324 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4325 | |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4326 | HInvoke(InstructionKind kind, |
| 4327 | ArenaAllocator* allocator, |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4328 | uint32_t number_of_arguments, |
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4329 | uint32_t number_of_other_inputs, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4330 | DataType::Type return_type, |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4331 | uint32_t dex_pc, |
| Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4332 | uint32_t dex_method_index, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4333 | ArtMethod* resolved_method, |
| 4334 | InvokeType invoke_type) |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4335 | : HVariableInputSizeInstruction( |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4336 | kind, |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4337 | return_type, |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4338 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4339 | dex_pc, |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4340 | allocator, |
| Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4341 | number_of_arguments + number_of_other_inputs, |
| 4342 | kArenaAllocInvokeInputs), |
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4343 | number_of_arguments_(number_of_arguments), |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4344 | resolved_method_(resolved_method), |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4345 | dex_method_index_(dex_method_index), |
| agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4346 | intrinsic_(Intrinsics::kNone), |
| Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4347 | intrinsic_optimizations_(0) { |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4348 | SetPackedField<InvokeTypeField>(invoke_type); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4349 | SetPackedFlag<kFlagCanThrow>(true); |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4350 | } |
| 4351 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4352 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4353 | |
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4354 | uint32_t number_of_arguments_; |
| Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4355 | ArtMethod* resolved_method_; |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4356 | const uint32_t dex_method_index_; |
| 4357 | Intrinsics intrinsic_; |
| Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4358 | |
| 4359 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4360 | uint32_t intrinsic_optimizations_; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4361 | }; |
| 4362 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4363 | class HInvokeUnresolved FINAL : public HInvoke { |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4364 | public: |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4365 | HInvokeUnresolved(ArenaAllocator* allocator, |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4366 | uint32_t number_of_arguments, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4367 | DataType::Type return_type, |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4368 | uint32_t dex_pc, |
| 4369 | uint32_t dex_method_index, |
| 4370 | InvokeType invoke_type) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4371 | : HInvoke(kInvokeUnresolved, |
| 4372 | allocator, |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4373 | number_of_arguments, |
| 4374 | 0u /* number_of_other_inputs */, |
| 4375 | return_type, |
| 4376 | dex_pc, |
| 4377 | dex_method_index, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4378 | nullptr, |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4379 | invoke_type) { |
| 4380 | } |
| 4381 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4382 | bool IsClonable() const OVERRIDE { return true; } |
| 4383 | |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4384 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4385 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4386 | protected: |
| 4387 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
| Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4388 | }; |
| 4389 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4390 | class HInvokePolymorphic FINAL : public HInvoke { |
| 4391 | public: |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4392 | HInvokePolymorphic(ArenaAllocator* allocator, |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4393 | uint32_t number_of_arguments, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4394 | DataType::Type return_type, |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4395 | uint32_t dex_pc, |
| 4396 | uint32_t dex_method_index) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4397 | : HInvoke(kInvokePolymorphic, |
| 4398 | allocator, |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4399 | number_of_arguments, |
| 4400 | 0u /* number_of_other_inputs */, |
| 4401 | return_type, |
| 4402 | dex_pc, |
| 4403 | dex_method_index, |
| 4404 | nullptr, |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4405 | kVirtual) { |
| 4406 | } |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4407 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4408 | bool IsClonable() const OVERRIDE { return true; } |
| 4409 | |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4410 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4411 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4412 | protected: |
| 4413 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
| Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4414 | }; |
| 4415 | |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4416 | class HInvokeCustom FINAL : public HInvoke { |
| 4417 | public: |
| 4418 | HInvokeCustom(ArenaAllocator* allocator, |
| 4419 | uint32_t number_of_arguments, |
| 4420 | uint32_t call_site_index, |
| 4421 | DataType::Type return_type, |
| 4422 | uint32_t dex_pc) |
| 4423 | : HInvoke(kInvokeCustom, |
| 4424 | allocator, |
| 4425 | number_of_arguments, |
| 4426 | /* number_of_other_inputs */ 0u, |
| 4427 | return_type, |
| 4428 | dex_pc, |
| 4429 | /* dex_method_index */ dex::kDexNoIndex, |
| 4430 | /* resolved_method */ nullptr, |
| 4431 | kStatic), |
| 4432 | call_site_index_(call_site_index) { |
| 4433 | } |
| 4434 | |
| 4435 | uint32_t GetCallSiteIndex() const { return call_site_index_; } |
| 4436 | |
| 4437 | bool IsClonable() const OVERRIDE { return true; } |
| 4438 | |
| 4439 | DECLARE_INSTRUCTION(InvokeCustom); |
| 4440 | |
| 4441 | protected: |
| 4442 | DEFAULT_COPY_CONSTRUCTOR(InvokeCustom); |
| 4443 | |
| 4444 | private: |
| 4445 | uint32_t call_site_index_; |
| 4446 | }; |
| 4447 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4448 | class HInvokeStaticOrDirect FINAL : public HInvoke { |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4449 | public: |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4450 | // Requirements of this method call regarding the class |
| 4451 | // initialization (clinit) check of its declaring class. |
| 4452 | enum class ClinitCheckRequirement { |
| 4453 | kNone, // Class already initialized. |
| 4454 | kExplicit, // Static call having explicit clinit check as last input. |
| 4455 | kImplicit, // Static call implicitly requiring a clinit check. |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4456 | kLast = kImplicit |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4457 | }; |
| 4458 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4459 | // Determines how to load the target ArtMethod*. |
| 4460 | enum class MethodLoadKind { |
| 4461 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4462 | kStringInit, |
| 4463 | |
| 4464 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4465 | kRecursive, |
| 4466 | |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4467 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4468 | // Used for boot image methods referenced by boot image code. |
| 4469 | kBootImageLinkTimePcRelative, |
| 4470 | |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4471 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 4472 | // Used for app->boot calls with relocatable image. |
| 4473 | kBootImageRelRo, |
| 4474 | |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4475 | // Load from an entry in the .bss section using a PC-relative load. |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4476 | // Used for methods outside boot image referenced by AOT-compiled app and boot image code. |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4477 | kBssEntry, |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4478 | |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4479 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4480 | // Used for for JIT-compiled calls. |
| 4481 | kJitDirectAddress, |
| 4482 | |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4483 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4484 | // used when other kinds are unimplemented on a particular architecture. |
| 4485 | kRuntimeCall, |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4486 | }; |
| 4487 | |
| 4488 | // Determines the location of the code pointer. |
| 4489 | enum class CodePtrLocation { |
| 4490 | // Recursive call, use local PC-relative call instruction. |
| 4491 | kCallSelf, |
| 4492 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4493 | // Use code pointer from the ArtMethod*. |
| 4494 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4495 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4496 | kCallArtMethod, |
| 4497 | }; |
| 4498 | |
| 4499 | struct DispatchInfo { |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4500 | MethodLoadKind method_load_kind; |
| 4501 | CodePtrLocation code_ptr_location; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4502 | // The method load data holds |
| 4503 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4504 | // Note that there are multiple string init methods, each having its own offset. |
| 4505 | // - the method address for kDirectAddress |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4506 | uint64_t method_load_data; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4507 | }; |
| 4508 | |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4509 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4510 | uint32_t number_of_arguments, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4511 | DataType::Type return_type, |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4512 | uint32_t dex_pc, |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4513 | uint32_t method_index, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4514 | ArtMethod* resolved_method, |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4515 | DispatchInfo dispatch_info, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4516 | InvokeType invoke_type, |
| 4517 | MethodReference target_method, |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4518 | ClinitCheckRequirement clinit_check_requirement) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4519 | : HInvoke(kInvokeStaticOrDirect, |
| 4520 | allocator, |
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4521 | number_of_arguments, |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4522 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4523 | // potentially one other if the clinit check is explicit, and potentially |
| 4524 | // one other if the method is a string factory. |
| 4525 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
| David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4526 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
| Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4527 | return_type, |
| 4528 | dex_pc, |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4529 | method_index, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4530 | resolved_method, |
| 4531 | invoke_type), |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4532 | target_method_(target_method), |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4533 | dispatch_info_(dispatch_info) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4534 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4535 | } |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4536 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4537 | bool IsClonable() const OVERRIDE { return true; } |
| 4538 | |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4539 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4540 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4541 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4542 | |
| 4543 | // Using the current method is the default and once we find a better |
| 4544 | // method load kind, we should not go back to using the current method. |
| 4545 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4546 | |
| 4547 | if (had_current_method_input && !needs_current_method_input) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4548 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4549 | RemoveInputAt(GetSpecialInputIndex()); |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4550 | } |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4551 | dispatch_info_ = dispatch_info; |
| 4552 | } |
| 4553 | |
| Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4554 | DispatchInfo GetDispatchInfo() const { |
| 4555 | return dispatch_info_; |
| 4556 | } |
| 4557 | |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4558 | void AddSpecialInput(HInstruction* input) { |
| 4559 | // We allow only one special input. |
| 4560 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4561 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4562 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4563 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4564 | } |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4565 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4566 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 4567 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE { |
| 4568 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4569 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4570 | DCHECK(!input_records.empty()); |
| 4571 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4572 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4573 | // Note: `last_input` may be null during arguments setup. |
| 4574 | if (last_input != nullptr) { |
| 4575 | // `last_input` is the last input of a static invoke marked as having |
| 4576 | // an explicit clinit check. It must either be: |
| 4577 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4578 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4579 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4580 | } |
| 4581 | } |
| 4582 | return input_records; |
| 4583 | } |
| 4584 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4585 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4586 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4587 | // TODO: for intrinsics we can generate implicit null checks. |
| 4588 | return false; |
| 4589 | } |
| 4590 | |
| Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4591 | bool CanBeNull() const OVERRIDE { |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4592 | return GetType() == DataType::Type::kReference && !IsStringInit(); |
| Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4593 | } |
| 4594 | |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4595 | // Get the index of the special input, if any. |
| 4596 | // |
| David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4597 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4598 | // method pointer; otherwise there may be one platform-specific special input, |
| 4599 | // such as PC-relative addressing base. |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4600 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
| Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4601 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4602 | |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4603 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4604 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4605 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
| Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4606 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4607 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4608 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kJitDirectAddress; } |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4609 | bool HasPcRelativeMethodLoadKind() const { |
| 4610 | return GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4611 | GetMethodLoadKind() == MethodLoadKind::kBootImageRelRo || |
| Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4612 | GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
| Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4613 | } |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4614 | bool HasCurrentMethodInput() const { |
| 4615 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4616 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4617 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4618 | return true; |
| 4619 | } else { |
| Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4620 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4621 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4622 | return false; |
| 4623 | } |
| 4624 | } |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4625 | |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4626 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4627 | DCHECK(IsStringInit()); |
| Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4628 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
| 4631 | uint64_t GetMethodAddress() const { |
| 4632 | DCHECK(HasMethodAddress()); |
| 4633 | return dispatch_info_.method_load_data; |
| 4634 | } |
| 4635 | |
| Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4636 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4637 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4638 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4639 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4640 | } |
| Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4641 | |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4642 | // Is this instruction a call to a static method? |
| 4643 | bool IsStatic() const { |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4644 | return GetInvokeType() == kStatic; |
| 4645 | } |
| 4646 | |
| 4647 | MethodReference GetTargetMethod() const { |
| 4648 | return target_method_; |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4649 | } |
| 4650 | |
| Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4651 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4652 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4653 | // instruction; only relevant for static calls with explicit clinit check. |
| 4654 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4655 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4656 | size_t last_input_index = inputs_.size() - 1u; |
| 4657 | HInstruction* last_input = inputs_.back().GetInstruction(); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4658 | DCHECK(last_input != nullptr); |
| Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4659 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4660 | RemoveAsUserOfInput(last_input_index); |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4661 | inputs_.pop_back(); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4662 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
| Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4663 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4664 | } |
| 4665 | |
| 4666 | // 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] | 4667 | // explicit initialization check in the graph? |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4668 | bool IsStaticWithExplicitClinitCheck() const { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4669 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | // Is this a call to a static method whose declaring class has an |
| 4673 | // implicit intialization check requirement? |
| 4674 | bool IsStaticWithImplicitClinitCheck() const { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4675 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
| Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4676 | } |
| 4677 | |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4678 | // Does this method load kind need the current method as an input? |
| 4679 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
| Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4680 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kRuntimeCall; |
| Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4681 | } |
| 4682 | |
| Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4683 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4684 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4685 | protected: |
| 4686 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 4687 | |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4688 | private: |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4689 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4690 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4691 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4692 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4693 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4694 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4695 | "Too many packed fields."); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4696 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4697 | kFieldClinitCheckRequirement, |
| 4698 | kFieldClinitCheckRequirementSize>; |
| 4699 | |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4700 | // Cached values of the resolved method, to avoid needing the mutator lock. |
| Nicolas Geoffray | ea179f4 | 2018-02-08 22:30:18 +0000 | [diff] [blame] | 4701 | const MethodReference target_method_; |
| Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4702 | DispatchInfo dispatch_info_; |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4703 | }; |
| Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4704 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
| Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4705 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
| Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4706 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4707 | class HInvokeVirtual FINAL : public HInvoke { |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4708 | public: |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4709 | HInvokeVirtual(ArenaAllocator* allocator, |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4710 | uint32_t number_of_arguments, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4711 | DataType::Type return_type, |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4712 | uint32_t dex_pc, |
| Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4713 | uint32_t dex_method_index, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4714 | ArtMethod* resolved_method, |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4715 | uint32_t vtable_index) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4716 | : HInvoke(kInvokeVirtual, |
| 4717 | allocator, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4718 | number_of_arguments, |
| 4719 | 0u, |
| 4720 | return_type, |
| 4721 | dex_pc, |
| 4722 | dex_method_index, |
| 4723 | resolved_method, |
| 4724 | kVirtual), |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4725 | vtable_index_(vtable_index) { |
| 4726 | } |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4727 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4728 | bool IsClonable() const OVERRIDE { return true; } |
| 4729 | |
| Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4730 | bool CanBeNull() const OVERRIDE { |
| 4731 | switch (GetIntrinsic()) { |
| 4732 | case Intrinsics::kThreadCurrentThread: |
| 4733 | case Intrinsics::kStringBufferAppend: |
| 4734 | case Intrinsics::kStringBufferToString: |
| 4735 | case Intrinsics::kStringBuilderAppend: |
| 4736 | case Intrinsics::kStringBuilderToString: |
| 4737 | return false; |
| 4738 | default: |
| 4739 | return HInvoke::CanBeNull(); |
| 4740 | } |
| 4741 | } |
| 4742 | |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4743 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4744 | // TODO: Add implicit null checks in intrinsics. |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4745 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4748 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4749 | |
| 4750 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4751 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4752 | protected: |
| 4753 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 4754 | |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4755 | private: |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4756 | // Cached value of the resolved method, to avoid needing the mutator lock. |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4757 | const uint32_t vtable_index_; |
| Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4758 | }; |
| 4759 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4760 | class HInvokeInterface FINAL : public HInvoke { |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4761 | public: |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4762 | HInvokeInterface(ArenaAllocator* allocator, |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4763 | uint32_t number_of_arguments, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4764 | DataType::Type return_type, |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4765 | uint32_t dex_pc, |
| 4766 | uint32_t dex_method_index, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4767 | ArtMethod* resolved_method, |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4768 | uint32_t imt_index) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4769 | : HInvoke(kInvokeInterface, |
| 4770 | allocator, |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4771 | number_of_arguments, |
| 4772 | 0u, |
| 4773 | return_type, |
| 4774 | dex_pc, |
| 4775 | dex_method_index, |
| 4776 | resolved_method, |
| 4777 | kInterface), |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4778 | imt_index_(imt_index) { |
| 4779 | } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4780 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4781 | bool IsClonable() const OVERRIDE { return true; } |
| 4782 | |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4783 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4784 | // TODO: Add implicit null checks in intrinsics. |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4785 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4786 | } |
| 4787 | |
| Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4788 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| 4789 | // The assembly stub currently needs it. |
| 4790 | return true; |
| 4791 | } |
| 4792 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4793 | uint32_t GetImtIndex() const { return imt_index_; } |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4794 | |
| 4795 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4796 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4797 | protected: |
| 4798 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 4799 | |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4800 | private: |
| Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4801 | // Cached value of the resolved method, to avoid needing the mutator lock. |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4802 | const uint32_t imt_index_; |
| Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4803 | }; |
| 4804 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4805 | class HNeg FINAL : public HUnaryOperation { |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4806 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4807 | HNeg(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4808 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4809 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
| Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4810 | } |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4811 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4812 | template <typename T> static T Compute(T x) { return -x; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4813 | |
| 4814 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4815 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4816 | } |
| 4817 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4818 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4819 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4820 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 4821 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4822 | } |
| 4823 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 4824 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4825 | } |
| Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4826 | |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4827 | DECLARE_INSTRUCTION(Neg); |
| 4828 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4829 | protected: |
| 4830 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
| Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4831 | }; |
| 4832 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4833 | class HNewArray FINAL : public HExpression<2> { |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4834 | public: |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4835 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4836 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4837 | SetRawInputAt(0, cls); |
| 4838 | SetRawInputAt(1, length); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4839 | } |
| 4840 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4841 | bool IsClonable() const OVERRIDE { return true; } |
| 4842 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4843 | // Calls runtime so needs an environment. |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4844 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4845 | |
| Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4846 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 4847 | bool CanThrow() const OVERRIDE { return true; } |
| 4848 | |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4849 | bool CanBeNull() const OVERRIDE { return false; } |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4850 | |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4851 | HLoadClass* GetLoadClass() const { |
| 4852 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4853 | return InputAt(0)->AsLoadClass(); |
| 4854 | } |
| 4855 | |
| 4856 | HInstruction* GetLength() const { |
| 4857 | return InputAt(1); |
| 4858 | } |
| Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4859 | |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4860 | DECLARE_INSTRUCTION(NewArray); |
| 4861 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4862 | protected: |
| 4863 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
| Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4864 | }; |
| 4865 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4866 | class HAdd FINAL : public HBinaryOperation { |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4867 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4868 | HAdd(DataType::Type result_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4869 | HInstruction* left, |
| 4870 | HInstruction* right, |
| 4871 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4872 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4873 | } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4874 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4875 | bool IsCommutative() const OVERRIDE { return true; } |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4876 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4877 | template <typename T> static T Compute(T x, T y) { return x + y; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4878 | |
| 4879 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4880 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4881 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4882 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4883 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4884 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4885 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4886 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4887 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4888 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4889 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4890 | } |
| 4891 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4892 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4893 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4894 | } |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4895 | |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4896 | DECLARE_INSTRUCTION(Add); |
| 4897 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4898 | protected: |
| 4899 | DEFAULT_COPY_CONSTRUCTOR(Add); |
| Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4900 | }; |
| 4901 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4902 | class HSub FINAL : public HBinaryOperation { |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4903 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4904 | HSub(DataType::Type result_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4905 | HInstruction* left, |
| 4906 | HInstruction* right, |
| 4907 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4908 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4909 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4910 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4911 | template <typename T> static T Compute(T x, T y) { return x - y; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4912 | |
| 4913 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4914 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4915 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4916 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4917 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4918 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4919 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4920 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4921 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4922 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4923 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4924 | } |
| 4925 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4926 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4927 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4928 | } |
| Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4929 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4930 | DECLARE_INSTRUCTION(Sub); |
| 4931 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4932 | protected: |
| 4933 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4934 | }; |
| 4935 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4936 | class HMul FINAL : public HBinaryOperation { |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4937 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4938 | HMul(DataType::Type result_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4939 | HInstruction* left, |
| 4940 | HInstruction* right, |
| 4941 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4942 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4943 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4944 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4945 | bool IsCommutative() const OVERRIDE { return true; } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4946 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4947 | template <typename T> static T Compute(T x, T y) { return x * y; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4948 | |
| 4949 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4950 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4951 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4952 | } |
| 4953 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4954 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4955 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4956 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4957 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 4958 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4959 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4960 | } |
| 4961 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 4962 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4963 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4964 | } |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4965 | |
| 4966 | DECLARE_INSTRUCTION(Mul); |
| 4967 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4968 | protected: |
| 4969 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
| Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4970 | }; |
| 4971 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 4972 | class HDiv FINAL : public HBinaryOperation { |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4973 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4974 | HDiv(DataType::Type result_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4975 | HInstruction* left, |
| 4976 | HInstruction* right, |
| 4977 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4978 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4979 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4980 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4981 | template <typename T> |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4982 | T ComputeIntegral(T x, T y) const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4983 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4984 | // Our graph structure ensures we never have 0 for `y` during |
| 4985 | // constant folding. |
| Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4986 | DCHECK_NE(y, 0); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4987 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 4988 | return (y == -1) ? -x : x / y; |
| 4989 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 4990 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4991 | template <typename T> |
| 4992 | T ComputeFP(T x, T y) const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4993 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4994 | return x / y; |
| 4995 | } |
| 4996 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4997 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4998 | return GetBlock()->GetGraph()->GetIntConstant( |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4999 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5000 | } |
| 5001 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5002 | return GetBlock()->GetGraph()->GetLongConstant( |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5003 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5004 | } |
| 5005 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 5006 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5007 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5008 | } |
| 5009 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 5010 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5011 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5012 | } |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5013 | |
| 5014 | DECLARE_INSTRUCTION(Div); |
| 5015 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5016 | protected: |
| 5017 | DEFAULT_COPY_CONSTRUCTOR(Div); |
| Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5018 | }; |
| 5019 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5020 | class HRem FINAL : public HBinaryOperation { |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5021 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5022 | HRem(DataType::Type result_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5023 | HInstruction* left, |
| 5024 | HInstruction* right, |
| 5025 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5026 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5027 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5028 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5029 | template <typename T> |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5030 | T ComputeIntegral(T x, T y) const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5031 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5032 | // Our graph structure ensures we never have 0 for `y` during |
| 5033 | // constant folding. |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5034 | DCHECK_NE(y, 0); |
| 5035 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 5036 | return (y == -1) ? 0 : x % y; |
| 5037 | } |
| 5038 | |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5039 | template <typename T> |
| 5040 | T ComputeFP(T x, T y) const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5041 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5042 | return std::fmod(x, y); |
| 5043 | } |
| 5044 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5045 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5046 | return GetBlock()->GetGraph()->GetIntConstant( |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5047 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5048 | } |
| 5049 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5050 | return GetBlock()->GetGraph()->GetLongConstant( |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5051 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5052 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5053 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const OVERRIDE { |
| 5054 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5055 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5056 | } |
| 5057 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const OVERRIDE { |
| 5058 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5059 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5060 | } |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5061 | |
| 5062 | DECLARE_INSTRUCTION(Rem); |
| 5063 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5064 | protected: |
| 5065 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
| Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5066 | }; |
| 5067 | |
| Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5068 | class HMin FINAL : public HBinaryOperation { |
| 5069 | public: |
| 5070 | HMin(DataType::Type result_type, |
| 5071 | HInstruction* left, |
| 5072 | HInstruction* right, |
| 5073 | uint32_t dex_pc) |
| 5074 | : HBinaryOperation(kMin, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5075 | |
| 5076 | bool IsCommutative() const OVERRIDE { return true; } |
| 5077 | |
| 5078 | // Evaluation for integral values. |
| 5079 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5080 | return (x <= y) ? x : y; |
| 5081 | } |
| 5082 | |
| 5083 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 5084 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5085 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5086 | } |
| 5087 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 5088 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5089 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5090 | } |
| 5091 | // TODO: Evaluation for floating-point values. |
| 5092 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5093 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { return nullptr; } |
| 5094 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5095 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { return nullptr; } |
| 5096 | |
| 5097 | DECLARE_INSTRUCTION(Min); |
| 5098 | |
| 5099 | protected: |
| 5100 | DEFAULT_COPY_CONSTRUCTOR(Min); |
| 5101 | }; |
| 5102 | |
| 5103 | class HMax FINAL : public HBinaryOperation { |
| 5104 | public: |
| 5105 | HMax(DataType::Type result_type, |
| 5106 | HInstruction* left, |
| 5107 | HInstruction* right, |
| 5108 | uint32_t dex_pc) |
| 5109 | : HBinaryOperation(kMax, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5110 | |
| 5111 | bool IsCommutative() const OVERRIDE { return true; } |
| 5112 | |
| 5113 | // Evaluation for integral values. |
| 5114 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5115 | return (x >= y) ? x : y; |
| 5116 | } |
| 5117 | |
| 5118 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 5119 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5120 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5121 | } |
| 5122 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 5123 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5124 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5125 | } |
| 5126 | // TODO: Evaluation for floating-point values. |
| 5127 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5128 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { return nullptr; } |
| 5129 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5130 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { return nullptr; } |
| 5131 | |
| 5132 | DECLARE_INSTRUCTION(Max); |
| 5133 | |
| 5134 | protected: |
| 5135 | DEFAULT_COPY_CONSTRUCTOR(Max); |
| 5136 | }; |
| 5137 | |
| Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5138 | class HAbs FINAL : public HUnaryOperation { |
| 5139 | public: |
| 5140 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5141 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5142 | |
| 5143 | // Evaluation for integral values. |
| 5144 | template <typename T> static T ComputeIntegral(T x) { |
| 5145 | return x < 0 ? -x : x; |
| 5146 | } |
| 5147 | |
| 5148 | // Evaluation for floating-point values. |
| 5149 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5150 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5151 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5152 | // http://b/30758343 |
| 5153 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5154 | S bits = bit_cast<S, T>(x); |
| 5155 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5156 | } |
| 5157 | |
| 5158 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
| 5159 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5160 | } |
| 5161 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
| 5162 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5163 | } |
| 5164 | HConstant* Evaluate(HFloatConstant* x) const OVERRIDE { |
| 5165 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5166 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5167 | } |
| 5168 | HConstant* Evaluate(HDoubleConstant* x) const OVERRIDE { |
| 5169 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5170 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5171 | } |
| 5172 | |
| 5173 | DECLARE_INSTRUCTION(Abs); |
| 5174 | |
| 5175 | protected: |
| 5176 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5177 | }; |
| 5178 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5179 | class HDivZeroCheck FINAL : public HExpression<1> { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5180 | public: |
| Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5181 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 5182 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5183 | // instruction following the current one; thus 'SideEffects::None()' is used. |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5184 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 5185 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::None(), dex_pc) { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5186 | SetRawInputAt(0, value); |
| 5187 | } |
| 5188 | |
| Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 5189 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5190 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5191 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5192 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5193 | return true; |
| 5194 | } |
| 5195 | |
| 5196 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5197 | bool CanThrow() const OVERRIDE { return true; } |
| 5198 | |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5199 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5200 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5201 | protected: |
| 5202 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
| Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5203 | }; |
| 5204 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5205 | class HShl FINAL : public HBinaryOperation { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5206 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5207 | HShl(DataType::Type result_type, |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5208 | HInstruction* value, |
| 5209 | HInstruction* distance, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5210 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5211 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5212 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5213 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5214 | } |
| 5215 | |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5216 | template <typename T> |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5217 | static T Compute(T value, int32_t distance, int32_t max_shift_distance) { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5218 | return value << (distance & max_shift_distance); |
| 5219 | } |
| 5220 | |
| 5221 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5222 | return GetBlock()->GetGraph()->GetIntConstant( |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5223 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5224 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5225 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5226 | return GetBlock()->GetGraph()->GetLongConstant( |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5227 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5228 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5229 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5230 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5231 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5232 | UNREACHABLE(); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5233 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5234 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5235 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5236 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5237 | UNREACHABLE(); |
| 5238 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5239 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5240 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5241 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5242 | UNREACHABLE(); |
| 5243 | } |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5244 | |
| 5245 | DECLARE_INSTRUCTION(Shl); |
| 5246 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5247 | protected: |
| 5248 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5249 | }; |
| 5250 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5251 | class HShr FINAL : public HBinaryOperation { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5252 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5253 | HShr(DataType::Type result_type, |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5254 | HInstruction* value, |
| 5255 | HInstruction* distance, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5256 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5257 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5258 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5259 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5260 | } |
| 5261 | |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5262 | template <typename T> |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5263 | static T Compute(T value, int32_t distance, int32_t max_shift_distance) { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5264 | return value >> (distance & max_shift_distance); |
| 5265 | } |
| 5266 | |
| 5267 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5268 | return GetBlock()->GetGraph()->GetIntConstant( |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5269 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5270 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5271 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5272 | return GetBlock()->GetGraph()->GetLongConstant( |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5273 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5274 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5275 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5276 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5277 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5278 | UNREACHABLE(); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5279 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5280 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5281 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5282 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5283 | UNREACHABLE(); |
| 5284 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5285 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5286 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5287 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5288 | UNREACHABLE(); |
| 5289 | } |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5290 | |
| 5291 | DECLARE_INSTRUCTION(Shr); |
| 5292 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5293 | protected: |
| 5294 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5295 | }; |
| 5296 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5297 | class HUShr FINAL : public HBinaryOperation { |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5298 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5299 | HUShr(DataType::Type result_type, |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5300 | HInstruction* value, |
| 5301 | HInstruction* distance, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5302 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5303 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5304 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5305 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5306 | } |
| 5307 | |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5308 | template <typename T> |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5309 | static T Compute(T value, int32_t distance, int32_t max_shift_distance) { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5310 | typedef typename std::make_unsigned<T>::type V; |
| 5311 | V ux = static_cast<V>(value); |
| 5312 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5313 | } |
| 5314 | |
| 5315 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5316 | return GetBlock()->GetGraph()->GetIntConstant( |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5317 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5318 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5319 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5320 | return GetBlock()->GetGraph()->GetLongConstant( |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5321 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5322 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5323 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5324 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5325 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5326 | UNREACHABLE(); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5327 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5328 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5329 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5330 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5331 | UNREACHABLE(); |
| 5332 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5333 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5334 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5335 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5336 | UNREACHABLE(); |
| 5337 | } |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5338 | |
| 5339 | DECLARE_INSTRUCTION(UShr); |
| 5340 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5341 | protected: |
| 5342 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
| Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5343 | }; |
| 5344 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5345 | class HAnd FINAL : public HBinaryOperation { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5346 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5347 | HAnd(DataType::Type result_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5348 | HInstruction* left, |
| 5349 | HInstruction* right, |
| 5350 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5351 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5352 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5353 | |
| Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5354 | bool IsCommutative() const OVERRIDE { return true; } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5355 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5356 | template <typename T> static T Compute(T x, T y) { return x & y; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5357 | |
| 5358 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5359 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5360 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5361 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5362 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5363 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5364 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5365 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5366 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5367 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5368 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5369 | UNREACHABLE(); |
| 5370 | } |
| 5371 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5372 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5373 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5374 | UNREACHABLE(); |
| 5375 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5376 | |
| 5377 | DECLARE_INSTRUCTION(And); |
| 5378 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5379 | protected: |
| 5380 | DEFAULT_COPY_CONSTRUCTOR(And); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5381 | }; |
| 5382 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5383 | class HOr FINAL : public HBinaryOperation { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5384 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5385 | HOr(DataType::Type result_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5386 | HInstruction* left, |
| 5387 | HInstruction* right, |
| 5388 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5389 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5390 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5391 | |
| Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5392 | bool IsCommutative() const OVERRIDE { return true; } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5393 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5394 | template <typename T> static T Compute(T x, T y) { return x | y; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5395 | |
| 5396 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5397 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5398 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5399 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5400 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5401 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5402 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5403 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5404 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5405 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5406 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5407 | UNREACHABLE(); |
| 5408 | } |
| 5409 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5410 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5411 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5412 | UNREACHABLE(); |
| 5413 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5414 | |
| 5415 | DECLARE_INSTRUCTION(Or); |
| 5416 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5417 | protected: |
| 5418 | DEFAULT_COPY_CONSTRUCTOR(Or); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5419 | }; |
| 5420 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5421 | class HXor FINAL : public HBinaryOperation { |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5422 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5423 | HXor(DataType::Type result_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5424 | HInstruction* left, |
| 5425 | HInstruction* right, |
| 5426 | uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5427 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5428 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5429 | |
| Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 5430 | bool IsCommutative() const OVERRIDE { return true; } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5431 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5432 | template <typename T> static T Compute(T x, T y) { return x ^ y; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5433 | |
| 5434 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5435 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5436 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5437 | } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5438 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5439 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5440 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5441 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5442 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
| 5443 | HFloatConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5444 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5445 | UNREACHABLE(); |
| 5446 | } |
| 5447 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
| 5448 | HDoubleConstant* y ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5449 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5450 | UNREACHABLE(); |
| 5451 | } |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5452 | |
| 5453 | DECLARE_INSTRUCTION(Xor); |
| 5454 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5455 | protected: |
| 5456 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
| Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5457 | }; |
| 5458 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5459 | class HRor FINAL : public HBinaryOperation { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5460 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5461 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5462 | : HBinaryOperation(kRor, result_type, value, distance) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5463 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5464 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
| Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5465 | } |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5466 | |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5467 | template <typename T> |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5468 | static T Compute(T value, int32_t distance, int32_t max_shift_value) { |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5469 | typedef typename std::make_unsigned<T>::type V; |
| 5470 | V ux = static_cast<V>(value); |
| 5471 | if ((distance & max_shift_value) == 0) { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5472 | return static_cast<T>(ux); |
| 5473 | } else { |
| 5474 | const V reg_bits = sizeof(T) * 8; |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5475 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5476 | (value << (reg_bits - (distance & max_shift_value))); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5477 | } |
| 5478 | } |
| 5479 | |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5480 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const OVERRIDE { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5481 | return GetBlock()->GetGraph()->GetIntConstant( |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5482 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5483 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5484 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const OVERRIDE { |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5485 | return GetBlock()->GetGraph()->GetLongConstant( |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5486 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5487 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5488 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
| 5489 | HLongConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5490 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5491 | UNREACHABLE(); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5492 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5493 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
| 5494 | HFloatConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5495 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5496 | UNREACHABLE(); |
| 5497 | } |
| Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5498 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
| 5499 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const OVERRIDE { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5500 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5501 | UNREACHABLE(); |
| 5502 | } |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5503 | |
| 5504 | DECLARE_INSTRUCTION(Ror); |
| 5505 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5506 | protected: |
| 5507 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
| Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5508 | }; |
| 5509 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5510 | // The value of a parameter in this method. Its location depends on |
| 5511 | // the calling convention. |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5512 | class HParameterValue FINAL : public HExpression<0> { |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5513 | public: |
| Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5514 | HParameterValue(const DexFile& dex_file, |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5515 | dex::TypeIndex type_index, |
| Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5516 | uint8_t index, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5517 | DataType::Type parameter_type, |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5518 | bool is_this = false) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5519 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
| Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5520 | dex_file_(dex_file), |
| 5521 | type_index_(type_index), |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5522 | index_(index) { |
| 5523 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5524 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5525 | } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5526 | |
| Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5527 | const DexFile& GetDexFile() const { return dex_file_; } |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5528 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5529 | uint8_t GetIndex() const { return index_; } |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5530 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5531 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5532 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| 5533 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5534 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5535 | DECLARE_INSTRUCTION(ParameterValue); |
| 5536 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5537 | protected: |
| 5538 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5539 | |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5540 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5541 | // Whether or not the parameter value corresponds to 'this' argument. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5542 | static constexpr size_t kFlagIsThis = kNumberOfGenericPackedBits; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5543 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5544 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5545 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5546 | "Too many packed fields."); |
| 5547 | |
| Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5548 | const DexFile& dex_file_; |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5549 | const dex::TypeIndex type_index_; |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5550 | // The index of this parameter in the parameters list. Must be less |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5551 | // than HGraph::number_of_in_vregs_. |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5552 | const uint8_t index_; |
| Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5553 | }; |
| 5554 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5555 | class HNot FINAL : public HUnaryOperation { |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5556 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5557 | HNot(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5558 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 5559 | } |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5560 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5561 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5562 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5563 | return true; |
| 5564 | } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5565 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5566 | template <typename T> static T Compute(T x) { return ~x; } |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5567 | |
| 5568 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5569 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5570 | } |
| 5571 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5572 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5573 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5574 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5575 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5576 | UNREACHABLE(); |
| 5577 | } |
| 5578 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5579 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5580 | UNREACHABLE(); |
| 5581 | } |
| Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5582 | |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5583 | DECLARE_INSTRUCTION(Not); |
| 5584 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5585 | protected: |
| 5586 | DEFAULT_COPY_CONSTRUCTOR(Not); |
| Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5587 | }; |
| 5588 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5589 | class HBooleanNot FINAL : public HUnaryOperation { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5590 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5591 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5592 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 5593 | } |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5594 | |
| 5595 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5596 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5597 | return true; |
| 5598 | } |
| 5599 | |
| Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5600 | template <typename T> static bool Compute(T x) { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5601 | DCHECK(IsUint<1>(x)) << x; |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5602 | return !x; |
| 5603 | } |
| 5604 | |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5605 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5606 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
| Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5607 | } |
| 5608 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5609 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5610 | UNREACHABLE(); |
| 5611 | } |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5612 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5613 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5614 | UNREACHABLE(); |
| 5615 | } |
| 5616 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5617 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5618 | UNREACHABLE(); |
| 5619 | } |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5620 | |
| 5621 | DECLARE_INSTRUCTION(BooleanNot); |
| 5622 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5623 | protected: |
| 5624 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
| David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5625 | }; |
| 5626 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5627 | class HTypeConversion FINAL : public HExpression<1> { |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5628 | public: |
| 5629 | // Instantiate a type conversion of `input` to `result_type`. |
| Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 5630 | HTypeConversion(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5631 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5632 | SetRawInputAt(0, input); |
| Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5633 | // Invariant: We should never generate a conversion to a Boolean value. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5634 | DCHECK_NE(DataType::Type::kBool, result_type); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5635 | } |
| 5636 | |
| 5637 | HInstruction* GetInput() const { return InputAt(0); } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5638 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 5639 | DataType::Type GetResultType() const { return GetType(); } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5640 | |
| Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 5641 | bool IsClonable() const OVERRIDE { return true; } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5642 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5643 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5644 | return true; |
| 5645 | } |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5646 | |
| Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5647 | // Try to statically evaluate the conversion and return a HConstant |
| 5648 | // containing the result. If the input cannot be converted, return nullptr. |
| 5649 | HConstant* TryStaticEvaluation() const; |
| 5650 | |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5651 | DECLARE_INSTRUCTION(TypeConversion); |
| 5652 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5653 | protected: |
| 5654 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
| Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5655 | }; |
| 5656 | |
| Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5657 | static constexpr uint32_t kNoRegNumber = -1; |
| 5658 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5659 | class HNullCheck FINAL : public HExpression<1> { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5660 | public: |
| Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5661 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 5662 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5663 | // instruction following the current one; thus 'SideEffects::None()' is used. |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5664 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 5665 | : HExpression(kNullCheck, value->GetType(), SideEffects::None(), dex_pc) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5666 | SetRawInputAt(0, value); |
| 5667 | } |
| 5668 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5669 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5670 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5671 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5672 | return true; |
| 5673 | } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5674 | |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5675 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5676 | |
| Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5677 | bool CanThrow() const OVERRIDE { return true; } |
| 5678 | |
| 5679 | bool CanBeNull() const OVERRIDE { return false; } |
| Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5680 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5681 | DECLARE_INSTRUCTION(NullCheck); |
| 5682 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5683 | protected: |
| 5684 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5685 | }; |
| 5686 | |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5687 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5688 | // that information to avoid requiring the mutator lock every time we need it. |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5689 | class FieldInfo : public ValueObject { |
| 5690 | public: |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5691 | FieldInfo(ArtField* field, |
| 5692 | MemberOffset field_offset, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5693 | DataType::Type field_type, |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5694 | bool is_volatile, |
| 5695 | uint32_t index, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5696 | uint16_t declaring_class_def_index, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5697 | const DexFile& dex_file) |
| 5698 | : field_(field), |
| 5699 | field_offset_(field_offset), |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5700 | field_type_(field_type), |
| 5701 | is_volatile_(is_volatile), |
| 5702 | index_(index), |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5703 | declaring_class_def_index_(declaring_class_def_index), |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5704 | dex_file_(dex_file) {} |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5705 | |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5706 | ArtField* GetField() const { return field_; } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5707 | MemberOffset GetFieldOffset() const { return field_offset_; } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5708 | DataType::Type GetFieldType() const { return field_type_; } |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5709 | uint32_t GetFieldIndex() const { return index_; } |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5710 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5711 | const DexFile& GetDexFile() const { return dex_file_; } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5712 | bool IsVolatile() const { return is_volatile_; } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5713 | |
| 5714 | private: |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5715 | ArtField* const field_; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5716 | const MemberOffset field_offset_; |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5717 | const DataType::Type field_type_; |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5718 | const bool is_volatile_; |
| Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5719 | const uint32_t index_; |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5720 | const uint16_t declaring_class_def_index_; |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5721 | const DexFile& dex_file_; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5722 | }; |
| 5723 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5724 | class HInstanceFieldGet FINAL : public HExpression<1> { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5725 | public: |
| 5726 | HInstanceFieldGet(HInstruction* value, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5727 | ArtField* field, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5728 | DataType::Type field_type, |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5729 | MemberOffset field_offset, |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5730 | bool is_volatile, |
| 5731 | uint32_t field_idx, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5732 | uint16_t declaring_class_def_index, |
| Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5733 | const DexFile& dex_file, |
| Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5734 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5735 | : HExpression(kInstanceFieldGet, |
| 5736 | field_type, |
| 5737 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5738 | dex_pc), |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5739 | field_info_(field, |
| 5740 | field_offset, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5741 | field_type, |
| 5742 | is_volatile, |
| 5743 | field_idx, |
| 5744 | declaring_class_def_index, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5745 | dex_file) { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5746 | SetRawInputAt(0, value); |
| 5747 | } |
| 5748 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5749 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 5750 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5751 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5752 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 5753 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5754 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5755 | } |
| 5756 | |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5757 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5758 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
| 5761 | size_t ComputeHashCode() const OVERRIDE { |
| Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5762 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5763 | } |
| 5764 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5765 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5766 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5767 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5768 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5769 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5770 | void SetType(DataType::Type new_type) { |
| 5771 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5772 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5773 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5774 | SetPackedField<TypeField>(new_type); |
| 5775 | } |
| 5776 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5777 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5778 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5779 | protected: |
| 5780 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 5781 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5782 | private: |
| 5783 | const FieldInfo field_info_; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5784 | }; |
| 5785 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5786 | class HInstanceFieldSet FINAL : public HExpression<2> { |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5787 | public: |
| 5788 | HInstanceFieldSet(HInstruction* object, |
| 5789 | HInstruction* value, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5790 | ArtField* field, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5791 | DataType::Type field_type, |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5792 | MemberOffset field_offset, |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5793 | bool is_volatile, |
| 5794 | uint32_t field_idx, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5795 | uint16_t declaring_class_def_index, |
| Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5796 | const DexFile& dex_file, |
| Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5797 | uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5798 | : HExpression(kInstanceFieldSet, |
| 5799 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5800 | dex_pc), |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5801 | field_info_(field, |
| 5802 | field_offset, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5803 | field_type, |
| 5804 | is_volatile, |
| 5805 | field_idx, |
| 5806 | declaring_class_def_index, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5807 | dex_file) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5808 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5809 | SetRawInputAt(0, object); |
| 5810 | SetRawInputAt(1, value); |
| 5811 | } |
| 5812 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5813 | bool IsClonable() const OVERRIDE { return true; } |
| 5814 | |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 5815 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5816 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5817 | } |
| 5818 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5819 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5820 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5821 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5822 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5823 | HInstruction* GetValue() const { return InputAt(1); } |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5824 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5825 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5826 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5827 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5828 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5829 | protected: |
| 5830 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 5831 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5832 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5833 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5834 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5835 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5836 | "Too many packed fields."); |
| 5837 | |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5838 | const FieldInfo field_info_; |
| Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5839 | }; |
| 5840 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 5841 | class HArrayGet FINAL : public HExpression<2> { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5842 | public: |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5843 | HArrayGet(HInstruction* array, |
| 5844 | HInstruction* index, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5845 | DataType::Type type, |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5846 | uint32_t dex_pc) |
| 5847 | : HArrayGet(array, |
| 5848 | index, |
| 5849 | type, |
| 5850 | SideEffects::ArrayReadOfType(type), |
| 5851 | dex_pc, |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5852 | /* is_string_char_at */ false) { |
| 5853 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5854 | |
| 5855 | HArrayGet(HInstruction* array, |
| 5856 | HInstruction* index, |
| 5857 | DataType::Type type, |
| 5858 | SideEffects side_effects, |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5859 | uint32_t dex_pc, |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5860 | bool is_string_char_at) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5861 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5862 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5863 | SetRawInputAt(0, array); |
| 5864 | SetRawInputAt(1, index); |
| 5865 | } |
| 5866 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5867 | bool IsClonable() const OVERRIDE { return true; } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5868 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5869 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5870 | return true; |
| 5871 | } |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5872 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5873 | // TODO: We can be smarter here. |
| Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5874 | // Currently, unless the array is the result of NewArray, the array access is always |
| 5875 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 5876 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 5877 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 5878 | // If we ever add optimizations to do so we should allow an implicit check here |
| 5879 | // (as long as the address falls in the first page). |
| 5880 | // |
| 5881 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 5882 | // a = cond ? new int[1] : null; |
| 5883 | // a[0]; // The Phi does not need bounds check for either input. |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5884 | return false; |
| 5885 | } |
| 5886 | |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5887 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5888 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5889 | if (kIsDebugBuild && result) { |
| 5890 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5891 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5892 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5893 | if (DataType::IsIntOrLongType(GetType())) { |
| 5894 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5895 | } else { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5896 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 5897 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
| David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5898 | } |
| 5899 | } |
| 5900 | return result; |
| 5901 | } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5902 | |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5903 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5904 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5905 | HInstruction* GetArray() const { return InputAt(0); } |
| 5906 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5907 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5908 | void SetType(DataType::Type new_type) { |
| 5909 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5910 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5911 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5912 | SetPackedField<TypeField>(new_type); |
| 5913 | } |
| 5914 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5915 | DECLARE_INSTRUCTION(ArrayGet); |
| 5916 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5917 | protected: |
| 5918 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 5919 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5920 | private: |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5921 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5922 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5923 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5924 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5925 | // a flag, so that code generators don't need to do the locking. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5926 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5927 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5928 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5929 | "Too many packed fields."); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5930 | }; |
| 5931 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5932 | class HArraySet FINAL : public HExpression<3> { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5933 | public: |
| 5934 | HArraySet(HInstruction* array, |
| 5935 | HInstruction* index, |
| 5936 | HInstruction* value, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5937 | DataType::Type expected_component_type, |
| Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5938 | uint32_t dex_pc) |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5939 | : HArraySet(array, |
| 5940 | index, |
| 5941 | value, |
| 5942 | expected_component_type, |
| 5943 | // Make a best guess for side effects now, may be refined during SSA building. |
| 5944 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5945 | dex_pc) { |
| 5946 | } |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5947 | |
| 5948 | HArraySet(HInstruction* array, |
| 5949 | HInstruction* index, |
| 5950 | HInstruction* value, |
| 5951 | DataType::Type expected_component_type, |
| 5952 | SideEffects side_effects, |
| 5953 | uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5954 | : HExpression(kArraySet, side_effects, dex_pc) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5955 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5956 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5957 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5958 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5959 | SetRawInputAt(0, array); |
| 5960 | SetRawInputAt(1, index); |
| 5961 | SetRawInputAt(2, value); |
| 5962 | } |
| 5963 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5964 | bool IsClonable() const OVERRIDE { return true; } |
| 5965 | |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5966 | bool NeedsEnvironment() const OVERRIDE { |
| Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5967 | // We call a runtime method to throw ArrayStoreException. |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5968 | return NeedsTypeCheck(); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5969 | } |
| 5970 | |
| Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5971 | // Can throw ArrayStoreException. |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5972 | bool CanThrow() const OVERRIDE { return NeedsTypeCheck(); } |
| Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5973 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5974 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5975 | // TODO: Same as for ArrayGet. |
| 5976 | return false; |
| 5977 | } |
| 5978 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5979 | void ClearNeedsTypeCheck() { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5980 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5981 | } |
| 5982 | |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5983 | void ClearValueCanBeNull() { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5984 | SetPackedFlag<kFlagValueCanBeNull>(false); |
| Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 5985 | } |
| 5986 | |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5987 | void SetStaticTypeOfArrayIsObjectArray() { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5988 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 5989 | } |
| 5990 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5991 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5992 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 5993 | bool StaticTypeOfArrayIsObjectArray() const { |
| 5994 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 5995 | } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5996 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5997 | HInstruction* GetArray() const { return InputAt(0); } |
| 5998 | HInstruction* GetIndex() const { return InputAt(1); } |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 5999 | HInstruction* GetValue() const { return InputAt(2); } |
| 6000 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6001 | DataType::Type GetComponentType() const { |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6002 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 6003 | } |
| 6004 | |
| 6005 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 6006 | DataType::Type expected_component_type) { |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6007 | // The Dex format does not type floating point index operations. Since the |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6008 | // `expected_component_type` comes from SSA building and can therefore not |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6009 | // be correct, we also check what is the value type. If it is a floating |
| 6010 | // point type, we must use that type. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6011 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6012 | ? value_type |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6013 | : expected_component_type; |
| Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6014 | } |
| Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6015 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6016 | DataType::Type GetRawExpectedComponentType() const { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6017 | return GetPackedField<ExpectedComponentTypeField>(); |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6018 | } |
| 6019 | |
| Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6020 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 6021 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
| Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6022 | } |
| 6023 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6024 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 6025 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 6026 | : SideEffects::None(); |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6027 | } |
| 6028 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6029 | DECLARE_INSTRUCTION(ArraySet); |
| 6030 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6031 | protected: |
| 6032 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 6033 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6034 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6035 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 6036 | static constexpr size_t kFieldExpectedComponentTypeSize = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6037 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6038 | static constexpr size_t kFlagNeedsTypeCheck = |
| 6039 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 6040 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
| Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6041 | // Cached information for the reference_type_info_ so that codegen |
| 6042 | // does not need to inspect the static type. |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6043 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 6044 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 6045 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 6046 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6047 | using ExpectedComponentTypeField = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6048 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6049 | }; |
| 6050 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6051 | class HArrayLength FINAL : public HExpression<1> { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6052 | public: |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6053 | HArrayLength(HInstruction* array, uint32_t dex_pc, bool is_string_length = false) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6054 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6055 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6056 | // Note that arrays do not change length, so the instruction does not |
| 6057 | // depend on any write. |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6058 | SetRawInputAt(0, array); |
| 6059 | } |
| 6060 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6061 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 6062 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6063 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6064 | return true; |
| 6065 | } |
| Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 6066 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 6067 | return obj == InputAt(0); |
| 6068 | } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6069 | |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6070 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 6071 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6072 | DECLARE_INSTRUCTION(ArrayLength); |
| 6073 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6074 | protected: |
| 6075 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 6076 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6077 | private: |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6078 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 6079 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 6080 | // determine whether a particular HArrayLength is actually a String.length() by |
| 6081 | // looking at the type of the input but that requires holding the mutator lock, so |
| 6082 | // we prefer to use a flag, so that code generators don't need to do the locking. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6083 | static constexpr size_t kFlagIsStringLength = kNumberOfGenericPackedBits; |
| Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6084 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 6085 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6086 | "Too many packed fields."); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6087 | }; |
| 6088 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6089 | class HBoundsCheck FINAL : public HExpression<2> { |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6090 | public: |
| Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6091 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 6092 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6093 | // instruction following the current one; thus 'SideEffects::None()' is used. |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6094 | HBoundsCheck(HInstruction* index, |
| 6095 | HInstruction* length, |
| 6096 | uint32_t dex_pc, |
| Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6097 | bool is_string_char_at = false) |
| Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame^] | 6098 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::None(), dex_pc) { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6099 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
| Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6100 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6101 | SetRawInputAt(0, index); |
| 6102 | SetRawInputAt(1, length); |
| 6103 | } |
| 6104 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6105 | bool IsClonable() const OVERRIDE { return true; } |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6106 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6107 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6108 | return true; |
| 6109 | } |
| Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6110 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6111 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6112 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6113 | bool CanThrow() const OVERRIDE { return true; } |
| Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6114 | |
| Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6115 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6116 | |
| Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6117 | HInstruction* GetIndex() const { return InputAt(0); } |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6118 | |
| 6119 | DECLARE_INSTRUCTION(BoundsCheck); |
| 6120 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6121 | protected: |
| 6122 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6123 | |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6124 | private: |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6125 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
| Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6126 | }; |
| 6127 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6128 | class HSuspendCheck FINAL : public HExpression<0> { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6129 | public: |
| David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 6130 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6131 | : HExpression(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6132 | slow_path_(nullptr) { |
| 6133 | } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6134 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6135 | bool IsClonable() const OVERRIDE { return true; } |
| 6136 | |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 6137 | bool NeedsEnvironment() const OVERRIDE { |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6138 | return true; |
| 6139 | } |
| 6140 | |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6141 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6142 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6143 | |
| 6144 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6145 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6146 | protected: |
| 6147 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6148 | |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6149 | private: |
| Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6150 | // Only used for code generation, in order to share the same slow path between back edges |
| 6151 | // of a same loop. |
| 6152 | SlowPathCode* slow_path_; |
| Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6153 | }; |
| 6154 | |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6155 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 6156 | // It ensures that we can generate line number and local variables at this point. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6157 | class HNativeDebugInfo : public HExpression<0> { |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6158 | public: |
| 6159 | explicit HNativeDebugInfo(uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6160 | : HExpression<0>(kNativeDebugInfo, SideEffects::None(), dex_pc) { |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6161 | } |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6162 | |
| 6163 | bool NeedsEnvironment() const OVERRIDE { |
| 6164 | return true; |
| 6165 | } |
| 6166 | |
| 6167 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 6168 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6169 | protected: |
| 6170 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
| David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6171 | }; |
| 6172 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6173 | /** |
| 6174 | * Instruction to load a Class object. |
| 6175 | */ |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6176 | class HLoadClass FINAL : public HInstruction { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6177 | public: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6178 | // Determines how to load the Class. |
| 6179 | enum class LoadKind { |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6180 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6181 | kInvalid = -1, |
| 6182 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6183 | // Use the Class* from the method's own ArtMethod*. |
| 6184 | kReferrersClass, |
| 6185 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6186 | // Use PC-relative boot image Class* address that will be known at link time. |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6187 | // Used for boot image classes referenced by boot image code. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6188 | kBootImageLinkTimePcRelative, |
| 6189 | |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6190 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6191 | // Used for boot image classes referenced by apps in AOT-compiled code. |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6192 | kBootImageRelRo, |
| Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6193 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6194 | // Load from an entry in the .bss section using a PC-relative load. |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6195 | // Used for classes outside boot image referenced by AOT-compiled app and boot image code. |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6196 | kBssEntry, |
| 6197 | |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6198 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 6199 | // Used for boot image classes referenced by apps in JIT-compiled code. |
| 6200 | kJitBootImageAddress, |
| 6201 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6202 | // Load from the root table associated with the JIT compiled method. |
| 6203 | kJitTableAddress, |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6204 | |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6205 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6206 | // the codegen is unable to use another appropriate kind. |
| 6207 | kRuntimeCall, |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6208 | |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6209 | kLast = kRuntimeCall |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6210 | }; |
| 6211 | |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6212 | HLoadClass(HCurrentMethod* current_method, |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6213 | dex::TypeIndex type_index, |
| Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6214 | const DexFile& dex_file, |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6215 | Handle<mirror::Class> klass, |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6216 | bool is_referrers_class, |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6217 | uint32_t dex_pc, |
| Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6218 | bool needs_access_check) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6219 | : HInstruction(kLoadClass, |
| 6220 | DataType::Type::kReference, |
| 6221 | SideEffectsForArchRuntimeCalls(), |
| 6222 | dex_pc), |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6223 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6224 | type_index_(type_index), |
| Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6225 | dex_file_(dex_file), |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6226 | klass_(klass) { |
| Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6227 | // Referrers class should not need access check. We never inline unverified |
| 6228 | // methods so we can't possibly end up in this situation. |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6229 | DCHECK(!is_referrers_class || !needs_access_check); |
| 6230 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6231 | SetPackedField<LoadKindField>( |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6232 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6233 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
| Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6234 | SetPackedFlag<kFlagIsInBootImage>(false); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6235 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6236 | SetPackedFlag<kFlagValidLoadedClassRTI>(false); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6237 | } |
| 6238 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6239 | bool IsClonable() const OVERRIDE { return true; } |
| 6240 | |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6241 | void SetLoadKind(LoadKind load_kind); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6242 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6243 | LoadKind GetLoadKind() const { |
| 6244 | return GetPackedField<LoadKindField>(); |
| Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6245 | } |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6246 | |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6247 | bool HasPcRelativeLoadKind() const { |
| 6248 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6249 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6250 | GetLoadKind() == LoadKind::kBssEntry; |
| 6251 | } |
| 6252 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6253 | bool CanBeMoved() const OVERRIDE { return true; } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6254 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6255 | bool InstructionDataEquals(const HInstruction* other) const; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6256 | |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6257 | size_t ComputeHashCode() const OVERRIDE { return type_index_.index_; } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6258 | |
| Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 6259 | bool CanBeNull() const OVERRIDE { return false; } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6260 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6261 | bool NeedsEnvironment() const OVERRIDE { |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6262 | return CanCallRuntime(); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6263 | } |
| 6264 | |
| Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 6265 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
| Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 6266 | // The entrypoint the code generator is going to call does not do |
| 6267 | // clinit of the class. |
| 6268 | DCHECK(!NeedsAccessCheck()); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6269 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | bool CanCallRuntime() const { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6273 | return NeedsAccessCheck() || |
| 6274 | MustGenerateClinitCheck() || |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6275 | GetLoadKind() == LoadKind::kRuntimeCall || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6276 | GetLoadKind() == LoadKind::kBssEntry; |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6277 | } |
| 6278 | |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6279 | bool CanThrow() const OVERRIDE { |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6280 | return NeedsAccessCheck() || |
| 6281 | MustGenerateClinitCheck() || |
| 6282 | // If the class is in the boot image, the lookup in the runtime call cannot throw. |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6283 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6284 | GetLoadKind() == LoadKind::kBssEntry) && |
| 6285 | !IsInBootImage()); |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6288 | ReferenceTypeInfo GetLoadedClassRTI() { |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6289 | if (GetPackedFlag<kFlagValidLoadedClassRTI>()) { |
| 6290 | // Note: The is_exact flag from the return value should not be used. |
| 6291 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact */ true); |
| 6292 | } else { |
| 6293 | return ReferenceTypeInfo::CreateInvalid(); |
| 6294 | } |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6295 | } |
| 6296 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6297 | // Loaded class RTI is marked as valid by RTP if the klass_ is admissible. |
| 6298 | void SetValidLoadedClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 6299 | DCHECK(klass_ != nullptr); |
| 6300 | SetPackedFlag<kFlagValidLoadedClassRTI>(true); |
| Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6303 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6304 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6305 | |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6306 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6307 | return GetLoadKind() == LoadKind::kRuntimeCall; |
| Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6308 | } |
| Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 6309 | |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6310 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6311 | return SideEffects::CanTriggerGC(); |
| 6312 | } |
| 6313 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6314 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6315 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6316 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6317 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
| Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6318 | |
| Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6319 | bool MustResolveTypeOnSlowPath() const { |
| 6320 | // Check that this instruction has a slow path. |
| 6321 | DCHECK(GetLoadKind() != LoadKind::kRuntimeCall); // kRuntimeCall calls on main path. |
| 6322 | DCHECK(GetLoadKind() == LoadKind::kBssEntry || MustGenerateClinitCheck()); |
| 6323 | return GetLoadKind() == LoadKind::kBssEntry; |
| 6324 | } |
| 6325 | |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6326 | void MarkInBootImage() { |
| 6327 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6328 | } |
| 6329 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6330 | void AddSpecialInput(HInstruction* special_input); |
| 6331 | |
| 6332 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6333 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6334 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6335 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6336 | } |
| 6337 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6338 | Handle<mirror::Class> GetClass() const { |
| 6339 | return klass_; |
| 6340 | } |
| 6341 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6342 | DECLARE_INSTRUCTION(LoadClass); |
| 6343 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6344 | protected: |
| 6345 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6346 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6347 | private: |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6348 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
| Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6349 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6350 | // Whether this instruction must generate the initialization check. |
| 6351 | // Used for code generation. |
| Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6352 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6353 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6354 | static constexpr size_t kFieldLoadKindSize = |
| 6355 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6356 | static constexpr size_t kFlagValidLoadedClassRTI = kFieldLoadKind + kFieldLoadKindSize; |
| 6357 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagValidLoadedClassRTI + 1; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6358 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6359 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6360 | |
| 6361 | static bool HasTypeReference(LoadKind load_kind) { |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6362 | return load_kind == LoadKind::kReferrersClass || |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6363 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6364 | load_kind == LoadKind::kBssEntry || |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6365 | load_kind == LoadKind::kRuntimeCall; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6366 | } |
| 6367 | |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6368 | void SetLoadKindInternal(LoadKind load_kind); |
| 6369 | |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6370 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6371 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6372 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6373 | HUserRecord<HInstruction*> special_input_; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6374 | |
| Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6375 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6376 | // - The compiling method's dex file if the class is defined there too. |
| 6377 | // - The compiling method's dex file if the class is referenced there. |
| 6378 | // - The dex file where the class is defined. When the load kind can only be |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6379 | // kBssEntry or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
| Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6380 | const dex::TypeIndex type_index_; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6381 | const DexFile& dex_file_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6382 | |
| Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6383 | Handle<mirror::Class> klass_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6384 | }; |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6385 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6386 | |
| 6387 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6388 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6389 | // The load kind should be determined before inserting the instruction to the graph. |
| 6390 | DCHECK(GetBlock() == nullptr); |
| 6391 | DCHECK(GetEnvironment() == nullptr); |
| 6392 | SetPackedField<LoadKindField>(load_kind); |
| 6393 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6394 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6395 | } |
| 6396 | if (!NeedsEnvironment()) { |
| 6397 | SetSideEffects(SideEffects::None()); |
| 6398 | } |
| 6399 | } |
| 6400 | |
| 6401 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6402 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6403 | // The special input is used for PC-relative loads on some architectures, |
| 6404 | // including literal pool loads, which are PC-relative too. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6405 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6406 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6407 | GetLoadKind() == LoadKind::kBssEntry || |
| 6408 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6409 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6410 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6411 | special_input->AddUseAt(this, 0); |
| 6412 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6413 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6414 | class HLoadString FINAL : public HInstruction { |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6415 | public: |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6416 | // Determines how to load the String. |
| 6417 | enum class LoadKind { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6418 | // Use PC-relative boot image String* address that will be known at link time. |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6419 | // Used for boot image strings referenced by boot image code. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6420 | kBootImageLinkTimePcRelative, |
| 6421 | |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6422 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6423 | // Used for boot image strings referenced by apps in AOT-compiled code. |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6424 | kBootImageRelRo, |
| Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6425 | |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6426 | // Load from an entry in the .bss section using a PC-relative load. |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6427 | // Used for strings outside boot image referenced by AOT-compiled app and boot image code. |
| Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6428 | kBssEntry, |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6429 | |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6430 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 6431 | // Used for boot image strings referenced by apps in JIT-compiled code. |
| 6432 | kJitBootImageAddress, |
| 6433 | |
| Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6434 | // Load from the root table associated with the JIT compiled method. |
| 6435 | kJitTableAddress, |
| 6436 | |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6437 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6438 | // the codegen is unable to use another appropriate kind. |
| 6439 | kRuntimeCall, |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6440 | |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6441 | kLast = kRuntimeCall, |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6442 | }; |
| 6443 | |
| Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6444 | HLoadString(HCurrentMethod* current_method, |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6445 | dex::StringIndex string_index, |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6446 | const DexFile& dex_file, |
| 6447 | uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6448 | : HInstruction(kLoadString, |
| 6449 | DataType::Type::kReference, |
| 6450 | SideEffectsForArchRuntimeCalls(), |
| 6451 | dex_pc), |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6452 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6453 | string_index_(string_index), |
| 6454 | dex_file_(dex_file) { |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6455 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
| Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6456 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6457 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6458 | bool IsClonable() const OVERRIDE { return true; } |
| 6459 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6460 | void SetLoadKind(LoadKind load_kind); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6461 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6462 | LoadKind GetLoadKind() const { |
| 6463 | return GetPackedField<LoadKindField>(); |
| 6464 | } |
| 6465 | |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6466 | bool HasPcRelativeLoadKind() const { |
| 6467 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6468 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6469 | GetLoadKind() == LoadKind::kBssEntry; |
| 6470 | } |
| 6471 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6472 | const DexFile& GetDexFile() const { |
| 6473 | return dex_file_; |
| 6474 | } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6475 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6476 | dex::StringIndex GetStringIndex() const { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6477 | return string_index_; |
| 6478 | } |
| 6479 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6480 | Handle<mirror::String> GetString() const { |
| 6481 | return string_; |
| 6482 | } |
| 6483 | |
| 6484 | void SetString(Handle<mirror::String> str) { |
| 6485 | string_ = str; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6486 | } |
| 6487 | |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6488 | bool CanBeMoved() const OVERRIDE { return true; } |
| 6489 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6490 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6491 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6492 | size_t ComputeHashCode() const OVERRIDE { return string_index_.index_; } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6493 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6494 | // Will call the runtime if we need to load the string through |
| 6495 | // the dex cache and the string is not guaranteed to be there yet. |
| 6496 | bool NeedsEnvironment() const OVERRIDE { |
| 6497 | LoadKind load_kind = GetLoadKind(); |
| Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6498 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6499 | load_kind == LoadKind::kBootImageRelRo || |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6500 | load_kind == LoadKind::kJitBootImageAddress || |
| Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6501 | load_kind == LoadKind::kJitTableAddress) { |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6502 | return false; |
| 6503 | } |
| Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6504 | return true; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6505 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6506 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6507 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6508 | return GetLoadKind() == LoadKind::kRuntimeCall; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6509 | } |
| Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6510 | |
| Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 6511 | bool CanBeNull() const OVERRIDE { return false; } |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6512 | bool CanThrow() const OVERRIDE { return NeedsEnvironment(); } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6513 | |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6514 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6515 | return SideEffects::CanTriggerGC(); |
| 6516 | } |
| 6517 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6518 | void AddSpecialInput(HInstruction* special_input); |
| 6519 | |
| 6520 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6521 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6522 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6523 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6524 | } |
| 6525 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6526 | DECLARE_INSTRUCTION(LoadString); |
| 6527 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6528 | protected: |
| 6529 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 6530 | |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6531 | private: |
| Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6532 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6533 | static constexpr size_t kFieldLoadKindSize = |
| 6534 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6535 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6536 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6537 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6538 | |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6539 | void SetLoadKindInternal(LoadKind load_kind); |
| 6540 | |
| Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6541 | // The special input is the HCurrentMethod for kRuntimeCall. |
| Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6542 | // For other load kinds it's empty or possibly some architecture-specific instruction |
| Vladimir Marko | 48886c2 | 2017-01-06 11:45:47 +0000 | [diff] [blame] | 6543 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6544 | HUserRecord<HInstruction*> special_input_; |
| 6545 | |
| Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6546 | dex::StringIndex string_index_; |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6547 | const DexFile& dex_file_; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6548 | |
| Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6549 | Handle<mirror::String> string_; |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6550 | }; |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6551 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 6552 | |
| 6553 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6554 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 6555 | // The load kind should be determined before inserting the instruction to the graph. |
| 6556 | DCHECK(GetBlock() == nullptr); |
| 6557 | DCHECK(GetEnvironment() == nullptr); |
| 6558 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 6559 | SetPackedField<LoadKindField>(load_kind); |
| 6560 | if (load_kind != LoadKind::kRuntimeCall) { |
| 6561 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6562 | } |
| 6563 | if (!NeedsEnvironment()) { |
| 6564 | SetSideEffects(SideEffects::None()); |
| 6565 | } |
| 6566 | } |
| 6567 | |
| 6568 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6569 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
| Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6570 | // The special input is used for PC-relative loads on some architectures, |
| 6571 | // including literal pool loads, which are PC-relative too. |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6572 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6573 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6574 | GetLoadKind() == LoadKind::kBssEntry || |
| 6575 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6576 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 6577 | // so use the GetInputRecords() from the base class to set the input record. |
| 6578 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6579 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6580 | special_input->AddUseAt(this, 0); |
| 6581 | } |
| Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6582 | |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6583 | class HLoadMethodHandle FINAL : public HInstruction { |
| 6584 | public: |
| 6585 | HLoadMethodHandle(HCurrentMethod* current_method, |
| Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 6586 | uint16_t method_handle_idx, |
| 6587 | const DexFile& dex_file, |
| 6588 | uint32_t dex_pc) |
| Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6589 | : HInstruction(kLoadMethodHandle, |
| 6590 | DataType::Type::kReference, |
| 6591 | SideEffectsForArchRuntimeCalls(), |
| 6592 | dex_pc), |
| 6593 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| 6594 | method_handle_idx_(method_handle_idx), |
| 6595 | dex_file_(dex_file) { |
| 6596 | } |
| 6597 | |
| 6598 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6599 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6600 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6601 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6602 | } |
| 6603 | |
| 6604 | bool IsClonable() const OVERRIDE { return true; } |
| 6605 | |
| 6606 | uint16_t GetMethodHandleIndex() const { return method_handle_idx_; } |
| 6607 | |
| 6608 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6609 | |
| 6610 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6611 | return SideEffects::CanTriggerGC(); |
| 6612 | } |
| 6613 | |
| 6614 | DECLARE_INSTRUCTION(LoadMethodHandle); |
| 6615 | |
| 6616 | protected: |
| 6617 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodHandle); |
| 6618 | |
| 6619 | private: |
| 6620 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6621 | HUserRecord<HInstruction*> special_input_; |
| 6622 | |
| 6623 | const uint16_t method_handle_idx_; |
| 6624 | const DexFile& dex_file_; |
| 6625 | }; |
| 6626 | |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6627 | class HLoadMethodType FINAL : public HInstruction { |
| 6628 | public: |
| 6629 | HLoadMethodType(HCurrentMethod* current_method, |
| Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6630 | dex::ProtoIndex proto_index, |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6631 | const DexFile& dex_file, |
| 6632 | uint32_t dex_pc) |
| 6633 | : HInstruction(kLoadMethodType, |
| 6634 | DataType::Type::kReference, |
| 6635 | SideEffectsForArchRuntimeCalls(), |
| 6636 | dex_pc), |
| 6637 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6638 | proto_index_(proto_index), |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6639 | dex_file_(dex_file) { |
| 6640 | } |
| 6641 | |
| 6642 | using HInstruction::GetInputRecords; // Keep the const version visible. |
| 6643 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() OVERRIDE FINAL { |
| 6644 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6645 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6646 | } |
| 6647 | |
| 6648 | bool IsClonable() const OVERRIDE { return true; } |
| 6649 | |
| Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6650 | dex::ProtoIndex GetProtoIndex() const { return proto_index_; } |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6651 | |
| 6652 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6653 | |
| 6654 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6655 | return SideEffects::CanTriggerGC(); |
| 6656 | } |
| 6657 | |
| 6658 | DECLARE_INSTRUCTION(LoadMethodType); |
| 6659 | |
| 6660 | protected: |
| 6661 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodType); |
| 6662 | |
| 6663 | private: |
| 6664 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6665 | HUserRecord<HInstruction*> special_input_; |
| 6666 | |
| Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6667 | const dex::ProtoIndex proto_index_; |
| Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6668 | const DexFile& dex_file_; |
| 6669 | }; |
| 6670 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6671 | /** |
| 6672 | * Performs an initialization check on its Class object input. |
| 6673 | */ |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6674 | class HClinitCheck FINAL : public HExpression<1> { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6675 | public: |
| Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6676 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
| Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6677 | : HExpression( |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6678 | kClinitCheck, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6679 | DataType::Type::kReference, |
| Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 6680 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6681 | dex_pc) { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6682 | SetRawInputAt(0, constant); |
| 6683 | } |
| Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 6684 | // TODO: Make ClinitCheck clonable. |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6685 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6686 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6687 | return true; |
| 6688 | } |
| 6689 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6690 | bool NeedsEnvironment() const OVERRIDE { |
| 6691 | // May call runtime to initialize the class. |
| 6692 | return true; |
| 6693 | } |
| 6694 | |
| Nicolas Geoffray | 729645a | 2015-11-19 13:29:02 +0000 | [diff] [blame] | 6695 | bool CanThrow() const OVERRIDE { return true; } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6696 | |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6697 | HLoadClass* GetLoadClass() const { |
| 6698 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6699 | return InputAt(0)->AsLoadClass(); |
| 6700 | } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6701 | |
| 6702 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6703 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6704 | |
| 6705 | protected: |
| 6706 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6707 | }; |
| 6708 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6709 | class HStaticFieldGet FINAL : public HExpression<1> { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6710 | public: |
| 6711 | HStaticFieldGet(HInstruction* cls, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6712 | ArtField* field, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6713 | DataType::Type field_type, |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6714 | MemberOffset field_offset, |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6715 | bool is_volatile, |
| 6716 | uint32_t field_idx, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6717 | uint16_t declaring_class_def_index, |
| Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6718 | const DexFile& dex_file, |
| Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6719 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6720 | : HExpression(kStaticFieldGet, |
| 6721 | field_type, |
| 6722 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6723 | dex_pc), |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6724 | field_info_(field, |
| 6725 | field_offset, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6726 | field_type, |
| 6727 | is_volatile, |
| 6728 | field_idx, |
| 6729 | declaring_class_def_index, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6730 | dex_file) { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6731 | SetRawInputAt(0, cls); |
| 6732 | } |
| 6733 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6734 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6735 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 6736 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6737 | |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6738 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 6739 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6740 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6741 | } |
| 6742 | |
| 6743 | size_t ComputeHashCode() const OVERRIDE { |
| 6744 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6745 | } |
| 6746 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6747 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6748 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6749 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6750 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6751 | |
| Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6752 | void SetType(DataType::Type new_type) { |
| 6753 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6754 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6755 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6756 | SetPackedField<TypeField>(new_type); |
| 6757 | } |
| 6758 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6759 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6760 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6761 | protected: |
| 6762 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 6763 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6764 | private: |
| 6765 | const FieldInfo field_info_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6766 | }; |
| 6767 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6768 | class HStaticFieldSet FINAL : public HExpression<2> { |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6769 | public: |
| 6770 | HStaticFieldSet(HInstruction* cls, |
| 6771 | HInstruction* value, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6772 | ArtField* field, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6773 | DataType::Type field_type, |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6774 | MemberOffset field_offset, |
| Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6775 | bool is_volatile, |
| 6776 | uint32_t field_idx, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6777 | uint16_t declaring_class_def_index, |
| Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6778 | const DexFile& dex_file, |
| Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6779 | uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6780 | : HExpression(kStaticFieldSet, |
| 6781 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6782 | dex_pc), |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6783 | field_info_(field, |
| 6784 | field_offset, |
| Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6785 | field_type, |
| 6786 | is_volatile, |
| 6787 | field_idx, |
| 6788 | declaring_class_def_index, |
| Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6789 | dex_file) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6790 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6791 | SetRawInputAt(0, cls); |
| 6792 | SetRawInputAt(1, value); |
| 6793 | } |
| 6794 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6795 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6796 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6797 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6798 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6799 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6800 | |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6801 | HInstruction* GetValue() const { return InputAt(1); } |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6802 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6803 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
| Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6804 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6805 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6806 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6807 | protected: |
| 6808 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 6809 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6810 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6811 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6812 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6813 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6814 | "Too many packed fields."); |
| 6815 | |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6816 | const FieldInfo field_info_; |
| Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6817 | }; |
| 6818 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6819 | class HUnresolvedInstanceFieldGet FINAL : public HExpression<1> { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6820 | public: |
| 6821 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6822 | DataType::Type field_type, |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6823 | uint32_t field_index, |
| 6824 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6825 | : HExpression(kUnresolvedInstanceFieldGet, |
| 6826 | field_type, |
| 6827 | SideEffects::AllExceptGCDependency(), |
| 6828 | dex_pc), |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6829 | field_index_(field_index) { |
| 6830 | SetRawInputAt(0, obj); |
| 6831 | } |
| 6832 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6833 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6834 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6835 | bool CanThrow() const OVERRIDE { return true; } |
| 6836 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6837 | DataType::Type GetFieldType() const { return GetType(); } |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6838 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6839 | |
| 6840 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6841 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6842 | protected: |
| 6843 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 6844 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6845 | private: |
| 6846 | const uint32_t field_index_; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6847 | }; |
| 6848 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6849 | class HUnresolvedInstanceFieldSet FINAL : public HExpression<2> { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6850 | public: |
| 6851 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6852 | HInstruction* value, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6853 | DataType::Type field_type, |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6854 | uint32_t field_index, |
| 6855 | uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6856 | : HExpression(kUnresolvedInstanceFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6857 | field_index_(field_index) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6858 | SetPackedField<FieldTypeField>(field_type); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6859 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6860 | SetRawInputAt(0, obj); |
| 6861 | SetRawInputAt(1, value); |
| 6862 | } |
| 6863 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6864 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6865 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6866 | bool CanThrow() const OVERRIDE { return true; } |
| 6867 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6868 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6869 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6870 | |
| 6871 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6872 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6873 | protected: |
| 6874 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 6875 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6876 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6877 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6878 | static constexpr size_t kFieldFieldTypeSize = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6879 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6880 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6881 | kFieldFieldType + kFieldFieldTypeSize; |
| 6882 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6883 | "Too many packed fields."); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6884 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6885 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6886 | const uint32_t field_index_; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6887 | }; |
| 6888 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6889 | class HUnresolvedStaticFieldGet FINAL : public HExpression<0> { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6890 | public: |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6891 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6892 | uint32_t field_index, |
| 6893 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6894 | : HExpression(kUnresolvedStaticFieldGet, |
| 6895 | field_type, |
| 6896 | SideEffects::AllExceptGCDependency(), |
| 6897 | dex_pc), |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6898 | field_index_(field_index) { |
| 6899 | } |
| 6900 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6901 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6902 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6903 | bool CanThrow() const OVERRIDE { return true; } |
| 6904 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6905 | DataType::Type GetFieldType() const { return GetType(); } |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6906 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6907 | |
| 6908 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6909 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6910 | protected: |
| 6911 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 6912 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6913 | private: |
| 6914 | const uint32_t field_index_; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6915 | }; |
| 6916 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6917 | class HUnresolvedStaticFieldSet FINAL : public HExpression<1> { |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6918 | public: |
| 6919 | HUnresolvedStaticFieldSet(HInstruction* value, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6920 | DataType::Type field_type, |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6921 | uint32_t field_index, |
| 6922 | uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6923 | : HExpression(kUnresolvedStaticFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6924 | field_index_(field_index) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6925 | SetPackedField<FieldTypeField>(field_type); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6926 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6927 | SetRawInputAt(0, value); |
| 6928 | } |
| 6929 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6930 | bool IsClonable() const OVERRIDE { return true; } |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6931 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6932 | bool CanThrow() const OVERRIDE { return true; } |
| 6933 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6934 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6935 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6936 | |
| 6937 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6938 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6939 | protected: |
| 6940 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 6941 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6942 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6943 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6944 | static constexpr size_t kFieldFieldTypeSize = |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6945 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6946 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6947 | kFieldFieldType + kFieldFieldTypeSize; |
| 6948 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6949 | "Too many packed fields."); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6950 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6951 | |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6952 | const uint32_t field_index_; |
| Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6953 | }; |
| 6954 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6955 | // Implement the move-exception DEX instruction. |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 6956 | class HLoadException FINAL : public HExpression<0> { |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6957 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6958 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6959 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 6960 | } |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6961 | |
| David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6962 | bool CanBeNull() const OVERRIDE { return false; } |
| 6963 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6964 | DECLARE_INSTRUCTION(LoadException); |
| 6965 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6966 | protected: |
| 6967 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6968 | }; |
| 6969 | |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6970 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6971 | // Must not be removed because the runtime expects the TLS to get cleared. |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6972 | class HClearException FINAL : public HExpression<0> { |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6973 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6974 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6975 | : HExpression(kClearException, SideEffects::AllWrites(), dex_pc) { |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6976 | } |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6977 | |
| 6978 | DECLARE_INSTRUCTION(ClearException); |
| 6979 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6980 | protected: |
| 6981 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
| David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6982 | }; |
| 6983 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6984 | class HThrow FINAL : public HExpression<1> { |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6985 | public: |
| 6986 | HThrow(HInstruction* exception, uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6987 | : HExpression(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6988 | SetRawInputAt(0, exception); |
| 6989 | } |
| 6990 | |
| 6991 | bool IsControlFlow() const OVERRIDE { return true; } |
| 6992 | |
| 6993 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 6994 | |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6995 | bool CanThrow() const OVERRIDE { return true; } |
| 6996 | |
| Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 6997 | bool AlwaysThrows() const OVERRIDE { return true; } |
| 6998 | |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6999 | DECLARE_INSTRUCTION(Throw); |
| 7000 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7001 | protected: |
| 7002 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
| Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7003 | }; |
| 7004 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7005 | /** |
| 7006 | * Implementation strategies for the code generator of a HInstanceOf |
| 7007 | * or `HCheckCast`. |
| 7008 | */ |
| 7009 | enum class TypeCheckKind { |
| Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7010 | kUnresolvedCheck, // Check against an unresolved type. |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7011 | kExactCheck, // Can do a single class compare. |
| 7012 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 7013 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 7014 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 7015 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7016 | kArrayCheck, // No optimization yet when checking against a generic array. |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7017 | kBitstringCheck, // Compare the type check bitstring. |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7018 | kLast = kArrayCheck |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7019 | }; |
| 7020 | |
| Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 7021 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 7022 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7023 | // Note: HTypeCheckInstruction is just a helper class, not an abstract instruction with an |
| 7024 | // `IsTypeCheckInstruction()`. (New virtual methods in the HInstruction class have a high cost.) |
| 7025 | class HTypeCheckInstruction : public HVariableInputSizeInstruction { |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7026 | public: |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7027 | HTypeCheckInstruction(InstructionKind kind, |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7028 | DataType::Type type, |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7029 | HInstruction* object, |
| 7030 | HInstruction* target_class_or_null, |
| 7031 | TypeCheckKind check_kind, |
| 7032 | Handle<mirror::Class> klass, |
| 7033 | uint32_t dex_pc, |
| 7034 | ArenaAllocator* allocator, |
| 7035 | HIntConstant* bitstring_path_to_root, |
| 7036 | HIntConstant* bitstring_mask, |
| 7037 | SideEffects side_effects) |
| 7038 | : HVariableInputSizeInstruction( |
| 7039 | kind, |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7040 | type, |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7041 | side_effects, |
| 7042 | dex_pc, |
| 7043 | allocator, |
| 7044 | /* number_of_inputs */ check_kind == TypeCheckKind::kBitstringCheck ? 4u : 2u, |
| 7045 | kArenaAllocTypeCheckInputs), |
| 7046 | klass_(klass) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7047 | SetPackedField<TypeCheckKindField>(check_kind); |
| 7048 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7049 | SetPackedFlag<kFlagValidTargetClassRTI>(false); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7050 | SetRawInputAt(0, object); |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7051 | SetRawInputAt(1, target_class_or_null); |
| 7052 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_path_to_root != nullptr); |
| 7053 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_mask != nullptr); |
| 7054 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 7055 | DCHECK(target_class_or_null->IsNullConstant()); |
| 7056 | SetRawInputAt(2, bitstring_path_to_root); |
| 7057 | SetRawInputAt(3, bitstring_mask); |
| 7058 | } else { |
| 7059 | DCHECK(target_class_or_null->IsLoadClass()); |
| 7060 | } |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7061 | } |
| 7062 | |
| 7063 | HLoadClass* GetTargetClass() const { |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7064 | DCHECK_NE(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7065 | HInstruction* load_class = InputAt(1); |
| 7066 | DCHECK(load_class->IsLoadClass()); |
| 7067 | return load_class->AsLoadClass(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7068 | } |
| 7069 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7070 | uint32_t GetBitstringPathToRoot() const { |
| 7071 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7072 | HInstruction* path_to_root = InputAt(2); |
| 7073 | DCHECK(path_to_root->IsIntConstant()); |
| 7074 | return static_cast<uint32_t>(path_to_root->AsIntConstant()->GetValue()); |
| 7075 | } |
| 7076 | |
| 7077 | uint32_t GetBitstringMask() const { |
| 7078 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7079 | HInstruction* mask = InputAt(3); |
| 7080 | DCHECK(mask->IsIntConstant()); |
| 7081 | return static_cast<uint32_t>(mask->AsIntConstant()->GetValue()); |
| 7082 | } |
| 7083 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7084 | bool IsClonable() const OVERRIDE { return true; } |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7085 | bool CanBeMoved() const OVERRIDE { return true; } |
| 7086 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7087 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE { |
| 7088 | DCHECK(other->IsInstanceOf() || other->IsCheckCast()) << other->DebugName(); |
| 7089 | return GetPackedFields() == down_cast<const HTypeCheckInstruction*>(other)->GetPackedFields(); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7090 | } |
| 7091 | |
| Andreas Gampe | 3fbd3ad | 2018-03-26 21:14:46 +0000 | [diff] [blame] | 7092 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 7093 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 7094 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 7095 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 7096 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7097 | ReferenceTypeInfo GetTargetClassRTI() { |
| 7098 | if (GetPackedFlag<kFlagValidTargetClassRTI>()) { |
| 7099 | // Note: The is_exact flag from the return value should not be used. |
| 7100 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact */ true); |
| 7101 | } else { |
| 7102 | return ReferenceTypeInfo::CreateInvalid(); |
| 7103 | } |
| 7104 | } |
| 7105 | |
| 7106 | // Target class RTI is marked as valid by RTP if the klass_ is admissible. |
| 7107 | void SetValidTargetClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 7108 | DCHECK(klass_ != nullptr); |
| 7109 | SetPackedFlag<kFlagValidTargetClassRTI>(true); |
| 7110 | } |
| 7111 | |
| 7112 | Handle<mirror::Class> GetClass() const { |
| 7113 | return klass_; |
| 7114 | } |
| 7115 | |
| 7116 | protected: |
| 7117 | DEFAULT_COPY_CONSTRUCTOR(TypeCheckInstruction); |
| 7118 | |
| 7119 | private: |
| 7120 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 7121 | static constexpr size_t kFieldTypeCheckKindSize = |
| 7122 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 7123 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 7124 | static constexpr size_t kFlagValidTargetClassRTI = kFlagMustDoNullCheck + 1; |
| 7125 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagValidTargetClassRTI + 1; |
| 7126 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7127 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
| 7128 | |
| 7129 | Handle<mirror::Class> klass_; |
| 7130 | }; |
| 7131 | |
| 7132 | class HInstanceOf FINAL : public HTypeCheckInstruction { |
| 7133 | public: |
| 7134 | HInstanceOf(HInstruction* object, |
| 7135 | HInstruction* target_class_or_null, |
| 7136 | TypeCheckKind check_kind, |
| 7137 | Handle<mirror::Class> klass, |
| 7138 | uint32_t dex_pc, |
| 7139 | ArenaAllocator* allocator, |
| 7140 | HIntConstant* bitstring_path_to_root, |
| 7141 | HIntConstant* bitstring_mask) |
| 7142 | : HTypeCheckInstruction(kInstanceOf, |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7143 | DataType::Type::kBool, |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7144 | object, |
| 7145 | target_class_or_null, |
| 7146 | check_kind, |
| 7147 | klass, |
| 7148 | dex_pc, |
| 7149 | allocator, |
| 7150 | bitstring_path_to_root, |
| 7151 | bitstring_mask, |
| 7152 | SideEffectsForArchRuntimeCalls(check_kind)) {} |
| 7153 | |
| Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7154 | bool IsClonable() const OVERRIDE { return true; } |
| 7155 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7156 | bool NeedsEnvironment() const OVERRIDE { |
| 7157 | return CanCallRuntime(GetTypeCheckKind()); |
| 7158 | } |
| 7159 | |
| Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7160 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 7161 | // Mips currently does runtime calls for any other checks. |
| 7162 | return check_kind != TypeCheckKind::kExactCheck; |
| 7163 | } |
| 7164 | |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7165 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7166 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7167 | } |
| 7168 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7169 | DECLARE_INSTRUCTION(InstanceOf); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7170 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7171 | protected: |
| 7172 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7173 | }; |
| 7174 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7175 | class HBoundType FINAL : public HExpression<1> { |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7176 | public: |
| Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 7177 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7178 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7179 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 7180 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 7181 | SetPackedFlag<kFlagCanBeNull>(true); |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7182 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7183 | SetRawInputAt(0, input); |
| 7184 | } |
| 7185 | |
| Artem Serov | 4d277ba | 2018-06-05 20:54:42 +0100 | [diff] [blame] | 7186 | bool InstructionDataEquals(const HInstruction* other) const OVERRIDE; |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7187 | bool IsClonable() const OVERRIDE { return true; } |
| 7188 | |
| David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7189 | // {Get,Set}Upper* should only be used in reference type propagation. |
| Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7190 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7191 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
| David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7192 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7193 | |
| Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7194 | void SetCanBeNull(bool can_be_null) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7195 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 7196 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7197 | } |
| 7198 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7199 | bool CanBeNull() const OVERRIDE { return GetPackedFlag<kFlagCanBeNull>(); } |
| Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7200 | |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7201 | DECLARE_INSTRUCTION(BoundType); |
| 7202 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7203 | protected: |
| 7204 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 7205 | |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7206 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7207 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 7208 | // is false then CanBeNull() cannot be true). |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7209 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfGenericPackedBits; |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7210 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 7211 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 7212 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7213 | |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7214 | // 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] | 7215 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 7216 | // It is used to bound the type in cases like: |
| 7217 | // if (x instanceof ClassX) { |
| 7218 | // // uper_bound_ will be ClassX |
| 7219 | // } |
| David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7220 | ReferenceTypeInfo upper_bound_; |
| Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7221 | }; |
| 7222 | |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7223 | class HCheckCast FINAL : public HTypeCheckInstruction { |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7224 | public: |
| 7225 | HCheckCast(HInstruction* object, |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7226 | HInstruction* target_class_or_null, |
| Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7227 | TypeCheckKind check_kind, |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7228 | Handle<mirror::Class> klass, |
| 7229 | uint32_t dex_pc, |
| 7230 | ArenaAllocator* allocator, |
| 7231 | HIntConstant* bitstring_path_to_root, |
| 7232 | HIntConstant* bitstring_mask) |
| 7233 | : HTypeCheckInstruction(kCheckCast, |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7234 | DataType::Type::kVoid, |
| Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7235 | object, |
| 7236 | target_class_or_null, |
| 7237 | check_kind, |
| 7238 | klass, |
| 7239 | dex_pc, |
| 7240 | allocator, |
| 7241 | bitstring_path_to_root, |
| 7242 | bitstring_mask, |
| 7243 | SideEffects::CanTriggerGC()) {} |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7244 | |
| Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7245 | bool IsClonable() const OVERRIDE { return true; } |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7246 | bool NeedsEnvironment() const OVERRIDE { |
| 7247 | // Instruction may throw a CheckCastError. |
| 7248 | return true; |
| 7249 | } |
| 7250 | |
| 7251 | bool CanThrow() const OVERRIDE { return true; } |
| 7252 | |
| Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7253 | DECLARE_INSTRUCTION(CheckCast); |
| 7254 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7255 | protected: |
| 7256 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
| Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7257 | }; |
| 7258 | |
| Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7259 | /** |
| 7260 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 7261 | * @details We define the combined barrier types that are actually required |
| 7262 | * by the Java Memory Model, rather than using exactly the terminology from |
| 7263 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 7264 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 7265 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 7266 | * The current recipe is as follows: |
| 7267 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 7268 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 7269 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 7270 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 7271 | * class has final fields. |
| 7272 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 7273 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 7274 | */ |
| 7275 | enum MemBarrierKind { |
| 7276 | kAnyStore, |
| 7277 | kLoadAny, |
| 7278 | kStoreStore, |
| 7279 | kAnyAny, |
| 7280 | kNTStoreStore, |
| 7281 | kLastBarrierKind = kNTStoreStore |
| 7282 | }; |
| 7283 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 7284 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7285 | class HMemoryBarrier FINAL : public HExpression<0> { |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7286 | public: |
| Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7287 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7288 | : HExpression(kMemoryBarrier, |
| 7289 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 7290 | dex_pc) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7291 | SetPackedField<BarrierKindField>(barrier_kind); |
| 7292 | } |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7293 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7294 | bool IsClonable() const OVERRIDE { return true; } |
| 7295 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7296 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7297 | |
| 7298 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 7299 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7300 | protected: |
| 7301 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 7302 | |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7303 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7304 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 7305 | static constexpr size_t kFieldBarrierKindSize = |
| 7306 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 7307 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 7308 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 7309 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 7310 | "Too many packed fields."); |
| 7311 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
| Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7312 | }; |
| 7313 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7314 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 7315 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 7316 | // (i.e. make visible) the specified object to another thread. |
| 7317 | // |
| 7318 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 7319 | // for all final fields (that were set) at the end of the invoked constructor. |
| 7320 | // |
| 7321 | // The constructor fence models the freeze actions for the final fields of an object |
| 7322 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 7323 | // have a per-object affinity; two separate objects being constructed get two separate |
| 7324 | // constructor fences. |
| 7325 | // |
| 7326 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 7327 | // the freezes would happen at the end of *that* constructor being invoked). |
| 7328 | // |
| 7329 | // The memory model guarantees that when the object being constructed is "published" after |
| 7330 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 7331 | // writes must be observable on other threads (once they observe that publication). |
| 7332 | // |
| 7333 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 7334 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 7335 | // yet the freeze must also extend to them). |
| 7336 | // |
| 7337 | // Constructor example: |
| 7338 | // |
| 7339 | // class HasFinal { |
| 7340 | // final int field; Optimizing IR for <init>()V: |
| 7341 | // HasFinal() { |
| 7342 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 7343 | // // freeze(this.field); HConstructorFence(this) |
| 7344 | // } HReturn |
| 7345 | // } |
| 7346 | // |
| 7347 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 7348 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 7349 | // of the object which effectively writes the class pointer "final field". |
| 7350 | // |
| 7351 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 7352 | // |
| 7353 | // class Object { |
| 7354 | // private final Class header; |
| 7355 | // } |
| 7356 | // |
| 7357 | // Java code: Optimizing IR: |
| 7358 | // |
| 7359 | // T new_instance<T>() { |
| 7360 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 7361 | // obj.header = T.class; // header write is done by above call. |
| 7362 | // // freeze(obj.header) HConstructorFence(obj) |
| 7363 | // return (T)obj; |
| 7364 | // } |
| 7365 | // |
| 7366 | // See also: |
| 7367 | // * CompilerDriver::RequiresConstructorBarrier |
| 7368 | // * QuasiAtomic::ThreadFenceForConstructor |
| 7369 | // |
| 7370 | class HConstructorFence FINAL : public HVariableInputSizeInstruction { |
| 7371 | // A fence has variable inputs because the inputs can be removed |
| 7372 | // after prepare_for_register_allocation phase. |
| 7373 | // (TODO: In the future a fence could freeze multiple objects |
| 7374 | // after merging two fences together.) |
| 7375 | public: |
| 7376 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 7377 | // |
| 7378 | // It makes sense in the following situations: |
| 7379 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 7380 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 7381 | // |
| 7382 | // After construction the `fence_object` becomes the 0th input. |
| 7383 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 7384 | // about the associated object. |
| 7385 | HConstructorFence(HInstruction* fence_object, |
| 7386 | uint32_t dex_pc, |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7387 | ArenaAllocator* allocator) |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7388 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 7389 | // constraints described in the class header. We claim that these SideEffects constraints |
| 7390 | // enforce a superset of the real constraints. |
| 7391 | // |
| 7392 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 7393 | // |
| 7394 | // * To prevent reordering of the publication stores: |
| 7395 | // ----> "Reads of objects" is the initial SideEffect. |
| 7396 | // * For every primitive final field store in the constructor: |
| 7397 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 7398 | // * If there are any stores to reference final fields in the constructor: |
| 7399 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 7400 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 7401 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 7402 | // |
| 7403 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 7404 | // even more conservative approach than the one described above, and prevents all of the |
| 7405 | // above reordering without analyzing any of the instructions in the constructor. |
| 7406 | // |
| 7407 | // If in a later phase we discover that there are no writes to reference final fields, |
| 7408 | // we can refine the side effect to a smaller set of type reads (see above constraints). |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7409 | : HVariableInputSizeInstruction(kConstructorFence, |
| 7410 | SideEffects::AllReads(), |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7411 | dex_pc, |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7412 | allocator, |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7413 | /* number_of_inputs */ 1, |
| 7414 | kArenaAllocConstructorFenceInputs) { |
| 7415 | DCHECK(fence_object != nullptr); |
| 7416 | SetRawInputAt(0, fence_object); |
| 7417 | } |
| 7418 | |
| 7419 | // The object associated with this constructor fence. |
| 7420 | // |
| 7421 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 7422 | // as all constructor fence inputs are removed there). |
| 7423 | HInstruction* GetFenceObject() const { |
| 7424 | return InputAt(0); |
| 7425 | } |
| 7426 | |
| 7427 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 7428 | // - Delete `fence_use` from `this`'s use list. |
| 7429 | // - Delete `this` from `fence_use`'s inputs list. |
| 7430 | // - If the `fence_use` is dead, remove it from the graph. |
| 7431 | // |
| 7432 | // A fence is considered dead once it no longer has any uses |
| 7433 | // and all of the inputs are dead. |
| 7434 | // |
| 7435 | // This must *not* be called during/after prepare_for_register_allocation, |
| 7436 | // because that removes all the inputs to the fences but the fence is actually |
| 7437 | // still considered live. |
| Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7438 | // |
| 7439 | // Returns how many HConstructorFence instructions were removed from graph. |
| 7440 | static size_t RemoveConstructorFences(HInstruction* instruction); |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7441 | |
| Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7442 | // Combine all inputs of `this` and `other` instruction and remove |
| 7443 | // `other` from the graph. |
| 7444 | // |
| 7445 | // Inputs are unique after the merge. |
| 7446 | // |
| 7447 | // Requirement: `this` must not be the same as `other. |
| 7448 | void Merge(HConstructorFence* other); |
| 7449 | |
| Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7450 | // Check if this constructor fence is protecting |
| 7451 | // an HNewInstance or HNewArray that is also the immediate |
| 7452 | // predecessor of `this`. |
| 7453 | // |
| Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7454 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 7455 | // to be one of the inputs of `this`. |
| 7456 | // |
| Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7457 | // Returns the associated HNewArray or HNewInstance, |
| 7458 | // or null otherwise. |
| Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7459 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
| Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7460 | |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7461 | DECLARE_INSTRUCTION(ConstructorFence); |
| 7462 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7463 | protected: |
| 7464 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
| Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7465 | }; |
| 7466 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7467 | class HMonitorOperation FINAL : public HExpression<1> { |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7468 | public: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7469 | enum class OperationKind { |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7470 | kEnter, |
| 7471 | kExit, |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7472 | kLast = kExit |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7473 | }; |
| 7474 | |
| 7475 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7476 | : HExpression(kMonitorOperation, |
| 7477 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 7478 | dex_pc) { |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7479 | SetPackedField<OperationKindField>(kind); |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7480 | SetRawInputAt(0, object); |
| 7481 | } |
| 7482 | |
| Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7483 | // Instruction may go into runtime, so we need an environment. |
| 7484 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7485 | |
| 7486 | bool CanThrow() const OVERRIDE { |
| 7487 | // Verifier guarantees that monitor-exit cannot throw. |
| 7488 | // This is important because it allows the HGraphBuilder to remove |
| 7489 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 7490 | return IsEnter(); |
| 7491 | } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7492 | |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7493 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 7494 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7495 | |
| 7496 | DECLARE_INSTRUCTION(MonitorOperation); |
| 7497 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7498 | protected: |
| 7499 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 7500 | |
| Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7501 | private: |
| Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7502 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 7503 | static constexpr size_t kFieldOperationKindSize = |
| 7504 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 7505 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 7506 | kFieldOperationKind + kFieldOperationKindSize; |
| 7507 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7508 | "Too many packed fields."); |
| 7509 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
| Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7510 | }; |
| 7511 | |
| Vladimir Marko | fcb503c | 2016-05-18 12:48:17 +0100 | [diff] [blame] | 7512 | class HSelect FINAL : public HExpression<3> { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7513 | public: |
| 7514 | HSelect(HInstruction* condition, |
| 7515 | HInstruction* true_value, |
| 7516 | HInstruction* false_value, |
| 7517 | uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7518 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7519 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 7520 | |
| 7521 | // First input must be `true_value` or `false_value` to allow codegens to |
| 7522 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 7523 | // that architectures which implement HSelect as a conditional move also |
| 7524 | // will not need to invert the condition. |
| 7525 | SetRawInputAt(0, false_value); |
| 7526 | SetRawInputAt(1, true_value); |
| 7527 | SetRawInputAt(2, condition); |
| 7528 | } |
| 7529 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7530 | bool IsClonable() const OVERRIDE { return true; } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7531 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 7532 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 7533 | HInstruction* GetCondition() const { return InputAt(2); } |
| 7534 | |
| 7535 | bool CanBeMoved() const OVERRIDE { return true; } |
| Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7536 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 7537 | return true; |
| 7538 | } |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7539 | |
| 7540 | bool CanBeNull() const OVERRIDE { |
| 7541 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 7542 | } |
| 7543 | |
| 7544 | DECLARE_INSTRUCTION(Select); |
| 7545 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7546 | protected: |
| 7547 | DEFAULT_COPY_CONSTRUCTOR(Select); |
| David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7548 | }; |
| 7549 | |
| Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 7550 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7551 | public: |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7552 | MoveOperands(Location source, |
| 7553 | Location destination, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7554 | DataType::Type type, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7555 | HInstruction* instruction) |
| 7556 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7557 | |
| 7558 | Location GetSource() const { return source_; } |
| 7559 | Location GetDestination() const { return destination_; } |
| 7560 | |
| 7561 | void SetSource(Location value) { source_ = value; } |
| 7562 | void SetDestination(Location value) { destination_ = value; } |
| 7563 | |
| 7564 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 7565 | // destination (but not the source). |
| 7566 | Location MarkPending() { |
| 7567 | DCHECK(!IsPending()); |
| 7568 | Location dest = destination_; |
| 7569 | destination_ = Location::NoLocation(); |
| 7570 | return dest; |
| 7571 | } |
| 7572 | |
| 7573 | void ClearPending(Location dest) { |
| 7574 | DCHECK(IsPending()); |
| 7575 | destination_ = dest; |
| 7576 | } |
| 7577 | |
| 7578 | bool IsPending() const { |
| Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7579 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 7580 | return destination_.IsInvalid() && source_.IsValid(); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7581 | } |
| 7582 | |
| 7583 | // True if this blocks a move from the given location. |
| 7584 | bool Blocks(Location loc) const { |
| Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 7585 | return !IsEliminated() && source_.OverlapsWith(loc); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7586 | } |
| 7587 | |
| 7588 | // A move is redundant if it's been eliminated, if its source and |
| 7589 | // destination are the same, or if its destination is unneeded. |
| 7590 | bool IsRedundant() const { |
| 7591 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 7592 | } |
| 7593 | |
| 7594 | // We clear both operands to indicate move that's been eliminated. |
| 7595 | void Eliminate() { |
| 7596 | source_ = destination_ = Location::NoLocation(); |
| 7597 | } |
| 7598 | |
| 7599 | bool IsEliminated() const { |
| 7600 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 7601 | return source_.IsInvalid(); |
| 7602 | } |
| 7603 | |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7604 | DataType::Type GetType() const { return type_; } |
| Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7605 | |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7606 | bool Is64BitMove() const { |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7607 | return DataType::Is64BitType(type_); |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7608 | } |
| 7609 | |
| Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7610 | HInstruction* GetInstruction() const { return instruction_; } |
| 7611 | |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7612 | private: |
| 7613 | Location source_; |
| 7614 | Location destination_; |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7615 | // The type this move is for. |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7616 | DataType::Type type_; |
| Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7617 | // The instruction this move is assocatied with. Null when this move is |
| 7618 | // for moving an input in the expected locations of user (including a phi user). |
| 7619 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 7620 | // in the same parallel move. |
| 7621 | HInstruction* instruction_; |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7622 | }; |
| 7623 | |
| Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7624 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 7625 | |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7626 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 7627 | |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7628 | class HParallelMove FINAL : public HExpression<0> { |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7629 | public: |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7630 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
| Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7631 | : HExpression(kParallelMove, SideEffects::None(), dex_pc), |
| Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7632 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7633 | moves_.reserve(kDefaultNumberOfMoves); |
| 7634 | } |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7635 | |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7636 | void AddMove(Location source, |
| 7637 | Location destination, |
| Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7638 | DataType::Type type, |
| Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7639 | HInstruction* instruction) { |
| Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 7640 | DCHECK(source.IsValid()); |
| 7641 | DCHECK(destination.IsValid()); |
| Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7642 | if (kIsDebugBuild) { |
| 7643 | if (instruction != nullptr) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7644 | for (const MoveOperands& move : moves_) { |
| 7645 | if (move.GetInstruction() == instruction) { |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7646 | // Special case the situation where the move is for the spill slot |
| 7647 | // of the instruction. |
| 7648 | if ((GetPrevious() == instruction) |
| 7649 | || ((GetPrevious() == nullptr) |
| 7650 | && instruction->IsPhi() |
| 7651 | && instruction->GetBlock() == GetBlock())) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7652 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
| Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7653 | << "Doing parallel moves for the same instruction."; |
| 7654 | } else { |
| 7655 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 7656 | } |
| 7657 | } |
| Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 7658 | } |
| 7659 | } |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7660 | for (const MoveOperands& move : moves_) { |
| 7661 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
| Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7662 | << "Overlapped destination for two moves in a parallel move: " |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7663 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
| Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7664 | << source << " ==> " << destination; |
| Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7665 | } |
| Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7666 | } |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7667 | moves_.emplace_back(source, destination, type, instruction); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7668 | } |
| 7669 | |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7670 | MoveOperands* MoveOperandsAt(size_t index) { |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7671 | return &moves_[index]; |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7672 | } |
| 7673 | |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7674 | size_t NumMoves() const { return moves_.size(); } |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7675 | |
| Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 7676 | DECLARE_INSTRUCTION(ParallelMove); |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7677 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7678 | protected: |
| 7679 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 7680 | |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7681 | private: |
| Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7682 | ArenaVector<MoveOperands> moves_; |
| Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7683 | }; |
| 7684 | |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7685 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 7686 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 7687 | // never used across anything that can trigger GC. |
| 7688 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 7689 | // So we represent it by the type `DataType::Type::kInt`. |
| 7690 | class HIntermediateAddress FINAL : public HExpression<2> { |
| 7691 | public: |
| 7692 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
| Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7693 | : HExpression(kIntermediateAddress, |
| 7694 | DataType::Type::kInt32, |
| 7695 | SideEffects::DependsOnGC(), |
| 7696 | dex_pc) { |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7697 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 7698 | DataType::Size(DataType::Type::kReference)) |
| 7699 | << "kPrimInt and kPrimNot have different sizes."; |
| 7700 | SetRawInputAt(0, base_address); |
| 7701 | SetRawInputAt(1, offset); |
| 7702 | } |
| 7703 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7704 | bool IsClonable() const OVERRIDE { return true; } |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7705 | bool CanBeMoved() const OVERRIDE { return true; } |
| 7706 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 7707 | return true; |
| 7708 | } |
| 7709 | bool IsActualObject() const OVERRIDE { return false; } |
| 7710 | |
| 7711 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 7712 | HInstruction* GetOffset() const { return InputAt(1); } |
| 7713 | |
| 7714 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 7715 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7716 | protected: |
| 7717 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
| xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7718 | }; |
| 7719 | |
| 7720 | |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7721 | } // namespace art |
| 7722 | |
| Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 7723 | #include "nodes_vector.h" |
| 7724 | |
| Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7725 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 7726 | #include "nodes_shared.h" |
| 7727 | #endif |
| Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7728 | #ifdef ART_ENABLE_CODEGEN_mips |
| 7729 | #include "nodes_mips.h" |
| 7730 | #endif |
| Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7731 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 7732 | #include "nodes_x86.h" |
| 7733 | #endif |
| 7734 | |
| 7735 | namespace art { |
| 7736 | |
| Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7737 | class OptimizingCompilerStats; |
| 7738 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7739 | class HGraphVisitor : public ValueObject { |
| 7740 | public: |
| Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7741 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7742 | : stats_(stats), |
| 7743 | graph_(graph) {} |
| Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 7744 | virtual ~HGraphVisitor() {} |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7745 | |
| Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7746 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7747 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 7748 | |
| Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7749 | // Visit the graph following basic block insertion order. |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7750 | void VisitInsertionOrder(); |
| 7751 | |
| Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7752 | // Visit the graph following dominator tree reverse post-order. |
| 7753 | void VisitReversePostOrder(); |
| 7754 | |
| Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 7755 | HGraph* GetGraph() const { return graph_; } |
| Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7756 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7757 | // Visit functions for instruction classes. |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7758 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7759 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 7760 | |
| 7761 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7762 | |
| 7763 | #undef DECLARE_VISIT_INSTRUCTION |
| 7764 | |
| Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7765 | protected: |
| 7766 | OptimizingCompilerStats* stats_; |
| 7767 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7768 | private: |
| Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 7769 | HGraph* const graph_; |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7770 | |
| 7771 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 7772 | }; |
| 7773 | |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7774 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 7775 | public: |
| Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7776 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7777 | : HGraphVisitor(graph, stats) {} |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7778 | virtual ~HGraphDelegateVisitor() {} |
| 7779 | |
| 7780 | // Visit functions that delegate to to super class. |
| 7781 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
| Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 7782 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
| Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7783 | |
| 7784 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7785 | |
| 7786 | #undef DECLARE_VISIT_INSTRUCTION |
| 7787 | |
| 7788 | private: |
| 7789 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 7790 | }; |
| 7791 | |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7792 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 7793 | // and remove the old instruction. |
| 7794 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 7795 | |
| 7796 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 7797 | // |
| 7798 | // Used for testing individual instruction cloner. |
| 7799 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 7800 | public: |
| 7801 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
| Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7802 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7803 | |
| 7804 | void VisitInstruction(HInstruction* instruction) OVERRIDE { |
| 7805 | if (instruction->IsClonable()) { |
| 7806 | ReplaceInstrOrPhiByClone(instruction); |
| Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7807 | instr_replaced_by_clones_count_++; |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7808 | } |
| 7809 | } |
| 7810 | |
| Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7811 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7812 | |
| 7813 | private: |
| Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7814 | size_t instr_replaced_by_clones_count_; |
| Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7815 | |
| 7816 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 7817 | }; |
| 7818 | |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7819 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7820 | // of an inner loop. The order in which the blocks are iterated is on their |
| 7821 | // block id. |
| 7822 | class HBlocksInLoopIterator : public ValueObject { |
| 7823 | public: |
| 7824 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 7825 | : blocks_in_loop_(info.GetBlocks()), |
| 7826 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 7827 | index_(0) { |
| 7828 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 7829 | Advance(); |
| 7830 | } |
| 7831 | } |
| 7832 | |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7833 | bool Done() const { return index_ == blocks_.size(); } |
| 7834 | HBasicBlock* Current() const { return blocks_[index_]; } |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7835 | void Advance() { |
| 7836 | ++index_; |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7837 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7838 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 7839 | break; |
| 7840 | } |
| 7841 | } |
| 7842 | } |
| 7843 | |
| 7844 | private: |
| 7845 | const BitVector& blocks_in_loop_; |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7846 | const ArenaVector<HBasicBlock*>& blocks_; |
| Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7847 | size_t index_; |
| 7848 | |
| 7849 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 7850 | }; |
| 7851 | |
| Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7852 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7853 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 7854 | // post order. |
| 7855 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 7856 | public: |
| 7857 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 7858 | : blocks_in_loop_(info.GetBlocks()), |
| 7859 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 7860 | index_(0) { |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7861 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
| Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7862 | Advance(); |
| 7863 | } |
| 7864 | } |
| 7865 | |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7866 | bool Done() const { return index_ == blocks_.size(); } |
| 7867 | HBasicBlock* Current() const { return blocks_[index_]; } |
| Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7868 | void Advance() { |
| 7869 | ++index_; |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7870 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 7871 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
| Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7872 | break; |
| 7873 | } |
| 7874 | } |
| 7875 | } |
| 7876 | |
| 7877 | private: |
| 7878 | const BitVector& blocks_in_loop_; |
| Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7879 | const ArenaVector<HBasicBlock*>& blocks_; |
| Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7880 | size_t index_; |
| 7881 | |
| 7882 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 7883 | }; |
| 7884 | |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7885 | // Returns int64_t value of a properly typed constant. |
| Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7886 | inline int64_t Int64FromConstant(HConstant* constant) { |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7887 | if (constant->IsIntConstant()) { |
| 7888 | return constant->AsIntConstant()->GetValue(); |
| 7889 | } else if (constant->IsLongConstant()) { |
| 7890 | return constant->AsLongConstant()->GetValue(); |
| 7891 | } else { |
| Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 7892 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
| David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7893 | return 0; |
| 7894 | } |
| Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7895 | } |
| 7896 | |
| Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7897 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 7898 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 7899 | if (instruction->IsIntConstant()) { |
| 7900 | *value = instruction->AsIntConstant()->GetValue(); |
| 7901 | return true; |
| 7902 | } else if (instruction->IsLongConstant()) { |
| 7903 | *value = instruction->AsLongConstant()->GetValue(); |
| 7904 | return true; |
| 7905 | } else if (instruction->IsNullConstant()) { |
| 7906 | *value = 0; |
| 7907 | return true; |
| 7908 | } |
| 7909 | return false; |
| 7910 | } |
| 7911 | |
| Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 7912 | // Returns true iff instruction is the given integral constant. |
| 7913 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 7914 | int64_t val = 0; |
| 7915 | return IsInt64AndGet(instruction, &val) && val == value; |
| 7916 | } |
| 7917 | |
| 7918 | // Returns true iff instruction is a zero bit pattern. |
| 7919 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 7920 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 7921 | } |
| 7922 | |
| Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7923 | // Implement HInstruction::Is##type() for concrete instructions. |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7924 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7925 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } |
| 7926 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7927 | #undef INSTRUCTION_TYPE_CHECK |
| 7928 | |
| Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7929 | // Implement HInstruction::Is##type() for abstract instructions. |
| Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7930 | #define INSTRUCTION_TYPE_CHECK_RESULT(type, super) \ |
| 7931 | std::is_base_of<BaseType, H##type>::value, |
| 7932 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 7933 | inline bool HInstruction::Is##type() const { \ |
| 7934 | DCHECK_LT(GetKind(), kLastInstructionKind); \ |
| 7935 | using BaseType = H##type; \ |
| 7936 | static constexpr bool results[] = { \ |
| 7937 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK_RESULT) \ |
| 7938 | }; \ |
| 7939 | return results[static_cast<size_t>(GetKind())]; \ |
| 7940 | } |
| 7941 | |
| 7942 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7943 | #undef INSTRUCTION_TYPE_CHECK |
| Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7944 | #undef INSTRUCTION_TYPE_CHECK_RESULT |
| Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7945 | |
| 7946 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7947 | inline const H##type* HInstruction::As##type() const { \ |
| 7948 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 7949 | } \ |
| 7950 | inline H##type* HInstruction::As##type() { \ |
| 7951 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 7952 | } |
| 7953 | |
| Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7954 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 7955 | #undef INSTRUCTION_TYPE_CAST |
| 7956 | |
| Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7957 | |
| Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 7958 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 7959 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 7960 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 7961 | size_t number_of_new_blocks, |
| 7962 | size_t after) { |
| 7963 | DCHECK_LT(after, blocks->size()); |
| 7964 | size_t old_size = blocks->size(); |
| 7965 | size_t new_size = old_size + number_of_new_blocks; |
| 7966 | blocks->resize(new_size); |
| 7967 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 7968 | } |
| 7969 | |
| Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7970 | /* |
| 7971 | * Hunt "under the hood" of array lengths (leading to array references), |
| 7972 | * null checks (also leading to array references), and new arrays |
| 7973 | * (leading to the actual length). This makes it more likely related |
| 7974 | * instructions become actually comparable. |
| 7975 | */ |
| 7976 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 7977 | while (instruction->IsArrayLength() || |
| 7978 | instruction->IsNullCheck() || |
| 7979 | instruction->IsNewArray()) { |
| 7980 | instruction = instruction->IsNewArray() |
| 7981 | ? instruction->AsNewArray()->GetLength() |
| 7982 | : instruction->InputAt(0); |
| 7983 | } |
| 7984 | return instruction; |
| 7985 | } |
| 7986 | |
| Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 7987 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 7988 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 7989 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 7990 | |
| Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7991 | } // namespace art |
| 7992 | |
| 7993 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |