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" |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 32 | #include "art_method.h" |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 33 | #include "data_type.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 34 | #include "deoptimization_kind.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 35 | #include "dex/dex_file.h" |
| 36 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 37 | #include "dex/invoke_type.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 38 | #include "dex/method_reference.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 39 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 40 | #include "handle.h" |
| 41 | #include "handle_scope.h" |
Nicolas Geoffray | 762869d | 2016-07-15 15:28:35 +0100 | [diff] [blame] | 42 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 43 | #include "locations.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 44 | #include "mirror/class.h" |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 45 | #include "mirror/method_type.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 46 | #include "offsets.h" |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 47 | #include "utils/intrusive_forward_list.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 48 | |
| 49 | namespace art { |
| 50 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 51 | class ArenaStack; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 52 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 53 | class HBasicBlock; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 54 | class HConstructorFence; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 55 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 56 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 57 | class HEnvironment; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 58 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 59 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 60 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 61 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 62 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 63 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 64 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 65 | class HNullConstant; |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 66 | class HParameterValue; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 67 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 68 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 69 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 70 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 71 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 72 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 73 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 74 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 75 | namespace mirror { |
| 76 | class DexCache; |
| 77 | } // namespace mirror |
| 78 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 79 | static const int kDefaultNumberOfBlocks = 8; |
| 80 | static const int kDefaultNumberOfSuccessors = 2; |
| 81 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 82 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 83 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 84 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 85 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 86 | // The maximum (meaningful) distance (31) that can be used in an integer shift/rotate operation. |
| 87 | static constexpr int32_t kMaxIntShiftDistance = 0x1f; |
| 88 | // The maximum (meaningful) distance (63) that can be used in a long shift/rotate operation. |
| 89 | static constexpr int32_t kMaxLongShiftDistance = 0x3f; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 90 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 91 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 92 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 93 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 94 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 95 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 96 | static constexpr uint32_t kNoDexPc = -1; |
| 97 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 98 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 99 | // For the purposes of the compiler, the dex files must actually be the same object |
| 100 | // if we want to safely treat them as the same. This is especially important for JIT |
| 101 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 102 | // times and provide different class resolution but no two class loaders should ever |
| 103 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 104 | // all sorts of weird failures. |
| 105 | return &lhs == &rhs; |
| 106 | } |
| 107 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 108 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 109 | // All types. |
| 110 | kCondEQ, // == |
| 111 | kCondNE, // != |
| 112 | // Signed integers and floating-point numbers. |
| 113 | kCondLT, // < |
| 114 | kCondLE, // <= |
| 115 | kCondGT, // > |
| 116 | kCondGE, // >= |
| 117 | // Unsigned integers. |
| 118 | kCondB, // < |
| 119 | kCondBE, // <= |
| 120 | kCondA, // > |
| 121 | kCondAE, // >= |
Scott Wakeling | 2c76e06 | 2016-08-31 09:48:54 +0100 | [diff] [blame] | 122 | // First and last aliases. |
| 123 | kCondFirst = kCondEQ, |
| 124 | kCondLast = kCondAE, |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 127 | enum GraphAnalysisResult { |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 128 | kAnalysisSkipped, |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 129 | kAnalysisInvalidBytecode, |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 130 | kAnalysisFailThrowCatchLoop, |
| 131 | kAnalysisFailAmbiguousArrayOp, |
| 132 | kAnalysisSuccess, |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
Andreas Gampe | 9186ced | 2016-12-12 14:28:21 -0800 | [diff] [blame] | 135 | template <typename T> |
| 136 | static inline typename std::make_unsigned<T>::type MakeUnsigned(T x) { |
| 137 | return static_cast<typename std::make_unsigned<T>::type>(x); |
| 138 | } |
| 139 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 140 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 141 | public: |
| 142 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 143 | |
| 144 | void AddInstruction(HInstruction* instruction); |
| 145 | void RemoveInstruction(HInstruction* instruction); |
| 146 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 147 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 148 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 149 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 150 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 151 | // Return true if this list contains `instruction`. |
| 152 | bool Contains(HInstruction* instruction) const; |
| 153 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 154 | // Return true if `instruction1` is found before `instruction2` in |
| 155 | // this instruction list and false otherwise. Abort if none |
| 156 | // of these instructions is found. |
| 157 | bool FoundBefore(const HInstruction* instruction1, |
| 158 | const HInstruction* instruction2) const; |
| 159 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 160 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 161 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 162 | |
| 163 | // Update the block of all instructions to be `block`. |
| 164 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 165 | |
| 166 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 167 | void AddBefore(HInstruction* cursor, const HInstructionList& instruction_list); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 168 | void Add(const HInstructionList& instruction_list); |
| 169 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 170 | // Return the number of instructions in the list. This is an expensive operation. |
| 171 | size_t CountSize() const; |
| 172 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 173 | private: |
| 174 | HInstruction* first_instruction_; |
| 175 | HInstruction* last_instruction_; |
| 176 | |
| 177 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 178 | friend class HGraph; |
| 179 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 180 | friend class HInstructionIterator; |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 181 | friend class HInstructionIteratorHandleChanges; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 182 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 183 | |
| 184 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 185 | }; |
| 186 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 187 | class ReferenceTypeInfo : ValueObject { |
| 188 | public: |
| 189 | typedef Handle<mirror::Class> TypeHandle; |
| 190 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 191 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact); |
| 192 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 193 | static ReferenceTypeInfo Create(TypeHandle type_handle) REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 94ab38f | 2016-06-21 17:48:19 +0100 | [diff] [blame] | 194 | return Create(type_handle, type_handle->CannotBeAssignedFromOtherTypes()); |
| 195 | } |
| 196 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 197 | static ReferenceTypeInfo CreateUnchecked(TypeHandle type_handle, bool is_exact) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 198 | return ReferenceTypeInfo(type_handle, is_exact); |
| 199 | } |
| 200 | |
| 201 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 202 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 203 | static bool IsValidHandle(TypeHandle handle) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 204 | return handle.GetReference() != nullptr; |
| 205 | } |
| 206 | |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 207 | bool IsValid() const { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 208 | return IsValidHandle(type_handle_); |
| 209 | } |
| 210 | |
| 211 | bool IsExact() const { return is_exact_; } |
| 212 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 213 | bool IsObjectClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 214 | DCHECK(IsValid()); |
| 215 | return GetTypeHandle()->IsObjectClass(); |
| 216 | } |
| 217 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 218 | bool IsStringClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 219 | DCHECK(IsValid()); |
| 220 | return GetTypeHandle()->IsStringClass(); |
| 221 | } |
| 222 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 223 | bool IsObjectArray() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 224 | DCHECK(IsValid()); |
| 225 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 226 | } |
| 227 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 228 | bool IsInterface() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 229 | DCHECK(IsValid()); |
| 230 | return GetTypeHandle()->IsInterface(); |
| 231 | } |
| 232 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 233 | bool IsArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 234 | DCHECK(IsValid()); |
| 235 | return GetTypeHandle()->IsArrayClass(); |
| 236 | } |
| 237 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 238 | bool IsPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 239 | DCHECK(IsValid()); |
| 240 | return GetTypeHandle()->IsPrimitiveArray(); |
| 241 | } |
| 242 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 243 | bool IsNonPrimitiveArrayClass() const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 244 | DCHECK(IsValid()); |
| 245 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 246 | } |
| 247 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 248 | bool CanArrayHold(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 249 | DCHECK(IsValid()); |
| 250 | if (!IsExact()) return false; |
| 251 | if (!IsArrayClass()) return false; |
| 252 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 253 | } |
| 254 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 255 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 256 | DCHECK(IsValid()); |
| 257 | if (!IsExact()) return false; |
| 258 | if (!IsArrayClass()) return false; |
| 259 | if (!rti.IsArrayClass()) return false; |
| 260 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 261 | rti.GetTypeHandle()->GetComponentType()); |
| 262 | } |
| 263 | |
| 264 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 265 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 266 | bool IsSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 267 | DCHECK(IsValid()); |
| 268 | DCHECK(rti.IsValid()); |
| 269 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 270 | } |
| 271 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 272 | bool IsStrictSupertypeOf(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 273 | DCHECK(IsValid()); |
| 274 | DCHECK(rti.IsValid()); |
| 275 | return GetTypeHandle().Get() != rti.GetTypeHandle().Get() && |
| 276 | GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 277 | } |
| 278 | |
| 279 | // Returns true if the type information provide the same amount of details. |
| 280 | // Note that it does not mean that the instructions have the same actual type |
| 281 | // (because the type can be the result of a merge). |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 282 | bool IsEqual(ReferenceTypeInfo rti) const REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 283 | if (!IsValid() && !rti.IsValid()) { |
| 284 | // Invalid types are equal. |
| 285 | return true; |
| 286 | } |
| 287 | if (!IsValid() || !rti.IsValid()) { |
| 288 | // One is valid, the other not. |
| 289 | return false; |
| 290 | } |
| 291 | return IsExact() == rti.IsExact() |
| 292 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
| 293 | } |
| 294 | |
| 295 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 296 | ReferenceTypeInfo() : type_handle_(TypeHandle()), is_exact_(false) {} |
| 297 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact) |
| 298 | : type_handle_(type_handle), is_exact_(is_exact) { } |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 299 | |
| 300 | // The class of the object. |
| 301 | TypeHandle type_handle_; |
| 302 | // Whether or not the type is exact or a superclass of the actual type. |
| 303 | // Whether or not we have any information about this type. |
| 304 | bool is_exact_; |
| 305 | }; |
| 306 | |
| 307 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 308 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 309 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 310 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 311 | public: |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 312 | HGraph(ArenaAllocator* allocator, |
| 313 | ArenaStack* arena_stack, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 314 | const DexFile& dex_file, |
| 315 | uint32_t method_idx, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 316 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 317 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 318 | bool debuggable = false, |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 319 | bool osr = false, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 320 | int start_instruction_id = 0) |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 321 | : allocator_(allocator), |
| 322 | arena_stack_(arena_stack), |
| 323 | blocks_(allocator->Adapter(kArenaAllocBlockList)), |
| 324 | reverse_post_order_(allocator->Adapter(kArenaAllocReversePostOrder)), |
| 325 | linear_order_(allocator->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 326 | entry_block_(nullptr), |
| 327 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 328 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 329 | number_of_vregs_(0), |
| 330 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 331 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 332 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 333 | has_try_catch_(false), |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 334 | has_simd_(false), |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 335 | has_loops_(false), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 336 | has_irreducible_loops_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 337 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 338 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 339 | dex_file_(dex_file), |
| 340 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 341 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 342 | in_ssa_form_(false), |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 343 | number_of_cha_guards_(0), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 344 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 345 | cached_null_constant_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 346 | cached_int_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 347 | cached_float_constants_(std::less<int32_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 348 | cached_long_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
| 349 | cached_double_constants_(std::less<int64_t>(), allocator->Adapter(kArenaAllocConstantsMap)), |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 350 | cached_current_method_(nullptr), |
Nicolas Geoffray | 53fec08 | 2017-03-27 12:56:16 +0100 | [diff] [blame] | 351 | art_method_(nullptr), |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 352 | inexact_object_rti_(ReferenceTypeInfo::CreateInvalid()), |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 353 | osr_(osr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 354 | cha_single_implementation_list_(allocator->Adapter(kArenaAllocCHA)) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 355 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 356 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 357 | |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 358 | // 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] | 359 | void InitializeInexactObjectRTI(VariableSizedHandleScope* handles); |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 360 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 361 | ArenaAllocator* GetAllocator() const { return allocator_; } |
| 362 | ArenaStack* GetArenaStack() const { return arena_stack_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 363 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 364 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 365 | bool IsInSsaForm() const { return in_ssa_form_; } |
David Brazdil | badd826 | 2016-02-02 16:28:56 +0000 | [diff] [blame] | 366 | void SetInSsaForm() { in_ssa_form_ = true; } |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 367 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 368 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 369 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 370 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 371 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 372 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 373 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 374 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 375 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 376 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 377 | void ComputeDominanceInformation(); |
| 378 | void ClearDominanceInformation(); |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 379 | void ClearLoopInformation(); |
| 380 | void FindBackEdges(ArenaBitVector* visited); |
| 381 | GraphAnalysisResult BuildDominatorTree(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 382 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 383 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 384 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 385 | // Analyze all natural loops in this graph. Returns a code specifying that it |
| 386 | // 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] | 387 | // 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] | 388 | GraphAnalysisResult AnalyzeLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 389 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 390 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 391 | // order and loop information. |
| 392 | void ComputeTryBlockInformation(); |
| 393 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 394 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Nicolas Geoffray | 55bd749 | 2016-02-16 15:37:12 +0000 | [diff] [blame] | 395 | // Returns the instruction to replace the invoke expression or null if the |
| 396 | // invoke is for a void method. Note that the caller is responsible for replacing |
| 397 | // and removing the invoke instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 398 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 399 | |
Nicolas Geoffray | a1d8ddf | 2016-02-29 11:46:58 +0000 | [diff] [blame] | 400 | // Update the loop and try membership of `block`, which was spawned from `reference`. |
| 401 | // In case `reference` is a back edge, `replace_if_back_edge` notifies whether `block` |
| 402 | // should be the new back edge. |
| 403 | void UpdateLoopAndTryInformationOfNewBlock(HBasicBlock* block, |
| 404 | HBasicBlock* reference, |
| 405 | bool replace_if_back_edge); |
| 406 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 407 | // Need to add a couple of blocks to test if the loop body is entered and |
| 408 | // put deoptimization instructions, etc. |
| 409 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 410 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 411 | // Adds a new loop directly after the loop with the given header and exit. |
| 412 | // Returns the new preheader. |
| 413 | HBasicBlock* TransformLoopForVectorization(HBasicBlock* header, |
| 414 | HBasicBlock* body, |
| 415 | HBasicBlock* exit); |
| 416 | |
David Brazdil | 8a7c0fe | 2015-11-02 20:24:55 +0000 | [diff] [blame] | 417 | // Removes `block` from the graph. Assumes `block` has been disconnected from |
| 418 | // other blocks and has no instructions or phis. |
| 419 | void DeleteDeadEmptyBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 420 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 421 | // Splits the edge between `block` and `successor` while preserving the |
| 422 | // indices in the predecessor/successor lists. If there are multiple edges |
| 423 | // between the blocks, the lowest indices are used. |
| 424 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 425 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 426 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 427 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
Artem Serov | c73ee37 | 2017-07-31 15:08:40 +0100 | [diff] [blame] | 428 | void OrderLoopHeaderPredecessors(HBasicBlock* header); |
Artem Serov | 09faaea | 2017-12-07 14:36:01 +0000 | [diff] [blame] | 429 | |
| 430 | // Transform a loop into a format with a single preheader. |
| 431 | // |
| 432 | // Each phi in the header should be split: original one in the header should only hold |
| 433 | // inputs reachable from the back edges and a single input from the preheader. The newly created |
| 434 | // phi in the preheader should collate the inputs from the original multiple incoming blocks. |
| 435 | // |
| 436 | // Loops in the graph typically have a single preheader, so this method is used to "repair" loops |
| 437 | // that no longer have this property. |
| 438 | void TransformLoopToSinglePreheaderFormat(HBasicBlock* header); |
| 439 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 440 | void SimplifyLoop(HBasicBlock* header); |
| 441 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 442 | int32_t GetNextInstructionId() { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 443 | CHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 444 | return current_instruction_id_++; |
| 445 | } |
| 446 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 447 | int32_t GetCurrentInstructionId() const { |
| 448 | return current_instruction_id_; |
| 449 | } |
| 450 | |
| 451 | void SetCurrentInstructionId(int32_t id) { |
Nicolas Geoffray | c9c3104 | 2017-06-29 14:04:16 +0100 | [diff] [blame] | 452 | CHECK_GE(id, current_instruction_id_); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 453 | current_instruction_id_ = id; |
| 454 | } |
| 455 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 456 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 457 | return maximum_number_of_out_vregs_; |
| 458 | } |
| 459 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 460 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 461 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 462 | } |
| 463 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 464 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 465 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 466 | } |
| 467 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 468 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 469 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 470 | } |
| 471 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 472 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 473 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 474 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 475 | } |
| 476 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 477 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 478 | number_of_vregs_ = number_of_vregs; |
| 479 | } |
| 480 | |
| 481 | uint16_t GetNumberOfVRegs() const { |
| 482 | return number_of_vregs_; |
| 483 | } |
| 484 | |
| 485 | void SetNumberOfInVRegs(uint16_t value) { |
| 486 | number_of_in_vregs_ = value; |
| 487 | } |
| 488 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 489 | uint16_t GetNumberOfInVRegs() const { |
| 490 | return number_of_in_vregs_; |
| 491 | } |
| 492 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 493 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 494 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 495 | return number_of_vregs_ - number_of_in_vregs_; |
| 496 | } |
| 497 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 498 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 499 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 500 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 501 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 502 | ArrayRef<HBasicBlock* const> GetReversePostOrderSkipEntryBlock() { |
| 503 | DCHECK(GetReversePostOrder()[0] == entry_block_); |
| 504 | return ArrayRef<HBasicBlock* const>(GetReversePostOrder()).SubArray(1); |
| 505 | } |
| 506 | |
| 507 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetPostOrder() const { |
| 508 | return ReverseRange(GetReversePostOrder()); |
| 509 | } |
| 510 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 511 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 512 | return linear_order_; |
| 513 | } |
| 514 | |
Vladimir Marko | 2c45bc9 | 2016-10-25 16:54:12 +0100 | [diff] [blame] | 515 | IterationRange<ArenaVector<HBasicBlock*>::const_reverse_iterator> GetLinearPostOrder() const { |
| 516 | return ReverseRange(GetLinearOrder()); |
| 517 | } |
| 518 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 519 | bool HasBoundsChecks() const { |
| 520 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 523 | void SetHasBoundsChecks(bool value) { |
| 524 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 525 | } |
| 526 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 527 | bool IsDebuggable() const { return debuggable_; } |
| 528 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 529 | // 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] | 530 | // already, it is created and inserted into the graph. This method is only for |
| 531 | // integral types. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 532 | 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] | 533 | |
| 534 | // TODO: This is problematic for the consistency of reference type propagation |
| 535 | // because it can be created anytime after the pass and thus it will be left |
| 536 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 537 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 538 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 539 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 540 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 541 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 542 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 543 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 544 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 545 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 546 | 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] | 547 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 548 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 549 | 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] | 550 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 551 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 552 | HCurrentMethod* GetCurrentMethod(); |
| 553 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 554 | const DexFile& GetDexFile() const { |
| 555 | return dex_file_; |
| 556 | } |
| 557 | |
| 558 | uint32_t GetMethodIdx() const { |
| 559 | return method_idx_; |
| 560 | } |
| 561 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 562 | // Get the method name (without the signature), e.g. "<init>" |
| 563 | const char* GetMethodName() const; |
| 564 | |
| 565 | // Get the pretty method name (class + name + optionally signature). |
| 566 | std::string PrettyMethod(bool with_signature = true) const; |
| 567 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 568 | InvokeType GetInvokeType() const { |
| 569 | return invoke_type_; |
| 570 | } |
| 571 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 572 | InstructionSet GetInstructionSet() const { |
| 573 | return instruction_set_; |
| 574 | } |
| 575 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 576 | bool IsCompilingOsr() const { return osr_; } |
| 577 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 578 | ArenaSet<ArtMethod*>& GetCHASingleImplementationList() { |
| 579 | return cha_single_implementation_list_; |
| 580 | } |
| 581 | |
| 582 | void AddCHASingleImplementationDependency(ArtMethod* method) { |
| 583 | cha_single_implementation_list_.insert(method); |
| 584 | } |
| 585 | |
| 586 | bool HasShouldDeoptimizeFlag() const { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 587 | return number_of_cha_guards_ != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 588 | } |
| 589 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 590 | bool HasTryCatch() const { return has_try_catch_; } |
| 591 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 592 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 593 | bool HasSIMD() const { return has_simd_; } |
| 594 | void SetHasSIMD(bool value) { has_simd_ = value; } |
| 595 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 596 | bool HasLoops() const { return has_loops_; } |
| 597 | void SetHasLoops(bool value) { has_loops_ = value; } |
| 598 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 599 | bool HasIrreducibleLoops() const { return has_irreducible_loops_; } |
| 600 | void SetHasIrreducibleLoops(bool value) { has_irreducible_loops_ = value; } |
| 601 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 602 | ArtMethod* GetArtMethod() const { return art_method_; } |
| 603 | void SetArtMethod(ArtMethod* method) { art_method_ = method; } |
| 604 | |
Roland Levillain | 5e8d5f0 | 2016-10-18 18:03:43 +0100 | [diff] [blame] | 605 | // Returns an instruction with the opposite Boolean value from 'cond'. |
Mark Mendell | f652917 | 2015-11-17 11:16:56 -0500 | [diff] [blame] | 606 | // The instruction has been inserted into the graph, either as a constant, or |
| 607 | // before cursor. |
| 608 | HInstruction* InsertOppositeCondition(HInstruction* cond, HInstruction* cursor); |
| 609 | |
Nicolas Geoffray | 18401b7 | 2016-03-11 13:35:51 +0000 | [diff] [blame] | 610 | ReferenceTypeInfo GetInexactObjectRti() const { return inexact_object_rti_; } |
| 611 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 612 | uint32_t GetNumberOfCHAGuards() { return number_of_cha_guards_; } |
| 613 | void SetNumberOfCHAGuards(uint32_t num) { number_of_cha_guards_ = num; } |
| 614 | void IncrementNumberOfCHAGuards() { number_of_cha_guards_++; } |
| 615 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 616 | private: |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 617 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 618 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 619 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 620 | template <class InstructionType, typename ValueType> |
| 621 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 622 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 623 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 624 | // Try to find an existing constant of the given value. |
| 625 | InstructionType* constant = nullptr; |
| 626 | auto cached_constant = cache->find(value); |
| 627 | if (cached_constant != cache->end()) { |
| 628 | constant = cached_constant->second; |
| 629 | } |
| 630 | |
| 631 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 632 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 633 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 634 | constant = new (allocator_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 635 | cache->Overwrite(value, constant); |
| 636 | InsertConstant(constant); |
| 637 | } |
| 638 | return constant; |
| 639 | } |
| 640 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 641 | void InsertConstant(HConstant* instruction); |
| 642 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 643 | // Cache a float constant into the graph. This method should only be |
| 644 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 645 | void CacheFloatConstant(HFloatConstant* constant); |
| 646 | |
| 647 | // See CacheFloatConstant comment. |
| 648 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 649 | |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 650 | ArenaAllocator* const allocator_; |
| 651 | ArenaStack* const arena_stack_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 652 | |
| 653 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 654 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 655 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 656 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 657 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 658 | |
Aart Bik | 281c681 | 2016-08-26 11:31:48 -0700 | [diff] [blame] | 659 | // List of blocks to perform a linear order tree traversal. Unlike the reverse |
| 660 | // post order, this order is not incrementally kept up-to-date. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 661 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 662 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 663 | HBasicBlock* entry_block_; |
| 664 | HBasicBlock* exit_block_; |
| 665 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 666 | // 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] | 667 | uint16_t maximum_number_of_out_vregs_; |
| 668 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 669 | // The number of virtual registers in this method. Contains the parameters. |
| 670 | uint16_t number_of_vregs_; |
| 671 | |
| 672 | // The number of virtual registers used by parameters of this method. |
| 673 | uint16_t number_of_in_vregs_; |
| 674 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 675 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 676 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 677 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 678 | // Flag whether there are bounds checks in the graph. We can skip |
| 679 | // BCE if it's false. It's only best effort to keep it up to date in |
| 680 | // the presence of code elimination so there might be false positives. |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 681 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 682 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 683 | // Flag whether there are try/catch blocks in the graph. We will skip |
| 684 | // try/catch-related passes if it's false. It's only best effort to keep |
| 685 | // it up to date in the presence of code elimination so there might be |
| 686 | // false positives. |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 687 | bool has_try_catch_; |
| 688 | |
Aart Bik | b13c65b | 2017-03-21 20:14:07 -0700 | [diff] [blame] | 689 | // Flag whether SIMD instructions appear in the graph. If true, the |
| 690 | // code generators may have to be more careful spilling the wider |
| 691 | // contents of SIMD registers. |
| 692 | bool has_simd_; |
| 693 | |
Mingyao Yang | 69d75ff | 2017-02-07 13:06:06 -0800 | [diff] [blame] | 694 | // Flag whether there are any loops in the graph. We can skip loop |
| 695 | // optimization if it's false. It's only best effort to keep it up |
| 696 | // to date in the presence of code elimination so there might be false |
| 697 | // positives. |
| 698 | bool has_loops_; |
| 699 | |
| 700 | // Flag whether there are any irreducible loops in the graph. It's only |
| 701 | // best effort to keep it up to date in the presence of code elimination |
| 702 | // so there might be false positives. |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 703 | bool has_irreducible_loops_; |
| 704 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 705 | // Indicates whether the graph should be compiled in a way that |
| 706 | // ensures full debuggability. If false, we can apply more |
| 707 | // aggressive optimizations that may limit the level of debugging. |
| 708 | const bool debuggable_; |
| 709 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 710 | // 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] | 711 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 712 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 713 | // The dex file from which the method is from. |
| 714 | const DexFile& dex_file_; |
| 715 | |
| 716 | // The method index in the dex file. |
| 717 | const uint32_t method_idx_; |
| 718 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 719 | // If inlined, this encodes how the callee is being invoked. |
| 720 | const InvokeType invoke_type_; |
| 721 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 722 | // Whether the graph has been transformed to SSA form. Only used |
| 723 | // in debug mode to ensure we are not using properties only valid |
| 724 | // for non-SSA form (like the number of temporaries). |
| 725 | bool in_ssa_form_; |
| 726 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 727 | // Number of CHA guards in the graph. Used to short-circuit the |
| 728 | // CHA guard optimization pass when there is no CHA guard left. |
| 729 | uint32_t number_of_cha_guards_; |
| 730 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 731 | const InstructionSet instruction_set_; |
| 732 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 733 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 734 | HNullConstant* cached_null_constant_; |
| 735 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 736 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 737 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 738 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 739 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 740 | HCurrentMethod* cached_current_method_; |
| 741 | |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 742 | // The ArtMethod this graph is for. Note that for AOT, it may be null, |
| 743 | // for example for methods whose declaring class could not be resolved |
| 744 | // (such as when the superclass could not be found). |
| 745 | ArtMethod* art_method_; |
| 746 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 747 | // Keep the RTI of inexact Object to avoid having to pass stack handle |
| 748 | // collection pointer to passes which may create NullConstant. |
| 749 | ReferenceTypeInfo inexact_object_rti_; |
| 750 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 751 | // Whether we are compiling this graph for on stack replacement: this will |
| 752 | // make all loops seen as irreducible and emit special stack maps to mark |
| 753 | // compiled code entries which the interpreter can directly jump to. |
| 754 | const bool osr_; |
| 755 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 756 | // List of methods that are assumed to have single implementation. |
| 757 | ArenaSet<ArtMethod*> cha_single_implementation_list_; |
| 758 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 759 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 760 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 761 | friend class HInliner; // For the reverse post order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 762 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 763 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 764 | }; |
| 765 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 766 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 767 | public: |
| 768 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 769 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 770 | suspend_check_(nullptr), |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 771 | irreducible_(false), |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 772 | contains_irreducible_loop_(false), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 773 | back_edges_(graph->GetAllocator()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 774 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 775 | blocks_(graph->GetAllocator(), |
| 776 | graph->GetBlocks().size(), |
| 777 | true, |
| 778 | kArenaAllocLoopInfoBackEdges) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 779 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 780 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 781 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 782 | bool IsIrreducible() const { return irreducible_; } |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 783 | bool ContainsIrreducibleLoop() const { return contains_irreducible_loop_; } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 784 | |
| 785 | void Dump(std::ostream& os); |
| 786 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 787 | HBasicBlock* GetHeader() const { |
| 788 | return header_; |
| 789 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 790 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 791 | void SetHeader(HBasicBlock* block) { |
| 792 | header_ = block; |
| 793 | } |
| 794 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 795 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 796 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 797 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 798 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 799 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 800 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 801 | } |
| 802 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 803 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 804 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 805 | } |
| 806 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 807 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 808 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 809 | } |
| 810 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 811 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 812 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 815 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 816 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 817 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 818 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 819 | } |
| 820 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 821 | // Returns the lifetime position of the back edge that has the |
| 822 | // greatest lifetime position. |
| 823 | size_t GetLifetimeEnd() const; |
| 824 | |
| 825 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 826 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 827 | } |
| 828 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 829 | // Finds blocks that are part of this loop. |
| 830 | void Populate(); |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 831 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 832 | // Updates blocks population of the loop and all of its outer' ones recursively after the |
| 833 | // population of the inner loop is updated. |
| 834 | void PopulateInnerLoopUpwards(HLoopInformation* inner_loop); |
| 835 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 836 | // Returns whether this loop information contains `block`. |
| 837 | // Note that this loop information *must* be populated before entering this function. |
| 838 | bool Contains(const HBasicBlock& block) const; |
| 839 | |
| 840 | // Returns whether this loop information is an inner loop of `other`. |
| 841 | // Note that `other` *must* be populated before entering this function. |
| 842 | bool IsIn(const HLoopInformation& other) const; |
| 843 | |
Mingyao Yang | 4b467ed | 2015-11-19 17:04:22 -0800 | [diff] [blame] | 844 | // Returns true if instruction is not defined within this loop. |
| 845 | bool IsDefinedOutOfTheLoop(HInstruction* instruction) const; |
Aart Bik | 73f1f3b | 2015-10-28 15:28:08 -0700 | [diff] [blame] | 846 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 847 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 848 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 849 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 850 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 851 | |
Nicolas Geoffray | 788f2f0 | 2016-01-22 12:41:38 +0000 | [diff] [blame] | 852 | void ClearAllBlocks() { |
| 853 | blocks_.ClearAllBits(); |
| 854 | } |
| 855 | |
David Brazdil | 3f4a522 | 2016-05-06 12:46:21 +0100 | [diff] [blame] | 856 | bool HasBackEdgeNotDominatedByHeader() const; |
| 857 | |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 858 | bool IsPopulated() const { |
| 859 | return blocks_.GetHighestBitSet() != -1; |
| 860 | } |
| 861 | |
Anton Shamin | f89381f | 2016-05-16 16:44:13 +0600 | [diff] [blame] | 862 | bool DominatesAllBackEdges(HBasicBlock* block); |
| 863 | |
David Sehr | c757dec | 2016-11-04 15:48:34 -0700 | [diff] [blame] | 864 | bool HasExitEdge() const; |
| 865 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 866 | // Resets back edge and blocks-in-loop data. |
| 867 | void ResetBasicBlockData() { |
| 868 | back_edges_.clear(); |
| 869 | ClearAllBlocks(); |
| 870 | } |
| 871 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 872 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 873 | // Internal recursive implementation of `Populate`. |
| 874 | void PopulateRecursive(HBasicBlock* block); |
David Brazdil | c2e8af9 | 2016-04-05 17:15:19 +0100 | [diff] [blame] | 875 | void PopulateIrreducibleRecursive(HBasicBlock* block, ArenaBitVector* finalized); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 876 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 877 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 878 | HSuspendCheck* suspend_check_; |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 879 | bool irreducible_; |
Nicolas Geoffray | d7c2fdc | 2016-05-10 14:35:34 +0100 | [diff] [blame] | 880 | bool contains_irreducible_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 881 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 882 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 883 | |
| 884 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 885 | }; |
| 886 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 887 | // Stores try/catch information for basic blocks. |
| 888 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 889 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 890 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 891 | public: |
| 892 | // Try block information constructor. |
| 893 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 894 | : try_entry_(&try_entry), |
| 895 | catch_dex_file_(nullptr), |
| 896 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 897 | DCHECK(try_entry_ != nullptr); |
| 898 | } |
| 899 | |
| 900 | // Catch block information constructor. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 901 | TryCatchInformation(dex::TypeIndex catch_type_index, const DexFile& dex_file) |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 902 | : try_entry_(nullptr), |
| 903 | catch_dex_file_(&dex_file), |
| 904 | catch_type_index_(catch_type_index) {} |
| 905 | |
| 906 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 907 | |
| 908 | const HTryBoundary& GetTryEntry() const { |
| 909 | DCHECK(IsTryBlock()); |
| 910 | return *try_entry_; |
| 911 | } |
| 912 | |
| 913 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 914 | |
| 915 | bool IsCatchAllTypeIndex() const { |
| 916 | DCHECK(IsCatchBlock()); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 917 | return !catch_type_index_.IsValid(); |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 920 | dex::TypeIndex GetCatchTypeIndex() const { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 921 | DCHECK(IsCatchBlock()); |
| 922 | return catch_type_index_; |
| 923 | } |
| 924 | |
| 925 | const DexFile& GetCatchDexFile() const { |
| 926 | DCHECK(IsCatchBlock()); |
| 927 | return *catch_dex_file_; |
| 928 | } |
| 929 | |
| 930 | private: |
| 931 | // One of possibly several TryBoundary instructions entering the block's try. |
| 932 | // Only set for try blocks. |
| 933 | const HTryBoundary* try_entry_; |
| 934 | |
| 935 | // Exception type information. Only set for catch blocks. |
| 936 | const DexFile* catch_dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 937 | const dex::TypeIndex catch_type_index_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 938 | }; |
| 939 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 940 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 941 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 942 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 943 | // A block in a method. Contains the list of instructions represented |
| 944 | // as a double linked list. Each block knows its predecessors and |
| 945 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 946 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 947 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 948 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 949 | explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 950 | : graph_(graph), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 951 | predecessors_(graph->GetAllocator()->Adapter(kArenaAllocPredecessors)), |
| 952 | successors_(graph->GetAllocator()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 953 | loop_information_(nullptr), |
| 954 | dominator_(nullptr), |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 955 | dominated_blocks_(graph->GetAllocator()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 956 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 957 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 958 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 959 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 960 | try_catch_information_(nullptr) { |
| 961 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 962 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 963 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 964 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 965 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 966 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 967 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 968 | } |
| 969 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 970 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 971 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 972 | } |
| 973 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 974 | ArrayRef<HBasicBlock* const> GetNormalSuccessors() const; |
| 975 | ArrayRef<HBasicBlock* const> GetExceptionalSuccessors() const; |
| 976 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 977 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 978 | return ContainsElement(successors_, block, start_from); |
| 979 | } |
| 980 | |
| 981 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 982 | return dominated_blocks_; |
| 983 | } |
| 984 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 985 | bool IsEntryBlock() const { |
| 986 | return graph_->GetEntryBlock() == this; |
| 987 | } |
| 988 | |
| 989 | bool IsExitBlock() const { |
| 990 | return graph_->GetExitBlock() == this; |
| 991 | } |
| 992 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 993 | bool IsSingleGoto() const; |
Mads Ager | 16e5289 | 2017-07-14 13:11:37 +0200 | [diff] [blame] | 994 | bool IsSingleReturn() const; |
Mingyao Yang | 46721ef | 2017-10-05 14:45:17 -0700 | [diff] [blame] | 995 | bool IsSingleReturnOrReturnVoidAllowingPhis() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 996 | bool IsSingleTryBoundary() const; |
| 997 | |
| 998 | // Returns true if this block emits nothing but a jump. |
| 999 | bool IsSingleJump() const { |
| 1000 | HLoopInformation* loop_info = GetLoopInformation(); |
| 1001 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 1002 | // Back edges generate a suspend check. |
| 1003 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 1004 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1005 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1006 | void AddBackEdge(HBasicBlock* back_edge) { |
| 1007 | if (loop_information_ == nullptr) { |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 1008 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1009 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1010 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1011 | loop_information_->AddBackEdge(back_edge); |
| 1012 | } |
| 1013 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 1014 | // Registers a back edge; if the block was not a loop header before the call associates a newly |
| 1015 | // created loop info with it. |
| 1016 | // |
| 1017 | // Used in SuperblockCloner to preserve LoopInformation object instead of reseting loop |
| 1018 | // info for all blocks during back edges recalculation. |
| 1019 | void AddBackEdgeWhileUpdating(HBasicBlock* back_edge) { |
| 1020 | if (loop_information_ == nullptr || loop_information_->GetHeader() != this) { |
| 1021 | loop_information_ = new (graph_->GetAllocator()) HLoopInformation(this, graph_); |
| 1022 | } |
| 1023 | loop_information_->AddBackEdge(back_edge); |
| 1024 | } |
| 1025 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1026 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1027 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1028 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1029 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1030 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1031 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1032 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1033 | HBasicBlock* GetDominator() const { return dominator_; } |
| 1034 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1035 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 1036 | |
| 1037 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 1038 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 1039 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1040 | |
| 1041 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1042 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 1043 | } |
| 1044 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1045 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1046 | |
| 1047 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 1048 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1051 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 1052 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 1053 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 1054 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 1055 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 1056 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1057 | |
Nicolas Geoffray | 09aa147 | 2016-01-19 10:52:54 +0000 | [diff] [blame] | 1058 | HInstruction* GetFirstInstructionDisregardMoves() const; |
| 1059 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1060 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1061 | successors_.push_back(block); |
| 1062 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1065 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1066 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1067 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1068 | new_block->predecessors_.push_back(this); |
| 1069 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1072 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 1073 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1074 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1075 | new_block->successors_.push_back(this); |
| 1076 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1079 | // Insert `this` between `predecessor` and `successor. This method |
| 1080 | // preserves the indicies, and will update the first edge found between |
| 1081 | // `predecessor` and `successor`. |
| 1082 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 1083 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1084 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1085 | successor->predecessors_[predecessor_index] = this; |
| 1086 | predecessor->successors_[successor_index] = this; |
| 1087 | successors_.push_back(successor); |
| 1088 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 1089 | } |
| 1090 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1091 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1092 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1095 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1096 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1099 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1100 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1104 | predecessors_.push_back(block); |
| 1105 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1106 | } |
| 1107 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1108 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1109 | DCHECK_EQ(predecessors_.size(), 2u); |
| 1110 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 1111 | } |
| 1112 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1113 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1114 | DCHECK_EQ(successors_.size(), 2u); |
| 1115 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 1116 | } |
| 1117 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1118 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1119 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1120 | } |
| 1121 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1122 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1123 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1124 | } |
| 1125 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1126 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1127 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1128 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1132 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1133 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | // Returns whether the first occurrence of `predecessor` in the list of |
| 1137 | // predecessors is at index `idx`. |
| 1138 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1139 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1140 | return GetPredecessorIndexOf(predecessor) == idx; |
| 1141 | } |
| 1142 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 1143 | // Create a new block between this block and its predecessors. The new block |
| 1144 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 1145 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 1146 | // loop and try/catch information are not updated. |
| 1147 | HBasicBlock* CreateImmediateDominator(); |
| 1148 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1149 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 1150 | // created, latter block. Note that this method will add the block to the |
| 1151 | // graph, create a Goto at the end of the former block and will create an edge |
| 1152 | // 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] | 1153 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1154 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 1155 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1156 | // Split the block into two blocks just before `cursor`. Returns the newly |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1157 | // created block. Note that this method just updates raw block information, |
| 1158 | // like predecessors, successors, dominators, and instruction list. It does not |
| 1159 | // update the graph, reverse post order, loop information, nor make sure the |
| 1160 | // blocks are consistent (for example ending with a control flow instruction). |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 1161 | HBasicBlock* SplitBeforeForInlining(HInstruction* cursor); |
| 1162 | |
| 1163 | // Similar to `SplitBeforeForInlining` but does it after `cursor`. |
| 1164 | HBasicBlock* SplitAfterForInlining(HInstruction* cursor); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1165 | |
| 1166 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 1167 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 1168 | // that this method does not update the graph, reverse post order, loop |
| 1169 | // information, nor make sure the blocks are consistent (for example ending |
| 1170 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1171 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1172 | |
| 1173 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 1174 | // of `this` are moved to `other`. |
| 1175 | // Note that this method does not update the graph, reverse post order, loop |
| 1176 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1177 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1178 | void ReplaceWith(HBasicBlock* other); |
| 1179 | |
Aart Bik | 6b69e0a | 2017-01-11 10:20:43 -0800 | [diff] [blame] | 1180 | // Merges the instructions of `other` at the end of `this`. |
| 1181 | void MergeInstructionsWith(HBasicBlock* other); |
| 1182 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1183 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 1184 | // order, links to predecessors, successors, dominators and deletes the block |
| 1185 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 1186 | // predecessor of `other` and vice versa. |
| 1187 | void MergeWith(HBasicBlock* other); |
| 1188 | |
| 1189 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 1190 | // removes it from all loops it is included in and eventually from the graph. |
| 1191 | // The block must not dominate any other block. Predecessors and successors |
| 1192 | // are safely updated. |
| 1193 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1194 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1195 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1196 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 1197 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 1198 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1199 | // Replace phi `initial` with `replacement` within this block. |
| 1200 | void ReplaceAndRemovePhiWith(HPhi* initial, HPhi* replacement); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1201 | // Replace instruction `initial` with `replacement` within this block. |
| 1202 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 1203 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1204 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1205 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1206 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 1207 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 1208 | // instruction is not in use and removes it from the use lists of its inputs. |
| 1209 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 1210 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 1211 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1212 | |
| 1213 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1214 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1215 | } |
| 1216 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1217 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 1218 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 1219 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1220 | } |
| 1221 | |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 1222 | bool IsFirstPredecessorBackEdge() const { |
| 1223 | DCHECK(IsLoopHeader()); |
| 1224 | return GetLoopInformation()->IsBackEdge(*GetPredecessors()[0]); |
| 1225 | } |
| 1226 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1227 | HLoopInformation* GetLoopInformation() const { |
| 1228 | return loop_information_; |
| 1229 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1230 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1231 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1232 | // 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] | 1233 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1234 | void SetInLoop(HLoopInformation* info) { |
| 1235 | if (IsLoopHeader()) { |
| 1236 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1237 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1238 | loop_information_ = info; |
| 1239 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 1240 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 1241 | // Note that a non loop header having a loop information means this loop information |
| 1242 | // has already been populated |
| 1243 | loop_information_ = info; |
| 1244 | } else { |
| 1245 | // Block is part of an inner loop. Do not update the loop information. |
| 1246 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 1247 | // at this point, because this method is being called while populating `info`. |
| 1248 | } |
| 1249 | } |
| 1250 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1251 | // Raw update of the loop information. |
| 1252 | void SetLoopInformation(HLoopInformation* info) { |
| 1253 | loop_information_ = info; |
| 1254 | } |
| 1255 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1256 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 1257 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1258 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 1259 | |
| 1260 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 1261 | try_catch_information_ = try_catch_information; |
| 1262 | } |
| 1263 | |
| 1264 | bool IsTryBlock() const { |
| 1265 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 1266 | } |
| 1267 | |
| 1268 | bool IsCatchBlock() const { |
| 1269 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 1270 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1271 | |
| 1272 | // Returns the try entry that this block's successors should have. They will |
| 1273 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 1274 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1275 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1276 | |
Aart Bik | 75ff2c9 | 2018-04-21 01:28:11 +0000 | [diff] [blame] | 1277 | bool HasThrowingInstructions() const; |
| 1278 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 1279 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 1280 | bool Dominates(HBasicBlock* block) const; |
| 1281 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1282 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 1283 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 1284 | |
| 1285 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 1286 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 1287 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 1288 | bool EndsWithControlFlowInstruction() const; |
Aart Bik | 4dc09e7 | 2018-05-11 14:40:31 -0700 | [diff] [blame] | 1289 | bool EndsWithReturn() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1290 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1291 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1292 | bool HasSinglePhi() const; |
| 1293 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1294 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1295 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1296 | ArenaVector<HBasicBlock*> predecessors_; |
| 1297 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1298 | HInstructionList instructions_; |
| 1299 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 1300 | HLoopInformation* loop_information_; |
| 1301 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 1302 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1303 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 1304 | // The dex program counter of the first instruction of this block. |
| 1305 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1306 | size_t lifetime_start_; |
| 1307 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1308 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 1309 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1310 | friend class HGraph; |
| 1311 | friend class HInstruction; |
| 1312 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1313 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 1314 | }; |
| 1315 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1316 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 1317 | // from the innermost to the outermost. |
| 1318 | class HLoopInformationOutwardIterator : public ValueObject { |
| 1319 | public: |
| 1320 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 1321 | : current_(block.GetLoopInformation()) {} |
| 1322 | |
| 1323 | bool Done() const { return current_ == nullptr; } |
| 1324 | |
| 1325 | void Advance() { |
| 1326 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 1327 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | HLoopInformation* Current() const { |
| 1331 | DCHECK(!Done()); |
| 1332 | return current_; |
| 1333 | } |
| 1334 | |
| 1335 | private: |
| 1336 | HLoopInformation* current_; |
| 1337 | |
| 1338 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1339 | }; |
| 1340 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1341 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1342 | M(Above, Condition) \ |
| 1343 | M(AboveOrEqual, Condition) \ |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 1344 | M(Abs, UnaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1345 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1346 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1347 | M(ArrayGet, Instruction) \ |
| 1348 | M(ArrayLength, Instruction) \ |
| 1349 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1350 | M(Below, Condition) \ |
| 1351 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1352 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1353 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1354 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1355 | M(CheckCast, Instruction) \ |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 1356 | M(ClassTableGet, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1357 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1358 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1359 | M(Compare, BinaryOperation) \ |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1360 | M(ConstructorFence, Instruction) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1361 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 1362 | M(ShouldDeoptimizeFlag, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1363 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1364 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1365 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1366 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1367 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1368 | M(Exit, Instruction) \ |
| 1369 | M(FloatConstant, Constant) \ |
| 1370 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1371 | M(GreaterThan, Condition) \ |
| 1372 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1373 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1374 | M(InstanceFieldGet, Instruction) \ |
| 1375 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1376 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1377 | M(IntConstant, Constant) \ |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 1378 | M(IntermediateAddress, Instruction) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1379 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1380 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1381 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1382 | M(InvokeVirtual, Invoke) \ |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 1383 | M(InvokePolymorphic, Invoke) \ |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 1384 | M(InvokeCustom, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1385 | M(LessThan, Condition) \ |
| 1386 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1387 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1388 | M(LoadException, Instruction) \ |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 1389 | M(LoadMethodHandle, Instruction) \ |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 1390 | M(LoadMethodType, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1391 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1392 | M(LongConstant, Constant) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1393 | M(Max, Instruction) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1394 | M(MemoryBarrier, Instruction) \ |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 1395 | M(Min, BinaryOperation) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1396 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1397 | M(Mul, BinaryOperation) \ |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 1398 | M(NativeDebugInfo, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1399 | M(Neg, UnaryOperation) \ |
| 1400 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1401 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1402 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1403 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1404 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1405 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1406 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1407 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1408 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1409 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1410 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1411 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1412 | M(Return, Instruction) \ |
| 1413 | M(ReturnVoid, Instruction) \ |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 1414 | M(Ror, BinaryOperation) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1415 | M(Shl, BinaryOperation) \ |
| 1416 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1417 | M(StaticFieldGet, Instruction) \ |
| 1418 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1419 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1420 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1421 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1422 | M(UnresolvedStaticFieldSet, Instruction) \ |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 1423 | M(Select, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1424 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1425 | M(SuspendCheck, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1426 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1427 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1428 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1429 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1430 | M(Xor, BinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1431 | M(VecReplicateScalar, VecUnaryOperation) \ |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 1432 | M(VecExtractScalar, VecUnaryOperation) \ |
| 1433 | M(VecReduce, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1434 | M(VecCnv, VecUnaryOperation) \ |
| 1435 | M(VecNeg, VecUnaryOperation) \ |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1436 | M(VecAbs, VecUnaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1437 | M(VecNot, VecUnaryOperation) \ |
| 1438 | M(VecAdd, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1439 | M(VecHalvingAdd, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1440 | M(VecSub, VecBinaryOperation) \ |
| 1441 | M(VecMul, VecBinaryOperation) \ |
| 1442 | M(VecDiv, VecBinaryOperation) \ |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 1443 | M(VecMin, VecBinaryOperation) \ |
| 1444 | M(VecMax, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1445 | M(VecAnd, VecBinaryOperation) \ |
| 1446 | M(VecAndNot, VecBinaryOperation) \ |
| 1447 | M(VecOr, VecBinaryOperation) \ |
| 1448 | M(VecXor, VecBinaryOperation) \ |
Aart Bik | 29aa082 | 2018-03-08 11:28:00 -0800 | [diff] [blame] | 1449 | M(VecSaturationAdd, VecBinaryOperation) \ |
| 1450 | M(VecSaturationSub, VecBinaryOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1451 | M(VecShl, VecBinaryOperation) \ |
| 1452 | M(VecShr, VecBinaryOperation) \ |
| 1453 | M(VecUShr, VecBinaryOperation) \ |
Aart Bik | 8de5916 | 2017-04-21 09:42:01 -0700 | [diff] [blame] | 1454 | M(VecSetScalars, VecOperation) \ |
Artem Serov | f34dd20 | 2017-04-10 17:41:46 +0100 | [diff] [blame] | 1455 | M(VecMultiplyAccumulate, VecOperation) \ |
Aart Bik | dbbac8f | 2017-09-01 13:06:08 -0700 | [diff] [blame] | 1456 | M(VecSADAccumulate, VecOperation) \ |
Artem Serov | aaac0e3 | 2018-08-07 00:52:22 +0100 | [diff] [blame] | 1457 | M(VecDotProd, VecOperation) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1458 | M(VecLoad, VecMemoryOperation) \ |
| 1459 | M(VecStore, VecMemoryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1460 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1461 | /* |
| 1462 | * Instructions, shared across several (not all) architectures. |
| 1463 | */ |
| 1464 | #if !defined(ART_ENABLE_CODEGEN_arm) && !defined(ART_ENABLE_CODEGEN_arm64) |
| 1465 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) |
| 1466 | #else |
| 1467 | #define FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Artem Serov | 7fc6350 | 2016-02-09 17:15:29 +0000 | [diff] [blame] | 1468 | M(BitwiseNegatedRight, Instruction) \ |
Anton Kirilov | 74234da | 2017-01-13 14:42:47 +0000 | [diff] [blame] | 1469 | M(DataProcWithShifterOp, Instruction) \ |
Artem Serov | 328429f | 2016-07-06 16:23:04 +0100 | [diff] [blame] | 1470 | M(MultiplyAccumulate, Instruction) \ |
Artem Serov | e1811ed | 2017-04-27 16:50:47 +0100 | [diff] [blame] | 1471 | M(IntermediateAddressIndex, Instruction) |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1472 | #endif |
| 1473 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1474 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1475 | |
| 1476 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1477 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1478 | #ifndef ART_ENABLE_CODEGEN_mips |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1479 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1480 | #else |
| 1481 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
| 1482 | M(MipsComputeBaseMethodAddress, Instruction) \ |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 1483 | M(MipsPackedSwitch, Instruction) \ |
| 1484 | M(IntermediateArrayAddressIndex, Instruction) |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1485 | #endif |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1486 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1487 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1488 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1489 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1490 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1491 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1492 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1493 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1494 | M(X86LoadFromConstantTable, Instruction) \ |
Mark P Mendell | 2f10a5f | 2016-01-25 14:47:50 +0000 | [diff] [blame] | 1495 | M(X86FPNeg, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1496 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1497 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1498 | |
| 1499 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1500 | |
| 1501 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1502 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 1503 | FOR_EACH_CONCRETE_INSTRUCTION_SHARED(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1504 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1505 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1506 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1507 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1508 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1509 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1510 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1511 | #define FOR_EACH_ABSTRACT_INSTRUCTION(M) \ |
| 1512 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1513 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1514 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1515 | M(BinaryOperation, Instruction) \ |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 1516 | M(Invoke, Instruction) \ |
| 1517 | M(VecOperation, Instruction) \ |
| 1518 | M(VecUnaryOperation, VecOperation) \ |
| 1519 | M(VecBinaryOperation, VecOperation) \ |
| 1520 | M(VecMemoryOperation, VecOperation) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1521 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1522 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1523 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1524 | FOR_EACH_ABSTRACT_INSTRUCTION(M) |
| 1525 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1526 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1527 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1528 | #undef FORWARD_DECLARATION |
| 1529 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 1530 | #define DECLARE_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1531 | private: \ |
| 1532 | H##type& operator=(const H##type&) = delete; \ |
| 1533 | public: \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1534 | const char* DebugName() const override { return #type; } \ |
| 1535 | HInstruction* Clone(ArenaAllocator* arena) const override { \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1536 | DCHECK(IsClonable()); \ |
| 1537 | return new (arena) H##type(*this->As##type()); \ |
| 1538 | } \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 1539 | void Accept(HGraphVisitor* visitor) override |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1540 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1541 | #define DECLARE_ABSTRACT_INSTRUCTION(type) \ |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1542 | private: \ |
| 1543 | H##type& operator=(const H##type&) = delete; \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 1544 | public: |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 1545 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 1546 | #define DEFAULT_COPY_CONSTRUCTOR(type) \ |
| 1547 | explicit H##type(const H##type& other) = default; |
| 1548 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1549 | template <typename T> |
Vladimir Marko | 82b0740 | 2017-03-01 19:02:04 +0000 | [diff] [blame] | 1550 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode>, |
| 1551 | public IntrusiveForwardListNode<HUseListNode<T>> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1552 | public: |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1553 | // Get the instruction which has this use as one of the inputs. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1554 | T GetUser() const { return user_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1555 | // Get the position of the input record that this use corresponds to. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1556 | size_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 1557 | // Set the position of the input record that this use corresponds to. |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1558 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1559 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1560 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1561 | HUseListNode(T user, size_t index) |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1562 | : user_(user), index_(index) {} |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1563 | |
| 1564 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1565 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1566 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1567 | friend class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1568 | |
| 1569 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1570 | }; |
| 1571 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1572 | template <typename T> |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1573 | using HUseList = IntrusiveForwardList<HUseListNode<T>>; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1574 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1575 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1576 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1577 | // by the used instructions. |
| 1578 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1579 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1580 | public: |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1581 | HUserRecord() : instruction_(nullptr), before_use_node_() {} |
| 1582 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), before_use_node_() {} |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1583 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1584 | HUserRecord(const HUserRecord<T>& old_record, typename HUseList<T>::iterator before_use_node) |
| 1585 | : HUserRecord(old_record.instruction_, before_use_node) {} |
| 1586 | HUserRecord(HInstruction* instruction, typename HUseList<T>::iterator before_use_node) |
| 1587 | : instruction_(instruction), before_use_node_(before_use_node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1588 | DCHECK(instruction_ != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | HInstruction* GetInstruction() const { return instruction_; } |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1592 | typename HUseList<T>::iterator GetBeforeUseNode() const { return before_use_node_; } |
| 1593 | typename HUseList<T>::iterator GetUseNode() const { return ++GetBeforeUseNode(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1594 | |
| 1595 | private: |
| 1596 | // Instruction used by the user. |
| 1597 | HInstruction* instruction_; |
| 1598 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 1599 | // Iterator before the corresponding entry in the use list kept by 'instruction_'. |
| 1600 | typename HUseList<T>::iterator before_use_node_; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1601 | }; |
| 1602 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 1603 | // Helper class that extracts the input instruction from HUserRecord<HInstruction*>. |
| 1604 | // This is used for HInstruction::GetInputs() to return a container wrapper providing |
| 1605 | // HInstruction* values even though the underlying container has HUserRecord<>s. |
| 1606 | struct HInputExtractor { |
| 1607 | HInstruction* operator()(HUserRecord<HInstruction*>& record) const { |
| 1608 | return record.GetInstruction(); |
| 1609 | } |
| 1610 | const HInstruction* operator()(const HUserRecord<HInstruction*>& record) const { |
| 1611 | return record.GetInstruction(); |
| 1612 | } |
| 1613 | }; |
| 1614 | |
| 1615 | using HInputsRef = TransformArrayRef<HUserRecord<HInstruction*>, HInputExtractor>; |
| 1616 | using HConstInputsRef = TransformArrayRef<const HUserRecord<HInstruction*>, HInputExtractor>; |
| 1617 | |
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 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1620 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1621 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1622 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1623 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1624 | * modify the value of a reference field read [although it may modify the |
| 1625 | * reference fetch prior to reading the field, which is represented by its own |
| 1626 | * write/read dependence]). The analysis makes conservative points-to |
| 1627 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1628 | * the same, and any reference read depends on any reference read without |
| 1629 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1630 | * |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1631 | * kDependsOnGCBit is defined in the following way: instructions with kDependsOnGCBit must not be |
| 1632 | * alive across the point where garbage collection might happen. |
| 1633 | * |
| 1634 | * Note: Instructions with kCanTriggerGCBit do not depend on each other. |
| 1635 | * |
| 1636 | * kCanTriggerGCBit must be used for instructions for which GC might happen on the path across |
| 1637 | * those instructions from the compiler perspective (between this instruction and the next one |
| 1638 | * in the IR). |
| 1639 | * |
| 1640 | * Note: Instructions which can cause GC only on a fatal slow path do not need |
| 1641 | * kCanTriggerGCBit as the execution never returns to the instruction next to the exceptional |
| 1642 | * one. However the execution may return to compiled code if there is a catch block in the |
| 1643 | * current method; for this purpose the TryBoundary exit instruction has kCanTriggerGCBit |
| 1644 | * set. |
| 1645 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1646 | * The internal representation uses 38-bit and is described in the table below. |
| 1647 | * The first line indicates the side effect, and for field/array accesses the |
| 1648 | * 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] | 1649 | * DataType::Type enum). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1650 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1651 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1652 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1653 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1654 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1655 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1656 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1657 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1658 | * |
| 1659 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1660 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1661 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1662 | class SideEffects : public ValueObject { |
| 1663 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1664 | SideEffects() : flags_(0) {} |
| 1665 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1666 | static SideEffects None() { |
| 1667 | return SideEffects(0); |
| 1668 | } |
| 1669 | |
| 1670 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1671 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1672 | } |
| 1673 | |
| 1674 | static SideEffects AllChanges() { |
| 1675 | return SideEffects(kAllChangeBits); |
| 1676 | } |
| 1677 | |
| 1678 | static SideEffects AllDependencies() { |
| 1679 | return SideEffects(kAllDependOnBits); |
| 1680 | } |
| 1681 | |
| 1682 | static SideEffects AllExceptGCDependency() { |
| 1683 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1684 | } |
| 1685 | |
| 1686 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1687 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1688 | } |
| 1689 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1690 | static SideEffects AllWrites() { |
| 1691 | return SideEffects(kAllWrites); |
| 1692 | } |
| 1693 | |
| 1694 | static SideEffects AllReads() { |
| 1695 | return SideEffects(kAllReads); |
| 1696 | } |
| 1697 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1698 | static SideEffects FieldWriteOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1699 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1700 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1701 | : SideEffects(TypeFlag(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1702 | } |
| 1703 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1704 | static SideEffects ArrayWriteOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1705 | return SideEffects(TypeFlag(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1706 | } |
| 1707 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1708 | static SideEffects FieldReadOfType(DataType::Type type, bool is_volatile) { |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1709 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1710 | ? AllWritesAndReads() |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1711 | : SideEffects(TypeFlag(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 1714 | static SideEffects ArrayReadOfType(DataType::Type type) { |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 1715 | return SideEffects(TypeFlag(type, kArrayReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1716 | } |
| 1717 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1718 | // Returns whether GC might happen across this instruction from the compiler perspective so |
| 1719 | // the next instruction in the IR would see that. |
| 1720 | // |
| 1721 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1722 | static SideEffects CanTriggerGC() { |
| 1723 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1724 | } |
| 1725 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 1726 | // Returns whether the instruction must not be alive across a GC point. |
| 1727 | // |
| 1728 | // See the SideEffect class comments. |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1729 | static SideEffects DependsOnGC() { |
| 1730 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1731 | } |
| 1732 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1733 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1734 | SideEffects Union(SideEffects other) const { |
| 1735 | return SideEffects(flags_ | other.flags_); |
| 1736 | } |
| 1737 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1738 | SideEffects Exclusion(SideEffects other) const { |
| 1739 | return SideEffects(flags_ & ~other.flags_); |
| 1740 | } |
| 1741 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1742 | void Add(SideEffects other) { |
| 1743 | flags_ |= other.flags_; |
| 1744 | } |
| 1745 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1746 | bool Includes(SideEffects other) const { |
| 1747 | return (other.flags_ & flags_) == other.flags_; |
| 1748 | } |
| 1749 | |
| 1750 | bool HasSideEffects() const { |
| 1751 | return (flags_ & kAllChangeBits); |
| 1752 | } |
| 1753 | |
| 1754 | bool HasDependencies() const { |
| 1755 | return (flags_ & kAllDependOnBits); |
| 1756 | } |
| 1757 | |
| 1758 | // Returns true if there are no side effects or dependencies. |
| 1759 | bool DoesNothing() const { |
| 1760 | return flags_ == 0; |
| 1761 | } |
| 1762 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1763 | // Returns true if something is written. |
| 1764 | bool DoesAnyWrite() const { |
| 1765 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1766 | } |
| 1767 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1768 | // Returns true if something is read. |
| 1769 | bool DoesAnyRead() const { |
| 1770 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1771 | } |
| 1772 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1773 | // Returns true if potentially everything is written and read |
| 1774 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1775 | bool DoesAllReadWrite() const { |
| 1776 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1777 | } |
| 1778 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1779 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1780 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1781 | } |
| 1782 | |
Roland Levillain | 0d5a281 | 2015-11-13 10:07:31 +0000 | [diff] [blame] | 1783 | // Returns true if `this` may read something written by `other`. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1784 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1785 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1786 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1790 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1791 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1792 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1793 | for (int s = kLastBit; s >= 0; s--) { |
| 1794 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1795 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1796 | // This is a bit for the GC side effect. |
| 1797 | if (current_bit_is_set) { |
| 1798 | flags += "GC"; |
| 1799 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1800 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1801 | } else { |
| 1802 | // This is a bit for the array/field analysis. |
| 1803 | // The underscore character stands for the 'can trigger GC' bit. |
| 1804 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1805 | if (current_bit_is_set) { |
| 1806 | flags += kDebug[s]; |
| 1807 | } |
| 1808 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1809 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1810 | flags += "|"; |
| 1811 | } |
| 1812 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1813 | } |
| 1814 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1815 | } |
| 1816 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1817 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1818 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1819 | private: |
| 1820 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1821 | |
| 1822 | static constexpr int kFieldWriteOffset = 0; |
| 1823 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1824 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1825 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1826 | |
| 1827 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1828 | |
| 1829 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1830 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1831 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1832 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1833 | |
| 1834 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1835 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1836 | |
| 1837 | // Aliases. |
| 1838 | |
| 1839 | static_assert(kChangeBits == kDependOnBits, |
| 1840 | "the 'change' bits should match the 'depend on' bits."); |
| 1841 | |
| 1842 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1843 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1844 | static constexpr uint64_t kAllWrites = |
| 1845 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1846 | static constexpr uint64_t kAllReads = |
| 1847 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1848 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1849 | // 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] | 1850 | static uint64_t TypeFlag(DataType::Type type, int offset) { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1851 | int shift; |
| 1852 | switch (type) { |
| 1853 | case DataType::Type::kReference: shift = 0; break; |
| 1854 | case DataType::Type::kBool: shift = 1; break; |
| 1855 | case DataType::Type::kInt8: shift = 2; break; |
| 1856 | case DataType::Type::kUint16: shift = 3; break; |
| 1857 | case DataType::Type::kInt16: shift = 4; break; |
| 1858 | case DataType::Type::kInt32: shift = 5; break; |
| 1859 | case DataType::Type::kInt64: shift = 6; break; |
| 1860 | case DataType::Type::kFloat32: shift = 7; break; |
| 1861 | case DataType::Type::kFloat64: shift = 8; break; |
| 1862 | default: |
| 1863 | LOG(FATAL) << "Unexpected data type " << type; |
| 1864 | UNREACHABLE(); |
| 1865 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1866 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1867 | DCHECK_LT(shift, kArrayWriteOffset); |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 1868 | return UINT64_C(1) << (shift + offset); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | // Private constructor on direct flags value. |
| 1872 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1873 | |
| 1874 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1875 | }; |
| 1876 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1877 | // 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] | 1878 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1879 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1880 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
Mingyao Yang | 01b47b0 | 2017-02-03 12:09:57 -0800 | [diff] [blame] | 1881 | size_t number_of_vregs, |
| 1882 | ArtMethod* method, |
| 1883 | uint32_t dex_pc, |
| 1884 | HInstruction* holder) |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1885 | : vregs_(number_of_vregs, allocator->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1886 | locations_(allocator->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1887 | parent_(nullptr), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1888 | method_(method), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1889 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1890 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1891 | } |
| 1892 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 1893 | ALWAYS_INLINE HEnvironment(ArenaAllocator* allocator, |
| 1894 | const HEnvironment& to_copy, |
| 1895 | HInstruction* holder) |
| 1896 | : HEnvironment(allocator, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1897 | to_copy.Size(), |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1898 | to_copy.GetMethod(), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1899 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1900 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1901 | |
Vladimir Marko | ec32f64 | 2017-06-02 10:51:55 +0100 | [diff] [blame] | 1902 | void AllocateLocations() { |
| 1903 | DCHECK(locations_.empty()); |
| 1904 | locations_.resize(vregs_.size()); |
| 1905 | } |
| 1906 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1907 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1908 | if (parent_ != nullptr) { |
| 1909 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1910 | } else { |
| 1911 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1912 | parent_->CopyFrom(parent); |
| 1913 | if (parent->GetParent() != nullptr) { |
| 1914 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1915 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1916 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1917 | } |
| 1918 | |
Vladimir Marko | 69d310e | 2017-10-09 14:12:23 +0100 | [diff] [blame] | 1919 | void CopyFrom(ArrayRef<HInstruction* const> locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1920 | void CopyFrom(HEnvironment* environment); |
| 1921 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1922 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1923 | // input to the loop phi instead. This is for inserting instructions that |
| 1924 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1925 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1926 | |
| 1927 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1928 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1932 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1933 | } |
| 1934 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1935 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1936 | |
Artem Serov | ca210e3 | 2017-12-15 13:43:20 +0000 | [diff] [blame] | 1937 | // Replaces the input at the position 'index' with the replacement; the replacement and old |
| 1938 | // input instructions' env_uses_ lists are adjusted. The function works similar to |
| 1939 | // HInstruction::ReplaceInput. |
| 1940 | void ReplaceInput(HInstruction* replacement, size_t index); |
| 1941 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1942 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1943 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1944 | HEnvironment* GetParent() const { return parent_; } |
| 1945 | |
| 1946 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1947 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1951 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | uint32_t GetDexPc() const { |
| 1955 | return dex_pc_; |
| 1956 | } |
| 1957 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1958 | ArtMethod* GetMethod() const { |
| 1959 | return method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1962 | HInstruction* GetHolder() const { |
| 1963 | return holder_; |
| 1964 | } |
| 1965 | |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 1966 | |
| 1967 | bool IsFromInlinedInvoke() const { |
| 1968 | return GetParent() != nullptr; |
| 1969 | } |
| 1970 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1971 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1972 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1973 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1974 | HEnvironment* parent_; |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 1975 | ArtMethod* method_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1976 | const uint32_t dex_pc_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1977 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1978 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1979 | HInstruction* const holder_; |
| 1980 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1981 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1982 | |
| 1983 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1984 | }; |
| 1985 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1986 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1987 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1988 | #define DECLARE_KIND(type, super) k##type, |
| 1989 | enum InstructionKind { |
Vladimir Marko | e394622 | 2018-05-04 14:18:47 +0100 | [diff] [blame] | 1990 | FOR_EACH_CONCRETE_INSTRUCTION(DECLARE_KIND) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 1991 | kLastInstructionKind |
| 1992 | }; |
| 1993 | #undef DECLARE_KIND |
| 1994 | |
| 1995 | HInstruction(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 1996 | : HInstruction(kind, DataType::Type::kVoid, side_effects, dex_pc) {} |
| 1997 | |
| 1998 | 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] | 1999 | : previous_(nullptr), |
| 2000 | next_(nullptr), |
| 2001 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2002 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2003 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2004 | ssa_index_(-1), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2005 | packed_fields_(0u), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2006 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2007 | locations_(nullptr), |
| 2008 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2009 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 2010 | side_effects_(side_effects), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2011 | reference_type_handle_(ReferenceTypeInfo::CreateInvalid().GetTypeHandle()) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2012 | SetPackedField<InstructionKindField>(kind); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2013 | SetPackedField<TypeField>(type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2014 | SetPackedFlag<kFlagReferenceTypeIsExact>(ReferenceTypeInfo::CreateInvalid().IsExact()); |
| 2015 | } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2016 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2017 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2018 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2019 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2020 | HInstruction* GetNext() const { return next_; } |
| 2021 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2022 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2023 | HInstruction* GetNextDisregardingMoves() const; |
| 2024 | HInstruction* GetPreviousDisregardingMoves() const; |
| 2025 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2026 | HBasicBlock* GetBlock() const { return block_; } |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2027 | ArenaAllocator* GetAllocator() const { return block_->GetGraph()->GetAllocator(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2028 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 2029 | bool IsInBlock() const { return block_ != nullptr; } |
| 2030 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 15bd228 | 2016-01-05 15:55:41 +0000 | [diff] [blame] | 2031 | bool IsLoopHeaderPhi() const { return IsPhi() && block_->IsLoopHeader(); } |
| 2032 | bool IsIrreducibleLoopHeaderPhi() const { |
| 2033 | return IsLoopHeaderPhi() && GetBlock()->GetLoopInformation()->IsIrreducible(); |
| 2034 | } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2035 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2036 | virtual ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() = 0; |
| 2037 | |
| 2038 | ArrayRef<const HUserRecord<HInstruction*>> GetInputRecords() const { |
| 2039 | // One virtual method is enough, just const_cast<> and then re-add the const. |
| 2040 | return ArrayRef<const HUserRecord<HInstruction*>>( |
| 2041 | const_cast<HInstruction*>(this)->GetInputRecords()); |
| 2042 | } |
| 2043 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2044 | HInputsRef GetInputs() { |
| 2045 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2046 | } |
| 2047 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2048 | HConstInputsRef GetInputs() const { |
| 2049 | return MakeTransformArrayRef(GetInputRecords(), HInputExtractor()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | size_t InputCount() const { return GetInputRecords().size(); } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2053 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2054 | |
Aart Bik | 2767f4b | 2016-10-28 15:03:53 -0700 | [diff] [blame] | 2055 | bool HasInput(HInstruction* input) const { |
| 2056 | for (const HInstruction* i : GetInputs()) { |
| 2057 | if (i == input) { |
| 2058 | return true; |
| 2059 | } |
| 2060 | } |
| 2061 | return false; |
| 2062 | } |
| 2063 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2064 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 2065 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 2066 | } |
| 2067 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2068 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 2069 | virtual const char* DebugName() const = 0; |
| 2070 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2071 | DataType::Type GetType() const { |
| 2072 | return TypeField::Decode(GetPackedFields()); |
| 2073 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2074 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2075 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2076 | |
| 2077 | uint32_t GetDexPc() const { return dex_pc_; } |
| 2078 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2079 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2080 | |
Nicolas Geoffray | 331605a | 2017-03-01 11:01:41 +0000 | [diff] [blame] | 2081 | // Can the instruction throw? |
| 2082 | // TODO: We should rename to CanVisiblyThrow, as some instructions (like HNewInstance), |
| 2083 | // 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] | 2084 | virtual bool CanThrow() const { return false; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 2085 | |
| 2086 | // Does the instruction always throw an exception unconditionally? |
| 2087 | virtual bool AlwaysThrows() const { return false; } |
| 2088 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 2089 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2090 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2091 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 2092 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2093 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2094 | // Does not apply for all instructions, but having this at top level greatly |
| 2095 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 2096 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2097 | virtual bool CanBeNull() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2098 | DCHECK_EQ(GetType(), DataType::Type::kReference) << "CanBeNull only applies to reference types"; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 2099 | return true; |
| 2100 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 2101 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2102 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 2103 | return false; |
| 2104 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 2105 | |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 2106 | // If this instruction will do an implicit null check, return the `HNullCheck` associated |
| 2107 | // with it. Otherwise return null. |
| 2108 | HNullCheck* GetImplicitNullCheck() const { |
| 2109 | // Find the first previous instruction which is not a move. |
| 2110 | HInstruction* first_prev_not_move = GetPreviousDisregardingMoves(); |
| 2111 | if (first_prev_not_move != nullptr && |
| 2112 | first_prev_not_move->IsNullCheck() && |
| 2113 | first_prev_not_move->IsEmittedAtUseSite()) { |
| 2114 | return first_prev_not_move->AsNullCheck(); |
| 2115 | } |
| 2116 | return nullptr; |
| 2117 | } |
| 2118 | |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2119 | virtual bool IsActualObject() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2120 | return GetType() == DataType::Type::kReference; |
Nicolas Geoffray | a3eca2d | 2016-01-12 16:03:16 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 2123 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2124 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2125 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2126 | DCHECK_EQ(GetType(), DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2127 | return ReferenceTypeInfo::CreateUnchecked(reference_type_handle_, |
Vladimir Marko | 456307a | 2016-04-19 14:12:13 +0000 | [diff] [blame] | 2128 | GetPackedFlag<kFlagReferenceTypeIsExact>()); |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 2129 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2130 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2131 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2132 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2133 | // Note: fixup_end remains valid across push_front(). |
| 2134 | auto fixup_end = uses_.empty() ? uses_.begin() : ++uses_.begin(); |
| 2135 | HUseListNode<HInstruction*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2136 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HInstruction*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2137 | uses_.push_front(*new_node); |
| 2138 | FixUpUserRecordsAfterUseInsertion(fixup_end); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2141 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 2142 | DCHECK(user != nullptr); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2143 | // Note: env_fixup_end remains valid across push_front(). |
| 2144 | auto env_fixup_end = env_uses_.empty() ? env_uses_.begin() : ++env_uses_.begin(); |
| 2145 | HUseListNode<HEnvironment*>* new_node = |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2146 | new (GetBlock()->GetGraph()->GetAllocator()) HUseListNode<HEnvironment*>(user, index); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2147 | env_uses_.push_front(*new_node); |
| 2148 | FixUpUserRecordsAfterEnvUseInsertion(env_fixup_end); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2149 | } |
| 2150 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2151 | void RemoveAsUserOfInput(size_t input) { |
| 2152 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2153 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2154 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2155 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2156 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2157 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2158 | void RemoveAsUserOfAllInputs() { |
| 2159 | for (const HUserRecord<HInstruction*>& input_use : GetInputRecords()) { |
| 2160 | HUseList<HInstruction*>::iterator before_use_node = input_use.GetBeforeUseNode(); |
| 2161 | input_use.GetInstruction()->uses_.erase_after(before_use_node); |
| 2162 | input_use.GetInstruction()->FixUpUserRecordsAfterUseRemoval(before_use_node); |
| 2163 | } |
| 2164 | } |
| 2165 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2166 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 2167 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2168 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2169 | bool HasUses() const { return !uses_.empty() || !env_uses_.empty(); } |
| 2170 | bool HasEnvironmentUses() const { return !env_uses_.empty(); } |
| 2171 | bool HasNonEnvironmentUses() const { return !uses_.empty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2172 | bool HasOnlyOneNonEnvironmentUse() const { |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2173 | return !HasEnvironmentUses() && GetUses().HasExactlyOneElement(); |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2174 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2175 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2176 | bool IsRemovable() const { |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2177 | return |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 2178 | !DoesAnyWrite() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2179 | !CanThrow() && |
| 2180 | !IsSuspendCheck() && |
| 2181 | !IsControlFlow() && |
| 2182 | !IsNativeDebugInfo() && |
| 2183 | !IsParameterValue() && |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2184 | // If we added an explicit barrier then we should keep it. |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2185 | !IsMemoryBarrier() && |
| 2186 | !IsConstructorFence(); |
Aart Bik | 482095d | 2016-10-10 15:39:10 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
Aart Bik | cc42be0 | 2016-10-20 16:14:16 -0700 | [diff] [blame] | 2189 | bool IsDeadAndRemovable() const { |
| 2190 | return IsRemovable() && !HasUses(); |
| 2191 | } |
| 2192 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 2193 | // Does this instruction strictly dominate `other_instruction`? |
| 2194 | // Returns false if this instruction and `other_instruction` are the same. |
| 2195 | // Aborts if this instruction and `other_instruction` are both phis. |
| 2196 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2197 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2198 | int GetId() const { return id_; } |
| 2199 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2200 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2201 | int GetSsaIndex() const { return ssa_index_; } |
| 2202 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 2203 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 2204 | |
| 2205 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 2206 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2207 | // Set the `environment_` field. Raw because this method does not |
| 2208 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2209 | void SetRawEnvironment(HEnvironment* environment) { |
| 2210 | DCHECK(environment_ == nullptr); |
| 2211 | DCHECK_EQ(environment->GetHolder(), this); |
| 2212 | environment_ = environment; |
| 2213 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2214 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 2215 | void InsertRawEnvironment(HEnvironment* environment) { |
| 2216 | DCHECK(environment_ != nullptr); |
| 2217 | DCHECK_EQ(environment->GetHolder(), this); |
| 2218 | DCHECK(environment->GetParent() == nullptr); |
| 2219 | environment->parent_ = environment_; |
| 2220 | environment_ = environment; |
| 2221 | } |
| 2222 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 2223 | void RemoveEnvironment(); |
| 2224 | |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2225 | // Set the environment of this instruction, copying it from `environment`. While |
| 2226 | // copying, the uses lists are being updated. |
| 2227 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2228 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2229 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2230 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2231 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2232 | if (environment->GetParent() != nullptr) { |
| 2233 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2234 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 2235 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2236 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2237 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 2238 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2239 | DCHECK(environment_ == nullptr); |
Vladimir Marko | ca6fff8 | 2017-10-03 14:49:14 +0100 | [diff] [blame] | 2240 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetAllocator(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 2241 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 2242 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 2243 | if (environment->GetParent() != nullptr) { |
| 2244 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 2245 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2248 | // Returns the number of entries in the environment. Typically, that is the |
| 2249 | // number of dex registers in a method. It could be more in case of inlining. |
| 2250 | size_t EnvironmentSize() const; |
| 2251 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2252 | LocationSummary* GetLocations() const { return locations_; } |
| 2253 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2254 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2255 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 2256 | void ReplaceUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 8a62a4c | 2018-07-03 09:39:07 +0100 | [diff] [blame] | 2257 | void ReplaceEnvUsesDominatedBy(HInstruction* dominator, HInstruction* replacement); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2258 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2259 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 2260 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 2261 | // uses of this instruction by `other` are *not* updated. |
| 2262 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 2263 | ReplaceWith(other); |
| 2264 | other->ReplaceInput(this, use_index); |
| 2265 | } |
| 2266 | |
Alexandre Rames | 22aa54b | 2016-10-18 09:32:29 +0100 | [diff] [blame] | 2267 | // Move `this` instruction before `cursor` |
| 2268 | void MoveBefore(HInstruction* cursor, bool do_checks = true); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2269 | |
Vladimir Marko | fb337ea | 2015-11-25 15:25:10 +0000 | [diff] [blame] | 2270 | // Move `this` before its first user and out of any loops. If there is no |
| 2271 | // out-of-loop user that dominates all other users, move the instruction |
| 2272 | // to the end of the out-of-loop common dominator of the user's blocks. |
| 2273 | // |
| 2274 | // This can be used only on non-throwing instructions with no side effects that |
| 2275 | // have at least one use but no environment uses. |
| 2276 | void MoveBeforeFirstUserAndOutOfLoops(); |
| 2277 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2278 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2279 | bool Is##type() const; |
| 2280 | |
| 2281 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 2282 | #undef INSTRUCTION_TYPE_CHECK |
| 2283 | |
| 2284 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2285 | const H##type* As##type() const; \ |
| 2286 | H##type* As##type(); |
| 2287 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 2288 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 2289 | #undef INSTRUCTION_TYPE_CAST |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2290 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2291 | // Return a clone of the instruction if it is clonable (shallow copy by default, custom copy |
| 2292 | // if a custom copy-constructor is provided for a particular type). If IsClonable() is false for |
| 2293 | // the instruction then the behaviour of this function is undefined. |
| 2294 | // |
| 2295 | // Note: It is semantically valid to create a clone of the instruction only until |
| 2296 | // prepare_for_register_allocator phase as lifetime, intervals and codegen info are not |
| 2297 | // copied. |
| 2298 | // |
| 2299 | // Note: HEnvironment and some other fields are not copied and are set to default values, see |
| 2300 | // 'explicit HInstruction(const HInstruction& other)' for details. |
| 2301 | virtual HInstruction* Clone(ArenaAllocator* arena ATTRIBUTE_UNUSED) const { |
| 2302 | LOG(FATAL) << "Cloning is not implemented for the instruction " << |
| 2303 | DebugName() << " " << GetId(); |
| 2304 | UNREACHABLE(); |
| 2305 | } |
| 2306 | |
| 2307 | // Return whether instruction can be cloned (copied). |
| 2308 | virtual bool IsClonable() const { return false; } |
| 2309 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2310 | // Returns whether the instruction can be moved within the graph. |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 2311 | // TODO: this method is used by LICM and GVN with possibly different |
| 2312 | // meanings? split and rename? |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2313 | virtual bool CanBeMoved() const { return false; } |
| 2314 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2315 | // Returns whether any data encoded in the two instructions is equal. |
| 2316 | // This method does not look at the inputs. Both instructions must be |
| 2317 | // of the same type, otherwise the method has undefined behavior. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2318 | virtual bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2319 | return false; |
| 2320 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2321 | |
| 2322 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2323 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2324 | // 2) Their inputs are identical. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2325 | bool Equals(const HInstruction* other) const; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2326 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2327 | // TODO: Remove this indirection when the [[pure]] attribute proposal (n3744) |
| 2328 | // is adopted and implemented by our C++ compiler(s). Fow now, we need to hide |
| 2329 | // the virtual function because the __attribute__((__pure__)) doesn't really |
| 2330 | // apply the strong requirement for virtual functions, preventing optimizations. |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2331 | InstructionKind GetKind() const { return GetPackedField<InstructionKindField>(); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2332 | |
| 2333 | virtual size_t ComputeHashCode() const { |
| 2334 | size_t result = GetKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2335 | for (const HInstruction* input : GetInputs()) { |
| 2336 | result = (result * 31) + input->GetId(); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2337 | } |
| 2338 | return result; |
| 2339 | } |
| 2340 | |
| 2341 | SideEffects GetSideEffects() const { return side_effects_; } |
Nicolas Geoffray | e4084a5 | 2016-02-18 14:43:42 +0000 | [diff] [blame] | 2342 | void SetSideEffects(SideEffects other) { side_effects_ = other; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2343 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 2344 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2345 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 2346 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 2347 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 2348 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 2349 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 2350 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2351 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 2352 | |
| 2353 | // Returns whether the code generation of the instruction will require to have access |
| 2354 | // to the current method. Such instructions are: |
| 2355 | // (1): Instructions that require an environment, as calling the runtime requires |
| 2356 | // 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] | 2357 | // (2): HCurrentMethod, potentially used by HInvokeStaticOrDirect, HLoadString, or HLoadClass |
| 2358 | // to access the dex cache. |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2359 | bool NeedsCurrentMethod() const { |
Nicolas Geoffray | 96eeb4e | 2016-10-12 22:03:31 +0100 | [diff] [blame] | 2360 | return NeedsEnvironment() || IsCurrentMethod(); |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 2363 | // Returns whether the code generation of the instruction will require to have access |
| 2364 | // to the dex cache of the current method's declaring class via the current method. |
| 2365 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 2366 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2367 | // Does this instruction have any use in an environment before |
| 2368 | // control flow hits 'other'? |
| 2369 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 2370 | |
| 2371 | // Remove all references to environment uses of this instruction. |
| 2372 | // The caller must ensure that this is safe to do. |
| 2373 | void RemoveEnvironmentUsers(); |
| 2374 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2375 | bool IsEmittedAtUseSite() const { return GetPackedFlag<kFlagEmittedAtUseSite>(); } |
| 2376 | void MarkEmittedAtUseSite() { SetPackedFlag<kFlagEmittedAtUseSite>(true); } |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2377 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2378 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2379 | // If set, the machine code for this instruction is assumed to be generated by |
| 2380 | // its users. Used by liveness analysis to compute use positions accordingly. |
| 2381 | static constexpr size_t kFlagEmittedAtUseSite = 0u; |
| 2382 | static constexpr size_t kFlagReferenceTypeIsExact = kFlagEmittedAtUseSite + 1; |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2383 | static constexpr size_t kFieldInstructionKind = kFlagReferenceTypeIsExact + 1; |
| 2384 | static constexpr size_t kFieldInstructionKindSize = |
| 2385 | MinimumBitsToStore(static_cast<size_t>(InstructionKind::kLastInstructionKind - 1)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2386 | static constexpr size_t kFieldType = |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2387 | kFieldInstructionKind + kFieldInstructionKindSize; |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2388 | static constexpr size_t kFieldTypeSize = |
| 2389 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
| 2390 | static constexpr size_t kNumberOfGenericPackedBits = kFieldType + kFieldTypeSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2391 | static constexpr size_t kMaxNumberOfPackedBits = sizeof(uint32_t) * kBitsPerByte; |
| 2392 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2393 | static_assert(kNumberOfGenericPackedBits <= kMaxNumberOfPackedBits, |
| 2394 | "Too many generic packed fields"); |
| 2395 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2396 | using TypeField = BitField<DataType::Type, kFieldType, kFieldTypeSize>; |
| 2397 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2398 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const { |
| 2399 | return GetInputRecords()[i]; |
| 2400 | } |
| 2401 | |
| 2402 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) { |
| 2403 | ArrayRef<HUserRecord<HInstruction*>> input_records = GetInputRecords(); |
| 2404 | input_records[index] = input; |
| 2405 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2406 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2407 | uint32_t GetPackedFields() const { |
| 2408 | return packed_fields_; |
| 2409 | } |
| 2410 | |
| 2411 | template <size_t flag> |
| 2412 | bool GetPackedFlag() const { |
| 2413 | return (packed_fields_ & (1u << flag)) != 0u; |
| 2414 | } |
| 2415 | |
| 2416 | template <size_t flag> |
| 2417 | void SetPackedFlag(bool value = true) { |
| 2418 | packed_fields_ = (packed_fields_ & ~(1u << flag)) | ((value ? 1u : 0u) << flag); |
| 2419 | } |
| 2420 | |
| 2421 | template <typename BitFieldType> |
| 2422 | typename BitFieldType::value_type GetPackedField() const { |
| 2423 | return BitFieldType::Decode(packed_fields_); |
| 2424 | } |
| 2425 | |
| 2426 | template <typename BitFieldType> |
| 2427 | void SetPackedField(typename BitFieldType::value_type value) { |
| 2428 | DCHECK(IsUint<BitFieldType::size>(static_cast<uintptr_t>(value))); |
| 2429 | packed_fields_ = BitFieldType::Update(value, packed_fields_); |
| 2430 | } |
| 2431 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2432 | // Copy construction for the instruction (used for Clone function). |
| 2433 | // |
| 2434 | // Fields (e.g. lifetime, intervals and codegen info) associated with phases starting from |
| 2435 | // prepare_for_register_allocator are not copied (set to default values). |
| 2436 | // |
| 2437 | // Copy constructors must be provided for every HInstruction type; default copy constructor is |
| 2438 | // fine for most of them. However for some of the instructions a custom copy constructor must be |
| 2439 | // specified (when instruction has non-trivially copyable fields and must have a special behaviour |
| 2440 | // for copying them). |
| 2441 | explicit HInstruction(const HInstruction& other) |
| 2442 | : previous_(nullptr), |
| 2443 | next_(nullptr), |
| 2444 | block_(nullptr), |
| 2445 | dex_pc_(other.dex_pc_), |
| 2446 | id_(-1), |
| 2447 | ssa_index_(-1), |
| 2448 | packed_fields_(other.packed_fields_), |
| 2449 | environment_(nullptr), |
| 2450 | locations_(nullptr), |
| 2451 | live_interval_(nullptr), |
| 2452 | lifetime_position_(kNoLifetime), |
| 2453 | side_effects_(other.side_effects_), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2454 | reference_type_handle_(other.reference_type_handle_) { |
| 2455 | } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2456 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2457 | private: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2458 | using InstructionKindField = |
| 2459 | BitField<InstructionKind, kFieldInstructionKind, kFieldInstructionKindSize>; |
| 2460 | |
Vladimir Marko | 46817b8 | 2016-03-29 12:21:58 +0100 | [diff] [blame] | 2461 | void FixUpUserRecordsAfterUseInsertion(HUseList<HInstruction*>::iterator fixup_end) { |
| 2462 | auto before_use_node = uses_.before_begin(); |
| 2463 | for (auto use_node = uses_.begin(); use_node != fixup_end; ++use_node) { |
| 2464 | HInstruction* user = use_node->GetUser(); |
| 2465 | size_t input_index = use_node->GetIndex(); |
| 2466 | user->SetRawInputRecordAt(input_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2467 | before_use_node = use_node; |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | void FixUpUserRecordsAfterUseRemoval(HUseList<HInstruction*>::iterator before_use_node) { |
| 2472 | auto next = ++HUseList<HInstruction*>::iterator(before_use_node); |
| 2473 | if (next != uses_.end()) { |
| 2474 | HInstruction* next_user = next->GetUser(); |
| 2475 | size_t next_index = next->GetIndex(); |
| 2476 | DCHECK(next_user->InputRecordAt(next_index).GetInstruction() == this); |
| 2477 | next_user->SetRawInputRecordAt(next_index, HUserRecord<HInstruction*>(this, before_use_node)); |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | void FixUpUserRecordsAfterEnvUseInsertion(HUseList<HEnvironment*>::iterator env_fixup_end) { |
| 2482 | auto before_env_use_node = env_uses_.before_begin(); |
| 2483 | for (auto env_use_node = env_uses_.begin(); env_use_node != env_fixup_end; ++env_use_node) { |
| 2484 | HEnvironment* user = env_use_node->GetUser(); |
| 2485 | size_t input_index = env_use_node->GetIndex(); |
| 2486 | user->vregs_[input_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2487 | before_env_use_node = env_use_node; |
| 2488 | } |
| 2489 | } |
| 2490 | |
| 2491 | void FixUpUserRecordsAfterEnvUseRemoval(HUseList<HEnvironment*>::iterator before_env_use_node) { |
| 2492 | auto next = ++HUseList<HEnvironment*>::iterator(before_env_use_node); |
| 2493 | if (next != env_uses_.end()) { |
| 2494 | HEnvironment* next_user = next->GetUser(); |
| 2495 | size_t next_index = next->GetIndex(); |
| 2496 | DCHECK(next_user->vregs_[next_index].GetInstruction() == this); |
| 2497 | next_user->vregs_[next_index] = HUserRecord<HEnvironment*>(this, before_env_use_node); |
| 2498 | } |
| 2499 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2500 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2501 | HInstruction* previous_; |
| 2502 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2503 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2504 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2505 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2506 | // An instruction gets an id when it is added to the graph. |
| 2507 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2508 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2509 | int id_; |
| 2510 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2511 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2512 | int ssa_index_; |
| 2513 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2514 | // Packed fields. |
| 2515 | uint32_t packed_fields_; |
David Brazdil | b3e773e | 2016-01-26 11:28:37 +0000 | [diff] [blame] | 2516 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2517 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2518 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2519 | |
| 2520 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2521 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2522 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2523 | // The environment associated with this instruction. Not null if the instruction |
| 2524 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2525 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2526 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2527 | // Set by the code generator. |
| 2528 | LocationSummary* locations_; |
| 2529 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2530 | // Set by the liveness analysis. |
| 2531 | LiveInterval* live_interval_; |
| 2532 | |
| 2533 | // Set by the liveness analysis, this is the position in a linear |
| 2534 | // order of blocks where this instruction's live interval start. |
| 2535 | size_t lifetime_position_; |
| 2536 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2537 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2538 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2539 | // The reference handle part of the reference type info. |
| 2540 | // The IsExact() flag is stored in packed fields. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2541 | // TODO: for primitive types this should be marked as invalid. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 2542 | ReferenceTypeInfo::TypeHandle reference_type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2543 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2544 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2545 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2546 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2547 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2548 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2549 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2550 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2551 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2552 | // Iterates over the instructions, while preserving the next instruction |
| 2553 | // in case the current instruction gets removed from the list by the user |
| 2554 | // of this iterator. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2555 | class HInstructionIterator : public ValueObject { |
| 2556 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2557 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2558 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2559 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2562 | bool Done() const { return instruction_ == nullptr; } |
| 2563 | HInstruction* Current() const { return instruction_; } |
| 2564 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2565 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2566 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
| 2569 | private: |
| 2570 | HInstruction* instruction_; |
| 2571 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2572 | |
| 2573 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2574 | }; |
| 2575 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 2576 | // Iterates over the instructions without saving the next instruction, |
| 2577 | // therefore handling changes in the graph potentially made by the user |
| 2578 | // of this iterator. |
| 2579 | class HInstructionIteratorHandleChanges : public ValueObject { |
| 2580 | public: |
| 2581 | explicit HInstructionIteratorHandleChanges(const HInstructionList& instructions) |
| 2582 | : instruction_(instructions.first_instruction_) { |
| 2583 | } |
| 2584 | |
| 2585 | bool Done() const { return instruction_ == nullptr; } |
| 2586 | HInstruction* Current() const { return instruction_; } |
| 2587 | void Advance() { |
| 2588 | instruction_ = instruction_->GetNext(); |
| 2589 | } |
| 2590 | |
| 2591 | private: |
| 2592 | HInstruction* instruction_; |
| 2593 | |
| 2594 | DISALLOW_COPY_AND_ASSIGN(HInstructionIteratorHandleChanges); |
| 2595 | }; |
| 2596 | |
| 2597 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2598 | class HBackwardInstructionIterator : public ValueObject { |
| 2599 | public: |
| 2600 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2601 | : instruction_(instructions.last_instruction_) { |
| 2602 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2603 | } |
| 2604 | |
| 2605 | bool Done() const { return instruction_ == nullptr; } |
| 2606 | HInstruction* Current() const { return instruction_; } |
| 2607 | void Advance() { |
| 2608 | instruction_ = next_; |
| 2609 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2610 | } |
| 2611 | |
| 2612 | private: |
| 2613 | HInstruction* instruction_; |
| 2614 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2615 | |
| 2616 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2617 | }; |
| 2618 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2619 | class HVariableInputSizeInstruction : public HInstruction { |
| 2620 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2621 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2622 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 2623 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
| 2624 | } |
| 2625 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2626 | void AddInput(HInstruction* input); |
| 2627 | void InsertInputAt(size_t index, HInstruction* input); |
| 2628 | void RemoveInputAt(size_t index); |
| 2629 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 2630 | // Removes all the inputs. |
| 2631 | // Also removes this instructions from each input's use list |
| 2632 | // (for non-environment uses only). |
| 2633 | void RemoveAllInputs(); |
| 2634 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2635 | protected: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2636 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2637 | SideEffects side_effects, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2638 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2639 | ArenaAllocator* allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2640 | size_t number_of_inputs, |
| 2641 | ArenaAllocKind kind) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2642 | : HInstruction(inst_kind, side_effects, dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2643 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2644 | HVariableInputSizeInstruction(InstructionKind inst_kind, |
| 2645 | DataType::Type type, |
| 2646 | SideEffects side_effects, |
| 2647 | uint32_t dex_pc, |
| 2648 | ArenaAllocator* allocator, |
| 2649 | size_t number_of_inputs, |
| 2650 | ArenaAllocKind kind) |
| 2651 | : HInstruction(inst_kind, type, side_effects, dex_pc), |
| 2652 | inputs_(number_of_inputs, allocator->Adapter(kind)) {} |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2653 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2654 | DEFAULT_COPY_CONSTRUCTOR(VariableInputSizeInstruction); |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2655 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2656 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2657 | }; |
| 2658 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2659 | template<size_t N> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2660 | class HExpression : public HInstruction { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2661 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2662 | HExpression<N>(InstructionKind kind, SideEffects side_effects, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2663 | : HInstruction(kind, side_effects, dex_pc), inputs_() {} |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2664 | HExpression<N>(InstructionKind kind, |
| 2665 | DataType::Type type, |
| 2666 | SideEffects side_effects, |
| 2667 | uint32_t dex_pc) |
| 2668 | : HInstruction(kind, type, side_effects, dex_pc), inputs_() {} |
| 2669 | virtual ~HExpression() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2670 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2671 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2672 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2673 | return ArrayRef<HUserRecord<HInstruction*>>(inputs_); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2674 | } |
| 2675 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2676 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2677 | DEFAULT_COPY_CONSTRUCTOR(Expression<N>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2678 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2679 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2680 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2681 | |
| 2682 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2683 | }; |
| 2684 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2685 | // HExpression specialization for N=0. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2686 | template<> |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2687 | class HExpression<0> : public HInstruction { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2688 | public: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2689 | using HInstruction::HInstruction; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2690 | |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2691 | virtual ~HExpression() {} |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2692 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2693 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 2694 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 2695 | return ArrayRef<HUserRecord<HInstruction*>>(); |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2696 | } |
| 2697 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2698 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2699 | DEFAULT_COPY_CONSTRUCTOR(Expression<0>); |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2700 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2701 | private: |
| 2702 | friend class SsaBuilder; |
| 2703 | }; |
| 2704 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2705 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2706 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2707 | class HReturnVoid final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2708 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2709 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2710 | : HExpression(kReturnVoid, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2711 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2712 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2713 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2714 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2715 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2716 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2717 | protected: |
| 2718 | DEFAULT_COPY_CONSTRUCTOR(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2719 | }; |
| 2720 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2721 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2722 | // instruction that branches to the exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2723 | class HReturn final : public HExpression<1> { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2724 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2725 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2726 | : HExpression(kReturn, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2727 | SetRawInputAt(0, value); |
| 2728 | } |
| 2729 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2730 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2731 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2732 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2733 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2734 | protected: |
| 2735 | DEFAULT_COPY_CONSTRUCTOR(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2736 | }; |
| 2737 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2738 | class HPhi final : public HVariableInputSizeInstruction { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2739 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2740 | HPhi(ArenaAllocator* allocator, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2741 | uint32_t reg_number, |
| 2742 | size_t number_of_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2743 | DataType::Type type, |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2744 | uint32_t dex_pc = kNoDexPc) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2745 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2746 | kPhi, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2747 | ToPhiType(type), |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2748 | SideEffects::None(), |
| 2749 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 2750 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 2751 | number_of_inputs, |
| 2752 | kArenaAllocPhiInputs), |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2753 | reg_number_(reg_number) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2754 | DCHECK_NE(GetType(), DataType::Type::kVoid); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2755 | // Phis are constructed live and marked dead if conflicting or unused. |
| 2756 | // Individual steps of SsaBuilder should assume that if a phi has been |
| 2757 | // marked dead, it can be ignored and will be removed by SsaPhiElimination. |
| 2758 | SetPackedFlag<kFlagIsLive>(true); |
| 2759 | SetPackedFlag<kFlagCanBeNull>(true); |
| 2760 | } |
| 2761 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2762 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2763 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2764 | // 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] | 2765 | static DataType::Type ToPhiType(DataType::Type type) { |
| 2766 | return DataType::Kind(type); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 2770 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2771 | void SetType(DataType::Type new_type) { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2772 | // Make sure that only valid type changes occur. The following are allowed: |
| 2773 | // (1) int -> float/ref (primitive type propagation), |
| 2774 | // (2) long -> double (primitive type propagation). |
| 2775 | DCHECK(GetType() == new_type || |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2776 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kFloat32) || |
| 2777 | (GetType() == DataType::Type::kInt32 && new_type == DataType::Type::kReference) || |
| 2778 | (GetType() == DataType::Type::kInt64 && new_type == DataType::Type::kFloat64)); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2779 | SetPackedField<TypeField>(new_type); |
| 2780 | } |
| 2781 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2782 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2783 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
| 2784 | |
| 2785 | uint32_t GetRegNumber() const { return reg_number_; } |
| 2786 | |
| 2787 | void SetDead() { SetPackedFlag<kFlagIsLive>(false); } |
| 2788 | void SetLive() { SetPackedFlag<kFlagIsLive>(true); } |
| 2789 | bool IsDead() const { return !IsLive(); } |
| 2790 | bool IsLive() const { return GetPackedFlag<kFlagIsLive>(); } |
| 2791 | |
Vladimir Marko | e900491 | 2016-06-16 16:50:52 +0100 | [diff] [blame] | 2792 | bool IsVRegEquivalentOf(const HInstruction* other) const { |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2793 | return other != nullptr |
| 2794 | && other->IsPhi() |
| 2795 | && other->AsPhi()->GetBlock() == GetBlock() |
| 2796 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 2797 | } |
| 2798 | |
Nicolas Geoffray | f57c1ae | 2017-06-28 17:40:18 +0100 | [diff] [blame] | 2799 | bool HasEquivalentPhi() const { |
| 2800 | if (GetPrevious() != nullptr && GetPrevious()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2801 | return true; |
| 2802 | } |
| 2803 | if (GetNext() != nullptr && GetNext()->AsPhi()->GetRegNumber() == GetRegNumber()) { |
| 2804 | return true; |
| 2805 | } |
| 2806 | return false; |
| 2807 | } |
| 2808 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2809 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 2810 | // An equivalent phi is a phi having the same dex register and type. |
| 2811 | // It assumes that phis with the same dex register are adjacent. |
| 2812 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 2813 | HInstruction* next = GetNext(); |
| 2814 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 2815 | if (next->GetType() == GetType()) { |
| 2816 | return next->AsPhi(); |
| 2817 | } |
| 2818 | next = next->GetNext(); |
| 2819 | } |
| 2820 | return nullptr; |
| 2821 | } |
| 2822 | |
| 2823 | DECLARE_INSTRUCTION(Phi); |
| 2824 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2825 | protected: |
| 2826 | DEFAULT_COPY_CONSTRUCTOR(Phi); |
| 2827 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2828 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2829 | static constexpr size_t kFlagIsLive = HInstruction::kNumberOfGenericPackedBits; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2830 | static constexpr size_t kFlagCanBeNull = kFlagIsLive + 1; |
| 2831 | static constexpr size_t kNumberOfPhiPackedBits = kFlagCanBeNull + 1; |
| 2832 | static_assert(kNumberOfPhiPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2833 | |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2834 | const uint32_t reg_number_; |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 2835 | }; |
| 2836 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2837 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2838 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2839 | // exit block. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2840 | class HExit 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 HExit(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2843 | : HExpression(kExit, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2844 | } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2845 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2846 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2847 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2848 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2849 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2850 | protected: |
| 2851 | DEFAULT_COPY_CONSTRUCTOR(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2852 | }; |
| 2853 | |
| 2854 | // Jumps from one block to another. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2855 | class HGoto final : public HExpression<0> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2856 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2857 | explicit HGoto(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 2858 | : HExpression(kGoto, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2859 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2860 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2861 | bool IsClonable() const override { return true; } |
| 2862 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2863 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2864 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2865 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2866 | } |
| 2867 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2868 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2869 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2870 | protected: |
| 2871 | DEFAULT_COPY_CONSTRUCTOR(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2872 | }; |
| 2873 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2874 | class HConstant : public HExpression<0> { |
| 2875 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2876 | explicit HConstant(InstructionKind kind, DataType::Type type, uint32_t dex_pc = kNoDexPc) |
| 2877 | : HExpression(kind, type, SideEffects::None(), dex_pc) { |
| 2878 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2879 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2880 | bool CanBeMoved() const override { return true; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2881 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2882 | // Is this constant -1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2883 | virtual bool IsMinusOne() const { return false; } |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2884 | // Is this constant 0 in the arithmetic sense? |
| 2885 | virtual bool IsArithmeticZero() const { return false; } |
| 2886 | // Is this constant a 0-bit pattern? |
| 2887 | virtual bool IsZeroBitPattern() const { return false; } |
| 2888 | // Is this constant 1 in the arithmetic sense? |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2889 | virtual bool IsOne() const { return false; } |
| 2890 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2891 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2892 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 2893 | DECLARE_ABSTRACT_INSTRUCTION(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2894 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2895 | protected: |
| 2896 | DEFAULT_COPY_CONSTRUCTOR(Constant); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2897 | }; |
| 2898 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2899 | class HNullConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2900 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2901 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2902 | return true; |
| 2903 | } |
| 2904 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2905 | uint64_t GetValueAsUint64() const override { return 0; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2906 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2907 | size_t ComputeHashCode() const override { return 0; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2908 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2909 | // The null constant representation is a 0-bit pattern. |
| 2910 | virtual bool IsZeroBitPattern() const { return true; } |
| 2911 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2912 | DECLARE_INSTRUCTION(NullConstant); |
| 2913 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2914 | protected: |
| 2915 | DEFAULT_COPY_CONSTRUCTOR(NullConstant); |
| 2916 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2917 | private: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 2918 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2919 | : HConstant(kNullConstant, DataType::Type::kReference, dex_pc) { |
| 2920 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2921 | |
| 2922 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2923 | }; |
| 2924 | |
| 2925 | // Constants of the type int. Those can be from Dex instructions, or |
| 2926 | // synthesized (for example with the if-eqz instruction). |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2927 | class HIntConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2928 | public: |
| 2929 | int32_t GetValue() const { return value_; } |
| 2930 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2931 | uint64_t GetValueAsUint64() const override { |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2932 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2933 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2934 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2935 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2936 | DCHECK(other->IsIntConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2937 | return other->AsIntConstant()->value_ == value_; |
| 2938 | } |
| 2939 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2940 | size_t ComputeHashCode() const override { return GetValue(); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2941 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2942 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 2943 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 2944 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 2945 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2946 | |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 2947 | // Integer constants are used to encode Boolean values as well, |
| 2948 | // where 1 means true and 0 means false. |
| 2949 | bool IsTrue() const { return GetValue() == 1; } |
| 2950 | bool IsFalse() const { return GetValue() == 0; } |
| 2951 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2952 | DECLARE_INSTRUCTION(IntConstant); |
| 2953 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2954 | protected: |
| 2955 | DEFAULT_COPY_CONSTRUCTOR(IntConstant); |
| 2956 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2957 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2958 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2959 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), value_(value) { |
| 2960 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2961 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2962 | : HConstant(kIntConstant, DataType::Type::kInt32, dex_pc), |
| 2963 | value_(value ? 1 : 0) { |
| 2964 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2965 | |
| 2966 | const int32_t value_; |
| 2967 | |
| 2968 | friend class HGraph; |
| 2969 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2970 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2971 | }; |
| 2972 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2973 | class HLongConstant final : public HConstant { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2974 | public: |
| 2975 | int64_t GetValue() const { return value_; } |
| 2976 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2977 | uint64_t GetValueAsUint64() const override { return value_; } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2978 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2979 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 2980 | DCHECK(other->IsLongConstant()) << other->DebugName(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2981 | return other->AsLongConstant()->value_ == value_; |
| 2982 | } |
| 2983 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2984 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2985 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 2986 | bool IsMinusOne() const override { return GetValue() == -1; } |
| 2987 | bool IsArithmeticZero() const override { return GetValue() == 0; } |
| 2988 | bool IsZeroBitPattern() const override { return GetValue() == 0; } |
| 2989 | bool IsOne() const override { return GetValue() == 1; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2990 | |
| 2991 | DECLARE_INSTRUCTION(LongConstant); |
| 2992 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 2993 | protected: |
| 2994 | DEFAULT_COPY_CONSTRUCTOR(LongConstant); |
| 2995 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2996 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2997 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 2998 | : HConstant(kLongConstant, DataType::Type::kInt64, dex_pc), |
| 2999 | value_(value) { |
| 3000 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3001 | |
| 3002 | const int64_t value_; |
| 3003 | |
| 3004 | friend class HGraph; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3005 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3006 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3007 | class HFloatConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3008 | public: |
| 3009 | float GetValue() const { return value_; } |
| 3010 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3011 | uint64_t GetValueAsUint64() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3012 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3013 | } |
| 3014 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3015 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3016 | DCHECK(other->IsFloatConstant()) << other->DebugName(); |
| 3017 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3018 | } |
| 3019 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3020 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3021 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3022 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3023 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
| 3024 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3025 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3026 | return std::fpclassify(value_) == FP_ZERO; |
| 3027 | } |
| 3028 | bool IsArithmeticPositiveZero() const { |
| 3029 | return IsArithmeticZero() && !std::signbit(value_); |
| 3030 | } |
| 3031 | bool IsArithmeticNegativeZero() const { |
| 3032 | return IsArithmeticZero() && std::signbit(value_); |
| 3033 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3034 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3035 | 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] | 3036 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3037 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3038 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3039 | } |
| 3040 | bool IsNaN() const { |
| 3041 | return std::isnan(value_); |
| 3042 | } |
| 3043 | |
| 3044 | DECLARE_INSTRUCTION(FloatConstant); |
| 3045 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3046 | protected: |
| 3047 | DEFAULT_COPY_CONSTRUCTOR(FloatConstant); |
| 3048 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3049 | private: |
| 3050 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3051 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3052 | value_(value) { |
| 3053 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3054 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3055 | : HConstant(kFloatConstant, DataType::Type::kFloat32, dex_pc), |
| 3056 | value_(bit_cast<float, int32_t>(value)) { |
| 3057 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3058 | |
| 3059 | const float value_; |
| 3060 | |
| 3061 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3062 | friend class SsaBuilder; |
| 3063 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3064 | }; |
| 3065 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3066 | class HDoubleConstant final : public HConstant { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3067 | public: |
| 3068 | double GetValue() const { return value_; } |
| 3069 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3070 | uint64_t GetValueAsUint64() const override { return bit_cast<uint64_t, double>(value_); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3071 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3072 | bool InstructionDataEquals(const HInstruction* other) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3073 | DCHECK(other->IsDoubleConstant()) << other->DebugName(); |
| 3074 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
| 3075 | } |
| 3076 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3077 | size_t ComputeHashCode() const override { return static_cast<size_t>(GetValue()); } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3078 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3079 | bool IsMinusOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3080 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
| 3081 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3082 | bool IsArithmeticZero() const override { |
Roland Levillain | 1a65388 | 2016-03-18 18:05:57 +0000 | [diff] [blame] | 3083 | return std::fpclassify(value_) == FP_ZERO; |
| 3084 | } |
| 3085 | bool IsArithmeticPositiveZero() const { |
| 3086 | return IsArithmeticZero() && !std::signbit(value_); |
| 3087 | } |
| 3088 | bool IsArithmeticNegativeZero() const { |
| 3089 | return IsArithmeticZero() && std::signbit(value_); |
| 3090 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3091 | bool IsZeroBitPattern() const override { |
Nicolas Geoffray | 949e54d | 2016-03-15 16:23:04 +0000 | [diff] [blame] | 3092 | 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] | 3093 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3094 | bool IsOne() const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3095 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3096 | } |
| 3097 | bool IsNaN() const { |
| 3098 | return std::isnan(value_); |
| 3099 | } |
| 3100 | |
| 3101 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3102 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3103 | protected: |
| 3104 | DEFAULT_COPY_CONSTRUCTOR(DoubleConstant); |
| 3105 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3106 | private: |
| 3107 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3108 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3109 | value_(value) { |
| 3110 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3111 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3112 | : HConstant(kDoubleConstant, DataType::Type::kFloat64, dex_pc), |
| 3113 | value_(bit_cast<double, int64_t>(value)) { |
| 3114 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3115 | |
| 3116 | const double value_; |
| 3117 | |
| 3118 | // Only the SsaBuilder and HGraph can create floating-point constants. |
| 3119 | friend class SsaBuilder; |
| 3120 | friend class HGraph; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3121 | }; |
| 3122 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3123 | // Conditional branch. A block ending with an HIf instruction must have |
| 3124 | // two successors. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3125 | class HIf final : public HExpression<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3126 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3127 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3128 | : HExpression(kIf, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3129 | SetRawInputAt(0, input); |
| 3130 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3131 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3132 | bool IsClonable() const override { return true; } |
| 3133 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3134 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3135 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3136 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3140 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3143 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3144 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3145 | protected: |
| 3146 | DEFAULT_COPY_CONSTRUCTOR(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 3147 | }; |
| 3148 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3149 | |
| 3150 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 3151 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 3152 | // non-exceptional control flow. |
| 3153 | // Normal-flow successor is stored at index zero, exception handlers under |
| 3154 | // higher indices in no particular order. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3155 | class HTryBoundary final : public HExpression<0> { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3156 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3157 | enum class BoundaryKind { |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3158 | kEntry, |
| 3159 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3160 | kLast = kExit |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 3161 | }; |
| 3162 | |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3163 | // SideEffects::CanTriggerGC prevents instructions with SideEffects::DependOnGC to be alive |
| 3164 | // across the catch block entering edges as GC might happen during throwing an exception. |
| 3165 | // TryBoundary with BoundaryKind::kExit is conservatively used for that as there is no |
| 3166 | // HInstruction which a catch block must start from. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3167 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 3168 | : HExpression(kTryBoundary, |
| 3169 | (kind == BoundaryKind::kExit) ? SideEffects::CanTriggerGC() |
| 3170 | : SideEffects::None(), |
| 3171 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3172 | SetPackedField<BoundaryKindField>(kind); |
| 3173 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3174 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3175 | bool IsControlFlow() const override { return true; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3176 | |
| 3177 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3178 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3179 | |
David Brazdil | d26a411 | 2015-11-10 11:07:31 +0000 | [diff] [blame] | 3180 | ArrayRef<HBasicBlock* const> GetExceptionHandlers() const { |
| 3181 | return ArrayRef<HBasicBlock* const>(GetBlock()->GetSuccessors()).SubArray(1u); |
| 3182 | } |
| 3183 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3184 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 3185 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3186 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 3187 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 3188 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | // If not present already, adds `handler` to its block's list of exception |
| 3192 | // handlers. |
| 3193 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3194 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3195 | GetBlock()->AddSuccessor(handler); |
| 3196 | } |
| 3197 | } |
| 3198 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3199 | BoundaryKind GetBoundaryKind() const { return GetPackedField<BoundaryKindField>(); } |
| 3200 | bool IsEntry() const { return GetBoundaryKind() == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3201 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 3202 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 3203 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3204 | DECLARE_INSTRUCTION(TryBoundary); |
| 3205 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3206 | protected: |
| 3207 | DEFAULT_COPY_CONSTRUCTOR(TryBoundary); |
| 3208 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3209 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3210 | static constexpr size_t kFieldBoundaryKind = kNumberOfGenericPackedBits; |
| 3211 | static constexpr size_t kFieldBoundaryKindSize = |
| 3212 | MinimumBitsToStore(static_cast<size_t>(BoundaryKind::kLast)); |
| 3213 | static constexpr size_t kNumberOfTryBoundaryPackedBits = |
| 3214 | kFieldBoundaryKind + kFieldBoundaryKindSize; |
| 3215 | static_assert(kNumberOfTryBoundaryPackedBits <= kMaxNumberOfPackedBits, |
| 3216 | "Too many packed fields."); |
| 3217 | using BoundaryKindField = BitField<BoundaryKind, kFieldBoundaryKind, kFieldBoundaryKindSize>; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 3218 | }; |
| 3219 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3220 | // Deoptimize to interpreter, upon checking a condition. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3221 | class HDeoptimize final : public HVariableInputSizeInstruction { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3222 | public: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3223 | // Use this constructor when the `HDeoptimize` acts as a barrier, where no code can move |
| 3224 | // across. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3225 | HDeoptimize(ArenaAllocator* allocator, |
| 3226 | HInstruction* cond, |
| 3227 | DeoptimizationKind kind, |
| 3228 | uint32_t dex_pc) |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3229 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3230 | kDeoptimize, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3231 | SideEffects::All(), |
| 3232 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3233 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3234 | /* number_of_inputs */ 1, |
| 3235 | kArenaAllocMisc) { |
| 3236 | SetPackedFlag<kFieldCanBeMoved>(false); |
| 3237 | SetPackedField<DeoptimizeKindField>(kind); |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3238 | SetRawInputAt(0, cond); |
| 3239 | } |
| 3240 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3241 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3242 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3243 | // Use this constructor when the `HDeoptimize` guards an instruction, and any user |
| 3244 | // that relies on the deoptimization to pass should have its input be the `HDeoptimize` |
| 3245 | // instead of `guard`. |
| 3246 | // We set CanTriggerGC to prevent any intermediate address to be live |
| 3247 | // at the point of the `HDeoptimize`. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3248 | HDeoptimize(ArenaAllocator* allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3249 | HInstruction* cond, |
| 3250 | HInstruction* guard, |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3251 | DeoptimizationKind kind, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3252 | uint32_t dex_pc) |
| 3253 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3254 | kDeoptimize, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3255 | guard->GetType(), |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3256 | SideEffects::CanTriggerGC(), |
| 3257 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3258 | allocator, |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3259 | /* number_of_inputs */ 2, |
| 3260 | kArenaAllocMisc) { |
| 3261 | SetPackedFlag<kFieldCanBeMoved>(true); |
| 3262 | SetPackedField<DeoptimizeKindField>(kind); |
| 3263 | SetRawInputAt(0, cond); |
| 3264 | SetRawInputAt(1, guard); |
Nicolas Geoffray | 73be1e8 | 2015-09-17 15:22:56 +0100 | [diff] [blame] | 3265 | } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3266 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3267 | bool CanBeMoved() const override { return GetPackedFlag<kFieldCanBeMoved>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3268 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3269 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3270 | return (other->CanBeMoved() == CanBeMoved()) && (other->AsDeoptimize()->GetKind() == GetKind()); |
| 3271 | } |
| 3272 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3273 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3274 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3275 | bool CanThrow() const override { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3276 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3277 | DeoptimizationKind GetDeoptimizationKind() const { return GetPackedField<DeoptimizeKindField>(); } |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3278 | |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3279 | bool GuardsAnInput() const { |
| 3280 | return InputCount() == 2; |
| 3281 | } |
| 3282 | |
| 3283 | HInstruction* GuardedInput() const { |
| 3284 | DCHECK(GuardsAnInput()); |
| 3285 | return InputAt(1); |
| 3286 | } |
| 3287 | |
| 3288 | void RemoveGuard() { |
| 3289 | RemoveInputAt(1); |
| 3290 | } |
| 3291 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3292 | DECLARE_INSTRUCTION(Deoptimize); |
| 3293 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3294 | protected: |
| 3295 | DEFAULT_COPY_CONSTRUCTOR(Deoptimize); |
| 3296 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3297 | private: |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3298 | static constexpr size_t kFieldCanBeMoved = kNumberOfGenericPackedBits; |
| 3299 | static constexpr size_t kFieldDeoptimizeKind = kNumberOfGenericPackedBits + 1; |
| 3300 | static constexpr size_t kFieldDeoptimizeKindSize = |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3301 | MinimumBitsToStore(static_cast<size_t>(DeoptimizationKind::kLast)); |
Nicolas Geoffray | 6f8e2c9 | 2017-03-23 14:37:26 +0000 | [diff] [blame] | 3302 | static constexpr size_t kNumberOfDeoptimizePackedBits = |
| 3303 | kFieldDeoptimizeKind + kFieldDeoptimizeKindSize; |
| 3304 | static_assert(kNumberOfDeoptimizePackedBits <= kMaxNumberOfPackedBits, |
| 3305 | "Too many packed fields."); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 3306 | using DeoptimizeKindField = |
| 3307 | BitField<DeoptimizationKind, kFieldDeoptimizeKind, kFieldDeoptimizeKindSize>; |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3308 | }; |
| 3309 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3310 | // Represents a should_deoptimize flag. Currently used for CHA-based devirtualization. |
| 3311 | // The compiled code checks this flag value in a guard before devirtualized call and |
| 3312 | // if it's true, starts to do deoptimization. |
| 3313 | // It has a 4-byte slot on stack. |
| 3314 | // TODO: allocate a register for this flag. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3315 | class HShouldDeoptimizeFlag final : public HVariableInputSizeInstruction { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3316 | public: |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3317 | // CHA guards are only optimized in a separate pass and it has no side effects |
| 3318 | // with regard to other passes. |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 3319 | HShouldDeoptimizeFlag(ArenaAllocator* allocator, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3320 | : HVariableInputSizeInstruction(kShouldDeoptimizeFlag, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3321 | DataType::Type::kInt32, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3322 | SideEffects::None(), |
| 3323 | dex_pc, |
| 3324 | allocator, |
| 3325 | 0, |
| 3326 | kArenaAllocCHA) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3327 | } |
| 3328 | |
Mingyao Yang | b0b051a | 2016-11-17 09:04:53 -0800 | [diff] [blame] | 3329 | // We do all CHA guard elimination/motion in a single pass, after which there is no |
| 3330 | // further guard elimination/motion since a guard might have been used for justification |
| 3331 | // of the elimination of another guard. Therefore, we pretend this guard cannot be moved |
| 3332 | // to avoid other optimizations trying to move it. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3333 | bool CanBeMoved() const override { return false; } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3334 | |
| 3335 | DECLARE_INSTRUCTION(ShouldDeoptimizeFlag); |
| 3336 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3337 | protected: |
| 3338 | DEFAULT_COPY_CONSTRUCTOR(ShouldDeoptimizeFlag); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 3339 | }; |
| 3340 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3341 | // Represents the ArtMethod that was passed as a first argument to |
| 3342 | // the method. It is used by instructions that depend on it, like |
| 3343 | // instructions that work with the dex cache. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3344 | class HCurrentMethod final : public HExpression<0> { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3345 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3346 | explicit HCurrentMethod(DataType::Type type, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3347 | : HExpression(kCurrentMethod, type, SideEffects::None(), dex_pc) { |
| 3348 | } |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3349 | |
| 3350 | DECLARE_INSTRUCTION(CurrentMethod); |
| 3351 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3352 | protected: |
| 3353 | DEFAULT_COPY_CONSTRUCTOR(CurrentMethod); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 3354 | }; |
| 3355 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3356 | // Fetches an ArtMethod from the virtual table or the interface method table |
| 3357 | // of a class. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3358 | class HClassTableGet final : public HExpression<1> { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3359 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3360 | enum class TableKind { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3361 | kVTable, |
| 3362 | kIMTable, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3363 | kLast = kIMTable |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3364 | }; |
| 3365 | HClassTableGet(HInstruction* cls, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3366 | DataType::Type type, |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3367 | TableKind kind, |
| 3368 | size_t index, |
| 3369 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3370 | : HExpression(kClassTableGet, type, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3371 | index_(index) { |
| 3372 | SetPackedField<TableKindField>(kind); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3373 | SetRawInputAt(0, cls); |
| 3374 | } |
| 3375 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3376 | bool IsClonable() const override { return true; } |
| 3377 | bool CanBeMoved() const override { return true; } |
| 3378 | bool InstructionDataEquals(const HInstruction* other) const override { |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3379 | return other->AsClassTableGet()->GetIndex() == index_ && |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3380 | other->AsClassTableGet()->GetPackedFields() == GetPackedFields(); |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3383 | TableKind GetTableKind() const { return GetPackedField<TableKindField>(); } |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3384 | size_t GetIndex() const { return index_; } |
| 3385 | |
| 3386 | DECLARE_INSTRUCTION(ClassTableGet); |
| 3387 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3388 | protected: |
| 3389 | DEFAULT_COPY_CONSTRUCTOR(ClassTableGet); |
| 3390 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3391 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3392 | static constexpr size_t kFieldTableKind = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3393 | static constexpr size_t kFieldTableKindSize = |
| 3394 | MinimumBitsToStore(static_cast<size_t>(TableKind::kLast)); |
| 3395 | static constexpr size_t kNumberOfClassTableGetPackedBits = kFieldTableKind + kFieldTableKindSize; |
| 3396 | static_assert(kNumberOfClassTableGetPackedBits <= kMaxNumberOfPackedBits, |
| 3397 | "Too many packed fields."); |
| 3398 | using TableKindField = BitField<TableKind, kFieldTableKind, kFieldTableKind>; |
| 3399 | |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3400 | // The index of the ArtMethod in the table. |
| 3401 | const size_t index_; |
Nicolas Geoffray | a42363f | 2015-12-17 14:57:09 +0000 | [diff] [blame] | 3402 | }; |
| 3403 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3404 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 3405 | // have one successor for each entry in the switch table, and the final successor |
| 3406 | // will be the block containing the next Dex opcode. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3407 | class HPackedSwitch final : public HExpression<1> { |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3408 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3409 | HPackedSwitch(int32_t start_value, |
| 3410 | uint32_t num_entries, |
| 3411 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3412 | uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3413 | : HExpression(kPackedSwitch, SideEffects::None(), dex_pc), |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3414 | start_value_(start_value), |
| 3415 | num_entries_(num_entries) { |
| 3416 | SetRawInputAt(0, input); |
| 3417 | } |
| 3418 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3419 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3420 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3421 | bool IsControlFlow() const override { return true; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3422 | |
| 3423 | int32_t GetStartValue() const { return start_value_; } |
| 3424 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 3425 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3426 | |
| 3427 | HBasicBlock* GetDefaultBlock() const { |
| 3428 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 3429 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3430 | } |
| 3431 | DECLARE_INSTRUCTION(PackedSwitch); |
| 3432 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3433 | protected: |
| 3434 | DEFAULT_COPY_CONSTRUCTOR(PackedSwitch); |
| 3435 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3436 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 3437 | const int32_t start_value_; |
| 3438 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 3439 | }; |
| 3440 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3441 | class HUnaryOperation : public HExpression<1> { |
| 3442 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3443 | HUnaryOperation(InstructionKind kind, |
| 3444 | DataType::Type result_type, |
| 3445 | HInstruction* input, |
| 3446 | uint32_t dex_pc = kNoDexPc) |
| 3447 | : HExpression(kind, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3448 | SetRawInputAt(0, input); |
| 3449 | } |
| 3450 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3451 | // All of the UnaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3452 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3453 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3454 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3455 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3456 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3457 | bool CanBeMoved() const override { return true; } |
| 3458 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3459 | return true; |
| 3460 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3461 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3462 | // Try to statically evaluate `this` and return a HConstant |
| 3463 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3464 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3465 | HConstant* TryStaticEvaluation() const; |
| 3466 | |
| 3467 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3468 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 3469 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3470 | virtual HConstant* Evaluate(HFloatConstant* x) const = 0; |
| 3471 | virtual HConstant* Evaluate(HDoubleConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3472 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3473 | DECLARE_ABSTRACT_INSTRUCTION(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3474 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3475 | protected: |
| 3476 | DEFAULT_COPY_CONSTRUCTOR(UnaryOperation); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3477 | }; |
| 3478 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3479 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3480 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3481 | HBinaryOperation(InstructionKind kind, |
| 3482 | DataType::Type result_type, |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3483 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3484 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3485 | SideEffects side_effects = SideEffects::None(), |
| 3486 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3487 | : HExpression(kind, result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3488 | SetRawInputAt(0, left); |
| 3489 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3492 | // All of the BinaryOperation instructions are clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3493 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3494 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3495 | HInstruction* GetLeft() const { return InputAt(0); } |
| 3496 | HInstruction* GetRight() const { return InputAt(1); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3497 | DataType::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3498 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3499 | virtual bool IsCommutative() const { return false; } |
| 3500 | |
| 3501 | // Put constant on the right. |
| 3502 | // Returns whether order is changed. |
| 3503 | bool OrderInputsWithConstantOnTheRight() { |
| 3504 | HInstruction* left = InputAt(0); |
| 3505 | HInstruction* right = InputAt(1); |
| 3506 | if (left->IsConstant() && !right->IsConstant()) { |
| 3507 | ReplaceInput(right, 0); |
| 3508 | ReplaceInput(left, 1); |
| 3509 | return true; |
| 3510 | } |
| 3511 | return false; |
| 3512 | } |
| 3513 | |
| 3514 | // Order inputs by instruction id, but favor constant on the right side. |
| 3515 | // This helps GVN for commutative ops. |
| 3516 | void OrderInputs() { |
| 3517 | DCHECK(IsCommutative()); |
| 3518 | HInstruction* left = InputAt(0); |
| 3519 | HInstruction* right = InputAt(1); |
| 3520 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 3521 | return; |
| 3522 | } |
| 3523 | if (OrderInputsWithConstantOnTheRight()) { |
| 3524 | return; |
| 3525 | } |
| 3526 | // Order according to instruction id. |
| 3527 | if (left->GetId() > right->GetId()) { |
| 3528 | ReplaceInput(right, 0); |
| 3529 | ReplaceInput(left, 1); |
| 3530 | } |
| 3531 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3532 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3533 | bool CanBeMoved() const override { return true; } |
| 3534 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3535 | return true; |
| 3536 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3537 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3538 | // Try to statically evaluate `this` and return a HConstant |
| 3539 | // containing the result of this evaluation. If `this` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3540 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3541 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3542 | |
| 3543 | // Apply this operation to `x` and `y`. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3544 | virtual HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
| 3545 | HNullConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3546 | LOG(FATAL) << DebugName() << " is not defined for the (null, null) case."; |
| 3547 | UNREACHABLE(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3548 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3549 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 3550 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3551 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 3552 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
Roland Levillain | e53bd81 | 2016-02-24 14:54:18 +0000 | [diff] [blame] | 3553 | LOG(FATAL) << DebugName() << " is not defined for the (long, int) case."; |
| 3554 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3555 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3556 | virtual HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const = 0; |
| 3557 | virtual HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const = 0; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3558 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3559 | // 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] | 3560 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3561 | HConstant* GetConstantRight() const; |
| 3562 | |
| 3563 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 3564 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3565 | HInstruction* GetLeastConstantLeft() const; |
| 3566 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3567 | DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 3568 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3569 | protected: |
| 3570 | DEFAULT_COPY_CONSTRUCTOR(BinaryOperation); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3571 | }; |
| 3572 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3573 | // The comparison bias applies for floating point operations and indicates how NaN |
| 3574 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3575 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3576 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 3577 | kGtBias, // return 1 for NaN comparisons |
| 3578 | kLtBias, // return -1 for NaN comparisons |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3579 | kLast = kLtBias |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3580 | }; |
| 3581 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3582 | std::ostream& operator<<(std::ostream& os, const ComparisonBias& rhs); |
| 3583 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3584 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3585 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3586 | HCondition(InstructionKind kind, |
| 3587 | HInstruction* first, |
| 3588 | HInstruction* second, |
| 3589 | uint32_t dex_pc = kNoDexPc) |
| 3590 | : HBinaryOperation(kind, |
| 3591 | DataType::Type::kBool, |
| 3592 | first, |
| 3593 | second, |
| 3594 | SideEffects::None(), |
| 3595 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3596 | SetPackedField<ComparisonBiasField>(ComparisonBias::kNoBias); |
| 3597 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3598 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3599 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 3600 | // `instruction`, and disregard moves in between. |
| 3601 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 3602 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 3603 | DECLARE_ABSTRACT_INSTRUCTION(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3604 | |
| 3605 | virtual IfCondition GetCondition() const = 0; |
| 3606 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3607 | virtual IfCondition GetOppositeCondition() const = 0; |
| 3608 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3609 | bool IsGtBias() const { return GetBias() == ComparisonBias::kGtBias; } |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3610 | bool IsLtBias() const { return GetBias() == ComparisonBias::kLtBias; } |
| 3611 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3612 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
| 3613 | void SetBias(ComparisonBias bias) { SetPackedField<ComparisonBiasField>(bias); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3614 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3615 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3616 | return GetPackedFields() == other->AsCondition()->GetPackedFields(); |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3617 | } |
| 3618 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3619 | bool IsFPConditionTrueIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3620 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3621 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3622 | if (if_cond == kCondNE) { |
| 3623 | return true; |
| 3624 | } else if (if_cond == kCondEQ) { |
| 3625 | return false; |
| 3626 | } |
| 3627 | return ((if_cond == kCondGT) || (if_cond == kCondGE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | bool IsFPConditionFalseIfNaN() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3631 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3632 | IfCondition if_cond = GetCondition(); |
Anton Shamin | bdd7935 | 2016-02-15 12:48:36 +0600 | [diff] [blame] | 3633 | if (if_cond == kCondEQ) { |
| 3634 | return true; |
| 3635 | } else if (if_cond == kCondNE) { |
| 3636 | return false; |
| 3637 | } |
| 3638 | return ((if_cond == kCondLT) || (if_cond == kCondLE)) && IsGtBias(); |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3639 | } |
| 3640 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3641 | protected: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3642 | // Needed if we merge a HCompare into a HCondition. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 3643 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 3644 | static constexpr size_t kFieldComparisonBiasSize = |
| 3645 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 3646 | static constexpr size_t kNumberOfConditionPackedBits = |
| 3647 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 3648 | static_assert(kNumberOfConditionPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 3649 | using ComparisonBiasField = |
| 3650 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 3651 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3652 | template <typename T> |
| 3653 | int32_t Compare(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 3654 | |
| 3655 | template <typename T> |
| 3656 | int32_t CompareFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 3657 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3658 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 3659 | // Handle the bias. |
| 3660 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compare(x, y); |
| 3661 | } |
| 3662 | |
| 3663 | // Return an integer constant containing the result of a condition evaluated at compile time. |
| 3664 | HIntConstant* MakeConstantCondition(bool value, uint32_t dex_pc) const { |
| 3665 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 3666 | } |
| 3667 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3668 | DEFAULT_COPY_CONSTRUCTOR(Condition); |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3669 | }; |
| 3670 | |
| 3671 | // Instruction to check if two inputs are equal to each other. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3672 | class HEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3673 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3674 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3675 | : HCondition(kEqual, first, second, dex_pc) { |
| 3676 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3677 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3678 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3679 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3680 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3681 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3682 | return MakeConstantCondition(true, GetDexPc()); |
| 3683 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3684 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3685 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3686 | } |
| 3687 | // In the following Evaluate methods, a HCompare instruction has |
| 3688 | // been merged into this HEqual instruction; evaluate it as |
| 3689 | // `Compare(x, y) == 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3690 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3691 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), |
| 3692 | GetDexPc()); |
| 3693 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3694 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3695 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3696 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3697 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3698 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3699 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3700 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3701 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3702 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3703 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3704 | return kCondEQ; |
| 3705 | } |
| 3706 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3707 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3708 | return kCondNE; |
| 3709 | } |
| 3710 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3711 | protected: |
| 3712 | DEFAULT_COPY_CONSTRUCTOR(Equal); |
| 3713 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3714 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3715 | 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] | 3716 | }; |
| 3717 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3718 | class HNotEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3719 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3720 | HNotEqual(HInstruction* first, HInstruction* second, |
| 3721 | uint32_t dex_pc = kNoDexPc) |
| 3722 | : HCondition(kNotEqual, first, second, dex_pc) { |
| 3723 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3724 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3725 | bool IsCommutative() const override { return true; } |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3726 | |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3727 | HConstant* Evaluate(HNullConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3728 | HNullConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3729 | return MakeConstantCondition(false, GetDexPc()); |
| 3730 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3731 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3732 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3733 | } |
| 3734 | // In the following Evaluate methods, a HCompare instruction has |
| 3735 | // been merged into this HNotEqual instruction; evaluate it as |
| 3736 | // `Compare(x, y) != 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3737 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3738 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3739 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3740 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3741 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3742 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3743 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3744 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 3745 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3746 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3747 | DECLARE_INSTRUCTION(NotEqual); |
| 3748 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3749 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3750 | return kCondNE; |
| 3751 | } |
| 3752 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3753 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3754 | return kCondEQ; |
| 3755 | } |
| 3756 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3757 | protected: |
| 3758 | DEFAULT_COPY_CONSTRUCTOR(NotEqual); |
| 3759 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3760 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3761 | 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] | 3762 | }; |
| 3763 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3764 | class HLessThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3765 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3766 | HLessThan(HInstruction* first, HInstruction* second, |
| 3767 | uint32_t dex_pc = kNoDexPc) |
| 3768 | : HCondition(kLessThan, first, second, dex_pc) { |
| 3769 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3770 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3771 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3772 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3773 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3774 | // In the following Evaluate methods, a HCompare instruction has |
| 3775 | // been merged into this HLessThan instruction; evaluate it as |
| 3776 | // `Compare(x, y) < 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3777 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3778 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3779 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3780 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3781 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3782 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3783 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3784 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3785 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3786 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3787 | DECLARE_INSTRUCTION(LessThan); |
| 3788 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3789 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3790 | return kCondLT; |
| 3791 | } |
| 3792 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3793 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3794 | return kCondGE; |
| 3795 | } |
| 3796 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3797 | protected: |
| 3798 | DEFAULT_COPY_CONSTRUCTOR(LessThan); |
| 3799 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3800 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3801 | 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] | 3802 | }; |
| 3803 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3804 | class HLessThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3805 | public: |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3806 | HLessThanOrEqual(HInstruction* first, HInstruction* second, |
| 3807 | uint32_t dex_pc = kNoDexPc) |
| 3808 | : HCondition(kLessThanOrEqual, first, second, dex_pc) { |
| 3809 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3810 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3811 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3812 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3813 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3814 | // In the following Evaluate methods, a HCompare instruction has |
| 3815 | // been merged into this HLessThanOrEqual instruction; evaluate it as |
| 3816 | // `Compare(x, y) <= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3817 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3818 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3819 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3820 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3821 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3822 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3823 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3824 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3825 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3826 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3827 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 3828 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3829 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3830 | return kCondLE; |
| 3831 | } |
| 3832 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3833 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3834 | return kCondGT; |
| 3835 | } |
| 3836 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3837 | protected: |
| 3838 | DEFAULT_COPY_CONSTRUCTOR(LessThanOrEqual); |
| 3839 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3840 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3841 | 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] | 3842 | }; |
| 3843 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3844 | class HGreaterThan final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3845 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3846 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3847 | : HCondition(kGreaterThan, first, second, dex_pc) { |
| 3848 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3849 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3850 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3851 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3852 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3853 | // In the following Evaluate methods, a HCompare instruction has |
| 3854 | // been merged into this HGreaterThan instruction; evaluate it as |
| 3855 | // `Compare(x, y) > 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3856 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3857 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3858 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3859 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3860 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3861 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3862 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3863 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3864 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3865 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3866 | DECLARE_INSTRUCTION(GreaterThan); |
| 3867 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3868 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3869 | return kCondGT; |
| 3870 | } |
| 3871 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3872 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3873 | return kCondLE; |
| 3874 | } |
| 3875 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3876 | protected: |
| 3877 | DEFAULT_COPY_CONSTRUCTOR(GreaterThan); |
| 3878 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3879 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3880 | 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] | 3881 | }; |
| 3882 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3883 | class HGreaterThanOrEqual final : public HCondition { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3884 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3885 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3886 | : HCondition(kGreaterThanOrEqual, first, second, dex_pc) { |
| 3887 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3888 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3889 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3890 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3891 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3892 | // In the following Evaluate methods, a HCompare instruction has |
| 3893 | // been merged into this HGreaterThanOrEqual instruction; evaluate it as |
| 3894 | // `Compare(x, y) >= 0`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3895 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3896 | return MakeConstantCondition(Compute(Compare(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3897 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3898 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3899 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
| 3900 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3901 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3902 | return MakeConstantCondition(Compute(CompareFP(x->GetValue(), y->GetValue()), 0), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3903 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3904 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3905 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 3906 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3907 | IfCondition GetCondition() const override { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3908 | return kCondGE; |
| 3909 | } |
| 3910 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3911 | IfCondition GetOppositeCondition() const override { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3912 | return kCondLT; |
| 3913 | } |
| 3914 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3915 | protected: |
| 3916 | DEFAULT_COPY_CONSTRUCTOR(GreaterThanOrEqual); |
| 3917 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3918 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3919 | 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] | 3920 | }; |
| 3921 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3922 | class HBelow final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3923 | public: |
| 3924 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3925 | : HCondition(kBelow, first, second, dex_pc) { |
| 3926 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3927 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3928 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3929 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3930 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3931 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3932 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3933 | } |
| 3934 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3935 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3936 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3937 | UNREACHABLE(); |
| 3938 | } |
| 3939 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3940 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3941 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3942 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | DECLARE_INSTRUCTION(Below); |
| 3946 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3947 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3948 | return kCondB; |
| 3949 | } |
| 3950 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3951 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3952 | return kCondAE; |
| 3953 | } |
| 3954 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3955 | protected: |
| 3956 | DEFAULT_COPY_CONSTRUCTOR(Below); |
| 3957 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3958 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 3959 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3960 | return MakeUnsigned(x) < MakeUnsigned(y); |
| 3961 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3962 | }; |
| 3963 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3964 | class HBelowOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3965 | public: |
| 3966 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 3967 | : HCondition(kBelowOrEqual, first, second, dex_pc) { |
| 3968 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3969 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3970 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3971 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3972 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3973 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3974 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 3975 | } |
| 3976 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3977 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3978 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 3979 | UNREACHABLE(); |
| 3980 | } |
| 3981 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3982 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 3983 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 3984 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3985 | } |
| 3986 | |
| 3987 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 3988 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3989 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3990 | return kCondBE; |
| 3991 | } |
| 3992 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 3993 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 3994 | return kCondA; |
| 3995 | } |
| 3996 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 3997 | protected: |
| 3998 | DEFAULT_COPY_CONSTRUCTOR(BelowOrEqual); |
| 3999 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4000 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4001 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4002 | return MakeUnsigned(x) <= MakeUnsigned(y); |
| 4003 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4004 | }; |
| 4005 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4006 | class HAbove final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4007 | public: |
| 4008 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4009 | : HCondition(kAbove, first, second, dex_pc) { |
| 4010 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4011 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4012 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4013 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4014 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4015 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4016 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4017 | } |
| 4018 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4019 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4020 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4021 | UNREACHABLE(); |
| 4022 | } |
| 4023 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4024 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4025 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4026 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4027 | } |
| 4028 | |
| 4029 | DECLARE_INSTRUCTION(Above); |
| 4030 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4031 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4032 | return kCondA; |
| 4033 | } |
| 4034 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4035 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4036 | return kCondBE; |
| 4037 | } |
| 4038 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4039 | protected: |
| 4040 | DEFAULT_COPY_CONSTRUCTOR(Above); |
| 4041 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4042 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4043 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4044 | return MakeUnsigned(x) > MakeUnsigned(y); |
| 4045 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4046 | }; |
| 4047 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4048 | class HAboveOrEqual final : public HCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4049 | public: |
| 4050 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4051 | : HCondition(kAboveOrEqual, first, second, dex_pc) { |
| 4052 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4053 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4054 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4055 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4056 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4057 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4058 | return MakeConstantCondition(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4059 | } |
| 4060 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4061 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4062 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 4063 | UNREACHABLE(); |
| 4064 | } |
| 4065 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4066 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4067 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 4068 | UNREACHABLE(); |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 4072 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4073 | IfCondition GetCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4074 | return kCondAE; |
| 4075 | } |
| 4076 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4077 | IfCondition GetOppositeCondition() const override { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4078 | return kCondB; |
| 4079 | } |
| 4080 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4081 | protected: |
| 4082 | DEFAULT_COPY_CONSTRUCTOR(AboveOrEqual); |
| 4083 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4084 | private: |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4085 | template <typename T> static bool Compute(T x, T y) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4086 | return MakeUnsigned(x) >= MakeUnsigned(y); |
| 4087 | } |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 4088 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4089 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4090 | // Instruction to check how two inputs compare to each other. |
| 4091 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4092 | class HCompare final : public HBinaryOperation { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4093 | public: |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4094 | // Note that `comparison_type` is the type of comparison performed |
| 4095 | // between the comparison's inputs, not the type of the instantiated |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4096 | // HCompare instruction (which is always DataType::Type::kInt). |
| 4097 | HCompare(DataType::Type comparison_type, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4098 | HInstruction* first, |
| 4099 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4100 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4101 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4102 | : HBinaryOperation(kCompare, |
| 4103 | DataType::Type::kInt32, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4104 | first, |
| 4105 | second, |
Roland Levillain | a5c4a40 | 2016-03-15 15:02:50 +0000 | [diff] [blame] | 4106 | SideEffectsForArchRuntimeCalls(comparison_type), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4107 | dex_pc) { |
| 4108 | SetPackedField<ComparisonBiasField>(bias); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4109 | DCHECK_EQ(comparison_type, DataType::Kind(first->GetType())); |
| 4110 | DCHECK_EQ(comparison_type, DataType::Kind(second->GetType())); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4111 | } |
| 4112 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4113 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4114 | int32_t Compute(T x, T y) const { return x > y ? 1 : (x < y ? -1 : 0); } |
| 4115 | |
| 4116 | template <typename T> |
| 4117 | int32_t ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4118 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4119 | DCHECK_NE(GetBias(), ComparisonBias::kNoBias); |
| 4120 | // Handle the bias. |
| 4121 | return std::isunordered(x, y) ? (IsGtBias() ? 1 : -1) : Compute(x, y); |
| 4122 | } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4123 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4124 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4125 | // Note that there is no "cmp-int" Dex instruction so we shouldn't |
| 4126 | // reach this code path when processing a freshly built HIR |
| 4127 | // graph. However HCompare integer instructions can be synthesized |
| 4128 | // by the instruction simplifier to implement IntegerCompare and |
| 4129 | // IntegerSignum intrinsics, so we have to handle this case. |
| 4130 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4131 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4132 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4133 | return MakeConstantComparison(Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4134 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4135 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4136 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4137 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4138 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4139 | return MakeConstantComparison(ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4140 | } |
| 4141 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4142 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4143 | return GetPackedFields() == other->AsCompare()->GetPackedFields(); |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 4144 | } |
| 4145 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4146 | ComparisonBias GetBias() const { return GetPackedField<ComparisonBiasField>(); } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 4147 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4148 | // Does this compare instruction have a "gt bias" (vs an "lt bias")? |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4149 | // Only meaningful for floating-point comparisons. |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4150 | bool IsGtBias() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4151 | DCHECK(DataType::IsFloatingPointType(InputAt(0)->GetType())) << InputAt(0)->GetType(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4152 | return GetBias() == ComparisonBias::kGtBias; |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4153 | } |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4154 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4155 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type type ATTRIBUTE_UNUSED) { |
Roland Levillain | 1693a1f | 2016-03-15 14:57:31 +0000 | [diff] [blame] | 4156 | // Comparisons do not require a runtime call in any back end. |
| 4157 | return SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4158 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4159 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4160 | DECLARE_INSTRUCTION(Compare); |
| 4161 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4162 | protected: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4163 | static constexpr size_t kFieldComparisonBias = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4164 | static constexpr size_t kFieldComparisonBiasSize = |
| 4165 | MinimumBitsToStore(static_cast<size_t>(ComparisonBias::kLast)); |
| 4166 | static constexpr size_t kNumberOfComparePackedBits = |
| 4167 | kFieldComparisonBias + kFieldComparisonBiasSize; |
| 4168 | static_assert(kNumberOfComparePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 4169 | using ComparisonBiasField = |
| 4170 | BitField<ComparisonBias, kFieldComparisonBias, kFieldComparisonBiasSize>; |
| 4171 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4172 | // Return an integer constant containing the result of a comparison evaluated at compile time. |
| 4173 | HIntConstant* MakeConstantComparison(int32_t value, uint32_t dex_pc) const { |
| 4174 | DCHECK(value == -1 || value == 0 || value == 1) << value; |
| 4175 | return GetBlock()->GetGraph()->GetIntConstant(value, dex_pc); |
| 4176 | } |
| 4177 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4178 | DEFAULT_COPY_CONSTRUCTOR(Compare); |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 4179 | }; |
| 4180 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4181 | class HNewInstance final : public HExpression<1> { |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4182 | public: |
| 4183 | HNewInstance(HInstruction* cls, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4184 | uint32_t dex_pc, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4185 | dex::TypeIndex type_index, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4186 | const DexFile& dex_file, |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4187 | bool finalizable, |
| 4188 | QuickEntrypointEnum entrypoint) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4189 | : HExpression(kNewInstance, |
| 4190 | DataType::Type::kReference, |
| 4191 | SideEffects::CanTriggerGC(), |
| 4192 | dex_pc), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4193 | type_index_(type_index), |
| 4194 | dex_file_(dex_file), |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4195 | entrypoint_(entrypoint) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4196 | SetPackedFlag<kFlagFinalizable>(finalizable); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4197 | SetRawInputAt(0, cls); |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4198 | } |
| 4199 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4200 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4201 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4202 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4203 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4204 | |
| 4205 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4206 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4207 | |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4208 | // Can throw errors when out-of-memory or if it's not instantiable/accessible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4209 | bool CanThrow() const override { return true; } |
Mingyao Yang | 062157f | 2016-03-02 10:15:36 -0800 | [diff] [blame] | 4210 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 4211 | bool NeedsChecks() const { |
| 4212 | return entrypoint_ == kQuickAllocObjectWithChecks; |
| 4213 | } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4214 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4215 | bool IsFinalizable() const { return GetPackedFlag<kFlagFinalizable>(); } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4216 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4217 | bool CanBeNull() const override { return false; } |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4218 | |
| 4219 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 4220 | |
| 4221 | void SetEntrypoint(QuickEntrypointEnum entrypoint) { |
| 4222 | entrypoint_ = entrypoint; |
| 4223 | } |
| 4224 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4225 | HLoadClass* GetLoadClass() const { |
| 4226 | HInstruction* input = InputAt(0); |
| 4227 | if (input->IsClinitCheck()) { |
| 4228 | input = input->InputAt(0); |
| 4229 | } |
| 4230 | DCHECK(input->IsLoadClass()); |
| 4231 | return input->AsLoadClass(); |
| 4232 | } |
| 4233 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4234 | bool IsStringAlloc() const; |
| 4235 | |
| 4236 | DECLARE_INSTRUCTION(NewInstance); |
| 4237 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4238 | protected: |
| 4239 | DEFAULT_COPY_CONSTRUCTOR(NewInstance); |
| 4240 | |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4241 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4242 | static constexpr size_t kFlagFinalizable = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4243 | static constexpr size_t kNumberOfNewInstancePackedBits = kFlagFinalizable + 1; |
| 4244 | static_assert(kNumberOfNewInstancePackedBits <= kMaxNumberOfPackedBits, |
| 4245 | "Too many packed fields."); |
| 4246 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 4247 | const dex::TypeIndex type_index_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4248 | const DexFile& dex_file_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4249 | QuickEntrypointEnum entrypoint_; |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4250 | }; |
| 4251 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 4252 | enum IntrinsicNeedsEnvironmentOrCache { |
| 4253 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 4254 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4255 | }; |
| 4256 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4257 | enum IntrinsicSideEffects { |
| 4258 | kNoSideEffects, // Intrinsic does not have any heap memory side effects. |
| 4259 | kReadSideEffects, // Intrinsic may read heap memory. |
| 4260 | kWriteSideEffects, // Intrinsic may write heap memory. |
| 4261 | kAllSideEffects // Intrinsic may read or write heap memory, or trigger GC. |
| 4262 | }; |
| 4263 | |
| 4264 | enum IntrinsicExceptions { |
| 4265 | kNoThrow, // Intrinsic does not throw any exceptions. |
| 4266 | kCanThrow // Intrinsic may throw exceptions. |
| 4267 | }; |
| 4268 | |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4269 | class HInvoke : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4270 | public: |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4271 | bool NeedsEnvironment() const override; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4272 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 4273 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4274 | SetRawInputAt(index, argument); |
| 4275 | } |
| 4276 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4277 | // Return the number of arguments. This number can be lower than |
| 4278 | // the number of inputs returned by InputCount(), as some invoke |
| 4279 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 4280 | // inputs at the end of their list of inputs. |
| 4281 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 4282 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4283 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 4284 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4285 | InvokeType GetInvokeType() const { |
| 4286 | return GetPackedField<InvokeTypeField>(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4287 | } |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4288 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 4289 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4290 | return intrinsic_; |
| 4291 | } |
| 4292 | |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4293 | void SetIntrinsic(Intrinsics intrinsic, |
| 4294 | IntrinsicNeedsEnvironmentOrCache needs_env_or_cache, |
| 4295 | IntrinsicSideEffects side_effects, |
| 4296 | IntrinsicExceptions exceptions); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4297 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4298 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | 8e1ef53 | 2015-11-23 12:04:37 +0000 | [diff] [blame] | 4299 | return GetEnvironment()->IsFromInlinedInvoke(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4300 | } |
| 4301 | |
Aart Bik | ff7d89c | 2016-11-07 08:49:28 -0800 | [diff] [blame] | 4302 | void SetCanThrow(bool can_throw) { SetPackedFlag<kFlagCanThrow>(can_throw); } |
| 4303 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4304 | bool CanThrow() const override { return GetPackedFlag<kFlagCanThrow>(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4305 | |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4306 | void SetAlwaysThrows(bool always_throws) { SetPackedFlag<kFlagAlwaysThrows>(always_throws); } |
| 4307 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4308 | bool AlwaysThrows() const override { return GetPackedFlag<kFlagAlwaysThrows>(); } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4309 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4310 | bool CanBeMoved() const override { return IsIntrinsic() && !DoesAnyWrite(); } |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4311 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4312 | bool InstructionDataEquals(const HInstruction* other) const override { |
Aart Bik | 5d75afe | 2015-12-14 11:57:01 -0800 | [diff] [blame] | 4313 | return intrinsic_ != Intrinsics::kNone && intrinsic_ == other->AsInvoke()->intrinsic_; |
| 4314 | } |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 4315 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4316 | uint32_t* GetIntrinsicOptimizations() { |
| 4317 | return &intrinsic_optimizations_; |
| 4318 | } |
| 4319 | |
| 4320 | const uint32_t* GetIntrinsicOptimizations() const { |
| 4321 | return &intrinsic_optimizations_; |
| 4322 | } |
| 4323 | |
| 4324 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 4325 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4326 | ArtMethod* GetResolvedMethod() const { return resolved_method_; } |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 4327 | void SetResolvedMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4328 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 4329 | DECLARE_ABSTRACT_INSTRUCTION(Invoke); |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 4330 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4331 | protected: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4332 | static constexpr size_t kFieldInvokeType = kNumberOfGenericPackedBits; |
| 4333 | static constexpr size_t kFieldInvokeTypeSize = |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4334 | MinimumBitsToStore(static_cast<size_t>(kMaxInvokeType)); |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4335 | static constexpr size_t kFlagCanThrow = kFieldInvokeType + kFieldInvokeTypeSize; |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 4336 | static constexpr size_t kFlagAlwaysThrows = kFlagCanThrow + 1; |
| 4337 | static constexpr size_t kNumberOfInvokePackedBits = kFlagAlwaysThrows + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4338 | static_assert(kNumberOfInvokePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4339 | using InvokeTypeField = BitField<InvokeType, kFieldInvokeType, kFieldInvokeTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4340 | |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4341 | HInvoke(InstructionKind kind, |
| 4342 | ArenaAllocator* allocator, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4343 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4344 | uint32_t number_of_other_inputs, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4345 | DataType::Type return_type, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4346 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 4347 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4348 | ArtMethod* resolved_method, |
| 4349 | InvokeType invoke_type) |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4350 | : HVariableInputSizeInstruction( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4351 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4352 | return_type, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4353 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 4354 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4355 | allocator, |
Mingyao Yang | a9dbe83 | 2016-12-15 12:02:53 -0800 | [diff] [blame] | 4356 | number_of_arguments + number_of_other_inputs, |
| 4357 | kArenaAllocInvokeInputs), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4358 | number_of_arguments_(number_of_arguments), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4359 | dex_method_index_(dex_method_index), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 4360 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4361 | intrinsic_optimizations_(0) { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4362 | SetPackedField<InvokeTypeField>(invoke_type); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4363 | SetPackedFlag<kFlagCanThrow>(true); |
Nicolas Geoffray | 76d4bb0f3 | 2018-09-21 12:58:45 +0100 | [diff] [blame] | 4364 | // Check mutator lock, constructors lack annotalysis support. |
| 4365 | Locks::mutator_lock_->AssertNotExclusiveHeld(Thread::Current()); |
| 4366 | SetResolvedMethod(resolved_method); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4367 | } |
| 4368 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4369 | DEFAULT_COPY_CONSTRUCTOR(Invoke); |
| 4370 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4371 | uint32_t number_of_arguments_; |
Nicolas Geoffray | c4aa82c | 2017-03-06 14:38:52 +0000 | [diff] [blame] | 4372 | ArtMethod* resolved_method_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4373 | const uint32_t dex_method_index_; |
| 4374 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 4375 | |
| 4376 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 4377 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4378 | }; |
| 4379 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4380 | class HInvokeUnresolved final : public HInvoke { |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4381 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4382 | HInvokeUnresolved(ArenaAllocator* allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4383 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4384 | DataType::Type return_type, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4385 | uint32_t dex_pc, |
| 4386 | uint32_t dex_method_index, |
| 4387 | InvokeType invoke_type) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4388 | : HInvoke(kInvokeUnresolved, |
| 4389 | allocator, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4390 | number_of_arguments, |
| 4391 | 0u /* number_of_other_inputs */, |
| 4392 | return_type, |
| 4393 | dex_pc, |
| 4394 | dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4395 | nullptr, |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4396 | invoke_type) { |
| 4397 | } |
| 4398 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4399 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4400 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4401 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 4402 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4403 | protected: |
| 4404 | DEFAULT_COPY_CONSTRUCTOR(InvokeUnresolved); |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 4405 | }; |
| 4406 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4407 | class HInvokePolymorphic final : public HInvoke { |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4408 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4409 | HInvokePolymorphic(ArenaAllocator* allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4410 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4411 | DataType::Type return_type, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4412 | uint32_t dex_pc, |
| 4413 | uint32_t dex_method_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4414 | : HInvoke(kInvokePolymorphic, |
| 4415 | allocator, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4416 | number_of_arguments, |
| 4417 | 0u /* number_of_other_inputs */, |
| 4418 | return_type, |
| 4419 | dex_pc, |
| 4420 | dex_method_index, |
| 4421 | nullptr, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4422 | kVirtual) { |
| 4423 | } |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4424 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4425 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4426 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4427 | DECLARE_INSTRUCTION(InvokePolymorphic); |
| 4428 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4429 | protected: |
| 4430 | DEFAULT_COPY_CONSTRUCTOR(InvokePolymorphic); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 4431 | }; |
| 4432 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4433 | class HInvokeCustom final : public HInvoke { |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4434 | public: |
| 4435 | HInvokeCustom(ArenaAllocator* allocator, |
| 4436 | uint32_t number_of_arguments, |
| 4437 | uint32_t call_site_index, |
| 4438 | DataType::Type return_type, |
| 4439 | uint32_t dex_pc) |
| 4440 | : HInvoke(kInvokeCustom, |
| 4441 | allocator, |
| 4442 | number_of_arguments, |
| 4443 | /* number_of_other_inputs */ 0u, |
| 4444 | return_type, |
| 4445 | dex_pc, |
| 4446 | /* dex_method_index */ dex::kDexNoIndex, |
| 4447 | /* resolved_method */ nullptr, |
| 4448 | kStatic), |
| 4449 | call_site_index_(call_site_index) { |
| 4450 | } |
| 4451 | |
| 4452 | uint32_t GetCallSiteIndex() const { return call_site_index_; } |
| 4453 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4454 | bool IsClonable() const override { return true; } |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 4455 | |
| 4456 | DECLARE_INSTRUCTION(InvokeCustom); |
| 4457 | |
| 4458 | protected: |
| 4459 | DEFAULT_COPY_CONSTRUCTOR(InvokeCustom); |
| 4460 | |
| 4461 | private: |
| 4462 | uint32_t call_site_index_; |
| 4463 | }; |
| 4464 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4465 | class HInvokeStaticOrDirect final : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4466 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4467 | // Requirements of this method call regarding the class |
| 4468 | // initialization (clinit) check of its declaring class. |
| 4469 | enum class ClinitCheckRequirement { |
| 4470 | kNone, // Class already initialized. |
| 4471 | kExplicit, // Static call having explicit clinit check as last input. |
| 4472 | kImplicit, // Static call implicitly requiring a clinit check. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4473 | kLast = kImplicit |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4474 | }; |
| 4475 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4476 | // Determines how to load the target ArtMethod*. |
| 4477 | enum class MethodLoadKind { |
| 4478 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 4479 | kStringInit, |
| 4480 | |
| 4481 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 4482 | kRecursive, |
| 4483 | |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4484 | // Use PC-relative boot image ArtMethod* address that will be known at link time. |
| 4485 | // Used for boot image methods referenced by boot image code. |
| 4486 | kBootImageLinkTimePcRelative, |
| 4487 | |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4488 | // Load from an entry in the .data.bimg.rel.ro using a PC-relative load. |
| 4489 | // Used for app->boot calls with relocatable image. |
| 4490 | kBootImageRelRo, |
| 4491 | |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4492 | // 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] | 4493 | // 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] | 4494 | kBssEntry, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4495 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4496 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 4497 | // Used for for JIT-compiled calls. |
| 4498 | kJitDirectAddress, |
| 4499 | |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4500 | // Make a runtime call to resolve and call the method. This is the last-resort-kind |
| 4501 | // used when other kinds are unimplemented on a particular architecture. |
| 4502 | kRuntimeCall, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4503 | }; |
| 4504 | |
| 4505 | // Determines the location of the code pointer. |
| 4506 | enum class CodePtrLocation { |
| 4507 | // Recursive call, use local PC-relative call instruction. |
| 4508 | kCallSelf, |
| 4509 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4510 | // Use code pointer from the ArtMethod*. |
| 4511 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 4512 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 4513 | kCallArtMethod, |
| 4514 | }; |
| 4515 | |
| 4516 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4517 | MethodLoadKind method_load_kind; |
| 4518 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4519 | // The method load data holds |
| 4520 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 4521 | // Note that there are multiple string init methods, each having its own offset. |
| 4522 | // - the method address for kDirectAddress |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4523 | uint64_t method_load_data; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4524 | }; |
| 4525 | |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4526 | HInvokeStaticOrDirect(ArenaAllocator* allocator, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4527 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4528 | DataType::Type return_type, |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4529 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4530 | uint32_t method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4531 | ArtMethod* resolved_method, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4532 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4533 | InvokeType invoke_type, |
| 4534 | MethodReference target_method, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4535 | ClinitCheckRequirement clinit_check_requirement) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4536 | : HInvoke(kInvokeStaticOrDirect, |
| 4537 | allocator, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4538 | number_of_arguments, |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4539 | // There is potentially one extra argument for the HCurrentMethod node, and |
| 4540 | // potentially one other if the clinit check is explicit, and potentially |
| 4541 | // one other if the method is a string factory. |
| 4542 | (NeedsCurrentMethodInput(dispatch_info.method_load_kind) ? 1u : 0u) + |
David Brazdil | dee58d6 | 2016-04-07 09:54:26 +0000 | [diff] [blame] | 4543 | (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 4544 | return_type, |
| 4545 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4546 | method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4547 | resolved_method, |
| 4548 | invoke_type), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4549 | target_method_(target_method), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4550 | dispatch_info_(dispatch_info) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4551 | SetPackedField<ClinitCheckRequirementField>(clinit_check_requirement); |
| 4552 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4553 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4554 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4555 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4556 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4557 | bool had_current_method_input = HasCurrentMethodInput(); |
| 4558 | bool needs_current_method_input = NeedsCurrentMethodInput(dispatch_info.method_load_kind); |
| 4559 | |
| 4560 | // Using the current method is the default and once we find a better |
| 4561 | // method load kind, we should not go back to using the current method. |
| 4562 | DCHECK(had_current_method_input || !needs_current_method_input); |
| 4563 | |
| 4564 | if (had_current_method_input && !needs_current_method_input) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4565 | DCHECK_EQ(InputAt(GetSpecialInputIndex()), GetBlock()->GetGraph()->GetCurrentMethod()); |
| 4566 | RemoveInputAt(GetSpecialInputIndex()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4567 | } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4568 | dispatch_info_ = dispatch_info; |
| 4569 | } |
| 4570 | |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 4571 | DispatchInfo GetDispatchInfo() const { |
| 4572 | return dispatch_info_; |
| 4573 | } |
| 4574 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4575 | void AddSpecialInput(HInstruction* input) { |
| 4576 | // We allow only one special input. |
| 4577 | DCHECK(!IsStringInit() && !HasCurrentMethodInput()); |
| 4578 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4579 | (InputCount() == GetSpecialInputIndex() + 1 && IsStaticWithExplicitClinitCheck())); |
| 4580 | InsertInputAt(GetSpecialInputIndex(), input); |
| 4581 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4582 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4583 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4584 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4585 | ArrayRef<HUserRecord<HInstruction*>> input_records = HInvoke::GetInputRecords(); |
| 4586 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck()) { |
| 4587 | DCHECK(!input_records.empty()); |
| 4588 | DCHECK_GT(input_records.size(), GetNumberOfArguments()); |
| 4589 | HInstruction* last_input = input_records.back().GetInstruction(); |
| 4590 | // Note: `last_input` may be null during arguments setup. |
| 4591 | if (last_input != nullptr) { |
| 4592 | // `last_input` is the last input of a static invoke marked as having |
| 4593 | // an explicit clinit check. It must either be: |
| 4594 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 4595 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 4596 | DCHECK(last_input->IsClinitCheck() || last_input->IsLoadClass()) << last_input->DebugName(); |
| 4597 | } |
| 4598 | } |
| 4599 | return input_records; |
| 4600 | } |
| 4601 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4602 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4603 | // We access the method via the dex cache so we can't do an implicit null check. |
| 4604 | // TODO: for intrinsics we can generate implicit null checks. |
| 4605 | return false; |
| 4606 | } |
| 4607 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4608 | bool CanBeNull() const override { |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 4609 | return GetType() == DataType::Type::kReference && !IsStringInit(); |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 4610 | } |
| 4611 | |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4612 | // Get the index of the special input, if any. |
| 4613 | // |
David Brazdil | 6de1938 | 2016-01-08 17:37:10 +0000 | [diff] [blame] | 4614 | // If the invoke HasCurrentMethodInput(), the "special input" is the current |
| 4615 | // method pointer; otherwise there may be one platform-specific special input, |
| 4616 | // such as PC-relative addressing base. |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4617 | uint32_t GetSpecialInputIndex() const { return GetNumberOfArguments(); } |
Nicolas Geoffray | 9779307 | 2016-02-16 15:33:54 +0000 | [diff] [blame] | 4618 | bool HasSpecialInput() const { return GetNumberOfArguments() != InputCount(); } |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4619 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4620 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 4621 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 4622 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4623 | bool NeedsDexCacheOfDeclaringClass() const override; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4624 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 4625 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kJitDirectAddress; } |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4626 | bool HasPcRelativeMethodLoadKind() const { |
| 4627 | return GetMethodLoadKind() == MethodLoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | b066d43 | 2018-01-03 13:14:37 +0000 | [diff] [blame] | 4628 | GetMethodLoadKind() == MethodLoadKind::kBootImageRelRo || |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 4629 | GetMethodLoadKind() == MethodLoadKind::kBssEntry; |
Vladimir Marko | 6597946 | 2017-05-19 17:25:12 +0100 | [diff] [blame] | 4630 | } |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4631 | bool HasCurrentMethodInput() const { |
| 4632 | // This function can be called only after the invoke has been fully initialized by the builder. |
| 4633 | if (NeedsCurrentMethodInput(GetMethodLoadKind())) { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4634 | DCHECK(InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4635 | return true; |
| 4636 | } else { |
Vladimir Marko | c53c079 | 2015-11-19 15:48:33 +0000 | [diff] [blame] | 4637 | DCHECK(InputCount() == GetSpecialInputIndex() || |
| 4638 | !InputAt(GetSpecialInputIndex())->IsCurrentMethod()); |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4639 | return false; |
| 4640 | } |
| 4641 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4642 | |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4643 | QuickEntrypointEnum GetStringInitEntryPoint() const { |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4644 | DCHECK(IsStringInit()); |
Nicolas Geoffray | da079bb | 2016-09-26 17:56:07 +0100 | [diff] [blame] | 4645 | return static_cast<QuickEntrypointEnum>(dispatch_info_.method_load_data); |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | uint64_t GetMethodAddress() const { |
| 4649 | DCHECK(HasMethodAddress()); |
| 4650 | return dispatch_info_.method_load_data; |
| 4651 | } |
| 4652 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 4653 | const DexFile& GetDexFileForPcRelativeDexCache() const; |
| 4654 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4655 | ClinitCheckRequirement GetClinitCheckRequirement() const { |
| 4656 | return GetPackedField<ClinitCheckRequirementField>(); |
| 4657 | } |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 4658 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4659 | // Is this instruction a call to a static method? |
| 4660 | bool IsStatic() const { |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4661 | return GetInvokeType() == kStatic; |
| 4662 | } |
| 4663 | |
| 4664 | MethodReference GetTargetMethod() const { |
| 4665 | return target_method_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4666 | } |
| 4667 | |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4668 | // Remove the HClinitCheck or the replacement HLoadClass (set as last input by |
| 4669 | // PrepareForRegisterAllocation::VisitClinitCheck() in lieu of the initial HClinitCheck) |
| 4670 | // instruction; only relevant for static calls with explicit clinit check. |
| 4671 | void RemoveExplicitClinitCheck(ClinitCheckRequirement new_requirement) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4672 | DCHECK(IsStaticWithExplicitClinitCheck()); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 4673 | size_t last_input_index = inputs_.size() - 1u; |
| 4674 | HInstruction* last_input = inputs_.back().GetInstruction(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4675 | DCHECK(last_input != nullptr); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4676 | DCHECK(last_input->IsLoadClass() || last_input->IsClinitCheck()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4677 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4678 | inputs_.pop_back(); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4679 | SetPackedField<ClinitCheckRequirementField>(new_requirement); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4680 | DCHECK(!IsStaticWithExplicitClinitCheck()); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4681 | } |
| 4682 | |
| 4683 | // 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] | 4684 | // explicit initialization check in the graph? |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4685 | bool IsStaticWithExplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4686 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kExplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | // Is this a call to a static method whose declaring class has an |
| 4690 | // implicit intialization check requirement? |
| 4691 | bool IsStaticWithImplicitClinitCheck() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4692 | return IsStatic() && (GetClinitCheckRequirement() == ClinitCheckRequirement::kImplicit); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 4693 | } |
| 4694 | |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4695 | // Does this method load kind need the current method as an input? |
| 4696 | static bool NeedsCurrentMethodInput(MethodLoadKind kind) { |
Vladimir Marko | e7197bf | 2017-06-02 17:00:23 +0100 | [diff] [blame] | 4697 | return kind == MethodLoadKind::kRecursive || kind == MethodLoadKind::kRuntimeCall; |
Vladimir Marko | b554b5a | 2015-11-06 12:57:55 +0000 | [diff] [blame] | 4698 | } |
| 4699 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 4700 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4701 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4702 | protected: |
| 4703 | DEFAULT_COPY_CONSTRUCTOR(InvokeStaticOrDirect); |
| 4704 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4705 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4706 | static constexpr size_t kFieldClinitCheckRequirement = kNumberOfInvokePackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4707 | static constexpr size_t kFieldClinitCheckRequirementSize = |
| 4708 | MinimumBitsToStore(static_cast<size_t>(ClinitCheckRequirement::kLast)); |
| 4709 | static constexpr size_t kNumberOfInvokeStaticOrDirectPackedBits = |
| 4710 | kFieldClinitCheckRequirement + kFieldClinitCheckRequirementSize; |
| 4711 | static_assert(kNumberOfInvokeStaticOrDirectPackedBits <= kMaxNumberOfPackedBits, |
| 4712 | "Too many packed fields."); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 4713 | using ClinitCheckRequirementField = BitField<ClinitCheckRequirement, |
| 4714 | kFieldClinitCheckRequirement, |
| 4715 | kFieldClinitCheckRequirementSize>; |
| 4716 | |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4717 | // Cached values of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | ea179f4 | 2018-02-08 22:30:18 +0000 | [diff] [blame] | 4718 | const MethodReference target_method_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 4719 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4720 | }; |
Vladimir Marko | f64242a | 2015-12-01 14:58:23 +0000 | [diff] [blame] | 4721 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::MethodLoadKind rhs); |
Vladimir Marko | fbb184a | 2015-11-13 14:47:00 +0000 | [diff] [blame] | 4722 | std::ostream& operator<<(std::ostream& os, HInvokeStaticOrDirect::ClinitCheckRequirement rhs); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 4723 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4724 | class HInvokeVirtual final : public HInvoke { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4725 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4726 | HInvokeVirtual(ArenaAllocator* allocator, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4727 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4728 | DataType::Type return_type, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4729 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 4730 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4731 | ArtMethod* resolved_method, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4732 | uint32_t vtable_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4733 | : HInvoke(kInvokeVirtual, |
| 4734 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4735 | number_of_arguments, |
| 4736 | 0u, |
| 4737 | return_type, |
| 4738 | dex_pc, |
| 4739 | dex_method_index, |
| 4740 | resolved_method, |
| 4741 | kVirtual), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4742 | vtable_index_(vtable_index) { |
| 4743 | } |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4744 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4745 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4746 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4747 | bool CanBeNull() const override { |
Aart Bik | 71bf7b4 | 2016-11-16 10:17:46 -0800 | [diff] [blame] | 4748 | switch (GetIntrinsic()) { |
| 4749 | case Intrinsics::kThreadCurrentThread: |
| 4750 | case Intrinsics::kStringBufferAppend: |
| 4751 | case Intrinsics::kStringBufferToString: |
| 4752 | case Intrinsics::kStringBuilderAppend: |
| 4753 | case Intrinsics::kStringBuilderToString: |
| 4754 | return false; |
| 4755 | default: |
| 4756 | return HInvoke::CanBeNull(); |
| 4757 | } |
| 4758 | } |
| 4759 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4760 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4761 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 4762 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4763 | } |
| 4764 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4765 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 4766 | |
| 4767 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 4768 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4769 | protected: |
| 4770 | DEFAULT_COPY_CONSTRUCTOR(InvokeVirtual); |
| 4771 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4772 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4773 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4774 | const uint32_t vtable_index_; |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 4775 | }; |
| 4776 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4777 | class HInvokeInterface final : public HInvoke { |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4778 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 4779 | HInvokeInterface(ArenaAllocator* allocator, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4780 | uint32_t number_of_arguments, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4781 | DataType::Type return_type, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4782 | uint32_t dex_pc, |
| 4783 | uint32_t dex_method_index, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4784 | ArtMethod* resolved_method, |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4785 | uint32_t imt_index) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4786 | : HInvoke(kInvokeInterface, |
| 4787 | allocator, |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4788 | number_of_arguments, |
| 4789 | 0u, |
| 4790 | return_type, |
| 4791 | dex_pc, |
| 4792 | dex_method_index, |
| 4793 | resolved_method, |
| 4794 | kInterface), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4795 | imt_index_(imt_index) { |
| 4796 | } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4797 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4798 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4799 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4800 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4801 | // TODO: Add implicit null checks in intrinsics. |
Nicolas Geoffray | 61ba8d2 | 2018-08-07 09:55:57 +0100 | [diff] [blame] | 4802 | return (obj == InputAt(0)) && !IsIntrinsic(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4803 | } |
| 4804 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4805 | bool NeedsDexCacheOfDeclaringClass() const override { |
Nicolas Geoffray | fbdfa6d | 2017-02-03 10:43:13 +0000 | [diff] [blame] | 4806 | // The assembly stub currently needs it. |
| 4807 | return true; |
| 4808 | } |
| 4809 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4810 | uint32_t GetImtIndex() const { return imt_index_; } |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4811 | |
| 4812 | DECLARE_INSTRUCTION(InvokeInterface); |
| 4813 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4814 | protected: |
| 4815 | DEFAULT_COPY_CONSTRUCTOR(InvokeInterface); |
| 4816 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4817 | private: |
Nicolas Geoffray | 5e4e11e | 2016-09-22 13:17:41 +0100 | [diff] [blame] | 4818 | // Cached value of the resolved method, to avoid needing the mutator lock. |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4819 | const uint32_t imt_index_; |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 4820 | }; |
| 4821 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4822 | class HNeg final : public HUnaryOperation { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4823 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4824 | 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] | 4825 | : HUnaryOperation(kNeg, result_type, input, dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4826 | DCHECK_EQ(result_type, DataType::Kind(input->GetType())); |
Roland Levillain | 937e6cd | 2016-03-22 11:54:37 +0000 | [diff] [blame] | 4827 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4828 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4829 | template <typename T> static T Compute(T x) { return -x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4830 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4831 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4832 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4833 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4834 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4835 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4836 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4837 | HConstant* Evaluate(HFloatConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4838 | return GetBlock()->GetGraph()->GetFloatConstant(Compute(x->GetValue()), GetDexPc()); |
| 4839 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4840 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4841 | return GetBlock()->GetGraph()->GetDoubleConstant(Compute(x->GetValue()), GetDexPc()); |
| 4842 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 4843 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4844 | DECLARE_INSTRUCTION(Neg); |
| 4845 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4846 | protected: |
| 4847 | DEFAULT_COPY_CONSTRUCTOR(Neg); |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 4848 | }; |
| 4849 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4850 | class HNewArray final : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4851 | public: |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4852 | HNewArray(HInstruction* cls, HInstruction* length, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4853 | : HExpression(kNewArray, DataType::Type::kReference, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4854 | SetRawInputAt(0, cls); |
| 4855 | SetRawInputAt(1, length); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4856 | } |
| 4857 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4858 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4859 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4860 | // Calls runtime so needs an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4861 | bool NeedsEnvironment() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4862 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4863 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4864 | bool CanThrow() const override { return true; } |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 4865 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4866 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4867 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 4868 | HLoadClass* GetLoadClass() const { |
| 4869 | DCHECK(InputAt(0)->IsLoadClass()); |
| 4870 | return InputAt(0)->AsLoadClass(); |
| 4871 | } |
| 4872 | |
| 4873 | HInstruction* GetLength() const { |
| 4874 | return InputAt(1); |
| 4875 | } |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 4876 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4877 | DECLARE_INSTRUCTION(NewArray); |
| 4878 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4879 | protected: |
| 4880 | DEFAULT_COPY_CONSTRUCTOR(NewArray); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 4881 | }; |
| 4882 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4883 | class HAdd final : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4884 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4885 | HAdd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4886 | HInstruction* left, |
| 4887 | HInstruction* right, |
| 4888 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4889 | : HBinaryOperation(kAdd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4890 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4891 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4892 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4893 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4894 | 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] | 4895 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4896 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4897 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4898 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4899 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4900 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4901 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4902 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4903 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4904 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4905 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4906 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4907 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4908 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4909 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4910 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4911 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4912 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4913 | DECLARE_INSTRUCTION(Add); |
| 4914 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4915 | protected: |
| 4916 | DEFAULT_COPY_CONSTRUCTOR(Add); |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 4917 | }; |
| 4918 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4919 | class HSub final : public HBinaryOperation { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4920 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4921 | HSub(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4922 | HInstruction* left, |
| 4923 | HInstruction* right, |
| 4924 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4925 | : HBinaryOperation(kSub, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4926 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4927 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4928 | 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] | 4929 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4930 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4931 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4932 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4933 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4934 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4935 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4936 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 4937 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4938 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4939 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4940 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4941 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4942 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4943 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4944 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4945 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 4946 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4947 | DECLARE_INSTRUCTION(Sub); |
| 4948 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4949 | protected: |
| 4950 | DEFAULT_COPY_CONSTRUCTOR(Sub); |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4951 | }; |
| 4952 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4953 | class HMul final : public HBinaryOperation { |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4954 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4955 | HMul(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4956 | HInstruction* left, |
| 4957 | HInstruction* right, |
| 4958 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4959 | : HBinaryOperation(kMul, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4960 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4961 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4962 | bool IsCommutative() const override { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4963 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 4964 | 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] | 4965 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4966 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4967 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4968 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4969 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4970 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4971 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4972 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4973 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4974 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4975 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 4976 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4977 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4978 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4979 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 4980 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
| 4981 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4982 | |
| 4983 | DECLARE_INSTRUCTION(Mul); |
| 4984 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 4985 | protected: |
| 4986 | DEFAULT_COPY_CONSTRUCTOR(Mul); |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 4987 | }; |
| 4988 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 4989 | class HDiv final : public HBinaryOperation { |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4990 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 4991 | HDiv(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4992 | HInstruction* left, |
| 4993 | HInstruction* right, |
| 4994 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 4995 | : HBinaryOperation(kDiv, result_type, left, right, SideEffects::None(), dex_pc) { |
| 4996 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 4997 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4998 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 4999 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5000 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5001 | // Our graph structure ensures we never have 0 for `y` during |
| 5002 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5003 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5004 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 5005 | return (y == -1) ? -x : x / y; |
| 5006 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5007 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5008 | template <typename T> |
| 5009 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5010 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5011 | return x / y; |
| 5012 | } |
| 5013 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5014 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5015 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5016 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5017 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5018 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5019 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5020 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5021 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5022 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5023 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5024 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5025 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5026 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5027 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5028 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5029 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5030 | |
| 5031 | DECLARE_INSTRUCTION(Div); |
| 5032 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5033 | protected: |
| 5034 | DEFAULT_COPY_CONSTRUCTOR(Div); |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 5035 | }; |
| 5036 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5037 | class HRem final : public HBinaryOperation { |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5038 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5039 | HRem(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5040 | HInstruction* left, |
| 5041 | HInstruction* right, |
| 5042 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5043 | : HBinaryOperation(kRem, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5044 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5045 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5046 | template <typename T> |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5047 | T ComputeIntegral(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5048 | DCHECK(!DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5049 | // Our graph structure ensures we never have 0 for `y` during |
| 5050 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5051 | DCHECK_NE(y, 0); |
| 5052 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 5053 | return (y == -1) ? 0 : x % y; |
| 5054 | } |
| 5055 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5056 | template <typename T> |
| 5057 | T ComputeFP(T x, T y) const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5058 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5059 | return std::fmod(x, y); |
| 5060 | } |
| 5061 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5062 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5063 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5064 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5065 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5066 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5067 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5068 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5069 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5070 | HConstant* Evaluate(HFloatConstant* x, HFloatConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5071 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5072 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5073 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5074 | HConstant* Evaluate(HDoubleConstant* x, HDoubleConstant* y) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5075 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5076 | ComputeFP(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5077 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5078 | |
| 5079 | DECLARE_INSTRUCTION(Rem); |
| 5080 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5081 | protected: |
| 5082 | DEFAULT_COPY_CONSTRUCTOR(Rem); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 5083 | }; |
| 5084 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5085 | class HMin final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5086 | public: |
| 5087 | HMin(DataType::Type result_type, |
| 5088 | HInstruction* left, |
| 5089 | HInstruction* right, |
| 5090 | uint32_t dex_pc) |
| 5091 | : HBinaryOperation(kMin, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5092 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5093 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5094 | |
| 5095 | // Evaluation for integral values. |
| 5096 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5097 | return (x <= y) ? x : y; |
| 5098 | } |
| 5099 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5100 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5101 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5102 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5103 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5104 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5105 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5106 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5107 | } |
| 5108 | // TODO: Evaluation for floating-point values. |
| 5109 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5110 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5111 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5112 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5113 | |
| 5114 | DECLARE_INSTRUCTION(Min); |
| 5115 | |
| 5116 | protected: |
| 5117 | DEFAULT_COPY_CONSTRUCTOR(Min); |
| 5118 | }; |
| 5119 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5120 | class HMax final : public HBinaryOperation { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5121 | public: |
| 5122 | HMax(DataType::Type result_type, |
| 5123 | HInstruction* left, |
| 5124 | HInstruction* right, |
| 5125 | uint32_t dex_pc) |
| 5126 | : HBinaryOperation(kMax, result_type, left, right, SideEffects::None(), dex_pc) {} |
| 5127 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5128 | bool IsCommutative() const override { return true; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5129 | |
| 5130 | // Evaluation for integral values. |
| 5131 | template <typename T> static T ComputeIntegral(T x, T y) { |
| 5132 | return (x >= y) ? x : y; |
| 5133 | } |
| 5134 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5135 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5136 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5137 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5138 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5139 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5140 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5141 | ComputeIntegral(x->GetValue(), y->GetValue()), GetDexPc()); |
| 5142 | } |
| 5143 | // TODO: Evaluation for floating-point values. |
| 5144 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5145 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5146 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5147 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { return nullptr; } |
Aart Bik | 1f8d51b | 2018-02-15 10:42:37 -0800 | [diff] [blame] | 5148 | |
| 5149 | DECLARE_INSTRUCTION(Max); |
| 5150 | |
| 5151 | protected: |
| 5152 | DEFAULT_COPY_CONSTRUCTOR(Max); |
| 5153 | }; |
| 5154 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5155 | class HAbs final : public HUnaryOperation { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5156 | public: |
| 5157 | HAbs(DataType::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 5158 | : HUnaryOperation(kAbs, result_type, input, dex_pc) {} |
| 5159 | |
| 5160 | // Evaluation for integral values. |
| 5161 | template <typename T> static T ComputeIntegral(T x) { |
| 5162 | return x < 0 ? -x : x; |
| 5163 | } |
| 5164 | |
| 5165 | // Evaluation for floating-point values. |
| 5166 | // Note, as a "quality of implementation", rather than pure "spec compliance", |
| 5167 | // we require that Math.abs() clears the sign bit (but changes nothing else) |
| 5168 | // for all floating-point numbers, including NaN (signaling NaN may become quiet though). |
| 5169 | // http://b/30758343 |
| 5170 | template <typename T, typename S> static T ComputeFP(T x) { |
| 5171 | S bits = bit_cast<S, T>(x); |
| 5172 | return bit_cast<T, S>(bits & std::numeric_limits<S>::max()); |
| 5173 | } |
| 5174 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5175 | HConstant* Evaluate(HIntConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5176 | return GetBlock()->GetGraph()->GetIntConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5177 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5178 | HConstant* Evaluate(HLongConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5179 | return GetBlock()->GetGraph()->GetLongConstant(ComputeIntegral(x->GetValue()), GetDexPc()); |
| 5180 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5181 | HConstant* Evaluate(HFloatConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5182 | return GetBlock()->GetGraph()->GetFloatConstant( |
| 5183 | ComputeFP<float, int32_t>(x->GetValue()), GetDexPc()); |
| 5184 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5185 | HConstant* Evaluate(HDoubleConstant* x) const override { |
Aart Bik | 3dad341 | 2018-02-28 12:01:46 -0800 | [diff] [blame] | 5186 | return GetBlock()->GetGraph()->GetDoubleConstant( |
| 5187 | ComputeFP<double, int64_t>(x->GetValue()), GetDexPc()); |
| 5188 | } |
| 5189 | |
| 5190 | DECLARE_INSTRUCTION(Abs); |
| 5191 | |
| 5192 | protected: |
| 5193 | DEFAULT_COPY_CONSTRUCTOR(Abs); |
| 5194 | }; |
| 5195 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5196 | class HDivZeroCheck final : public HExpression<1> { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5197 | public: |
Alexandre Rames | 780aece | 2016-01-13 14:34:39 +0000 | [diff] [blame] | 5198 | // `HDivZeroCheck` can trigger GC, as it may call the `ArithmeticException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5199 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5200 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5201 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5202 | : HExpression(kDivZeroCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5203 | SetRawInputAt(0, value); |
| 5204 | } |
| 5205 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5206 | bool IsClonable() const override { return true; } |
| 5207 | bool CanBeMoved() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5208 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5209 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5210 | return true; |
| 5211 | } |
| 5212 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5213 | bool NeedsEnvironment() const override { return true; } |
| 5214 | bool CanThrow() const override { return true; } |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5215 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5216 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 5217 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5218 | protected: |
| 5219 | DEFAULT_COPY_CONSTRUCTOR(DivZeroCheck); |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 5220 | }; |
| 5221 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5222 | class HShl final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5223 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5224 | HShl(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5225 | HInstruction* value, |
| 5226 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5227 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5228 | : HBinaryOperation(kShl, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5229 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5230 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5231 | } |
| 5232 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5233 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5234 | 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] | 5235 | return value << (distance & max_shift_distance); |
| 5236 | } |
| 5237 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5238 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5239 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5240 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5241 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5242 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5243 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5244 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5245 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5246 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5247 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5248 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5249 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5250 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5251 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5252 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5253 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5254 | UNREACHABLE(); |
| 5255 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5256 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5257 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5258 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5259 | UNREACHABLE(); |
| 5260 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5261 | |
| 5262 | DECLARE_INSTRUCTION(Shl); |
| 5263 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5264 | protected: |
| 5265 | DEFAULT_COPY_CONSTRUCTOR(Shl); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5266 | }; |
| 5267 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5268 | class HShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5269 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5270 | HShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5271 | HInstruction* value, |
| 5272 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5273 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5274 | : HBinaryOperation(kShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5275 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5276 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5277 | } |
| 5278 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5279 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5280 | 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] | 5281 | return value >> (distance & max_shift_distance); |
| 5282 | } |
| 5283 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5284 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5285 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5286 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5287 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5288 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5289 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5290 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5291 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5292 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5293 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5294 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5295 | UNREACHABLE(); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5296 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5297 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5298 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5299 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5300 | UNREACHABLE(); |
| 5301 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5302 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5303 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5304 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5305 | UNREACHABLE(); |
| 5306 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5307 | |
| 5308 | DECLARE_INSTRUCTION(Shr); |
| 5309 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5310 | protected: |
| 5311 | DEFAULT_COPY_CONSTRUCTOR(Shr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5312 | }; |
| 5313 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5314 | class HUShr final : public HBinaryOperation { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5315 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5316 | HUShr(DataType::Type result_type, |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5317 | HInstruction* value, |
| 5318 | HInstruction* distance, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5319 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5320 | : HBinaryOperation(kUShr, result_type, value, distance, SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5321 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5322 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5323 | } |
| 5324 | |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5325 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5326 | 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] | 5327 | typedef typename std::make_unsigned<T>::type V; |
| 5328 | V ux = static_cast<V>(value); |
| 5329 | return static_cast<T>(ux >> (distance & max_shift_distance)); |
| 5330 | } |
| 5331 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5332 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5333 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5334 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5335 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5336 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5337 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5338 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5339 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5340 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5341 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5342 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5343 | UNREACHABLE(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5344 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5345 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5346 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5347 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5348 | UNREACHABLE(); |
| 5349 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5350 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5351 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5352 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5353 | UNREACHABLE(); |
| 5354 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5355 | |
| 5356 | DECLARE_INSTRUCTION(UShr); |
| 5357 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5358 | protected: |
| 5359 | DEFAULT_COPY_CONSTRUCTOR(UShr); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 5360 | }; |
| 5361 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5362 | class HAnd final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5363 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5364 | HAnd(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5365 | HInstruction* left, |
| 5366 | HInstruction* right, |
| 5367 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5368 | : HBinaryOperation(kAnd, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5369 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5370 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5371 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5372 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5373 | 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] | 5374 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5375 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5376 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5377 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5378 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5379 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5380 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5381 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5382 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5383 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5384 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5385 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5386 | UNREACHABLE(); |
| 5387 | } |
| 5388 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5389 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5390 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5391 | UNREACHABLE(); |
| 5392 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5393 | |
| 5394 | DECLARE_INSTRUCTION(And); |
| 5395 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5396 | protected: |
| 5397 | DEFAULT_COPY_CONSTRUCTOR(And); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5398 | }; |
| 5399 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5400 | class HOr final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5401 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5402 | HOr(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5403 | HInstruction* left, |
| 5404 | HInstruction* right, |
| 5405 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5406 | : HBinaryOperation(kOr, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5407 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5408 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5409 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5410 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5411 | 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] | 5412 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5413 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5414 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5415 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5416 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5417 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5418 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5419 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5420 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5421 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5422 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5423 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5424 | UNREACHABLE(); |
| 5425 | } |
| 5426 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5427 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5428 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5429 | UNREACHABLE(); |
| 5430 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5431 | |
| 5432 | DECLARE_INSTRUCTION(Or); |
| 5433 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5434 | protected: |
| 5435 | DEFAULT_COPY_CONSTRUCTOR(Or); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5436 | }; |
| 5437 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5438 | class HXor final : public HBinaryOperation { |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5439 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5440 | HXor(DataType::Type result_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5441 | HInstruction* left, |
| 5442 | HInstruction* right, |
| 5443 | uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5444 | : HBinaryOperation(kXor, result_type, left, right, SideEffects::None(), dex_pc) { |
| 5445 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5446 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5447 | bool IsCommutative() const override { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5448 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5449 | 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] | 5450 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5451 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5452 | return GetBlock()->GetGraph()->GetIntConstant( |
| 5453 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5454 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5455 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5456 | return GetBlock()->GetGraph()->GetLongConstant( |
| 5457 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5458 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5459 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5460 | HFloatConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5461 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5462 | UNREACHABLE(); |
| 5463 | } |
| 5464 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5465 | HDoubleConstant* y ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5466 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5467 | UNREACHABLE(); |
| 5468 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5469 | |
| 5470 | DECLARE_INSTRUCTION(Xor); |
| 5471 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5472 | protected: |
| 5473 | DEFAULT_COPY_CONSTRUCTOR(Xor); |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 5474 | }; |
| 5475 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5476 | class HRor final : public HBinaryOperation { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5477 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5478 | HRor(DataType::Type result_type, HInstruction* value, HInstruction* distance) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5479 | : HBinaryOperation(kRor, result_type, value, distance) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5480 | DCHECK_EQ(result_type, DataType::Kind(value->GetType())); |
| 5481 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(distance->GetType())); |
Roland Levillain | 22c4922 | 2016-03-18 14:04:28 +0000 | [diff] [blame] | 5482 | } |
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 | template <typename T> |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5485 | 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] | 5486 | typedef typename std::make_unsigned<T>::type V; |
| 5487 | V ux = static_cast<V>(value); |
| 5488 | if ((distance & max_shift_value) == 0) { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5489 | return static_cast<T>(ux); |
| 5490 | } else { |
| 5491 | const V reg_bits = sizeof(T) * 8; |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5492 | return static_cast<T>(ux >> (distance & max_shift_value)) | |
| 5493 | (value << (reg_bits - (distance & max_shift_value))); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5494 | } |
| 5495 | } |
| 5496 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5497 | HConstant* Evaluate(HIntConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5498 | return GetBlock()->GetGraph()->GetIntConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5499 | Compute(value->GetValue(), distance->GetValue(), kMaxIntShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5500 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5501 | HConstant* Evaluate(HLongConstant* value, HIntConstant* distance) const override { |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5502 | return GetBlock()->GetGraph()->GetLongConstant( |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5503 | Compute(value->GetValue(), distance->GetValue(), kMaxLongShiftDistance), GetDexPc()); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5504 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5505 | HConstant* Evaluate(HLongConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5506 | HLongConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5507 | LOG(FATAL) << DebugName() << " is not defined for the (long, long) case."; |
| 5508 | UNREACHABLE(); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5509 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5510 | HConstant* Evaluate(HFloatConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5511 | HFloatConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5512 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5513 | UNREACHABLE(); |
| 5514 | } |
Roland Levillain | 5b5b931 | 2016-03-22 14:57:31 +0000 | [diff] [blame] | 5515 | HConstant* Evaluate(HDoubleConstant* value ATTRIBUTE_UNUSED, |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5516 | HDoubleConstant* distance ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5517 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5518 | UNREACHABLE(); |
| 5519 | } |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5520 | |
| 5521 | DECLARE_INSTRUCTION(Ror); |
| 5522 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5523 | protected: |
| 5524 | DEFAULT_COPY_CONSTRUCTOR(Ror); |
Scott Wakeling | 40a04bf | 2015-12-11 09:50:36 +0000 | [diff] [blame] | 5525 | }; |
| 5526 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5527 | // The value of a parameter in this method. Its location depends on |
| 5528 | // the calling convention. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5529 | class HParameterValue final : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5530 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5531 | HParameterValue(const DexFile& dex_file, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5532 | dex::TypeIndex type_index, |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5533 | uint8_t index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5534 | DataType::Type parameter_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5535 | bool is_this = false) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5536 | : HExpression(kParameterValue, parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5537 | dex_file_(dex_file), |
| 5538 | type_index_(type_index), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5539 | index_(index) { |
| 5540 | SetPackedFlag<kFlagIsThis>(is_this); |
| 5541 | SetPackedFlag<kFlagCanBeNull>(!is_this); |
| 5542 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5543 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5544 | const DexFile& GetDexFile() const { return dex_file_; } |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5545 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5546 | uint8_t GetIndex() const { return index_; } |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 5547 | bool IsThis() const { return GetPackedFlag<kFlagIsThis>(); } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5548 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5549 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5550 | void SetCanBeNull(bool can_be_null) { SetPackedFlag<kFlagCanBeNull>(can_be_null); } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5551 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5552 | DECLARE_INSTRUCTION(ParameterValue); |
| 5553 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5554 | protected: |
| 5555 | DEFAULT_COPY_CONSTRUCTOR(ParameterValue); |
| 5556 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5557 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5558 | // Whether or not the parameter value corresponds to 'this' argument. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5559 | static constexpr size_t kFlagIsThis = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5560 | static constexpr size_t kFlagCanBeNull = kFlagIsThis + 1; |
| 5561 | static constexpr size_t kNumberOfParameterValuePackedBits = kFlagCanBeNull + 1; |
| 5562 | static_assert(kNumberOfParameterValuePackedBits <= kMaxNumberOfPackedBits, |
| 5563 | "Too many packed fields."); |
| 5564 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 5565 | const DexFile& dex_file_; |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 5566 | const dex::TypeIndex type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5567 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5568 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5569 | const uint8_t index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 5570 | }; |
| 5571 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5572 | class HNot final : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5573 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5574 | 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] | 5575 | : HUnaryOperation(kNot, result_type, input, dex_pc) { |
| 5576 | } |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5577 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5578 | bool CanBeMoved() const override { return true; } |
| 5579 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5580 | return true; |
| 5581 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5582 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5583 | template <typename T> static T Compute(T x) { return ~x; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5584 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5585 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5586 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5587 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5588 | HConstant* Evaluate(HLongConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5589 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5590 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5591 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5592 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5593 | UNREACHABLE(); |
| 5594 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5595 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5596 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5597 | UNREACHABLE(); |
| 5598 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 5599 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5600 | DECLARE_INSTRUCTION(Not); |
| 5601 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5602 | protected: |
| 5603 | DEFAULT_COPY_CONSTRUCTOR(Not); |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 5604 | }; |
| 5605 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5606 | class HBooleanNot final : public HUnaryOperation { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5607 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5608 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5609 | : HUnaryOperation(kBooleanNot, DataType::Type::kBool, input, dex_pc) { |
| 5610 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5611 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5612 | bool CanBeMoved() const override { return true; } |
| 5613 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5614 | return true; |
| 5615 | } |
| 5616 | |
Anton Kirilov | 7fe30f9 | 2016-06-29 17:03:40 +0100 | [diff] [blame] | 5617 | template <typename T> static bool Compute(T x) { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5618 | DCHECK(IsUint<1>(x)) << x; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5619 | return !x; |
| 5620 | } |
| 5621 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5622 | HConstant* Evaluate(HIntConstant* x) const override { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5623 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5624 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5625 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 5626 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5627 | UNREACHABLE(); |
| 5628 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5629 | HConstant* Evaluate(HFloatConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5630 | LOG(FATAL) << DebugName() << " is not defined for float values"; |
| 5631 | UNREACHABLE(); |
| 5632 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5633 | HConstant* Evaluate(HDoubleConstant* x ATTRIBUTE_UNUSED) const override { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 5634 | LOG(FATAL) << DebugName() << " is not defined for double values"; |
| 5635 | UNREACHABLE(); |
| 5636 | } |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5637 | |
| 5638 | DECLARE_INSTRUCTION(BooleanNot); |
| 5639 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5640 | protected: |
| 5641 | DEFAULT_COPY_CONSTRUCTOR(BooleanNot); |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 5642 | }; |
| 5643 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5644 | class HTypeConversion final : public HExpression<1> { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5645 | public: |
| 5646 | // Instantiate a type conversion of `input` to `result_type`. |
Vladimir Marko | c8fb211 | 2017-10-03 11:37:52 +0100 | [diff] [blame] | 5647 | 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] | 5648 | : HExpression(kTypeConversion, result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5649 | SetRawInputAt(0, input); |
Roland Levillain | f355c3f | 2016-03-30 19:09:03 +0100 | [diff] [blame] | 5650 | // Invariant: We should never generate a conversion to a Boolean value. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5651 | DCHECK_NE(DataType::Type::kBool, result_type); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | HInstruction* GetInput() const { return InputAt(0); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5655 | DataType::Type GetInputType() const { return GetInput()->GetType(); } |
| 5656 | DataType::Type GetResultType() const { return GetType(); } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5657 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5658 | bool IsClonable() const override { return true; } |
| 5659 | bool CanBeMoved() const override { return true; } |
| 5660 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5661 | return true; |
| 5662 | } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5663 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 5664 | // Try to statically evaluate the conversion and return a HConstant |
| 5665 | // containing the result. If the input cannot be converted, return nullptr. |
| 5666 | HConstant* TryStaticEvaluation() const; |
| 5667 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5668 | DECLARE_INSTRUCTION(TypeConversion); |
| 5669 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5670 | protected: |
| 5671 | DEFAULT_COPY_CONSTRUCTOR(TypeConversion); |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 5672 | }; |
| 5673 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 5674 | static constexpr uint32_t kNoRegNumber = -1; |
| 5675 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5676 | class HNullCheck final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5677 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 5678 | // `HNullCheck` can trigger GC, as it may call the `NullPointerException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5679 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 5680 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5681 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 5682 | : HExpression(kNullCheck, value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5683 | SetRawInputAt(0, value); |
| 5684 | } |
| 5685 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5686 | bool IsClonable() const override { return true; } |
| 5687 | bool CanBeMoved() const override { return true; } |
| 5688 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5689 | return true; |
| 5690 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5691 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5692 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5693 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5694 | bool CanThrow() const override { return true; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 5695 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5696 | bool CanBeNull() const override { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 5697 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5698 | DECLARE_INSTRUCTION(NullCheck); |
| 5699 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5700 | protected: |
| 5701 | DEFAULT_COPY_CONSTRUCTOR(NullCheck); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5702 | }; |
| 5703 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5704 | // Embeds an ArtField and all the information required by the compiler. We cache |
| 5705 | // 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] | 5706 | class FieldInfo : public ValueObject { |
| 5707 | public: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5708 | FieldInfo(ArtField* field, |
| 5709 | MemberOffset field_offset, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5710 | DataType::Type field_type, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5711 | bool is_volatile, |
| 5712 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5713 | uint16_t declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5714 | const DexFile& dex_file) |
| 5715 | : field_(field), |
| 5716 | field_offset_(field_offset), |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5717 | field_type_(field_type), |
| 5718 | is_volatile_(is_volatile), |
| 5719 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5720 | declaring_class_def_index_(declaring_class_def_index), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5721 | dex_file_(dex_file) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5722 | |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5723 | ArtField* GetField() const { return field_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5724 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5725 | DataType::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5726 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5727 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5728 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5729 | bool IsVolatile() const { return is_volatile_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5730 | |
| 5731 | private: |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5732 | ArtField* const field_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5733 | const MemberOffset field_offset_; |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5734 | const DataType::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5735 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5736 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5737 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5738 | const DexFile& dex_file_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5739 | }; |
| 5740 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5741 | class HInstanceFieldGet final : public HExpression<1> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5742 | public: |
| 5743 | HInstanceFieldGet(HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5744 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5745 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5746 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5747 | bool is_volatile, |
| 5748 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5749 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5750 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5751 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5752 | : HExpression(kInstanceFieldGet, |
| 5753 | field_type, |
| 5754 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 5755 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5756 | field_info_(field, |
| 5757 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5758 | field_type, |
| 5759 | is_volatile, |
| 5760 | field_idx, |
| 5761 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5762 | dex_file) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5763 | SetRawInputAt(0, value); |
| 5764 | } |
| 5765 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5766 | bool IsClonable() const override { return true; } |
| 5767 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5768 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5769 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 5770 | const HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5771 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5772 | } |
| 5773 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5774 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5775 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5776 | } |
| 5777 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5778 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 5779 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 5780 | } |
| 5781 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5782 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5783 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5784 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5785 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5786 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5787 | void SetType(DataType::Type new_type) { |
| 5788 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5789 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5790 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5791 | SetPackedField<TypeField>(new_type); |
| 5792 | } |
| 5793 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5794 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 5795 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5796 | protected: |
| 5797 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldGet); |
| 5798 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5799 | private: |
| 5800 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5801 | }; |
| 5802 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5803 | class HInstanceFieldSet final : public HExpression<2> { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5804 | public: |
| 5805 | HInstanceFieldSet(HInstruction* object, |
| 5806 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5807 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5808 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5809 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 5810 | bool is_volatile, |
| 5811 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5812 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 5813 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 5814 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5815 | : HExpression(kInstanceFieldSet, |
| 5816 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 5817 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5818 | field_info_(field, |
| 5819 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 5820 | field_type, |
| 5821 | is_volatile, |
| 5822 | field_idx, |
| 5823 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 5824 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5825 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5826 | SetRawInputAt(0, object); |
| 5827 | SetRawInputAt(1, value); |
| 5828 | } |
| 5829 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5830 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5831 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5832 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 5833 | return (obj == InputAt(0)) && art::CanDoImplicitNullCheckOn(GetFieldOffset().Uint32Value()); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5834 | } |
| 5835 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5836 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5837 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5838 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5839 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5840 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5841 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 5842 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5843 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5844 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 5845 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5846 | protected: |
| 5847 | DEFAULT_COPY_CONSTRUCTOR(InstanceFieldSet); |
| 5848 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5849 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5850 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 5851 | static constexpr size_t kNumberOfInstanceFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 5852 | static_assert(kNumberOfInstanceFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 5853 | "Too many packed fields."); |
| 5854 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5855 | const FieldInfo field_info_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 5856 | }; |
| 5857 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5858 | class HArrayGet final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5859 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5860 | HArrayGet(HInstruction* array, |
| 5861 | HInstruction* index, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5862 | DataType::Type type, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5863 | uint32_t dex_pc) |
| 5864 | : HArrayGet(array, |
| 5865 | index, |
| 5866 | type, |
| 5867 | SideEffects::ArrayReadOfType(type), |
| 5868 | dex_pc, |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5869 | /* is_string_char_at */ false) { |
| 5870 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5871 | |
| 5872 | HArrayGet(HInstruction* array, |
| 5873 | HInstruction* index, |
| 5874 | DataType::Type type, |
| 5875 | SideEffects side_effects, |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5876 | uint32_t dex_pc, |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5877 | bool is_string_char_at) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5878 | : HExpression(kArrayGet, type, side_effects, dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5879 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5880 | SetRawInputAt(0, array); |
| 5881 | SetRawInputAt(1, index); |
| 5882 | } |
| 5883 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5884 | bool IsClonable() const override { return true; } |
| 5885 | bool CanBeMoved() const override { return true; } |
| 5886 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5887 | return true; |
| 5888 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5889 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5890 | // TODO: We can be smarter here. |
Vladimir Marko | 66d691d | 2017-04-07 17:53:39 +0100 | [diff] [blame] | 5891 | // Currently, unless the array is the result of NewArray, the array access is always |
| 5892 | // preceded by some form of null NullCheck necessary for the bounds check, usually |
| 5893 | // implicit null check on the ArrayLength input to BoundsCheck or Deoptimize for |
| 5894 | // dynamic BCE. There are cases when these could be removed to produce better code. |
| 5895 | // If we ever add optimizations to do so we should allow an implicit check here |
| 5896 | // (as long as the address falls in the first page). |
| 5897 | // |
| 5898 | // As an example of such fancy optimization, we could eliminate BoundsCheck for |
| 5899 | // a = cond ? new int[1] : null; |
| 5900 | // a[0]; // The Phi does not need bounds check for either input. |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5901 | return false; |
| 5902 | } |
| 5903 | |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5904 | bool IsEquivalentOf(HArrayGet* other) const { |
| 5905 | bool result = (GetDexPc() == other->GetDexPc()); |
| 5906 | if (kIsDebugBuild && result) { |
| 5907 | DCHECK_EQ(GetBlock(), other->GetBlock()); |
| 5908 | DCHECK_EQ(GetArray(), other->GetArray()); |
| 5909 | DCHECK_EQ(GetIndex(), other->GetIndex()); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5910 | if (DataType::IsIntOrLongType(GetType())) { |
| 5911 | DCHECK(DataType::IsFloatingPointType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5912 | } else { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5913 | DCHECK(DataType::IsFloatingPointType(GetType())) << GetType(); |
| 5914 | DCHECK(DataType::IsIntOrLongType(other->GetType())) << other->GetType(); |
David Brazdil | 4833f5a | 2015-12-16 10:37:39 +0000 | [diff] [blame] | 5915 | } |
| 5916 | } |
| 5917 | return result; |
| 5918 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 5919 | |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5920 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
| 5921 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5922 | HInstruction* GetArray() const { return InputAt(0); } |
| 5923 | HInstruction* GetIndex() const { return InputAt(1); } |
| 5924 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 5925 | void SetType(DataType::Type new_type) { |
| 5926 | DCHECK(DataType::IsIntegralType(GetType())); |
| 5927 | DCHECK(DataType::IsIntegralType(new_type)); |
| 5928 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 5929 | SetPackedField<TypeField>(new_type); |
| 5930 | } |
| 5931 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5932 | DECLARE_INSTRUCTION(ArrayGet); |
| 5933 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5934 | protected: |
| 5935 | DEFAULT_COPY_CONSTRUCTOR(ArrayGet); |
| 5936 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5937 | private: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5938 | // We treat a String as an array, creating the HArrayGet from String.charAt() |
| 5939 | // intrinsic in the instruction simplifier. We can always determine whether |
| 5940 | // a particular HArrayGet is actually a String.charAt() by looking at the type |
| 5941 | // of the input but that requires holding the mutator lock, so we prefer to use |
| 5942 | // 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] | 5943 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 5944 | static constexpr size_t kNumberOfArrayGetPackedBits = kFlagIsStringCharAt + 1; |
| 5945 | static_assert(kNumberOfArrayGetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 5946 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5947 | }; |
| 5948 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5949 | class HArraySet final : public HExpression<3> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5950 | public: |
| 5951 | HArraySet(HInstruction* array, |
| 5952 | HInstruction* index, |
| 5953 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5954 | DataType::Type expected_component_type, |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 5955 | uint32_t dex_pc) |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5956 | : HArraySet(array, |
| 5957 | index, |
| 5958 | value, |
| 5959 | expected_component_type, |
| 5960 | // Make a best guess for side effects now, may be refined during SSA building. |
| 5961 | ComputeSideEffects(GetComponentType(value->GetType(), expected_component_type)), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 5962 | dex_pc) { |
| 5963 | } |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 5964 | |
| 5965 | HArraySet(HInstruction* array, |
| 5966 | HInstruction* index, |
| 5967 | HInstruction* value, |
| 5968 | DataType::Type expected_component_type, |
| 5969 | SideEffects side_effects, |
| 5970 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 5971 | : HExpression(kArraySet, side_effects, dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5972 | SetPackedField<ExpectedComponentTypeField>(expected_component_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 5973 | SetPackedFlag<kFlagNeedsTypeCheck>(value->GetType() == DataType::Type::kReference); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5974 | SetPackedFlag<kFlagValueCanBeNull>(true); |
| 5975 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(false); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5976 | SetRawInputAt(0, array); |
| 5977 | SetRawInputAt(1, index); |
| 5978 | SetRawInputAt(2, value); |
| 5979 | } |
| 5980 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5981 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 5982 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5983 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 5984 | // We call a runtime method to throw ArrayStoreException. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5985 | return NeedsTypeCheck(); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 5986 | } |
| 5987 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5988 | // Can throw ArrayStoreException. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5989 | bool CanThrow() const override { return NeedsTypeCheck(); } |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 5990 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 5991 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const override { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 5992 | // TODO: Same as for ArrayGet. |
| 5993 | return false; |
| 5994 | } |
| 5995 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5996 | void ClearNeedsTypeCheck() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 5997 | SetPackedFlag<kFlagNeedsTypeCheck>(false); |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 5998 | } |
| 5999 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6000 | void ClearValueCanBeNull() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6001 | SetPackedFlag<kFlagValueCanBeNull>(false); |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 6002 | } |
| 6003 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6004 | void SetStaticTypeOfArrayIsObjectArray() { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6005 | SetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(true); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6006 | } |
| 6007 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6008 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6009 | bool NeedsTypeCheck() const { return GetPackedFlag<kFlagNeedsTypeCheck>(); } |
| 6010 | bool StaticTypeOfArrayIsObjectArray() const { |
| 6011 | return GetPackedFlag<kFlagStaticTypeOfArrayIsObjectArray>(); |
| 6012 | } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6013 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6014 | HInstruction* GetArray() const { return InputAt(0); } |
| 6015 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6016 | HInstruction* GetValue() const { return InputAt(2); } |
| 6017 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6018 | DataType::Type GetComponentType() const { |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6019 | return GetComponentType(GetValue()->GetType(), GetRawExpectedComponentType()); |
| 6020 | } |
| 6021 | |
| 6022 | static DataType::Type GetComponentType(DataType::Type value_type, |
| 6023 | DataType::Type expected_component_type) { |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6024 | // The Dex format does not type floating point index operations. Since the |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6025 | // `expected_component_type` comes from SSA building and can therefore not |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6026 | // be correct, we also check what is the value type. If it is a floating |
| 6027 | // point type, we must use that type. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6028 | return ((value_type == DataType::Type::kFloat32) || (value_type == DataType::Type::kFloat64)) |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6029 | ? value_type |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6030 | : expected_component_type; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 6031 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 6032 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6033 | DataType::Type GetRawExpectedComponentType() const { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6034 | return GetPackedField<ExpectedComponentTypeField>(); |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6035 | } |
| 6036 | |
Vladimir Marko | d5d2f2c | 2017-09-26 12:37:26 +0100 | [diff] [blame] | 6037 | static SideEffects ComputeSideEffects(DataType::Type type) { |
| 6038 | return SideEffects::ArrayWriteOfType(type).Union(SideEffectsForArchRuntimeCalls(type)); |
Aart Bik | 18b36ab | 2016-04-13 16:41:35 -0700 | [diff] [blame] | 6039 | } |
| 6040 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6041 | static SideEffects SideEffectsForArchRuntimeCalls(DataType::Type value_type) { |
| 6042 | return (value_type == DataType::Type::kReference) ? SideEffects::CanTriggerGC() |
| 6043 | : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6044 | } |
| 6045 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6046 | DECLARE_INSTRUCTION(ArraySet); |
| 6047 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6048 | protected: |
| 6049 | DEFAULT_COPY_CONSTRUCTOR(ArraySet); |
| 6050 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6051 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6052 | static constexpr size_t kFieldExpectedComponentType = kNumberOfGenericPackedBits; |
| 6053 | static constexpr size_t kFieldExpectedComponentTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6054 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6055 | static constexpr size_t kFlagNeedsTypeCheck = |
| 6056 | kFieldExpectedComponentType + kFieldExpectedComponentTypeSize; |
| 6057 | static constexpr size_t kFlagValueCanBeNull = kFlagNeedsTypeCheck + 1; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 6058 | // Cached information for the reference_type_info_ so that codegen |
| 6059 | // does not need to inspect the static type. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6060 | static constexpr size_t kFlagStaticTypeOfArrayIsObjectArray = kFlagValueCanBeNull + 1; |
| 6061 | static constexpr size_t kNumberOfArraySetPackedBits = |
| 6062 | kFlagStaticTypeOfArrayIsObjectArray + 1; |
| 6063 | static_assert(kNumberOfArraySetPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 6064 | using ExpectedComponentTypeField = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6065 | BitField<DataType::Type, kFieldExpectedComponentType, kFieldExpectedComponentTypeSize>; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6066 | }; |
| 6067 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6068 | class HArrayLength final : public HExpression<1> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6069 | public: |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6070 | 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] | 6071 | : HExpression(kArrayLength, DataType::Type::kInt32, SideEffects::None(), dex_pc) { |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6072 | SetPackedFlag<kFlagIsStringLength>(is_string_length); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6073 | // Note that arrays do not change length, so the instruction does not |
| 6074 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6075 | SetRawInputAt(0, array); |
| 6076 | } |
| 6077 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6078 | bool IsClonable() const override { return true; } |
| 6079 | bool CanBeMoved() const override { return true; } |
| 6080 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6081 | return true; |
| 6082 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6083 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const override { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 6084 | return obj == InputAt(0); |
| 6085 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6086 | |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6087 | bool IsStringLength() const { return GetPackedFlag<kFlagIsStringLength>(); } |
| 6088 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6089 | DECLARE_INSTRUCTION(ArrayLength); |
| 6090 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6091 | protected: |
| 6092 | DEFAULT_COPY_CONSTRUCTOR(ArrayLength); |
| 6093 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6094 | private: |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6095 | // We treat a String as an array, creating the HArrayLength from String.length() |
| 6096 | // or String.isEmpty() intrinsic in the instruction simplifier. We can always |
| 6097 | // determine whether a particular HArrayLength is actually a String.length() by |
| 6098 | // looking at the type of the input but that requires holding the mutator lock, so |
| 6099 | // 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] | 6100 | static constexpr size_t kFlagIsStringLength = kNumberOfGenericPackedBits; |
Vladimir Marko | dce016e | 2016-04-28 13:10:02 +0100 | [diff] [blame] | 6101 | static constexpr size_t kNumberOfArrayLengthPackedBits = kFlagIsStringLength + 1; |
| 6102 | static_assert(kNumberOfArrayLengthPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6103 | "Too many packed fields."); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6104 | }; |
| 6105 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6106 | class HBoundsCheck final : public HExpression<2> { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6107 | public: |
Nicolas Geoffray | 1af564e | 2016-01-13 12:09:39 +0000 | [diff] [blame] | 6108 | // `HBoundsCheck` can trigger GC, as it may call the `IndexOutOfBoundsException` |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6109 | // constructor. However it can only do it on a fatal slow path so execution never returns to the |
| 6110 | // instruction following the current one; thus 'SideEffects::None()' is used. |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6111 | HBoundsCheck(HInstruction* index, |
| 6112 | HInstruction* length, |
| 6113 | uint32_t dex_pc, |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6114 | bool is_string_char_at = false) |
Artem Serov | d1aa7d0 | 2018-06-22 11:35:46 +0100 | [diff] [blame] | 6115 | : HExpression(kBoundsCheck, index->GetType(), SideEffects::None(), dex_pc) { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6116 | DCHECK_EQ(DataType::Type::kInt32, DataType::Kind(index->GetType())); |
Vladimir Marko | 0259c24 | 2017-12-04 11:27:47 +0000 | [diff] [blame] | 6117 | SetPackedFlag<kFlagIsStringCharAt>(is_string_char_at); |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6118 | SetRawInputAt(0, index); |
| 6119 | SetRawInputAt(1, length); |
| 6120 | } |
| 6121 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6122 | bool IsClonable() const override { return true; } |
| 6123 | bool CanBeMoved() const override { return true; } |
| 6124 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 6125 | return true; |
| 6126 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 6127 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6128 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6129 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6130 | bool CanThrow() const override { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 6131 | |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 6132 | bool IsStringCharAt() const { return GetPackedFlag<kFlagIsStringCharAt>(); } |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 6133 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 6134 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6135 | |
| 6136 | DECLARE_INSTRUCTION(BoundsCheck); |
| 6137 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6138 | protected: |
| 6139 | DEFAULT_COPY_CONSTRUCTOR(BoundsCheck); |
| 6140 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6141 | private: |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6142 | static constexpr size_t kFlagIsStringCharAt = kNumberOfGenericPackedBits; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 6143 | }; |
| 6144 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6145 | class HSuspendCheck final : public HExpression<0> { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6146 | public: |
David Brazdil | 86ea7ee | 2016-02-16 09:26:07 +0000 | [diff] [blame] | 6147 | explicit HSuspendCheck(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6148 | : HExpression(kSuspendCheck, SideEffects::CanTriggerGC(), dex_pc), |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6149 | slow_path_(nullptr) { |
| 6150 | } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6151 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6152 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6153 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6154 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6155 | return true; |
| 6156 | } |
| 6157 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6158 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 6159 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6160 | |
| 6161 | DECLARE_INSTRUCTION(SuspendCheck); |
| 6162 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6163 | protected: |
| 6164 | DEFAULT_COPY_CONSTRUCTOR(SuspendCheck); |
| 6165 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6166 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 6167 | // Only used for code generation, in order to share the same slow path between back edges |
| 6168 | // of a same loop. |
| 6169 | SlowPathCode* slow_path_; |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 6170 | }; |
| 6171 | |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6172 | // Pseudo-instruction which provides the native debugger with mapping information. |
| 6173 | // 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] | 6174 | class HNativeDebugInfo : public HExpression<0> { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6175 | public: |
| 6176 | explicit HNativeDebugInfo(uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6177 | : HExpression<0>(kNativeDebugInfo, SideEffects::None(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6178 | } |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6179 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6180 | bool NeedsEnvironment() const override { |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6181 | return true; |
| 6182 | } |
| 6183 | |
| 6184 | DECLARE_INSTRUCTION(NativeDebugInfo); |
| 6185 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6186 | protected: |
| 6187 | DEFAULT_COPY_CONSTRUCTOR(NativeDebugInfo); |
David Srbecky | 0cf4493 | 2015-12-09 14:09:59 +0000 | [diff] [blame] | 6188 | }; |
| 6189 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6190 | /** |
| 6191 | * Instruction to load a Class object. |
| 6192 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6193 | class HLoadClass final : public HInstruction { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6194 | public: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6195 | // Determines how to load the Class. |
| 6196 | enum class LoadKind { |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6197 | // We cannot load this class. See HSharpening::SharpenLoadClass. |
| 6198 | kInvalid = -1, |
| 6199 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6200 | // Use the Class* from the method's own ArtMethod*. |
| 6201 | kReferrersClass, |
| 6202 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6203 | // 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] | 6204 | // Used for boot image classes referenced by boot image code. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6205 | kBootImageLinkTimePcRelative, |
| 6206 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6207 | // 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] | 6208 | // Used for boot image classes referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6209 | kBootImageRelRo, |
Vladimir Marko | 94ec2db | 2017-09-06 17:21:03 +0100 | [diff] [blame] | 6210 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6211 | // 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] | 6212 | // 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] | 6213 | kBssEntry, |
| 6214 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6215 | // Use a known boot image Class* address, embedded in the code by the codegen. |
| 6216 | // Used for boot image classes referenced by apps in JIT-compiled code. |
| 6217 | kJitBootImageAddress, |
| 6218 | |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6219 | // Load from the root table associated with the JIT compiled method. |
| 6220 | kJitTableAddress, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6221 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6222 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6223 | // the codegen is unable to use another appropriate kind. |
| 6224 | kRuntimeCall, |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6225 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6226 | kLast = kRuntimeCall |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6227 | }; |
| 6228 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6229 | HLoadClass(HCurrentMethod* current_method, |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6230 | dex::TypeIndex type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6231 | const DexFile& dex_file, |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6232 | Handle<mirror::Class> klass, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6233 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6234 | uint32_t dex_pc, |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6235 | bool needs_access_check) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6236 | : HInstruction(kLoadClass, |
| 6237 | DataType::Type::kReference, |
| 6238 | SideEffectsForArchRuntimeCalls(), |
| 6239 | dex_pc), |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6240 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6241 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 6242 | dex_file_(dex_file), |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6243 | klass_(klass) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 6244 | // Referrers class should not need access check. We never inline unverified |
| 6245 | // methods so we can't possibly end up in this situation. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6246 | DCHECK(!is_referrers_class || !needs_access_check); |
| 6247 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6248 | SetPackedField<LoadKindField>( |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6249 | is_referrers_class ? LoadKind::kReferrersClass : LoadKind::kRuntimeCall); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6250 | SetPackedFlag<kFlagNeedsAccessCheck>(needs_access_check); |
Nicolas Geoffray | 5687634 | 2016-12-16 16:09:08 +0000 | [diff] [blame] | 6251 | SetPackedFlag<kFlagIsInBootImage>(false); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6252 | SetPackedFlag<kFlagGenerateClInitCheck>(false); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6253 | SetPackedFlag<kFlagValidLoadedClassRTI>(false); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6254 | } |
| 6255 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6256 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6257 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6258 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6259 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6260 | LoadKind GetLoadKind() const { |
| 6261 | return GetPackedField<LoadKindField>(); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 6262 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6263 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6264 | bool HasPcRelativeLoadKind() const { |
| 6265 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6266 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6267 | GetLoadKind() == LoadKind::kBssEntry; |
| 6268 | } |
| 6269 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6270 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6271 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6272 | bool InstructionDataEquals(const HInstruction* other) const; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6273 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6274 | size_t ComputeHashCode() const override { return type_index_.index_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6275 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6276 | bool CanBeNull() const override { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6277 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6278 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6279 | return CanCallRuntime(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6280 | } |
| 6281 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 6282 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
Nicolas Geoffray | d930929 | 2015-10-31 22:21:31 +0000 | [diff] [blame] | 6283 | // The entrypoint the code generator is going to call does not do |
| 6284 | // clinit of the class. |
| 6285 | DCHECK(!NeedsAccessCheck()); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6286 | SetPackedFlag<kFlagGenerateClInitCheck>(generate_clinit_check); |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | bool CanCallRuntime() const { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6290 | return NeedsAccessCheck() || |
| 6291 | MustGenerateClinitCheck() || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6292 | GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6293 | GetLoadKind() == LoadKind::kBssEntry; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 6294 | } |
| 6295 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6296 | bool CanThrow() const override { |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6297 | return NeedsAccessCheck() || |
| 6298 | MustGenerateClinitCheck() || |
| 6299 | // 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] | 6300 | ((GetLoadKind() == LoadKind::kRuntimeCall || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6301 | GetLoadKind() == LoadKind::kBssEntry) && |
| 6302 | !IsInBootImage()); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 6303 | } |
| 6304 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6305 | ReferenceTypeInfo GetLoadedClassRTI() { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6306 | if (GetPackedFlag<kFlagValidLoadedClassRTI>()) { |
| 6307 | // Note: The is_exact flag from the return value should not be used. |
| 6308 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact */ true); |
| 6309 | } else { |
| 6310 | return ReferenceTypeInfo::CreateInvalid(); |
| 6311 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6314 | // Loaded class RTI is marked as valid by RTP if the klass_ is admissible. |
| 6315 | void SetValidLoadedClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 6316 | DCHECK(klass_ != nullptr); |
| 6317 | SetPackedFlag<kFlagValidLoadedClassRTI>(true); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 6318 | } |
| 6319 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6320 | dex::TypeIndex GetTypeIndex() const { return type_index_; } |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6321 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6322 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6323 | bool NeedsDexCacheOfDeclaringClass() const override { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6324 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Nicolas Geoffray | 22384ae | 2016-12-12 22:33:36 +0000 | [diff] [blame] | 6325 | } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 6326 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6327 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6328 | return SideEffects::CanTriggerGC(); |
| 6329 | } |
| 6330 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6331 | bool IsReferrersClass() const { return GetLoadKind() == LoadKind::kReferrersClass; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6332 | bool NeedsAccessCheck() const { return GetPackedFlag<kFlagNeedsAccessCheck>(); } |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6333 | bool IsInBootImage() const { return GetPackedFlag<kFlagIsInBootImage>(); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6334 | bool MustGenerateClinitCheck() const { return GetPackedFlag<kFlagGenerateClInitCheck>(); } |
Nicolas Geoffray | 42e372e | 2015-11-24 15:48:56 +0000 | [diff] [blame] | 6335 | |
Vladimir Marko | a9f303c | 2018-07-20 16:43:56 +0100 | [diff] [blame] | 6336 | bool MustResolveTypeOnSlowPath() const { |
| 6337 | // Check that this instruction has a slow path. |
| 6338 | DCHECK(GetLoadKind() != LoadKind::kRuntimeCall); // kRuntimeCall calls on main path. |
| 6339 | DCHECK(GetLoadKind() == LoadKind::kBssEntry || MustGenerateClinitCheck()); |
| 6340 | return GetLoadKind() == LoadKind::kBssEntry; |
| 6341 | } |
| 6342 | |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6343 | void MarkInBootImage() { |
| 6344 | SetPackedFlag<kFlagIsInBootImage>(true); |
| 6345 | } |
| 6346 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6347 | void AddSpecialInput(HInstruction* special_input); |
| 6348 | |
| 6349 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6350 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6351 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6352 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6353 | } |
| 6354 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6355 | Handle<mirror::Class> GetClass() const { |
| 6356 | return klass_; |
| 6357 | } |
| 6358 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6359 | DECLARE_INSTRUCTION(LoadClass); |
| 6360 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6361 | protected: |
| 6362 | DEFAULT_COPY_CONSTRUCTOR(LoadClass); |
| 6363 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6364 | private: |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6365 | static constexpr size_t kFlagNeedsAccessCheck = kNumberOfGenericPackedBits; |
Vladimir Marko | 4155998 | 2017-01-06 14:04:23 +0000 | [diff] [blame] | 6366 | static constexpr size_t kFlagIsInBootImage = kFlagNeedsAccessCheck + 1; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6367 | // Whether this instruction must generate the initialization check. |
| 6368 | // Used for code generation. |
Mathieu Chartier | 31b12e3 | 2016-09-02 17:11:57 -0700 | [diff] [blame] | 6369 | static constexpr size_t kFlagGenerateClInitCheck = kFlagIsInBootImage + 1; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6370 | static constexpr size_t kFieldLoadKind = kFlagGenerateClInitCheck + 1; |
| 6371 | static constexpr size_t kFieldLoadKindSize = |
| 6372 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 6373 | static constexpr size_t kFlagValidLoadedClassRTI = kFieldLoadKind + kFieldLoadKindSize; |
| 6374 | static constexpr size_t kNumberOfLoadClassPackedBits = kFlagValidLoadedClassRTI + 1; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6375 | static_assert(kNumberOfLoadClassPackedBits < kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6376 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
| 6377 | |
| 6378 | static bool HasTypeReference(LoadKind load_kind) { |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6379 | return load_kind == LoadKind::kReferrersClass || |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6380 | load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6381 | load_kind == LoadKind::kBssEntry || |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6382 | load_kind == LoadKind::kRuntimeCall; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6383 | } |
| 6384 | |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6385 | void SetLoadKindInternal(LoadKind load_kind); |
| 6386 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6387 | // The special input is the HCurrentMethod for kRuntimeCall or kReferrersClass. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6388 | // 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] | 6389 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6390 | HUserRecord<HInstruction*> special_input_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6391 | |
Nicolas Geoffray | 83c8e27 | 2017-01-31 14:36:37 +0000 | [diff] [blame] | 6392 | // A type index and dex file where the class can be accessed. The dex file can be: |
| 6393 | // - The compiling method's dex file if the class is defined there too. |
| 6394 | // - The compiling method's dex file if the class is referenced there. |
| 6395 | // - 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] | 6396 | // kBssEntry or kRuntimeCall, we cannot emit code for this `HLoadClass`. |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 6397 | const dex::TypeIndex type_index_; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6398 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6399 | |
Nicolas Geoffray | 5247c08 | 2017-01-13 14:17:29 +0000 | [diff] [blame] | 6400 | Handle<mirror::Class> klass_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6401 | }; |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6402 | std::ostream& operator<<(std::ostream& os, HLoadClass::LoadKind rhs); |
| 6403 | |
| 6404 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6405 | inline void HLoadClass::SetLoadKind(LoadKind load_kind) { |
| 6406 | // The load kind should be determined before inserting the instruction to the graph. |
| 6407 | DCHECK(GetBlock() == nullptr); |
| 6408 | DCHECK(GetEnvironment() == nullptr); |
| 6409 | SetPackedField<LoadKindField>(load_kind); |
| 6410 | if (load_kind != LoadKind::kRuntimeCall && load_kind != LoadKind::kReferrersClass) { |
| 6411 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6412 | } |
| 6413 | if (!NeedsEnvironment()) { |
| 6414 | SetSideEffects(SideEffects::None()); |
| 6415 | } |
| 6416 | } |
| 6417 | |
| 6418 | // Note: defined outside class to see operator<<(., HLoadClass::LoadKind). |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6419 | inline void HLoadClass::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6420 | // The special input is used for PC-relative loads on some architectures, |
| 6421 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6422 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6423 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6424 | GetLoadKind() == LoadKind::kBssEntry || |
| 6425 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6426 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6427 | special_input_ = HUserRecord<HInstruction*>(special_input); |
| 6428 | special_input->AddUseAt(this, 0); |
| 6429 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6430 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6431 | class HLoadString final : public HInstruction { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6432 | public: |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6433 | // Determines how to load the String. |
| 6434 | enum class LoadKind { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6435 | // 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] | 6436 | // Used for boot image strings referenced by boot image code. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6437 | kBootImageLinkTimePcRelative, |
| 6438 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6439 | // 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] | 6440 | // Used for boot image strings referenced by apps in AOT-compiled code. |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6441 | kBootImageRelRo, |
Vladimir Marko | 6cfbdbc | 2017-07-25 13:26:39 +0100 | [diff] [blame] | 6442 | |
Vladimir Marko | aad75c6 | 2016-10-03 08:46:48 +0000 | [diff] [blame] | 6443 | // 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] | 6444 | // 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] | 6445 | kBssEntry, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6446 | |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6447 | // Use a known boot image String* address, embedded in the code by the codegen. |
| 6448 | // Used for boot image strings referenced by apps in JIT-compiled code. |
| 6449 | kJitBootImageAddress, |
| 6450 | |
Vladimir Marko | 6bec91c | 2017-01-09 15:03:12 +0000 | [diff] [blame] | 6451 | // Load from the root table associated with the JIT compiled method. |
| 6452 | kJitTableAddress, |
| 6453 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6454 | // Load using a simple runtime call. This is the fall-back load kind when |
| 6455 | // the codegen is unable to use another appropriate kind. |
| 6456 | kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6457 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6458 | kLast = kRuntimeCall, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6459 | }; |
| 6460 | |
Nicolas Geoffray | 917d016 | 2015-11-24 18:25:35 +0000 | [diff] [blame] | 6461 | HLoadString(HCurrentMethod* current_method, |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6462 | dex::StringIndex string_index, |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6463 | const DexFile& dex_file, |
| 6464 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6465 | : HInstruction(kLoadString, |
| 6466 | DataType::Type::kReference, |
| 6467 | SideEffectsForArchRuntimeCalls(), |
| 6468 | dex_pc), |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6469 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6470 | string_index_(string_index), |
| 6471 | dex_file_(dex_file) { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6472 | SetPackedField<LoadKindField>(LoadKind::kRuntimeCall); |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 6473 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6474 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6475 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6476 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6477 | void SetLoadKind(LoadKind load_kind); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6478 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6479 | LoadKind GetLoadKind() const { |
| 6480 | return GetPackedField<LoadKindField>(); |
| 6481 | } |
| 6482 | |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6483 | bool HasPcRelativeLoadKind() const { |
| 6484 | return GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
| 6485 | GetLoadKind() == LoadKind::kBootImageRelRo || |
| 6486 | GetLoadKind() == LoadKind::kBssEntry; |
| 6487 | } |
| 6488 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6489 | const DexFile& GetDexFile() const { |
| 6490 | return dex_file_; |
| 6491 | } |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6492 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6493 | dex::StringIndex GetStringIndex() const { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6494 | return string_index_; |
| 6495 | } |
| 6496 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6497 | Handle<mirror::String> GetString() const { |
| 6498 | return string_; |
| 6499 | } |
| 6500 | |
| 6501 | void SetString(Handle<mirror::String> str) { |
| 6502 | string_ = str; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6503 | } |
| 6504 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6505 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6506 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6507 | bool InstructionDataEquals(const HInstruction* other) const override; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6508 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6509 | size_t ComputeHashCode() const override { return string_index_.index_; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6510 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6511 | // Will call the runtime if we need to load the string through |
| 6512 | // the dex cache and the string is not guaranteed to be there yet. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6513 | bool NeedsEnvironment() const override { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6514 | LoadKind load_kind = GetLoadKind(); |
Vladimir Marko | 764d454 | 2017-05-16 10:31:41 +0100 | [diff] [blame] | 6515 | if (load_kind == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6516 | load_kind == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6517 | load_kind == LoadKind::kJitBootImageAddress || |
Nicolas Geoffray | 132d836 | 2016-11-16 09:19:42 +0000 | [diff] [blame] | 6518 | load_kind == LoadKind::kJitTableAddress) { |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6519 | return false; |
| 6520 | } |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6521 | return true; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6522 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6523 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6524 | bool NeedsDexCacheOfDeclaringClass() const override { |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6525 | return GetLoadKind() == LoadKind::kRuntimeCall; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6526 | } |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 6527 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6528 | bool CanBeNull() const override { return false; } |
| 6529 | bool CanThrow() const override { return NeedsEnvironment(); } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6530 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 6531 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6532 | return SideEffects::CanTriggerGC(); |
| 6533 | } |
| 6534 | |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6535 | void AddSpecialInput(HInstruction* special_input); |
| 6536 | |
| 6537 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6538 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6539 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6540 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6541 | } |
| 6542 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6543 | DECLARE_INSTRUCTION(LoadString); |
| 6544 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6545 | protected: |
| 6546 | DEFAULT_COPY_CONSTRUCTOR(LoadString); |
| 6547 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6548 | private: |
Vladimir Marko | 4d1be492 | 2017-01-06 14:43:11 +0000 | [diff] [blame] | 6549 | static constexpr size_t kFieldLoadKind = kNumberOfGenericPackedBits; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6550 | static constexpr size_t kFieldLoadKindSize = |
| 6551 | MinimumBitsToStore(static_cast<size_t>(LoadKind::kLast)); |
| 6552 | static constexpr size_t kNumberOfLoadStringPackedBits = kFieldLoadKind + kFieldLoadKindSize; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6553 | static_assert(kNumberOfLoadStringPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6554 | using LoadKindField = BitField<LoadKind, kFieldLoadKind, kFieldLoadKindSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6555 | |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6556 | void SetLoadKindInternal(LoadKind load_kind); |
| 6557 | |
Vladimir Marko | 847e6ce | 2017-06-02 13:55:07 +0100 | [diff] [blame] | 6558 | // The special input is the HCurrentMethod for kRuntimeCall. |
Vladimir Marko | dbb7f5b | 2016-03-30 13:23:58 +0100 | [diff] [blame] | 6559 | // 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] | 6560 | // for PC-relative loads, i.e. kBssEntry or kBootImageLinkTimePcRelative. |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6561 | HUserRecord<HInstruction*> special_input_; |
| 6562 | |
Andreas Gampe | 8a0128a | 2016-11-28 07:38:35 -0800 | [diff] [blame] | 6563 | dex::StringIndex string_index_; |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6564 | const DexFile& dex_file_; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6565 | |
Nicolas Geoffray | f0acfe7 | 2017-01-09 20:54:52 +0000 | [diff] [blame] | 6566 | Handle<mirror::String> string_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6567 | }; |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6568 | std::ostream& operator<<(std::ostream& os, HLoadString::LoadKind rhs); |
| 6569 | |
| 6570 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | 28e012a | 2017-12-07 11:22:59 +0000 | [diff] [blame] | 6571 | inline void HLoadString::SetLoadKind(LoadKind load_kind) { |
| 6572 | // The load kind should be determined before inserting the instruction to the graph. |
| 6573 | DCHECK(GetBlock() == nullptr); |
| 6574 | DCHECK(GetEnvironment() == nullptr); |
| 6575 | DCHECK_EQ(GetLoadKind(), LoadKind::kRuntimeCall); |
| 6576 | SetPackedField<LoadKindField>(load_kind); |
| 6577 | if (load_kind != LoadKind::kRuntimeCall) { |
| 6578 | special_input_ = HUserRecord<HInstruction*>(nullptr); |
| 6579 | } |
| 6580 | if (!NeedsEnvironment()) { |
| 6581 | SetSideEffects(SideEffects::None()); |
| 6582 | } |
| 6583 | } |
| 6584 | |
| 6585 | // Note: defined outside class to see operator<<(., HLoadString::LoadKind). |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6586 | inline void HLoadString::AddSpecialInput(HInstruction* special_input) { |
Alexey Frunze | 06a46c4 | 2016-07-19 15:00:40 -0700 | [diff] [blame] | 6587 | // The special input is used for PC-relative loads on some architectures, |
| 6588 | // including literal pool loads, which are PC-relative too. |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6589 | DCHECK(GetLoadKind() == LoadKind::kBootImageLinkTimePcRelative || |
Vladimir Marko | e47f60c | 2018-02-21 13:43:28 +0000 | [diff] [blame] | 6590 | GetLoadKind() == LoadKind::kBootImageRelRo || |
Vladimir Marko | 8e524ad | 2018-07-13 10:27:43 +0100 | [diff] [blame] | 6591 | GetLoadKind() == LoadKind::kBssEntry || |
| 6592 | GetLoadKind() == LoadKind::kJitBootImageAddress) << GetLoadKind(); |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6593 | // HLoadString::GetInputRecords() returns an empty array at this point, |
| 6594 | // so use the GetInputRecords() from the base class to set the input record. |
| 6595 | DCHECK(special_input_.GetInstruction() == nullptr); |
| 6596 | special_input_ = HUserRecord<HInstruction*>(special_input); |
Vladimir Marko | cac5a7e | 2016-02-22 10:39:50 +0000 | [diff] [blame] | 6597 | special_input->AddUseAt(this, 0); |
| 6598 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 6599 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6600 | class HLoadMethodHandle final : public HInstruction { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6601 | public: |
| 6602 | HLoadMethodHandle(HCurrentMethod* current_method, |
Orion Hodson | 4c8e12e | 2018-05-18 08:33:20 +0100 | [diff] [blame] | 6603 | uint16_t method_handle_idx, |
| 6604 | const DexFile& dex_file, |
| 6605 | uint32_t dex_pc) |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6606 | : HInstruction(kLoadMethodHandle, |
| 6607 | DataType::Type::kReference, |
| 6608 | SideEffectsForArchRuntimeCalls(), |
| 6609 | dex_pc), |
| 6610 | special_input_(HUserRecord<HInstruction*>(current_method)), |
| 6611 | method_handle_idx_(method_handle_idx), |
| 6612 | dex_file_(dex_file) { |
| 6613 | } |
| 6614 | |
| 6615 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6616 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6617 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6618 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6619 | } |
| 6620 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6621 | bool IsClonable() const override { return true; } |
Orion Hodson | dbaa5c7 | 2018-05-10 08:22:46 +0100 | [diff] [blame] | 6622 | |
| 6623 | uint16_t GetMethodHandleIndex() const { return method_handle_idx_; } |
| 6624 | |
| 6625 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6626 | |
| 6627 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6628 | return SideEffects::CanTriggerGC(); |
| 6629 | } |
| 6630 | |
| 6631 | DECLARE_INSTRUCTION(LoadMethodHandle); |
| 6632 | |
| 6633 | protected: |
| 6634 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodHandle); |
| 6635 | |
| 6636 | private: |
| 6637 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6638 | HUserRecord<HInstruction*> special_input_; |
| 6639 | |
| 6640 | const uint16_t method_handle_idx_; |
| 6641 | const DexFile& dex_file_; |
| 6642 | }; |
| 6643 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6644 | class HLoadMethodType final : public HInstruction { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6645 | public: |
| 6646 | HLoadMethodType(HCurrentMethod* current_method, |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6647 | dex::ProtoIndex proto_index, |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6648 | const DexFile& dex_file, |
| 6649 | uint32_t dex_pc) |
| 6650 | : HInstruction(kLoadMethodType, |
| 6651 | DataType::Type::kReference, |
| 6652 | SideEffectsForArchRuntimeCalls(), |
| 6653 | dex_pc), |
| 6654 | special_input_(HUserRecord<HInstruction*>(current_method)), |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6655 | proto_index_(proto_index), |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6656 | dex_file_(dex_file) { |
| 6657 | } |
| 6658 | |
| 6659 | using HInstruction::GetInputRecords; // Keep the const version visible. |
Roland Levillain | 625ca47 | 2018-08-24 19:14:16 +0100 | [diff] [blame] | 6660 | ArrayRef<HUserRecord<HInstruction*>> GetInputRecords() final { |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6661 | return ArrayRef<HUserRecord<HInstruction*>>( |
| 6662 | &special_input_, (special_input_.GetInstruction() != nullptr) ? 1u : 0u); |
| 6663 | } |
| 6664 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6665 | bool IsClonable() const override { return true; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6666 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6667 | dex::ProtoIndex GetProtoIndex() const { return proto_index_; } |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6668 | |
| 6669 | const DexFile& GetDexFile() const { return dex_file_; } |
| 6670 | |
| 6671 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 6672 | return SideEffects::CanTriggerGC(); |
| 6673 | } |
| 6674 | |
| 6675 | DECLARE_INSTRUCTION(LoadMethodType); |
| 6676 | |
| 6677 | protected: |
| 6678 | DEFAULT_COPY_CONSTRUCTOR(LoadMethodType); |
| 6679 | |
| 6680 | private: |
| 6681 | // The special input is the HCurrentMethod for kRuntimeCall. |
| 6682 | HUserRecord<HInstruction*> special_input_; |
| 6683 | |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 6684 | const dex::ProtoIndex proto_index_; |
Orion Hodson | 18259d7 | 2018-04-12 11:18:23 +0100 | [diff] [blame] | 6685 | const DexFile& dex_file_; |
| 6686 | }; |
| 6687 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6688 | /** |
| 6689 | * Performs an initialization check on its Class object input. |
| 6690 | */ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6691 | class HClinitCheck final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6692 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 6693 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 6694 | : HExpression( |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6695 | kClinitCheck, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6696 | DataType::Type::kReference, |
Mingyao Yang | 217eb06 | 2017-12-11 15:20:07 -0800 | [diff] [blame] | 6697 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6698 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6699 | SetRawInputAt(0, constant); |
| 6700 | } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 6701 | // TODO: Make ClinitCheck clonable. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6702 | bool CanBeMoved() const override { return true; } |
| 6703 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 6704 | return true; |
| 6705 | } |
| 6706 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6707 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6708 | // May call runtime to initialize the class. |
| 6709 | return true; |
| 6710 | } |
| 6711 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6712 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6713 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 6714 | HLoadClass* GetLoadClass() const { |
| 6715 | DCHECK(InputAt(0)->IsLoadClass()); |
| 6716 | return InputAt(0)->AsLoadClass(); |
| 6717 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6718 | |
| 6719 | DECLARE_INSTRUCTION(ClinitCheck); |
| 6720 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6721 | |
| 6722 | protected: |
| 6723 | DEFAULT_COPY_CONSTRUCTOR(ClinitCheck); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6724 | }; |
| 6725 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6726 | class HStaticFieldGet final : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6727 | public: |
| 6728 | HStaticFieldGet(HInstruction* cls, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6729 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6730 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6731 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6732 | bool is_volatile, |
| 6733 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6734 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6735 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6736 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6737 | : HExpression(kStaticFieldGet, |
| 6738 | field_type, |
| 6739 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 6740 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6741 | field_info_(field, |
| 6742 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6743 | field_type, |
| 6744 | is_volatile, |
| 6745 | field_idx, |
| 6746 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6747 | dex_file) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6748 | SetRawInputAt(0, cls); |
| 6749 | } |
| 6750 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6751 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6752 | bool IsClonable() const override { return true; } |
| 6753 | bool CanBeMoved() const override { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6754 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6755 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 6756 | const HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6757 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6758 | } |
| 6759 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6760 | size_t ComputeHashCode() const override { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6761 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 6762 | } |
| 6763 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6764 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6765 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6766 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6767 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6768 | |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame] | 6769 | void SetType(DataType::Type new_type) { |
| 6770 | DCHECK(DataType::IsIntegralType(GetType())); |
| 6771 | DCHECK(DataType::IsIntegralType(new_type)); |
| 6772 | DCHECK_EQ(DataType::Size(GetType()), DataType::Size(new_type)); |
| 6773 | SetPackedField<TypeField>(new_type); |
| 6774 | } |
| 6775 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6776 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 6777 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6778 | protected: |
| 6779 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldGet); |
| 6780 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6781 | private: |
| 6782 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6783 | }; |
| 6784 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6785 | class HStaticFieldSet final : public HExpression<2> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6786 | public: |
| 6787 | HStaticFieldSet(HInstruction* cls, |
| 6788 | HInstruction* value, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6789 | ArtField* field, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6790 | DataType::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6791 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 6792 | bool is_volatile, |
| 6793 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6794 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 6795 | const DexFile& dex_file, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 6796 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6797 | : HExpression(kStaticFieldSet, |
| 6798 | SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 6799 | dex_pc), |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6800 | field_info_(field, |
| 6801 | field_offset, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 6802 | field_type, |
| 6803 | is_volatile, |
| 6804 | field_idx, |
| 6805 | declaring_class_def_index, |
Nicolas Geoffray | c52b26d | 2016-12-19 09:18:07 +0000 | [diff] [blame] | 6806 | dex_file) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6807 | SetPackedFlag<kFlagValueCanBeNull>(true); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6808 | SetRawInputAt(0, cls); |
| 6809 | SetRawInputAt(1, value); |
| 6810 | } |
| 6811 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6812 | bool IsClonable() const override { return true; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6813 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6814 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6815 | DataType::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 6816 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6817 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6818 | HInstruction* GetValue() const { return InputAt(1); } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6819 | bool GetValueCanBeNull() const { return GetPackedFlag<kFlagValueCanBeNull>(); } |
| 6820 | void ClearValueCanBeNull() { SetPackedFlag<kFlagValueCanBeNull>(false); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 6821 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6822 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 6823 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6824 | protected: |
| 6825 | DEFAULT_COPY_CONSTRUCTOR(StaticFieldSet); |
| 6826 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6827 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6828 | static constexpr size_t kFlagValueCanBeNull = kNumberOfGenericPackedBits; |
| 6829 | static constexpr size_t kNumberOfStaticFieldSetPackedBits = kFlagValueCanBeNull + 1; |
| 6830 | static_assert(kNumberOfStaticFieldSetPackedBits <= kMaxNumberOfPackedBits, |
| 6831 | "Too many packed fields."); |
| 6832 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6833 | const FieldInfo field_info_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 6834 | }; |
| 6835 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6836 | class HUnresolvedInstanceFieldGet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6837 | public: |
| 6838 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6839 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6840 | uint32_t field_index, |
| 6841 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6842 | : HExpression(kUnresolvedInstanceFieldGet, |
| 6843 | field_type, |
| 6844 | SideEffects::AllExceptGCDependency(), |
| 6845 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6846 | field_index_(field_index) { |
| 6847 | SetRawInputAt(0, obj); |
| 6848 | } |
| 6849 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6850 | bool IsClonable() const override { return true; } |
| 6851 | bool NeedsEnvironment() const override { return true; } |
| 6852 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6853 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6854 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6855 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6856 | |
| 6857 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 6858 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6859 | protected: |
| 6860 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldGet); |
| 6861 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6862 | private: |
| 6863 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6864 | }; |
| 6865 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6866 | class HUnresolvedInstanceFieldSet final : public HExpression<2> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6867 | public: |
| 6868 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 6869 | HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6870 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6871 | uint32_t field_index, |
| 6872 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6873 | : HExpression(kUnresolvedInstanceFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6874 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6875 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6876 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6877 | SetRawInputAt(0, obj); |
| 6878 | SetRawInputAt(1, value); |
| 6879 | } |
| 6880 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6881 | bool IsClonable() const override { return true; } |
| 6882 | bool NeedsEnvironment() const override { return true; } |
| 6883 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6884 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6885 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6886 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6887 | |
| 6888 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 6889 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6890 | protected: |
| 6891 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedInstanceFieldSet); |
| 6892 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6893 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6894 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6895 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6896 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6897 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6898 | kFieldFieldType + kFieldFieldTypeSize; |
| 6899 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6900 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6901 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6902 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6903 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6904 | }; |
| 6905 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6906 | class HUnresolvedStaticFieldGet final : public HExpression<0> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6907 | public: |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6908 | HUnresolvedStaticFieldGet(DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6909 | uint32_t field_index, |
| 6910 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6911 | : HExpression(kUnresolvedStaticFieldGet, |
| 6912 | field_type, |
| 6913 | SideEffects::AllExceptGCDependency(), |
| 6914 | dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6915 | field_index_(field_index) { |
| 6916 | } |
| 6917 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6918 | bool IsClonable() const override { return true; } |
| 6919 | bool NeedsEnvironment() const override { return true; } |
| 6920 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6921 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6922 | DataType::Type GetFieldType() const { return GetType(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6923 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6924 | |
| 6925 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 6926 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6927 | protected: |
| 6928 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldGet); |
| 6929 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6930 | private: |
| 6931 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6932 | }; |
| 6933 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6934 | class HUnresolvedStaticFieldSet final : public HExpression<1> { |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6935 | public: |
| 6936 | HUnresolvedStaticFieldSet(HInstruction* value, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6937 | DataType::Type field_type, |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6938 | uint32_t field_index, |
| 6939 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6940 | : HExpression(kUnresolvedStaticFieldSet, SideEffects::AllExceptGCDependency(), dex_pc), |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6941 | field_index_(field_index) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6942 | SetPackedField<FieldTypeField>(field_type); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6943 | DCHECK_EQ(DataType::Kind(field_type), DataType::Kind(value->GetType())); |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6944 | SetRawInputAt(0, value); |
| 6945 | } |
| 6946 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6947 | bool IsClonable() const override { return true; } |
| 6948 | bool NeedsEnvironment() const override { return true; } |
| 6949 | bool CanThrow() const override { return true; } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6950 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6951 | DataType::Type GetFieldType() const { return GetPackedField<FieldTypeField>(); } |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6952 | uint32_t GetFieldIndex() const { return field_index_; } |
| 6953 | |
| 6954 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 6955 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6956 | protected: |
| 6957 | DEFAULT_COPY_CONSTRUCTOR(UnresolvedStaticFieldSet); |
| 6958 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6959 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6960 | static constexpr size_t kFieldFieldType = HInstruction::kNumberOfGenericPackedBits; |
| 6961 | static constexpr size_t kFieldFieldTypeSize = |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6962 | MinimumBitsToStore(static_cast<size_t>(DataType::Type::kLast)); |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6963 | static constexpr size_t kNumberOfUnresolvedStaticFieldSetPackedBits = |
| 6964 | kFieldFieldType + kFieldFieldTypeSize; |
| 6965 | static_assert(kNumberOfUnresolvedStaticFieldSetPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 6966 | "Too many packed fields."); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 6967 | using FieldTypeField = BitField<DataType::Type, kFieldFieldType, kFieldFieldTypeSize>; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 6968 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6969 | const uint32_t field_index_; |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 6970 | }; |
| 6971 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6972 | // Implement the move-exception DEX instruction. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6973 | class HLoadException final : public HExpression<0> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6974 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6975 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6976 | : HExpression(kLoadException, DataType::Type::kReference, SideEffects::None(), dex_pc) { |
| 6977 | } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6978 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6979 | bool CanBeNull() const override { return false; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 6980 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6981 | DECLARE_INSTRUCTION(LoadException); |
| 6982 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6983 | protected: |
| 6984 | DEFAULT_COPY_CONSTRUCTOR(LoadException); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 6985 | }; |
| 6986 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6987 | // Implicit part of move-exception which clears thread-local exception storage. |
| 6988 | // Must not be removed because the runtime expects the TLS to get cleared. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 6989 | class HClearException final : public HExpression<0> { |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6990 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 6991 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 6992 | : HExpression(kClearException, SideEffects::AllWrites(), dex_pc) { |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 6993 | } |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6994 | |
| 6995 | DECLARE_INSTRUCTION(ClearException); |
| 6996 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 6997 | protected: |
| 6998 | DEFAULT_COPY_CONSTRUCTOR(ClearException); |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 6999 | }; |
| 7000 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7001 | class HThrow final : public HExpression<1> { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7002 | public: |
| 7003 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7004 | : HExpression(kThrow, SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7005 | SetRawInputAt(0, exception); |
| 7006 | } |
| 7007 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7008 | bool IsControlFlow() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7009 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7010 | bool NeedsEnvironment() const override { return true; } |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7011 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7012 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7013 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7014 | bool AlwaysThrows() const override { return true; } |
Aart Bik | a8b8e9b | 2018-01-09 11:01:02 -0800 | [diff] [blame] | 7015 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7016 | DECLARE_INSTRUCTION(Throw); |
| 7017 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7018 | protected: |
| 7019 | DEFAULT_COPY_CONSTRUCTOR(Throw); |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 7020 | }; |
| 7021 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7022 | /** |
| 7023 | * Implementation strategies for the code generator of a HInstanceOf |
| 7024 | * or `HCheckCast`. |
| 7025 | */ |
| 7026 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 7027 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7028 | kExactCheck, // Can do a single class compare. |
| 7029 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 7030 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 7031 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 7032 | kArrayObjectCheck, // Can just check if the array is not primitive. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7033 | kArrayCheck, // No optimization yet when checking against a generic array. |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7034 | kBitstringCheck, // Compare the type check bitstring. |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7035 | kLast = kArrayCheck |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7036 | }; |
| 7037 | |
Roland Levillain | 8650378 | 2016-02-11 19:07:30 +0000 | [diff] [blame] | 7038 | std::ostream& operator<<(std::ostream& os, TypeCheckKind rhs); |
| 7039 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7040 | // Note: HTypeCheckInstruction is just a helper class, not an abstract instruction with an |
| 7041 | // `IsTypeCheckInstruction()`. (New virtual methods in the HInstruction class have a high cost.) |
| 7042 | class HTypeCheckInstruction : public HVariableInputSizeInstruction { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7043 | public: |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7044 | HTypeCheckInstruction(InstructionKind kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7045 | DataType::Type type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7046 | HInstruction* object, |
| 7047 | HInstruction* target_class_or_null, |
| 7048 | TypeCheckKind check_kind, |
| 7049 | Handle<mirror::Class> klass, |
| 7050 | uint32_t dex_pc, |
| 7051 | ArenaAllocator* allocator, |
| 7052 | HIntConstant* bitstring_path_to_root, |
| 7053 | HIntConstant* bitstring_mask, |
| 7054 | SideEffects side_effects) |
| 7055 | : HVariableInputSizeInstruction( |
| 7056 | kind, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7057 | type, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7058 | side_effects, |
| 7059 | dex_pc, |
| 7060 | allocator, |
| 7061 | /* number_of_inputs */ check_kind == TypeCheckKind::kBitstringCheck ? 4u : 2u, |
| 7062 | kArenaAllocTypeCheckInputs), |
| 7063 | klass_(klass) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7064 | SetPackedField<TypeCheckKindField>(check_kind); |
| 7065 | SetPackedFlag<kFlagMustDoNullCheck>(true); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7066 | SetPackedFlag<kFlagValidTargetClassRTI>(false); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7067 | SetRawInputAt(0, object); |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7068 | SetRawInputAt(1, target_class_or_null); |
| 7069 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_path_to_root != nullptr); |
| 7070 | DCHECK_EQ(check_kind == TypeCheckKind::kBitstringCheck, bitstring_mask != nullptr); |
| 7071 | if (check_kind == TypeCheckKind::kBitstringCheck) { |
| 7072 | DCHECK(target_class_or_null->IsNullConstant()); |
| 7073 | SetRawInputAt(2, bitstring_path_to_root); |
| 7074 | SetRawInputAt(3, bitstring_mask); |
| 7075 | } else { |
| 7076 | DCHECK(target_class_or_null->IsLoadClass()); |
| 7077 | } |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | HLoadClass* GetTargetClass() const { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7081 | DCHECK_NE(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
Vladimir Marko | 8758454 | 2017-12-12 17:47:52 +0000 | [diff] [blame] | 7082 | HInstruction* load_class = InputAt(1); |
| 7083 | DCHECK(load_class->IsLoadClass()); |
| 7084 | return load_class->AsLoadClass(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7085 | } |
| 7086 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7087 | uint32_t GetBitstringPathToRoot() const { |
| 7088 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7089 | HInstruction* path_to_root = InputAt(2); |
| 7090 | DCHECK(path_to_root->IsIntConstant()); |
| 7091 | return static_cast<uint32_t>(path_to_root->AsIntConstant()->GetValue()); |
| 7092 | } |
| 7093 | |
| 7094 | uint32_t GetBitstringMask() const { |
| 7095 | DCHECK_EQ(GetTypeCheckKind(), TypeCheckKind::kBitstringCheck); |
| 7096 | HInstruction* mask = InputAt(3); |
| 7097 | DCHECK(mask->IsIntConstant()); |
| 7098 | return static_cast<uint32_t>(mask->AsIntConstant()->GetValue()); |
| 7099 | } |
| 7100 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7101 | bool IsClonable() const override { return true; } |
| 7102 | bool CanBeMoved() const override { return true; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7103 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7104 | bool InstructionDataEquals(const HInstruction* other) const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7105 | DCHECK(other->IsInstanceOf() || other->IsCheckCast()) << other->DebugName(); |
| 7106 | return GetPackedFields() == down_cast<const HTypeCheckInstruction*>(other)->GetPackedFields(); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7107 | } |
| 7108 | |
Andreas Gampe | 3fbd3ad | 2018-03-26 21:14:46 +0000 | [diff] [blame] | 7109 | bool MustDoNullCheck() const { return GetPackedFlag<kFlagMustDoNullCheck>(); } |
| 7110 | void ClearMustDoNullCheck() { SetPackedFlag<kFlagMustDoNullCheck>(false); } |
| 7111 | TypeCheckKind GetTypeCheckKind() const { return GetPackedField<TypeCheckKindField>(); } |
| 7112 | bool IsExactCheck() const { return GetTypeCheckKind() == TypeCheckKind::kExactCheck; } |
| 7113 | |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7114 | ReferenceTypeInfo GetTargetClassRTI() { |
| 7115 | if (GetPackedFlag<kFlagValidTargetClassRTI>()) { |
| 7116 | // Note: The is_exact flag from the return value should not be used. |
| 7117 | return ReferenceTypeInfo::CreateUnchecked(klass_, /* is_exact */ true); |
| 7118 | } else { |
| 7119 | return ReferenceTypeInfo::CreateInvalid(); |
| 7120 | } |
| 7121 | } |
| 7122 | |
| 7123 | // Target class RTI is marked as valid by RTP if the klass_ is admissible. |
| 7124 | void SetValidTargetClassRTI() REQUIRES_SHARED(Locks::mutator_lock_) { |
| 7125 | DCHECK(klass_ != nullptr); |
| 7126 | SetPackedFlag<kFlagValidTargetClassRTI>(true); |
| 7127 | } |
| 7128 | |
| 7129 | Handle<mirror::Class> GetClass() const { |
| 7130 | return klass_; |
| 7131 | } |
| 7132 | |
| 7133 | protected: |
| 7134 | DEFAULT_COPY_CONSTRUCTOR(TypeCheckInstruction); |
| 7135 | |
| 7136 | private: |
| 7137 | static constexpr size_t kFieldTypeCheckKind = kNumberOfGenericPackedBits; |
| 7138 | static constexpr size_t kFieldTypeCheckKindSize = |
| 7139 | MinimumBitsToStore(static_cast<size_t>(TypeCheckKind::kLast)); |
| 7140 | static constexpr size_t kFlagMustDoNullCheck = kFieldTypeCheckKind + kFieldTypeCheckKindSize; |
| 7141 | static constexpr size_t kFlagValidTargetClassRTI = kFlagMustDoNullCheck + 1; |
| 7142 | static constexpr size_t kNumberOfInstanceOfPackedBits = kFlagValidTargetClassRTI + 1; |
| 7143 | static_assert(kNumberOfInstanceOfPackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7144 | using TypeCheckKindField = BitField<TypeCheckKind, kFieldTypeCheckKind, kFieldTypeCheckKindSize>; |
| 7145 | |
| 7146 | Handle<mirror::Class> klass_; |
| 7147 | }; |
| 7148 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7149 | class HInstanceOf final : public HTypeCheckInstruction { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7150 | public: |
| 7151 | HInstanceOf(HInstruction* object, |
| 7152 | HInstruction* target_class_or_null, |
| 7153 | TypeCheckKind check_kind, |
| 7154 | Handle<mirror::Class> klass, |
| 7155 | uint32_t dex_pc, |
| 7156 | ArenaAllocator* allocator, |
| 7157 | HIntConstant* bitstring_path_to_root, |
| 7158 | HIntConstant* bitstring_mask) |
| 7159 | : HTypeCheckInstruction(kInstanceOf, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7160 | DataType::Type::kBool, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7161 | object, |
| 7162 | target_class_or_null, |
| 7163 | check_kind, |
| 7164 | klass, |
| 7165 | dex_pc, |
| 7166 | allocator, |
| 7167 | bitstring_path_to_root, |
| 7168 | bitstring_mask, |
| 7169 | SideEffectsForArchRuntimeCalls(check_kind)) {} |
| 7170 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7171 | bool IsClonable() const override { return true; } |
Artem Serov | a6e2614 | 2018-06-19 14:55:17 +0100 | [diff] [blame] | 7172 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7173 | bool NeedsEnvironment() const override { |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7174 | return CanCallRuntime(GetTypeCheckKind()); |
| 7175 | } |
| 7176 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7177 | static bool CanCallRuntime(TypeCheckKind check_kind) { |
| 7178 | // Mips currently does runtime calls for any other checks. |
| 7179 | return check_kind != TypeCheckKind::kExactCheck; |
| 7180 | } |
| 7181 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7182 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7183 | return CanCallRuntime(check_kind) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 7184 | } |
| 7185 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7186 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7187 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7188 | protected: |
| 7189 | DEFAULT_COPY_CONSTRUCTOR(InstanceOf); |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7190 | }; |
| 7191 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7192 | class HBoundType final : public HExpression<1> { |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7193 | public: |
Chih-Hung Hsieh | a593118 | 2016-09-01 15:08:13 -0700 | [diff] [blame] | 7194 | explicit HBoundType(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7195 | : HExpression(kBoundType, DataType::Type::kReference, SideEffects::None(), dex_pc), |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7196 | upper_bound_(ReferenceTypeInfo::CreateInvalid()) { |
| 7197 | SetPackedFlag<kFlagUpperCanBeNull>(true); |
| 7198 | SetPackedFlag<kFlagCanBeNull>(true); |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7199 | DCHECK_EQ(input->GetType(), DataType::Type::kReference); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7200 | SetRawInputAt(0, input); |
| 7201 | } |
| 7202 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7203 | bool InstructionDataEquals(const HInstruction* other) const override; |
| 7204 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7205 | |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7206 | // {Get,Set}Upper* should only be used in reference type propagation. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7207 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7208 | bool GetUpperCanBeNull() const { return GetPackedFlag<kFlagUpperCanBeNull>(); } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7209 | void SetUpperBound(const ReferenceTypeInfo& upper_bound, bool can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7210 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7211 | void SetCanBeNull(bool can_be_null) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7212 | DCHECK(GetUpperCanBeNull() || !can_be_null); |
| 7213 | SetPackedFlag<kFlagCanBeNull>(can_be_null); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7214 | } |
| 7215 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7216 | bool CanBeNull() const override { return GetPackedFlag<kFlagCanBeNull>(); } |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 7217 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7218 | DECLARE_INSTRUCTION(BoundType); |
| 7219 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7220 | protected: |
| 7221 | DEFAULT_COPY_CONSTRUCTOR(BoundType); |
| 7222 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7223 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7224 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 7225 | // is false then CanBeNull() cannot be true). |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7226 | static constexpr size_t kFlagUpperCanBeNull = kNumberOfGenericPackedBits; |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7227 | static constexpr size_t kFlagCanBeNull = kFlagUpperCanBeNull + 1; |
| 7228 | static constexpr size_t kNumberOfBoundTypePackedBits = kFlagCanBeNull + 1; |
| 7229 | static_assert(kNumberOfBoundTypePackedBits <= kMaxNumberOfPackedBits, "Too many packed fields."); |
| 7230 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7231 | // 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] | 7232 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 7233 | // It is used to bound the type in cases like: |
| 7234 | // if (x instanceof ClassX) { |
| 7235 | // // uper_bound_ will be ClassX |
| 7236 | // } |
David Brazdil | f555258 | 2015-12-27 13:36:12 +0000 | [diff] [blame] | 7237 | ReferenceTypeInfo upper_bound_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 7238 | }; |
| 7239 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7240 | class HCheckCast final : public HTypeCheckInstruction { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7241 | public: |
| 7242 | HCheckCast(HInstruction* object, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7243 | HInstruction* target_class_or_null, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 7244 | TypeCheckKind check_kind, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7245 | Handle<mirror::Class> klass, |
| 7246 | uint32_t dex_pc, |
| 7247 | ArenaAllocator* allocator, |
| 7248 | HIntConstant* bitstring_path_to_root, |
| 7249 | HIntConstant* bitstring_mask) |
| 7250 | : HTypeCheckInstruction(kCheckCast, |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7251 | DataType::Type::kVoid, |
Vladimir Marko | 175e786 | 2018-03-27 09:03:13 +0000 | [diff] [blame] | 7252 | object, |
| 7253 | target_class_or_null, |
| 7254 | check_kind, |
| 7255 | klass, |
| 7256 | dex_pc, |
| 7257 | allocator, |
| 7258 | bitstring_path_to_root, |
| 7259 | bitstring_mask, |
| 7260 | SideEffects::CanTriggerGC()) {} |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7261 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7262 | bool IsClonable() const override { return true; } |
| 7263 | bool NeedsEnvironment() const override { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7264 | // Instruction may throw a CheckCastError. |
| 7265 | return true; |
| 7266 | } |
| 7267 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7268 | bool CanThrow() const override { return true; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7269 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 7270 | DECLARE_INSTRUCTION(CheckCast); |
| 7271 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7272 | protected: |
| 7273 | DEFAULT_COPY_CONSTRUCTOR(CheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 7274 | }; |
| 7275 | |
Andreas Gampe | 26de38b | 2016-07-27 17:53:11 -0700 | [diff] [blame] | 7276 | /** |
| 7277 | * @brief Memory barrier types (see "The JSR-133 Cookbook for Compiler Writers"). |
| 7278 | * @details We define the combined barrier types that are actually required |
| 7279 | * by the Java Memory Model, rather than using exactly the terminology from |
| 7280 | * the JSR-133 cookbook. These should, in many cases, be replaced by acquire/release |
| 7281 | * primitives. Note that the JSR-133 cookbook generally does not deal with |
| 7282 | * store atomicity issues, and the recipes there are not always entirely sufficient. |
| 7283 | * The current recipe is as follows: |
| 7284 | * -# Use AnyStore ~= (LoadStore | StoreStore) ~= release barrier before volatile store. |
| 7285 | * -# Use AnyAny barrier after volatile store. (StoreLoad is as expensive.) |
| 7286 | * -# Use LoadAny barrier ~= (LoadLoad | LoadStore) ~= acquire barrier after each volatile load. |
| 7287 | * -# Use StoreStore barrier after all stores but before return from any constructor whose |
| 7288 | * class has final fields. |
| 7289 | * -# Use NTStoreStore to order non-temporal stores with respect to all later |
| 7290 | * store-to-memory instructions. Only generated together with non-temporal stores. |
| 7291 | */ |
| 7292 | enum MemBarrierKind { |
| 7293 | kAnyStore, |
| 7294 | kLoadAny, |
| 7295 | kStoreStore, |
| 7296 | kAnyAny, |
| 7297 | kNTStoreStore, |
| 7298 | kLastBarrierKind = kNTStoreStore |
| 7299 | }; |
| 7300 | std::ostream& operator<<(std::ostream& os, const MemBarrierKind& kind); |
| 7301 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7302 | class HMemoryBarrier final : public HExpression<0> { |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7303 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 7304 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7305 | : HExpression(kMemoryBarrier, |
| 7306 | SideEffects::AllWritesAndReads(), // Assume write/read on all fields/arrays. |
| 7307 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7308 | SetPackedField<BarrierKindField>(barrier_kind); |
| 7309 | } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7310 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7311 | bool IsClonable() const override { return true; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7312 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7313 | MemBarrierKind GetBarrierKind() { return GetPackedField<BarrierKindField>(); } |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7314 | |
| 7315 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 7316 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7317 | protected: |
| 7318 | DEFAULT_COPY_CONSTRUCTOR(MemoryBarrier); |
| 7319 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7320 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7321 | static constexpr size_t kFieldBarrierKind = HInstruction::kNumberOfGenericPackedBits; |
| 7322 | static constexpr size_t kFieldBarrierKindSize = |
| 7323 | MinimumBitsToStore(static_cast<size_t>(kLastBarrierKind)); |
| 7324 | static constexpr size_t kNumberOfMemoryBarrierPackedBits = |
| 7325 | kFieldBarrierKind + kFieldBarrierKindSize; |
| 7326 | static_assert(kNumberOfMemoryBarrierPackedBits <= kMaxNumberOfPackedBits, |
| 7327 | "Too many packed fields."); |
| 7328 | using BarrierKindField = BitField<MemBarrierKind, kFieldBarrierKind, kFieldBarrierKindSize>; |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 7329 | }; |
| 7330 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7331 | // A constructor fence orders all prior stores to fields that could be accessed via a final field of |
| 7332 | // the specified object(s), with respect to any subsequent store that might "publish" |
| 7333 | // (i.e. make visible) the specified object to another thread. |
| 7334 | // |
| 7335 | // JLS 17.5.1 "Semantics of final fields" states that a freeze action happens |
| 7336 | // for all final fields (that were set) at the end of the invoked constructor. |
| 7337 | // |
| 7338 | // The constructor fence models the freeze actions for the final fields of an object |
| 7339 | // being constructed (semantically at the end of the constructor). Constructor fences |
| 7340 | // have a per-object affinity; two separate objects being constructed get two separate |
| 7341 | // constructor fences. |
| 7342 | // |
| 7343 | // (Note: that if calling a super-constructor or forwarding to another constructor, |
| 7344 | // the freezes would happen at the end of *that* constructor being invoked). |
| 7345 | // |
| 7346 | // The memory model guarantees that when the object being constructed is "published" after |
| 7347 | // constructor completion (i.e. escapes the current thread via a store), then any final field |
| 7348 | // writes must be observable on other threads (once they observe that publication). |
| 7349 | // |
| 7350 | // Further, anything written before the freeze, and read by dereferencing through the final field, |
| 7351 | // must also be visible (so final object field could itself have an object with non-final fields; |
| 7352 | // yet the freeze must also extend to them). |
| 7353 | // |
| 7354 | // Constructor example: |
| 7355 | // |
| 7356 | // class HasFinal { |
| 7357 | // final int field; Optimizing IR for <init>()V: |
| 7358 | // HasFinal() { |
| 7359 | // field = 123; HInstanceFieldSet(this, HasFinal.field, 123) |
| 7360 | // // freeze(this.field); HConstructorFence(this) |
| 7361 | // } HReturn |
| 7362 | // } |
| 7363 | // |
| 7364 | // HConstructorFence can serve double duty as a fence for new-instance/new-array allocations of |
| 7365 | // already-initialized classes; in that case the allocation must act as a "default-initializer" |
| 7366 | // of the object which effectively writes the class pointer "final field". |
| 7367 | // |
| 7368 | // For example, we can model default-initialiation as roughly the equivalent of the following: |
| 7369 | // |
| 7370 | // class Object { |
| 7371 | // private final Class header; |
| 7372 | // } |
| 7373 | // |
| 7374 | // Java code: Optimizing IR: |
| 7375 | // |
| 7376 | // T new_instance<T>() { |
| 7377 | // Object obj = allocate_memory(T.class.size); obj = HInvoke(art_quick_alloc_object, T) |
| 7378 | // obj.header = T.class; // header write is done by above call. |
| 7379 | // // freeze(obj.header) HConstructorFence(obj) |
| 7380 | // return (T)obj; |
| 7381 | // } |
| 7382 | // |
| 7383 | // See also: |
| 7384 | // * CompilerDriver::RequiresConstructorBarrier |
| 7385 | // * QuasiAtomic::ThreadFenceForConstructor |
| 7386 | // |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7387 | class HConstructorFence final : public HVariableInputSizeInstruction { |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7388 | // A fence has variable inputs because the inputs can be removed |
| 7389 | // after prepare_for_register_allocation phase. |
| 7390 | // (TODO: In the future a fence could freeze multiple objects |
| 7391 | // after merging two fences together.) |
| 7392 | public: |
| 7393 | // `fence_object` is the reference that needs to be protected for correct publication. |
| 7394 | // |
| 7395 | // It makes sense in the following situations: |
| 7396 | // * <init> constructors, it's the "this" parameter (i.e. HParameterValue, s.t. IsThis() == true). |
| 7397 | // * new-instance-like instructions, it's the return value (i.e. HNewInstance). |
| 7398 | // |
| 7399 | // After construction the `fence_object` becomes the 0th input. |
| 7400 | // This is not an input in a real sense, but just a convenient place to stash the information |
| 7401 | // about the associated object. |
| 7402 | HConstructorFence(HInstruction* fence_object, |
| 7403 | uint32_t dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7404 | ArenaAllocator* allocator) |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7405 | // We strongly suspect there is not a more accurate way to describe the fine-grained reordering |
| 7406 | // constraints described in the class header. We claim that these SideEffects constraints |
| 7407 | // enforce a superset of the real constraints. |
| 7408 | // |
| 7409 | // The ordering described above is conservatively modeled with SideEffects as follows: |
| 7410 | // |
| 7411 | // * To prevent reordering of the publication stores: |
| 7412 | // ----> "Reads of objects" is the initial SideEffect. |
| 7413 | // * For every primitive final field store in the constructor: |
| 7414 | // ----> Union that field's type as a read (e.g. "Read of T") into the SideEffect. |
| 7415 | // * If there are any stores to reference final fields in the constructor: |
| 7416 | // ----> Use a more conservative "AllReads" SideEffect because any stores to any references |
| 7417 | // that are reachable from `fence_object` also need to be prevented for reordering |
| 7418 | // (and we do not want to do alias analysis to figure out what those stores are). |
| 7419 | // |
| 7420 | // In the implementation, this initially starts out as an "all reads" side effect; this is an |
| 7421 | // even more conservative approach than the one described above, and prevents all of the |
| 7422 | // above reordering without analyzing any of the instructions in the constructor. |
| 7423 | // |
| 7424 | // If in a later phase we discover that there are no writes to reference final fields, |
| 7425 | // 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] | 7426 | : HVariableInputSizeInstruction(kConstructorFence, |
| 7427 | SideEffects::AllReads(), |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7428 | dex_pc, |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7429 | allocator, |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7430 | /* number_of_inputs */ 1, |
| 7431 | kArenaAllocConstructorFenceInputs) { |
| 7432 | DCHECK(fence_object != nullptr); |
| 7433 | SetRawInputAt(0, fence_object); |
| 7434 | } |
| 7435 | |
| 7436 | // The object associated with this constructor fence. |
| 7437 | // |
| 7438 | // (Note: This will be null after the prepare_for_register_allocation phase, |
| 7439 | // as all constructor fence inputs are removed there). |
| 7440 | HInstruction* GetFenceObject() const { |
| 7441 | return InputAt(0); |
| 7442 | } |
| 7443 | |
| 7444 | // Find all the HConstructorFence uses (`fence_use`) for `this` and: |
| 7445 | // - Delete `fence_use` from `this`'s use list. |
| 7446 | // - Delete `this` from `fence_use`'s inputs list. |
| 7447 | // - If the `fence_use` is dead, remove it from the graph. |
| 7448 | // |
| 7449 | // A fence is considered dead once it no longer has any uses |
| 7450 | // and all of the inputs are dead. |
| 7451 | // |
| 7452 | // This must *not* be called during/after prepare_for_register_allocation, |
| 7453 | // because that removes all the inputs to the fences but the fence is actually |
| 7454 | // still considered live. |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7455 | // |
| 7456 | // Returns how many HConstructorFence instructions were removed from graph. |
| 7457 | static size_t RemoveConstructorFences(HInstruction* instruction); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7458 | |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7459 | // Combine all inputs of `this` and `other` instruction and remove |
| 7460 | // `other` from the graph. |
| 7461 | // |
| 7462 | // Inputs are unique after the merge. |
| 7463 | // |
| 7464 | // Requirement: `this` must not be the same as `other. |
| 7465 | void Merge(HConstructorFence* other); |
| 7466 | |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7467 | // Check if this constructor fence is protecting |
| 7468 | // an HNewInstance or HNewArray that is also the immediate |
| 7469 | // predecessor of `this`. |
| 7470 | // |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7471 | // If `ignore_inputs` is true, then the immediate predecessor doesn't need |
| 7472 | // to be one of the inputs of `this`. |
| 7473 | // |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7474 | // Returns the associated HNewArray or HNewInstance, |
| 7475 | // or null otherwise. |
Igor Murashkin | dd018df | 2017-08-09 10:38:31 -0700 | [diff] [blame] | 7476 | HInstruction* GetAssociatedAllocation(bool ignore_inputs = false); |
Igor Murashkin | 79d8fa7 | 2017-04-18 09:37:23 -0700 | [diff] [blame] | 7477 | |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7478 | DECLARE_INSTRUCTION(ConstructorFence); |
| 7479 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7480 | protected: |
| 7481 | DEFAULT_COPY_CONSTRUCTOR(ConstructorFence); |
Igor Murashkin | d01745e | 2017-04-05 16:40:31 -0700 | [diff] [blame] | 7482 | }; |
| 7483 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7484 | class HMonitorOperation final : public HExpression<1> { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7485 | public: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7486 | enum class OperationKind { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7487 | kEnter, |
| 7488 | kExit, |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7489 | kLast = kExit |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7490 | }; |
| 7491 | |
| 7492 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7493 | : HExpression(kMonitorOperation, |
| 7494 | SideEffects::AllExceptGCDependency(), // Assume write/read on all fields/arrays. |
| 7495 | dex_pc) { |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7496 | SetPackedField<OperationKindField>(kind); |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7497 | SetRawInputAt(0, object); |
| 7498 | } |
| 7499 | |
Nicolas Geoffray | 03196cf | 2016-02-01 12:23:22 +0000 | [diff] [blame] | 7500 | // Instruction may go into runtime, so we need an environment. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7501 | bool NeedsEnvironment() const override { return true; } |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7502 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7503 | bool CanThrow() const override { |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 7504 | // Verifier guarantees that monitor-exit cannot throw. |
| 7505 | // This is important because it allows the HGraphBuilder to remove |
| 7506 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 7507 | return IsEnter(); |
| 7508 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7509 | |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7510 | OperationKind GetOperationKind() const { return GetPackedField<OperationKindField>(); } |
| 7511 | bool IsEnter() const { return GetOperationKind() == OperationKind::kEnter; } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7512 | |
| 7513 | DECLARE_INSTRUCTION(MonitorOperation); |
| 7514 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7515 | protected: |
| 7516 | DEFAULT_COPY_CONSTRUCTOR(MonitorOperation); |
| 7517 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 7518 | private: |
Vladimir Marko | a1de918 | 2016-02-25 11:37:38 +0000 | [diff] [blame] | 7519 | static constexpr size_t kFieldOperationKind = HInstruction::kNumberOfGenericPackedBits; |
| 7520 | static constexpr size_t kFieldOperationKindSize = |
| 7521 | MinimumBitsToStore(static_cast<size_t>(OperationKind::kLast)); |
| 7522 | static constexpr size_t kNumberOfMonitorOperationPackedBits = |
| 7523 | kFieldOperationKind + kFieldOperationKindSize; |
| 7524 | static_assert(kNumberOfMonitorOperationPackedBits <= HInstruction::kMaxNumberOfPackedBits, |
| 7525 | "Too many packed fields."); |
| 7526 | using OperationKindField = BitField<OperationKind, kFieldOperationKind, kFieldOperationKindSize>; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 7527 | }; |
| 7528 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7529 | class HSelect final : public HExpression<3> { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7530 | public: |
| 7531 | HSelect(HInstruction* condition, |
| 7532 | HInstruction* true_value, |
| 7533 | HInstruction* false_value, |
| 7534 | uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7535 | : HExpression(kSelect, HPhi::ToPhiType(true_value->GetType()), SideEffects::None(), dex_pc) { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7536 | DCHECK_EQ(HPhi::ToPhiType(true_value->GetType()), HPhi::ToPhiType(false_value->GetType())); |
| 7537 | |
| 7538 | // First input must be `true_value` or `false_value` to allow codegens to |
| 7539 | // use the SameAsFirstInput allocation policy. We make it `false_value`, so |
| 7540 | // that architectures which implement HSelect as a conditional move also |
| 7541 | // will not need to invert the condition. |
| 7542 | SetRawInputAt(0, false_value); |
| 7543 | SetRawInputAt(1, true_value); |
| 7544 | SetRawInputAt(2, condition); |
| 7545 | } |
| 7546 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7547 | bool IsClonable() const override { return true; } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7548 | HInstruction* GetFalseValue() const { return InputAt(0); } |
| 7549 | HInstruction* GetTrueValue() const { return InputAt(1); } |
| 7550 | HInstruction* GetCondition() const { return InputAt(2); } |
| 7551 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7552 | bool CanBeMoved() const override { return true; } |
| 7553 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
Vladimir Marko | 372f10e | 2016-05-17 16:30:10 +0100 | [diff] [blame] | 7554 | return true; |
| 7555 | } |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7556 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7557 | bool CanBeNull() const override { |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7558 | return GetTrueValue()->CanBeNull() || GetFalseValue()->CanBeNull(); |
| 7559 | } |
| 7560 | |
| 7561 | DECLARE_INSTRUCTION(Select); |
| 7562 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7563 | protected: |
| 7564 | DEFAULT_COPY_CONSTRUCTOR(Select); |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 7565 | }; |
| 7566 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 7567 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7568 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7569 | MoveOperands(Location source, |
| 7570 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7571 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7572 | HInstruction* instruction) |
| 7573 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7574 | |
| 7575 | Location GetSource() const { return source_; } |
| 7576 | Location GetDestination() const { return destination_; } |
| 7577 | |
| 7578 | void SetSource(Location value) { source_ = value; } |
| 7579 | void SetDestination(Location value) { destination_ = value; } |
| 7580 | |
| 7581 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 7582 | // destination (but not the source). |
| 7583 | Location MarkPending() { |
| 7584 | DCHECK(!IsPending()); |
| 7585 | Location dest = destination_; |
| 7586 | destination_ = Location::NoLocation(); |
| 7587 | return dest; |
| 7588 | } |
| 7589 | |
| 7590 | void ClearPending(Location dest) { |
| 7591 | DCHECK(IsPending()); |
| 7592 | destination_ = dest; |
| 7593 | } |
| 7594 | |
| 7595 | bool IsPending() const { |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7596 | DCHECK(source_.IsValid() || destination_.IsInvalid()); |
| 7597 | return destination_.IsInvalid() && source_.IsValid(); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7598 | } |
| 7599 | |
| 7600 | // True if this blocks a move from the given location. |
| 7601 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 7602 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7603 | } |
| 7604 | |
| 7605 | // A move is redundant if it's been eliminated, if its source and |
| 7606 | // destination are the same, or if its destination is unneeded. |
| 7607 | bool IsRedundant() const { |
| 7608 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 7609 | } |
| 7610 | |
| 7611 | // We clear both operands to indicate move that's been eliminated. |
| 7612 | void Eliminate() { |
| 7613 | source_ = destination_ = Location::NoLocation(); |
| 7614 | } |
| 7615 | |
| 7616 | bool IsEliminated() const { |
| 7617 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 7618 | return source_.IsInvalid(); |
| 7619 | } |
| 7620 | |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7621 | DataType::Type GetType() const { return type_; } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 7622 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7623 | bool Is64BitMove() const { |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7624 | return DataType::Is64BitType(type_); |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7625 | } |
| 7626 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7627 | HInstruction* GetInstruction() const { return instruction_; } |
| 7628 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7629 | private: |
| 7630 | Location source_; |
| 7631 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7632 | // The type this move is for. |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7633 | DataType::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7634 | // The instruction this move is assocatied with. Null when this move is |
| 7635 | // for moving an input in the expected locations of user (including a phi user). |
| 7636 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 7637 | // in the same parallel move. |
| 7638 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7639 | }; |
| 7640 | |
Roland Levillain | c928591 | 2015-12-18 10:38:42 +0000 | [diff] [blame] | 7641 | std::ostream& operator<<(std::ostream& os, const MoveOperands& rhs); |
| 7642 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7643 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 7644 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7645 | class HParallelMove final : public HExpression<0> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7646 | public: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7647 | explicit HParallelMove(ArenaAllocator* allocator, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 7648 | : HExpression(kParallelMove, SideEffects::None(), dex_pc), |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 7649 | moves_(allocator->Adapter(kArenaAllocMoveOperands)) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7650 | moves_.reserve(kDefaultNumberOfMoves); |
| 7651 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7652 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7653 | void AddMove(Location source, |
| 7654 | Location destination, |
Vladimir Marko | 0ebe0d8 | 2017-09-21 22:50:39 +0100 | [diff] [blame] | 7655 | DataType::Type type, |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 7656 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 7657 | DCHECK(source.IsValid()); |
| 7658 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7659 | if (kIsDebugBuild) { |
| 7660 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7661 | for (const MoveOperands& move : moves_) { |
| 7662 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7663 | // Special case the situation where the move is for the spill slot |
| 7664 | // of the instruction. |
| 7665 | if ((GetPrevious() == instruction) |
| 7666 | || ((GetPrevious() == nullptr) |
| 7667 | && instruction->IsPhi() |
| 7668 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7669 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 7670 | << "Doing parallel moves for the same instruction."; |
| 7671 | } else { |
| 7672 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 7673 | } |
| 7674 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 7675 | } |
| 7676 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7677 | for (const MoveOperands& move : moves_) { |
| 7678 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7679 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7680 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 7681 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 7682 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 7683 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7684 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7685 | } |
| 7686 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7687 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7688 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7689 | } |
| 7690 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7691 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7692 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 7693 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7694 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7695 | protected: |
| 7696 | DEFAULT_COPY_CONSTRUCTOR(ParallelMove); |
| 7697 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7698 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 7699 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 7700 | }; |
| 7701 | |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7702 | // This instruction computes an intermediate address pointing in the 'middle' of an object. The |
| 7703 | // result pointer cannot be handled by GC, so extra care is taken to make sure that this value is |
| 7704 | // never used across anything that can trigger GC. |
| 7705 | // The result of this instruction is not a pointer in the sense of `DataType::Type::kreference`. |
| 7706 | // So we represent it by the type `DataType::Type::kInt`. |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7707 | class HIntermediateAddress final : public HExpression<2> { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7708 | public: |
| 7709 | HIntermediateAddress(HInstruction* base_address, HInstruction* offset, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 7710 | : HExpression(kIntermediateAddress, |
| 7711 | DataType::Type::kInt32, |
| 7712 | SideEffects::DependsOnGC(), |
| 7713 | dex_pc) { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7714 | DCHECK_EQ(DataType::Size(DataType::Type::kInt32), |
| 7715 | DataType::Size(DataType::Type::kReference)) |
| 7716 | << "kPrimInt and kPrimNot have different sizes."; |
| 7717 | SetRawInputAt(0, base_address); |
| 7718 | SetRawInputAt(1, offset); |
| 7719 | } |
| 7720 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7721 | bool IsClonable() const override { return true; } |
| 7722 | bool CanBeMoved() const override { return true; } |
| 7723 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const override { |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7724 | return true; |
| 7725 | } |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7726 | bool IsActualObject() const override { return false; } |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7727 | |
| 7728 | HInstruction* GetBaseAddress() const { return InputAt(0); } |
| 7729 | HInstruction* GetOffset() const { return InputAt(1); } |
| 7730 | |
| 7731 | DECLARE_INSTRUCTION(IntermediateAddress); |
| 7732 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7733 | protected: |
| 7734 | DEFAULT_COPY_CONSTRUCTOR(IntermediateAddress); |
xueliang.zhong | e0eb483 | 2017-10-30 13:43:14 +0000 | [diff] [blame] | 7735 | }; |
| 7736 | |
| 7737 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7738 | } // namespace art |
| 7739 | |
Aart Bik | f8f5a16 | 2017-02-06 15:35:29 -0800 | [diff] [blame] | 7740 | #include "nodes_vector.h" |
| 7741 | |
Artem Udovichenko | 4a0dad6 | 2016-01-26 12:28:31 +0300 | [diff] [blame] | 7742 | #if defined(ART_ENABLE_CODEGEN_arm) || defined(ART_ENABLE_CODEGEN_arm64) |
| 7743 | #include "nodes_shared.h" |
| 7744 | #endif |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 7745 | #ifdef ART_ENABLE_CODEGEN_mips |
| 7746 | #include "nodes_mips.h" |
| 7747 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 7748 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 7749 | #include "nodes_x86.h" |
| 7750 | #endif |
| 7751 | |
| 7752 | namespace art { |
| 7753 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7754 | class OptimizingCompilerStats; |
| 7755 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7756 | class HGraphVisitor : public ValueObject { |
| 7757 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7758 | explicit HGraphVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7759 | : stats_(stats), |
| 7760 | graph_(graph) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 7761 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7762 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 7763 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7764 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 7765 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7766 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7767 | void VisitInsertionOrder(); |
| 7768 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 7769 | // Visit the graph following dominator tree reverse post-order. |
| 7770 | void VisitReversePostOrder(); |
| 7771 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 7772 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 7773 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7774 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7775 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7776 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 7777 | |
| 7778 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7779 | |
| 7780 | #undef DECLARE_VISIT_INSTRUCTION |
| 7781 | |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7782 | protected: |
| 7783 | OptimizingCompilerStats* stats_; |
| 7784 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7785 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 7786 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 7787 | |
| 7788 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 7789 | }; |
| 7790 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7791 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 7792 | public: |
Igor Murashkin | 6ef4567 | 2017-08-08 13:59:55 -0700 | [diff] [blame] | 7793 | explicit HGraphDelegateVisitor(HGraph* graph, OptimizingCompilerStats* stats = nullptr) |
| 7794 | : HGraphVisitor(graph, stats) {} |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7795 | virtual ~HGraphDelegateVisitor() {} |
| 7796 | |
| 7797 | // Visit functions that delegate to to super class. |
| 7798 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7799 | void Visit##name(H##name* instr) override { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 7800 | |
| 7801 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 7802 | |
| 7803 | #undef DECLARE_VISIT_INSTRUCTION |
| 7804 | |
| 7805 | private: |
| 7806 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 7807 | }; |
| 7808 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7809 | // Create a clone of the instruction, insert it into the graph; replace the old one with a new |
| 7810 | // and remove the old instruction. |
| 7811 | HInstruction* ReplaceInstrOrPhiByClone(HInstruction* instr); |
| 7812 | |
| 7813 | // Create a clone for each clonable instructions/phis and replace the original with the clone. |
| 7814 | // |
| 7815 | // Used for testing individual instruction cloner. |
| 7816 | class CloneAndReplaceInstructionVisitor : public HGraphDelegateVisitor { |
| 7817 | public: |
| 7818 | explicit CloneAndReplaceInstructionVisitor(HGraph* graph) |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7819 | : HGraphDelegateVisitor(graph), instr_replaced_by_clones_count_(0) {} |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7820 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 7821 | void VisitInstruction(HInstruction* instruction) override { |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7822 | if (instruction->IsClonable()) { |
| 7823 | ReplaceInstrOrPhiByClone(instruction); |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7824 | instr_replaced_by_clones_count_++; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7825 | } |
| 7826 | } |
| 7827 | |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7828 | size_t GetInstrReplacedByClonesCount() const { return instr_replaced_by_clones_count_; } |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7829 | |
| 7830 | private: |
Artem Serov | 7f4aff6 | 2017-06-21 17:02:18 +0100 | [diff] [blame] | 7831 | size_t instr_replaced_by_clones_count_; |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 7832 | |
| 7833 | DISALLOW_COPY_AND_ASSIGN(CloneAndReplaceInstructionVisitor); |
| 7834 | }; |
| 7835 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7836 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7837 | // of an inner loop. The order in which the blocks are iterated is on their |
| 7838 | // block id. |
| 7839 | class HBlocksInLoopIterator : public ValueObject { |
| 7840 | public: |
| 7841 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 7842 | : blocks_in_loop_(info.GetBlocks()), |
| 7843 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 7844 | index_(0) { |
| 7845 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 7846 | Advance(); |
| 7847 | } |
| 7848 | } |
| 7849 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7850 | bool Done() const { return index_ == blocks_.size(); } |
| 7851 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7852 | void Advance() { |
| 7853 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7854 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7855 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 7856 | break; |
| 7857 | } |
| 7858 | } |
| 7859 | } |
| 7860 | |
| 7861 | private: |
| 7862 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7863 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 7864 | size_t index_; |
| 7865 | |
| 7866 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 7867 | }; |
| 7868 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7869 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 7870 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 7871 | // post order. |
| 7872 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 7873 | public: |
| 7874 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 7875 | : blocks_in_loop_(info.GetBlocks()), |
| 7876 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 7877 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7878 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7879 | Advance(); |
| 7880 | } |
| 7881 | } |
| 7882 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7883 | bool Done() const { return index_ == blocks_.size(); } |
| 7884 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7885 | void Advance() { |
| 7886 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7887 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 7888 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7889 | break; |
| 7890 | } |
| 7891 | } |
| 7892 | } |
| 7893 | |
| 7894 | private: |
| 7895 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 7896 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 7897 | size_t index_; |
| 7898 | |
| 7899 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 7900 | }; |
| 7901 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7902 | // Returns int64_t value of a properly typed constant. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7903 | inline int64_t Int64FromConstant(HConstant* constant) { |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7904 | if (constant->IsIntConstant()) { |
| 7905 | return constant->AsIntConstant()->GetValue(); |
| 7906 | } else if (constant->IsLongConstant()) { |
| 7907 | return constant->AsLongConstant()->GetValue(); |
| 7908 | } else { |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame] | 7909 | DCHECK(constant->IsNullConstant()) << constant->DebugName(); |
David Brazdil | c0b601b | 2016-02-08 14:20:45 +0000 | [diff] [blame] | 7910 | return 0; |
| 7911 | } |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 7912 | } |
| 7913 | |
Aart Bik | f3e61ee | 2017-04-12 17:09:20 -0700 | [diff] [blame] | 7914 | // Returns true iff instruction is an integral constant (and sets value on success). |
| 7915 | inline bool IsInt64AndGet(HInstruction* instruction, /*out*/ int64_t* value) { |
| 7916 | if (instruction->IsIntConstant()) { |
| 7917 | *value = instruction->AsIntConstant()->GetValue(); |
| 7918 | return true; |
| 7919 | } else if (instruction->IsLongConstant()) { |
| 7920 | *value = instruction->AsLongConstant()->GetValue(); |
| 7921 | return true; |
| 7922 | } else if (instruction->IsNullConstant()) { |
| 7923 | *value = 0; |
| 7924 | return true; |
| 7925 | } |
| 7926 | return false; |
| 7927 | } |
| 7928 | |
Aart Bik | 0148de4 | 2017-09-05 09:25:01 -0700 | [diff] [blame] | 7929 | // Returns true iff instruction is the given integral constant. |
| 7930 | inline bool IsInt64Value(HInstruction* instruction, int64_t value) { |
| 7931 | int64_t val = 0; |
| 7932 | return IsInt64AndGet(instruction, &val) && val == value; |
| 7933 | } |
| 7934 | |
| 7935 | // Returns true iff instruction is a zero bit pattern. |
| 7936 | inline bool IsZeroBitPattern(HInstruction* instruction) { |
| 7937 | return instruction->IsConstant() && instruction->AsConstant()->IsZeroBitPattern(); |
| 7938 | } |
| 7939 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7940 | // Implement HInstruction::Is##type() for concrete instructions. |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7941 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7942 | inline bool HInstruction::Is##type() const { return GetKind() == k##type; } |
| 7943 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7944 | #undef INSTRUCTION_TYPE_CHECK |
| 7945 | |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7946 | // Implement HInstruction::Is##type() for abstract instructions. |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7947 | #define INSTRUCTION_TYPE_CHECK_RESULT(type, super) \ |
| 7948 | std::is_base_of<BaseType, H##type>::value, |
| 7949 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
| 7950 | inline bool HInstruction::Is##type() const { \ |
| 7951 | DCHECK_LT(GetKind(), kLastInstructionKind); \ |
| 7952 | using BaseType = H##type; \ |
| 7953 | static constexpr bool results[] = { \ |
| 7954 | FOR_EACH_CONCRETE_INSTRUCTION(INSTRUCTION_TYPE_CHECK_RESULT) \ |
| 7955 | }; \ |
| 7956 | return results[static_cast<size_t>(GetKind())]; \ |
| 7957 | } |
| 7958 | |
| 7959 | FOR_EACH_ABSTRACT_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 7960 | #undef INSTRUCTION_TYPE_CHECK |
Vladimir Marko | 6d5b7e3 | 2018-05-09 16:52:48 +0100 | [diff] [blame] | 7961 | #undef INSTRUCTION_TYPE_CHECK_RESULT |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7962 | |
| 7963 | #define INSTRUCTION_TYPE_CAST(type, super) \ |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7964 | inline const H##type* HInstruction::As##type() const { \ |
| 7965 | return Is##type() ? down_cast<const H##type*>(this) : nullptr; \ |
| 7966 | } \ |
| 7967 | inline H##type* HInstruction::As##type() { \ |
| 7968 | return Is##type() ? static_cast<H##type*>(this) : nullptr; \ |
| 7969 | } |
| 7970 | |
Vladimir Marko | a90dd51 | 2018-05-04 15:04:45 +0100 | [diff] [blame] | 7971 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CAST) |
| 7972 | #undef INSTRUCTION_TYPE_CAST |
| 7973 | |
Vladimir Marko | 5f7b58e | 2015-11-23 19:49:34 +0000 | [diff] [blame] | 7974 | |
Nicolas Geoffray | 916cc1d | 2016-02-18 11:12:31 +0000 | [diff] [blame] | 7975 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 7976 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 7977 | inline void MakeRoomFor(ArenaVector<HBasicBlock*>* blocks, |
| 7978 | size_t number_of_new_blocks, |
| 7979 | size_t after) { |
| 7980 | DCHECK_LT(after, blocks->size()); |
| 7981 | size_t old_size = blocks->size(); |
| 7982 | size_t new_size = old_size + number_of_new_blocks; |
| 7983 | blocks->resize(new_size); |
| 7984 | std::copy_backward(blocks->begin() + after + 1u, blocks->begin() + old_size, blocks->end()); |
| 7985 | } |
| 7986 | |
Nicolas Geoffray | e761bcc | 2017-01-19 08:59:37 +0000 | [diff] [blame] | 7987 | /* |
| 7988 | * Hunt "under the hood" of array lengths (leading to array references), |
| 7989 | * null checks (also leading to array references), and new arrays |
| 7990 | * (leading to the actual length). This makes it more likely related |
| 7991 | * instructions become actually comparable. |
| 7992 | */ |
| 7993 | inline HInstruction* HuntForDeclaration(HInstruction* instruction) { |
| 7994 | while (instruction->IsArrayLength() || |
| 7995 | instruction->IsNullCheck() || |
| 7996 | instruction->IsNewArray()) { |
| 7997 | instruction = instruction->IsNewArray() |
| 7998 | ? instruction->AsNewArray()->GetLength() |
| 7999 | : instruction->InputAt(0); |
| 8000 | } |
| 8001 | return instruction; |
| 8002 | } |
| 8003 | |
Artem Serov | 21c7e6f | 2017-07-27 16:04:42 +0100 | [diff] [blame] | 8004 | void RemoveEnvironmentUses(HInstruction* instruction); |
| 8005 | bool HasEnvironmentUsedByOthers(HInstruction* instruction); |
| 8006 | void ResetEnvironmentInputRecords(HInstruction* instruction); |
| 8007 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 8008 | } // namespace art |
| 8009 | |
| 8010 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |